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