浏览代码

Merge pull request #1446 from blackberry/master

Merge master to next.
Sean Taylor 12 年之前
父节点
当前提交
a61f38d350
共有 2 个文件被更改,包括 73 次插入64 次删除
  1. 41 45
      gameplay/src/Container.cpp
  2. 32 19
      gameplay/src/Effect.cpp

+ 41 - 45
gameplay/src/Container.cpp

@@ -197,55 +197,51 @@ unsigned int Container::addControl(Control* control)
 {
 	GP_ASSERT(control);
 
-    // Remove the control from its current parent
-    if (control->_parent && control->_parent != this)
-    {
-        control->_parent->removeControl(control);
-    }
+	if( control->_parent == this )
+	{
+		// Control is already in this container.
+		// Do nothing but determine and return control's index.
+		const size_t size = _controls.size();
+		for( size_t i = 0; i < size; ++i ) {
+			Control* c = _controls[ i ];
+			if( c == control ) {
+				return (unsigned int)i;
+			}
+		}
 
-    if (control->getZIndex() == -1)
-    {
-        control->setZIndex(_zIndexDefault++);
-    }
+		// Should never reach this.
+		GP_ASSERT( false );
+		return 0;
+	}
 
-    if (control->getFocusIndex() == -1)
-    {
-        // Find the current largest focus index
-        int maxFocusIndex = 0;
-        for (size_t i = 0, count = _controls.size(); i < count; ++i)
-        {
-            if (_controls[i]->_focusIndex > maxFocusIndex)
-                maxFocusIndex = _controls[i]->_focusIndex;
-        }
-        control->setFocusIndex(maxFocusIndex + 1);
-    }
+	if( control->getZIndex() == -1 ) {
+		control->setZIndex( _zIndexDefault++ );
+	}
 
-    if (control->_parent != this)
-    {
-        _controls.push_back(control);
-        control->addRef();
-        control->_parent = this;
-        sortControls();
-        return (unsigned int)(_controls.size() - 1);
-    }
-    else
-    {
-        // Control is already in this container.
-        // Do nothing but determine and return control's index.
-        const size_t size = _controls.size();
-        for (size_t i = 0; i < size; ++i)
-        {
-            Control* c = _controls[i];
-            if (c == control)
-            {
-                return (unsigned int)i;
-            }
-        }
+	if( control->getFocusIndex() == -1 ) {
+		// Find the current largest focus index
+		int maxFocusIndex = 0;
+		for( size_t i = 0, count = _controls.size(); i < count; ++i ) {
+			if( _controls[ i ]->_focusIndex > maxFocusIndex )
+				maxFocusIndex = _controls[ i ]->_focusIndex;
+		}
+		control->setFocusIndex( maxFocusIndex + 1 );
+	}
 
-        // Should never reach this.
-        GP_ASSERT(false);
-        return 0;
-    }
+	_controls.push_back( control );
+	control->addRef();
+
+	// Remove the control from its current parent
+	if( control->_parent )
+	{
+		control->_parent->removeControl( control );
+	}
+
+	control->_parent = this;
+
+	sortControls();
+
+	return (unsigned int)( _controls.size() - 1 );
 }
 
 void Container::insertControl(Control* control, unsigned int index)

+ 32 - 19
gameplay/src/Effect.cpp

@@ -473,27 +473,40 @@ Uniform* Effect::getUniform(const char* name) const
 {
     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)+1];
+		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;
+
+				delete parentname;
+				return uniform;
+			}
+		}
+		delete parentname;
     }
 
-    return (itr == _uniforms.end() ? NULL : itr->second);
+	// No uniform variable found - return NULL
+	return NULL;
 }
 
 Uniform* Effect::getUniform(unsigned int index) const