Skip to content

Commit a9b4be5

Browse files
committed
Merge pull request #425 from Echelon9/fix/SHADER_MODEL-concept-removal
OpenGL: Refactor GLSL setup and remove DirectX Shader Model concept
2 parents e32e21b + 7691c49 commit a9b4be5

22 files changed

+93
-116
lines changed

code/cmdline/cmdline.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ cmdline_parm noglsl_arg("-no_glsl", NULL, AT_NONE); // Cmdline_noglsl -- disa
424424
cmdline_parm mipmap_arg("-mipmap", NULL, AT_NONE); // Cmdline_mipmap
425425
cmdline_parm atiswap_arg("-ati_swap", NULL, AT_NONE); // Cmdline_atiswap - Fix ATI color swap issue for screenshots.
426426
cmdline_parm no3dsound_arg("-no_3d_sound", NULL, AT_NONE); // Cmdline_no_3d_sound - Disable use of full 3D sounds
427-
cmdline_parm no_glsl_models_arg("-disable_glsl_model", NULL, AT_NONE); // Cmdline_no_glsl_model_rendering -- switches model rendering to fixed pipeline
428427
cmdline_parm no_di_mouse_arg("-disable_di_mouse", "Disable DirectInput mouse code (Windows only)", AT_NONE); // Cmdline_no_di_mouse -- Disables directinput use for mouse control
429428
cmdline_parm no_drawrangeelements("-use_gldrawelements", NULL, AT_NONE); // Cmdline_drawelements -- Uses glDrawElements instead of glDrawRangeElements
430429
cmdline_parm keyboard_layout("-keyboard_layout", "Specify keyboard layout (qwertz or azerty)", AT_STRING);
@@ -443,7 +442,6 @@ int Cmdline_no_pbo = 0;
443442
int Cmdline_noglsl = 0;
444443
int Cmdline_ati_color_swap = 0;
445444
int Cmdline_no_3d_sound = 0;
446-
int Cmdline_no_glsl_model_rendering = 0;
447445
int Cmdline_no_di_mouse = 0;
448446
int Cmdline_drawelements = 0;
449447
char* Cmdline_keyboard_layout = NULL;
@@ -1542,10 +1540,6 @@ bool SetCmdlineParams()
15421540
Cmdline_noglsl = 1;
15431541
}
15441542

