Permalink
Browse files

Changes to run on an OpenGL core profile.

  • Loading branch information...
1 parent f0037f6 commit 703122c93024eaa2da265dffd05cd024b9014f6f @gimhael gimhael committed Mar 7, 2016
@@ -255,18 +255,21 @@ void GLShaderManager::UpdateShaderProgramUniformLocations( GLShader *shader, sha
// create buffer for uniform firewall
shaderProgram->uniformFirewall = ( byte * ) ri.Z_Malloc( uniformSize );
- // create buffer for storing uniform block indexes
- shaderProgram->uniformBlockIndexes = ( GLuint * ) ri.Z_Malloc( sizeof( GLuint ) * numUniformBlocks );
-
// update uniforms
for (GLUniform *uniform : shader->_uniforms)
{
uniform->UpdateShaderProgramUniformLocation( shaderProgram );
}
- // update uniform blocks
- for (GLUniformBlock *uniformBlock : shader->_uniformBlocks)
- {
- uniformBlock->UpdateShaderProgramUniformBlockIndex( shaderProgram );
+
+ if( GLEW_ARB_uniform_buffer_object || glConfig2.glCoreProfile ) {
+ // create buffer for storing uniform block indexes
+ shaderProgram->uniformBlockIndexes = ( GLuint * ) ri.Z_Malloc( sizeof( GLuint ) * numUniformBlocks );
+
+ // update uniform blocks
+ for (GLUniformBlock *uniformBlock : shader->_uniformBlocks)
+ {
+ uniformBlock->UpdateShaderProgramUniformBlockIndex( shaderProgram );
+ }
}
}
@@ -381,7 +384,12 @@ std::string GLShaderManager::BuildDeformShaderText( const std::string& steps ) c
{
std::string shaderText;
- shaderText = Str::Format( "#version %d\n", glConfig2.shadingLanguageVersion );
+ const char *profile = "";
+
+ if( glConfig2.shadingLanguageVersion >= 150 ) {
+ profile = glConfig2.glCoreProfile ? "core" : "compatibility";
+ }
+ shaderText = Str::Format( "#version %d %s\n", glConfig2.shadingLanguageVersion, profile );
shaderText += steps + "\n";
// We added a lot of stuff but if we do something bad
@@ -851,10 +859,15 @@ void GLShaderManager::CompileGPUShaders( GLShader *shader, shaderProgram_t *prog
if ( glConfig2.shadingLanguageVersion != 120 )
{
- // HACK: abuse the GLSL preprocessor to turn GLSL 1.20 shaders into 1.30 ones
-
- vertexHeader += "#version 130\n";
- fragmentHeader += "#version 130\n";
+ // HACK: abuse the GLSL preprocessor to turn GLSL 1.20 shaders into 1.50 ones
+
+ if( glConfig2.glCoreProfile ) {
+ vertexHeader += "#version 150 core\n";
+ fragmentHeader += "#version 150 core\n";
+ } else {
+ vertexHeader += "#version 150 compatibility\n";
+ fragmentHeader += "#version 150 compatibility\n";
+ }
vertexHeader += "#define attribute in\n";
vertexHeader += "#define varying out\n";
@@ -864,10 +877,15 @@ void GLShaderManager::CompileGPUShaders( GLShader *shader, shaderProgram_t *prog
vertexHeader += "#define textureCube texture\n";
vertexHeader += "#define texture2D texture\n";
vertexHeader += "#define texture2DProj textureProj\n";
+ vertexHeader += "#define texture3D texture\n";
fragmentHeader += "#define textureCube texture\n";
fragmentHeader += "#define texture2D texture\n";
fragmentHeader += "#define texture2DProj textureProj\n";
+ fragmentHeader += "#define texture3D texture\n";
+
+ fragmentHeader += "out vec4 output;\n";
+ fragmentHeader += "#define gl_FragColor output\n";
}
else
{
@@ -2827,11 +2827,13 @@ void RB_RenderPostDepth()
tess.numVertexes = tr.depthtile2RenderImage->width * tr.depthtile2RenderImage->height;
GL_VertexAttribsState( ATTR_POSITION | ATTR_TEXCOORD );
- glEnable( GL_POINT_SPRITE );
+ if( !glConfig2.glCoreProfile )
+ glEnable( GL_POINT_SPRITE );
glEnable( GL_PROGRAM_POINT_SIZE );
Tess_DrawArrays( GL_POINTS );
glDisable( GL_PROGRAM_POINT_SIZE );
- glDisable( GL_POINT_SPRITE );
+ if( !glConfig2.glCoreProfile )
+ glDisable( GL_POINT_SPRITE );
}
// back to main image
@@ -5415,7 +5417,7 @@ static const void *RB_SetupLights( const void *data )
cmd = ( const setupLightsCommand_t * ) data;
- if( GLEW_ARB_uniform_buffer_object &&
+ if( ( GLEW_ARB_uniform_buffer_object || glConfig2.glCoreProfile ) &&
(numLights = cmd->refdef.numLights) > 0 ) {
shaderLight_t *buffer;
@@ -373,6 +373,7 @@ struct glconfig_t
struct glconfig2_t
{
bool ARBTextureCompressionAvailable;
+ bool glCoreProfile;
int maxCubeMapTextureSize;
@@ -1023,7 +1023,7 @@ void R_InitVBOs()
nullptr, GL_STREAM_COPY );
glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
- if( GLEW_ARB_uniform_buffer_object ) {
+ if( GLEW_ARB_uniform_buffer_object || glConfig2.glCoreProfile ) {
glGenBuffers( 1, &tr.dlightUBO );
glBindBuffer( GL_UNIFORM_BUFFER, tr.dlightUBO );
glBufferData( GL_UNIFORM_BUFFER, MAX_REF_LIGHTS * sizeof( shaderLight_t ), nullptr, GL_DYNAMIC_DRAW );
@@ -1101,7 +1101,7 @@ void R_ShutdownVBOs()
Com_Free_Aligned( tess.vertsBuffer );
Com_Free_Aligned( tess.indexesBuffer );
- if( GLEW_ARB_uniform_buffer_object ) {
+ if( GLEW_ARB_uniform_buffer_object || glConfig2.glCoreProfile ) {
glDeleteBuffers( 1, &tr.dlightUBO );
tr.dlightUBO = 0;
}
@@ -619,91 +619,22 @@ static rserr_t GLimp_SetMode( int mode, bool fullscreen, bool noborder )
stencilBits = r_stencilbits->integer;
samples = r_ext_multisample->integer;
- for ( i = 0; i < 16; i++ )
+ for ( i = 0; i < 4; i++ )
{
- int testColorBits, testDepthBits, testStencilBits;
+ int testColorBits, testCore;
- // 0 - default
- // 1 - minus colorbits
- // 2 - minus depthbits
- // 3 - minus stencil
- if ( ( i % 4 ) == 0 && i )
- {
- // one pass, reduce
- switch ( i / 4 )
- {
- case 2:
- if ( colorBits == 24 )
- {
- colorBits = 16;
- }
-
- break;
-
- case 1:
- if ( depthBits == 24 )
- {
- depthBits = 16;
- }
- else if ( depthBits == 16 )
- {
- depthBits = 8;
- }
-
- case 3:
- if ( stencilBits == 24 )
- {
- stencilBits = 16;
- }
- else if ( stencilBits == 16 )
- {
- stencilBits = 8;
- }
- }
- }
+ // 0 - 24 bit color, core
+ // 1 - 24 bit color, compat
+ // 2 - 16 bit color, core
+ // 3 - 16 bit color, compat
+ testColorBits = (i >= 2) ? 16 : 24;
+ testCore = ((i & 1) == 0);
- testColorBits = colorBits;
- testDepthBits = depthBits;
- testStencilBits = stencilBits;
-
- if ( ( i % 4 ) == 3 )
- {
- // reduce colorbits
- if ( testColorBits == 24 )
- {
- testColorBits = 16;
- }
- }
-
- if ( ( i % 4 ) == 2 )
- {
- // reduce depthbits
- if ( testDepthBits == 24 )
- {
- testDepthBits = 16;
- }
- else if ( testDepthBits == 16 )
- {
- testDepthBits = 8;
- }
- }
+ if( testCore && !r_glCoreProfile->integer )
+ continue;
- if ( ( i % 4 ) == 1 )
- {
- // reduce stencilbits
- if ( testStencilBits == 24 )
- {
- testStencilBits = 16;
- }
- else if ( testStencilBits == 16 )
- {
- testStencilBits = 8;
- }
- else
- {
- testStencilBits = 0;
- }
- }
+ if( testColorBits > colorBits )
+ continue;
if ( testColorBits == 24 )
{
@@ -717,27 +648,27 @@ static rserr_t GLimp_SetMode( int mode, bool fullscreen, bool noborder )
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, perChannelColorBits );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, perChannelColorBits );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, perChannelColorBits );
- SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, alphaBits );
- SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, testDepthBits );
- SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, testStencilBits );
- SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, samples ? 1 : 0 );
- SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if ( !r_glAllowSoftware->integer )
{
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
}
- if ( r_glCoreProfile->integer || r_glDebugProfile->integer )
+ if ( testCore || r_glDebugProfile->integer )
{
int major = r_glMajorVersion->integer;
int minor = r_glMinorVersion->integer;
+ if( testCore && (major < 3 || (major == 3 && minor < 2)) ) {
+ major = 3;
+ minor = 2;
+ }
+
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, major );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, minor );
- if ( r_glCoreProfile->integer )
+ if ( testCore )
{
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
}
@@ -771,8 +702,9 @@ static rserr_t GLimp_SetMode( int mode, bool fullscreen, bool noborder )
SDL_GL_SetSwapInterval( r_swapInterval->integer );
glConfig.colorBits = testColorBits;
- glConfig.depthBits = testDepthBits;
- glConfig.stencilBits = testStencilBits;
+ glConfig.depthBits = depthBits;
+ glConfig.stencilBits = stencilBits;
+ glConfig2.glCoreProfile = testCore;
Log::Notice("Using %d Color bits, %d depth, %d stencil display.",
glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits );

0 comments on commit 703122c

Please sign in to comment.