From 79eee9b14547b1375b9b002616f166154243ceae Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 20 Jan 2015 16:50:51 +0800 Subject: [PATCH] fix crash on windows --- cocos/2d/CCDrawNode.cpp | 34 +++++++++---------- cocos/2d/CCDrawNode.h | 2 +- cocos/renderer/CCGLProgram.cpp | 4 +-- cocos/renderer/CCGLProgram.h | 4 +-- cocos/renderer/CCGLProgramCache.cpp | 14 ++++---- ...ader_PositionColorTextureAsPointsize.vert} | 7 ++-- cocos/renderer/ccShaders.cpp | 2 +- cocos/renderer/ccShaders.h | 2 +- 8 files changed, 32 insertions(+), 37 deletions(-) rename cocos/renderer/{ccShader_PositionColorPointsize.vert => ccShader_PositionColorTextureAsPointsize.vert} (91%) diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 43c8e2dd97..ff8058bda9 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -185,7 +185,7 @@ void DrawNode::ensureCapacityGLPoint(int count) if(_bufferCountGLPoint + count > _bufferCapacityGLPoint) { _bufferCapacityGLPoint += MAX(_bufferCapacityGLPoint, count); - _bufferGLPoint = (V2F_C4B_PF*)realloc(_bufferGLPoint, _bufferCapacityGLPoint*sizeof(V2F_C4B_PF)); + _bufferGLPoint = (V2F_C4B_T2F*)realloc(_bufferGLPoint, _bufferCapacityGLPoint*sizeof(V2F_C4B_T2F)); } } @@ -254,15 +254,13 @@ bool DrawNode::init() glGenBuffers(1, &_vboGLPoint); glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint); glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW); + GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); // vertex - glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_PF), (GLvoid *)offsetof(V2F_C4B_PF, vertices)); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices)); // color - glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_PF), (GLvoid *)offsetof(V2F_C4B_PF, colors)); - // pointsize - glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POINTSIZE); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POINTSIZE, 1, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_PF), (GLvoid *)offsetof(V2F_C4B_PF, pointSize)); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors)); + // Texture coord as pointsize + 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, 0); if (Configuration::getInstance()->supportsShareableVAO()) @@ -389,14 +387,14 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags) void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags) { - auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_POINTSIZE); + auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE); glProgram->use(); glProgram->setUniformsForBuiltins(transform); if (_dirtyGLPoint) { glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint); - glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_PF)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW); _dirtyGLPoint = false; } @@ -408,10 +406,10 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags) 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_PF), (GLvoid *)offsetof(V2F_C4B_PF, vertices)); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_PF), (GLvoid *)offsetof(V2F_C4B_PF, colors)); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POINTSIZE, 1, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_PF), (GLvoid *)offsetof(V2F_C4B_PF, pointSize)); + GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + 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)); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 1, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords)); } glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint); @@ -425,8 +423,8 @@ void DrawNode::drawPoint(const Vec2& position, const float pointSize, const Colo { ensureCapacityGLPoint(1); - V2F_C4B_PF *point = (V2F_C4B_PF*)(_bufferGLPoint + _bufferCountGLPoint); - V2F_C4B_PF a = {position, Color4B(color), pointSize}; + V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint); + V2F_C4B_T2F a = {position, Color4B(color), Tex2F(pointSize,0)}; *point = a; _bufferCountGLPoint += 1; @@ -442,11 +440,11 @@ void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, con { ensureCapacityGLPoint(numberOfPoints); - V2F_C4B_PF *point = (V2F_C4B_PF*)(_bufferGLPoint + _bufferCountGLPoint); + V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint); for(unsigned int i=0; i < numberOfPoints; i++,point++) { - V2F_C4B_PF a = {position[i], Color4B(color), pointSize}; + V2F_C4B_T2F a = {position[i], Color4B(color), Tex2F(pointSize,0)}; *point = a; } diff --git a/cocos/2d/CCDrawNode.h b/cocos/2d/CCDrawNode.h index 4cff2d1fb8..c9257973e3 100644 --- a/cocos/2d/CCDrawNode.h +++ b/cocos/2d/CCDrawNode.h @@ -154,7 +154,7 @@ protected: int _bufferCapacityGLPoint; GLsizei _bufferCountGLPoint; - V2F_C4B_PF *_bufferGLPoint; + V2F_C4B_T2F *_bufferGLPoint; Color4F _pointColor; int _pointSize; diff --git a/cocos/renderer/CCGLProgram.cpp b/cocos/renderer/CCGLProgram.cpp index cef6a240a6..5788664a7a 100644 --- a/cocos/renderer/CCGLProgram.cpp +++ b/cocos/renderer/CCGLProgram.cpp @@ -50,7 +50,7 @@ const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP = "ShaderPositi const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST = "ShaderPositionTextureColorAlphaTest"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV = "ShaderPositionTextureColorAlphaTest_NoMV"; const char* GLProgram::SHADER_NAME_POSITION_COLOR = "ShaderPositionColor"; -const char* GLProgram::SHADER_NAME_POSITION_COLOR_POINTSIZE = "ShaderPositionColorPointsize"; +const char* GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE = "ShaderPositionColorTexAsPointsize"; const char* GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP = "ShaderPositionColor_noMVP"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE = "ShaderPositionTexture"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_U_COLOR = "ShaderPositionTexture_uColor"; @@ -90,7 +90,6 @@ const char* GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE = "CC_alpha_value"; // Attribute names const char* GLProgram::ATTRIBUTE_NAME_COLOR = "a_color"; const char* GLProgram::ATTRIBUTE_NAME_POSITION = "a_position"; -const char* GLProgram::ATTRIBUTE_NAME_POINTSIZE = "a_pointSize"; const char* GLProgram::ATTRIBUTE_NAME_TEX_COORD = "a_texCoord"; const char* GLProgram::ATTRIBUTE_NAME_TEX_COORD1 = "a_texCoord1"; const char* GLProgram::ATTRIBUTE_NAME_TEX_COORD2 = "a_texCoord2"; @@ -278,7 +277,6 @@ void GLProgram::bindPredefinedVertexAttribs() } attribute_locations[] = { {GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION}, - {GLProgram::ATTRIBUTE_NAME_POINTSIZE, GLProgram::VERTEX_ATTRIB_POINTSIZE}, {GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR}, {GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORD}, {GLProgram::ATTRIBUTE_NAME_TEX_COORD1, GLProgram::VERTEX_ATTRIB_TEX_COORD1}, diff --git a/cocos/renderer/CCGLProgram.h b/cocos/renderer/CCGLProgram.h index 9566846f5b..8955a370ff 100644 --- a/cocos/renderer/CCGLProgram.h +++ b/cocos/renderer/CCGLProgram.h @@ -89,7 +89,6 @@ public: VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_BLEND_INDEX, - VERTEX_ATTRIB_POINTSIZE, VERTEX_ATTRIB_MAX, // backward compatibility @@ -120,7 +119,7 @@ public: static const char* SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST; static const char* SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV; static const char* SHADER_NAME_POSITION_COLOR; - static const char* SHADER_NAME_POSITION_COLOR_POINTSIZE; + static const char* SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE; static const char* SHADER_NAME_POSITION_COLOR_NO_MVP; static const char* SHADER_NAME_POSITION_TEXTURE; static const char* SHADER_NAME_POSITION_TEXTURE_U_COLOR; @@ -161,7 +160,6 @@ public: // Attribute names static const char* ATTRIBUTE_NAME_COLOR; static const char* ATTRIBUTE_NAME_POSITION; - static const char* ATTRIBUTE_NAME_POINTSIZE; static const char* ATTRIBUTE_NAME_TEX_COORD; static const char* ATTRIBUTE_NAME_TEX_COORD1; static const char* ATTRIBUTE_NAME_TEX_COORD2; diff --git a/cocos/renderer/CCGLProgramCache.cpp b/cocos/renderer/CCGLProgramCache.cpp index da8d77fc8c..b2c557b829 100644 --- a/cocos/renderer/CCGLProgramCache.cpp +++ b/cocos/renderer/CCGLProgramCache.cpp @@ -40,7 +40,7 @@ enum { kShaderType_PositionTextureColorAlphaTest, kShaderType_PositionTextureColorAlphaTestNoMV, kShaderType_PositionColor, - kShaderType_PositionColorPointsize, + kShaderType_PositionColorTextureAsPointsize, kShaderType_PositionColor_noMVP, kShaderType_PositionTexture, kShaderType_PositionTexture_uColor, @@ -142,8 +142,8 @@ void GLProgramCache::loadDefaultGLPrograms() // Position, Color, PointSize shader p = new (std::nothrow) GLProgram(); - loadDefaultGLProgram(p, kShaderType_PositionColorPointsize); - _programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_COLOR_POINTSIZE, p) ); + loadDefaultGLProgram(p, kShaderType_PositionColorTextureAsPointsize); + _programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE, p) ); // // Position, Color shader no MVP @@ -261,9 +261,9 @@ void GLProgramCache::reloadDefaultGLPrograms() loadDefaultGLProgram(p, kShaderType_PositionColor); // Position, Color, PointSize shader - p = getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_POINTSIZE); + p = getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE); p->reset(); - loadDefaultGLProgram(p, kShaderType_PositionColorPointsize); + loadDefaultGLProgram(p, kShaderType_PositionColorTextureAsPointsize); // // Position, Color shader no MVP @@ -368,8 +368,8 @@ void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type) case kShaderType_PositionColor: p->initWithByteArrays(ccPositionColor_vert ,ccPositionColor_frag); break; - case kShaderType_PositionColorPointsize: - p->initWithByteArrays(ccPositionColorPointsize_vert ,ccPositionColor_frag); + case kShaderType_PositionColorTextureAsPointsize: + p->initWithByteArrays(ccPositionColorTextureAsPointsize_vert ,ccPositionColor_frag); break; case kShaderType_PositionColor_noMVP: p->initWithByteArrays(ccPositionTextureColor_noMVP_vert ,ccPositionColor_frag); diff --git a/cocos/renderer/ccShader_PositionColorPointsize.vert b/cocos/renderer/ccShader_PositionColorTextureAsPointsize.vert similarity index 91% rename from cocos/renderer/ccShader_PositionColorPointsize.vert rename to cocos/renderer/ccShader_PositionColorTextureAsPointsize.vert index f2f6fb04dd..485e80578a 100644 --- a/cocos/renderer/ccShader_PositionColorPointsize.vert +++ b/cocos/renderer/ccShader_PositionColorTextureAsPointsize.vert @@ -22,11 +22,12 @@ * THE SOFTWARE. */ -const char* ccPositionColorPointsize_vert = STRINGIFY( +const char* ccPositionColorTextureAsPointsize_vert = STRINGIFY( attribute vec4 a_position; attribute vec4 a_color; -attribute float a_pointSize; + +attribute vec2 a_texCoord; \n#ifdef GL_ES\n varying lowp vec4 v_fragmentColor; @@ -37,7 +38,7 @@ varying vec4 v_fragmentColor; void main() { gl_Position = CC_MVPMatrix * a_position; - gl_PointSize = a_pointSize; + gl_PointSize = a_texCoord.x; v_fragmentColor = a_color; } ); diff --git a/cocos/renderer/ccShaders.cpp b/cocos/renderer/ccShaders.cpp index 9a99144214..a12e466ec9 100644 --- a/cocos/renderer/ccShaders.cpp +++ b/cocos/renderer/ccShaders.cpp @@ -43,7 +43,7 @@ NS_CC_BEGIN #include "ccShader_PositionColor.vert" // -#include "ccShader_PositionColorPointsize.vert" +#include "ccShader_PositionColorTextureAsPointsize.vert" // #include "ccShader_PositionTexture.frag" diff --git a/cocos/renderer/ccShaders.h b/cocos/renderer/ccShaders.h index 931c5a4f3f..5737f1656f 100644 --- a/cocos/renderer/ccShaders.h +++ b/cocos/renderer/ccShaders.h @@ -42,7 +42,7 @@ extern CC_DLL const GLchar * ccPosition_uColor_vert; extern CC_DLL const GLchar * ccPositionColor_frag; extern CC_DLL const GLchar * ccPositionColor_vert; -extern CC_DLL const GLchar * ccPositionColorPointsize_vert; +extern CC_DLL const GLchar * ccPositionColorTextureAsPointsize_vert; extern CC_DLL const GLchar * ccPositionTexture_frag; extern CC_DLL const GLchar * ccPositionTexture_vert;