mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5977 from dabingnn/develop_fixID_Android_bug
Develop fix id android bug
This commit is contained in:
commit
e52fc981cc
|
@ -84,6 +84,38 @@ const char* GLProgram::ATTRIBUTE_NAME_COLOR = "a_color";
|
||||||
const char* GLProgram::ATTRIBUTE_NAME_POSITION = "a_position";
|
const char* GLProgram::ATTRIBUTE_NAME_POSITION = "a_position";
|
||||||
const char* GLProgram::ATTRIBUTE_NAME_TEX_COORD = "a_texCoord";
|
const char* GLProgram::ATTRIBUTE_NAME_TEX_COORD = "a_texCoord";
|
||||||
|
|
||||||
|
#define CC_GLPROGRAM_MAX_MATERIAL_ID_NUMBER 1024
|
||||||
|
|
||||||
|
GLProgram::MaterialProgramIDAllocator::MaterialProgramIDAllocator()
|
||||||
|
{
|
||||||
|
for(GLuint id = 1; id < CC_GLPROGRAM_MAX_MATERIAL_ID_NUMBER; ++id)
|
||||||
|
{
|
||||||
|
_freeIDs.insert(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GLProgram::MaterialProgramIDAllocator::~MaterialProgramIDAllocator()
|
||||||
|
{
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint GLProgram::MaterialProgramIDAllocator::allocID()
|
||||||
|
{
|
||||||
|
CCASSERT(_freeIDs.size()!=0, "There are no allocated ID");
|
||||||
|
GLuint id = *(_freeIDs.begin());
|
||||||
|
_freeIDs.erase(id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLProgram::MaterialProgramIDAllocator::freeID(GLuint id)
|
||||||
|
{
|
||||||
|
CCASSERT(_freeIDs.find(id) == _freeIDs.end() && id != 0, "free id is 0 or a duplicated id");
|
||||||
|
_freeIDs.insert(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLProgram::MaterialProgramIDAllocator GLProgram::_idAllocator;
|
||||||
|
const GLuint GLProgram::_maxMaterialIDNumber = CC_GLPROGRAM_MAX_MATERIAL_ID_NUMBER;
|
||||||
|
|
||||||
GLProgram::GLProgram()
|
GLProgram::GLProgram()
|
||||||
: _program(0)
|
: _program(0)
|
||||||
, _vertShader(0)
|
, _vertShader(0)
|
||||||
|
@ -92,10 +124,13 @@ GLProgram::GLProgram()
|
||||||
, _flags()
|
, _flags()
|
||||||
{
|
{
|
||||||
memset(_uniforms, 0, sizeof(_uniforms));
|
memset(_uniforms, 0, sizeof(_uniforms));
|
||||||
|
_materialProgramID = _idAllocator.allocID();
|
||||||
}
|
}
|
||||||
|
|
||||||
GLProgram::~GLProgram()
|
GLProgram::~GLProgram()
|
||||||
{
|
{
|
||||||
|
_idAllocator.freeID(_materialProgramID);
|
||||||
|
_materialProgramID = 0;
|
||||||
CCLOGINFO("%s %d deallocing GLProgram: %p", __FUNCTION__, __LINE__, this);
|
CCLOGINFO("%s %d deallocing GLProgram: %p", __FUNCTION__, __LINE__, this);
|
||||||
|
|
||||||
// there is no need to delete the shaders. They should have been already deleted.
|
// there is no need to delete the shaders. They should have been already deleted.
|
||||||
|
|
|
@ -34,6 +34,7 @@ THE SOFTWARE.
|
||||||
#include "CCRef.h"
|
#include "CCRef.h"
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
#include "kazmath/kazmath.h"
|
#include "kazmath/kazmath.h"
|
||||||
|
#include <set>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -256,7 +257,7 @@ public:
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
inline const GLuint getProgram() const { return _program; }
|
inline const GLuint getProgram() const { return _program; }
|
||||||
|
inline const GLuint getMaterialProgramID() const { return _materialProgramID; }
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
CC_DEPRECATED_ATTRIBUTE bool initWithVertexShaderByteArray(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray)
|
CC_DEPRECATED_ATTRIBUTE bool initWithVertexShaderByteArray(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray)
|
||||||
{ return initWithByteArrays(vShaderByteArray, fShaderByteArray); }
|
{ return initWithByteArrays(vShaderByteArray, fShaderByteArray); }
|
||||||
|
@ -272,6 +273,8 @@ private:
|
||||||
std::string logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;
|
std::string logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//ID used for renderer material, _materialProgramID maybe different from _program
|
||||||
|
GLuint _materialProgramID;
|
||||||
GLuint _program;
|
GLuint _program;
|
||||||
GLuint _vertShader;
|
GLuint _vertShader;
|
||||||
GLuint _fragShader;
|
GLuint _fragShader;
|
||||||
|
@ -292,6 +295,21 @@ private:
|
||||||
// handy way to initialize the bitfield
|
// handy way to initialize the bitfield
|
||||||
flag_struct() { memset(this, 0, sizeof(*this)); }
|
flag_struct() { memset(this, 0, sizeof(*this)); }
|
||||||
} _flags;
|
} _flags;
|
||||||
|
private:
|
||||||
|
class MaterialProgramIDAllocator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MaterialProgramIDAllocator();
|
||||||
|
~MaterialProgramIDAllocator();
|
||||||
|
GLuint allocID();
|
||||||
|
void freeID(GLuint id);
|
||||||
|
private:
|
||||||
|
std::set<GLuint> _freeIDs;
|
||||||
|
};
|
||||||
|
|
||||||
|
static MaterialProgramIDAllocator _idAllocator;
|
||||||
|
public:
|
||||||
|
static const GLuint _maxMaterialIDNumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of shaders group
|
// end of shaders group
|
||||||
|
|
|
@ -61,9 +61,7 @@ void QuadCommand::generateMaterialID()
|
||||||
{
|
{
|
||||||
//Generate Material ID
|
//Generate Material ID
|
||||||
//TODO fix shader ID generation
|
//TODO fix shader ID generation
|
||||||
CCASSERT(_shader->getProgram() < pow(2,10), "ShaderID is greater than 2^10");
|
CCASSERT(_shader->getMaterialProgramID() < GLProgram::_maxMaterialIDNumber, "ShaderID is greater than Id limitation");
|
||||||
//TODO fix texture ID generation
|
|
||||||
CCASSERT(_textureID < pow(2,18), "TextureID is greater than 2^18");
|
|
||||||
|
|
||||||
//TODO fix blend id generation
|
//TODO fix blend id generation
|
||||||
int blendID = 0;
|
int blendID = 0;
|
||||||
|
@ -96,7 +94,7 @@ void QuadCommand::generateMaterialID()
|
||||||
// | Shader ID (10 bits) | Blend ID (4 bits) | empty (18bits) | Texture ID (32 bits) |
|
// | Shader ID (10 bits) | Blend ID (4 bits) | empty (18bits) | Texture ID (32 bits) |
|
||||||
// +---------------------+-------------------+----------------------------------------+
|
// +---------------------+-------------------+----------------------------------------+
|
||||||
|
|
||||||
_materialID = (uint64_t)_shader->getProgram() << 54
|
_materialID = (uint64_t)_shader->getMaterialProgramID() << 54
|
||||||
| (uint64_t)blendID << 50
|
| (uint64_t)blendID << 50
|
||||||
| (uint64_t)_textureID << 0;
|
| (uint64_t)_textureID << 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue