Skip to content

Commit c05ca53

Browse files
committed
sdl_glimp: move EnableAvailableFeatures() from tr_share
1 parent 1d1af87 commit c05ca53

2 files changed

Lines changed: 178 additions & 181 deletions

File tree

src/engine/renderer/tr_shade.cpp

Lines changed: 0 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -30,188 +30,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3030
/*
3131
=================================================================================
3232
THIS ENTIRE FILE IS BACK END!
33-
^ Not true, EnableAvailableFeatures() right below this isn't.
3433
3534
This file deals with applying shaders to surface data in the tess struct.
3635
=================================================================================
3736
*/
3837

39-
static void EnableAvailableFeatures()
40-
{
41-
glConfig.realtimeLighting = r_realtimeLighting.Get();
42-
43-
if ( glConfig.realtimeLighting )
44-
{
45-
if ( !glConfig.uniformBufferObjectAvailable ) {
46-
Log::Warn( "Tiled dynamic light renderer disabled because GL_ARB_uniform_buffer_object is not available." );
47-
glConfig.realtimeLighting = false;
48-
}
49-
50-
if ( !glConfig.textureIntegerAvailable ) {
51-
Log::Warn( "Tiled dynamic light renderer disabled because GL_EXT_texture_integer is not available." );
52-
glConfig.realtimeLighting = false;
53-
}
54-
55-
if ( !glConfig.textureFloatAvailable )
56-
{
57-
Log::Warn( "Tiled dynamic light renderer disabled because GL_ARB_texture_float is not available." );
58-
glConfig.realtimeLighting = false;
59-
}
60-
61-
if ( glConfig.max3DTextureSize == 0 )
62-
{
63-
Log::Warn( "Tiled dynamic light renderer disabled because of missing 3D texture support." );
64-
glConfig.realtimeLighting = false;
65-
}
66-
67-
// See below about ALU instructions on ATI R300 and Intel GMA 3.
68-
if ( !glConfig.glCoreProfile && glConfig.maxAluInstructions < 128 )
69-
{
70-
Log::Warn( "Tiled dynamic light rendered disabled because GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB is too small: %d", glConfig.maxAluInstructions );
71-
glConfig.realtimeLighting = false;
72-
}
73-
}
74-
75-
if ( glConfig.realtimeLighting ) {
76-
glConfig.realtimeLightLayers = r_realtimeLightLayers.Get();
77-
78-
if ( glConfig.realtimeLightLayers > glConfig.max3DTextureSize ) {
79-
glConfig.realtimeLightLayers = glConfig.max3DTextureSize;
80-
Log::Notice( "r_realtimeLightLayers exceeds maximum 3D texture size, using %i instead.", glConfig.max3DTextureSize );
81-
}
82-
83-
Log::Notice( "Using %i dynamic light layers, %i dynamic lights available per tile", glConfig.realtimeLightLayers,
84-
glConfig.realtimeLightLayers * 16 );
85-
}
86-
87-
glConfig.colorGrading = r_colorGrading.Get();
88-
89-
if ( glConfig.colorGrading )
90-
{
91-
if ( glConfig.max3DTextureSize == 0 )
92-
{
93-
Log::Warn( "Color grading disabled because of missing 3D texture support." );
94-
glConfig.colorGrading = false;
95-
}
96-
}
97-
98-
glConfig.deluxeMapping = r_deluxeMapping->integer;
99-
glConfig.normalMapping = r_normalMapping->integer;
100-
glConfig.specularMapping = r_specularMapping->integer;
101-
glConfig.physicalMapping = r_physicalMapping->integer;
102-
glConfig.reliefMapping = r_reliefMapping->integer;
103-
104-
/* ATI R300 and Intel GMA 3 only have 64 ALU instructions, which is not enough for some shader
105-
variants. For example the lightMapping shader permutation with macros USE_GRID_LIGHTING and
106-
USE_GRID_DELUXE_MAPPING from the medium graphics preset requires 67 ALU.
107-
For comparison, ATI R400 and R500 have 512 of them. */
108-
if ( !glConfig.glCoreProfile && glConfig.maxAluInstructions < 128 )
109-
{
110-
static const std::pair<bool*, std::string> aluFeatures[] = {
111-
/* Normal mapping, specular mapping and physical mapping does nothing when deluxe mapping
112-
is disabled. Hardware that can't do deluxe mapping or normal mapping is not powerful
113-
enoough to do relief mapping. */
114-
{ &glConfig.deluxeMapping, "Deluxe mapping" },
115-
{ &glConfig.normalMapping, "Normal mapping" },
116-
{ &glConfig.specularMapping, "Specular mapping" },
117-
{ &glConfig.physicalMapping, "Physical mapping" },
118-
{ &glConfig.reliefMapping, "Relief mapping" },
119-
};
120-
121-
for ( auto& f : aluFeatures )
122-
{
123-
if ( *f.first )
124-
{
125-
Log::Warn( "%s disabled because GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB is too small: %d", f.second, glConfig.maxAluInstructions );
126-
*f.first = false;
127-
}
128-
}
129-
}
130-
131-
// Disable features that require deluxe mapping to be enabled.
132-
glConfig.normalMapping = glConfig.deluxeMapping && glConfig.normalMapping;
133-
glConfig.specularMapping = glConfig.deluxeMapping && glConfig.specularMapping;
134-
glConfig.physicalMapping = glConfig.deluxeMapping && glConfig.physicalMapping;
135-
136-
glConfig.bloom = r_bloom.Get();
137-
138-
glConfig.SSAO = r_SSAO.Get() != Util::ordinal( ssaoMode::DISABLED );
139-
140-
static const std::pair<bool*, std::string> ssaoRequiredExtensions[] = {
141-
{ &glConfig.textureGatherAvailable, "ARB_texture_gather" },
142-
{ &glConfig.gpuShader4Available, "EXT_gpu_shader4" },
143-
};
144-
145-
for ( auto& e: ssaoRequiredExtensions )
146-
{
147-
if ( !*e.first )
148-
{
149-
Log::Warn( "SSAO disabled because %s is not available.", e.second );
150-
glConfig.SSAO = false;
151-
}
152-
}
153-
154-
/* Motion blur is enabled by cg_motionblur which is a client cvar so we have to build it in all cases,
155-
unless unsupported by the hardware which is the only condition when the engine knows it is not used. */
156-
glConfig.motionBlur = true;
157-
158-
// This will be enabled later on by R_BuildCubeMaps()
159-
glConfig.reflectionMapping = false;
160-
161-
/* Intel GMA 3 only has 4 tex indirections, which is not enough for some shaders.
162-
For example blurX requires 6, contrast requires 5, motionblur requires 5…
163-
For comparison, ATI R300, R400 and R500 have 16 of them. We don't need a finer check as early R300
164-
hardware with 16 indirections would better not run that code for performance, so disabling the shader
165-
by mistake on an hypothetical lower-end hardware only supporting 8 indirections can't do harm. */
166-
if ( !glConfig.glCoreProfile && glConfig.maxTexIndirections < 16 )
167-
{
168-
static const std::pair<bool*, std::string> indirectFeatures[] = {
169-
{ &glConfig.bloom, "Bloom" },
170-
{ &glConfig.motionBlur, "Motion blur" },
171-
};
172-
173-
for ( auto& f : indirectFeatures )
174-
{
175-
if ( *f.first )
176-
{
177-
Log::Warn( "%s disabled because GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB is too small: %d", f.second, glConfig.maxTexIndirections );
178-
*f.first = false;
179-
}
180-
}
181-
}
182-
183-
if ( std::make_pair( glConfig.glMajor, glConfig.glMinor ) >= std::make_pair( 3, 2 ) ) {
184-
glConfig.MSAA = r_MSAA.Get();
185-
const int maxSamples = std::min( glConfig.maxColorTextureSamples, glConfig.maxDepthTextureSamples );
186-
187-
if ( glConfig.MSAA > maxSamples ) {
188-
Log::Warn( "MSAA samples %i > %i, setting to %i", r_MSAA.Get(), maxSamples, maxSamples );
189-
glConfig.MSAA = maxSamples;
190-
}
191-
} else if ( r_MSAA.Get() ) {
192-
Log::Warn( "MSAA unavailable because GL version is lower than required (%i.%i < %i.%i)", glConfig.glMajor, glConfig.glMinor, 3, 2 );
193-
}
194-
195-
glConfig.FXAA = r_FXAA.Get();
196-
197-
if ( glConfig.FXAA && glConfig.MSAA )
198-
{
199-
Log::Notice( "FXAA disabled because MSAA is enabled." );
200-
glConfig.FXAA = false;
201-
}
202-
203-
if ( glConfig.FXAA && !glConfig.samplerObjectsAvailable )
204-
{
205-
Log::Warn( "FXAA disabled because ARB_sampler_objects is not available." );
206-
glConfig.FXAA = false;
207-
}
208-
209-
glConfig.usingMaterialSystem = r_materialSystem.Get() && glConfig.materialSystemAvailable;
210-
glConfig.usingBindlessTextures = glConfig.usingMaterialSystem ||
211-
( r_preferBindlessTextures.Get() && glConfig.bindlessTexturesAvailable );
212-
glConfig.usingGeometryCache = glConfig.usingMaterialSystem && glConfig.geometryCacheAvailable;
213-
}
214-
21538
// For shaders that require map data for compile-time values
21639
void GLSL_InitWorldShaders() {
21740
// make sure the render thread is stopped
@@ -240,10 +63,6 @@ static void GLSL_InitGPUShadersOrError()
24063

24164
gl_shaderManager.InitDriverInfo();
24265

243-
/* It must be done before GenerateBuiltinHeaders() because glConfig.realtimeLighting
244-
is read in GenEngineConstants(). */
245-
EnableAvailableFeatures();
246-
24766
gl_shaderManager.GenerateBuiltinHeaders();
24867

24968
// single texture rendering

src/engine/sys/sdl_glimp.cpp

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,182 @@ static void GLimp_InitExtensions()
26752675
GL_CheckErrors();
26762676
}
26772677

