thin3d: Use floats directly for 4x4 matrices.

This commit is contained in:
Unknown W. Brackets 2016-02-13 14:50:06 -08:00
parent 05fee24ccf
commit f84ebdc3e4
5 changed files with 17 additions and 34 deletions

View file

@ -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);
}

View file

@ -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_);

View file

@ -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 {

View file

@ -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);
}
}

View file

@ -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);
}
}