Skip to content

Commit

Permalink
Sync v3 pr20107 & fix builtin shaders, see: cocos2d/cocos2d-x#20107
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Feb 24, 2020
1 parent f0d60d4 commit d9e6cb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
15 changes: 8 additions & 7 deletions cocos/renderer/backend/opengl/ProgramGL.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/****************************************************************************
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2020 c4games.com.
http://www.cocos2d-x.org
Expand Down Expand Up @@ -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<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(std::move(vsPreDefine + _vertexShader)));
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(std::move(fsPreDefine + _fragmentShader)));
// some device required manually specify the precision qualifiers for vertex shader.
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(std::move(SHADER_PREDEFINE + _vertexShader)));
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(std::move(SHADER_PREDEFINE + _fragmentShader)));
#else
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(_vertexShader));
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(_fragmentShader));
Expand Down Expand Up @@ -88,8 +89,8 @@ void ProgramGL::reloadProgram()
_activeUniformInfos.clear();
_mapToCurrentActiveLocation.clear();
_mapToOriginalLocation.clear();
static_cast<ShaderModuleGL*>(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, std::move(vsPreDefine + _vertexShader));
static_cast<ShaderModuleGL*>(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, std::move(fsPreDefine + _fragmentShader));
static_cast<ShaderModuleGL*>(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, std::move(SHADER_PREDEFINE + _vertexShader));
static_cast<ShaderModuleGL*>(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, std::move(SHADER_PREDEFINE + _fragmentShader));
compileProgram();
computeUniformInfos();

Expand Down
6 changes: 3 additions & 3 deletions cocos/renderer/shaders/positionTexture.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 4 additions & 3 deletions cocos/renderer/shaders/positionTextureColor.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 5 additions & 6 deletions cocos/renderer/shaders/positionTextureUColor.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
)";

0 comments on commit d9e6cb8

Please sign in to comment.