fix shaders for OpenGL ES
This commit is contained in:
parent
a6b66e3f7e
commit
f89bc352d5
|
@ -79,7 +79,7 @@ IF(WIN32)
|
||||||
ENDIF(NO_CONSOLE)
|
ENDIF(NO_CONSOLE)
|
||||||
ELSE(WIN32)
|
ELSE(WIN32)
|
||||||
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic")
|
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic")
|
||||||
SET(ADDITIONAL_LIBRARIES pthread)
|
SET(ADDITIONAL_LIBRARIES pthread X11)
|
||||||
SET(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp)
|
SET(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp)
|
||||||
ENDIF(WIN32)
|
ENDIF(WIN32)
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,8 @@ void Painter::init()
|
||||||
setCompositionMode(CompositionMode_SourceOver);
|
setCompositionMode(CompositionMode_SourceOver);
|
||||||
|
|
||||||
PainterShaderProgramPtr program = PainterShaderProgramPtr(new PainterShaderProgram);
|
PainterShaderProgramPtr program = PainterShaderProgramPtr(new PainterShaderProgram);
|
||||||
program->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader);
|
program->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
||||||
program->addShaderFromSourceCode(Shader::Vertex, glslPositionOnlyVertexShader);
|
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslTextureSrcFragmentShader);
|
||||||
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader);
|
|
||||||
program->addShaderFromSourceCode(Shader::Fragment, glslTextureSrcFragmentShader);
|
|
||||||
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
|
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
|
||||||
program->bindAttributeLocation(TEXTURE_COORDS_ATTR, "textureCoord");
|
program->bindAttributeLocation(TEXTURE_COORDS_ATTR, "textureCoord");
|
||||||
assert(program->link());
|
assert(program->link());
|
||||||
|
@ -51,10 +49,8 @@ void Painter::init()
|
||||||
m_drawTexturedProgram = program;
|
m_drawTexturedProgram = program;
|
||||||
|
|
||||||
program = PainterShaderProgramPtr(new PainterShaderProgram);
|
program = PainterShaderProgramPtr(new PainterShaderProgram);
|
||||||
program->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader);
|
program->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader);
|
||||||
program->addShaderFromSourceCode(Shader::Vertex, glslPositionOnlyVertexShader);
|
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader);
|
||||||
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader);
|
|
||||||
program->addShaderFromSourceCode(Shader::Fragment, glslSolidColorFragmentShader);
|
|
||||||
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
|
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
|
||||||
assert(program->link());
|
assert(program->link());
|
||||||
program->bindUniformLocation(PainterShaderProgram::PROJECTION_MATRIX_UNIFORM, "projectionMatrix");
|
program->bindUniformLocation(PainterShaderProgram::PROJECTION_MATRIX_UNIFORM, "projectionMatrix");
|
||||||
|
|
|
@ -29,13 +29,13 @@ static int COLOR_UNIFORM = 2;
|
||||||
static int OPACITY_UNIFORM = 3;
|
static int OPACITY_UNIFORM = 3;
|
||||||
static int TEXTURE_UNIFORM = 4;
|
static int TEXTURE_UNIFORM = 4;
|
||||||
|
|
||||||
static const char *glslMainVertexShader = "\n\
|
static const std::string glslMainVertexShader = "\n\
|
||||||
vec4 calculatePosition();\n\
|
vec4 calculatePosition();\n\
|
||||||
void main() {\n\
|
void main() {\n\
|
||||||
gl_Position = calculatePosition();\n\
|
gl_Position = calculatePosition();\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static const char *glslMainWithTexCoordsVertexShader = "\n\
|
static const std::string glslMainWithTexCoordsVertexShader = "\n\
|
||||||
attribute vec2 textureCoord;\n\
|
attribute vec2 textureCoord;\n\
|
||||||
uniform mat2 textureTransformMatrix;\n\
|
uniform mat2 textureTransformMatrix;\n\
|
||||||
varying vec2 textureCoords;\n\
|
varying vec2 textureCoords;\n\
|
||||||
|
@ -46,14 +46,16 @@ static const char *glslMainWithTexCoordsVertexShader = "\n\
|
||||||
textureCoords = textureTransformMatrix * textureCoord;\n\
|
textureCoords = textureTransformMatrix * textureCoord;\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static const char *glslPositionOnlyVertexShader = "\n\
|
static std::string glslPositionOnlyVertexShader = "\n\
|
||||||
attribute vec2 vertexCoord;\n\
|
attribute vec2 vertexCoord;\n\
|
||||||
uniform mat3 projectionMatrix;\n\
|
uniform mat3 projectionMatrix;\n\
|
||||||
vec4 calculatePosition() {\n\
|
vec4 calculatePosition() {\n\
|
||||||
return vec4(projectionMatrix * vec3(vertexCoord.xy, 1), 1);\n\
|
return vec4(projectionMatrix * vec3(vertexCoord.xy, 1), 1);\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static const char *glslMainFragmentShader = "\n\
|
static const std::string glslMainFragmentShader = "\n\
|
||||||
|
precision lowp vec4;\n\
|
||||||
|
precision lowp float;\n\
|
||||||
uniform float opacity;\n\
|
uniform float opacity;\n\
|
||||||
vec4 calculatePixel();\n\
|
vec4 calculatePixel();\n\
|
||||||
void main()\n\
|
void main()\n\
|
||||||
|
@ -61,7 +63,8 @@ static const char *glslMainFragmentShader = "\n\
|
||||||
gl_FragColor = calculatePixel() * opacity;\n\
|
gl_FragColor = calculatePixel() * opacity;\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static const char *glslTextureSrcFragmentShader = "\n\
|
static const std::string glslTextureSrcFragmentShader = "\n\
|
||||||
|
precision mediump vec2;\n\
|
||||||
varying vec2 textureCoords;\n\
|
varying vec2 textureCoords;\n\
|
||||||
uniform vec4 color;\n\
|
uniform vec4 color;\n\
|
||||||
uniform sampler2D texture;\n\
|
uniform sampler2D texture;\n\
|
||||||
|
@ -69,7 +72,7 @@ static const char *glslTextureSrcFragmentShader = "\n\
|
||||||
return texture2D(texture, textureCoords) * color;\n\
|
return texture2D(texture, textureCoords) * color;\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static const char *glslSolidColorFragmentShader = "\n\
|
static const std::string glslSolidColorFragmentShader = "\n\
|
||||||
uniform vec4 color;\n\
|
uniform vec4 color;\n\
|
||||||
vec4 calculatePixel() {\n\
|
vec4 calculatePixel() {\n\
|
||||||
return color;\n\
|
return color;\n\
|
||||||
|
|
|
@ -340,7 +340,7 @@ void X11Window::internalChooseGLVisual()
|
||||||
m_rootWindow = RootWindow(m_display, m_visual->screen);
|
m_rootWindow = RootWindow(m_display, m_visual->screen);
|
||||||
#else
|
#else
|
||||||
static int attrList[] = {
|
static int attrList[] = {
|
||||||
EGL_BUFFER_SIZE, 24,
|
//EGL_BUFFER_SIZE, 24,
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue