Browse Source

Minor tweaks, balanced disable/enable clientstate calls in SpriteBatches

Alexander Szpakowski 12 years ago
parent
commit
3e3f5c6bdd

+ 9 - 9
src/modules/graphics/opengl/ShaderEffect.cpp

@@ -87,31 +87,31 @@ ShaderEffect::~ShaderEffect()
 	unloadVolatile();
 }
 
-GLuint ShaderEffect::createShader(const ShaderType &type, const std::string &code)
+GLuint ShaderEffect::createShader(ShaderType type, const std::string &code)
 {
-	GLenum shadertype;
+	GLenum glshadertype;
 	const char *shadertypename = NULL;
 
 	switch (type)
 	{
 	case TYPE_VERTEX:
-		shadertype = GL_VERTEX_SHADER;
+		glshadertype = GL_VERTEX_SHADER;
 		shadertypename = "vertex";
 		break;
 	case TYPE_TESSCONTROL:
-		shadertype = GL_TESS_CONTROL_SHADER;
+		glshadertype = GL_TESS_CONTROL_SHADER;
 		shadertypename = "tesselation control";
 		break;
 	case TYPE_TESSEVAL:
-		shadertype = GL_TESS_EVALUATION_SHADER;
+		glshadertype = GL_TESS_EVALUATION_SHADER;
 		shadertypename = "tesselation evaluation";
 		break;
 	case TYPE_GEOMETRY:
-		shadertype = GL_GEOMETRY_SHADER;
+		glshadertype = GL_GEOMETRY_SHADER;
 		shadertypename = "geometry";
 		break;
 	case TYPE_FRAGMENT:
-		shadertype = GL_FRAGMENT_SHADER;
+		glshadertype = GL_FRAGMENT_SHADER;
 		shadertypename = "fragment";
 		break;
 	default:
@@ -122,7 +122,7 @@ GLuint ShaderEffect::createShader(const ShaderType &type, const std::string &cod
 	// clear existing errors
 	while (glGetError() != GL_NO_ERROR);
 
-	GLuint shaderid = glCreateShader(shadertype);
+	GLuint shaderid = glCreateShader(glshadertype);
 
 	if (shaderid == 0) // oh no!
 	{
@@ -204,7 +204,7 @@ bool ShaderEffect::loadVolatile()
 		shaderids.push_back(shaderid);
 	}
 
-	if (shaderids.size() == 0)
+	if (shaderids.empty())
 		throw love::Exception("Cannot create shader effect: no valid source code!");
 
 	createProgram(shaderids);

+ 2 - 2
src/modules/graphics/opengl/ShaderEffect.h

@@ -59,7 +59,7 @@ public:
 	 * Creates a new ShaderEffect using a list of source codes.
 	 * Must contain at least one vertex or fragment shader source.
 	 * 
-	 * @param shadersources map of shader source codes.
+	 * @param shadersources Map of shader types to source codes.
 	 **/
 	ShaderEffect(const ShaderSources &shadersources);
 
@@ -142,7 +142,7 @@ private:
 	GLint getUniformLocation(const std::string &name);
 	void checkSetUniformError();
 	
-	GLuint createShader(const ShaderType &type, const std::string &code);
+	GLuint createShader(ShaderType type, const std::string &code);
 	void createProgram(const std::vector<GLuint> &shaderids);
 
 	GLint getTextureUnit(const std::string &name);

+ 3 - 1
src/modules/graphics/opengl/SpriteBatch.cpp

@@ -225,7 +225,9 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
 
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-	glDisableClientState(GL_COLOR_ARRAY);
+
+	if (color)
+		glDisableClientState(GL_COLOR_ARRAY);
 
 	glPopMatrix();
 }

+ 4 - 4
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -452,23 +452,23 @@ int w_newShaderEffect(lua_State *L)
 		// call effectCodeToGLSL, returned values will be at the top of the stack
 		lua_pcall(L, 2, 2, 0);
 
-		ShaderEffect::ShaderSources shadersources;
+		ShaderEffect::ShaderSources sources;
 
 		// vertex shader code
 		if (lua_isstring(L, -2))
 		{
 			std::string vertcode(luaL_checkstring(L, -2));
-			shadersources[ShaderEffect::TYPE_VERTEX] = vertcode;
+			sources[ShaderEffect::TYPE_VERTEX] = vertcode;
 		}
 
 		// fragment shader code
 		if (lua_isstring(L, -1))
 		{
 			std::string fragcode(luaL_checkstring(L, -1));
-			shadersources[ShaderEffect::TYPE_FRAGMENT] = fragcode;
+			sources[ShaderEffect::TYPE_FRAGMENT] = fragcode;
 		}
 
-		ShaderEffect *effect = instance->newShaderEffect(shadersources);
+		ShaderEffect *effect = instance->newShaderEffect(sources);
 		luax_newtype(L, "ShaderEffect", GRAPHICS_SHADEREFFECT_T, (void *)effect);
 	}
 	catch(const love::Exception &e)