From 8a53d1c4868c8964e6b5b483232c530816327643 Mon Sep 17 00:00:00 2001 From: kgv Date: Wed, 9 Sep 2015 10:29:43 +0300 Subject: [PATCH] 0026665: Visualization, TKOpenGl - specify precision for integer uniforms explicitly within OpenGL ES Use lowp for enumerations / Boolean uniforms. Define default integer precision to highp in Fragment Shader when available. --- src/OpenGl/OpenGl_ShaderProgram.cxx | 4 +++- src/Shaders/Declarations.glsl | 26 ++++++++++++++++---------- src/Shaders/DeclarationsImpl.glsl | 4 ++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/OpenGl/OpenGl_ShaderProgram.cxx b/src/OpenGl/OpenGl_ShaderProgram.cxx index f3ff0f0683..8a1e8d29f3 100755 --- a/src/OpenGl/OpenGl_ShaderProgram.cxx +++ b/src/OpenGl/OpenGl_ShaderProgram.cxx @@ -227,7 +227,9 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)& #if defined(GL_ES_VERSION_2_0) TCollection_AsciiString aPrefix (theCtx->hasHighp ? "precision highp float;\n" - : "precision mediump float;\n"); + "precision highp int;\n" + : "precision mediump float;\n" + "precision mediump int;\n"); aSource = aHeader + aPrefix + aSource; #else aSource = aHeader + aSource; diff --git a/src/Shaders/Declarations.glsl b/src/Shaders/Declarations.glsl index 8b6ec4b222..eb98ace021 100644 --- a/src/Shaders/Declarations.glsl +++ b/src/Shaders/Declarations.glsl @@ -33,6 +33,12 @@ #define occTexture2D texture2D #endif +#ifdef GL_ES + #define THE_PREC_ENUM lowp // enumerations should fit into lowp range +#else + #define THE_PREC_ENUM +#endif + // Vertex attributes #ifdef VERTEX_SHADER THE_ATTRIBUTE vec4 occVertex; @@ -68,8 +74,8 @@ const int OccLightType_Point = 2; //!< isotropic point light source const int OccLightType_Spot = 3; //!< spot light source // Light sources -uniform vec4 occLightAmbient; //!< Cumulative ambient color -uniform int occLightSourcesCount; //!< Total number of light sources +uniform vec4 occLightAmbient; //!< Cumulative ambient color +uniform THE_PREC_ENUM int occLightSourcesCount; //!< Total number of light sources int occLight_Type (in int theId); //!< Type of light source int occLight_IsHeadlight (in int theId); //!< Is light a headlight? vec4 occLight_Diffuse (in int theId); //!< Diffuse intensity for specified light source @@ -97,17 +103,17 @@ vec4 occBackMaterial_Specular(void); //!< Specular reflection float occBackMaterial_Shininess(void); //!< Specular exponent float occBackMaterial_Transparency(void); //!< Transparency coefficient -uniform vec4 occColor; //!< color value (in case of disabled lighting) -uniform int occDistinguishingMode; //!< Are front and back faces distinguished? -uniform int occTextureEnable; //!< Is texture enabled? -uniform sampler2D occActiveSampler; //!< Current active sampler -uniform float occPointSize; //!< point size +uniform vec4 occColor; //!< color value (in case of disabled lighting) +uniform THE_PREC_ENUM int occDistinguishingMode; //!< Are front and back faces distinguished? +uniform THE_PREC_ENUM int occTextureEnable; //!< Is texture enabled? +uniform sampler2D occActiveSampler; //!< Current active sampler +uniform float occPointSize; //!< point size // clipping planes state const int OccEquationCoords_View = 0; //!< view-space clipping plane const int OccEquationCoords_World = 1; //!< world-space clipping plane //! Parameters of clipping planes -uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES]; -uniform int occClipPlaneSpaces [THE_MAX_CLIP_PLANES]; -uniform int occClipPlaneCount; //!< Total number of clip planes +uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES]; +uniform THE_PREC_ENUM int occClipPlaneSpaces [THE_MAX_CLIP_PLANES]; +uniform THE_PREC_ENUM int occClipPlaneCount; //!< Total number of clip planes diff --git a/src/Shaders/DeclarationsImpl.glsl b/src/Shaders/DeclarationsImpl.glsl index c673c247cc..4c4754a030 100644 --- a/src/Shaders/DeclarationsImpl.glsl +++ b/src/Shaders/DeclarationsImpl.glsl @@ -16,8 +16,8 @@ // This file includes implementation of common functions and properties accessors // arrays of light sources -uniform ivec2 occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types -uniform vec4 occLightSources[THE_MAX_LIGHTS * 4]; //!< packed light sources parameters +uniform THE_PREC_ENUM ivec2 occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types +uniform vec4 occLightSources[THE_MAX_LIGHTS * 4]; //!< packed light sources parameters // light source properties accessors int occLight_Type (in int theId) { return occLightSourcesTypes[theId].x; }