From 2ebffd2da5e9669a804a1dd8761ccd0d27533733 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 23 Mar 2016 22:30:22 +0100 Subject: OPENGL: Fix black screen for some GL implementations with shaders. For compatibility location 0 is used to decide whether fixed function style vertex information is used in old GL contexts. In some cases drivers might assign the color information to be passed through attribute 0. This caused the array attribute status for location 0 to be disabled and resulted in wrong vertex data to be used. --- backends/graphics/opengl/pipelines/shader.cpp | 14 ++++++++++++-- backends/graphics/opengl/pipelines/shader.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'backends/graphics') diff --git a/backends/graphics/opengl/pipelines/shader.cpp b/backends/graphics/opengl/pipelines/shader.cpp index c7befe22b8..84c42e30ed 100644 --- a/backends/graphics/opengl/pipelines/shader.cpp +++ b/backends/graphics/opengl/pipelines/shader.cpp @@ -28,7 +28,7 @@ namespace OpenGL { #if !USE_FORCED_GLES ShaderPipeline::ShaderPipeline(Shader *shader) - : _activeShader(shader) { + : _activeShader(shader), _colorAttributes() { _vertexAttribLocation = shader->getAttributeLocation("position"); _texCoordAttribLocation = shader->getAttributeLocation("texCoordIn"); _colorAttribLocation = shader->getAttributeLocation("blendColorIn"); @@ -37,6 +37,7 @@ ShaderPipeline::ShaderPipeline(Shader *shader) void ShaderPipeline::activateInternal() { GL_CALL(glEnableVertexAttribArray(_vertexAttribLocation)); GL_CALL(glEnableVertexAttribArray(_texCoordAttribLocation)); + GL_CALL(glEnableVertexAttribArray(_colorAttribLocation)); if (g_context.multitextureSupported) { GL_CALL(glActiveTexture(GL_TEXTURE0)); @@ -48,12 +49,21 @@ void ShaderPipeline::activateInternal() { void ShaderPipeline::deactivateInternal() { GL_CALL(glDisableVertexAttribArray(_vertexAttribLocation)); GL_CALL(glDisableVertexAttribArray(_texCoordAttribLocation)); + GL_CALL(glDisableVertexAttribArray(_colorAttribLocation)); _activeShader->deactivate(); } void ShaderPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { - GL_CALL(glVertexAttrib4f(_colorAttribLocation, r, g, b, a)); + GLfloat *dst = _colorAttributes; + for (uint i = 0; i < 4; ++i) { + *dst++ = r; + *dst++ = g; + *dst++ = b; + *dst++ = a; + } + + GL_CALL(glVertexAttribPointer(_colorAttribLocation, 4, GL_FLOAT, GL_FALSE, 0, _colorAttributes)); } void ShaderPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) { diff --git a/backends/graphics/opengl/pipelines/shader.h b/backends/graphics/opengl/pipelines/shader.h index 95167ee03f..6159607099 100644 --- a/backends/graphics/opengl/pipelines/shader.h +++ b/backends/graphics/opengl/pipelines/shader.h @@ -48,6 +48,8 @@ protected: GLint _texCoordAttribLocation; GLint _colorAttribLocation; + GLfloat _colorAttributes[4*4]; + Shader *const _activeShader; }; #endif // !USE_FORCED_GLES -- cgit v1.2.3