i want to enable GL_OES_standard_derivatives
for my shader in order to have more functions which I need for the following:
const char* ccPositionColorLengthTexture_frag = R"(
#ifdef GL_ES
#extension GL_OES_standard_derivatives : enable
varying mediump vec4 v_color;
varying mediump vec2 v_texcoord;
#else
varying vec4 v_color;
varying vec2 v_texcoord;
#endif
void main()
{
#if defined GL_OES_standard_derivatives
gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord));
#else
gl_FragColor = v_color*step(0.0, 1.0 - length(v_texcoord));
#endif
}
)";
I got the following error:
ERROR: 0:22: ββ : syntax error: #extension must always be before any
non-preprocessor tokens
If I comment out the #extension line and just have this code:
gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord));
I got:
Invalid call of undeclared identifier βfwidthβ
In the CCGlprogramm.h I found the following comment:
Create or Initializes the GLProgram with a vertex and fragment with
bytes array, with shader headers definition(eg. #version β¦ or #extension β¦), with compileTimeDefines(eg. #define β¦).
static GLProgram* createWithByteArrays(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray, const std::string& compileTimeHeaders, const std::string& compileTimeDefines);
I also tried to add the #extension
line in the predefined headers in the bool GLProgram::compileShader
function like so:
if (compileTimeHeaders.empty()) {
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
headersDef = (type == GL_VERTEX_SHADER ? "precision mediump float;\n precision mediump int;\n" : "precision mediump float;\n precision mediump int;\n");
#elif (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && CC_TARGET_PLATFORM != CC_PLATFORM_LINUX && CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
headersDef = (type == GL_VERTEX_SHADER ? "precision highp float;\n precision highp int;\n" : "#extension GL_OES_standard_derivatives : enable;\n precision mediump float;\n precision mediump int;\n");
#endif
}else{
headersDef = compileTimeHeaders;
}
The following error appears:
cocos2d: ERROR: 0:1: ββ : syntax error: #extension
I want to enable the GL_OES_standard_derivatives
cause it seems like the solution for the antialiasing problem of the DrawNode
. I found this which is more or less the same for Cocos2d-Iphone.
Can someone give me an advice here.