More cleanup and some overdone comments

This commit is contained in:
Alexander Szpakowski
2013-01-05 15:59:01 -04:00
parent 37191a5953
commit 0968fa6f11
6 changed files with 104 additions and 28 deletions
+3 -2
View File
@@ -460,11 +460,12 @@ ShaderEffect *Graphics::newShaderEffect(const std::vector<ShaderEffect::ShaderSo
{
effect = new ShaderEffect(shadersources);
}
catch(love::Exception &e)
catch(love::Exception &)
{
if (effect)
delete effect;
throw(e);
throw;
}
return effect;
}
+1 -1
View File
@@ -83,7 +83,7 @@ void initializeContext()
}
else
{
// multitexturing not supported so we only have 1 texture unit
// multitexturing not supported, so we only have 1 texture unit
textureUnits.resize(1, 0);
curTextureUnitIndex = 0;
+4
View File
@@ -36,6 +36,7 @@ void uninitializeContext();
/**
* Helper for setting the active texture unit
*
* @param textureunit The GL texture unit to set
**/
void setActiveTextureUnit(GLenum textureunit);
@@ -43,12 +44,14 @@ void setActiveTextureUnit(GLenum textureunit);
/**
* Helper for binding an OpenGL texture.
* Makes sure we aren't redundantly binding textures.
*
* @param texture The texture to bind.
**/
void bindTexture(GLuint texture);
/**
* Helper for binding a texture to a specific texture unit
*
* @param texture The texture to bind
* @param textureunit The texture unit to switch to
* @param resoreprev Restore previous texture unit when done
@@ -58,6 +61,7 @@ void bindTextureToUnit(GLuint texture, GLenum textureunit, bool restoreprev);
/**
* Helper for deleting an OpenGL texture.
* Cleans up if the texture is currently bound.
*
* @param texture The texture to delete.
**/
void deleteTexture(GLuint texture);
+77 -10
View File
@@ -40,6 +40,8 @@ class ShaderEffect : public Object, public Volatile
{
public:
// Different types of shaders.
// Only vertex and fragment shaders have guaranteed support in all ShaderEffects.
enum ShaderType
{
TYPE_VERTEX,
@@ -50,33 +52,94 @@ public:
TYPE_MAX_ENUM
};
// thin wrapper for GLSL source code
// thin wrapper for GLSL source code.
struct ShaderSource
{
std::string code;
ShaderType type;
};
/**
* Creates a new ShaderEffect using a list of source codes.
* Must contain at least one vertex or fragment shader source.
*
* @param shadersources Vector of shader source codes.
**/
ShaderEffect(const std::vector<ShaderSource> &shadersources);
virtual ~ShaderEffect();
std::string getWarnings() const;
virtual ~ShaderEffect();
// Implements Volatile
virtual bool loadVolatile();
virtual void unloadVolatile();
/**
* Binds this ShaderEffect's program to be used when rendering.
*
* @param temporary True if we just want to send values to the shader with no intention of rendering.
**/
void attach(bool temporary = false);
/**
* Detach the currently bound ShaderEffect.
* Causes OpenGL to use fixed functionality in place of shader programs.
**/
static void detach();
/**
* Returns any warnings this ShaderEffect may have generated.
**/
std::string getWarnings() const;
/**
* Returns the maximum GLSL version supported on this system.
**/
static std::string getGLSLVersion();
/**
* Returns whether ShaderEffects are supported on this system.
**/
static bool isSupported();
static ShaderEffect *current; // pointer to currently active ShaderEffect
/**
* Send at least one float or vector value to this ShaderEffect as a uniform.
*
* @param name The name of the uniform variable in the source code.
* @param size Number of elements in each vector to send.
* A value of 1 indicates a single-component vector, AKA a float.
* @param vec Pointer to the float or vector values.
* @param count Number of float or vector values.
**/
void sendFloat(const std::string &name, int size, const GLfloat *vec, int count);
/**
* Send at least one matrix to this ShaderEffect as a uniform.
*
* @param name The name of the uniform variable in the source code.
* @param size Number of rows/columns in the matrix.
* @param m Pointer to the first element of the first matrix.
* @param count Number of matrices to send.
**/
void sendMatrix(const std::string &name, int size, const GLfloat *m, int count);
/**
* Send an image to this ShaderEffect as a uniform.
*
* @param name The name of the uniform variable in the source code.
* @param image The image to send.
**/
void sendImage(const std::string &name, const Image &image);
/**
* Send a canvas to this ShaderEffect as a uniform.
*
* @param name The name of the uniform variable in the source code.
* @param canvas The canvas to send.
**/
void sendCanvas(const std::string &name, const Canvas &canvas);
// pointer to currently active ShaderEffect.
static ShaderEffect *current;
private:
@@ -85,15 +148,19 @@ private:
GLuint createShader(const ShaderSource &source);
void createProgram(const std::vector<GLuint> &shaderids);
std::vector<ShaderSource> _shadersources; // all shader code attached to this ShaderEffect
// list of all shader code attached to this ShaderEffect
std::vector<ShaderSource> _shadersources;
GLuint _program; // volatile
// uniform location buffer
// uniform location buffer map
std::map<std::string, GLint> _uniforms;
static GLint _max_texture_units; // total max GPU texture units for shaders
static std::vector<int> _texture_id_counters; // counts total number of textures bound to each texture unit in all shaders
// total max GPU texture units for shaders
static GLint _max_texture_units;
// counts total number of textures bound to each texture unit in all shaders
static std::vector<int> _texture_id_counters;
// texture unit pool for setting images
std::map<std::string, GLint> _texture_unit_pool;