make use of glMapBuffer to set ubo data
This commit is contained in:
parent
16b58a8825
commit
5ae1f674f5
|
@ -25,6 +25,8 @@ namespace OGL
|
||||||
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
||||||
GLuint ProgramShaderCache::s_ps_ubo;
|
GLuint ProgramShaderCache::s_ps_ubo;
|
||||||
GLuint ProgramShaderCache::s_vs_ubo;
|
GLuint ProgramShaderCache::s_vs_ubo;
|
||||||
|
float* ProgramShaderCache::s_ps_mapped_data;
|
||||||
|
float* ProgramShaderCache::s_vs_mapped_data;
|
||||||
|
|
||||||
std::pair<u64, u64> ProgramShaderCache::CurrentShaderProgram;
|
std::pair<u64, u64> ProgramShaderCache::CurrentShaderProgram;
|
||||||
const char *UniformNames[NUM_UNIFORMS] = {
|
const char *UniformNames[NUM_UNIFORMS] = {
|
||||||
|
@ -141,16 +143,53 @@ namespace OGL
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
||||||
|
{
|
||||||
|
if (!s_ps_mapped_data)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, s_ps_ubo);
|
glBindBuffer(GL_UNIFORM_BUFFER, s_ps_ubo);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4, count * sizeof(float) * 4, f);
|
s_ps_mapped_data = reinterpret_cast<float*>(glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY));
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
|
if (!s_ps_mapped_data)
|
||||||
|
PanicAlert("glMapBuffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::copy(f, f + count * 4, s_ps_mapped_data + offset * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
||||||
|
{
|
||||||
|
if (!s_vs_mapped_data)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, s_vs_ubo);
|
glBindBuffer(GL_UNIFORM_BUFFER, s_vs_ubo);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4, count * sizeof(float) * 4, f);
|
s_vs_mapped_data = reinterpret_cast<float*>(glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY));
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
|
if (!s_vs_mapped_data)
|
||||||
|
PanicAlert("glMapBuffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::copy(f, f + count * 4, s_vs_mapped_data + offset * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramShaderCache::FlushConstants()
|
||||||
|
{
|
||||||
|
if (s_ps_mapped_data)
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, s_ps_ubo);
|
||||||
|
if (!glUnmapBuffer(GL_UNIFORM_BUFFER))
|
||||||
|
PanicAlert("glUnmapBuffer");
|
||||||
|
s_ps_mapped_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_vs_mapped_data)
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, s_vs_ubo);
|
||||||
|
if (!glUnmapBuffer(GL_UNIFORM_BUFFER))
|
||||||
|
PanicAlert("glUnmapBuffer");
|
||||||
|
s_vs_mapped_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,8 +239,11 @@ namespace OGL
|
||||||
iter->second.Destroy();
|
iter->second.Destroy();
|
||||||
pshaders.clear();
|
pshaders.clear();
|
||||||
|
|
||||||
|
// "A buffer object's mapped data store is automatically unmapped when the buffer object is deleted"
|
||||||
glDeleteBuffers(1, &s_ps_ubo);
|
glDeleteBuffers(1, &s_ps_ubo);
|
||||||
glDeleteBuffers(1, &s_ps_ubo);
|
glDeleteBuffers(1, &s_vs_ubo);
|
||||||
|
s_ps_ubo = s_vs_ubo = 0;
|
||||||
|
s_ps_mapped_data = s_vs_mapped_data = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ class ProgramShaderCache
|
||||||
static std::pair<u64, u64> CurrentShaderProgram;
|
static std::pair<u64, u64> CurrentShaderProgram;
|
||||||
|
|
||||||
static GLuint s_ps_ubo, s_vs_ubo;
|
static GLuint s_ps_ubo, s_vs_ubo;
|
||||||
|
static float *s_ps_mapped_data, *s_vs_mapped_data;
|
||||||
public:
|
public:
|
||||||
static PROGRAMSHADER GetShaderProgram(void);
|
static PROGRAMSHADER GetShaderProgram(void);
|
||||||
static GLint GetAttr(int num);
|
static GLint GetAttr(int num);
|
||||||
|
@ -105,6 +106,8 @@ public:
|
||||||
static void SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count);
|
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 SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count);
|
||||||
|
|
||||||
|
static void FlushConstants();
|
||||||
|
|
||||||
static void Init(void);
|
static void Init(void);
|
||||||
static void Shutdown(void);
|
static void Shutdown(void);
|
||||||
|
|
||||||
|
|
|
@ -215,6 +215,9 @@ void VertexManager::vFlush()
|
||||||
VertexShaderManager::SetConstants();
|
VertexShaderManager::SetConstants();
|
||||||
PixelShaderManager::SetConstants();
|
PixelShaderManager::SetConstants();
|
||||||
|
|
||||||
|
if(g_ActiveConfig.bUseGLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
ProgramShaderCache::FlushConstants();
|
||||||
|
|
||||||
// setup the pointers
|
// setup the pointers
|
||||||
if (g_nativeVertexFmt)
|
if (g_nativeVertexFmt)
|
||||||
g_nativeVertexFmt->SetupVertexPointers();
|
g_nativeVertexFmt->SetupVertexPointers();
|
||||||
|
|
Loading…
Reference in New Issue