cocos2d / cocos2d-x-samples

Contains different cocos2d-x samples
MIT License
576 stars 242 forks source link

gl_PointCoord can not be supported on windows and linux for openGL 2.0 #32

Closed dabingnn closed 7 years ago

dabingnn commented 9 years ago

@ricardoquesada Heard from minggo, that you have a solution for this. Could you please take a look at it?

ricardoquesada commented 9 years ago

Yes, gl_PointCoord is available on OpenGL ES 2.0, and it is available on OpenGL as well, but only with the shading language version 1.1 or newer. https://www.opengl.org/sdk/docs/man/html/gl_PointCoord.xhtml

So, the way to fix it is by adding `

version 1.1

`

at the very beginning of the shader... but only on OpenGL shaders (not OpenGL ES).

Since cocos2d pre-pends some code to all shaders, probably we should add a function that says something like:

GLProgram::setOpenGLSLversion(foat version);

of something like that.

samuele3hu commented 9 years ago

I have add #version 110 at the beginnig of the shader only to check the crash on win32 , like this

bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source)
{
    ...
    const GLchar *sources[] = {
        "#version 110 \n"
    ...
}

And the test case still crashed.

ricardoquesada commented 9 years ago

what error did you get ? have you tried on Mac ?

samuele3hu commented 9 years ago

The errors on the win32 as follows:

cocos2d: ERROR: Failed to compile shader:
#version 110 

uniform mat4 CC_PMatrix;
uniform mat4 CC_MVMatrix;
uniform mat4 CC_MVPMatrix;
uniform mat3 CC_NormalMatrix;
uniform vec4 CC_Time;
uniform vec4 CC_SinTime;
uniform vec4 CC_CosTime;
uniform vec4 CC_Random01;
uniform sampler2D CC_Texture0;
uniform sampler2D CC_Texture1;
uniform sampler2D CC_Texture2;
uniform sampler2D CC_Texture3;
//CC INCLUDES END

#ifdef GL_ES precision lowp float; #endif void main() { gl_FragColor = texture2D(CC_Texture0, gl_PointCoord); }

First-chance exception at 0x62AE8F20 (glew32.dll) in LiquidFun-EyeCandy.exe: 0xC0000005: Access violation executing location 0x62AE8F20.
Unhandled exception at 0x62AE8F20 (glew32.dll) in LiquidFun-EyeCandy.exe: 0xC0000005: Access violation executing location 0x62AE8F20.

The errors on the Mac as follows:

ocos2d: cocos2d: ERROR: Failed to compile shader:
#version 110 

uniform mat4 CC_PMatrix;
uniform mat4 CC_MVMatrix;
uniform mat4 CC_MVPMatrix;
uniform mat3 CC_NormalMatrix;
uniform vec4 CC_Time;
uniform vec4 CC_SinTime;
uniform vec4 CC_CosTime;
uniform vec4 CC_Random01;
uniform sampler2D CC_Texture0;
uniform sampler2D CC_Texture1;
uniform sampler2D CC_Texture2;
uniform sampler2D CC_Texture3;
//CC INCLUDES END

void main() { gl_FragColor = texture2D(CC_Texture0, gl_PointCoord); }

cocos2d: cocos2d: ERROR: 0:17: Use of undeclared identifier 'gl_PointCoord'

cocos2d: cocos2d: ERROR: Failed to compile fragment shader
cocos2d: Assert failed: invalid shader
pinguo-huangliang commented 8 years ago

I have the same problem when compile shader

octachrome commented 7 years ago

I had a similar problem. For me, it was resolved by specifying version 1.2, not 1.1:

#version 120
minggo commented 7 years ago

I can not find where is gl_PointCoord being used in latest codes. @octachrome could you please show me where it is used? Thanks.

octachrome commented 7 years ago

@minggo Sorry, I am not actually using cocos2d. My post was a general solution for how to compile a shader which uses gl_PointCoord. There is a mistake in the OpenGL docs which state that gl_PointCoord is a 1.1 feature, whereas in fact it was introduced in 1.2.

minggo commented 7 years ago

@octachrome good to know, thanks. I will close this issue since gl_PointCoord is not used anymore.