From dd6bb0b3eb72288295688d9cabba1ad4d8423fca Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 23 Oct 2014 10:18:09 +0800 Subject: [PATCH 1/3] Uses reference in for loop inside ccvector_std_string_to_luaval --- cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp b/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp index e8f82d9faa..634baf4e97 100644 --- a/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp +++ b/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp @@ -2922,7 +2922,7 @@ void ccvector_std_string_to_luaval(lua_State* L, const std::vector& int index = 1; - for (const std::string value : inValue) + for (const std::string& value : inValue) { lua_pushnumber(L, (lua_Number)index); lua_pushstring(L, value.c_str()); From 603700179e34bd8967900bb0402e34c7e7bea076 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 24 Oct 2014 12:03:11 +0800 Subject: [PATCH 2/3] closed #8843: Fixes DrawNode::drawPoint crash and uses VAO if it's available when draw points. --- cocos/2d/CCDrawNode.cpp | 36 +++++++++++++------ .../DrawPrimitivesTest/DrawPrimitivesTest.cpp | 4 +++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index eae022bea6..3edbe0bbac 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -346,9 +346,8 @@ void DrawNode::onDraw(const Mat4 &transform, uint32_t flags) // texcood glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords)); } - glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glDrawArrays(GL_TRIANGLES, 0, _bufferCount); - glBindBuffer(GL_ARRAY_BUFFER, 0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCount); CHECK_GL_ERROR_DEBUG(); @@ -382,9 +381,7 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags) glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords)); } glLineWidth(2); - glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine); glDrawArrays(GL_LINES, 0, _bufferCountGLLine); - glBindBuffer(GL_ARRAY_BUFFER, 0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLLine); CHECK_GL_ERROR_DEBUG(); @@ -399,15 +396,28 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags) glProgram->setUniformLocationWith4fv(glProgram->getUniformLocation("u_color"), (GLfloat*) &_pointColor.r, 1); glProgram->setUniformLocationWith1f(glProgram->getUniformLocation("u_pointSize"), _pointSize); - glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint); - glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW); - - GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices)); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors)); + if (_dirtyGLPoint) + { + glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint); + glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW); + + _dirtyGLPoint = false; + } + + if (Configuration::getInstance()->supportsShareableVAO()) + { + GL::bindVAO(_vaoGLPoint); + } + else + { + glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint); + GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices)); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors)); + glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint); + } glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint); - glBindBuffer(GL_ARRAY_BUFFER, 0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLPoint); CHECK_GL_ERROR_DEBUG(); @@ -415,6 +425,8 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags) void DrawNode::drawPoint(const Vec2& position, const float pointSize, const Color4F &color) { + ensureCapacityGLPoint(1); + V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint); V2F_C4B_T2F a = {position, Color4B(color), Tex2F(0.0, 0.0) }; *point = a; @@ -423,6 +435,7 @@ void DrawNode::drawPoint(const Vec2& position, const float pointSize, const Colo _pointColor = color; _bufferCountGLPoint += 1; + _dirtyGLPoint = true; } void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, const Color4F &color) @@ -440,6 +453,7 @@ void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, con _pointColor = color; _bufferCountGLPoint += numberOfPoints; + _dirtyGLPoint = true; } void DrawNode::drawLine(const Vec2 &origin, const Vec2 &destination, const Color4F &color) diff --git a/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index af4e47a407..b213915745 100644 --- a/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -375,6 +375,10 @@ DrawNodeTest::DrawNodeTest() // Draw triangle draw->drawTriangle(Vec2(10, 10), Vec2(70, 30), Vec2(100, 140), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5)); + + for (int i = 0; i < 100; i++) { + draw->drawPoint(Vec2(i*7, 5), 5, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1)); + } } string DrawNodeTest::title() const From 13b51f7c73cfa7070669be3ffc132566cd1f8e2f Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 24 Oct 2014 12:03:42 +0800 Subject: [PATCH 3/3] Small fixes in Sprite3DTest --- tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 8e79b5b1f3..a282f2c15c 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -1259,7 +1259,7 @@ void Sprite3DWithOBBPerfromanceTest::addNewOBBWithCoords(Vec2 p) void Sprite3DWithOBBPerfromanceTest::onTouchesBegan(const std::vector& touches, Event* event) { - for (auto touch: touches) + for (const auto& touch: touches) { auto location = touch->getLocationInView(); auto obbSize = _obb.size(); @@ -1287,7 +1287,7 @@ void Sprite3DWithOBBPerfromanceTest::onTouchesEnded(const std::vector& t void Sprite3DWithOBBPerfromanceTest::onTouchesMoved(const std::vector& touches, Event* event) { - for (auto touch: touches) + for (const auto& touch: touches) { auto location = touch->getLocation(); auto obbSize = _obb.size(); @@ -1447,8 +1447,7 @@ void Sprite3DWithOBBPerfromanceTest::calculateRayByLocationInView(Ray* ray, cons { auto dir = Director::getInstance(); auto view = dir->getWinSize(); - Mat4 mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + Mat4 mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); Vec3 src = Vec3(location.x, location.y, -1); Vec3 nearPoint;