Merge pull request #10115 from dabingnn/FixCrashOnWin32

Fix crash on win32
This commit is contained in:
minggo 2015-01-21 10:34:22 +08:00
commit 372b11422d
10 changed files with 38 additions and 40 deletions

View File

@ -2923,7 +2923,6 @@
50FCEB9018C72017004AD434 /* WidgetReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WidgetReader.cpp; sourceTree = "<group>"; };
50FCEB9118C72017004AD434 /* WidgetReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WidgetReader.h; sourceTree = "<group>"; };
50FCEB9218C72017004AD434 /* WidgetReaderProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WidgetReaderProtocol.h; sourceTree = "<group>"; };
5224EE741A64FEC900D447D8 /* ccShader_PositionColorPointsize.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_PositionColorPointsize.vert; sourceTree = "<group>"; };
52B47A1D1A53489B004E4C60 /* HttpClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HttpClient.cpp; sourceTree = "<group>"; };
52B47A291A5349A3004E4C60 /* HttpAsynConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HttpAsynConnection.h; sourceTree = "<group>"; };
52B47A2A1A5349A3004E4C60 /* HttpAsynConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HttpAsynConnection.m; sourceTree = "<group>"; };
@ -2935,6 +2934,7 @@
5E9F61241A3FFE3D0038DE01 /* CCPlane.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPlane.cpp; sourceTree = "<group>"; };
5E9F61251A3FFE3D0038DE01 /* CCPlane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPlane.h; sourceTree = "<group>"; };
A07A4D641783777C0073F6A7 /* libcocos2d iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libcocos2d iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
B20564AA1A6E5744001C1B6E /* ccShader_PositionColorTextureAsPointsize.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_PositionColorTextureAsPointsize.vert; sourceTree = "<group>"; };
B217703B1977ECB4009EE11B /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
B217703D1977ECC1009EE11B /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
B217703F1977ECE6009EE11B /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
@ -4878,7 +4878,7 @@
5034CA5D191D591900CE6051 /* shaders */ = {
isa = PBXGroup;
children = (
5224EE741A64FEC900D447D8 /* ccShader_PositionColorPointsize.vert */,
B20564AA1A6E5744001C1B6E /* ccShader_PositionColorTextureAsPointsize.vert */,
B67C624319D4186F00F11FC6 /* ccShader_3D_ColorNormal.frag */,
B67C624419D4186F00F11FC6 /* ccShader_3D_ColorNormalTex.frag */,
B67C624519D4186F00F11FC6 /* ccShader_3D_PositionNormalTex.vert */,

View File

@ -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));
}
}
@ -253,16 +253,16 @@ bool DrawNode::init()
}
glGenBuffers(1, &_vboGLPoint);
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);
// 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
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
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 +389,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 +408,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, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
}
glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint);
@ -425,8 +425,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 +442,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;
}

View File

@ -154,7 +154,7 @@ protected:
int _bufferCapacityGLPoint;
GLsizei _bufferCountGLPoint;
V2F_C4B_PF *_bufferGLPoint;
V2F_C4B_T2F *_bufferGLPoint;
Color4F _pointColor;
int _pointSize;

View File

@ -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";
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || defined(WP8_SHADER_COMPILER)
const char* GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP_GRAYSCALE = "ShaderPositionColor_noMVP_GrayScale";
@ -93,7 +93,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";
@ -281,7 +280,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},

View File

@ -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;
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || defined(WP8_SHADER_COMPILER)
static const char* SHADER_NAME_POSITION_COLOR_NO_MVP_GRAYSCALE;
@ -164,7 +163,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;

View File

@ -44,7 +44,7 @@ enum {
kShaderType_PositionTextureColorAlphaTest,
kShaderType_PositionTextureColorAlphaTestNoMV,
kShaderType_PositionColor,
kShaderType_PositionColorPointsize,
kShaderType_PositionColorTextureAsPointsize,
kShaderType_PositionColor_noMVP,
kShaderType_PositionTexture,
kShaderType_PositionTexture_uColor,
@ -149,8 +149,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
@ -275,9 +275,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
@ -381,8 +381,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);

View File

@ -22,11 +22,11 @@
* 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;

View File

@ -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;
}
);

View File

@ -43,10 +43,11 @@ NS_CC_BEGIN
#include "ccShader_PositionColor.vert"
//
#ifdef CC_NO_GL_POINTSIZE
#include "ccShader_PositionColorPointsize-no-gl_PointSize.vert"
#else
#include "ccShader_PositionColorPointsize.vert"
#include "ccShader_PositionColorTextureAsPointsize.vert"
#endif
//

View File

@ -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;