Skip to content

Commit 703122c

Browse files
committed
Changes to run on an OpenGL core profile.
1 parent f0037f6 commit 703122c

File tree

5 files changed

+60
-107
lines changed

5 files changed

+60
-107
lines changed

daemon/src/engine/renderer/gl_shader.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,21 @@ void GLShaderManager::UpdateShaderProgramUniformLocations( GLShader *shader, sha
255255
// create buffer for uniform firewall
256256
shaderProgram->uniformFirewall = ( byte * ) ri.Z_Malloc( uniformSize );
257257

258-
// create buffer for storing uniform block indexes
259-
shaderProgram->uniformBlockIndexes = ( GLuint * ) ri.Z_Malloc( sizeof( GLuint ) * numUniformBlocks );
260-
261258
// update uniforms
262259
for (GLUniform *uniform : shader->_uniforms)
263260
{
264261
uniform->UpdateShaderProgramUniformLocation( shaderProgram );
265262
}
266-
// update uniform blocks
267-
for (GLUniformBlock *uniformBlock : shader->_uniformBlocks)
268-
{
269-
uniformBlock->UpdateShaderProgramUniformBlockIndex( shaderProgram );
263+
264+
if( GLEW_ARB_uniform_buffer_object || glConfig2.glCoreProfile ) {
265+
// create buffer for storing uniform block indexes
266+
shaderProgram->uniformBlockIndexes = ( GLuint * ) ri.Z_Malloc( sizeof( GLuint ) * numUniformBlocks );
267+
268+
// update uniform blocks
269+
for (GLUniformBlock *uniformBlock : shader->_uniformBlocks)
270+
{
271+
uniformBlock->UpdateShaderProgramUniformBlockIndex( shaderProgram );
272+
}
270273
}
271274
}
272275

@@ -381,7 +384,12 @@ std::string GLShaderManager::BuildDeformShaderText( const std::string& steps ) c
381384
{
382385
std::string shaderText;
383386

384-
shaderText = Str::Format( "#version %d\n", glConfig2.shadingLanguageVersion );
387+
const char *profile = "";
388+
389+
if( glConfig2.shadingLanguageVersion >= 150 ) {
390+
profile = glConfig2.glCoreProfile ? "core" : "compatibility";
391+
}
392+
shaderText = Str::Format( "#version %d %s\n", glConfig2.shadingLanguageVersion, profile );
385393
shaderText += steps + "\n";
386394

387395
// We added a lot of stuff but if we do something bad
@@ -851,10 +859,15 @@ void GLShaderManager::CompileGPUShaders( GLShader *shader, shaderProgram_t *prog
851859

852860
if ( glConfig2.shadingLanguageVersion != 120 )
853861
{
854-
// HACK: abuse the GLSL preprocessor to turn GLSL 1.20 shaders into 1.30 ones
855-
856-
vertexHeader += "#version 130\n";
857-
fragmentHeader += "#version 130\n";
862+
// HACK: abuse the GLSL preprocessor to turn GLSL 1.20 shaders into 1.50 ones
863+
864+
if( glConfig2.glCoreProfile ) {
865+
vertexHeader += "#version 150 core\n";
866+
fragmentHeader += "#version 150 core\n";
867+
} else {
868+
vertexHeader += "#version 150 compatibility\n";
869+
fragmentHeader += "#version 150 compatibility\n";
870+
}
858871

859872
vertexHeader += "#define attribute in\n";
860873
vertexHeader += "#define varying out\n";
@@ -864,10 +877,15 @@ void GLShaderManager::CompileGPUShaders( GLShader *shader, shaderProgram_t *prog
864877
vertexHeader += "#define textureCube texture\n";
865878
vertexHeader += "#define texture2D texture\n";
866879
vertexHeader += "#define texture2DProj textureProj\n";
880+
vertexHeader += "#define texture3D texture\n";
867881

868882
fragmentHeader += "#define textureCube texture\n";
869883
fragmentHeader += "#define texture2D texture\n";
870884
fragmentHeader += "#define texture2DProj textureProj\n";
885+
fragmentHeader += "#define texture3D texture\n";
886+
887+
fragmentHeader += "out vec4 output;\n";
888+
fragmentHeader += "#define gl_FragColor output\n";
871889
}
872890
else
873891
{

daemon/src/engine/renderer/tr_backend.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,11 +2827,13 @@ void RB_RenderPostDepth()
28272827
tess.numVertexes = tr.depthtile2RenderImage->width * tr.depthtile2RenderImage->height;
28282828

28292829
GL_VertexAttribsState( ATTR_POSITION | ATTR_TEXCOORD );
2830-
glEnable( GL_POINT_SPRITE );
2830+
if( !glConfig2.glCoreProfile )
2831+
glEnable( GL_POINT_SPRITE );
28312832
glEnable( GL_PROGRAM_POINT_SIZE );
28322833
Tess_DrawArrays( GL_POINTS );
28332834
glDisable( GL_PROGRAM_POINT_SIZE );
2834-
glDisable( GL_POINT_SPRITE );
2835+
if( !glConfig2.glCoreProfile )
2836+
glDisable( GL_POINT_SPRITE );
28352837
}
28362838

28372839
// back to main image
@@ -5415,7 +5417,7 @@ static const void *RB_SetupLights( const void *data )
54155417

54165418
cmd = ( const setupLightsCommand_t * ) data;
54175419

5418-
if( GLEW_ARB_uniform_buffer_object &&
5420+
if( ( GLEW_ARB_uniform_buffer_object || glConfig2.glCoreProfile ) &&
54195421
(numLights = cmd->refdef.numLights) > 0 ) {
54205422
shaderLight_t *buffer;
54215423

daemon/src/engine/renderer/tr_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ struct glconfig_t
373373
struct glconfig2_t
374374
{
375375
bool ARBTextureCompressionAvailable;
376+
bool glCoreProfile;
376377

377378
int maxCubeMapTextureSize;
378379

daemon/src/engine/renderer/tr_vbo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ void R_InitVBOs()
10231023
nullptr, GL_STREAM_COPY );
10241024
glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
10251025

1026-
if( GLEW_ARB_uniform_buffer_object ) {
1026+
if( GLEW_ARB_uniform_buffer_object || glConfig2.glCoreProfile ) {
10271027
glGenBuffers( 1, &tr.dlightUBO );
10281028
glBindBuffer( GL_UNIFORM_BUFFER, tr.dlightUBO );
10291029
glBufferData( GL_UNIFORM_BUFFER, MAX_REF_LIGHTS * sizeof( shaderLight_t ), nullptr, GL_DYNAMIC_DRAW );
@@ -1101,7 +1101,7 @@ void R_ShutdownVBOs()
11011101
Com_Free_Aligned( tess.vertsBuffer );
11021102
Com_Free_Aligned( tess.indexesBuffer );
11031103

1104-
if( GLEW_ARB_uniform_buffer_object ) {
1104+
if( GLEW_ARB_uniform_buffer_object || glConfig2.glCoreProfile ) {
11051105
glDeleteBuffers( 1, &tr.dlightUBO );
11061106
tr.dlightUBO = 0;
11071107
}

daemon/src/engine/sys/sdl_glimp.cpp

Lines changed: 22 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -619,91 +619,22 @@ static rserr_t GLimp_SetMode( int mode, bool fullscreen, bool noborder )
619619
stencilBits = r_stencilbits->integer;
620620
samples = r_ext_multisample->integer;
621621

622-
for ( i = 0; i < 16; i++ )
622+
for ( i = 0; i < 4; i++ )
623623
{
624-
int testColorBits, testDepthBits, testStencilBits;
624+
int testColorBits, testCore;
625625

626-
// 0 - default
627-
// 1 - minus colorbits
628-
// 2 - minus depthbits
629-
// 3 - minus stencil
630-
if ( ( i % 4 ) == 0 && i )
631-
{
632-
// one pass, reduce
633-
switch ( i / 4 )
634-
{
635-
case 2:
636-
if ( colorBits == 24 )
637-
{
638-
colorBits = 16;
639-
}
640-
641-
break;
642-
643-
case 1:
644-
if ( depthBits == 24 )
645-
{
646-
depthBits = 16;
647-
}
648-
else if ( depthBits == 16 )
649-
{
650-
depthBits = 8;
651-
}
652-
653-
case 3:
654-
if ( stencilBits == 24 )
655-
{
656-
stencilBits = 16;
657-
}
658-
else if ( stencilBits == 16 )
659-
{
660-
stencilBits = 8;
661-
}
662-
}
663-
}
626+
// 0 - 24 bit color, core
627+
// 1 - 24 bit color, compat
628+
// 2 - 16 bit color, core
629+
// 3 - 16 bit color, compat
630+
testColorBits = (i >= 2) ? 16 : 24;
631+
testCore = ((i & 1) == 0);
664632

665-
testColorBits = colorBits;
666-
testDepthBits = depthBits;
667-
testStencilBits = stencilBits;
668-
669-
if ( ( i % 4 ) == 3 )
670-
{
671-
// reduce colorbits
672-
if ( testColorBits == 24 )
673-
{
674-
testColorBits = 16;
675-
}
676-
}
677-
678-
if ( ( i % 4 ) == 2 )
679-
{
680-
// reduce depthbits
681-
if ( testDepthBits == 24 )
682-
{
683-
testDepthBits = 16;
684-
}
685-
else if ( testDepthBits == 16 )
686-
{
687-
testDepthBits = 8;
688-
}
689-
}
633+
if( testCore && !r_glCoreProfile->integer )
634+
continue;
690635

691-
if ( ( i % 4 ) == 1 )
692-
{
693-
// reduce stencilbits
694-
if ( testStencilBits == 24 )
695-
{
696-
testStencilBits = 16;
697-
}
698-
else if ( testStencilBits == 16 )
699-
{
700-
testStencilBits = 8;
701-
}
702-
else
703-
{
704-
testStencilBits = 0;
705-
}
706-
}
636+
if( testColorBits > colorBits )
637+
continue;
707638

708639
if ( testColorBits == 24 )
709640
{
@@ -717,27 +648,27 @@ static rserr_t GLimp_SetMode( int mode, bool fullscreen, bool noborder )
717648
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, perChannelColorBits );
718649
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, perChannelColorBits );
719650
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, perChannelColorBits );
720-
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, alphaBits );
721-
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, testDepthBits );
722-
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, testStencilBits );
723-
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, samples ? 1 : 0 );
724-
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );
725651
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
726652

727653
if ( !r_glAllowSoftware->integer )
728654
{
729655
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
730656
}
731657

732-
if ( r_glCoreProfile->integer || r_glDebugProfile->integer )
658+
if ( testCore || r_glDebugProfile->integer )
733659
{
734660
int major = r_glMajorVersion->integer;
735661
int minor = r_glMinorVersion->integer;
736662

663+
if( testCore && (major < 3 || (major == 3 && minor < 2)) ) {
664+
major = 3;
665+
minor = 2;
666+
}
667+
737668
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, major );
738669
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, minor );
739670

740-
if ( r_glCoreProfile->integer )
671+
if ( testCore )
741672
{
742673
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
743674
}
@@ -771,8 +702,9 @@ static rserr_t GLimp_SetMode( int mode, bool fullscreen, bool noborder )
771702
SDL_GL_SetSwapInterval( r_swapInterval->integer );
772703

773704
glConfig.colorBits = testColorBits;
774-
glConfig.depthBits = testDepthBits;
775-
glConfig.stencilBits = testStencilBits;
705+
glConfig.depthBits = depthBits;
706+
glConfig.stencilBits = stencilBits;
707+
glConfig2.glCoreProfile = testCore;
776708

777709
Log::Notice("Using %d Color bits, %d depth, %d stencil display.",
778710
glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits );

0 commit comments

Comments
 (0)