mirror of https://github.com/axmolengine/axmol.git
Merge pull request #8918 from dumganhar/iss8843-drawpoint
closed #8843: Fixes DrawNode::drawPoint crash and uses VAO if it's available when draw points.
This commit is contained in:
commit
baff367c94
|
@ -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);
|
||||
|
||||
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)
|
||||
|
|
|
@ -2922,7 +2922,7 @@ void ccvector_std_string_to_luaval(lua_State* L, const std::vector<std::string>&
|
|||
|
||||
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());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1259,7 +1259,7 @@ void Sprite3DWithOBBPerfromanceTest::addNewOBBWithCoords(Vec2 p)
|
|||
|
||||
void Sprite3DWithOBBPerfromanceTest::onTouchesBegan(const std::vector<Touch*>& 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<Touch*>& t
|
|||
|
||||
void Sprite3DWithOBBPerfromanceTest::onTouchesMoved(const std::vector<Touch*>& 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;
|
||||
|
|
Loading…
Reference in New Issue