have separate variables/functions for VS/PS ubo stuff, array was confusing.

This commit is contained in:
Jordan Woyak 2011-12-11 04:11:57 -06:00
parent fbef258dab
commit 031c523fba
4 changed files with 47 additions and 46 deletions

View File

@ -522,12 +522,12 @@ void SetPSConstant4fvByName(const char * name, unsigned int offset, const float
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{ {
float f[4] = { f1, f2, f3, f4 }; float const f[4] = {f1, f2, f3, f4};
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
ProgramShaderCache::SetUniformObjects(0, const_number, f); ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1);
return; return;
} }
for (unsigned int a = 0; a < 10; ++a) for (unsigned int a = 0; a < 10; ++a)
{ {
@ -544,8 +544,8 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
{ {
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
ProgramShaderCache::SetUniformObjects(0, const_number, f); ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1);
return; return;
} }
for (unsigned int a = 0; a < 10; ++a) for (unsigned int a = 0; a < 10; ++a)
{ {
@ -562,8 +562,8 @@ void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, co
{ {
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
ProgramShaderCache::SetUniformObjects(0, const_number, f, count); ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, count);
return; return;
} }
for (unsigned int a = 0; a < 10; ++a) for (unsigned int a = 0; a < 10; ++a)
{ {

View File

@ -23,7 +23,8 @@ namespace OGL
{ {
GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0; GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0;
ProgramShaderCache::PCache ProgramShaderCache::pshaders; ProgramShaderCache::PCache ProgramShaderCache::pshaders;
GLuint ProgramShaderCache::UBOBuffers[2]; GLuint ProgramShaderCache::s_ps_ubo;
GLuint ProgramShaderCache::s_vs_ubo;
std::pair<u64, u64> ProgramShaderCache::CurrentShaderProgram; std::pair<u64, u64> ProgramShaderCache::CurrentShaderProgram;
const char *UniformNames[NUM_UNIFORMS] = { const char *UniformNames[NUM_UNIFORMS] = {
@ -138,22 +139,21 @@ namespace OGL
CurrentShaderProgram = ShaderPair; CurrentShaderProgram = ShaderPair;
CurrentProgram = entry.program.glprogid; CurrentProgram = entry.program.glprogid;
} }
void ProgramShaderCache::SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count)
{ void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
assert(Buffer > 1);
static int _Buffer = -1;
if(_Buffer != Buffer)
{ {
_Buffer = Buffer; glBindBuffer(GL_UNIFORM_BUFFER, s_ps_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[_Buffer]); glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4, count * sizeof(float) * 4, f);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
} }
// Query for the offsets of each block variable
void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count)
// glBufferSubData expects data in bytes, so multiply count by four {
// Expects the offset in bytes as well, so multiply by *4 *4 since we are passing in a vec4 location glBindBuffer(GL_UNIFORM_BUFFER, s_vs_ubo);
glBufferSubData(GL_UNIFORM_BUFFER, offset * 4 * 4, count * 4 * 4, f); glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4, count * sizeof(float) * 4, f);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
} }
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; } GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; }
GLint ProgramShaderCache::GetAttr(int num) GLint ProgramShaderCache::GetAttr(int num)
@ -173,32 +173,35 @@ namespace OGL
{ {
GLint Align; GLint Align;
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &Align); glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &Align);
glGenBuffers(2, UBOBuffers);
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[0]);
// We multiply by *4*4 because we need to get down to basic machine units. // We multiply by *4*4 because we need to get down to basic machine units.
// So multiply by four to get how many floats we have from vec4s // So multiply by four to get how many floats we have from vec4s
// Then once more to get bytes // Then once more to get bytes
glBufferData(GL_UNIFORM_BUFFER, ROUND_UP(C_PENVCONST_END * 4 * 4, Align), NULL, GL_DYNAMIC_DRAW); glGenBuffers(1, &s_ps_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, s_ps_ubo);
glBufferData(GL_UNIFORM_BUFFER, ROUND_UP(C_PENVCONST_END * sizeof(float) * 4, Align), NULL, GL_DYNAMIC_DRAW);
glGenBuffers(1, &s_vs_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, s_vs_ubo);
glBufferData(GL_UNIFORM_BUFFER, ROUND_UP(C_VENVCONST_END * sizeof(float) * 4, Align), NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
// Now bind the buffer to the index point // Now bind the buffer to the index point
// We know PS is 0 since we have it statically set in the shader // We know PS is 0 since we have it statically set in the shader
glBindBufferBase(GL_UNIFORM_BUFFER, 1, UBOBuffers[0]);
// Repeat for VS shader // Repeat for VS shader
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[1]); glBindBufferBase(GL_UNIFORM_BUFFER, 1, s_ps_ubo);
glBufferData(GL_UNIFORM_BUFFER, ROUND_UP(C_VENVCONST_END * 4 * 4, Align), NULL, GL_DYNAMIC_DRAW); glBindBufferBase(GL_UNIFORM_BUFFER, 2, s_vs_ubo);
glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOBuffers[1]);
} }
} }
void ProgramShaderCache::Shutdown(void) void ProgramShaderCache::Shutdown(void)
{ {
PCache::iterator iter = pshaders.begin(); PCache::iterator iter = pshaders.begin();
for (; iter != pshaders.end(); iter++) for (; iter != pshaders.end(); ++iter)
iter->second.Destroy(); iter->second.Destroy();
pshaders.clear(); pshaders.clear();
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
glDeleteBuffers(2, UBOBuffers); glDeleteBuffers(1, &s_ps_ubo);
glDeleteBuffers(1, &s_ps_ubo);
} }
} }

