fix shaders for OpenGL ES
This commit is contained in:
parent
f89bc352d5
commit
b37a34219d
|
@ -30,7 +30,7 @@ static int OPACITY_UNIFORM = 3;
|
|||
static int TEXTURE_UNIFORM = 4;
|
||||
|
||||
static const std::string glslMainVertexShader = "\n\
|
||||
vec4 calculatePosition();\n\
|
||||
highp vec4 calculatePosition();\n\
|
||||
void main() {\n\
|
||||
gl_Position = calculatePosition();\n\
|
||||
}\n";
|
||||
|
@ -54,26 +54,23 @@ static std::string glslPositionOnlyVertexShader = "\n\
|
|||
}\n";
|
||||
|
||||
static const std::string glslMainFragmentShader = "\n\
|
||||
precision lowp vec4;\n\
|
||||
precision lowp float;\n\
|
||||
uniform float opacity;\n\
|
||||
vec4 calculatePixel();\n\
|
||||
uniform lowp float opacity;\n\
|
||||
lowp vec4 calculatePixel();\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
gl_FragColor = calculatePixel() * opacity;\n\
|
||||
}\n";
|
||||
|
||||
static const std::string glslTextureSrcFragmentShader = "\n\
|
||||
precision mediump vec2;\n\
|
||||
varying vec2 textureCoords;\n\
|
||||
uniform vec4 color;\n\
|
||||
varying mediump vec2 textureCoords;\n\
|
||||
uniform lowp vec4 color;\n\
|
||||
uniform sampler2D texture;\n\
|
||||
vec4 calculatePixel() {\n\
|
||||
return texture2D(texture, textureCoords) * color;\n\
|
||||
}\n";
|
||||
|
||||
static const std::string glslSolidColorFragmentShader = "\n\
|
||||
uniform vec4 color;\n\
|
||||
uniform lowp vec4 color;\n\
|
||||
vec4 calculatePixel() {\n\
|
||||
return color;\n\
|
||||
}\n";
|
||||
|
|
|
@ -45,7 +45,21 @@ Shader::~Shader()
|
|||
|
||||
bool Shader::compileSourceCode(const std::string& sourceCode)
|
||||
{
|
||||
const char *c_source = sourceCode.c_str();
|
||||
#ifndef OPENGL_ES2
|
||||
static const char *qualifierDefines =
|
||||
"#define lowp\n"
|
||||
"#define mediump\n"
|
||||
"#define highp\n";
|
||||
#else
|
||||
static const char *qualifierDefines =
|
||||
"#ifndef GL_FRAGMENT_PRECISION_HIGH\n"
|
||||
"#define highp mediump\n"
|
||||
"#endif\n";
|
||||
#endif
|
||||
|
||||
std::string code = qualifierDefines;
|
||||
code.append(sourceCode);
|
||||
const char *c_source = code.c_str();
|
||||
glShaderSource(m_shaderId, 1, &c_source, NULL);
|
||||
glCompileShader(m_shaderId);
|
||||
|
||||
|
|
Loading…
Reference in New Issue