2
0
Эх сурвалжийг харах

Fixed bug in Effect.cpp where the OpenGL function glGetActiveUniform is called with a wrong parameter, causing an assertion failure on some graphic cards.

Björn Zeutzheim 12 жил өмнө
parent
commit
d6533b9dc1

+ 30 - 19
gameplay/src/Effect.cpp

@@ -473,27 +473,38 @@ Uniform* Effect::getUniform(const char* name) const
 {
 {
     std::map<std::string, Uniform*>::const_iterator itr = _uniforms.find(name);
     std::map<std::string, Uniform*>::const_iterator itr = _uniforms.find(name);
 
 
-    if (itr == _uniforms.end())
-    {
-        GLint uniformLocation;
-        GL_ASSERT( uniformLocation = glGetUniformLocation(_program, name) );
-        if (uniformLocation > -1)
-        {
-            Uniform* uniform = new Uniform();
-            uniform->_effect = const_cast<Effect*>(this);
-            uniform->_name = name;
-            uniform->_location = uniformLocation;
-            uniform->_index = 0;
-            GLchar uniformName[128];
-            GLint uniformSize;
-            GL_ASSERT( glGetActiveUniform(_program, uniformLocation, 128, NULL, &uniformSize, &uniform->_type, uniformName) );
-            _uniforms[name] = uniform;
-
-            return uniform;
-        }
+	if (itr != _uniforms.end()) {
+		// Return cached uniform variable
+		return itr->second;
+	}
+
+    GLint uniformLocation;
+    GL_ASSERT( uniformLocation = glGetUniformLocation(_program, name) );
+    if (uniformLocation > -1)
+	{
+		// Check for array uniforms ("u_directionalLightColor[0]" -> "u_directionalLightColor")
+		char* parentname = new char[strlen(name)];
+		strcpy(parentname, name);
+		if (strtok(parentname, "[") != NULL) {
+			std::map<std::string, Uniform*>::const_iterator itr = _uniforms.find(parentname);
+			if (itr != _uniforms.end()) {
+				Uniform* puniform = itr->second;
+
+				Uniform* uniform = new Uniform();
+				uniform->_effect = const_cast<Effect*>(this);
+				uniform->_name = name;
+				uniform->_location = uniformLocation;
+				uniform->_index = 0;
+				uniform->_type = puniform->getType();
+				_uniforms[name] = uniform;
+
+				return uniform;
+			}
+		}
     }
     }
 
 
-    return (itr == _uniforms.end() ? NULL : itr->second);
+	// No uniform variable found - return NULL
+	return NULL;
 }
 }
 
 
 Uniform* Effect::getUniform(unsigned int index) const
 Uniform* Effect::getUniform(unsigned int index) const