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 int TEXTURE_UNIFORM = 4;
|
||||||
|
|
||||||
static const std::string glslMainVertexShader = "\n\
|
static const std::string glslMainVertexShader = "\n\
|
||||||
vec4 calculatePosition();\n\
|
highp vec4 calculatePosition();\n\
|
||||||
void main() {\n\
|
void main() {\n\
|
||||||
gl_Position = calculatePosition();\n\
|
gl_Position = calculatePosition();\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
@ -54,26 +54,23 @@ static std::string glslPositionOnlyVertexShader = "\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static const std::string glslMainFragmentShader = "\n\
|
static const std::string glslMainFragmentShader = "\n\
|
||||||
precision lowp vec4;\n\
|
uniform lowp float opacity;\n\
|
||||||
precision lowp float;\n\
|
lowp vec4 calculatePixel();\n\
|
||||||
uniform float opacity;\n\
|
|
||||||
vec4 calculatePixel();\n\
|
|
||||||
void main()\n\
|
void main()\n\
|
||||||
{\n\
|
{\n\
|
||||||
gl_FragColor = calculatePixel() * opacity;\n\
|
gl_FragColor = calculatePixel() * opacity;\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static const std::string glslTextureSrcFragmentShader = "\n\
|
static const std::string glslTextureSrcFragmentShader = "\n\
|
||||||
precision mediump vec2;\n\
|
varying mediump vec2 textureCoords;\n\
|
||||||
varying vec2 textureCoords;\n\
|
uniform lowp vec4 color;\n\
|
||||||
uniform vec4 color;\n\
|
|
||||||
uniform sampler2D texture;\n\
|
uniform sampler2D texture;\n\
|
||||||
vec4 calculatePixel() {\n\
|
vec4 calculatePixel() {\n\
|
||||||
return texture2D(texture, textureCoords) * color;\n\
|
return texture2D(texture, textureCoords) * color;\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static const std::string glslSolidColorFragmentShader = "\n\
|
static const std::string glslSolidColorFragmentShader = "\n\
|
||||||
uniform vec4 color;\n\
|
uniform lowp vec4 color;\n\
|
||||||
vec4 calculatePixel() {\n\
|
vec4 calculatePixel() {\n\
|
||||||
return color;\n\
|
return color;\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
|
@ -45,7 +45,21 @@ Shader::~Shader()
|
||||||
|
|
||||||
bool Shader::compileSourceCode(const std::string& sourceCode)
|
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);
|
glShaderSource(m_shaderId, 1, &c_source, NULL);
|
||||||
glCompileShader(m_shaderId);
|
glCompileShader(m_shaderId);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue