From 729e9c21620a86e604b0b1b376691dec84f2f607 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Thu, 26 Apr 2018 17:10:10 -0300 Subject: [PATCH] Revert "Merge pull request #12921 from SamGondelman/precisionq" This reverts commit d1e2e9ce71a46abf1aeb89311d0e14a8f2362ed7, reversing changes made to 7842ee8eacbb0574ae63074ac9e00a85840383b1. --- .../gpu-gl-common/src/gpu/gl/GLBackend.h | 2 +- .../src/gpu/gl/GLBackendShader.cpp | 21 +++++++++++++++++++ .../gpu-gl/src/gpu/gl41/GL41BackendShader.cpp | 8 +------ .../gpu-gl/src/gpu/gl45/GL45BackendShader.cpp | 16 +++++++------- .../src/gpu/gles/GLESBackendShader.cpp | 11 +--------- libraries/graphics/src/graphics/Light.slh | 9 +++++++- .../src/graphics/LightIrradiance.shared.slh | 8 ++++++- .../src/graphics/LightVolume.shared.slh | 8 +++++++ libraries/graphics/src/graphics/Material.slh | 9 +++++++- .../graphics/SphericalHarmonics.shared.slh | 8 +++++++ libraries/render-utils/src/LightingModel.slh | 8 +++++++ 11 files changed, 78 insertions(+), 30 deletions(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h index 895a7777c9..6355137a19 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h @@ -452,7 +452,7 @@ protected: // Backend dependant compilation of the shader virtual GLShader* compileBackendProgram(const Shader& program, const Shader::CompilationHandler& handler); virtual GLShader* compileBackendShader(const Shader& shader, const Shader::CompilationHandler& handler); - virtual std::string getBackendShaderHeader() const = 0; + virtual std::string getBackendShaderHeader() const; virtual void makeProgramBindings(ShaderObject& shaderObject); class ElementResource { public: diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendShader.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendShader.cpp index bf36c134de..0df228ddc4 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendShader.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendShader.cpp @@ -12,6 +12,27 @@ using namespace gpu; using namespace gpu::gl; +// GLSL version +std::string GLBackend::getBackendShaderHeader() const { + +#if defined(USE_GLES) + static const std::string header( +R"SHADER(#version 310 es +#extension GL_EXT_texture_buffer : enable +precision lowp float; // check precision 2 +precision lowp samplerBuffer; +precision lowp sampler2DShadow; +)SHADER"); +#else + static const std::string header( +R"SHADER(#version 410 core +)SHADER"); +#endif + + return header; +} + + // Shader domain static const size_t NUM_SHADER_DOMAINS = 3; static_assert(Shader::Type::NUM_DOMAINS == NUM_SHADER_DOMAINS, "GL shader domains must equal defined GPU shader domains"); diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp index 151b5bd1f9..35bfafdc50 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp @@ -14,13 +14,7 @@ using namespace gpu::gl41; // GLSL version std::string GL41Backend::getBackendShaderHeader() const { - static const std::string header( - R"SHADER(#version 410 core - #define GPU_GL410 - #define PRECISIONQ - #define BITFIELD int - )SHADER"); - return header; + return std::string("#version 410 core\n#define GPU_GL410 1"); } int GL41Backend::makeResourceBufferSlots(GLuint glprogram, const Shader::BindingSet& slotBindings,Shader::SlotSet& resourceBuffers) { diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendShader.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendShader.cpp index 6f6ded518f..8de60a7921 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendShader.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendShader.cpp @@ -15,17 +15,15 @@ using namespace gpu::gl45; // GLSL version std::string GL45Backend::getBackendShaderHeader() const { - static const std::string header( - R"SHADER(#version 450 core - #define GPU_GL450 - #define PRECISIONQ - #define BITFIELD int - )SHADER" + const char header[] = +R"GLSL(#version 450 core +#define GPU_GL450 +)GLSL" #ifdef GPU_SSBO_TRANSFORM_OBJECT - R"SHADER(#define GPU_SSBO_TRANSFORM_OBJECT)SHADER" + R"GLSL(#define GPU_SSBO_TRANSFORM_OBJECT 1)GLSL" #endif - ); - return header; + ; + return std::string(header); } int GL45Backend::makeResourceBufferSlots(GLuint glprogram, const Shader::BindingSet& slotBindings,Shader::SlotSet& resourceBuffers) { diff --git a/libraries/gpu-gles/src/gpu/gles/GLESBackendShader.cpp b/libraries/gpu-gles/src/gpu/gles/GLESBackendShader.cpp index 4278d732c8..16cf1559dd 100644 --- a/libraries/gpu-gles/src/gpu/gles/GLESBackendShader.cpp +++ b/libraries/gpu-gles/src/gpu/gles/GLESBackendShader.cpp @@ -14,16 +14,7 @@ using namespace gpu::gles; // GLSL version std::string GLESBackend::getBackendShaderHeader() const { - static const std::string header( - R"SHADER(#version 310 es - #extension GL_EXT_texture_buffer : enable - precision lowp float; // check precision 2 - precision lowp samplerBuffer; - precision lowp sampler2DShadow; - #define PRECISIONQ highp - #define BITFIELD highp int - )SHADER"); - return header; + return Parent::getBackendShaderHeader(); } int GLESBackend::makeResourceBufferSlots(GLuint glprogram, const Shader::BindingSet& slotBindings,Shader::SlotSet& resourceBuffers) { diff --git a/libraries/graphics/src/graphics/Light.slh b/libraries/graphics/src/graphics/Light.slh index c8992730f0..20394816c9 100644 --- a/libraries/graphics/src/graphics/Light.slh +++ b/libraries/graphics/src/graphics/Light.slh @@ -29,9 +29,16 @@ vec3 getLightColor(Light l) { return lightIrradiance_getColor(l.irradiance); } float getLightIntensity(Light l) { return lightIrradiance_getIntensity(l.irradiance); } vec3 getLightIrradiance(Light l) { return lightIrradiance_getIrradiance(l.irradiance); } -// Ambient lighting needs extra info provided from a different Buffer +// AMbient lighting needs extra info provided from a different Buffer <@include graphics/SphericalHarmonics.shared.slh@> // Light Ambient +#ifndef PRECISIONQ +#ifdef GL_ES +#define PRECISIONQ highp +#else +#define PRECISIONQ +#endif +#endif struct LightAmbient { PRECISIONQ vec4 _ambient; diff --git a/libraries/graphics/src/graphics/LightIrradiance.shared.slh b/libraries/graphics/src/graphics/LightIrradiance.shared.slh index 4ae7967bf5..ff42f57fd9 100644 --- a/libraries/graphics/src/graphics/LightIrradiance.shared.slh +++ b/libraries/graphics/src/graphics/LightIrradiance.shared.slh @@ -12,7 +12,13 @@ #define LightIrradianceConstRef LightIrradiance - +#ifndef PRECISIONQ +#ifdef GL_ES +#define PRECISIONQ highp +#else +#define PRECISIONQ +#endif +#endif struct LightIrradiance { PRECISIONQ vec4 colorIntensity; // falloffRadius, cutoffRadius, falloffSpot, spare diff --git a/libraries/graphics/src/graphics/LightVolume.shared.slh b/libraries/graphics/src/graphics/LightVolume.shared.slh index 4e4359eac0..48249e766f 100644 --- a/libraries/graphics/src/graphics/LightVolume.shared.slh +++ b/libraries/graphics/src/graphics/LightVolume.shared.slh @@ -15,6 +15,14 @@ #define LightVolumeConstRef LightVolume +#ifndef PRECISIONQ +#ifdef GL_ES +#define PRECISIONQ highp +#else +#define PRECISIONQ +#endif +#endif + struct LightVolume { PRECISIONQ vec4 positionRadius; PRECISIONQ vec4 directionSpotCos; diff --git a/libraries/graphics/src/graphics/Material.slh b/libraries/graphics/src/graphics/Material.slh index ecf3c18a0e..f9f4144748 100644 --- a/libraries/graphics/src/graphics/Material.slh +++ b/libraries/graphics/src/graphics/Material.slh @@ -13,7 +13,14 @@ // The material values (at least the material key) must be precisely bitwise accurate // to what is provided by the uniform buffer, or the material key has the wrong bits - +#ifdef GL_ES +precision highp float; +#define BITFIELD highp int +#define PRECISIONQ highp +#else +#define BITFIELD int +#define PRECISIONQ +#endif struct Material { PRECISIONQ vec4 _emissiveOpacity; PRECISIONQ vec4 _albedoRoughness; diff --git a/libraries/graphics/src/graphics/SphericalHarmonics.shared.slh b/libraries/graphics/src/graphics/SphericalHarmonics.shared.slh index 6e1763dcba..72a505fa25 100644 --- a/libraries/graphics/src/graphics/SphericalHarmonics.shared.slh +++ b/libraries/graphics/src/graphics/SphericalHarmonics.shared.slh @@ -15,6 +15,14 @@ #define SphericalHarmonicsConstRef SphericalHarmonics +#ifndef PRECISIONQ +#ifdef GL_ES +#define PRECISIONQ highp +#else +#define PRECISIONQ +#endif +#endif + struct SphericalHarmonics { PRECISIONQ vec4 L00; PRECISIONQ vec4 L1m1; diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index 6a5982f1e8..3f615f11db 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -13,6 +13,14 @@ <@func declareLightingModel()@> +#ifndef PRECISIONQ +#ifdef GL_ES +#define PRECISIONQ highp +#else +#define PRECISIONQ +#endif +#endif + struct LightingModel { PRECISIONQ vec4 _UnlitEmissiveLightmapBackground; PRECISIONQ vec4 _ScatteringDiffuseSpecularAlbedo;