View File

@ -95,14 +95,15 @@ class ProgramShaderCache
static GLuint CurrentFShader, CurrentVShader, CurrentProgram; static GLuint CurrentFShader, CurrentVShader, CurrentProgram;
static std::pair<u64, u64> CurrentShaderProgram; static std::pair<u64, u64> CurrentShaderProgram;
// For UBOS static GLuint s_ps_ubo, s_vs_ubo;
static GLuint UBOBuffers[2]; // PS is 0, VS is 1
public: public:
static PROGRAMSHADER GetShaderProgram(void); static PROGRAMSHADER GetShaderProgram(void);
static GLint GetAttr(int num); static GLint GetAttr(int num);
static void SetBothShaders(GLuint PS, GLuint VS); static void SetBothShaders(GLuint PS, GLuint VS);
static GLuint GetCurrentProgram(void); static GLuint GetCurrentProgram(void);
static void SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count = 1);
static void SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count);
static void SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count);
static void Init(void); static void Init(void);
static void Shutdown(void); static void Shutdown(void);

View File

@ -240,14 +240,11 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float
} }
void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{ {
float buf[4]; float const buf[4] = {f1, f2, f3, f4};
buf[0] = f1;
buf[1] = f2;
buf[2] = f3;
buf[3] = f4;
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
ProgramShaderCache::SetUniformObjects(1, const_number, buf); ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, 1);
return; return;
} }
for( unsigned int a = 0; a < 9; ++a) for( unsigned int a = 0; a < 9; ++a)
@ -265,7 +262,7 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
{ {
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
ProgramShaderCache::SetUniformObjects(1, const_number, f); ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, 1);
return; return;
} }
for( unsigned int a = 0; a < 9; ++a) for( unsigned int a = 0; a < 9; ++a)
@ -283,7 +280,7 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co
{ {
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
ProgramShaderCache::SetUniformObjects(1, const_number, f, count); ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, count);
return; return;
} }
for( unsigned int a = 0; a < 9; ++a) for( unsigned int a = 0; a < 9; ++a)
@ -309,7 +306,7 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co
} }
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
ProgramShaderCache::SetUniformObjects(1, const_number, buf, count); ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, count);
return; return;
} }
for( unsigned int a = 0; a < 9; ++a) for( unsigned int a = 0; a < 9; ++a)