fix shaders for OpenGL ES

This commit is contained in:
Eduardo Bart 2011-12-06 23:48:39 -02:00
parent a6b66e3f7e
commit f89bc352d5
4 changed files with 15 additions and 16 deletions

View File

@ -79,7 +79,7 @@ IF(WIN32)
ENDIF(NO_CONSOLE)
ELSE(WIN32)
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)
ENDIF(WIN32)

View File

@ -36,10 +36,8 @@ void Painter::init()
setCompositionMode(CompositionMode_SourceOver);
PainterShaderProgramPtr program = PainterShaderProgramPtr(new PainterShaderProgram);
program->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader);
program->addShaderFromSourceCode(Shader::Vertex, glslPositionOnlyVertexShader);
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader);
program->addShaderFromSourceCode(Shader::Fragment, glslTextureSrcFragmentShader);
program->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslTextureSrcFragmentShader);
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
program->bindAttributeLocation(TEXTURE_COORDS_ATTR, "textureCoord");
assert(program->link());
@ -51,10 +49,8 @@ void Painter::init()
m_drawTexturedProgram = program;
program = PainterShaderProgramPtr(new PainterShaderProgram);
program->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader);
program->addShaderFromSourceCode(Shader::Vertex, glslPositionOnlyVertexShader);
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader);
program->addShaderFromSourceCode(Shader::Fragment, glslSolidColorFragmentShader);
program->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader);
program->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader);
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
assert(program->link());
program->bindUniformLocation(PainterShaderProgram::PROJECTION_MATRIX_UNIFORM, "projectionMatrix");

View File

@ -29,13 +29,13 @@ static int COLOR_UNIFORM = 2;
static int OPACITY_UNIFORM = 3;
static int TEXTURE_UNIFORM = 4;
static const char *glslMainVertexShader = "\n\
static const std::string glslMainVertexShader = "\n\
vec4 calculatePosition();\n\
void main() {\n\
gl_Position = calculatePosition();\n\
}\n";
static const char *glslMainWithTexCoordsVertexShader = "\n\
static const std::string glslMainWithTexCoordsVertexShader = "\n\
attribute vec2 textureCoord;\n\
uniform mat2 textureTransformMatrix;\n\
varying vec2 textureCoords;\n\
@ -46,14 +46,16 @@ static const char *glslMainWithTexCoordsVertexShader = "\n\
textureCoords = textureTransformMatrix * textureCoord;\n\
}\n";
static const char *glslPositionOnlyVertexShader = "\n\
static std::string glslPositionOnlyVertexShader = "\n\
attribute vec2 vertexCoord;\n\
uniform mat3 projectionMatrix;\n\
vec4 calculatePosition() {\n\
return vec4(projectionMatrix * vec3(vertexCoord.xy, 1), 1);\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\
vec4 calculatePixel();\n\
void main()\n\
@ -61,7 +63,8 @@ static const char *glslMainFragmentShader = "\n\
gl_FragColor = calculatePixel() * opacity;\n\
}\n";
static const char *glslTextureSrcFragmentShader = "\n\
static const std::string glslTextureSrcFragmentShader = "\n\
precision mediump vec2;\n\
varying vec2 textureCoords;\n\
uniform vec4 color;\n\
uniform sampler2D texture;\n\
@ -69,7 +72,7 @@ static const char *glslTextureSrcFragmentShader = "\n\
return texture2D(texture, textureCoords) * color;\n\
}\n";
static const char *glslSolidColorFragmentShader = "\n\
static const std::string glslSolidColorFragmentShader = "\n\
uniform vec4 color;\n\
vec4 calculatePixel() {\n\
return color;\n\

View File

@ -340,7 +340,7 @@ void X11Window::internalChooseGLVisual()
m_rootWindow = RootWindow(m_display, m_visual->screen);
#else
static int attrList[] = {
EGL_BUFFER_SIZE, 24,
//EGL_BUFFER_SIZE, 24,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};