Fixed a couple potential memory leaks if love.graphics.newShader causes an error, and cleaned up some shader-related code.

This commit is contained in:
Alex Szpakowski
2014-09-27 02:26:58 -03:00
parent c6b610d116
commit b70f72acb3
5 changed files with 138 additions and 137 deletions
+18 -16
View File
@@ -49,11 +49,11 @@ public:
// Pointer to currently active Shader.
static Shader *current;
enum ShaderType
enum ShaderStage
{
TYPE_VERTEX,
TYPE_PIXEL,
TYPE_MAX_ENUM
STAGE_VERTEX,
STAGE_PIXEL,
STAGE_MAX_ENUM
};
// Built-in uniform (extern) variables.
@@ -74,14 +74,17 @@ public:
UNIFORM_MAX_ENUM
};
// Type for a list of shader source codes in the form of sources[shadertype] = code
typedef std::map<ShaderType, std::string> ShaderSources;
struct ShaderSource
{
std::string vertex;
std::string pixel;
};
/**
* Creates a new Shader using a list of source codes.
* Sources must contain either vertex or pixel shader code, or both.
* Source must contain either vertex or pixel shader code, or both.
**/
Shader(const ShaderSources &sources);
Shader(const ShaderSource &source);
virtual ~Shader();
@@ -196,8 +199,7 @@ private:
UniformType getUniformBaseType(GLenum type) const;
void checkSetUniformError(const Uniform &u, int size, int count, UniformType sendtype) const;
GLuint compileCode(ShaderType type, const std::string &code);
void createProgram(const std::vector<GLuint> &shaderids);
GLuint compileCode(ShaderStage stage, const std::string &code);
int getTextureUnit(const std::string &name);
@@ -206,11 +208,11 @@ private:
// Get any warnings or errors generated only by the shader program object.
std::string getProgramWarnings() const;
// List of all shader code attached to this Shader
ShaderSources shaderSources;
// Source code used for this Shader.
ShaderSource shaderSource;
// Shader compiler warning strings for individual shader stages.
std::map<ShaderType, std::string> shaderWarnings;
std::map<ShaderStage, std::string> shaderWarnings;
// volatile
GLuint program;
@@ -219,7 +221,7 @@ private:
GLint builtinUniforms[BUILTIN_MAX_ENUM];
// Location values for any generic vertex attribute variables.
GLint vertexAttributes[OpenGL::ATTRIB_MAX_ENUM];
GLint builtinAttributes[OpenGL::ATTRIB_MAX_ENUM];
// Uniform location buffer map
std::map<std::string, Uniform> uniforms;
@@ -241,8 +243,8 @@ private:
// 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;
static StringMap<ShaderStage, STAGE_MAX_ENUM>::Entry stageNameEntries[];
static StringMap<ShaderStage, STAGE_MAX_ENUM> stageNames;
static StringMap<UniformType, UNIFORM_MAX_ENUM>::Entry uniformTypeEntries[];
static StringMap<UniformType, UNIFORM_MAX_ENUM> uniformTypes;