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) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
||||||
|
Copyright (c) 2020 c4games.com.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
@ -32,18 +33,18 @@
|
||||||
#include "renderer/backend/opengl/UtilsGL.h"
|
#include "renderer/backend/opengl/UtilsGL.h"
|
||||||
|
|
||||||
CC_BACKEND_BEGIN
|
CC_BACKEND_BEGIN
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::string vsPreDefine("#version 100\n precision highp float;\n precision highp int;\n");
|
static const std::string SHADER_PREDEFINE = "#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.
|
||||||
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(std::move(vsPreDefine + _vertexShader)));
|
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(std::move(SHADER_PREDEFINE + _vertexShader)));
|
||||||
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(std::move(fsPreDefine + _fragmentShader)));
|
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(std::move(SHADER_PREDEFINE + _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));
|
||||||
|
@ -88,8 +89,8 @@ void ProgramGL::reloadProgram()
|
||||||
_activeUniformInfos.clear();
|
_activeUniformInfos.clear();
|
||||||
_mapToCurrentActiveLocation.clear();
|
_mapToCurrentActiveLocation.clear();
|
||||||
_mapToOriginalLocation.clear();
|
_mapToOriginalLocation.clear();
|
||||||
static_cast<ShaderModuleGL*>(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, std::move(vsPreDefine + _vertexShader));
|
static_cast<ShaderModuleGL*>(_vertexShaderModule)->compileShader(backend::ShaderStage::VERTEX, std::move(SHADER_PREDEFINE + _vertexShader));
|
||||||
static_cast<ShaderModuleGL*>(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, std::move(fsPreDefine + _fragmentShader));
|
static_cast<ShaderModuleGL*>(_fragmentShaderModule)->compileShader(backend::ShaderStage::FRAGMENT, std::move(SHADER_PREDEFINE + _fragmentShader));
|
||||||
compileProgram();
|
compileProgram();
|
||||||
computeUniformInfos();
|
computeUniformInfos();
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@
|
||||||
const char* positionTexture_frag = R"(
|
const char* positionTexture_frag = R"(
|
||||||
|
|
||||||
#ifdef GL_ES
|
#ifdef GL_ES
|
||||||
precision lowp float;
|
varying mediump vec2 v_texCoord;
|
||||||
#endif
|
#else
|
||||||
|
|
||||||
varying vec2 v_texCoord;
|
varying vec2 v_texCoord;
|
||||||
|
#endif
|
||||||
|
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,12 @@
|
||||||
|
|
||||||
const char* positionTextureColor_frag = R"(
|
const char* positionTextureColor_frag = R"(
|
||||||
#ifdef GL_ES
|
#ifdef GL_ES
|
||||||
precision lowp float;
|
varying lowp vec4 v_fragmentColor;
|
||||||
#endif
|
varying mediump vec2 v_texCoord;
|
||||||
|
#else
|
||||||
varying vec4 v_fragmentColor;
|
varying vec4 v_fragmentColor;
|
||||||
varying vec2 v_texCoord;
|
varying vec2 v_texCoord;
|
||||||
|
#endif
|
||||||
|
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
|
|
@ -24,18 +24,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char* positionTextureUColor_frag = R"(
|
const char* positionTextureUColor_frag = R"(
|
||||||
|
|
||||||
#ifdef GL_ES
|
#ifdef GL_ES
|
||||||
precision lowp float;
|
varying mediump vec2 v_texCoord;
|
||||||
|
#else
|
||||||
|
varying vec2 v_texCoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform vec4 u_color;
|
uniform vec4 u_color;
|
||||||
uinform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
varying vec2 v_texCoord;
|
|
||||||
|
|
||||||
void main()
|
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