1545-
if (no_glsl_models_arg.found() ) {
1546-
Cmdline_no_glsl_model_rendering = 1;
1547-
}
1548-
15491543
if (fxaa_arg.found() ) {
15501544
Cmdline_fxaa = true;
15511545

code/cmdline/cmdline.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ extern int Cmdline_noglsl;
130130
extern int Cmdline_mipmap;
131131
extern int Cmdline_ati_color_swap;
132132
extern int Cmdline_no_3d_sound;
133-
extern int Cmdline_no_glsl_model_rendering;
134133
extern int Cmdline_no_di_mouse;
135134
extern int Cmdline_drawelements;
136135
extern char* Cmdline_keyboard_layout;

code/cutscene/oggplayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static void OGG_video_init(theora_info *tinfo)
345345
opengl_set_texture_target(GL_TEXTURE_2D);
346346
opengl_tcache_get_adjusted_texture_size(g_screenWidth, g_screenHeight, &wp2, &hp2);
347347

348-
if(!Use_GLSL)
348+
if(!is_minimum_GLSL_version())
349349
use_shaders = false;
350350

351351
if(use_shaders) {

code/globalincs/def_files.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ char *Default_main_fragment_shader =
15361536
"varying vec4 position;\n"
15371537
"varying vec3 lNormal;\n"
15381538
"\n"
1539-
"#if SHADER_MODEL == 2\n"
1539+
"#if __VERSION__ == 120\n"
15401540
" #define MAX_LIGHTS 2\n"
15411541
"#else\n"
15421542
" #define MAX_LIGHTS 8\n"
@@ -1727,7 +1727,7 @@ char *Default_main_fragment_shader =
17271727
" float dist;\n"
17281728
" #pragma optionNV unroll all\n"
17291729
" for (int i = 0; i < MAX_LIGHTS; ++i) {\n"
1730-
" #if SHADER_MODEL > 2\n"
1730+
" #if __VERSION__ > 120\n"
17311731
" if (i > n_lights)\n"
17321732
" break;\n"
17331733
" #endif\n"
@@ -1737,15 +1737,15 @@ char *Default_main_fragment_shader =
17371737
" lightDir = normalize(gl_LightSource[i].position.xyz);\n"
17381738
" float attenuation = 1.0;\n"
17391739
" #ifndef FLAG_DEFERRED\n"
1740-
" #if SHADER_MODEL > 2\n"
1740+
" #if __VERSION__ > 120\n"
17411741
" if (gl_LightSource[i].position.w == 1.0) {\n"
17421742
" #else\n"
17431743
" if (gl_LightSource[i].position.w == 1.0 && i != 0) {\n"
17441744
" #endif\n"
17451745
" // Positional light source\n"
17461746
" dist = distance(gl_LightSource[i].position.xyz, position.xyz);\n"
17471747
" lightDir = (gl_LightSource[i].position.xyz - position.xyz);\n"
1748-
" #if SHADER_MODEL > 2\n"
1748+
" #if __VERSION__ > 120\n"
17491749
" if (gl_LightSource[i].spotCutoff < 91.0) { // Tube light\n"
17501750
" float beamlength = length(gl_LightSource[i].spotDirection);\n"
17511751
" vec3 beamDir = normalize(gl_LightSource[i].spotDirection);\n"
@@ -1904,14 +1904,6 @@ char* Default_fxaa_fragment_shader =
19041904
"#extension GL_EXT_gpu_shader4 : enable\n"
19051905
"#define FXAA_EARLY_EXIT 1\n"
19061906
"#define FXAA_DISCARD 1\n"
1907-
"#if SHADER_MODEL == 2\n"
1908-
" #define FXAA_GLSL_120 1\n"
1909-
" #define FXAA_GLSL_130 0\n"
1910-
"#endif\n"
1911-
"#if SHADER_MODEL > 2\n"
1912-
" #define FXAA_GLSL_120 0\n"
1913-
" #define FXAA_GLSL_130 1\n"
1914-
"#endif\n"
19151907
"#ifndef FXAA_FAST_PIXEL_OFFSET\n"
19161908
" #ifdef GL_EXT_gpu_shader4\n"
19171909
" #define FXAA_FAST_PIXEL_OFFSET 1\n"

code/graphics/2d.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ void poly_list::allocate(int _verts)
17401740
tsb = (tsb_t*)vm_malloc(sizeof(tsb_t) * _verts);
17411741
}
17421742

1743-
if ( Use_GLSL >= 3 ) {
1743+
if ( GLSL_version >= 130 ) {
17441744
submodels = (int*)vm_malloc(sizeof(int) * _verts);
17451745
}
17461746

@@ -1922,7 +1922,7 @@ void poly_list::make_index_buffer(SCP_vector<int> &vertex_list)
19221922
buffer_list_internal.tsb[z] = tsb[j];
19231923
}
19241924

1925-
if ( Use_GLSL >= 3 ) {
1925+
if ( GLSL_version >= 130 ) {
19261926
buffer_list_internal.submodels[z] = submodels[j];
19271927
}
19281928

@@ -1952,7 +1952,7 @@ poly_list& poly_list::operator = (poly_list &other_list)
19521952
memcpy(tsb, other_list.tsb, sizeof(tsb_t) * other_list.n_verts);
19531953
}
19541954

1955-
if ( Use_GLSL >= 3 ) {
1955+
if ( GLSL_version >= 130 ) {
19561956
memcpy(submodels, other_list.submodels, sizeof(int) * other_list.n_verts);
19571957
}
19581958

@@ -2147,7 +2147,7 @@ uint gr_determine_model_shader_flags(
21472147
) {
21482148
uint shader_flags = 0;
21492149

2150-
if ( Use_GLSL > 1 ) {
2150+
if ( GLSL_version >= 120 ) {
21512151
shader_flags |= SDR_FLAG_MODEL_CLIP;
21522152
}
21532153

code/graphics/grbatch.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,12 @@ int batch_add_bitmap(int texture, int tmap_flags, vertex *pnt, int orient, float
728728
return 1;
729729
}
730730

731-
if ( tmap_flags & TMAP_FLAG_SOFT_QUAD && ( !Cmdline_softparticles || Use_GLSL <= 2 ) ) {
731+
if ( tmap_flags & TMAP_FLAG_SOFT_QUAD && ( !Cmdline_softparticles || GLSL_version <= 120 ) ) {
732732
// don't render this as a soft particle if we don't support soft particles
733733
tmap_flags &= ~(TMAP_FLAG_SOFT_QUAD);
734734
}
735735

736-
if ( Use_GLSL > 2 && Cmdline_softparticles && !Cmdline_no_geo_sdr_effects && Is_Extension_Enabled(OGL_EXT_GEOMETRY_SHADER4) && (tmap_flags & TMAP_FLAG_VERTEX_GEN) ) {
736+
if ( GLSL_version > 120 && Cmdline_softparticles && !Cmdline_no_geo_sdr_effects && Is_Extension_Enabled(OGL_EXT_GEOMETRY_SHADER4) && (tmap_flags & TMAP_FLAG_VERTEX_GEN) ) {
737737
geometry_batch_add_bitmap(texture, tmap_flags, pnt, orient, rad, alpha, depth);
738738
return 0;
739739
} else if ( tmap_flags & TMAP_FLAG_VERTEX_GEN ) {
@@ -797,7 +797,7 @@ int batch_add_bitmap_rotated(int texture, int tmap_flags, vertex *pnt, float ang
797797
return 1;
798798
}
799799

800-
if ( tmap_flags & TMAP_FLAG_SOFT_QUAD && ( !Cmdline_softparticles || Use_GLSL <= 2 ) ) {
800+
if ( tmap_flags & TMAP_FLAG_SOFT_QUAD && ( !Cmdline_softparticles || GLSL_version <= 120 ) ) {
801801
// don't render this as a soft particle if we don't support soft particles
802802
tmap_flags &= ~(TMAP_FLAG_SOFT_QUAD);
803803
}
@@ -1179,7 +1179,7 @@ int distortion_add_bitmap_rotated(int texture, int tmap_flags, vertex *pnt, floa
11791179
return 1;
11801180
}
11811181

1182-
if ( Use_GLSL < 2 || !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) ) {
1182+
if ( GLSL_version < 120 || !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) ) {
11831183
// don't render distortions if we can't support them.
11841184
return 0;
11851185
}
@@ -1214,7 +1214,7 @@ int distortion_add_beam(int texture, int tmap_flags, vec3d *start, vec3d *end, f
12141214
return 1;
12151215
}
12161216

1217-
if ( Use_GLSL < 2 || !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) ) {
1217+
if ( GLSL_version < 120 || !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) ) {
12181218
// don't render distortions if we can't support them.
12191219
return 0;
12201220
}

code/graphics/gropengl.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ typedef int ( * PFNGLXSWAPINTERVALSGIPROC) (int interval);
5151
// minimum GL version we can reliably support is 1.2
5252
static const int MIN_REQUIRED_GL_VERSION = 12;
5353

54+
// minimum GLSL version we can reliably support is 110
55+
static const int MIN_REQUIRED_GLSL_VERSION = 110;
56+
5457
int GL_version = 0;
58+
int GLSL_version = 0;
5559

5660
bool GL_initted = 0;
5761

@@ -71,7 +75,6 @@ static ushort *GL_original_gamma_ramp = NULL;
7175

7276
int Use_VBOs = 0;
7377
int Use_PBOs = 0;
74-
int Use_GLSL = 0;
7578

7679
static int GL_dump_frames = 0;
7780
static ubyte *GL_dump_buffer = NULL;
@@ -2011,7 +2014,7 @@ bool gr_opengl_init()
20112014
GLint max_texture_units = GL_supported_texture_units;
20122015
GLint max_texture_coords = GL_supported_texture_units;
20132016

2014-
if (Use_GLSL) {
2017+
if (is_minimum_GLSL_version()) {
20152018
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units);
20162019
}
20172020

@@ -2091,7 +2094,7 @@ bool gr_opengl_init()
20912094
mprintf(( " Post-processing enabled: %s\n", (Cmdline_postprocess) ? "YES" : "NO"));
20922095
mprintf(( " Using %s texture filter.\n", (GL_mipmap_filter) ? NOX("trilinear") : NOX("bilinear") ));
20932096

2094-
if (Use_GLSL) {
2097+
if (is_minimum_GLSL_version()) {
20952098
mprintf(( " OpenGL Shader Version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION) ));
20962099
}
20972100

@@ -2166,3 +2169,15 @@ DCF(ogl_anisotropy, "toggles anisotropic filtering")
21662169
// opengl_set_anisotropy( (float)Dc_arg_float );
21672170
}
21682171
}
2172+
2173+
/**
2174+
* Helper function to enquire whether minimum GLSL version present.
2175+
*
2176+
* Compares global variable set by glGetString(GL_SHADING_LANGUAGE_VERSION)
2177+
* against compile time MIN_REQUIRED_GLSL_VERSION.
2178+
*
2179+
* @return true if GLSL support present is above the minimum version.
2180+
*/
2181+
bool is_minimum_GLSL_version() {
2182+
return GLSL_version >= MIN_REQUIRED_GLSL_VERSION ? true : false;
2183+
}

code/graphics/gropengl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ const ubyte GL_zero_3ub[3] = { 0, 0, 0 };
655655
bool gr_opengl_init();
656656
void gr_opengl_cleanup(int minimize=1);
657657
int opengl_check_for_errors(char *err_at = NULL);
658+
bool is_minimum_GLSL_version();
658659

659660
#ifndef NDEBUG
660661
#define GL_CHECK_FOR_ERRORS(s) opengl_check_for_errors((s))
@@ -663,9 +664,9 @@ int opengl_check_for_errors(char *err_at = NULL);
663664
#endif
664665

665666
extern int GL_version;
667+
extern int GLSL_version;
666668

667669
extern int Use_VBOs;
668670
extern int Use_PBOs;
669-
extern int Use_GLSL;
670671

671672
#endif

code/graphics/gropengldraw.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,7 +2546,7 @@ void opengl_setup_scene_textures()
25462546
{
25472547
Scene_texture_initialized = 0;
25482548

2549-
if ( !Use_GLSL || Cmdline_no_fbo || !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) ) {
2549+
if ( !is_minimum_GLSL_version() || Cmdline_no_fbo || !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) ) {
25502550
Cmdline_postprocess = 0;
25512551
Cmdline_softparticles = 0;
25522552
Cmdline_fb_explosions = 0;
@@ -3067,7 +3067,7 @@ void opengl_clear_deferred_buffers()
30673067

30683068
void gr_opengl_deferred_lighting_begin()
30693069
{
3070-
if (Use_GLSL < 2 || Cmdline_no_deferred_lighting)
3070+
if (GLSL_version < 120 || Cmdline_no_deferred_lighting)
30713071
return;
30723072

30733073
Deferred_lighting = true;
@@ -3093,7 +3093,7 @@ extern float static_tube_factor;
30933093

30943094
void gr_opengl_deferred_lighting_finish()
30953095
{
3096-
if ( Use_GLSL < 2 || Cmdline_no_deferred_lighting ) {
3096+
if ( GLSL_version < 120 || Cmdline_no_deferred_lighting ) {
30973097
return;
30983098
}
30993099

code/graphics/gropenglextension.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -444,41 +444,30 @@ void opengl_extensions_init()
444444
sscanf(glsl_ver, "%d.%d", &major, &minor);
445445
ver = (major * 100) + minor;
446446

447-
// SM 4.0 compatible or better
448-
if (ver >= 400) {
449-
Use_GLSL = 4;
450-
}
451-
// SM 3.0 compatible
452-
else if ( ver >= 130 ) {
453-
Use_GLSL = 3;
454-
}
455-
// SM 2.0 compatible
456-
else if (ver >= 120) {
457-
Use_GLSL = 2;
458-
}
459-
// we require GLSL 1.20 or higher
460-
else if (ver < 110) {
461-
Use_GLSL = 0;
447+
GLSL_version = ver;
448+
449+
// we require a minimum GLSL version
450+
if (!is_minimum_GLSL_version()) {
462451
mprintf((" OpenGL Shading Language version %s is not sufficient to use GLSL mode in FSO. Defaulting to fixed-function renderer.\n", glGetString(GL_SHADING_LANGUAGE_VERSION) ));
463452
}
464453
}
465454

466455
// can't have this stuff without GLSL support
467-
if ( !Use_GLSL ) {
456+
if ( !is_minimum_GLSL_version() ) {
468457
Cmdline_normal = 0;
469458
Cmdline_height = 0;
470459
Cmdline_postprocess = 0;
471460
Cmdline_shadow_quality = 0;
472461
Cmdline_no_deferred_lighting = 1;
473462
}
474463

475-
if ( Use_GLSL < 2 || !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) || !Is_Extension_Enabled(OGL_ARB_FLOATING_POINT_TEXTURES) ) {
464+
if ( GLSL_version < 120 || !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) || !Is_Extension_Enabled(OGL_ARB_FLOATING_POINT_TEXTURES) ) {
476465
mprintf((" No hardware support for deferred lighting. Deferred lighting will be disabled. \n"));
477466
Cmdline_no_deferred_lighting = 1;
478467
Cmdline_no_batching = true;
479468
}
480469

481-
if (Use_GLSL) {
470+
if (is_minimum_GLSL_version()) {
482471
GLint max_texture_units;
483472
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &max_texture_units);
484473

@@ -493,7 +482,7 @@ void opengl_extensions_init()
493482
Cmdline_height = 0;
494483
} else if (max_texture_units < 4) {
495484
mprintf(( "Not enough texture units found for GLSL support. We need at least 4, we found %d.\n", max_texture_units ));
496-
Use_GLSL = 0;
485+
GLSL_version = 0;
497486
}
498487
}
499488
}

0 commit comments

Comments
 (0)