Permalink
Browse files

Improve GLSL extension handling.

The extensions are always require'd at the top of the shader and can
now be disabled via Cvars for debugging.
  • Loading branch information...
gimhael committed Apr 4, 2016
1 parent 62a64e4 commit 21b9a188dbc302487f0ebb19fce6e932773ccd64
@@ -249,6 +249,23 @@ class GLShaderManager
std::unordered_map< std::string, int > _deformShaderLookup;
std::vector< GLint > _deformShaders;
int _totalBuildTime;
void addExtension( int enabled, int minGlslVersion, int supported,
const char *name ) {
if( !enabled ) {
// extension disabled by user
} else if( glConfig2.shadingLanguageVersion >= minGlslVersion ) {
// the extension is available in the core language
_versionDeclaration += Str::Format( "#define HAVE_%s 1\n", name );
} else if( supported ) {
// extension has to be explicitly enabled
_versionDeclaration += Str::Format( "#extension GL_%s : require\n", name );
_versionDeclaration += Str::Format( "#define HAVE_%s 1\n", name );
} else {
// extension is not supported
}
}
public:
GLShaderManager() : _totalBuildTime( 0 )
{
@@ -263,6 +280,16 @@ class GLShaderManager
profile = glConfig2.glCoreProfile ? "core" : "compatibility";
}
_versionDeclaration = Str::Format( "#version %d %s\n", glConfig2.shadingLanguageVersion, profile );
// add supported GLSL extensions
addExtension( r_arb_texture_gather->integer, 400,
GLEW_ARB_texture_gather, "ARB_texture_gather" );
addExtension( r_ext_texture_integer->integer, 130,
GLEW_EXT_texture_integer, "EXT_texture_integer" );
addExtension( r_ext_gpu_shader4->integer, 130,
GLEW_EXT_gpu_shader4, "EXT_gpu_shader4" );
addExtension( r_arb_uniform_buffer_object->integer, 140,
GLEW_ARB_uniform_buffer_object, "ARB_uniform_buffer_object" );
}
return _versionDeclaration;

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -100,10 +100,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *r_ext_texture_rg;
cvar_t *r_ext_texture_filter_anisotropic;
cvar_t *r_ext_packed_depth_stencil;
cvar_t *r_ext_gpu_shader4;
cvar_t *r_arb_buffer_storage;
cvar_t *r_arb_map_buffer_range;
cvar_t *r_arb_sync;
cvar_t *r_arb_uniform_buffer_object;
cvar_t *r_arb_texture_gather;
cvar_t *r_ignoreGLErrors;
cvar_t *r_logFile;
@@ -1080,10 +1082,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
r_ext_texture_rg = ri.Cvar_Get( "r_ext_texture_rg", "1", CVAR_CHEAT | CVAR_LATCH );
r_ext_texture_filter_anisotropic = ri.Cvar_Get( "r_ext_texture_filter_anisotropic", "4", CVAR_LATCH | CVAR_ARCHIVE );
r_ext_packed_depth_stencil = ri.Cvar_Get( "r_ext_packed_depth_stencil", "1", CVAR_CHEAT | CVAR_LATCH );
r_ext_gpu_shader4 = ri.Cvar_Get( "r_ext_gpu_shader4", "1", CVAR_CHEAT | CVAR_LATCH );
r_arb_buffer_storage = ri.Cvar_Get( "r_arb_buffer_storage", "1", CVAR_CHEAT | CVAR_LATCH );
r_arb_map_buffer_range = ri.Cvar_Get( "r_arb_map_buffer_range", "1", CVAR_CHEAT | CVAR_LATCH );
r_arb_sync = ri.Cvar_Get( "r_arb_sync", "1", CVAR_CHEAT | CVAR_LATCH );
r_arb_uniform_buffer_object = ri.Cvar_Get( "r_arb_uniform_buffer_object", "1", CVAR_CHEAT | CVAR_LATCH );
r_arb_texture_gather = ri.Cvar_Get( "r_arb_texture_gather", "1", CVAR_CHEAT | CVAR_LATCH );
r_collapseStages = ri.Cvar_Get( "r_collapseStages", "1", CVAR_LATCH | CVAR_CHEAT );
r_picmip = ri.Cvar_Get( "r_picmip", "0", CVAR_LATCH | CVAR_ARCHIVE );
@@ -2879,10 +2879,12 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
extern cvar_t *r_ext_texture_rg;
extern cvar_t *r_ext_texture_filter_anisotropic;
extern cvar_t *r_ext_packed_depth_stencil;
extern cvar_t *r_ext_gpu_shader4;
extern cvar_t *r_arb_buffer_storage;
extern cvar_t *r_arb_map_buffer_range;
extern cvar_t *r_arb_sync;
extern cvar_t *r_arb_uniform_buffer_object;
extern cvar_t *r_arb_texture_gather;
extern cvar_t *r_nobind; // turns off binding to appropriate textures
extern cvar_t *r_collapseStages;
@@ -22,8 +22,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
/* depthtile1_fp.glsl */
#extension GL_ARB_texture_gather : enable
uniform sampler2D u_DepthMap;
varying vec3 unprojectionParams;
@@ -54,7 +52,7 @@ void main()
vec2 st = gl_FragCoord.st * 4.0 * pixelScale;
vec4 depth[4], mask[4];
#ifdef GL_ARB_texture_gather
#ifdef HAVE_ARB_texture_gather
depth[0] = textureGather( u_DepthMap, st + vec2(-1.0, -1.0) * pixelScale );
depth[1] = textureGather( u_DepthMap, st + vec2(-1.0, 1.0) * pixelScale );
depth[2] = textureGather( u_DepthMap, st + vec2( 1.0, 1.0) * pixelScale );
@@ -663,8 +663,7 @@ float ShadowTest( float vertexDistance, vec4 shadowMoments, vec4 shadowClipMomen
// shadow = clamp(exp(r_OverDarkeningFactor * shadowDistance) * exp(-r_OverDarkeningFactor * vertexDistance), 0.0, 1.0);
// shadow = smoothstep(0.0, 1.0, shadow);
#if defined(r_DebugShadowMaps)
#extension GL_EXT_gpu_shader4 : enable
#if defined(r_DebugShadowMaps) && defined( HAVE_EXT_gpu_shader4 )
outputColor.r = (r_DebugShadowMaps & 1) != 0 ? shadowDistance : 0.0;
outputColor.g = (r_DebugShadowMaps & 2) != 0 ? -(shadowDistance - vertexDistance) : 0.0;
outputColor.b = (r_DebugShadowMaps & 4) != 0 ? shadow : 0.0;
@@ -694,8 +693,7 @@ float ShadowTest( float vertexDistance, vec4 shadowMoments, vec4 shadowClipMomen
shadow = min(posContrib, negContrib);
#if defined(r_DebugShadowMaps)
#extension GL_EXT_gpu_shader4 : enable
#if defined(r_DebugShadowMaps) && defined( HAVE_EXT_gpu_shader4 )
outputColor.r = (r_DebugShadowMaps & 1) != 0 ? posContrib : 0.0;
outputColor.g = (r_DebugShadowMaps & 2) != 0 ? negContrib : 0.0;
outputColor.b = (r_DebugShadowMaps & 4) != 0 ? shadow : 0.0;
@@ -21,14 +21,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* lighttile_fp.glsl */
#if __VERSION__ < 150 && defined( UNIFORM_BUFFER_OBJECT )
#extension GL_ARB_uniform_buffer_object : enable
#endif
#if __VERSION__ < 130 && defined( TEXTURE_INTEGER )
#extension GL_EXT_texture_integer : enable
#extension GL_EXT_gpu_shader4 : enable
#endif
varying vec2 vPosition;
varying vec2 vTexCoord;
@@ -39,7 +31,7 @@ struct light {
vec4 direction_angle;
};
#ifdef UNIFORM_BUFFER_OBJECT
#ifdef HAVE_ARB_uniform_buffer_object
layout(std140) uniform u_Lights {
light lights[ MAX_REF_LIGHTS ];
};
@@ -61,7 +53,7 @@ uniform int u_lightLayer;
const int numLayers = MAX_REF_LIGHTS / 256;
#ifdef TEXTURE_INTEGER
#if defined( HAVE_EXT_texture_integer ) && defined( HAVE_EXT_gpu_shader4 )
#define idxs_t uvec4
#define idx_initializer uvec4(3)
#if __VERSION__ < 130
@@ -22,22 +22,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// reliefMapping_vp.glsl - Relief mapping helper functions
#if defined( USE_SHADER_LIGHTS )
#if __VERSION__ < 150 && defined( UNIFORM_BUFFER_OBJECT )
#extension GL_ARB_uniform_buffer_object : enable
#endif
#if __VERSION__ < 130 && defined( TEXTURE_INTEGER )
#extension GL_EXT_texture_integer : enable
#extension GL_EXT_gpu_shader4 : enable
#endif
struct light {
vec4 center_radius;
vec4 color_type;
vec4 direction_angle;
};
#ifdef UNIFORM_BUFFER_OBJECT
#ifdef HAVE_ARB_uniform_buffer_object
layout(std140) uniform u_Lights {
light lights[ MAX_REF_LIGHTS ];
};
@@ -108,7 +100,7 @@ void computeLight( vec3 lightDir, vec3 normal, vec3 eyeDir, vec3 lightColor,
#if defined( USE_SHADER_LIGHTS )
#ifdef TEXTURE_INTEGER
#ifdef HAVE_EXT_texture_integer
const int lightsPerLayer = 16;
uniform usampler3D u_LightTiles;
#define idxs_t uvec4
View
@@ -22,8 +22,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
/* ssao_fp.glsl */
#extension GL_ARB_texture_gather : require
uniform sampler2D u_DepthMap;
varying vec3 unprojectionParams;

0 comments on commit 21b9a18

Please sign in to comment.