diff --git a/cocos/renderer/backend/opengl/ProgramGL.cpp b/cocos/renderer/backend/opengl/ProgramGL.cpp index ae6f222d4c..2b13e6693c 100644 --- a/cocos/renderer/backend/opengl/ProgramGL.cpp +++ b/cocos/renderer/backend/opengl/ProgramGL.cpp @@ -32,21 +32,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"); +} 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. - 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"); - vsPreDefine.append(vertexShader); - fsPreDefine.append(fragmentShader); - _vertexShader = std::move(vsPreDefine); - _fragmentShader = std::move(fsPreDefine); - _vertexShaderModule = static_cast(ShaderCache::newVertexShaderModule(_vertexShader)); - _fragmentShaderModule = static_cast(ShaderCache::newFragmentShaderModule(_fragmentShader)); + _vertexShaderModule = static_cast(ShaderCache::newVertexShaderModule(std::move(vsPreDefine + _vertexShader))); + _fragmentShaderModule = static_cast(ShaderCache::newFragmentShaderModule(std::move(fsPreDefine + _fragmentShader))); #else _vertexShaderModule = static_cast(ShaderCache::newVertexShaderModule(_vertexShader)); _fragmentShaderModule = static_cast(ShaderCache::newFragmentShaderModule(_fragmentShader)); @@ -91,8 +88,8 @@ void ProgramGL::reloadProgram() _activeUniformInfos.clear(); _mapToCurrentActiveLocation.clear(); _mapToOriginalLocation.clear(); - static_cast(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, _vertexShader); - static_cast(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, _fragmentShader); + static_cast(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, std::move(vsPreDefine + _vertexShader)); + static_cast(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, std::move(fsPreDefine + _fragmentShader)); compileProgram(); computeUniformInfos();