From 3e3f5c6bdd26e23313e2a05837af60d43497dbff Mon Sep 17 00:00:00 2001 From: Alexander Szpakowski Date: Tue, 8 Jan 2013 05:33:22 -0400 Subject: [PATCH] Minor tweaks, balanced disable/enable clientstate calls in SpriteBatches --- src/modules/graphics/opengl/ShaderEffect.cpp | 18 +++++++++--------- src/modules/graphics/opengl/ShaderEffect.h | 4 ++-- src/modules/graphics/opengl/SpriteBatch.cpp | 4 +++- src/modules/graphics/opengl/wrap_Graphics.cpp | 8 ++++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/modules/graphics/opengl/ShaderEffect.cpp b/src/modules/graphics/opengl/ShaderEffect.cpp index 79752b0d0..592cfe59d 100644 --- a/src/modules/graphics/opengl/ShaderEffect.cpp +++ b/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); diff --git a/src/modules/graphics/opengl/ShaderEffect.h b/src/modules/graphics/opengl/ShaderEffect.h index 3038a8d4c..d203d678c 100644 --- a/src/modules/graphics/opengl/ShaderEffect.h +++ b/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 &shaderids); GLint getTextureUnit(const std::string &name); diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index b46daf49c..7d6badaef 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/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(); } diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 3d469aa66..bfa53252f 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/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)