mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
More cleanup and some overdone comments
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1295,22 +1295,24 @@ do
|
||||
#define Texel texture2D
|
||||
|
||||
#define ModelViewMatrix gl_ModelViewMatrix
|
||||
#define ProjectionMatrix gl_ProjectionMatrix
|
||||
#define ModelViewProjectionMatrix gl_ModelViewProjectionMatrix
|
||||
#define NormalMatrix gl_NormalMatrix
|
||||
#define ExternColor vec4(1.0)
|
||||
|
||||
#define VertexColor gl_Color
|
||||
#define VaryingColor gl_FrontColor
|
||||
#define VertexTexCoord gl_MultiTexCoord0
|
||||
#define VaryingTexCoord gl_TexCoord[0]
|
||||
#define VertexPosition gl_Vertex
|
||||
|
||||
#define VaryingColor gl_FrontColor
|
||||
#define VaryingTexCoord gl_TexCoord[0]
|
||||
|
||||
uniform sampler2D _tex0_;
|
||||
|
||||
#line 0]],
|
||||
FOOTER = [[
|
||||
void main() {
|
||||
VaryingTexCoord = VertexTexCoord;
|
||||
VaryingColor = VertexColor * ExternColor;
|
||||
VaryingColor = VertexColor;
|
||||
gl_Position = position(ModelViewProjectionMatrix, VertexPosition);
|
||||
}]],
|
||||
}
|
||||
@@ -1325,9 +1327,10 @@ void main() {
|
||||
#define Texel texture2D
|
||||
|
||||
#define ModelViewMatrix gl_ModelViewMatrix
|
||||
#define ProjectionMatrix gl_ProjectionMatrix
|
||||
#define ModelViewProjectionMatrix gl_ModelViewProjectionMatrix
|
||||
#define NormalMatrix gl_NormalMatrix
|
||||
#define ExternColor vec4(1.0)
|
||||
|
||||
#define VaryingColor gl_Color
|
||||
#define VaryingTexCoord gl_TexCoord[0]
|
||||
|
||||
|
||||
+11
-10
@@ -6278,26 +6278,27 @@ const unsigned char graphics_lua[] =
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x4d,
|
||||
0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x67, 0x6c, 0x5f, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77,
|
||||
0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50,
|
||||
0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x67, 0x6c,
|
||||
0x5f, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x4e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x4d, 0x61, 0x74, 0x72,
|
||||
0x69, 0x78, 0x20, 0x67, 0x6c, 0x5f, 0x4e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x43, 0x6f, 0x6c, 0x6f,
|
||||
0x72, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x31, 0x2e, 0x30, 0x29, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f,
|
||||
0x72, 0x20, 0x67, 0x6c, 0x5f, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6c,
|
||||
0x6f, 0x72, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x54, 0x65, 0x78, 0x43,
|
||||
0x6f, 0x6f, 0x72, 0x64, 0x20, 0x67, 0x6c, 0x5f, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x54, 0x65, 0x78, 0x43, 0x6f,
|
||||
0x6f, 0x72, 0x64, 0x30, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x50, 0x6f, 0x73, 0x69,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x6c, 0x5f, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6c,
|
||||
0x6f, 0x72, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x54, 0x65, 0x78,
|
||||
0x43, 0x6f, 0x6f, 0x72, 0x64, 0x20, 0x67, 0x6c, 0x5f, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x5b,
|
||||
0x30, 0x5d, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x50, 0x6f, 0x73, 0x69,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x6c, 0x5f, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x0a,
|
||||
0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20,
|
||||
0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x3b, 0x0a,
|
||||
0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x30, 0x5d, 0x5d, 0x2c, 0x0a,
|
||||
@@ -6306,8 +6307,7 @@ const unsigned char graphics_lua[] =
|
||||
0x09, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x20, 0x3d,
|
||||
0x20, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x3b, 0x0a,
|
||||
0x09, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x56, 0x65,
|
||||
0x72, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x2a, 0x20, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e,
|
||||
0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a,
|
||||
0x72, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a,
|
||||
0x09, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x70, 0x6f, 0x73,
|
||||
0x69, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f,
|
||||
0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x2c, 0x20, 0x56, 0x65, 0x72,
|
||||
@@ -6330,14 +6330,15 @@ const unsigned char graphics_lua[] =
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x4d,
|
||||
0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x67, 0x6c, 0x5f, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77,
|
||||
0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50,
|
||||
0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x67, 0x6c,
|
||||
0x5f, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x4e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x4d, 0x61, 0x74, 0x72,
|
||||
0x69, 0x78, 0x20, 0x67, 0x6c, 0x5f, 0x4e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x78, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x43, 0x6f, 0x6c, 0x6f,
|
||||
0x72, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x31, 0x2e, 0x30, 0x29, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6c,
|
||||
0x6f, 0x72, 0x20, 0x67, 0x6c, 0x5f, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x0a,
|
||||
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x54, 0x65, 0x78,
|
||||
|
||||
Reference in New Issue
Block a user