mirror of https://github.com/axmolengine/axmol.git
Merge pull request #72 from c4games/sync-v3-pr20107
Sync v3 pr20107 & fix builtin shaders
This commit is contained in:
commit
23b3deaa23
|
@ -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<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));
|
||||
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
)";
|
||||
|
|
Loading…
Reference in New Issue