2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2014-04-20 14:29:58 +00:00
|
|
|
Copyright (C) 2013-2014 Robert Beckebans
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
#include "tr_local.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
idRenderProgManager renderProgManager;
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::idRenderProgManager()
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idRenderProgManager::idRenderProgManager()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::~idRenderProgManager()
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idRenderProgManager::~idRenderProgManager()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
R_ReloadShaders
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
static void R_ReloadShaders( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
renderProgManager.KillAllShaders();
|
|
|
|
renderProgManager.LoadAllShaders();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::Init()
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::Init()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "----- Initializing Render Shaders -----\n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
for( int i = 0; i < MAX_BUILTINS; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
builtinShaders[i] = -1;
|
|
|
|
}
|
2014-04-20 14:29:58 +00:00
|
|
|
|
|
|
|
// RB: added checks for GPU skinning
|
2012-11-28 15:47:07 +00:00
|
|
|
struct builtinShaders_t
|
|
|
|
{
|
2014-05-10 12:40:01 +00:00
|
|
|
int index;
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* name;
|
2014-05-10 12:40:01 +00:00
|
|
|
const char* nameOutSuffix;
|
|
|
|
uint32 shaderFeatures;
|
|
|
|
bool requireGPUSkinningSupport;
|
2012-11-28 15:47:07 +00:00
|
|
|
} builtins[] =
|
|
|
|
{
|
2014-05-10 12:40:01 +00:00
|
|
|
{ BUILTIN_GUI, "gui.vfp", 0, false },
|
|
|
|
{ BUILTIN_COLOR, "color.vfp", 0, false },
|
|
|
|
// RB begin
|
|
|
|
{ BUILTIN_COLOR_SKINNED, "color", "_skinned", BIT( USE_GPU_SKINNING ), true },
|
|
|
|
{ BUILTIN_VERTEX_COLOR, "vertex_color.vfp", "", 0, false },
|
|
|
|
// RB end
|
|
|
|
// { BUILTIN_SIMPLESHADE, "simpleshade.vfp", 0, false },
|
|
|
|
{ BUILTIN_TEXTURED, "texture.vfp", 0, false },
|
|
|
|
{ BUILTIN_TEXTURE_VERTEXCOLOR, "texture_color.vfp", 0, false },
|
|
|
|
{ BUILTIN_TEXTURE_VERTEXCOLOR_SKINNED, "texture_color_skinned.vfp", 0, true },
|
|
|
|
{ BUILTIN_TEXTURE_TEXGEN_VERTEXCOLOR, "texture_color_texgen.vfp", 0, false },
|
|
|
|
// RB begin
|
|
|
|
{ BUILTIN_INTERACTION, "interaction.vfp", "", 0, false },
|
|
|
|
{ BUILTIN_INTERACTION_SKINNED, "interaction", "_skinned", BIT( USE_GPU_SKINNING ), true },
|
|
|
|
{ BUILTIN_INTERACTION_AMBIENT, "interactionAmbient.vfp", 0, false },
|
|
|
|
{ BUILTIN_INTERACTION_AMBIENT_SKINNED, "interactionAmbient_skinned.vfp", 0, true },
|
|
|
|
{ BUILTIN_INTERACTION_SHADOW_MAPPING_SPOT, "interactionSM", "_spot", 0, false },
|
|
|
|
{ BUILTIN_INTERACTION_SHADOW_MAPPING_SPOT_SKINNED, "interactionSM", "_spot_skinned", BIT( USE_GPU_SKINNING ), true },
|
|
|
|
{ BUILTIN_INTERACTION_SHADOW_MAPPING_POINT, "interactionSM", "_point", BIT( LIGHT_POINT ), false },
|
|
|
|
{ BUILTIN_INTERACTION_SHADOW_MAPPING_POINT_SKINNED, "interactionSM", "_point_skinned", BIT( USE_GPU_SKINNING ) | BIT( LIGHT_POINT ), true },
|
|
|
|
{ BUILTIN_INTERACTION_SHADOW_MAPPING_PARALLEL, "interactionSM", "_parallel", BIT( LIGHT_PARALLEL ), false },
|
|
|
|
{ BUILTIN_INTERACTION_SHADOW_MAPPING_PARALLEL_SKINNED, "interactionSM", "_parallel_skinned", BIT( USE_GPU_SKINNING ) | BIT( LIGHT_PARALLEL ), true },
|
|
|
|
// RB end
|
|
|
|
{ BUILTIN_ENVIRONMENT, "environment.vfp", 0, false },
|
|
|
|
{ BUILTIN_ENVIRONMENT_SKINNED, "environment_skinned.vfp", 0, true },
|
|
|
|
{ BUILTIN_BUMPY_ENVIRONMENT, "bumpyenvironment.vfp", 0, false },
|
|
|
|
{ BUILTIN_BUMPY_ENVIRONMENT_SKINNED, "bumpyenvironment_skinned.vfp", 0, true },
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2014-05-10 12:40:01 +00:00
|
|
|
{ BUILTIN_DEPTH, "depth.vfp", 0, false },
|
|
|
|
{ BUILTIN_DEPTH_SKINNED, "depth_skinned.vfp", 0, true },
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2014-05-10 12:40:01 +00:00
|
|
|
{ BUILTIN_SHADOW, "shadow.vfp", 0, false },
|
|
|
|
{ BUILTIN_SHADOW_SKINNED, "shadow_skinned.vfp", 0, true },
|
|
|
|
|
|
|
|
{ BUILTIN_SHADOW_DEBUG, "shadowDebug.vfp", 0, false },
|
|
|
|
{ BUILTIN_SHADOW_DEBUG_SKINNED, "shadowDebug_skinned.vfp", 0, true },
|
|
|
|
|
|
|
|
{ BUILTIN_BLENDLIGHT, "blendlight.vfp", 0, false },
|
|
|
|
{ BUILTIN_FOG, "fog.vfp", 0, false },
|
|
|
|
{ BUILTIN_FOG_SKINNED, "fog_skinned.vfp", 0, true },
|
|
|
|
{ BUILTIN_SKYBOX, "skybox.vfp", 0, false },
|
|
|
|
{ BUILTIN_WOBBLESKY, "wobblesky.vfp", 0, false },
|
|
|
|
{ BUILTIN_POSTPROCESS, "postprocess.vfp", 0, false },
|
|
|
|
{ BUILTIN_STEREO_DEGHOST, "stereoDeGhost.vfp", 0, false },
|
|
|
|
{ BUILTIN_STEREO_WARP, "stereoWarp.vfp", 0, false },
|
|
|
|
// { BUILTIN_ZCULL_RECONSTRUCT, "zcullReconstruct.vfp", 0, false },
|
|
|
|
{ BUILTIN_BINK, "bink.vfp", 0, false },
|
|
|
|
{ BUILTIN_BINK_GUI, "bink_gui.vfp", 0, false },
|
|
|
|
{ BUILTIN_STEREO_INTERLACE, "stereoInterlace.vfp", 0, false },
|
|
|
|
{ BUILTIN_MOTION_BLUR, "motionBlur.vfp", 0, false },
|
|
|
|
|
|
|
|
// RB begin
|
|
|
|
{ BUILTIN_DEBUG_SHADOWMAP, "debug_shadowmap.vfp", "", 0, false },
|
|
|
|
// RB end
|
2012-11-26 18:58:24 +00:00
|
|
|
};
|
|
|
|
int numBuiltins = sizeof( builtins ) / sizeof( builtins[0] );
|
|
|
|
vertexShaders.SetNum( numBuiltins );
|
|
|
|
fragmentShaders.SetNum( numBuiltins );
|
|
|
|
glslPrograms.SetNum( numBuiltins );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < numBuiltins; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vertexShaders[i].name = builtins[i].name;
|
2014-05-10 12:40:01 +00:00
|
|
|
vertexShaders[i].nameOutSuffix = builtins[i].nameOutSuffix;
|
|
|
|
vertexShaders[i].shaderFeatures = builtins[i].shaderFeatures;
|
|
|
|
vertexShaders[i].builtin = true;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
fragmentShaders[i].name = builtins[i].name;
|
2014-05-10 12:40:01 +00:00
|
|
|
fragmentShaders[i].nameOutSuffix = builtins[i].nameOutSuffix;
|
|
|
|
fragmentShaders[i].shaderFeatures = builtins[i].shaderFeatures;
|
|
|
|
fragmentShaders[i].builtin = true;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
builtinShaders[builtins[i].index] = i;
|
2014-04-20 14:29:58 +00:00
|
|
|
|
|
|
|
if( builtins[i].requireGPUSkinningSupport && !glConfig.gpuSkinningAvailable )
|
|
|
|
{
|
|
|
|
// RB: don't try to load shaders that would break the GLSL compiler in the OpenGL driver
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
LoadVertexShader( i );
|
|
|
|
LoadFragmentShader( i );
|
|
|
|
LoadGLSLProgram( i, i, i );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2014-04-20 14:29:58 +00:00
|
|
|
// special case handling for fastZ shaders
|
|
|
|
/*
|
|
|
|
switch( glConfig.driverType )
|
|
|
|
{
|
|
|
|
case GLDRV_OPENGL32_CORE_PROFILE:
|
|
|
|
case GLDRV_OPENGL_ES2:
|
|
|
|
case GLDRV_OPENGL_ES3:
|
|
|
|
case GLDRV_OPENGL_MESA:
|
|
|
|
{
|
|
|
|
builtinShaders[BUILTIN_SHADOW] = FindVertexShader( "shadow.vp" );
|
|
|
|
int shadowFragmentShaderIndex = FindFragmentShader( "shadow.fp" );
|
|
|
|
FindGLSLProgram( "shadow.vp", builtinShaders[BUILTIN_SHADOW], shadowFragmentShaderIndex );
|
|
|
|
|
|
|
|
if( glConfig.gpuSkinningAvailable )
|
|
|
|
{
|
|
|
|
builtinShaders[BUILTIN_SHADOW_SKINNED] = FindVertexShader( "shadow_skinned.vp" );
|
|
|
|
int shadowFragmentShaderIndex = FindFragmentShader( "shadow_skinned.fp" );
|
|
|
|
FindGLSLProgram( "shadow_skinned.vp", builtinShaders[BUILTIN_SHADOW_SKINNED], shadowFragmentShaderIndex );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// fast path on PC
|
|
|
|
builtinShaders[BUILTIN_SHADOW] = FindVertexShader( "shadow.vp" );
|
|
|
|
FindGLSLProgram( "shadow.vp", builtinShaders[BUILTIN_SHADOW], -1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2014-04-20 14:29:58 +00:00
|
|
|
if( glConfig.gpuSkinningAvailable )
|
|
|
|
{
|
|
|
|
builtinShaders[BUILTIN_SHADOW_SKINNED] = FindVertexShader( "shadow_skinned.vp" );
|
|
|
|
FindGLSLProgram( "shadow_skinned.vp", builtinShaders[BUILTIN_SHADOW_SKINNED], -1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
glslUniforms.SetNum( RENDERPARM_USER + MAX_GLSL_USER_PARMS, vec4_zero );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2014-04-20 14:29:58 +00:00
|
|
|
if( glConfig.gpuSkinningAvailable )
|
|
|
|
{
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_TEXTURE_VERTEXCOLOR_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_INTERACTION_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_INTERACTION_AMBIENT_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_ENVIRONMENT_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_BUMPY_ENVIRONMENT_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_DEPTH_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_SHADOW_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_SHADOW_DEBUG_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_FOG_SKINNED]].usesJoints = true;
|
2014-05-10 12:40:01 +00:00
|
|
|
// RB begin
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_INTERACTION_SHADOW_MAPPING_SPOT_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_INTERACTION_SHADOW_MAPPING_POINT_SKINNED]].usesJoints = true;
|
|
|
|
vertexShaders[builtinShaders[BUILTIN_INTERACTION_SHADOW_MAPPING_PARALLEL_SKINNED]].usesJoints = true;
|
|
|
|
// RB end
|
2014-04-20 14:29:58 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
cmdSystem->AddCommand( "reloadShaders", R_ReloadShaders, CMD_FL_RENDERER, "reloads shaders" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::LoadAllShaders()
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::LoadAllShaders()
|
|
|
|
{
|
|
|
|
for( int i = 0; i < vertexShaders.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
LoadVertexShader( i );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < fragmentShaders.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
LoadFragmentShader( i );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < glslPrograms.Num(); ++i )
|
|
|
|
{
|
2014-05-10 12:40:01 +00:00
|
|
|
if( glslPrograms[i].vertexShaderIndex == -1 || glslPrograms[i].fragmentShaderIndex == -1 )
|
|
|
|
{
|
|
|
|
// RB: skip reloading because we didn't load it initially
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
LoadGLSLProgram( i, glslPrograms[i].vertexShaderIndex, glslPrograms[i].fragmentShaderIndex );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::KillAllShaders()
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::KillAllShaders()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Unbind();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < vertexShaders.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( vertexShaders[i].progId != INVALID_PROGID )
|
|
|
|
{
|
2012-12-17 16:30:59 +00:00
|
|
|
glDeleteShader( vertexShaders[i].progId );
|
2012-11-26 18:58:24 +00:00
|
|
|
vertexShaders[i].progId = INVALID_PROGID;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < fragmentShaders.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( fragmentShaders[i].progId != INVALID_PROGID )
|
|
|
|
{
|
2012-12-17 16:30:59 +00:00
|
|
|
glDeleteShader( fragmentShaders[i].progId );
|
2012-11-26 18:58:24 +00:00
|
|
|
fragmentShaders[i].progId = INVALID_PROGID;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < glslPrograms.Num(); ++i )
|
|
|
|
{
|
|
|
|
if( glslPrograms[i].progId != INVALID_PROGID )
|
|
|
|
{
|
2012-12-17 16:30:59 +00:00
|
|
|
glDeleteProgram( glslPrograms[i].progId );
|
2012-11-26 18:58:24 +00:00
|
|
|
glslPrograms[i].progId = INVALID_PROGID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::Shutdown()
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::Shutdown()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
KillAllShaders();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::FindVertexShader
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idRenderProgManager::FindVertexShader( const char* name )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < vertexShaders.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( vertexShaders[i].name.Icmp( name ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
LoadVertexShader( i );
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vertexShader_t shader;
|
|
|
|
shader.name = name;
|
|
|
|
int index = vertexShaders.Append( shader );
|
|
|
|
LoadVertexShader( index );
|
|
|
|
currentVertexShader = index;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2014-04-20 14:29:58 +00:00
|
|
|
// RB: removed idStr::Icmp( name, "heatHaze.vfp" ) == 0 hack
|
|
|
|
// this requires r_useUniformArrays 1
|
|
|
|
for( int i = 0; i < vertexShaders[index].uniforms.Num(); i++ )
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
2014-04-20 14:29:58 +00:00
|
|
|
if( vertexShaders[index].uniforms[i] == RENDERPARM_ENABLE_SKINNING )
|
|
|
|
{
|
|
|
|
vertexShaders[index].usesJoints = true;
|
|
|
|
vertexShaders[index].optionalSkinning = true;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2014-04-20 14:29:58 +00:00
|
|
|
// RB end
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::FindFragmentShader
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idRenderProgManager::FindFragmentShader( const char* name )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < fragmentShaders.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( fragmentShaders[i].name.Icmp( name ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
LoadFragmentShader( i );
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fragmentShader_t shader;
|
|
|
|
shader.name = name;
|
|
|
|
int index = fragmentShaders.Append( shader );
|
|
|
|
LoadFragmentShader( index );
|
|
|
|
currentFragmentShader = index;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::LoadVertexShader
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::LoadVertexShader( int index )
|
|
|
|
{
|
|
|
|
if( vertexShaders[index].progId != INVALID_PROGID )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return; // Already loaded
|
|
|
|
}
|
2014-05-10 12:40:01 +00:00
|
|
|
|
|
|
|
vertexShader_t& vs = vertexShaders[index];
|
|
|
|
vertexShaders[index].progId = ( GLuint ) LoadGLSLShader( GL_VERTEX_SHADER, vs.name, vs.nameOutSuffix, vs.shaderFeatures, vs.builtin, vs.uniforms );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::LoadFragmentShader
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::LoadFragmentShader( int index )
|
|
|
|
{
|
|
|
|
if( fragmentShaders[index].progId != INVALID_PROGID )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return; // Already loaded
|
|
|
|
}
|
2014-05-10 12:40:01 +00:00
|
|
|
|
|
|
|
fragmentShader_t& fs = fragmentShaders[index];
|
|
|
|
fragmentShaders[index].progId = ( GLuint ) LoadGLSLShader( GL_FRAGMENT_SHADER, fs.name, fs.nameOutSuffix, fs.shaderFeatures, fs.builtin, fs.uniforms );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::BindShader
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2014-04-20 14:29:58 +00:00
|
|
|
// RB begin
|
|
|
|
void idRenderProgManager::BindShader( int progIndex, int vIndex, int fIndex, bool builtin )
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
|
|
|
if( currentVertexShader == vIndex && currentFragmentShader == fIndex )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-04-20 14:29:58 +00:00
|
|
|
|
|
|
|
if( builtin )
|
|
|
|
{
|
|
|
|
currentVertexShader = vIndex;
|
|
|
|
currentFragmentShader = fIndex;
|
|
|
|
|
|
|
|
// vIndex denotes the GLSL program
|
|
|
|
if( vIndex >= 0 && vIndex < glslPrograms.Num() )
|
|
|
|
{
|
|
|
|
currentRenderProgram = vIndex;
|
|
|
|
RENDERLOG_PRINTF( "Binding GLSL Program %s\n", glslPrograms[vIndex].name.c_str() );
|
2014-04-25 18:23:34 +00:00
|
|
|
glUseProgram( glslPrograms[vIndex].progId );
|
2014-04-20 14:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
2014-04-20 14:29:58 +00:00
|
|
|
if( progIndex == -1 )
|
|
|
|
{
|
|
|
|
// RB: FIXME linear search
|
|
|
|
for( int i = 0; i < glslPrograms.Num(); ++i )
|
|
|
|
{
|
|
|
|
if( ( glslPrograms[i].vertexShaderIndex == vIndex ) && ( glslPrograms[i].fragmentShaderIndex == fIndex ) )
|
|
|
|
{
|
|
|
|
progIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentVertexShader = vIndex;
|
|
|
|
currentFragmentShader = fIndex;
|
|
|
|
|
|
|
|
if( progIndex >= 0 && progIndex < glslPrograms.Num() )
|
|
|
|
{
|
|
|
|
currentRenderProgram = progIndex;
|
|
|
|
RENDERLOG_PRINTF( "Binding GLSL Program %s\n", glslPrograms[progIndex].name.c_str() );
|
2014-04-25 18:23:34 +00:00
|
|
|
glUseProgram( glslPrograms[progIndex].progId );
|
2014-04-20 14:29:58 +00:00
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-20 14:29:58 +00:00
|
|
|
// RB end
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::Unbind
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::Unbind()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
currentVertexShader = -1;
|
|
|
|
currentFragmentShader = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-12-17 16:30:59 +00:00
|
|
|
glUseProgram( 0 );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2014-04-20 14:29:58 +00:00
|
|
|
// RB begin
|
|
|
|
bool idRenderProgManager::IsShaderBound() const
|
|
|
|
{
|
|
|
|
return ( currentVertexShader != -1 );
|
|
|
|
}
|
|
|
|
// RB end
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::SetRenderParms
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::SetRenderParms( renderParm_t rp, const float* value, int num )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < num; i++ )
|
|
|
|
{
|
|
|
|
SetRenderParm( ( renderParm_t )( rp + i ), value + ( i * 4 ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================================
|
|
|
|
idRenderProgManager::SetRenderParm
|
|
|
|
================================================================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idRenderProgManager::SetRenderParm( renderParm_t rp, const float* value )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SetUniformValue( rp, value );
|
|
|
|
}
|
|
|
|
|