From 14c679070194ebe021cccc686878b1203cccc640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 12:15:00 +0100 Subject: [PATCH] Shaders: set default values for VertexColorShader uniforms. Default value for matrix uniform would be zero uniform which would cause "black screen of death". --- src/Shaders/VertexColorShader.cpp | 5 +++++ src/Shaders/VertexColorShader.h | 2 ++ src/Shaders/VertexColorShader2D.vert | 6 +++++- src/Shaders/VertexColorShader3D.vert | 6 +++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index 82e25231f..748036744 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -75,6 +75,11 @@ template VertexColorShader::VertexColorShade { transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); } + + /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ + #ifdef MAGNUM_TARGET_GLES + setTransformationProjectionMatrix(typename DimensionTraits::MatrixType()); + #endif } template class VertexColorShader<2>; diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 87c6a5c88..a68697f90 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -57,6 +57,8 @@ template class MAGNUM_SHADERS_EXPORT VertexColorShader: /** * @brief Set transformation and projection matrix * @return Pointer to self (for method chaining) + * + * Default is identity matrix. */ inline VertexColorShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionMatrixUniform, matrix); diff --git a/src/Shaders/VertexColorShader2D.vert b/src/Shaders/VertexColorShader2D.vert index f7d2c879e..627fe2a64 100644 --- a/src/Shaders/VertexColorShader2D.vert +++ b/src/Shaders/VertexColorShader2D.vert @@ -27,8 +27,12 @@ #define out varying #endif +#ifndef GL_ES #ifdef EXPLICIT_UNIFORM_LOCATION -layout(location = 0) uniform mat3 transformationProjectionMatrix; +layout(location = 0) uniform mat3 transformationProjectionMatrix = mat3(1.0); +#else +uniform mat3 transformationProjectionMatrix = mat3(1.0); +#endif #else uniform highp mat3 transformationProjectionMatrix; #endif diff --git a/src/Shaders/VertexColorShader3D.vert b/src/Shaders/VertexColorShader3D.vert index 9cf727389..cbc07d517 100644 --- a/src/Shaders/VertexColorShader3D.vert +++ b/src/Shaders/VertexColorShader3D.vert @@ -27,8 +27,12 @@ #define out varying #endif +#ifndef GL_ES #ifdef EXPLICIT_UNIFORM_LOCATION -layout(location = 0) uniform mat4 transformationProjectionMatrix; +layout(location = 0) uniform mat4 transformationProjectionMatrix = mat4(1.0); +#else +uniform mat4 transformationProjectionMatrix = mat4(1.0); +#endif #else uniform highp mat4 transformationProjectionMatrix; #endif