diff --git a/cocos/renderer/backend/opengl/ProgramGL.cpp b/cocos/renderer/backend/opengl/ProgramGL.cpp index 41a4ed09fc..840c09f2fd 100644 --- a/cocos/renderer/backend/opengl/ProgramGL.cpp +++ b/cocos/renderer/backend/opengl/ProgramGL.cpp @@ -1,5 +1,6 @@ /**************************************************************************** Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2020 c4games.com. http://www.cocos2d-x.org @@ -32,18 +33,18 @@ #include "renderer/backend/opengl/UtilsGL.h" CC_BACKEND_BEGIN + namespace { - std::string vsPreDefine("#version 100\n precision highp float;\n precision highp int;\n"); - std::string fsPreDefine("precision mediump float;\n precision mediump int;\n"); + static const std::string SHADER_PREDEFINE = "#version 100\n precision highp float;\n precision highp int;\n"; } ProgramGL::ProgramGL(const std::string& vertexShader, const std::string& fragmentShader) : Program(vertexShader, fragmentShader) { #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID - //some device required manually specify the precision qualifiers for vertex shader. - _vertexShaderModule = static_cast(ShaderCache::newVertexShaderModule(std::move(vsPreDefine + _vertexShader))); - _fragmentShaderModule = static_cast(ShaderCache::newFragmentShaderModule(std::move(fsPreDefine + _fragmentShader))); + // some device required manually specify the precision qualifiers for vertex shader. + _vertexShaderModule = static_cast(ShaderCache::newVertexShaderModule(std::move(SHADER_PREDEFINE + _vertexShader))); + _fragmentShaderModule = static_cast(ShaderCache::newFragmentShaderModule(std::move(SHADER_PREDEFINE + _fragmentShader))); #else _vertexShaderModule = static_cast(ShaderCache::newVertexShaderModule(_vertexShader)); _fragmentShaderModule = static_cast(ShaderCache::newFragmentShaderModule(_fragmentShader)); @@ -88,8 +89,8 @@ void ProgramGL::reloadProgram() _activeUniformInfos.clear(); _mapToCurrentActiveLocation.clear(); _mapToOriginalLocation.clear(); - static_cast(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, std::move(vsPreDefine + _vertexShader)); - static_cast(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, std::move(fsPreDefine + _fragmentShader)); + static_cast(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, std::move(SHADER_PREDEFINE + _vertexShader)); + static_cast(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, std::move(SHADER_PREDEFINE + _fragmentShader)); compileProgram(); computeUniformInfos(); diff --git a/cocos/renderer/shaders/positionTexture.frag b/cocos/renderer/shaders/positionTexture.frag index f745a2aca3..ecf94f1363 100644 --- a/cocos/renderer/shaders/positionTexture.frag +++ b/cocos/renderer/shaders/positionTexture.frag @@ -26,10 +26,10 @@ const char* positionTexture_frag = R"( #ifdef GL_ES -precision lowp float; -#endif - +varying mediump vec2 v_texCoord; +#else varying vec2 v_texCoord; +#endif uniform sampler2D u_texture; diff --git a/cocos/renderer/shaders/positionTextureColor.frag b/cocos/renderer/shaders/positionTextureColor.frag index 4cf0c5227f..2c4d8c557f 100644 --- a/cocos/renderer/shaders/positionTextureColor.frag +++ b/cocos/renderer/shaders/positionTextureColor.frag @@ -25,11 +25,12 @@ const char* positionTextureColor_frag = R"( #ifdef GL_ES -precision lowp float; -#endif - +varying lowp vec4 v_fragmentColor; +varying mediump vec2 v_texCoord; +#else varying vec4 v_fragmentColor; varying vec2 v_texCoord; +#endif uniform sampler2D u_texture; diff --git a/cocos/renderer/shaders/positionTextureUColor.frag b/cocos/renderer/shaders/positionTextureUColor.frag index 83ad898a45..f4ef3aa1a3 100644 --- a/cocos/renderer/shaders/positionTextureUColor.frag +++ b/cocos/renderer/shaders/positionTextureUColor.frag @@ -24,18 +24,17 @@ */ const char* positionTextureUColor_frag = R"( - #ifdef GL_ES -precision lowp float; +varying mediump vec2 v_texCoord; +#else +varying vec2 v_texCoord; #endif uniform vec4 u_color; -uinform sampler2D u_texture; - -varying vec2 v_texCoord; +uniform sampler2D u_texture; void main() { - gl_FragColor = texture2D(u_texture, v_texCoord) * u_color; + gl_FragColor = u_color * texture2D(u_texture, v_texCoord); } )";