From 2881654ac9528267866e5d4d94707a0ddedd7743 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Thu, 15 Jun 2023 18:13:54 +0200 Subject: [PATCH] Fixing CompileTest --- 3D/Cube.h | 4 ++-- 3D/Device.h | 29 +++++++++++++++++------------ 3D/Devices/MTDX/MTDXDevice.h | 14 +++++--------- 3D/Mesh.h | 4 ++-- tests/3DTest.mq5 | 4 ++-- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/3D/Cube.h b/3D/Cube.h index 0bc9038ff..5ed20a8b9 100644 --- a/3D/Cube.h +++ b/3D/Cube.h @@ -77,8 +77,8 @@ class Cube : public Mesh { * Initializes graphics device-related things. */ virtual void Initialize(Device* _device) { - SetShaderVS(_device.VertexShader(ShaderCubeSourceVS, T::Layout)); - SetShaderPS(_device.PixelShader(ShaderCubeSourcePS)); + SetShaderVS(_device.CreateVertexShader(ShaderCubeSourceVS, T::Layout)); + SetShaderPS(_device.CreatePixelShader(ShaderCubeSourcePS)); } #endif }; diff --git a/3D/Device.h b/3D/Device.h index d7b64f94f..5124a22ac 100644 --- a/3D/Device.h +++ b/3D/Device.h @@ -138,20 +138,25 @@ class Device : public Dynamic { /** * Creates vertex shader to be used by current graphics device. */ - virtual Shader* VertexShader(string _source_code, const ShaderVertexLayout& _layout[], - string _entry_point = "main") = NULL; + virtual Shader* CreateVertexShader(string _source_code, const ShaderVertexLayout& _layout[], + string _entry_point = "main") = NULL; /** * Creates pixel shader to be used by current graphics device. */ - virtual Shader* PixelShader(string _source_code, string _entry_point = "main") = NULL; + virtual Shader* CreatePixelShader(string _source_code, string _entry_point = "main") = 0; + + /** + * Creates vertex buffer to be used by current graphics device. + */ + virtual VertexBuffer* CreateVertexBuffer() = 0; /** * Creates vertex buffer to be used by current graphics device. */ template - VertexBuffer* VertexBuffer(T& data[]) { - VertexBuffer* _buff = VertexBuffer(); + VertexBuffer* CreateVertexBuffer(T& data[]) { + VertexBuffer* _buff = CreateVertexBuffer(); // Unfortunately we can't make this method virtual. if (dynamic_cast(_buff) != NULL) { // MT5's DirectX. @@ -165,15 +170,10 @@ class Device : public Dynamic { return _buff; } - /** - * Creates vertex buffer to be used by current graphics device. - */ - virtual VertexBuffer* VertexBuffer() = NULL; - /** * Creates index buffer to be used by current graphics device. */ - virtual IndexBuffer* IndexBuffer(unsigned int& _indices[]) = NULL; + virtual IndexBuffer* CreateIndexBuffer(unsigned int& _indices[]) = 0; /** * Renders vertex buffer with optional point indices. @@ -183,7 +183,7 @@ class Device : public Dynamic { /** * Renders vertex buffer with optional point indices. */ - virtual void RenderBuffers(VertexBuffer* _vertices, IndexBuffer* _indices = NULL) = NULL; + virtual void RenderBuffers(VertexBuffer* _vertices, IndexBuffer* _indices = NULL) = 0; /** * Renders given mesh. @@ -233,6 +233,11 @@ class Device : public Dynamic { int Height() { return frontend.Ptr().Height(); } void SetCameraOrtho3D(float _pos_x = 0.0f, float _pos_y = 0.0f, float _pos_z = 0.0f) { + if (Width() <= 0 || Height() <= 0) { + Print("Cannot set 2D camera as width or height of the viewport is zero!"); + DebugBreak(); + return; + } DXMatrixOrthoLH(mtx_projection, 1.0f * _pos_z, 1.0f / Width() * Height() * _pos_z, -10000, 10000); } diff --git a/3D/Devices/MTDX/MTDXDevice.h b/3D/Devices/MTDX/MTDXDevice.h index 7bb1c93b8..166a924ed 100644 --- a/3D/Devices/MTDX/MTDXDevice.h +++ b/3D/Devices/MTDX/MTDXDevice.h @@ -93,15 +93,11 @@ class MTDXDevice : public Device { } } - /** - * Creates index buffer to be used by current graphics device. - */ - IndexBuffer* IndexBuffer() { return NULL; } - /** * Creates vertex shader to be used by current graphics device. */ - virtual Shader* VertexShader(string _source_code, const ShaderVertexLayout& _layout[], string _entry_point = "main") { + Shader* CreateVertexShader(string _source_code, const ShaderVertexLayout& _layout[], + string _entry_point = "main") override { MTDXShader* _shader = new MTDXShader(&this); _shader.Create(SHADER_TYPE_VS, _source_code, _entry_point); _shader.SetDataLayout(_layout); @@ -111,7 +107,7 @@ class MTDXDevice : public Device { /** * Creates pixel shader to be used by current graphics device. */ - virtual Shader* PixelShader(string _source_code, string _entry_point = "main") { + Shader* CreatePixelShader(string _source_code, string _entry_point = "main") override { MTDXShader* _shader = new MTDXShader(&this); _shader.Create(SHADER_TYPE_PS, _source_code, _entry_point); return _shader; @@ -120,12 +116,12 @@ class MTDXDevice : public Device { /** * Creates vertex buffer to be used by current graphics device. */ - VertexBuffer* VertexBuffer() { return new MTDXVertexBuffer(&this); } + VertexBuffer* CreateVertexBuffer() override { return new MTDXVertexBuffer(&this); } /** * Creates index buffer to be used by current graphics device. */ - virtual IndexBuffer* IndexBuffer(unsigned int& _indices[]) { + IndexBuffer* CreateIndexBuffer(unsigned int& _indices[]) override { IndexBuffer* _buffer = new MTDXIndexBuffer(&this); _buffer.Fill(_indices); return _buffer; diff --git a/3D/Mesh.h b/3D/Mesh.h index 0ee82c0dc..c6eaf1f78 100644 --- a/3D/Mesh.h +++ b/3D/Mesh.h @@ -249,8 +249,8 @@ class Mesh : public Dynamic { Print("Indices: ", _s_indices); #endif - vbuff = _vbuff = _device.VertexBuffer(_vertices); - ibuff = _ibuff = _device.IndexBuffer(_indices); + vbuff = _vbuff = _device.CreateVertexBuffer(_vertices); + ibuff = _ibuff = _device.CreateIndexBuffer(_indices); return true; } }; diff --git a/tests/3DTest.mq5 b/tests/3DTest.mq5 index 63390f3da..dd9ac7d5f 100644 --- a/tests/3DTest.mq5 +++ b/tests/3DTest.mq5 @@ -80,8 +80,8 @@ int OnInit() { gfx.Start(new MT5Frontend()); - Ref _shader_v = gfx.VertexShader(ShaderSourceVS, Vertex::Layout); - Ref _shader_p = gfx.PixelShader(ShaderSourcePS); + Ref _shader_v = gfx.CreateVertexShader(ShaderSourceVS, Vertex::Layout); + Ref _shader_p = gfx.CreatePixelShader(ShaderSourcePS); Ref> _mesh = new Cube(1.0f, 1.0f, 1.0f); _mesh.Ptr().SetShaderVS(_shader_v.Ptr());