From 02d2a872ab905c1626f11ab06d49d876b03847c9 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 29 Jan 2013 04:34:36 -0400 Subject: [PATCH] Improved shader member variable names, fixed up XCode project file --- .../macosx/love.xcodeproj/project.pbxproj | 22 +-- src/modules/graphics/opengl/Graphics.cpp | 4 +- src/modules/graphics/opengl/Graphics.h | 2 +- src/modules/graphics/opengl/Shader.cpp | 146 +++++++++--------- src/modules/graphics/opengl/Shader.h | 36 ++--- 5 files changed, 102 insertions(+), 108 deletions(-) diff --git a/platform/macosx/love.xcodeproj/project.pbxproj b/platform/macosx/love.xcodeproj/project.pbxproj index 83901c062..4c86f06b9 100644 --- a/platform/macosx/love.xcodeproj/project.pbxproj +++ b/platform/macosx/love.xcodeproj/project.pbxproj @@ -1713,7 +1713,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 0460; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "love" */; compatibilityVersion = "Xcode 3.2"; @@ -1966,9 +1966,9 @@ 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; @@ -1981,8 +1981,8 @@ 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"; @@ -2001,21 +2001,17 @@ 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; @@ -2029,14 +2025,15 @@ /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 = ( - "-W", "-Wall", + "-W", ); }; name = Debug; @@ -2051,21 +2048,17 @@ 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; @@ -2082,6 +2075,7 @@ ); 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 = ""; @@ -2089,8 +2083,8 @@ SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = YES; SDKROOT = macosx; WARNING_CFLAGS = ( - "-W", "-Wall", + "-W", ); }; name = Release; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index b7dfb4d11..68cb95668 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -453,12 +453,12 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::TextureType texture_t 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 &) { diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 19d7a1c72..f963a6840 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -270,7 +270,7 @@ public: 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. diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index 52c81af22..061c7295e 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -37,45 +37,45 @@ namespace 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 Shader::_texturecounters; +GLint Shader::maxTextureUnits = 0; +std::vector 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(); @@ -130,10 +130,10 @@ GLuint Shader::compileCode(ShaderType type, const std::string &code) 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); @@ -154,26 +154,26 @@ GLuint Shader::compileCode(ShaderType type, const std::string &code) void Shader::createProgram(const std::vector &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::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()); } @@ -182,13 +182,13 @@ void Shader::createProgram(const std::vector &shaderids) 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 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); @@ -213,45 +213,45 @@ void Shader::unloadVolatile() 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; @@ -259,10 +259,10 @@ void Shader::attach(bool temporary) { // 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); } @@ -351,11 +351,11 @@ void Shader::sendTexture(const std::string &name, GLuint texture) 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) @@ -370,11 +370,11 @@ void Shader::sendCanvas(const std::string &name, const Canvas &canvas) GLint Shader::getUniformLocation(const std::string &name) { - std::map::const_iterator it = _uniforms.find(name); - if (it != _uniforms.end()) + std::map::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( @@ -382,36 +382,36 @@ GLint Shader::getUniformLocation(const std::string &name) "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::const_iterator it = _textureunitpool.find(name); + std::map::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::iterator nextfreeunit = std::find(_texturecounters.begin(), _texturecounters.end(), 0); + std::vector::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::iterator nexttexunit = std::find(_activetextureunits.begin(), _activetextureunits.end(), 0); + std::vector::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; } @@ -431,8 +431,8 @@ void Shader::checkSetUniformError() 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 @@ -440,9 +440,9 @@ std::string Shader::getGLSLVersion() // 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() diff --git a/src/modules/graphics/opengl/Shader.h b/src/modules/graphics/opengl/Shader.h index 67120d12d..ddeb259e6 100644 --- a/src/modules/graphics/opengl/Shader.h +++ b/src/modules/graphics/opengl/Shader.h @@ -40,7 +40,7 @@ class Shader : public Object, public Volatile { public: - // pointer to currently active Shader. + // Pointer to currently active Shader. static Shader *current; enum ShaderType @@ -50,14 +50,14 @@ public: 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 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(); @@ -74,7 +74,7 @@ public: /** * 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(); @@ -125,7 +125,7 @@ private: GLint getUniformLocation(const std::string &name); void checkSetUniformError(); - + GLuint compileCode(ShaderType type, const std::string &code); void createProgram(const std::vector &shaderids); @@ -133,23 +133,23 @@ private: 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 _uniforms; + // Uniform location buffer map + std::map uniforms; - // texture unit pool for setting images - std::map _textureunitpool; // _textureunitpool[name] = textureunit - std::vector _activetextureunits; // _activetextureunits[textureunit-1] = textureid + // Texture unit pool for setting images + std::map textureUnitPool; // textureUnitPool[name] = textureunit + std::vector 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 _texturecounters; + // Counts total number of textures bound to each texture unit in all shaders + static std::vector textureCounters; }; } // opengl