2678+
static void GLimp_EnableAvailableFeatures()
2679+
{
2680+
glConfig.realtimeLighting = r_realtimeLighting.Get();
2681+
2682+
if ( glConfig.realtimeLighting )
2683+
{
2684+
if ( !glConfig.uniformBufferObjectAvailable ) {
2685+
Log::Warn( "Tiled dynamic light renderer disabled because GL_ARB_uniform_buffer_object is not available." );
2686+
glConfig.realtimeLighting = false;
2687+
}
2688+
2689+
if ( !glConfig.textureIntegerAvailable ) {
2690+
Log::Warn( "Tiled dynamic light renderer disabled because GL_EXT_texture_integer is not available." );
2691+
glConfig.realtimeLighting = false;
2692+
}
2693+
2694+
if ( !glConfig.textureFloatAvailable )
2695+
{
2696+
Log::Warn( "Tiled dynamic light renderer disabled because GL_ARB_texture_float is not available." );
2697+
glConfig.realtimeLighting = false;
2698+
}
2699+
2700+
if ( glConfig.max3DTextureSize == 0 )
2701+
{
2702+
Log::Warn( "Tiled dynamic light renderer disabled because of missing 3D texture support." );
2703+
glConfig.realtimeLighting = false;
2704+
}
2705+
2706+
// See below about ALU instructions on ATI R300 and Intel GMA 3.
2707+
if ( !glConfig.glCoreProfile && glConfig.maxAluInstructions < 128 )
2708+
{
2709+
Log::Warn( "Tiled dynamic light rendered disabled because GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB is too small: %d", glConfig.maxAluInstructions );
2710+
glConfig.realtimeLighting = false;
2711+
}
2712+
}
2713+
2714+
if ( glConfig.realtimeLighting ) {
2715+
glConfig.realtimeLightLayers = r_realtimeLightLayers.Get();
2716+
2717+
if ( glConfig.realtimeLightLayers > glConfig.max3DTextureSize ) {
2718+
glConfig.realtimeLightLayers = glConfig.max3DTextureSize;
2719+
Log::Notice( "r_realtimeLightLayers exceeds maximum 3D texture size, using %i instead.", glConfig.max3DTextureSize );
2720+
}
2721+
2722+
Log::Notice( "Using %i dynamic light layers, %i dynamic lights available per tile", glConfig.realtimeLightLayers,
2723+
glConfig.realtimeLightLayers * 16 );
2724+
}
2725+
2726+
glConfig.colorGrading = r_colorGrading.Get();
2727+
2728+
if ( glConfig.colorGrading )
2729+
{
2730+
if ( glConfig.max3DTextureSize == 0 )
2731+
{
2732+
Log::Warn( "Color grading disabled because of missing 3D texture support." );
2733+
glConfig.colorGrading = false;
2734+
}
2735+
}
2736+
2737+
glConfig.deluxeMapping = r_deluxeMapping->integer;
2738+
glConfig.normalMapping = r_normalMapping->integer;
2739+
glConfig.specularMapping = r_specularMapping->integer;
2740+
glConfig.physicalMapping = r_physicalMapping->integer;
2741+
glConfig.reliefMapping = r_reliefMapping->integer;
2742+
2743+
/* ATI R300 and Intel GMA 3 only have 64 ALU instructions, which is not enough for some shader
2744+
variants. For example the lightMapping shader permutation with macros USE_GRID_LIGHTING and
2745+
USE_GRID_DELUXE_MAPPING from the medium graphics preset requires 67 ALU.
2746+
For comparison, ATI R400 and R500 have 512 of them. */
2747+
if ( !glConfig.glCoreProfile && glConfig.maxAluInstructions < 128 )
2748+
{
2749+
static const std::pair<bool*, std::string> aluFeatures[] = {
2750+
/* Normal mapping, specular mapping and physical mapping does nothing when deluxe mapping
2751+
is disabled. Hardware that can't do deluxe mapping or normal mapping is not powerful
2752+
enoough to do relief mapping. */
2753+
{ &glConfig.deluxeMapping, "Deluxe mapping" },
2754+
{ &glConfig.normalMapping, "Normal mapping" },
2755+
{ &glConfig.specularMapping, "Specular mapping" },
2756+
{ &glConfig.physicalMapping, "Physical mapping" },
2757+
{ &glConfig.reliefMapping, "Relief mapping" },
2758+
};
2759+
2760+
for ( auto& f : aluFeatures )
2761+
{
2762+
if ( *f.first )
2763+
{
2764+
Log::Warn( "%s disabled because GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB is too small: %d", f.second, glConfig.maxAluInstructions );
2765+
*f.first = false;
2766+
}
2767+
}
2768+
}
2769+
2770+
// Disable features that require deluxe mapping to be enabled.
2771+
glConfig.normalMapping = glConfig.deluxeMapping && glConfig.normalMapping;
2772+
glConfig.specularMapping = glConfig.deluxeMapping && glConfig.specularMapping;
2773+
glConfig.physicalMapping = glConfig.deluxeMapping && glConfig.physicalMapping;
2774+
2775+
glConfig.bloom = r_bloom.Get();
2776+
2777+
glConfig.SSAO = r_SSAO.Get() != Util::ordinal( ssaoMode::DISABLED );
2778+
2779+
static const std::pair<bool*, std::string> ssaoRequiredExtensions[] = {
2780+
{ &glConfig.textureGatherAvailable, "ARB_texture_gather" },
2781+
{ &glConfig.gpuShader4Available, "EXT_gpu_shader4" },
2782+
};
2783+
2784+
for ( auto& e: ssaoRequiredExtensions )
2785+
{
2786+
if ( !*e.first )
2787+
{
2788+
Log::Warn( "SSAO disabled because %s is not available.", e.second );
2789+
glConfig.SSAO = false;
2790+
}
2791+
}
2792+
2793+
/* Motion blur is enabled by cg_motionblur which is a client cvar so we have to build it in all cases,
2794+
unless unsupported by the hardware which is the only condition when the engine knows it is not used. */
2795+
glConfig.motionBlur = true;
2796+
2797+
// This will be enabled later on by R_BuildCubeMaps()
2798+
glConfig.reflectionMapping = false;
2799+
2800+
/* Intel GMA 3 only has 4 tex indirections, which is not enough for some shaders.
2801+
For example blurX requires 6, contrast requires 5, motionblur requires 5…
2802+
For comparison, ATI R300, R400 and R500 have 16 of them. We don't need a finer check as early R300
2803+
hardware with 16 indirections would better not run that code for performance, so disabling the shader
2804+
by mistake on an hypothetical lower-end hardware only supporting 8 indirections can't do harm. */
2805+
if ( !glConfig.glCoreProfile && glConfig.maxTexIndirections < 16 )
2806+
{
2807+
static const std::pair<bool*, std::string> indirectFeatures[] = {
2808+
{ &glConfig.bloom, "Bloom" },
2809+
{ &glConfig.motionBlur, "Motion blur" },
2810+
};
2811+
2812+
for ( auto& f : indirectFeatures )
2813+
{
2814+
if ( *f.first )
2815+
{
2816+
Log::Warn( "%s disabled because GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB is too small: %d", f.second, glConfig.maxTexIndirections );
2817+
*f.first = false;
2818+
}
2819+
}
2820+
}
2821+
2822+
if ( std::make_pair( glConfig.glMajor, glConfig.glMinor ) >= std::make_pair( 3, 2 ) ) {
2823+
glConfig.MSAA = r_MSAA.Get();
2824+
const int maxSamples = std::min( glConfig.maxColorTextureSamples, glConfig.maxDepthTextureSamples );
2825+
2826+
if ( glConfig.MSAA > maxSamples ) {
2827+
Log::Warn( "MSAA samples %i > %i, setting to %i", r_MSAA.Get(), maxSamples, maxSamples );
2828+
glConfig.MSAA = maxSamples;
2829+
}
2830+
} else if ( r_MSAA.Get() ) {
2831+
Log::Warn( "MSAA unavailable because GL version is lower than required (%i.%i < %i.%i)", glConfig.glMajor, glConfig.glMinor, 3, 2 );
2832+
}
2833+
2834+
glConfig.FXAA = r_FXAA.Get();
2835+
2836+
if ( glConfig.FXAA && glConfig.MSAA )
2837+
{
2838+
Log::Notice( "FXAA disabled because MSAA is enabled." );
2839+
glConfig.FXAA = false;
2840+
}
2841+
2842+
if ( glConfig.FXAA && !glConfig.samplerObjectsAvailable )
2843+
{
2844+
Log::Warn( "FXAA disabled because ARB_sampler_objects is not available." );
2845+
glConfig.FXAA = false;
2846+
}
2847+
2848+
glConfig.usingMaterialSystem = r_materialSystem.Get() && glConfig.materialSystemAvailable;
2849+
glConfig.usingBindlessTextures = glConfig.usingMaterialSystem ||
2850+
( r_preferBindlessTextures.Get() && glConfig.bindlessTexturesAvailable );
2851+
glConfig.usingGeometryCache = glConfig.usingMaterialSystem && glConfig.geometryCacheAvailable;
2852+
}
2853+
26782854
static const int R_MODE_FALLBACK = 3; // 640 * 480
26792855

26802856
/* Support code for GLimp_Init */
@@ -2923,6 +3099,8 @@ bool GLimp_Init()
29233099
// initialize extensions
29243100
GLimp_InitExtensions();
29253101

3102+
GLimp_EnableAvailableFeatures();
3103+
29263104
// This depends on SDL_INIT_VIDEO, hence having it here
29273105
ri.IN_Init( window );
29283106

0 commit comments

Comments
 (0)