fix shader header defines (#20077)

This commit is contained in:
coulsonwang 2019-09-04 09:56:28 +08:00 committed by minggo
parent b4d0522116
commit f97717265b
1 changed files with 8 additions and 11 deletions

View File

@ -32,21 +32,18 @@
#include "renderer/backend/opengl/UtilsGL.h" #include "renderer/backend/opengl/UtilsGL.h"
CC_BACKEND_BEGIN 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) ProgramGL::ProgramGL(const std::string& vertexShader, const std::string& fragmentShader)
: Program(vertexShader, fragmentShader) : Program(vertexShader, fragmentShader)
{ {
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
//some device required manually specify the precision qualifiers for vertex shader. //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"); _vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(std::move(vsPreDefine + _vertexShader)));
std::string fsPreDefine("precision mediump float;\n precision mediump int;\n"); _fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(std::move(fsPreDefine + _fragmentShader)));
vsPreDefine.append(vertexShader);
fsPreDefine.append(fragmentShader);
_vertexShader = std::move(vsPreDefine);
_fragmentShader = std::move(fsPreDefine);
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(_vertexShader));
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(_fragmentShader));
#else #else
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(_vertexShader)); _vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(_vertexShader));
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(_fragmentShader)); _fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(_fragmentShader));
@ -91,8 +88,8 @@ void ProgramGL::reloadProgram()
_activeUniformInfos.clear(); _activeUniformInfos.clear();
_mapToCurrentActiveLocation.clear(); _mapToCurrentActiveLocation.clear();
_mapToOriginalLocation.clear(); _mapToOriginalLocation.clear();
static_cast<ShaderModuleGL*>(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, _vertexShader); static_cast<ShaderModuleGL*>(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, std::move(vsPreDefine + _vertexShader));
static_cast<ShaderModuleGL*>(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, _fragmentShader); static_cast<ShaderModuleGL*>(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, std::move(fsPreDefine + _fragmentShader));
compileProgram(); compileProgram();
computeUniformInfos(); computeUniformInfos();