Kaynağa Gözat

fixes for opengl uniform buffer loading

This fix allows uniform buffers to be used with glsl shaders.

Small issue with uniform buffers not being initialized correctly.
marauder2k7 4 ay önce
ebeveyn
işleme
ab36fe24ec

+ 4 - 0
Engine/source/gfx/gl/gfxGLDevice.cpp

@@ -323,9 +323,13 @@ GLuint GFXGLDevice::getDeviceBuffer(const GFXShaderConstDesc desc)
 
    GLuint uboHandle;
    glGenBuffers(1, &uboHandle);
+   glBindBuffer(GL_UNIFORM_BUFFER, uboHandle);
+   glBufferData(GL_UNIFORM_BUFFER, desc.size, NULL, GL_DYNAMIC_DRAW); // allocate once
 
    mDeviceBufferMap[name] = uboHandle;
 
+   glBindBuffer(GL_UNIFORM_BUFFER, 0);
+
    return uboHandle;
 }
 

+ 3 - 2
Engine/source/gfx/gl/gfxGLShader.cpp

@@ -713,7 +713,8 @@ void GFXGLShader::initConstantDescs()
 
       // fill out ubo desc.
       desc.name = String((char*)uboName);
-      desc.bindPoint = uboBinding;
+      desc.bindPoint = uboBinding == 0 ? glGetUniformBlockIndex(mProgram, uboName) : uboBinding;
+      glUniformBlockBinding(mProgram, glGetUniformBlockIndex(mProgram, uboName), desc.bindPoint);
       desc.size = uboSize;
       desc.constType = GFXSCT_ConstBuffer;
       desc.samplerReg = -1;
@@ -888,7 +889,7 @@ void GFXGLShader::initHandles()
       // Index element 1 of the name to skip the '$' we inserted earier.
       GLint loc = glGetUniformLocation(mProgram, &desc.name.c_str()[1]);
 
-      AssertFatal(loc != -1, avar("uniform %s in shader file Vert: (%s) Frag: (%s)", &desc.name.c_str()[1], mVertexFile.getFullPath().c_str(), mPixelFile.getFullPath().c_str()));
+      //AssertFatal(loc != -1, avar("uniform %s in shader file Vert: (%s) Frag: (%s)", &desc.name.c_str()[1], mVertexFile.getFullPath().c_str(), mPixelFile.getFullPath().c_str()));
 
       HandleMap::Iterator handle = mHandles.find(desc.name);
       S32 sampler = -1;