Commits

Alex Szpakowski committed 61021c7

Improved shader member variable names, fixed up XCode project file

  • Participants
  • Parent commits d185baf

Comments (0)

Files changed (5)

File platform/macosx/love.xcodeproj/project.pbxproj

 		29B97313FDCFA39411CA2CEA /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
-				LastUpgradeCheck = 0430;
+				LastUpgradeCheck = 0460;
 			};
 			buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "love" */;
 			compatibilityVersion = "Xcode 3.2";
 		C01FCF4B08A954540054247B /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				COMBINE_HIDPI_IMAGES = YES;
 				COPY_PHASE_STRIP = NO;
 				GCC_DYNAMIC_NO_PIC = NO;
-				GCC_MODEL_TUNING = G5;
 				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = love_Prefix.pch;
 		C01FCF4C08A954540054247B /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				COMBINE_HIDPI_IMAGES = YES;
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
-				GCC_MODEL_TUNING = G5;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = love_Prefix.pch;
 				INSTALL_PATH = "$(HOME)/Applications";
 				GCC_INCREASE_PRECOMPILED_HEADER_SHARING = YES;
 				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = NO;
-				GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = NO;
-				GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
 				GCC_WARN_ABOUT_MISSING_NEWLINE = NO;
 				GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
 				GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES;
 				GCC_WARN_ABOUT_RETURN_TYPE = NO;
-				GCC_WARN_CHECK_SWITCH_STATEMENTS = NO;
-				GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = NO;
+				GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
 				GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
 				GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = NO;
 				GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = NO;
 				GCC_WARN_MISSING_PARENTHESES = NO;
 				GCC_WARN_NON_VIRTUAL_DESTRUCTOR = NO;
 				GCC_WARN_PEDANTIC = NO;
-				GCC_WARN_PROTOTYPE_CONVERSION = NO;
 				GCC_WARN_SHADOW = NO;
 				GCC_WARN_SIGN_COMPARE = YES;
 				GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = NO;
 					/Library/Frameworks/SDL.framework/Headers,
 				);
 				INFOPLIST_FILE = "love-Info.plist";
+				LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
 				MACOSX_DEPLOYMENT_TARGET = 10.5;
 				ONLY_ACTIVE_ARCH = YES;
 				OTHER_LDFLAGS = "";
 				PRODUCT_NAME = love;
 				SDKROOT = macosx;
 				WARNING_CFLAGS = (
+					"-Wall",
 					"-W",
-					"-Wall",
 				);
 			};
 			name = Debug;
 				GCC_C_LANGUAGE_STANDARD = c99;
 				GCC_INPUT_FILETYPE = automatic;
 				GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = NO;
-				GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = NO;
-				GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
 				GCC_WARN_ABOUT_MISSING_NEWLINE = NO;
 				GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
 				GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES;
 				GCC_WARN_ABOUT_RETURN_TYPE = NO;
 				GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
-				GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = NO;
 				GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
 				GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = NO;
 				GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = NO;
 				GCC_WARN_MISSING_PARENTHESES = NO;
 				GCC_WARN_NON_VIRTUAL_DESTRUCTOR = NO;
 				GCC_WARN_PEDANTIC = NO;
-				GCC_WARN_PROTOTYPE_CONVERSION = NO;
 				GCC_WARN_SHADOW = NO;
 				GCC_WARN_SIGN_COMPARE = YES;
 				GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = NO;
 				);
 				INFOPLIST_FILE = "love-Info.plist";
 				LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
+				LLVM_LTO = YES;
 				MACOSX_DEPLOYMENT_TARGET = 10.5;
 				ONLY_ACTIVE_ARCH = NO;
 				OTHER_LDFLAGS = "";
 				SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = YES;
 				SDKROOT = macosx;
 				WARNING_CFLAGS = (
+					"-Wall",
 					"-W",
-					"-Wall",
 				);
 			};
 			name = Release;

File src/modules/graphics/opengl/Graphics.cpp

 	return NULL; // never reached
 }
 
