Alex Szpakowski avatar Alex Szpakowski committed 9702590

More cleanup and some overdone comments

Comments (0)

Files changed (6)

src/modules/graphics/opengl/Graphics.cpp

 	{
 		effect = new ShaderEffect(shadersources);
 	}
-	catch(love::Exception &e)
+	catch(love::Exception &)
 	{
 		if (effect)
 			delete effect;
-		throw(e);
+		
+		throw;
 	}
 	return effect;
 }

src/modules/graphics/opengl/OpenGL.cpp

 	}
 	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;
 		

src/modules/graphics/opengl/OpenGL.h

 
 /**
  * Helper for setting the active texture unit
+ * 
  * @param textureunit The GL texture unit to set
  **/
 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
 /**
  * Helper for deleting an OpenGL texture.
  * Cleans up if the texture is currently bound.
+ * 
  * @param texture The texture to delete.
  **/
 void deleteTexture(GLuint texture);

src/modules/graphics/opengl/ShaderEffect.h

 {
 public:
 	
+	// Different types of shaders.
+	// Only vertex and fragment shaders have guaranteed support in all ShaderEffects.
 	enum ShaderType
 	{
 		TYPE_VERTEX,
 		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;
 
+	// 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:
 	
 	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;

src/scripts/graphics.lua

 #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 VertexTexCoord gl_MultiTexCoord0
+#define VertexPosition gl_Vertex
+
 #define VaryingColor gl_FrontColor
-#define VertexTexCoord gl_MultiTexCoord0
 #define VaryingTexCoord gl_TexCoord[0]
-#define VertexPosition gl_Vertex
 
 uniform sampler2D _tex0_;
 
 		FOOTER = [[
 void main() {
 	VaryingTexCoord = VertexTexCoord;
-	VaryingColor = VertexColor * ExternColor;
+	VaryingColor = VertexColor;
 	gl_Position = position(ModelViewProjectionMatrix, VertexPosition);
 }]],
 	}
 #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]
 

src/scripts/graphics.lua.h

 	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,
 	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, 
 	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, 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.