Mercurial > love-experiments
changeset 1428:166144e3be18
Cleaned up some shader code internals
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Sat, 06 Apr 2013 14:14:11 -0300 |
| parents | 52ac0fb86a8b |
| children | cf1abdb916af ab2ad66523aa |
| files | src/modules/graphics/opengl/Shader.cpp src/modules/graphics/opengl/Shader.h |
| diffstat | 2 files changed, 31 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/modules/graphics/opengl/Shader.cpp Sat Apr 06 14:02:24 2013 -0300 +++ b/src/modules/graphics/opengl/Shader.cpp Sat Apr 06 14:14:11 2013 -0300 @@ -97,17 +97,18 @@ GLuint Shader::compileCode(ShaderType type, const std::string &code) { GLenum glshadertype; - const char *shadertypestr = NULL; + const char *typestr; + + if (!typeNames.find(type, typestr)) + typestr = ""; switch (type) { case TYPE_VERTEX: glshadertype = GL_VERTEX_SHADER; - shadertypestr = "vertex"; break; case TYPE_PIXEL: glshadertype = GL_FRAGMENT_SHADER; - shadertypestr = "pixel"; break; default: throw love::Exception("Cannot create shader object: unknown shader type."); @@ -124,9 +125,9 @@ GLenum err = glGetError(); if (err == GL_INVALID_ENUM) // invalid or unsupported shader type - throw love::Exception("Cannot create %s shader object: %s shaders not supported.", shadertypestr, shadertypestr); + throw love::Exception("Cannot create %s shader object: %s shaders not supported.", typestr, typestr); else // other errors should only happen between glBegin() and glEnd() - throw love::Exception("Cannot create %s shader object.", shadertypestr); + throw love::Exception("Cannot create %s shader object.", typestr); } const char *src = code.c_str(); @@ -144,7 +145,7 @@ // Save any warnings for later querying if (infologlen > 0) - shaderWarnings[type] = shadertypestr + std::string(" shader:\n") + infolog; + shaderWarnings[type] = infolog; delete[] infolog; @@ -154,7 +155,7 @@ if (status == GL_FALSE) { throw love::Exception("Cannot compile %s shader code:\n%s", - shadertypestr, shaderWarnings[type].c_str()); + typestr, shaderWarnings[type].c_str()); } return shaderid; @@ -263,11 +264,15 @@ std::string Shader::getWarnings() const { std::string warnings; + const char *typestr; // Get the individual shader stage warnings std::map<ShaderType, std::string>::const_iterator it; for (it = shaderWarnings.begin(); it != shaderWarnings.end(); ++it) - warnings += it->second; + { + if (typeNames.find(it->first, typestr)) + warnings += std::string(typestr) + std::string(" shader:\n") + it->second; + } warnings += getProgramWarnings(); @@ -476,6 +481,14 @@ return GLEE_VERSION_2_0 && getGLSLVersion() >= "1.2"; } +StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM>::Entry Shader::typeNameEntries[] = +{ + {"vertex", Shader::TYPE_VERTEX}, + {"pixel", Shader::TYPE_PIXEL}, +}; + +StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM> Shader::typeNames(Shader::typeNameEntries, sizeof(Shader::typeNameEntries)); + } // opengl } // graphics } // love
--- a/src/modules/graphics/opengl/Shader.h Sat Apr 06 14:02:24 2013 -0300 +++ b/src/modules/graphics/opengl/Shader.h Sat Apr 06 14:14:11 2013 -0300 @@ -21,13 +21,17 @@ #ifndef LOVE_GRAPHICS_SHADER_H #define LOVE_GRAPHICS_SHADER_H +// LOVE #include "common/Object.h" +#include "common/StringMap.h" +#include "OpenGL.h" +#include "Image.h" +#include "Canvas.h" + +// STL #include <string> #include <map> #include <vector> -#include "OpenGL.h" -#include "Image.h" -#include "Canvas.h" namespace love { @@ -156,6 +160,9 @@ // Counts total number of textures bound to each texture unit in all shaders static std::vector<int> textureCounters; + + static StringMap<ShaderType, TYPE_MAX_ENUM>::Entry typeNameEntries[]; + static StringMap<ShaderType, TYPE_MAX_ENUM> typeNames; }; } // opengl
