mirror of
https://github.com/love2d/love.git
synced 2026-08-21 05:00:08 +02:00
Improved shader member variable names, fixed up XCode project file
This commit is contained in:
@@ -1713,7 +1713,7 @@
|
|||||||
29B97313FDCFA39411CA2CEA /* Project object */ = {
|
29B97313FDCFA39411CA2CEA /* Project object */ = {
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastUpgradeCheck = 0430;
|
LastUpgradeCheck = 0460;
|
||||||
};
|
};
|
||||||
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "love" */;
|
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "love" */;
|
||||||
compatibilityVersion = "Xcode 3.2";
|
compatibilityVersion = "Xcode 3.2";
|
||||||
@@ -1966,9 +1966,9 @@
|
|||||||
C01FCF4B08A954540054247B /* Debug */ = {
|
C01FCF4B08A954540054247B /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
GCC_DYNAMIC_NO_PIC = NO;
|
GCC_DYNAMIC_NO_PIC = NO;
|
||||||
GCC_MODEL_TUNING = G5;
|
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||||
GCC_PREFIX_HEADER = love_Prefix.pch;
|
GCC_PREFIX_HEADER = love_Prefix.pch;
|
||||||
@@ -1981,8 +1981,8 @@
|
|||||||
C01FCF4C08A954540054247B /* Release */ = {
|
C01FCF4C08A954540054247B /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
GCC_MODEL_TUNING = G5;
|
|
||||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||||
GCC_PREFIX_HEADER = love_Prefix.pch;
|
GCC_PREFIX_HEADER = love_Prefix.pch;
|
||||||
INSTALL_PATH = "$(HOME)/Applications";
|
INSTALL_PATH = "$(HOME)/Applications";
|
||||||
@@ -2001,21 +2001,17 @@
|
|||||||
GCC_INCREASE_PRECOMPILED_HEADER_SHARING = YES;
|
GCC_INCREASE_PRECOMPILED_HEADER_SHARING = YES;
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = NO;
|
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_NEWLINE = NO;
|
||||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
|
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
|
||||||
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES;
|
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES;
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = NO;
|
GCC_WARN_ABOUT_RETURN_TYPE = NO;
|
||||||
GCC_WARN_CHECK_SWITCH_STATEMENTS = NO;
|
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
|
||||||
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = NO;
|
|
||||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
|
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
|
||||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = NO;
|
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = NO;
|
||||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = NO;
|
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = NO;
|
||||||
GCC_WARN_MISSING_PARENTHESES = NO;
|
GCC_WARN_MISSING_PARENTHESES = NO;
|
||||||
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = NO;
|
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = NO;
|
||||||
GCC_WARN_PEDANTIC = NO;
|
GCC_WARN_PEDANTIC = NO;
|
||||||
GCC_WARN_PROTOTYPE_CONVERSION = NO;
|
|
||||||
GCC_WARN_SHADOW = NO;
|
GCC_WARN_SHADOW = NO;
|
||||||
GCC_WARN_SIGN_COMPARE = YES;
|
GCC_WARN_SIGN_COMPARE = YES;
|
||||||
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = NO;
|
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = NO;
|
||||||
@@ -2029,14 +2025,15 @@
|
|||||||
/Library/Frameworks/SDL.framework/Headers,
|
/Library/Frameworks/SDL.framework/Headers,
|
||||||
);
|
);
|
||||||
INFOPLIST_FILE = "love-Info.plist";
|
INFOPLIST_FILE = "love-Info.plist";
|
||||||
|
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.5;
|
MACOSX_DEPLOYMENT_TARGET = 10.5;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
OTHER_LDFLAGS = "";
|
OTHER_LDFLAGS = "";
|
||||||
PRODUCT_NAME = love;
|
PRODUCT_NAME = love;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
WARNING_CFLAGS = (
|
WARNING_CFLAGS = (
|
||||||
"-W",
|
|
||||||
"-Wall",
|
"-Wall",
|
||||||
|
"-W",
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
@@ -2051,21 +2048,17 @@
|
|||||||
GCC_C_LANGUAGE_STANDARD = c99;
|
GCC_C_LANGUAGE_STANDARD = c99;
|
||||||
GCC_INPUT_FILETYPE = automatic;
|
GCC_INPUT_FILETYPE = automatic;
|
||||||
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = NO;
|
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_NEWLINE = NO;
|
||||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
|
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
|
||||||
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES;
|
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES;
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = NO;
|
GCC_WARN_ABOUT_RETURN_TYPE = NO;
|
||||||
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
|
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
|
||||||
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = NO;
|
|
||||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
|
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
|
||||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = NO;
|
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = NO;
|
||||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = NO;
|
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = NO;
|
||||||
GCC_WARN_MISSING_PARENTHESES = NO;
|
GCC_WARN_MISSING_PARENTHESES = NO;
|
||||||
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = NO;
|
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = NO;
|
||||||
GCC_WARN_PEDANTIC = NO;
|
GCC_WARN_PEDANTIC = NO;
|
||||||
GCC_WARN_PROTOTYPE_CONVERSION = NO;
|
|
||||||
GCC_WARN_SHADOW = NO;
|
GCC_WARN_SHADOW = NO;
|
||||||
GCC_WARN_SIGN_COMPARE = YES;
|
GCC_WARN_SIGN_COMPARE = YES;
|
||||||
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = NO;
|
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = NO;
|
||||||
@@ -2082,6 +2075,7 @@
|
|||||||
);
|
);
|
||||||
INFOPLIST_FILE = "love-Info.plist";
|
INFOPLIST_FILE = "love-Info.plist";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
|
||||||
|
LLVM_LTO = YES;
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.5;
|
MACOSX_DEPLOYMENT_TARGET = 10.5;
|
||||||
ONLY_ACTIVE_ARCH = NO;
|
ONLY_ACTIVE_ARCH = NO;
|
||||||
OTHER_LDFLAGS = "";
|
OTHER_LDFLAGS = "";
|
||||||
@@ -2089,8 +2083,8 @@
|
|||||||
SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = YES;
|
SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = YES;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
WARNING_CFLAGS = (
|
WARNING_CFLAGS = (
|
||||||
"-W",
|
|
||||||
"-Wall",
|
"-Wall",
|
||||||
|
"-W",
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
|
|||||||
@@ -453,12 +453,12 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::TextureType texture_t
|
|||||||
return NULL; // never reached
|
return NULL; // never reached
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader *Graphics::newShader(const Shader::ShaderSources &shadersources)
|
Shader *Graphics::newShader(const Shader::ShaderSources &sources)
|
||||||
{
|
{
|
||||||
Shader *shader = NULL;
|
Shader *shader = NULL;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
shader = new Shader(shadersources);
|
shader = new Shader(sources);
|
||||||
}
|
}
|
||||||
catch(love::Exception &)
|
catch(love::Exception &)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ public:
|
|||||||
|
|
||||||
Canvas *newCanvas(int width, int height, Canvas::TextureType texture_type = Canvas::TYPE_NORMAL);
|
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.
|
* Sets the foreground color.
|
||||||
|
|||||||
@@ -37,45 +37,45 @@ namespace
|
|||||||
struct TemporaryAttacher
|
struct TemporaryAttacher
|
||||||
{
|
{
|
||||||
TemporaryAttacher(Shader *shader)
|
TemporaryAttacher(Shader *shader)
|
||||||
: curshader(shader)
|
: curShader(shader)
|
||||||
, prevshader(Shader::current)
|
, prevShader(Shader::current)
|
||||||
{
|
{
|
||||||
curshader->attach(true);
|
curShader->attach(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
~TemporaryAttacher()
|
~TemporaryAttacher()
|
||||||
{
|
{
|
||||||
if (prevshader != NULL)
|
if (prevShader != NULL)
|
||||||
prevshader->attach();
|
prevShader->attach();
|
||||||
else
|
else
|
||||||
Shader::detach();
|
Shader::detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader *curshader;
|
Shader *curShader;
|
||||||
Shader *prevshader;
|
Shader *prevShader;
|
||||||
};
|
};
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
Shader *Shader::current = NULL;
|
Shader *Shader::current = NULL;
|
||||||
|
|
||||||
GLint Shader::_maxtextureunits = 0;
|
GLint Shader::maxTextureUnits = 0;
|
||||||
std::vector<int> Shader::_texturecounters;
|
std::vector<int> Shader::textureCounters;
|
||||||
|
|
||||||
Shader::Shader(const ShaderSources &shadersources)
|
Shader::Shader(const ShaderSources &sources)
|
||||||
: _shadersources(shadersources)
|
: shaderSources(sources)
|
||||||
, _program(0)
|
, program(0)
|
||||||
{
|
{
|
||||||
if (shadersources.empty())
|
if (shaderSources.empty())
|
||||||
throw love::Exception("Cannot create shader: no source code!");
|
throw love::Exception("Cannot create shader: no source code!");
|
||||||
|
|
||||||
GLint maxtextureunits;
|
GLint maxtexunits;
|
||||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtextureunits);
|
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits);
|
||||||
_maxtextureunits = std::max(maxtextureunits - 1, 0);
|
maxTextureUnits = std::max(maxtexunits - 1, 0);
|
||||||
|
|
||||||
// initialize global texture id counters if needed
|
// initialize global texture id counters if needed
|
||||||
if (_texturecounters.size() < (size_t) _maxtextureunits)
|
if (textureCounters.size() < (size_t) maxTextureUnits)
|
||||||
_texturecounters.resize(_maxtextureunits, 0);
|
textureCounters.resize(maxTextureUnits, 0);
|
||||||
|
|
||||||
// load shader source and create program object
|
// load shader source and create program object
|
||||||
loadVolatile();
|
loadVolatile();
|
||||||
@@ -130,10 +130,10 @@ GLuint Shader::compileCode(ShaderType type, const std::string &code)
|
|||||||
|
|
||||||
glCompileShader(shaderid);
|
glCompileShader(shaderid);
|
||||||
|
|
||||||
GLint compile_status;
|
GLint status;
|
||||||
glGetShaderiv(shaderid, GL_COMPILE_STATUS, &compile_status);
|
glGetShaderiv(shaderid, GL_COMPILE_STATUS, &status);
|
||||||
|
|
||||||
if (compile_status == GL_FALSE)
|
if (status == GL_FALSE)
|
||||||
{
|
{
|
||||||
GLint infologlen;
|
GLint infologlen;
|
||||||
glGetShaderiv(shaderid, GL_INFO_LOG_LENGTH, &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<GLuint> &shaderids)
|
void Shader::createProgram(const std::vector<GLuint> &shaderids)
|
||||||
{
|
{
|
||||||
_program = glCreateProgram();
|
program = glCreateProgram();
|
||||||
if (_program == 0) // should only fail when called between glBegin() and glEnd()
|
if (program == 0) // should only fail when called between glBegin() and glEnd()
|
||||||
throw love::Exception("Cannot create shader program object.");
|
throw love::Exception("Cannot create shader program object.");
|
||||||
|
|
||||||
std::vector<GLuint>::const_iterator it;
|
std::vector<GLuint>::const_iterator it;
|
||||||
for (it = shaderids.begin(); it != shaderids.end(); ++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)
|
for (it = shaderids.begin(); it != shaderids.end(); ++it)
|
||||||
glDeleteShader(*it); // flag shaders for auto-deletion when program object is deleted
|
glDeleteShader(*it); // flag shaders for auto-deletion when program object is deleted
|
||||||
|
|
||||||
GLint link_ok;
|
GLint status;
|
||||||
glGetProgramiv(_program, GL_LINK_STATUS, &link_ok);
|
glGetProgramiv(program, GL_LINK_STATUS, &status);
|
||||||
|
|
||||||
if (link_ok == GL_FALSE)
|
if (status == GL_FALSE)
|
||||||
{
|
{
|
||||||
const std::string warnings = getWarnings();
|
const std::string warnings = getWarnings();
|
||||||
glDeleteProgram(_program);
|
glDeleteProgram(program);
|
||||||
|
|
||||||
throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
|
throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
|
||||||
}
|
}
|
||||||
@@ -182,13 +182,13 @@ void Shader::createProgram(const std::vector<GLuint> &shaderids)
|
|||||||
bool Shader::loadVolatile()
|
bool Shader::loadVolatile()
|
||||||
{
|
{
|
||||||
// zero out active texture list
|
// zero out active texture list
|
||||||
_activetextureunits.clear();
|
activeTextureUnits.clear();
|
||||||
_activetextureunits.insert(_activetextureunits.begin(), _maxtextureunits, 0);
|
activeTextureUnits.insert(activeTextureUnits.begin(), maxTextureUnits, 0);
|
||||||
|
|
||||||
std::vector<GLuint> shaderids;
|
std::vector<GLuint> shaderids;
|
||||||
|
|
||||||
ShaderSources::const_iterator source;
|
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);
|
GLuint shaderid = compileCode(source->first, source->second);
|
||||||
shaderids.push_back(shaderid);
|
shaderids.push_back(shaderid);
|
||||||
@@ -213,45 +213,45 @@ void Shader::unloadVolatile()
|
|||||||
if (current == this)
|
if (current == this)
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
|
|
||||||
if (_program != 0)
|
if (program != 0)
|
||||||
glDeleteProgram(_program);
|
glDeleteProgram(program);
|
||||||
|
|
||||||
_program = 0;
|
program = 0;
|
||||||
|
|
||||||
// decrement global texture id counters for texture units which had textures bound from this shader
|
// 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)
|
if (activeTextureUnits[i] > 0)
|
||||||
_texturecounters[i] = std::max(_texturecounters[i] - 1, 0);
|
textureCounters[i] = std::max(textureCounters[i] - 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// active texture list is probably invalid, clear it
|
// active texture list is probably invalid, clear it
|
||||||
_activetextureunits.clear();
|
activeTextureUnits.clear();
|
||||||
_activetextureunits.insert(_activetextureunits.begin(), _maxtextureunits, 0);
|
activeTextureUnits.insert(activeTextureUnits.begin(), maxTextureUnits, 0);
|
||||||
|
|
||||||
// same with uniform location list
|
// same with uniform location list
|
||||||
_uniforms.clear();
|
uniforms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Shader::getWarnings() const
|
std::string Shader::getWarnings() const
|
||||||
{
|
{
|
||||||
GLint strlen, nullpos;
|
GLint strlen, nullpos;
|
||||||
glGetProgramiv(_program, GL_INFO_LOG_LENGTH, &strlen);
|
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &strlen);
|
||||||
char *temp_str = new char[strlen+1];
|
char *tempstr = new char[strlen+1];
|
||||||
// be extra sure that the error string will be 0-terminated
|
// be extra sure that the error string will be 0-terminated
|
||||||
memset(temp_str, '\0', strlen+1);
|
memset(tempstr, '\0', strlen+1);
|
||||||
glGetProgramInfoLog(_program, strlen, &nullpos, temp_str);
|
glGetProgramInfoLog(program, strlen, &nullpos, tempstr);
|
||||||
temp_str[nullpos] = '\0';
|
tempstr[nullpos] = '\0';
|
||||||
|
|
||||||
std::string warnings(temp_str);
|
std::string warnings(tempstr);
|
||||||
delete[] temp_str;
|
delete[] tempstr;
|
||||||
return warnings;
|
return warnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::attach(bool temporary)
|
void Shader::attach(bool temporary)
|
||||||
{
|
{
|
||||||
if (current != this)
|
if (current != this)
|
||||||
glUseProgram(_program);
|
glUseProgram(program);
|
||||||
|
|
||||||
current = this;
|
current = this;
|
||||||
|
|
||||||
@@ -259,10 +259,10 @@ void Shader::attach(bool temporary)
|
|||||||
{
|
{
|
||||||
// make sure all sent textures are properly bound to their respective texture units
|
// make sure all sent textures are properly bound to their respective texture units
|
||||||
// note: list potentially contains texture ids of deleted/invalid textures!
|
// 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)
|
if (activeTextureUnits[i] > 0)
|
||||||
bindTextureToUnit(_activetextureunits[i], i + 1, false);
|
bindTextureToUnit(activeTextureUnits[i], i + 1, false);
|
||||||
}
|
}
|
||||||
setActiveTextureUnit(0);
|
setActiveTextureUnit(0);
|
||||||
}
|
}
|
||||||
@@ -351,11 +351,11 @@ void Shader::sendTexture(const std::string &name, GLuint texture)
|
|||||||
checkSetUniformError();
|
checkSetUniformError();
|
||||||
|
|
||||||
// increment global shader texture id counter for this texture unit, if we haven't already
|
// increment global shader texture id counter for this texture unit, if we haven't already
|
||||||
if (_activetextureunits[textureunit-1] == 0)
|
if (activeTextureUnits[textureunit-1] == 0)
|
||||||
++_texturecounters[textureunit-1];
|
++textureCounters[textureunit-1];
|
||||||
|
|
||||||
// store texture id so it can be re-bound to the proper texture unit when necessary
|
// 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)
|
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)
|
GLint Shader::getUniformLocation(const std::string &name)
|
||||||
{
|
{
|
||||||
std::map<std::string, GLint>::const_iterator it = _uniforms.find(name);
|
std::map<std::string, GLint>::const_iterator it = uniforms.find(name);
|
||||||
if (it != _uniforms.end())
|
if (it != uniforms.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|
||||||
GLint location = glGetUniformLocation(_program, name.c_str());
|
GLint location = glGetUniformLocation(program, name.c_str());
|
||||||
if (location == -1)
|
if (location == -1)
|
||||||
{
|
{
|
||||||
throw love::Exception(
|
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());
|
"A common error is to define but not use the variable.", name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
_uniforms[name] = location;
|
uniforms[name] = location;
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Shader::getTextureUnit(const std::string &name)
|
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;
|
return it->second;
|
||||||
|
|
||||||
int textureunit = 1;
|
int textureunit = 1;
|
||||||
|
|
||||||
// prefer texture units which are unused by all other shaders
|
// 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())
|
if (nextfreeunit != textureCounters.end())
|
||||||
textureunit = std::distance(_texturecounters.begin(), nextfreeunit) + 1; // we don't want to use unit 0
|
textureunit = std::distance(textureCounters.begin(), nextfreeunit) + 1; // we don't want to use unit 0
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// no completely unused texture units exist, try to use next free slot in our own list
|
// 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.");
|
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;
|
return textureunit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,8 +431,8 @@ void Shader::checkSetUniformError()
|
|||||||
std::string Shader::getGLSLVersion()
|
std::string Shader::getGLSLVersion()
|
||||||
{
|
{
|
||||||
// GL_SHADING_LANGUAGE_VERSION may not be available in OpenGL < 2.0.
|
// GL_SHADING_LANGUAGE_VERSION may not be available in OpenGL < 2.0.
|
||||||
const char *tmp = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
const char *tmp = (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||||
if (NULL == tmp)
|
if (tmp == NULL)
|
||||||
return "0.0";
|
return "0.0";
|
||||||
|
|
||||||
// the version string always begins with a version number of the format
|
// the version string always begins with a version number of the format
|
||||||
@@ -440,9 +440,9 @@ std::string Shader::getGLSLVersion()
|
|||||||
// or
|
// or
|
||||||
// major_number.minor_number.release_number
|
// major_number.minor_number.release_number
|
||||||
// we can keep release_number, since it does not affect the check below.
|
// we can keep release_number, since it does not affect the check below.
|
||||||
std::string versionString(tmp);
|
std::string versionstring(tmp);
|
||||||
size_t minorEndPos = versionString.find(' ');
|
size_t minorendpos = versionstring.find(' ');
|
||||||
return versionString.substr(0, minorEndPos);
|
return versionstring.substr(0, minorendpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Shader::isSupported()
|
bool Shader::isSupported()
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class Shader : public Object, public Volatile
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// pointer to currently active Shader.
|
// Pointer to currently active Shader.
|
||||||
static Shader *current;
|
static Shader *current;
|
||||||
|
|
||||||
enum ShaderType
|
enum ShaderType
|
||||||
@@ -50,14 +50,14 @@ public:
|
|||||||
TYPE_MAX_ENUM
|
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;
|
typedef std::map<ShaderType, std::string> ShaderSources;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Shader using a list of source codes.
|
* 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();
|
virtual ~Shader();
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Detach the currently bound 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();
|
static void detach();
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ private:
|
|||||||
|
|
||||||
GLint getUniformLocation(const std::string &name);
|
GLint getUniformLocation(const std::string &name);
|
||||||
void checkSetUniformError();
|
void checkSetUniformError();
|
||||||
|
|
||||||
GLuint compileCode(ShaderType type, const std::string &code);
|
GLuint compileCode(ShaderType type, const std::string &code);
|
||||||
void createProgram(const std::vector<GLuint> &shaderids);
|
void createProgram(const std::vector<GLuint> &shaderids);
|
||||||
|
|
||||||
@@ -133,23 +133,23 @@ private:
|
|||||||
|
|
||||||
void sendTexture(const std::string &name, GLuint texture);
|
void sendTexture(const std::string &name, GLuint texture);
|
||||||
|
|
||||||
// list of all shader code attached to this Shader
|
// List of all shader code attached to this Shader
|
||||||
ShaderSources _shadersources;
|
ShaderSources shaderSources;
|
||||||
|
|
||||||
GLuint _program; // volatile
|
GLuint program; // volatile
|
||||||
|
|
||||||
// uniform location buffer map
|
// Uniform location buffer map
|
||||||
std::map<std::string, GLint> _uniforms;
|
std::map<std::string, GLint> uniforms;
|
||||||
|
|
||||||
// texture unit pool for setting images
|
// Texture unit pool for setting images
|
||||||
std::map<std::string, GLint> _textureunitpool; // _textureunitpool[name] = textureunit
|
std::map<std::string, GLint> textureUnitPool; // textureUnitPool[name] = textureunit
|
||||||
std::vector<GLuint> _activetextureunits; // _activetextureunits[textureunit-1] = textureid
|
std::vector<GLuint> activeTextureUnits; // activeTextureUnits[textureunit-1] = textureid
|
||||||
|
|
||||||
// max GPU texture units available for sent images
|
// Max GPU texture units available for sent images
|
||||||
static GLint _maxtextureunits;
|
static GLint maxTextureUnits;
|
||||||
|
|
||||||
// counts total number of textures bound to each texture unit in all shaders
|
// Counts total number of textures bound to each texture unit in all shaders
|
||||||
static std::vector<int> _texturecounters;
|
static std::vector<int> textureCounters;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // opengl
|
} // opengl
|
||||||
|
|||||||
Reference in New Issue
Block a user