Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
GLSL: store and use exact ubo sizes
  • Loading branch information
degasus committed Mar 17, 2013
1 parent 612c2e8 commit 106d7c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp
Expand Up @@ -27,6 +27,8 @@ namespace OGL

static const u32 UBO_LENGTH = 32*1024*1024;

GLintptr ProgramShaderCache::s_vs_data_size;
GLintptr ProgramShaderCache::s_ps_data_size;
GLintptr ProgramShaderCache::s_vs_data_offset;
u8 *ProgramShaderCache::s_ubo_buffer;
u32 ProgramShaderCache::s_ubo_buffer_size;
Expand Down Expand Up @@ -169,8 +171,8 @@ void ProgramShaderCache::UploadConstants()
if(s_ubo_dirty) {
s_buffer->Alloc(s_ubo_buffer_size);
size_t offset = s_buffer->Upload(s_ubo_buffer, s_ubo_buffer_size);
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->getBuffer(), offset, s_vs_data_offset);
glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_buffer->getBuffer(), offset + s_vs_data_offset, s_ubo_buffer_size - s_vs_data_offset);
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->getBuffer(), offset, s_ps_data_size);
glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_buffer->getBuffer(), offset + s_vs_data_offset, s_vs_data_size);
s_ubo_dirty = false;
}
}
Expand Down Expand Up @@ -388,10 +390,10 @@ void ProgramShaderCache::Init(void)
GLint Align;
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &Align);

GLintptr const ps_data_size = ROUND_UP(C_PENVCONST_END * sizeof(float) * 4, Align);
GLintptr const vs_data_size = ROUND_UP(C_VENVCONST_END * sizeof(float) * 4, Align);
s_vs_data_offset = ps_data_size;
s_ubo_buffer_size = ps_data_size + vs_data_size;
s_ps_data_size = C_PENVCONST_END * sizeof(float) * 4;
s_vs_data_size = C_VENVCONST_END * sizeof(float) * 4;
s_vs_data_offset = ROUND_UP(s_ps_data_size, Align);
s_ubo_buffer_size = ROUND_UP(s_ps_data_size, Align) + ROUND_UP(s_vs_data_size, Align);

// 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
Expand Down
2 changes: 2 additions & 0 deletions Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h
Expand Up @@ -125,6 +125,8 @@ class ProgramShaderCache
static PCacheEntry* last_entry;
static SHADERUID last_uid;

static GLintptr s_vs_data_size;
static GLintptr s_ps_data_size;
static GLintptr s_vs_data_offset;
static u8 *s_ubo_buffer;
static u32 s_ubo_buffer_size;
Expand Down

0 comments on commit 106d7c3

Please sign in to comment.