mirror of https://github.com/axmolengine/axmol.git
Merge pull request #200 from halx99/attach-programstate
More clearly programState management
This commit is contained in:
commit
67a6c03462
|
@ -42,38 +42,6 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
// AtlasNode - Creation & Init
|
// AtlasNode - Creation & Init
|
||||||
|
|
||||||
AtlasNode::AtlasNode()
|
|
||||||
{
|
|
||||||
auto& pipelineDescriptor = _quadCommand.getPipelineDescriptor();
|
|
||||||
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_COLOR);
|
|
||||||
attachProgramState(new (std::nothrow) backend::ProgramState(program));
|
|
||||||
pipelineDescriptor.programState = _programState;
|
|
||||||
_mvpMatrixLocation = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix");
|
|
||||||
_textureLocation = pipelineDescriptor.programState->getUniformLocation("u_texture");
|
|
||||||
|
|
||||||
auto vertexLayout = _programState->getVertexLayout();
|
|
||||||
//a_position
|
|
||||||
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_POSITION,
|
|
||||||
_programState->getAttributeLocation(backend::Attribute::POSITION),
|
|
||||||
backend::VertexFormat::FLOAT3,
|
|
||||||
0,
|
|
||||||
false);
|
|
||||||
|
|
||||||
//a_texCoord
|
|
||||||
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_TEXCOORD,
|
|
||||||
_programState->getAttributeLocation(backend::Attribute::TEXCOORD),
|
|
||||||
backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords),
|
|
||||||
false);
|
|
||||||
|
|
||||||
//a_color
|
|
||||||
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_COLOR,
|
|
||||||
_programState->getAttributeLocation(backend::Attribute::COLOR),
|
|
||||||
backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors),
|
|
||||||
true);
|
|
||||||
|
|
||||||
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
|
|
||||||
}
|
|
||||||
|
|
||||||
AtlasNode::~AtlasNode()
|
AtlasNode::~AtlasNode()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(_textureAtlas);
|
CC_SAFE_RELEASE(_textureAtlas);
|
||||||
|
@ -118,7 +86,8 @@ bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeigh
|
||||||
|
|
||||||
_textureAtlas->initWithTexture(texture, itemsToRender);
|
_textureAtlas->initWithTexture(texture, itemsToRender);
|
||||||
|
|
||||||
updateProgramStateTexture(texture);
|
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, texture);
|
||||||
|
|
||||||
this->updateBlendFunc();
|
this->updateBlendFunc();
|
||||||
this->updateOpacityModifyRGB();
|
this->updateOpacityModifyRGB();
|
||||||
|
|
||||||
|
@ -129,6 +98,41 @@ bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeigh
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AtlasNode::attachProgramState(backend::ProgramState* programState)
|
||||||
|
{
|
||||||
|
if (Node::attachProgramState(programState))
|
||||||
|
{
|
||||||
|
auto& pipelineDescriptor = _quadCommand.getPipelineDescriptor();
|
||||||
|
pipelineDescriptor.programState = _programState;
|
||||||
|
_mvpMatrixLocation = _programState->getUniformLocation("u_MVPMatrix");
|
||||||
|
|
||||||
|
auto vertexLayout = _programState->getVertexLayout();
|
||||||
|
//a_position
|
||||||
|
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_POSITION,
|
||||||
|
_programState->getAttributeLocation(backend::Attribute::POSITION),
|
||||||
|
backend::VertexFormat::FLOAT3,
|
||||||
|
0,
|
||||||
|
false);
|
||||||
|
|
||||||
|
//a_texCoord
|
||||||
|
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_TEXCOORD,
|
||||||
|
_programState->getAttributeLocation(backend::Attribute::TEXCOORD),
|
||||||
|
backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords),
|
||||||
|
false);
|
||||||
|
|
||||||
|
//a_color
|
||||||
|
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_COLOR,
|
||||||
|
_programState->getAttributeLocation(backend::Attribute::COLOR),
|
||||||
|
backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors),
|
||||||
|
true);
|
||||||
|
|
||||||
|
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
|
||||||
|
|
||||||
|
updateProgramStateTexture(_textureAtlas->getTexture());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// AtlasNode - Atlas generation
|
// AtlasNode - Atlas generation
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,10 @@ public:
|
||||||
void setQuadsToDraw(ssize_t quadsToDraw);
|
void setQuadsToDraw(ssize_t quadsToDraw);
|
||||||
size_t getQuadsToDraw() const;
|
size_t getQuadsToDraw() const;
|
||||||
|
|
||||||
|
bool attachProgramState(backend::ProgramState* programState) override;
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
AtlasNode();
|
AtlasNode() = default;
|
||||||
virtual ~AtlasNode();
|
virtual ~AtlasNode();
|
||||||
|
|
||||||
/** Initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
/** Initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
||||||
|
@ -141,7 +143,6 @@ protected:
|
||||||
bool _ignoreContentScaleFactor = false;
|
bool _ignoreContentScaleFactor = false;
|
||||||
|
|
||||||
QuadCommand _quadCommand;
|
QuadCommand _quadCommand;
|
||||||
backend::UniformLocation _textureLocation;
|
|
||||||
backend::UniformLocation _mvpMatrixLocation;
|
backend::UniformLocation _mvpMatrixLocation;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -689,18 +689,21 @@ void Label::setVertexLayout()
|
||||||
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
|
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::setProgramState(backend::ProgramState *programState)
|
bool Label::attachProgramState(backend::ProgramState* programState)
|
||||||
{
|
{
|
||||||
Node::setProgramState(programState);
|
if (Node::attachProgramState(programState)) {
|
||||||
updateUniformLocations();
|
updateUniformLocations();
|
||||||
for (auto &batch : _batchCommands)
|
for (auto& batch : _batchCommands)
|
||||||
{
|
{
|
||||||
updateBatchCommand(batch);
|
updateBatchCommand(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &quadPipeline = _quadCommand.getPipelineDescriptor();
|
auto& quadPipeline = _quadCommand.getPipelineDescriptor();
|
||||||
setVertexLayout();
|
setVertexLayout();
|
||||||
quadPipeline.programState = _programState;
|
quadPipeline.programState = _programState;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::updateShaderProgram()
|
void Label::updateShaderProgram()
|
||||||
|
|
|
@ -639,9 +639,9 @@ public:
|
||||||
float getAdditionalKerning() const;
|
float getAdditionalKerning() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set ProgramState of current render command
|
* Attach ProgramState of current render command
|
||||||
*/
|
*/
|
||||||
virtual void setProgramState(backend::ProgramState *programState) override;
|
bool attachProgramState(backend::ProgramState *programState) override;
|
||||||
|
|
||||||
FontAtlas* getFontAtlas() { return _fontAtlas; }
|
FontAtlas* getFontAtlas() { return _fontAtlas; }
|
||||||
|
|
||||||
|
|
|
@ -40,20 +40,7 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
//CCLabelAtlas - Creation & Init
|
//CCLabelAtlas - Creation & Init
|
||||||
|
|
||||||
LabelAtlas* LabelAtlas::create()
|
|
||||||
{
|
|
||||||
LabelAtlas* ret = new (std::nothrow) LabelAtlas();
|
|
||||||
if (ret)
|
|
||||||
{
|
|
||||||
ret->autorelease();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE_NULL(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||||
{
|
{
|
||||||
|
@ -102,6 +89,24 @@ LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& fnt
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LabelAtlas* LabelAtlas::create(const std::string& string, Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
|
||||||
|
{
|
||||||
|
LabelAtlas* ret = new (std::nothrow) LabelAtlas();
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
if (ret->initWithString(string, texture, itemWidth, itemHeight, startCharMap))
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_RELEASE_NULL(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool LabelAtlas::initWithString(const std::string& theString, const std::string& fntFile)
|
bool LabelAtlas::initWithString(const std::string& theString, const std::string& fntFile)
|
||||||
{
|
{
|
||||||
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(fntFile);
|
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(fntFile);
|
||||||
|
|
|
@ -56,12 +56,6 @@ NS_CC_BEGIN
|
||||||
class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol
|
class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* Creates an empty LabelAtlas.
|
|
||||||
* User need to call initWithString(...) later to make this object work properly.
|
|
||||||
*/
|
|
||||||
static LabelAtlas* create();
|
|
||||||
|
|
||||||
/** Creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas. */
|
/** Creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas. */
|
||||||
static LabelAtlas* create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
static LabelAtlas* create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||||
|
|
||||||
|
@ -71,6 +65,11 @@ public:
|
||||||
*/
|
*/
|
||||||
static LabelAtlas* create(const std::string& string, const std::string& fntFile);
|
static LabelAtlas* create(const std::string& string, const std::string& fntFile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the LabelAtlas with a string, a texture, the width and height of each element and the starting char of the atlas.
|
||||||
|
*/
|
||||||
|
static LabelAtlas* create(const std::string& string, Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||||
|
|
||||||
/** Initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas. */
|
/** Initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas. */
|
||||||
bool initWithString(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
bool initWithString(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||||
|
|
||||||
|
|
|
@ -281,8 +281,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st
|
||||||
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
||||||
{
|
{
|
||||||
CCASSERT( value.size() != 0, "value length must be greater than 0");
|
CCASSERT( value.size() != 0, "value length must be greater than 0");
|
||||||
LabelAtlas *label = LabelAtlas::create();
|
LabelAtlas *label = LabelAtlas::create(value, charMapFile, itemWidth, itemHeight, startCharMap);
|
||||||
label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
|
|
||||||
if (MenuItemLabel::initWithLabel(label, callback))
|
if (MenuItemLabel::initWithLabel(label, callback))
|
||||||
{
|
{
|
||||||
// do something ?
|
// do something ?
|
||||||
|
|
|
@ -211,17 +211,14 @@ void MotionStreak::setTexture(Texture2D *texture)
|
||||||
_texture = texture;
|
_texture = texture;
|
||||||
|
|
||||||
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, _texture);
|
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, _texture);
|
||||||
|
|
||||||
if (_texture)
|
|
||||||
_programState->setTexture(_texture->getBackendTexture());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotionStreak::setProgramState(backend::ProgramState* programState)
|
bool MotionStreak::attachProgramState(backend::ProgramState* programState)
|
||||||
{
|
{
|
||||||
|
if (Node::attachProgramState(programState)) {
|
||||||
CCASSERT(programState, "argument should not be nullptr");
|
CCASSERT(programState, "argument should not be nullptr");
|
||||||
auto& pipelineDescriptor = _customCommand.getPipelineDescriptor();
|
auto& pipelineDescriptor = _customCommand.getPipelineDescriptor();
|
||||||
Node::setProgramState(programState);
|
|
||||||
pipelineDescriptor.programState = _programState;
|
pipelineDescriptor.programState = _programState;
|
||||||
|
|
||||||
_mvpMatrixLocaiton = _programState->getUniformLocation("u_MVPMatrix");
|
_mvpMatrixLocaiton = _programState->getUniformLocation("u_MVPMatrix");
|
||||||
|
@ -245,6 +242,11 @@ void MotionStreak::setProgramState(backend::ProgramState* programState)
|
||||||
vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, 4 * sizeof(float), true);
|
vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, 4 * sizeof(float), true);
|
||||||
}
|
}
|
||||||
vertexLayout->setLayout(4 * sizeof(float) + 4 * sizeof(uint8_t));
|
vertexLayout->setLayout(4 * sizeof(float) + 4 * sizeof(uint8_t));
|
||||||
|
|
||||||
|
updateProgramStateTexture(_texture);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotionStreak::setBlendFunc(const BlendFunc &blendFunc)
|
void MotionStreak::setBlendFunc(const BlendFunc &blendFunc)
|
||||||
|
|
|
@ -147,7 +147,7 @@ public:
|
||||||
_startingPositionInitialized = bStartingPositionInitialized;
|
_startingPositionInitialized = bStartingPositionInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setProgramState(backend::ProgramState* programState) override;
|
bool attachProgramState(backend::ProgramState* programState) override;
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
MotionStreak();
|
MotionStreak();
|
||||||
|
|
|
@ -2132,16 +2132,7 @@ void Node::setProgramStateWithRegistry(backend::ProgramType programType, Texture
|
||||||
{
|
{
|
||||||
auto formatEXT = texture ? texture->getTextureFormatEXT() : 0;
|
auto formatEXT = texture ? texture->getTextureFormatEXT() : 0;
|
||||||
auto programState = backend::ProgramStateRegistry::getInstance()->newProgramState(programType, formatEXT);
|
auto programState = backend::ProgramStateRegistry::getInstance()->newProgramState(programType, formatEXT);
|
||||||
setProgramState(programState);
|
attachProgramState(programState);
|
||||||
programState->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Node::updateProgramStateTexture(Texture2D* texture)
|
|
||||||
{
|
|
||||||
if (texture == nullptr || texture->getBackendTexture() == nullptr || _programState == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_programState->setTexture(texture->getBackendTexture());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setProgramState(backend::ProgramState* programState)
|
void Node::setProgramState(backend::ProgramState* programState)
|
||||||
|
@ -2161,6 +2152,14 @@ bool Node::attachProgramState(backend::ProgramState* programState)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::updateProgramStateTexture(Texture2D* texture)
|
||||||
|
{
|
||||||
|
if (texture == nullptr || texture->getBackendTexture() == nullptr || _programState == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_programState->setTexture(texture->getBackendTexture());
|
||||||
|
}
|
||||||
|
|
||||||
backend::ProgramState* Node::getProgramState() const
|
backend::ProgramState* Node::getProgramState() const
|
||||||
{
|
{
|
||||||
return _programState;
|
return _programState;
|
||||||
|
|
|
@ -1768,13 +1768,22 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void setCameraMask(unsigned short mask, bool applyChildren = true);
|
virtual void setCameraMask(unsigned short mask, bool applyChildren = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets ProgramState with retain
|
||||||
|
* @param programState
|
||||||
|
*/
|
||||||
virtual void setProgramState(backend::ProgramState* programState);
|
virtual void setProgramState(backend::ProgramState* programState);
|
||||||
bool attachProgramState(backend::ProgramState* programState);
|
backend::ProgramState* getProgramState() const;
|
||||||
|
|
||||||
void setProgramStateWithRegistry(backend::ProgramType programType, Texture2D* texture);
|
void setProgramStateWithRegistry(backend::ProgramType programType, Texture2D* texture);
|
||||||
void updateProgramStateTexture(Texture2D* texture);
|
|
||||||
|
|
||||||
virtual backend::ProgramState* getProgramState() const;
|
/**
|
||||||
|
* Attach/Change current ProgramState without retain, override me
|
||||||
|
* @param programState should be new or retain if it has other owner
|
||||||
|
*/
|
||||||
|
virtual bool attachProgramState(backend::ProgramState* programState);
|
||||||
|
|
||||||
|
void updateProgramStateTexture(Texture2D* texture);
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
// Nodes should be created using create();
|
// Nodes should be created using create();
|
||||||
|
|
|
@ -376,9 +376,7 @@ void Sprite::setVertexLayout()
|
||||||
void Sprite::updateShaders(const char* vert, const char* frag)
|
void Sprite::updateShaders(const char* vert, const char* frag)
|
||||||
{
|
{
|
||||||
auto* program = backend::Device::getInstance()->newProgram(vert, frag);
|
auto* program = backend::Device::getInstance()->newProgram(vert, frag);
|
||||||
auto programState = new (std::nothrow) backend::ProgramState(program);
|
attachProgramState(new (std::nothrow) backend::ProgramState(program));
|
||||||
setProgramState(programState);
|
|
||||||
CC_SAFE_RELEASE(programState);
|
|
||||||
CC_SAFE_RELEASE(program);
|
CC_SAFE_RELEASE(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,25 +385,25 @@ void Sprite::setProgramState(backend::ProgramType type)
|
||||||
setProgramStateWithRegistry(type, _texture);
|
setProgramStateWithRegistry(type, _texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::setProgramState(backend::ProgramState *programState)
|
bool Sprite::attachProgramState(backend::ProgramState *programState)
|
||||||
{
|
{
|
||||||
CCASSERT(programState, "argument should not be nullptr");
|
CCASSERT(programState, "argument should not be nullptr");
|
||||||
|
if (Node::attachProgramState(programState)) {
|
||||||
auto& pipelineDescriptor = _trianglesCommand.getPipelineDescriptor();
|
auto& pipelineDescriptor = _trianglesCommand.getPipelineDescriptor();
|
||||||
Node::setProgramState(programState);
|
|
||||||
pipelineDescriptor.programState = _programState;
|
pipelineDescriptor.programState = _programState;
|
||||||
|
|
||||||
_mvpMatrixLocation = pipelineDescriptor.programState->getUniformLocation(backend::Uniform::MVP_MATRIX);
|
_mvpMatrixLocation = _programState->getUniformLocation(backend::Uniform::MVP_MATRIX);
|
||||||
_textureLocation = pipelineDescriptor.programState->getUniformLocation(backend::Uniform::TEXTURE);
|
|
||||||
|
|
||||||
setVertexLayout();
|
setVertexLayout();
|
||||||
updateProgramStateTexture(_texture);
|
updateProgramStateTexture(_texture);
|
||||||
setMVPMatrixUniform();
|
setMVPMatrixUniform();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::setTexture(Texture2D *texture)
|
void Sprite::setTexture(Texture2D *texture)
|
||||||
{
|
{
|
||||||
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, texture);
|
|
||||||
|
|
||||||
CCASSERT(! _batchNode || (texture && texture == _batchNode->getTexture()), "CCSprite: Batched sprites should use the same texture as the batchnode");
|
CCASSERT(! _batchNode || (texture && texture == _batchNode->getTexture()), "CCSprite: Batched sprites should use the same texture as the batchnode");
|
||||||
// accept texture==nil as argument
|
// accept texture==nil as argument
|
||||||
CCASSERT( !texture || dynamic_cast<Texture2D*>(texture), "setTexture expects a Texture2D. Invalid argument");
|
CCASSERT( !texture || dynamic_cast<Texture2D*>(texture), "setTexture expects a Texture2D. Invalid argument");
|
||||||
|
@ -437,7 +435,8 @@ void Sprite::setTexture(Texture2D *texture)
|
||||||
}
|
}
|
||||||
updateBlendFunc();
|
updateBlendFunc();
|
||||||
}
|
}
|
||||||
updateProgramStateTexture(_texture);
|
|
||||||
|
setProgramState(backend::ProgramType::POSITION_TEXTURE_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D* Sprite::getTexture() const
|
Texture2D* Sprite::getTexture() const
|
||||||
|
@ -1729,9 +1728,4 @@ void Sprite::setMVPMatrixUniform()
|
||||||
programState->setUniform(_mvpMatrixLocation, projectionMat.m, sizeof(projectionMat.m));
|
programState->setUniform(_mvpMatrixLocation, projectionMat.m, sizeof(projectionMat.m));
|
||||||
}
|
}
|
||||||
|
|
||||||
backend::ProgramState* Sprite::getProgramState() const
|
|
||||||
{
|
|
||||||
return _programState;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -418,14 +418,9 @@ public:
|
||||||
TextureAtlas* getTextureAtlas() const { return _textureAtlas; }
|
TextureAtlas* getTextureAtlas() const { return _textureAtlas; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set ProgramState
|
* Attach new ProgramState
|
||||||
*/
|
*/
|
||||||
virtual void setProgramState(backend::ProgramState *programState) override;
|
bool attachProgramState(backend::ProgramState *programState) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current ProgramState
|
|
||||||
*/
|
|
||||||
virtual backend::ProgramState *getProgramState() const override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode.
|
* Sets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode.
|
||||||
|
@ -625,6 +620,7 @@ CC_CONSTRUCTOR_ACCESS :
|
||||||
virtual void setVertexLayout();
|
virtual void setVertexLayout();
|
||||||
virtual void updateShaders(const char* vert, const char* frag);
|
virtual void updateShaders(const char* vert, const char* frag);
|
||||||
|
|
||||||
|
using Node::setProgramState;
|
||||||
void setProgramState(backend::ProgramType type);
|
void setProgramState(backend::ProgramType type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -663,7 +659,6 @@ protected:
|
||||||
TrianglesCommand _trianglesCommand;
|
TrianglesCommand _trianglesCommand;
|
||||||
|
|
||||||
backend::UniformLocation _mvpMatrixLocation;
|
backend::UniformLocation _mvpMatrixLocation;
|
||||||
backend::UniformLocation _textureLocation;
|
|
||||||
#if CC_SPRITE_DEBUG_DRAW
|
#if CC_SPRITE_DEBUG_DRAW
|
||||||
DrawNode *_debugDrawNode = nullptr;
|
DrawNode *_debugDrawNode = nullptr;
|
||||||
#endif //CC_SPRITE_DEBUG_DRAW
|
#endif //CC_SPRITE_DEBUG_DRAW
|
||||||
|
|
|
@ -103,7 +103,6 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity/* = DEFAU
|
||||||
_textureAtlas->initWithTexture(tex, capacity);
|
_textureAtlas->initWithTexture(tex, capacity);
|
||||||
|
|
||||||
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, tex);
|
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, tex);
|
||||||
updateProgramStateTexture(_textureAtlas->getTexture());
|
|
||||||
|
|
||||||
updateBlendFunc();
|
updateBlendFunc();
|
||||||
|
|
||||||
|
@ -148,15 +147,19 @@ void SpriteBatchNode::setVertexLayout()
|
||||||
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
|
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatchNode::setProgramState(backend::ProgramState *programState)
|
bool SpriteBatchNode::attachProgramState(backend::ProgramState *programState)
|
||||||
{
|
{
|
||||||
CCASSERT(programState, "programState should not be nullptr");
|
CCASSERT(programState, "programState should not be nullptr");
|
||||||
|
if (Node::attachProgramState(programState)) {
|
||||||
auto& pipelineDescriptor = _quadCommand.getPipelineDescriptor();
|
auto& pipelineDescriptor = _quadCommand.getPipelineDescriptor();
|
||||||
Node::setProgramState(programState);
|
|
||||||
pipelineDescriptor.programState = _programState;
|
pipelineDescriptor.programState = _programState;
|
||||||
|
|
||||||
setVertexLayout();
|
setVertexLayout();
|
||||||
|
updateProgramStateTexture(_textureAtlas->getTexture());
|
||||||
setUniformLocation();
|
setUniformLocation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpriteBatchNode::init()
|
bool SpriteBatchNode::init()
|
||||||
|
@ -694,7 +697,6 @@ void SpriteBatchNode::setTexture(Texture2D *texture)
|
||||||
{
|
{
|
||||||
_textureAtlas->setTexture(texture);
|
_textureAtlas->setTexture(texture);
|
||||||
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, texture);
|
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, texture);
|
||||||
updateProgramStateTexture(texture);
|
|
||||||
updateBlendFunc();
|
updateBlendFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -212,9 +212,9 @@ public:
|
||||||
virtual std::string getDescription() const override;
|
virtual std::string getDescription() const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set ProgramState
|
* Attach new ProgramState
|
||||||
*/
|
*/
|
||||||
virtual void setProgramState(backend::ProgramState *programState) override;
|
bool attachProgramState(backend::ProgramState *programState) override;
|
||||||
|
|
||||||
/** Inserts a quad at a certain index into the texture atlas. The Sprite won't be added into the children array.
|
/** Inserts a quad at a certain index into the texture atlas. The Sprite won't be added into the children array.
|
||||||
* This method should be called only when you are dealing with very big AtlasSprite and when most of the Sprite won't be updated.
|
* This method should be called only when you are dealing with very big AtlasSprite and when most of the Sprite won't be updated.
|
||||||
|
|
|
@ -119,8 +119,8 @@ public:
|
||||||
virtual const BlendFunc &getBlendFunc() const override;
|
virtual const BlendFunc &getBlendFunc() const override;
|
||||||
|
|
||||||
// overrides
|
// overrides
|
||||||
/** set ProgramState, you should bind attributes by yourself */
|
/** Sets ProgramState, you should bind attributes by yourself */
|
||||||
virtual void setProgramState(backend::ProgramState *programState) override;
|
void setProgramState(backend::ProgramState *programState) override;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get AABB
|
* Get AABB
|
||||||
|
|
|
@ -1275,22 +1275,19 @@ void Director::createStatsLabel()
|
||||||
*/
|
*/
|
||||||
float scaleFactor = 1 / CC_CONTENT_SCALE_FACTOR();
|
float scaleFactor = 1 / CC_CONTENT_SCALE_FACTOR();
|
||||||
|
|
||||||
_FPSLabel = LabelAtlas::create();
|
_FPSLabel = LabelAtlas::create(fpsString, texture, 12, 32, '.');
|
||||||
_FPSLabel->retain();
|
_FPSLabel->retain();
|
||||||
_FPSLabel->setIgnoreContentScaleFactor(true);
|
_FPSLabel->setIgnoreContentScaleFactor(true);
|
||||||
_FPSLabel->initWithString(fpsString, texture, 12, 32 , '.');
|
|
||||||
_FPSLabel->setScale(scaleFactor);
|
_FPSLabel->setScale(scaleFactor);
|
||||||
|
|
||||||
_drawnBatchesLabel = LabelAtlas::create();
|
_drawnBatchesLabel = LabelAtlas::create(drawBatchString, texture, 12, 32, '.');
|
||||||
_drawnBatchesLabel->retain();
|
_drawnBatchesLabel->retain();
|
||||||
_drawnBatchesLabel->setIgnoreContentScaleFactor(true);
|
_drawnBatchesLabel->setIgnoreContentScaleFactor(true);
|
||||||
_drawnBatchesLabel->initWithString(drawBatchString, texture, 12, 32, '.');
|
|
||||||
_drawnBatchesLabel->setScale(scaleFactor);
|
_drawnBatchesLabel->setScale(scaleFactor);
|
||||||
|
|
||||||
_drawnVerticesLabel = LabelAtlas::create();
|
_drawnVerticesLabel = LabelAtlas::create(drawVerticesString, texture, 12, 32, '.');
|
||||||
_drawnVerticesLabel->retain();
|
_drawnVerticesLabel->retain();
|
||||||
_drawnVerticesLabel->setIgnoreContentScaleFactor(true);
|
_drawnVerticesLabel->setIgnoreContentScaleFactor(true);
|
||||||
_drawnVerticesLabel->initWithString(drawVerticesString, texture, 12, 32, '.');
|
|
||||||
_drawnVerticesLabel->setScale(scaleFactor);
|
_drawnVerticesLabel->setScale(scaleFactor);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56366,16 +56366,6 @@ int lua_cocos2dx_LabelAtlas_create(lua_State* tolua_S)
|
||||||
} while (0);
|
} while (0);
|
||||||
ok = true;
|
ok = true;
|
||||||
do
|
do
|
||||||
{
|
|
||||||
if (argc == 0)
|
|
||||||
{
|
|
||||||
cocos2d::LabelAtlas* ret = cocos2d::LabelAtlas::create();
|
|
||||||
object_to_luaval<cocos2d::LabelAtlas>(tolua_S, "cc.LabelAtlas",(cocos2d::LabelAtlas*)ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
ok = true;
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -975,7 +975,7 @@ public:
|
||||||
sprite->setProgramState(programState);
|
sprite->setProgramState(programState);
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
virtual void setProgramState(backend::ProgramState* programState) override;
|
bool attachProgramState(backend::ProgramState* programState) override;
|
||||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -983,16 +983,19 @@ protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void MySprite::setProgramState(backend::ProgramState* programState)
|
bool MySprite::attachProgramState(backend::ProgramState* programState)
|
||||||
{
|
{
|
||||||
Sprite::setProgramState(programState);
|
if (Sprite::attachProgramState(programState)) {
|
||||||
auto& pipelineDescriptor = _customCommand.getPipelineDescriptor();
|
auto& pipelineDescriptor = _customCommand.getPipelineDescriptor();
|
||||||
pipelineDescriptor.programState = programState;
|
pipelineDescriptor.programState = programState;
|
||||||
|
|
||||||
_customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
|
_customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
|
||||||
_customCommand.setPrimitiveType(CustomCommand::PrimitiveType::TRIANGLE_STRIP);
|
_customCommand.setPrimitiveType(CustomCommand::PrimitiveType::TRIANGLE_STRIP);
|
||||||
_customCommand.createVertexBuffer(sizeof(V3F_C4B_T2F), 4, CustomCommand::BufferUsage::STATIC);
|
_customCommand.createVertexBuffer(sizeof(V3F_C4B_T2F), 4, CustomCommand::BufferUsage::STATIC);
|
||||||
_customCommand.updateVertexBuffer(&_quad, 4*sizeof(V3F_C4B_T2F));
|
_customCommand.updateVertexBuffer(&_quad, 4 * sizeof(V3F_C4B_T2F));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MySprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
void MySprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||||
|
|
Loading…
Reference in New Issue