mirror of https://github.com/axmolengine/axmol.git
Removes uthash in CCGLProgram
This commit is contained in:
parent
84e0ae750c
commit
22776dcd88
|
@ -45,13 +45,6 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
typedef struct _hashUniformEntry
|
|
||||||
{
|
|
||||||
GLvoid* value; // value
|
|
||||||
unsigned int location; // Key
|
|
||||||
UT_hash_handle hh; // hash entry
|
|
||||||
} tHashUniformEntry;
|
|
||||||
|
|
||||||
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR = "ShaderPositionTextureColor";
|
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR = "ShaderPositionTextureColor";
|
||||||
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP = "ShaderPositionTextureColor_noMVP";
|
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP = "ShaderPositionTextureColor_noMVP";
|
||||||
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST = "ShaderPositionTextureColorAlphaTest";
|
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST = "ShaderPositionTextureColorAlphaTest";
|
||||||
|
@ -136,7 +129,6 @@ GLProgram::GLProgram()
|
||||||
: _program(0)
|
: _program(0)
|
||||||
, _vertShader(0)
|
, _vertShader(0)
|
||||||
, _fragShader(0)
|
, _fragShader(0)
|
||||||
, _hashForUniforms(nullptr)
|
|
||||||
, _flags()
|
, _flags()
|
||||||
{
|
{
|
||||||
memset(_builtInUniforms, 0, sizeof(_builtInUniforms));
|
memset(_builtInUniforms, 0, sizeof(_builtInUniforms));
|
||||||
|
@ -163,15 +155,11 @@ GLProgram::~GLProgram()
|
||||||
GL::deleteProgram(_program);
|
GL::deleteProgram(_program);
|
||||||
}
|
}
|
||||||
|
|
||||||
tHashUniformEntry *current_element, *tmp;
|
for (auto e : _hashForUniforms)
|
||||||
|
|
||||||
// Purge uniform hash
|
|
||||||
HASH_ITER(hh, _hashForUniforms, current_element, tmp)
|
|
||||||
{
|
{
|
||||||
HASH_DEL(_hashForUniforms, current_element);
|
free(e.second);
|
||||||
free(current_element->value);
|
|
||||||
free(current_element);
|
|
||||||
}
|
}
|
||||||
|
_hashForUniforms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray)
|
bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray)
|
||||||
|
@ -222,7 +210,8 @@ bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar*
|
||||||
{
|
{
|
||||||
glAttachShader(_program, _fragShader);
|
glAttachShader(_program, _fragShader);
|
||||||
}
|
}
|
||||||
_hashForUniforms = nullptr;
|
|
||||||
|
_hashForUniforms.clear();
|
||||||
|
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
|
@ -260,7 +249,7 @@ bool GLProgram::initWithPrecompiledProgramByteArray(const GLchar* vShaderByteArr
|
||||||
haveProgram = CCPrecompiledShaders::getInstance()->loadProgram(_program, vShaderByteArray, fShaderByteArray);
|
haveProgram = CCPrecompiledShaders::getInstance()->loadProgram(_program, vShaderByteArray, fShaderByteArray);
|
||||||
|
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
_hashForUniforms = nullptr;
|
_hashForUniforms.clear();
|
||||||
|
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
|
@ -631,31 +620,23 @@ bool GLProgram::updateUniformLocation(GLint location, const GLvoid* data, unsign
|
||||||
}
|
}
|
||||||
|
|
||||||
bool updated = true;
|
bool updated = true;
|
||||||
tHashUniformEntry *element = nullptr;
|
|
||||||
HASH_FIND_INT(_hashForUniforms, &location, element);
|
auto element = _hashForUniforms.find(location);
|
||||||
|
if (element == _hashForUniforms.end())
|
||||||
if (! element)
|
|
||||||
{
|
{
|
||||||
element = (tHashUniformEntry*)malloc( sizeof(*element) );
|
GLvoid* value = malloc(bytes);
|
||||||
|
memcpy(value, data, bytes );
|
||||||
// key
|
_hashForUniforms.insert(std::make_pair(location, value));
|
||||||
element->location = location;
|
|
||||||
|
|
||||||
// value
|
|
||||||
element->value = malloc( bytes );
|
|
||||||
memcpy(element->value, data, bytes );
|
|
||||||
|
|
||||||
HASH_ADD_INT(_hashForUniforms, location, element);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (memcmp(element->value, data, bytes) == 0)
|
if (memcmp(element->second, data, bytes) == 0)
|
||||||
{
|
{
|
||||||
updated = false;
|
updated = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(element->value, data, bytes);
|
memcpy(element->second, data, bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -921,17 +902,12 @@ void GLProgram::reset()
|
||||||
//GL::deleteProgram(_program);
|
//GL::deleteProgram(_program);
|
||||||
_program = 0;
|
_program = 0;
|
||||||
|
|
||||||
|
for (auto e: _hashForUniforms)
|
||||||
tHashUniformEntry *current_element, *tmp;
|
|
||||||
|
|
||||||
// Purge uniform hash
|
|
||||||
HASH_ITER(hh, _hashForUniforms, current_element, tmp)
|
|
||||||
{
|
{
|
||||||
HASH_DEL(_hashForUniforms, current_element);
|
free(e.second);
|
||||||
free(current_element->value);
|
|
||||||
free(current_element);
|
|
||||||
}
|
}
|
||||||
_hashForUniforms = nullptr;
|
|
||||||
|
_hashForUniforms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -45,7 +45,6 @@ NS_CC_BEGIN
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct _hashUniformEntry;
|
|
||||||
class GLProgram;
|
class GLProgram;
|
||||||
|
|
||||||
typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params);
|
typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params);
|
||||||
|
@ -340,7 +339,6 @@ protected:
|
||||||
GLuint _vertShader;
|
GLuint _vertShader;
|
||||||
GLuint _fragShader;
|
GLuint _fragShader;
|
||||||
GLint _builtInUniforms[UNIFORM_MAX];
|
GLint _builtInUniforms[UNIFORM_MAX];
|
||||||
struct _hashUniformEntry* _hashForUniforms;
|
|
||||||
bool _hasShaderCompiler;
|
bool _hasShaderCompiler;
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || defined(WP8_SHADER_COMPILER)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || defined(WP8_SHADER_COMPILER)
|
||||||
|
@ -360,6 +358,7 @@ protected:
|
||||||
|
|
||||||
std::unordered_map<std::string, Uniform> _userUniforms;
|
std::unordered_map<std::string, Uniform> _userUniforms;
|
||||||
std::unordered_map<std::string, VertexAttrib> _vertexAttribs;
|
std::unordered_map<std::string, VertexAttrib> _vertexAttribs;
|
||||||
|
std::unordered_map<GLint, GLvoid*> _hashForUniforms;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
Loading…
Reference in New Issue