Skip to content

Commit

Permalink
Fixing CompileTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam authored and kenorb committed Apr 23, 2024
1 parent df05be8 commit 2881654
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions 3D/Cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class Cube : public Mesh<T> {
* 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
};
29 changes: 17 additions & 12 deletions 3D/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
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<MTDXVertexBuffer*>(_buff) != NULL) {
// MT5's DirectX.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 5 additions & 9 deletions 3D/Devices/MTDX/MTDXDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions 3D/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ class Mesh : public Dynamic {
Print("Indices: ", _s_indices);
#endif

vbuff = _vbuff = _device.VertexBuffer<T>(_vertices);
ibuff = _ibuff = _device.IndexBuffer(_indices);
vbuff = _vbuff = _device.CreateVertexBuffer<T>(_vertices);
ibuff = _ibuff = _device.CreateIndexBuffer(_indices);
return true;
}
};
4 changes: 2 additions & 2 deletions tests/3DTest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ int OnInit() {

gfx.Start(new MT5Frontend());

Ref<Shader> _shader_v = gfx.VertexShader(ShaderSourceVS, Vertex::Layout);
Ref<Shader> _shader_p = gfx.PixelShader(ShaderSourcePS);
Ref<Shader> _shader_v = gfx.CreateVertexShader(ShaderSourceVS, Vertex::Layout);
Ref<Shader> _shader_p = gfx.CreatePixelShader(ShaderSourcePS);

Ref<Cube<Vertex>> _mesh = new Cube<Vertex>(1.0f, 1.0f, 1.0f);
_mesh.Ptr().SetShaderVS(_shader_v.Ptr());
Expand Down

0 comments on commit 2881654

Please sign in to comment.