diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 3c218d2d4f..0d6c84791f 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -36,28 +36,6 @@ #include "GPU/Software/Rasterizer.h" #include "GPU/Common/FramebufferCommon.h" -// This is horrible, sorry. -class Matrix4x4 { -public: - union { - struct { - float xx, xy, xz, xw; - float yx, yy, yz, yw; - float zx, zy, zz, zw; - float wx, wy, wz, ww; - }; - float m[16]; - }; - - void setIdentity() { - memset(this, 0, 16 * sizeof(float)); - xx = 1.0f; - yy = 1.0f; - zz = 1.0f; - ww = 1.0f; - } -}; - const int FB_WIDTH = 480; const int FB_HEIGHT = 272; FormatBuffer fb; @@ -220,9 +198,14 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) thin3d->SetTexture(0, fbTex); Thin3DShaderSet *texColor = thin3d->GetShaderSetPreset(SS_TEXTURE_COLOR_2D); - Matrix4x4 identity; - identity.setIdentity(); - texColor->SetMatrix4x4("WorldViewProj", identity); + + static const float identity4x4[16] = { + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, + }; + texColor->SetMatrix4x4("WorldViewProj", identity4x4); thin3d->DrawIndexed(T3DPrimitive::PRIM_TRIANGLES, texColor, vformat, vdata, idata, 6, 0); } diff --git a/ext/native/gfx_es2/draw_buffer.cpp b/ext/native/gfx_es2/draw_buffer.cpp index 527fee59d5..2989977430 100644 --- a/ext/native/gfx_es2/draw_buffer.cpp +++ b/ext/native/gfx_es2/draw_buffer.cpp @@ -80,7 +80,7 @@ void DrawBuffer::Flush(bool set_blend_state) { if (count_ == 0) return; - shaderSet_->SetMatrix4x4("WorldViewProj", drawMatrix_); + shaderSet_->SetMatrix4x4("WorldViewProj", drawMatrix_.getReadPtr()); if (vbuf_) { vbuf_->SubData((const uint8_t *)verts_, 0, sizeof(Vertex) * count_); diff --git a/ext/native/thin3d/thin3d.h b/ext/native/thin3d/thin3d.h index bdf63c2120..5a71dfa528 100644 --- a/ext/native/thin3d/thin3d.h +++ b/ext/native/thin3d/thin3d.h @@ -282,7 +282,7 @@ class Thin3DShaderSet : public Thin3DObject { public: // TODO: Make some faster way of doing these. Support uniform buffers (and fake them on GL 2.0?) virtual void SetVector(const char *name, float *value, int n) = 0; - virtual void SetMatrix4x4(const char *name, const Matrix4x4 &value) = 0; + virtual void SetMatrix4x4(const char *name, const float value[16]) = 0; }; struct T3DBlendStateDesc { diff --git a/ext/native/thin3d/thin3d_d3d9.cpp b/ext/native/thin3d/thin3d_d3d9.cpp index cc49f7d9c7..a4ede14352 100644 --- a/ext/native/thin3d/thin3d_d3d9.cpp +++ b/ext/native/thin3d/thin3d_d3d9.cpp @@ -242,7 +242,7 @@ public: } } void SetVector(LPDIRECT3DDEVICE9 device, const char *name, float *value, int n); - void SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const Matrix4x4 &value); + void SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const float value[16]); private: bool isPixelShader_; @@ -258,7 +258,7 @@ public: Thin3DDX9Shader *pshader; void Apply(LPDIRECT3DDEVICE9 device); void SetVector(const char *name, float *value, int n) { vshader->SetVector(device_, name, value, n); pshader->SetVector(device_, name, value, n); } - void SetMatrix4x4(const char *name, const Matrix4x4 &value) { vshader->SetMatrix4x4(device_, name, value); } // pshaders don't usually have matrices + void SetMatrix4x4(const char *name, const float value[16]) { vshader->SetMatrix4x4(device_, name, value); } // pshaders don't usually have matrices private: LPDIRECT3DDEVICE9 device_; }; @@ -792,10 +792,10 @@ void Thin3DDX9Shader::SetVector(LPDIRECT3DDEVICE9 device, const char *name, floa } } -void Thin3DDX9Shader::SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const Matrix4x4 &value) { +void Thin3DDX9Shader::SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const float value[16]) { D3DXHANDLE handle = constantTable_->GetConstantByName(NULL, name); if (handle) { - constantTable_->SetFloatArray(device, handle, value.getReadPtr(), 16); + constantTable_->SetFloatArray(device, handle, value, 16); } } diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 141ed0b49d..4d72ac85ce 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -327,7 +327,7 @@ public: int GetUniformLoc(const char *name); void SetVector(const char *name, float *value, int n) override; - void SetMatrix4x4(const char *name, const Matrix4x4 &value) override; + void SetMatrix4x4(const char *name, const float value[16]) override; void GLLost() override { vshader->Compile(vshader->GetSource().c_str()); @@ -835,11 +835,11 @@ void Thin3DGLShaderSet::SetVector(const char *name, float *value, int n) { } } -void Thin3DGLShaderSet::SetMatrix4x4(const char *name, const Matrix4x4 &value) { +void Thin3DGLShaderSet::SetMatrix4x4(const char *name, const float value[16]) { glUseProgram(program_); int loc = GetUniformLoc(name); if (loc != -1) { - glUniformMatrix4fv(loc, 1, false, value.getReadPtr()); + glUniformMatrix4fv(loc, 1, false, value); } }