Minor tweaks, balanced disable/enable clientstate calls in SpriteBatches

This commit is contained in:
Alexander Szpakowski
2013-01-08 05:33:22 -04:00
parent 808a09f786
commit 3e3f5c6bdd
4 changed files with 18 additions and 16 deletions
+9 -9
View File
@@ -87,31 +87,31 @@ ShaderEffect::~ShaderEffect()
unloadVolatile(); 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; const char *shadertypename = NULL;
switch (type) switch (type)
{ {
case TYPE_VERTEX: case TYPE_VERTEX:
shadertype = GL_VERTEX_SHADER; glshadertype = GL_VERTEX_SHADER;
shadertypename = "vertex"; shadertypename = "vertex";
break; break;
case TYPE_TESSCONTROL: case TYPE_TESSCONTROL:
shadertype = GL_TESS_CONTROL_SHADER; glshadertype = GL_TESS_CONTROL_SHADER;
shadertypename = "tesselation control"; shadertypename = "tesselation control";
break; break;
case TYPE_TESSEVAL: case TYPE_TESSEVAL:
shadertype = GL_TESS_EVALUATION_SHADER; glshadertype = GL_TESS_EVALUATION_SHADER;
shadertypename = "tesselation evaluation"; shadertypename = "tesselation evaluation";
break; break;
case TYPE_GEOMETRY: case TYPE_GEOMETRY:
shadertype = GL_GEOMETRY_SHADER; glshadertype = GL_GEOMETRY_SHADER;
shadertypename = "geometry"; shadertypename = "geometry";
break; break;
case TYPE_FRAGMENT: case TYPE_FRAGMENT:
shadertype = GL_FRAGMENT_SHADER; glshadertype = GL_FRAGMENT_SHADER;
shadertypename = "fragment"; shadertypename = "fragment";
break; break;
default: default:
@@ -122,7 +122,7 @@ GLuint ShaderEffect::createShader(const ShaderType &type, const std::string &cod
// clear existing errors // clear existing errors
while (glGetError() != GL_NO_ERROR); while (glGetError() != GL_NO_ERROR);
GLuint shaderid = glCreateShader(shadertype); GLuint shaderid = glCreateShader(glshadertype);
if (shaderid == 0) // oh no! if (shaderid == 0) // oh no!
{ {
@@ -204,7 +204,7 @@ bool ShaderEffect::loadVolatile()
shaderids.push_back(shaderid); shaderids.push_back(shaderid);
} }
if (shaderids.size() == 0) if (shaderids.empty())
throw love::Exception("Cannot create shader effect: no valid source code!"); throw love::Exception("Cannot create shader effect: no valid source code!");
createProgram(shaderids); createProgram(shaderids);
+2 -2
View File
@@ -59,7 +59,7 @@ public:
* Creates a new ShaderEffect using a list of source codes. * Creates a new ShaderEffect using a list of source codes.
* Must contain at least one vertex or fragment shader source. * 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); ShaderEffect(const ShaderSources &shadersources);
@@ -142,7 +142,7 @@ private:
GLint getUniformLocation(const std::string &name); GLint getUniformLocation(const std::string &name);
void checkSetUniformError(); 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); void createProgram(const std::vector<GLuint> &shaderids);
GLint getTextureUnit(const std::string &name); GLint getTextureUnit(const std::string &name);
+3 -1
View File
@@ -225,7 +225,9 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
if (color)
glDisableClientState(GL_COLOR_ARRAY);
glPopMatrix(); glPopMatrix();
} }
@@ -452,23 +452,23 @@ int w_newShaderEffect(lua_State *L)
// call effectCodeToGLSL, returned values will be at the top of the stack // call effectCodeToGLSL, returned values will be at the top of the stack
lua_pcall(L, 2, 2, 0); lua_pcall(L, 2, 2, 0);
ShaderEffect::ShaderSources shadersources; ShaderEffect::ShaderSources sources;
// vertex shader code // vertex shader code
if (lua_isstring(L, -2)) if (lua_isstring(L, -2))
{ {
std::string vertcode(luaL_checkstring(L, -2)); std::string vertcode(luaL_checkstring(L, -2));
shadersources[ShaderEffect::TYPE_VERTEX] = vertcode; sources[ShaderEffect::TYPE_VERTEX] = vertcode;
} }
// fragment shader code // fragment shader code
if (lua_isstring(L, -1)) if (lua_isstring(L, -1))
{ {
std::string fragcode(luaL_checkstring(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); luax_newtype(L, "ShaderEffect", GRAPHICS_SHADEREFFECT_T, (void *)effect);
} }
catch(const love::Exception &e) catch(const love::Exception &e)