-Shader *Graphics::newShader(const Shader::ShaderSources &shadersources)
+Shader *Graphics::newShader(const Shader::ShaderSources &sources)
 {
 	Shader *shader = NULL;
 	try
 	{
-		shader = new Shader(shadersources);
+		shader = new Shader(sources);
 	}
 	catch(love::Exception &)
 	{

File src/modules/graphics/opengl/Graphics.h

 
 	Canvas *newCanvas(int width, int height, Canvas::TextureType texture_type = Canvas::TYPE_NORMAL);
 
-	Shader *newShader(const Shader::ShaderSources &shadersources);
+	Shader *newShader(const Shader::ShaderSources &sources);
 
 	/**
 	 * Sets the foreground color.

File src/modules/graphics/opengl/Shader.cpp

 	struct TemporaryAttacher
 	{
 		TemporaryAttacher(Shader *shader)
-		: curshader(shader)
-		, prevshader(Shader::current)
+		: curShader(shader)
+		, prevShader(Shader::current)
 		{
-			curshader->attach(true);
+			curShader->attach(true);
 		}
 
 		~TemporaryAttacher()
 		{
-			if (prevshader != NULL)
-				prevshader->attach();
+			if (prevShader != NULL)
+				prevShader->attach();
 			else
 				Shader::detach();
 		}
 
-		Shader *curshader;
-		Shader *prevshader;
+		Shader *curShader;
+		Shader *prevShader;
 	};
 } // anonymous namespace
 
 
 Shader *Shader::current = NULL;
 
-GLint Shader::_maxtextureunits = 0;
-std::vector<int> Shader::_texturecounters;
+GLint Shader::maxTextureUnits = 0;
+std::vector<int> Shader::textureCounters;
 
-Shader::Shader(const ShaderSources &shadersources)
-	: _shadersources(shadersources)
-	, _program(0)
+Shader::Shader(const ShaderSources &sources)
+	: shaderSources(sources)
+	, program(0)
 {
-	if (shadersources.empty())
+	if (shaderSources.empty())
 		throw love::Exception("Cannot create shader: no source code!");
 
-	GLint maxtextureunits;
-	glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtextureunits);
-	_maxtextureunits = std::max(maxtextureunits - 1, 0);
+	GLint maxtexunits;
+	glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits);
+	maxTextureUnits = std::max(maxtexunits - 1, 0);
 
 	// initialize global texture id counters if needed
-	if (_texturecounters.size() < (size_t) _maxtextureunits)
-		_texturecounters.resize(_maxtextureunits, 0);
+	if (textureCounters.size() < (size_t) maxTextureUnits)
+		textureCounters.resize(maxTextureUnits, 0);
 
 	// load shader source and create program object
 	loadVolatile();
 
 	glCompileShader(shaderid);
 
-	GLint compile_status;
-	glGetShaderiv(shaderid, GL_COMPILE_STATUS, &compile_status);
+	GLint status;
+	glGetShaderiv(shaderid, GL_COMPILE_STATUS, &status);
 
-	if (compile_status == GL_FALSE)
+	if (status == GL_FALSE)
 	{
 		GLint infologlen;
 		glGetShaderiv(shaderid, GL_INFO_LOG_LENGTH, &infologlen);
 
 void Shader::createProgram(const std::vector<GLuint> &shaderids)
 {
-	_program = glCreateProgram();
-	if (_program == 0) // should only fail when called between glBegin() and glEnd()
+	program = glCreateProgram();
+	if (program == 0) // should only fail when called between glBegin() and glEnd()
 		throw love::Exception("Cannot create shader program object.");
 
 	std::vector<GLuint>::const_iterator it;
 	for (it = shaderids.begin(); it != shaderids.end(); ++it)
-		glAttachShader(_program, *it);
+		glAttachShader(program, *it);
 
-	glLinkProgram(_program);
+	glLinkProgram(program);
 
 	for (it = shaderids.begin(); it != shaderids.end(); ++it)
 		glDeleteShader(*it); // flag shaders for auto-deletion when program object is deleted
 
-	GLint link_ok;
-	glGetProgramiv(_program, GL_LINK_STATUS, &link_ok);
+	GLint status;
+	glGetProgramiv(program, GL_LINK_STATUS, &status);
 
-	if (link_ok == GL_FALSE)
+	if (status == GL_FALSE)
 	{
 		const std::string warnings = getWarnings();
-		glDeleteProgram(_program);
+		glDeleteProgram(program);
 
 		throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
 	}
 bool Shader::loadVolatile()
 {
 	// zero out active texture list
-	_activetextureunits.clear();
-	_activetextureunits.insert(_activetextureunits.begin(), _maxtextureunits, 0);
+	activeTextureUnits.clear();
+	activeTextureUnits.insert(activeTextureUnits.begin(), maxTextureUnits, 0);
 
 	std::vector<GLuint> shaderids;
 
 	ShaderSources::const_iterator source;
-	for (source = _shadersources.begin(); source != _shadersources.end(); ++source)
+	for (source = shaderSources.begin(); source != shaderSources.end(); ++source)
 	{
 		GLuint shaderid = compileCode(source->first, source->second);
 		shaderids.push_back(shaderid);
 	if (current == this)
 		glUseProgram(0);
 
-	if (_program != 0)
-		glDeleteProgram(_program);
+	if (program != 0)
+		glDeleteProgram(program);
 
-	_program = 0;
+	program = 0;
 
 	// decrement global texture id counters for texture units which had textures bound from this shader
-	for (size_t i = 0; i < _activetextureunits.size(); ++i)
+	for (size_t i = 0; i < activeTextureUnits.size(); ++i)
 	{
-		if (_activetextureunits[i] > 0)
-			_texturecounters[i] = std::max(_texturecounters[i] - 1, 0);
+		if (activeTextureUnits[i] > 0)
+			textureCounters[i] = std::max(textureCounters[i] - 1, 0);
 	}
 
 	// active texture list is probably invalid, clear it
-	_activetextureunits.clear();
-	_activetextureunits.insert(_activetextureunits.begin(), _maxtextureunits, 0);
+	activeTextureUnits.clear();
+	activeTextureUnits.insert(activeTextureUnits.begin(), maxTextureUnits, 0);
 
 	// same with uniform location list
-	_uniforms.clear();
+	uniforms.clear();
 }
 
 std::string Shader::getWarnings() const
 {
 	GLint strlen, nullpos;
-	glGetProgramiv(_program, GL_INFO_LOG_LENGTH, &strlen);
-	char *temp_str = new char[strlen+1];
+	glGetProgramiv(program, GL_INFO_LOG_LENGTH, &strlen);
+	char *tempstr = new char[strlen+1];
 	// be extra sure that the error string will be 0-terminated
-	memset(temp_str, '\0', strlen+1);
-	glGetProgramInfoLog(_program, strlen, &nullpos, temp_str);
-	temp_str[nullpos] = '\0';
+	memset(tempstr, '\0', strlen+1);
+	glGetProgramInfoLog(program, strlen, &nullpos, tempstr);
+	tempstr[nullpos] = '\0';
 
-	std::string warnings(temp_str);
-	delete[] temp_str;
+	std::string warnings(tempstr);
+	delete[] tempstr;
 	return warnings;
 }
 
 void Shader::attach(bool temporary)
 {
 	if (current != this)
-		glUseProgram(_program);
+		glUseProgram(program);
 
 	current = this;
 
 	{
 		// make sure all sent textures are properly bound to their respective texture units
 		// note: list potentially contains texture ids of deleted/invalid textures!
-		for (size_t i = 0; i < _activetextureunits.size(); ++i)
+		for (size_t i = 0; i < activeTextureUnits.size(); ++i)
 		{
-			if (_activetextureunits[i] > 0)
-				bindTextureToUnit(_activetextureunits[i], i + 1, false);
+			if (activeTextureUnits[i] > 0)
+				bindTextureToUnit(activeTextureUnits[i], i + 1, false);
 		}
 		setActiveTextureUnit(0);
 	}
 	checkSetUniformError();
 
 	// increment global shader texture id counter for this texture unit, if we haven't already
-	if (_activetextureunits[textureunit-1] == 0)
-		++_texturecounters[textureunit-1];
+	if (activeTextureUnits[textureunit-1] == 0)
+		++textureCounters[textureunit-1];
 
 	// store texture id so it can be re-bound to the proper texture unit when necessary
-	_activetextureunits[textureunit-1] = texture;
+	activeTextureUnits[textureunit-1] = texture;
 }
 
 void Shader::sendImage(const std::string &name, const Image &image)
 
 GLint Shader::getUniformLocation(const std::string &name)
 {
-	std::map<std::string, GLint>::const_iterator it = _uniforms.find(name);
-	if (it != _uniforms.end())
+	std::map<std::string, GLint>::const_iterator it = uniforms.find(name);
+	if (it != uniforms.end())
 		return it->second;
 
-	GLint location = glGetUniformLocation(_program, name.c_str());
+	GLint location = glGetUniformLocation(program, name.c_str());
 	if (location == -1)
 	{
 		throw love::Exception(
 			"A common error is to define but not use the variable.", name.c_str());
 	}
 
-	_uniforms[name] = location;
+	uniforms[name] = location;
 	return location;
 }
 
 int Shader::getTextureUnit(const std::string &name)
 {
-	std::map<std::string, GLint>::const_iterator it = _textureunitpool.find(name);
+	std::map<std::string, GLint>::const_iterator it = textureUnitPool.find(name);
 
-	if (it != _textureunitpool.end())
+	if (it != textureUnitPool.end())
 		return it->second;
 
 	int textureunit = 1;
 
 	// prefer texture units which are unused by all other shaders
-	std::vector<int>::iterator nextfreeunit = std::find(_texturecounters.begin(), _texturecounters.end(), 0);
+	std::vector<int>::iterator nextfreeunit = std::find(textureCounters.begin(), textureCounters.end(), 0);
 
-	if (nextfreeunit != _texturecounters.end())
-		textureunit = std::distance(_texturecounters.begin(), nextfreeunit) + 1; // we don't want to use unit 0
+	if (nextfreeunit != textureCounters.end())
+		textureunit = std::distance(textureCounters.begin(), nextfreeunit) + 1; // we don't want to use unit 0
 	else
 	{
 		// no completely unused texture units exist, try to use next free slot in our own list
-		std::vector<GLuint>::iterator nexttexunit = std::find(_activetextureunits.begin(), _activetextureunits.end(), 0);
+		std::vector<GLuint>::iterator nexttexunit = std::find(activeTextureUnits.begin(), activeTextureUnits.end(), 0);
 
-		if (nexttexunit == _activetextureunits.end())
+		if (nexttexunit == activeTextureUnits.end())
 			throw love::Exception("No more texture units available for shader.");
 
-		textureunit = std::distance(_activetextureunits.begin(), nexttexunit) + 1; // we don't want to use unit 0
+		textureunit = std::distance(activeTextureUnits.begin(), nexttexunit) + 1; // we don't want to use unit 0
 	}
 
-	_textureunitpool[name] = textureunit;
+	textureUnitPool[name] = textureunit;
 	return textureunit;
 }
 
 std::string Shader::getGLSLVersion()
 {
 	// GL_SHADING_LANGUAGE_VERSION may not be available in OpenGL < 2.0.
-	const char *tmp = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
-	if (NULL == tmp)
+	const char *tmp = (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
+	if (tmp == NULL)
 		return "0.0";
 
 	// the version string always begins with a version number of the format
 	// or
 	//   major_number.minor_number.release_number
 	// we can keep release_number, since it does not affect the check below.
-	std::string versionString(tmp);
-	size_t minorEndPos = versionString.find(' ');
-	return versionString.substr(0, minorEndPos);
+	std::string versionstring(tmp);
+	size_t minorendpos = versionstring.find(' ');
+	return versionstring.substr(0, minorendpos);
 }
 
 bool Shader::isSupported()

File src/modules/graphics/opengl/Shader.h

 {
 public:
 
-	// pointer to currently active Shader.
+	// Pointer to currently active Shader.
 	static Shader *current;
 
 	enum ShaderType
 		TYPE_MAX_ENUM
 	};
 
-	// type for a list of shader source codes in the form of sources[shadertype] = code
+	// Type for a list of shader source codes in the form of sources[shadertype] = code
 	typedef std::map<ShaderType, std::string> ShaderSources;
 
 	/**
 	 * Creates a new Shader using a list of source codes.
-	 * Sources must contain at least one vertex or fragment shader.
+	 * Sources must contain either vertex or fragment shader code, or both.
 	 **/
-	Shader(const ShaderSources &shadersources);
+	Shader(const ShaderSources &sources);
 
 	virtual ~Shader();
 
 
 	/**
 	 * Detach the currently bound Shader.
-	 * Causes OpenGL to use fixed functionality in place of shader programs.
+	 * Causes the GPU rendering pipeline to use fixed functionality in place of shader programs.
 	 **/
 	static void detach();
 
 
 	GLint getUniformLocation(const std::string &name);
 	void checkSetUniformError();
-	
+
 	GLuint compileCode(ShaderType type, const std::string &code);
 	void createProgram(const std::vector<GLuint> &shaderids);
 
 
 	void sendTexture(const std::string &name, GLuint texture);
 
-	// list of all shader code attached to this Shader
-	ShaderSources _shadersources;
+	// List of all shader code attached to this Shader
+	ShaderSources shaderSources;
 
-	GLuint _program; // volatile
+	GLuint program; // volatile
 
-	// uniform location buffer map
-	std::map<std::string, GLint> _uniforms;
+	// Uniform location buffer map
+	std::map<std::string, GLint> uniforms;
 
-	// texture unit pool for setting images
-	std::map<std::string, GLint> _textureunitpool; // _textureunitpool[name] = textureunit
-	std::vector<GLuint> _activetextureunits; // _activetextureunits[textureunit-1] = textureid
+	// Texture unit pool for setting images
+	std::map<std::string, GLint> textureUnitPool; // textureUnitPool[name] = textureunit
+	std::vector<GLuint> activeTextureUnits; // activeTextureUnits[textureunit-1] = textureid
 
-	// max GPU texture units available for sent images
-	static GLint _maxtextureunits;
+	// Max GPU texture units available for sent images
+	static GLint maxTextureUnits;
 
-	// counts total number of textures bound to each texture unit in all shaders
-	static std::vector<int> _texturecounters;
+	// Counts total number of textures bound to each texture unit in all shaders
+	static std::vector<int> textureCounters;
 };
 
 } // opengl