Skip to content

Commit 9ad2545

Browse files
committed
Revert "fix crash of cclayercolor and fix some other error logic (cocos2d#19177)"
This reverts commit 30daf5d.
1 parent fde4e63 commit 9ad2545

File tree

11 files changed

+23
-41
lines changed

11 files changed

+23
-41
lines changed

cocos/2d/CCLayer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,13 @@ void LayerColor::onDraw(const Mat4& transform, uint32_t /*flags*/)
620620
getGLProgram()->use();
621621
getGLProgram()->setUniformsForBuiltins(transform);
622622

623+
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
624+
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
625+
623626
//
624627
// Attributes
625628
//
626629
glBindBuffer(GL_ARRAY_BUFFER, 0);
627-
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
628-
glDisableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
629-
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
630630
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, 0, _noMVPVertices);
631631
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, _squareColors);
632632

cocos/2d/CCMotionStreak.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,6 @@ void MotionStreak::onDraw(const Mat4 &transform, uint32_t /*flags*/)
390390

391391
glActiveTexture(GL_TEXTURE0);
392392
glBindTexture(GL_TEXTURE_2D, _texture->getName());
393-
auto alphaTexID = _texture->getAlphaTextureName();
394-
if (alphaTexID > 0)
395-
{
396-
glActiveTexture(GL_TEXTURE0 + 1);
397-
glBindTexture(GL_TEXTURE_2D, alphaTexID);
398-
}
399393

400394
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, _vertices);
401395
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, _texCoords);

cocos/2d/CCProgressTimer.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,6 @@ void ProgressTimer::onDraw(const Mat4 &transform, uint32_t /*flags*/)
517517

518518
glActiveTexture(GL_TEXTURE0);
519519
glBindTexture(GL_TEXTURE_2D, _sprite->getTexture()->getName());
520-
auto alphaTexID = _sprite->getTexture()->getAlphaTextureName();
521-
if (alphaTexID > 0)
522-
{
523-
glActiveTexture(GL_TEXTURE0 + 1);
524-
glBindTexture(GL_TEXTURE_2D, alphaTexID);
525-
}
526520

527521
glVertexAttribPointer( GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(_vertexData[0]) , &_vertexData[0].vertices);
528522
glVertexAttribPointer( GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(_vertexData[0]), &_vertexData[0].texCoords);

cocos/base/ccUtils.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -544,18 +544,6 @@ void setBlending(GLenum sfactor, GLenum dfactor)
544544
RenderState::StateBlock::_defaultState->setBlendDst((RenderState::Blend)dfactor);
545545
}
546546
}
547-
548-
void enableVertexAttributes(uint32_t flags)
549-
{
550-
for (int i = 0; flags > 0; i++)
551-
{
552-
int flag = 1 << i;
553-
if (flag & flags)
554-
glEnableVertexAttribArray(i);
555-
556-
flags &= ~flag;
557-
}
558-
}
559547

560548
}
561549

cocos/base/ccUtils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ namespace utils
190190
CC_DLL LanguageType getLanguageTypeByISO2(const char* code);
191191

192192
CC_DLL void setBlending(GLenum sfactor, GLenum dfactor);
193-
CC_DLL void enableVertexAttributes(uint32_t flags);
194193
}
195194

196195
NS_CC_END

cocos/renderer/CCTextureAtlas.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,6 @@ void TextureAtlas::drawNumberOfQuads(ssize_t numberOfQuads, ssize_t start)
614614

615615
glActiveTexture(GL_TEXTURE0);
616616
glBindTexture(GL_TEXTURE_2D, _texture->getName());
617-
auto alphaTexID = _texture->getAlphaTextureName();
618-
if (alphaTexID > 0)
619-
{
620-
glActiveTexture(GL_TEXTURE0 + 1);
621-
glBindTexture(GL_TEXTURE_2D, alphaTexID);
622-
}
623617

624618
auto conf = Configuration::getInstance();
625619
if (conf->supportsShareableVAO() && conf->supportsMapBuffer())

cocos/renderer/CCVertexAttribBinding.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "platform/CCGL.h"
2626
#include "base/CCConfiguration.h"
2727
#include "3d/CCMeshVertexIndexData.h"
28-
#include "base/ccUtils.h"
2928

3029
NS_CC_BEGIN
3130

@@ -148,7 +147,7 @@ bool VertexAttribBinding::init(MeshIndexData* meshIndexData, GLProgramState* glP
148147
glBindVertexArray(_handle);
149148
glBindBuffer(GL_ARRAY_BUFFER, meshVertexData->getVertexBuffer()->getVBO());
150149

151-
utils::enableVertexAttributes(_vertexAttribsFlags);
150+
enableVertexAttributes(_vertexAttribsFlags);
152151

153152
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshIndexData->getIndexBuffer()->getVBO());
154153

@@ -181,7 +180,7 @@ void VertexAttribBinding::bind()
181180
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _meshIndexData->getIndexBuffer()->getVBO());
182181

183182
// Software mode
184-
utils::enableVertexAttributes(_vertexAttribsFlags);
183+
enableVertexAttributes(_vertexAttribsFlags);
185184
// set attributes
186185
for(auto &attribute : _attributes)
187186
{
@@ -227,6 +226,19 @@ void VertexAttribBinding::parseAttributes()
227226
}
228227
}
229228

229+
void VertexAttribBinding::enableVertexAttributes(uint32_t flags) const
230+
{
231+
auto tmpFlags = flags;
232+
for (int i = 0; tmpFlags > 0; i++)
233+
{
234+
int flag = 1 << i;
235+
if (flag & tmpFlags)
236+
glEnableVertexAttribArray(i);
237+
238+
tmpFlags &= ~flag;
239+
}
240+
}
241+
230242
VertexAttribValue* VertexAttribBinding::getVertexAttribValue(const std::string& name)
231243
{
232244
const auto itr = _attributes.find(name);

cocos/renderer/CCVertexAttribBinding.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class CC_DLL VertexAttribBinding : public Ref
108108
void setVertexAttribPointer(const std::string& name, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid* pointer);
109109
VertexAttribValue* getVertexAttribValue(const std::string &name);
110110
void parseAttributes();
111+
void enableVertexAttributes(uint32_t flags) const;
112+
111113

112114
GLuint _handle;
113115

cocos/scripting/lua-bindings/manual/cocos2d/LuaOpengl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "2d/CCDrawingPrimitives.h"
3737
#include "renderer/CCRenderer.h"
3838
#include "platform/CCGL.h"
39-
#include "base/ccUtils.h"
4039

4140
using namespace cocos2d;
4241

@@ -4406,7 +4405,7 @@ static int tolua_Cocos2d_glEnableVertexAttribs00(lua_State* tolua_S)
44064405
#endif
44074406
{
44084407
int arg0 = (int)tolua_tonumber(tolua_S, 1, 0);
4409-
cocos2d::utils::enableVertexAttributes(arg0);
4408+
glEnableVertexAttribArray(arg0);
44104409
}
44114410
return 0;
44124411
#ifndef TOLUA_RELEASE

tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void DrawNode3D::onDraw(const Mat4 &transform, uint32_t flags)
224224
glProgram->use();
225225
glProgram->setUniformsForBuiltins(transform);
226226
glEnable(GL_DEPTH_TEST);
227-
cocos2d::utils::setBlending(_blendFunc.src, _blendFunc.dst);
227+
glBlendFunc(_blendFunc.src, _blendFunc.dst);
228228

229229
if (_dirty)
230230
{

0 commit comments

Comments
 (0)