mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 06:34:10 +00:00
Deleted almost all OpenGL code from _VK backend files
This commit is contained in:
parent
d115d84980
commit
3d9f9b75db
22 changed files with 884 additions and 5151 deletions
|
@ -672,7 +672,6 @@ void idCinematicLocal::FFMPEGReset()
|
|||
#ifdef USE_BINKDEC
|
||||
bool idCinematicLocal::InitFromBinkDecFile( const char* qpath, bool amilooping )
|
||||
{
|
||||
int ret;
|
||||
looping = amilooping;
|
||||
startTime = 0;
|
||||
isRoQ = false;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 2014-2016 Robert Beckebans
|
||||
Copyright (C) 2014-2018 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -36,489 +36,8 @@ idList<Framebuffer*> Framebuffer::framebuffers;
|
|||
|
||||
globalFramebuffers_t globalFramebuffers;
|
||||
|
||||
static void R_ListFramebuffers_f( const idCmdArgs& args )
|
||||
{
|
||||
if( !glConfig.framebufferObjectAvailable )
|
||||
{
|
||||
common->Printf( "GL_EXT_framebuffer_object is not available.\n" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Framebuffer::Framebuffer( const char* name, int w, int h )
|
||||
{
|
||||
fboName = name;
|
||||
|
||||
frameBuffer = 0;
|
||||
|
||||
memset( colorBuffers, 0, sizeof( colorBuffers ) );
|
||||
colorFormat = 0;
|
||||
|
||||
depthBuffer = 0;
|
||||
depthFormat = 0;
|
||||
|
||||
stencilBuffer = 0;
|
||||
stencilFormat = 0;
|
||||
|
||||
width = w;
|
||||
height = h;
|
||||
|
||||
msaaSamples = false;
|
||||
|
||||
glGenFramebuffers( 1, &frameBuffer );
|
||||
|
||||
framebuffers.Append( this );
|
||||
}
|
||||
|
||||
Framebuffer::~Framebuffer()
|
||||
{
|
||||
glDeleteFramebuffers( 1, &frameBuffer );
|
||||
}
|
||||
|
||||
void Framebuffer::Init()
|
||||
{
|
||||
cmdSystem->AddCommand( "listFramebuffers", R_ListFramebuffers_f, CMD_FL_RENDERER, "lists framebuffers" );
|
||||
|
||||
tr.backend.currentFramebuffer = NULL;
|
||||
|
||||
// SHADOWMAPS
|
||||
|
||||
int width, height;
|
||||
width = height = r_shadowMapImageSize.GetInteger();
|
||||
|
||||
for( int i = 0; i < MAX_SHADOWMAP_RESOLUTIONS; i++ )
|
||||
{
|
||||
width = height = shadowMapResolutions[i];
|
||||
|
||||
globalFramebuffers.shadowFBO[i] = new Framebuffer( va( "_shadowMap%i", i ) , width, height );
|
||||
globalFramebuffers.shadowFBO[i]->Bind();
|
||||
glDrawBuffers( 0, NULL );
|
||||
}
|
||||
|
||||
// HDR
|
||||
|
||||
int screenWidth = renderSystem->GetWidth();
|
||||
int screenHeight = renderSystem->GetHeight();
|
||||
|
||||
globalFramebuffers.hdrFBO = new Framebuffer( "_hdr", screenWidth, screenHeight );
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
|
||||
#if defined(USE_HDR_MSAA)
|
||||
if( glConfig.multisamples )
|
||||
{
|
||||
globalFramebuffers.hdrFBO->AddColorBuffer( GL_RGBA16F, 0, glConfig.multisamples );
|
||||
globalFramebuffers.hdrFBO->AddDepthBuffer( GL_DEPTH24_STENCIL8, glConfig.multisamples );
|
||||
|
||||
globalFramebuffers.hdrFBO->AttachImage2D( GL_TEXTURE_2D_MULTISAMPLE, globalImages->currentRenderHDRImage, 0 );
|
||||
globalFramebuffers.hdrFBO->AttachImageDepth( GL_TEXTURE_2D_MULTISAMPLE, globalImages->currentDepthImage );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
globalFramebuffers.hdrFBO->AddColorBuffer( GL_RGBA16F, 0 );
|
||||
globalFramebuffers.hdrFBO->AddDepthBuffer( GL_DEPTH24_STENCIL8 );
|
||||
|
||||
globalFramebuffers.hdrFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImage, 0 );
|
||||
globalFramebuffers.hdrFBO->AttachImageDepth( GL_TEXTURE_2D, globalImages->currentDepthImage );
|
||||
}
|
||||
|
||||
globalFramebuffers.hdrFBO->Check();
|
||||
|
||||
// HDR no MSAA
|
||||
#if defined(USE_HDR_MSAA)
|
||||
globalFramebuffers.hdrNonMSAAFBO = new Framebuffer( "_hdrNoMSAA", screenWidth, screenHeight );
|
||||
globalFramebuffers.hdrNonMSAAFBO->Bind();
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->AddColorBuffer( GL_RGBA16F, 0 );
|
||||
globalFramebuffers.hdrNonMSAAFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImageNoMSAA, 0 );
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->Check();
|
||||
#endif
|
||||
|
||||
// HDR DOWNSCALE
|
||||
|
||||
globalFramebuffers.hdr64FBO = new Framebuffer( "_hdr64", 64, 64 );
|
||||
globalFramebuffers.hdr64FBO->Bind();
|
||||
globalFramebuffers.hdr64FBO->AddColorBuffer( GL_RGBA16F, 0 );
|
||||
globalFramebuffers.hdr64FBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImage64, 0 );
|
||||
|
||||
globalFramebuffers.hdr64FBO->Check();
|
||||
|
||||
|
||||
// BLOOM
|
||||
|
||||
for( int i = 0; i < MAX_BLOOM_BUFFERS; i++ )
|
||||
{
|
||||
globalFramebuffers.bloomRenderFBO[i] = new Framebuffer( va( "_bloomRender%i", i ), screenWidth, screenHeight );
|
||||
globalFramebuffers.bloomRenderFBO[i]->Bind();
|
||||
globalFramebuffers.bloomRenderFBO[i]->AddColorBuffer( GL_RGBA8, 0 );
|
||||
globalFramebuffers.bloomRenderFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->bloomRenderImage[i], 0 );
|
||||
globalFramebuffers.bloomRenderFBO[i]->Check();
|
||||
}
|
||||
|
||||
// AMBIENT OCCLUSION
|
||||
|
||||
for( int i = 0; i < MAX_SSAO_BUFFERS; i++ )
|
||||
{
|
||||
globalFramebuffers.ambientOcclusionFBO[i] = new Framebuffer( va( "_aoRender%i", i ), screenWidth, screenHeight );
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->Bind();
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->AddColorBuffer( GL_RGBA8, 0 );
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->ambientOcclusionImage[i], 0 );
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->Check();
|
||||
}
|
||||
|
||||
// HIERARCHICAL Z BUFFER
|
||||
|
||||
for( int i = 0; i < MAX_HIERARCHICAL_ZBUFFERS; i++ )
|
||||
{
|
||||
globalFramebuffers.csDepthFBO[i] = new Framebuffer( va( "_csz%i", i ), screenWidth / ( 1 << i ), screenHeight / ( 1 << i ) );
|
||||
globalFramebuffers.csDepthFBO[i]->Bind();
|
||||
globalFramebuffers.csDepthFBO[i]->AddColorBuffer( GL_R32F, 0 );
|
||||
globalFramebuffers.csDepthFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->hierarchicalZbufferImage, 0, i );
|
||||
globalFramebuffers.csDepthFBO[i]->Check();
|
||||
}
|
||||
|
||||
// GEOMETRY BUFFER
|
||||
|
||||
//globalFramebuffers.geometryBufferFBO = new Framebuffer( "_gbuffer", screenWidth, screenHeight );
|
||||
//globalFramebuffers.geometryBufferFBO->Bind();
|
||||
//globalFramebuffers.geometryBufferFBO->AddColorBuffer( GL_RGBA8, 0 );
|
||||
//globalFramebuffers.geometryBufferFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentNormalsImage, 0 );
|
||||
//globalFramebuffers.geometryBufferFBO->Check();
|
||||
|
||||
// SMAA
|
||||
|
||||
globalFramebuffers.smaaEdgesFBO = new Framebuffer( "_smaaEdges", screenWidth, screenHeight );
|
||||
globalFramebuffers.smaaEdgesFBO->Bind();
|
||||
globalFramebuffers.smaaEdgesFBO->AddColorBuffer( GL_RGBA8, 0 );
|
||||
globalFramebuffers.smaaEdgesFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaEdgesImage, 0 );
|
||||
globalFramebuffers.smaaEdgesFBO->Check();
|
||||
|
||||
globalFramebuffers.smaaBlendFBO = new Framebuffer( "_smaaBlend", screenWidth, screenHeight );
|
||||
globalFramebuffers.smaaBlendFBO->Bind();
|
||||
globalFramebuffers.smaaBlendFBO->AddColorBuffer( GL_RGBA8, 0 );
|
||||
globalFramebuffers.smaaBlendFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaBlendImage, 0 );
|
||||
globalFramebuffers.smaaBlendFBO->Check();
|
||||
|
||||
Unbind();
|
||||
}
|
||||
|
||||
void Framebuffer::CheckFramebuffers()
|
||||
{
|
||||
int screenWidth = renderSystem->GetWidth();
|
||||
int screenHeight = renderSystem->GetHeight();
|
||||
|
||||
if( globalFramebuffers.hdrFBO->GetWidth() != screenWidth || globalFramebuffers.hdrFBO->GetHeight() != screenHeight )
|
||||
{
|
||||
Unbind();
|
||||
|
||||
// HDR
|
||||
globalImages->currentRenderHDRImage->Resize( screenWidth, screenHeight );
|
||||
globalImages->currentDepthImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
#if defined(USE_HDR_MSAA)
|
||||
if( glConfig.multisamples )
|
||||
{
|
||||
globalImages->currentRenderHDRImageNoMSAA->Resize( screenWidth, screenHeight );
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->Bind();
|
||||
globalFramebuffers.hdrNonMSAAFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImageNoMSAA, 0 );
|
||||
globalFramebuffers.hdrNonMSAAFBO->Check();
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->width = screenWidth;
|
||||
globalFramebuffers.hdrNonMSAAFBO->height = screenHeight;
|
||||
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
globalFramebuffers.hdrFBO->AttachImage2D( GL_TEXTURE_2D_MULTISAMPLE, globalImages->currentRenderHDRImage, 0 );
|
||||
globalFramebuffers.hdrFBO->AttachImageDepth( GL_TEXTURE_2D_MULTISAMPLE, globalImages->currentDepthImage );
|
||||
globalFramebuffers.hdrFBO->Check();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
globalFramebuffers.hdrFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImage, 0 );
|
||||
globalFramebuffers.hdrFBO->AttachImageDepth( GL_TEXTURE_2D, globalImages->currentDepthImage );
|
||||
globalFramebuffers.hdrFBO->Check();
|
||||
}
|
||||
|
||||
globalFramebuffers.hdrFBO->width = screenWidth;
|
||||
globalFramebuffers.hdrFBO->height = screenHeight;
|
||||
|
||||
// HDR quarter
|
||||
/*
|
||||
globalImages->currentRenderHDRImageQuarter->Resize( screenWidth / 4, screenHeight / 4 );
|
||||
|
||||
globalFramebuffers.hdrQuarterFBO->Bind();
|
||||
globalFramebuffers.hdrQuarterFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImageQuarter, 0 );
|
||||
globalFramebuffers.hdrQuarterFBO->Check();
|
||||
*/
|
||||
|
||||
// BLOOM
|
||||
|
||||
for( int i = 0; i < MAX_BLOOM_BUFFERS; i++ )
|
||||
{
|
||||
globalImages->bloomRenderImage[i]->Resize( screenWidth / 4, screenHeight / 4 );
|
||||
|
||||
globalFramebuffers.bloomRenderFBO[i]->width = screenWidth / 4;
|
||||
globalFramebuffers.bloomRenderFBO[i]->height = screenHeight / 4;
|
||||
|
||||
globalFramebuffers.bloomRenderFBO[i]->Bind();
|
||||
globalFramebuffers.bloomRenderFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->bloomRenderImage[i], 0 );
|
||||
globalFramebuffers.bloomRenderFBO[i]->Check();
|
||||
}
|
||||
|
||||
// AMBIENT OCCLUSION
|
||||
|
||||
for( int i = 0; i < MAX_SSAO_BUFFERS; i++ )
|
||||
{
|
||||
globalImages->ambientOcclusionImage[i]->Resize( screenWidth, screenHeight );
|
||||
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->width = screenWidth;
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->height = screenHeight;
|
||||
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->Bind();
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->ambientOcclusionImage[i], 0 );
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->Check();
|
||||
}
|
||||
|
||||
// HIERARCHICAL Z BUFFER
|
||||
|
||||
globalImages->hierarchicalZbufferImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
for( int i = 0; i < MAX_HIERARCHICAL_ZBUFFERS; i++ )
|
||||
{
|
||||
globalFramebuffers.csDepthFBO[i]->width = screenWidth / ( 1 << i );
|
||||
globalFramebuffers.csDepthFBO[i]->height = screenHeight / ( 1 << i );
|
||||
|
||||
globalFramebuffers.csDepthFBO[i]->Bind();
|
||||
globalFramebuffers.csDepthFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->hierarchicalZbufferImage, 0, i );
|
||||
globalFramebuffers.csDepthFBO[i]->Check();
|
||||
}
|
||||
|
||||
// GEOMETRY BUFFER
|
||||
|
||||
//globalImages->currentNormalsImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
//globalFramebuffers.geometryBufferFBO->width = screenWidth;
|
||||
//globalFramebuffers.geometryBufferFBO->height = screenHeight;
|
||||
|
||||
//globalFramebuffers.geometryBufferFBO->Bind();
|
||||
//globalFramebuffers.geometryBufferFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentNormalsImage, 0 );
|
||||
//globalFramebuffers.geometryBufferFBO->Check();
|
||||
|
||||
// SMAA
|
||||
|
||||
globalImages->smaaEdgesImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
globalFramebuffers.smaaEdgesFBO->width = screenWidth;
|
||||
globalFramebuffers.smaaEdgesFBO->height = screenHeight;
|
||||
|
||||
globalFramebuffers.smaaEdgesFBO->Bind();
|
||||
globalFramebuffers.smaaEdgesFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaEdgesImage, 0 );
|
||||
globalFramebuffers.smaaEdgesFBO->Check();
|
||||
|
||||
globalImages->smaaBlendImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
globalFramebuffers.smaaBlendFBO->width = screenWidth;
|
||||
globalFramebuffers.smaaBlendFBO->height = screenHeight;
|
||||
|
||||
globalFramebuffers.smaaBlendFBO->Bind();
|
||||
globalFramebuffers.smaaBlendFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaBlendImage, 0 );
|
||||
globalFramebuffers.smaaBlendFBO->Check();
|
||||
|
||||
Unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void Framebuffer::Shutdown()
|
||||
{
|
||||
framebuffers.DeleteContents( true );
|
||||
}
|
||||
|
||||
void Framebuffer::Bind()
|
||||
{
|
||||
RENDERLOG_PRINTF( "Framebuffer::Bind( %s )\n", fboName.c_str() );
|
||||
|
||||
if( tr.backend.currentFramebuffer != this )
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, frameBuffer );
|
||||
tr.backend.currentFramebuffer = this;
|
||||
}
|
||||
}
|
||||
|
||||
bool Framebuffer::IsBound()
|
||||
{
|
||||
return ( tr.backend.currentFramebuffer == this );
|
||||
}
|
||||
|
||||
void Framebuffer::Unbind()
|
||||
{
|
||||
RENDERLOG_PRINTF( "Framebuffer::Unbind()\n" );
|
||||
|
||||
//if(tr.backend.framebuffer != NULL)
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
glBindRenderbuffer( GL_RENDERBUFFER, 0 );
|
||||
tr.backend.currentFramebuffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool Framebuffer::IsDefaultFramebufferActive()
|
||||
{
|
||||
return ( tr.backend.currentFramebuffer == NULL );
|
||||
}
|
||||
|
||||
void Framebuffer::AddColorBuffer( int format, int index, int multiSamples )
|
||||
{
|
||||
if( index < 0 || index >= glConfig.maxColorAttachments )
|
||||
{
|
||||
common->Warning( "Framebuffer::AddColorBuffer( %s ): bad index = %i", fboName.c_str(), index );
|
||||
return;
|
||||
}
|
||||
|
||||
colorFormat = format;
|
||||
|
||||
bool notCreatedYet = colorBuffers[index] == 0;
|
||||
if( notCreatedYet )
|
||||
{
|
||||
glGenRenderbuffers( 1, &colorBuffers[index] );
|
||||
}
|
||||
|
||||
glBindRenderbuffer( GL_RENDERBUFFER, colorBuffers[index] );
|
||||
|
||||
if( multiSamples > 0 )
|
||||
{
|
||||
glRenderbufferStorageMultisample( GL_RENDERBUFFER, multiSamples, format, width, height );
|
||||
|
||||
msaaSamples = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
glRenderbufferStorage( GL_RENDERBUFFER, format, width, height );
|
||||
}
|
||||
|
||||
if( notCreatedYet )
|
||||
{
|
||||
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_RENDERBUFFER, colorBuffers[index] );
|
||||
}
|
||||
|
||||
GL_CheckErrors();
|
||||
}
|
||||
|
||||
void Framebuffer::AddDepthBuffer( int format, int multiSamples )
|
||||
{
|
||||
depthFormat = format;
|
||||
|
||||
bool notCreatedYet = depthBuffer == 0;
|
||||
if( notCreatedYet )
|
||||
{
|
||||
glGenRenderbuffers( 1, &depthBuffer );
|
||||
}
|
||||
|
||||
glBindRenderbuffer( GL_RENDERBUFFER, depthBuffer );
|
||||
|
||||
if( multiSamples > 0 )
|
||||
{
|
||||
glRenderbufferStorageMultisample( GL_RENDERBUFFER, multiSamples, format, width, height );
|
||||
|
||||
msaaSamples = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
glRenderbufferStorage( GL_RENDERBUFFER, format, width, height );
|
||||
}
|
||||
|
||||
if( notCreatedYet )
|
||||
{
|
||||
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer );
|
||||
}
|
||||
|
||||
GL_CheckErrors();
|
||||
}
|
||||
|
||||
void Framebuffer::AttachImage2D( int target, const idImage* image, int index, int mipmapLod )
|
||||
{
|
||||
if( ( target != GL_TEXTURE_2D ) && ( target != GL_TEXTURE_2D_MULTISAMPLE ) && ( target < GL_TEXTURE_CUBE_MAP_POSITIVE_X || target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z ) )
|
||||
{
|
||||
common->Warning( "Framebuffer::AttachImage2D( %s ): invalid target", fboName.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
if( index < 0 || index >= glConfig.maxColorAttachments )
|
||||
{
|
||||
common->Warning( "Framebuffer::AttachImage2D( %s ): bad index = %i", fboName.c_str(), index );
|
||||
return;
|
||||
}
|
||||
|
||||
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, target, image->texnum, mipmapLod );
|
||||
}
|
||||
|
||||
void Framebuffer::AttachImageDepth( int target, const idImage* image )
|
||||
{
|
||||
if( ( target != GL_TEXTURE_2D ) && ( target != GL_TEXTURE_2D_MULTISAMPLE ) )
|
||||
{
|
||||
common->Warning( "Framebuffer::AttachImageDepth( %s ): invalid target", fboName.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target, image->texnum, 0 );
|
||||
}
|
||||
|
||||
void Framebuffer::AttachImageDepthLayer( const idImage* image, int layer )
|
||||
{
|
||||
glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, image->texnum, 0, layer );
|
||||
}
|
||||
|
||||
void Framebuffer::Check()
|
||||
{
|
||||
int prev;
|
||||
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prev );
|
||||
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, frameBuffer );
|
||||
|
||||
int status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
|
||||
if( status == GL_FRAMEBUFFER_COMPLETE )
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, prev );
|
||||
return;
|
||||
}
|
||||
|
||||
// something went wrong
|
||||
switch( status )
|
||||
{
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, incomplete attachment", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing attachment", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing draw buffer", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing read buffer", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing layer targets", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing multisample", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
common->Error( "Framebuffer::Check( %s ): Unsupported framebuffer format", fboName.c_str() );
|
||||
break;
|
||||
|
||||
default:
|
||||
common->Error( "Framebuffer::Check( %s ): Unknown error 0x%X", fboName.c_str(), status );
|
||||
break;
|
||||
};
|
||||
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, prev );
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ static int shadowMapResolutions[MAX_SHADOWMAP_RESOLUTIONS] = { 2048, 1024, 512,
|
|||
static int shadowMapResolutions[MAX_SHADOWMAP_RESOLUTIONS] = { 1024, 1024, 1024, 1024, 1024 };
|
||||
#endif
|
||||
|
||||
|
||||
class Framebuffer
|
||||
{
|
||||
public:
|
||||
|
@ -137,5 +138,4 @@ struct globalFramebuffers_t
|
|||
};
|
||||
extern globalFramebuffers_t globalFramebuffers;
|
||||
|
||||
|
||||
#endif // __FRAMEBUFFER_H__
|
|
@ -363,9 +363,7 @@ public:
|
|||
return ( opts.format == FMT_DXT1 || opts.format == FMT_DXT5 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool IsLoaded() const;
|
||||
|
||||
static void GetGeneratedName( idStr& _name, const textureUsage_t& _usage, const cubeFiles_t& _cube );
|
||||
|
||||
|
@ -421,7 +419,7 @@ private:
|
|||
VkImageLayout layout;
|
||||
VkSampler sampler;
|
||||
|
||||
#if defined( ID_USE_AMD_ALLOCATOR )
|
||||
#if defined( USE_AMD_ALLOCATOR )
|
||||
VmaAllocation allocation;
|
||||
static idList< VmaAllocation > allocationGarbage[ NUM_FRAME_DATA ];
|
||||
#else
|
||||
|
@ -440,12 +438,6 @@ private:
|
|||
GLuint internalFormat;
|
||||
GLuint dataFormat;
|
||||
GLuint dataType;
|
||||
|
||||
public:
|
||||
bool IsLoaded() const
|
||||
{
|
||||
return texnum != TEXTURE_NOT_LOADED;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -690,7 +690,6 @@ Init
|
|||
*/
|
||||
void idImageManager::Init()
|
||||
{
|
||||
|
||||
images.Resize( 1024, 1024 );
|
||||
imageHash.ResizeIndex( 1024 );
|
||||
|
||||
|
|
|
@ -668,23 +668,6 @@ void idImage::Reload( bool force )
|
|||
ActuallyLoadImage( false );
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idImage::SetSamplerState
|
||||
========================
|
||||
*/
|
||||
void idImage::SetSamplerState( textureFilter_t tf, textureRepeat_t tr )
|
||||
{
|
||||
if( tf == filter && tr == repeat )
|
||||
{
|
||||
return;
|
||||
}
|
||||
filter = tf;
|
||||
repeat = tr;
|
||||
glBindTexture( ( opts.textureType == TT_CUBIC ) ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, texnum );
|
||||
SetTexParameters();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
GenerateImage
|
||||
|
|
524
neo/renderer/OpenGL/Framebuffer_GL.cpp
Normal file
524
neo/renderer/OpenGL/Framebuffer_GL.cpp
Normal file
|
@ -0,0 +1,524 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 2014-2018 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#pragma hdrstop
|
||||
|
||||
#include "../RenderCommon.h"
|
||||
#include "../Framebuffer.h"
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
|
||||
static void R_ListFramebuffers_f( const idCmdArgs& args )
|
||||
{
|
||||
if( !glConfig.framebufferObjectAvailable )
|
||||
{
|
||||
common->Printf( "GL_EXT_framebuffer_object is not available.\n" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Framebuffer::Framebuffer( const char* name, int w, int h )
|
||||
{
|
||||
fboName = name;
|
||||
|
||||
frameBuffer = 0;
|
||||
|
||||
memset( colorBuffers, 0, sizeof( colorBuffers ) );
|
||||
colorFormat = 0;
|
||||
|
||||
depthBuffer = 0;
|
||||
depthFormat = 0;
|
||||
|
||||
stencilBuffer = 0;
|
||||
stencilFormat = 0;
|
||||
|
||||
width = w;
|
||||
height = h;
|
||||
|
||||
msaaSamples = false;
|
||||
|
||||
glGenFramebuffers( 1, &frameBuffer );
|
||||
|
||||
framebuffers.Append( this );
|
||||
}
|
||||
|
||||
Framebuffer::~Framebuffer()
|
||||
{
|
||||
glDeleteFramebuffers( 1, &frameBuffer );
|
||||
}
|
||||
|
||||
void Framebuffer::Init()
|
||||
{
|
||||
cmdSystem->AddCommand( "listFramebuffers", R_ListFramebuffers_f, CMD_FL_RENDERER, "lists framebuffers" );
|
||||
|
||||
tr.backend.currentFramebuffer = NULL;
|
||||
|
||||
// SHADOWMAPS
|
||||
|
||||
int width, height;
|
||||
width = height = r_shadowMapImageSize.GetInteger();
|
||||
|
||||
for( int i = 0; i < MAX_SHADOWMAP_RESOLUTIONS; i++ )
|
||||
{
|
||||
width = height = shadowMapResolutions[i];
|
||||
|
||||
globalFramebuffers.shadowFBO[i] = new Framebuffer( va( "_shadowMap%i", i ) , width, height );
|
||||
globalFramebuffers.shadowFBO[i]->Bind();
|
||||
glDrawBuffers( 0, NULL );
|
||||
}
|
||||
|
||||
// HDR
|
||||
|
||||
int screenWidth = renderSystem->GetWidth();
|
||||
int screenHeight = renderSystem->GetHeight();
|
||||
|
||||
globalFramebuffers.hdrFBO = new Framebuffer( "_hdr", screenWidth, screenHeight );
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
|
||||
#if defined(USE_HDR_MSAA)
|
||||
if( glConfig.multisamples )
|
||||
{
|
||||
globalFramebuffers.hdrFBO->AddColorBuffer( GL_RGBA16F, 0, glConfig.multisamples );
|
||||
globalFramebuffers.hdrFBO->AddDepthBuffer( GL_DEPTH24_STENCIL8, glConfig.multisamples );
|
||||
|
||||
globalFramebuffers.hdrFBO->AttachImage2D( GL_TEXTURE_2D_MULTISAMPLE, globalImages->currentRenderHDRImage, 0 );
|
||||
globalFramebuffers.hdrFBO->AttachImageDepth( GL_TEXTURE_2D_MULTISAMPLE, globalImages->currentDepthImage );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
globalFramebuffers.hdrFBO->AddColorBuffer( GL_RGBA16F, 0 );
|
||||
globalFramebuffers.hdrFBO->AddDepthBuffer( GL_DEPTH24_STENCIL8 );
|
||||
|
||||
globalFramebuffers.hdrFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImage, 0 );
|
||||
globalFramebuffers.hdrFBO->AttachImageDepth( GL_TEXTURE_2D, globalImages->currentDepthImage );
|
||||
}
|
||||
|
||||
globalFramebuffers.hdrFBO->Check();
|
||||
|
||||
// HDR no MSAA
|
||||
#if defined(USE_HDR_MSAA)
|
||||
globalFramebuffers.hdrNonMSAAFBO = new Framebuffer( "_hdrNoMSAA", screenWidth, screenHeight );
|
||||
globalFramebuffers.hdrNonMSAAFBO->Bind();
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->AddColorBuffer( GL_RGBA16F, 0 );
|
||||
globalFramebuffers.hdrNonMSAAFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImageNoMSAA, 0 );
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->Check();
|
||||
#endif
|
||||
|
||||
// HDR DOWNSCALE
|
||||
|
||||
globalFramebuffers.hdr64FBO = new Framebuffer( "_hdr64", 64, 64 );
|
||||
globalFramebuffers.hdr64FBO->Bind();
|
||||
globalFramebuffers.hdr64FBO->AddColorBuffer( GL_RGBA16F, 0 );
|
||||
globalFramebuffers.hdr64FBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImage64, 0 );
|
||||
|
||||
globalFramebuffers.hdr64FBO->Check();
|
||||
|
||||
|
||||
// BLOOM
|
||||
|
||||
for( int i = 0; i < MAX_BLOOM_BUFFERS; i++ )
|
||||
{
|
||||
globalFramebuffers.bloomRenderFBO[i] = new Framebuffer( va( "_bloomRender%i", i ), screenWidth, screenHeight );
|
||||
globalFramebuffers.bloomRenderFBO[i]->Bind();
|
||||
globalFramebuffers.bloomRenderFBO[i]->AddColorBuffer( GL_RGBA8, 0 );
|
||||
globalFramebuffers.bloomRenderFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->bloomRenderImage[i], 0 );
|
||||
globalFramebuffers.bloomRenderFBO[i]->Check();
|
||||
}
|
||||
|
||||
// AMBIENT OCCLUSION
|
||||
|
||||
for( int i = 0; i < MAX_SSAO_BUFFERS; i++ )
|
||||
{
|
||||
globalFramebuffers.ambientOcclusionFBO[i] = new Framebuffer( va( "_aoRender%i", i ), screenWidth, screenHeight );
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->Bind();
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->AddColorBuffer( GL_RGBA8, 0 );
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->ambientOcclusionImage[i], 0 );
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->Check();
|
||||
}
|
||||
|
||||
// HIERARCHICAL Z BUFFER
|
||||
|
||||
for( int i = 0; i < MAX_HIERARCHICAL_ZBUFFERS; i++ )
|
||||
{
|
||||
globalFramebuffers.csDepthFBO[i] = new Framebuffer( va( "_csz%i", i ), screenWidth / ( 1 << i ), screenHeight / ( 1 << i ) );
|
||||
globalFramebuffers.csDepthFBO[i]->Bind();
|
||||
globalFramebuffers.csDepthFBO[i]->AddColorBuffer( GL_R32F, 0 );
|
||||
globalFramebuffers.csDepthFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->hierarchicalZbufferImage, 0, i );
|
||||
globalFramebuffers.csDepthFBO[i]->Check();
|
||||
}
|
||||
|
||||
// GEOMETRY BUFFER
|
||||
|
||||
//globalFramebuffers.geometryBufferFBO = new Framebuffer( "_gbuffer", screenWidth, screenHeight );
|
||||
//globalFramebuffers.geometryBufferFBO->Bind();
|
||||
//globalFramebuffers.geometryBufferFBO->AddColorBuffer( GL_RGBA8, 0 );
|
||||
//globalFramebuffers.geometryBufferFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentNormalsImage, 0 );
|
||||
//globalFramebuffers.geometryBufferFBO->Check();
|
||||
|
||||
// SMAA
|
||||
|
||||
globalFramebuffers.smaaEdgesFBO = new Framebuffer( "_smaaEdges", screenWidth, screenHeight );
|
||||
globalFramebuffers.smaaEdgesFBO->Bind();
|
||||
globalFramebuffers.smaaEdgesFBO->AddColorBuffer( GL_RGBA8, 0 );
|
||||
globalFramebuffers.smaaEdgesFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaEdgesImage, 0 );
|
||||
globalFramebuffers.smaaEdgesFBO->Check();
|
||||
|
||||
globalFramebuffers.smaaBlendFBO = new Framebuffer( "_smaaBlend", screenWidth, screenHeight );
|
||||
globalFramebuffers.smaaBlendFBO->Bind();
|
||||
globalFramebuffers.smaaBlendFBO->AddColorBuffer( GL_RGBA8, 0 );
|
||||
globalFramebuffers.smaaBlendFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaBlendImage, 0 );
|
||||
globalFramebuffers.smaaBlendFBO->Check();
|
||||
|
||||
Unbind();
|
||||
}
|
||||
|
||||
void Framebuffer::CheckFramebuffers()
|
||||
{
|
||||
int screenWidth = renderSystem->GetWidth();
|
||||
int screenHeight = renderSystem->GetHeight();
|
||||
|
||||
if( globalFramebuffers.hdrFBO->GetWidth() != screenWidth || globalFramebuffers.hdrFBO->GetHeight() != screenHeight )
|
||||
{
|
||||
Unbind();
|
||||
|
||||
// HDR
|
||||
globalImages->currentRenderHDRImage->Resize( screenWidth, screenHeight );
|
||||
globalImages->currentDepthImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
#if defined(USE_HDR_MSAA)
|
||||
if( glConfig.multisamples )
|
||||
{
|
||||
globalImages->currentRenderHDRImageNoMSAA->Resize( screenWidth, screenHeight );
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->Bind();
|
||||
globalFramebuffers.hdrNonMSAAFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImageNoMSAA, 0 );
|
||||
globalFramebuffers.hdrNonMSAAFBO->Check();
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->width = screenWidth;
|
||||
globalFramebuffers.hdrNonMSAAFBO->height = screenHeight;
|
||||
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
globalFramebuffers.hdrFBO->AttachImage2D( GL_TEXTURE_2D_MULTISAMPLE, globalImages->currentRenderHDRImage, 0 );
|
||||
globalFramebuffers.hdrFBO->AttachImageDepth( GL_TEXTURE_2D_MULTISAMPLE, globalImages->currentDepthImage );
|
||||
globalFramebuffers.hdrFBO->Check();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
globalFramebuffers.hdrFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImage, 0 );
|
||||
globalFramebuffers.hdrFBO->AttachImageDepth( GL_TEXTURE_2D, globalImages->currentDepthImage );
|
||||
globalFramebuffers.hdrFBO->Check();
|
||||
}
|
||||
|
||||
globalFramebuffers.hdrFBO->width = screenWidth;
|
||||
globalFramebuffers.hdrFBO->height = screenHeight;
|
||||
|
||||
// HDR quarter
|
||||
/*
|
||||
globalImages->currentRenderHDRImageQuarter->Resize( screenWidth / 4, screenHeight / 4 );
|
||||
|
||||
globalFramebuffers.hdrQuarterFBO->Bind();
|
||||
globalFramebuffers.hdrQuarterFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentRenderHDRImageQuarter, 0 );
|
||||
globalFramebuffers.hdrQuarterFBO->Check();
|
||||
*/
|
||||
|
||||
// BLOOM
|
||||
|
||||
for( int i = 0; i < MAX_BLOOM_BUFFERS; i++ )
|
||||
{
|
||||
globalImages->bloomRenderImage[i]->Resize( screenWidth / 4, screenHeight / 4 );
|
||||
|
||||
globalFramebuffers.bloomRenderFBO[i]->width = screenWidth / 4;
|
||||
globalFramebuffers.bloomRenderFBO[i]->height = screenHeight / 4;
|
||||
|
||||
globalFramebuffers.bloomRenderFBO[i]->Bind();
|
||||
globalFramebuffers.bloomRenderFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->bloomRenderImage[i], 0 );
|
||||
globalFramebuffers.bloomRenderFBO[i]->Check();
|
||||
}
|
||||
|
||||
// AMBIENT OCCLUSION
|
||||
|
||||
for( int i = 0; i < MAX_SSAO_BUFFERS; i++ )
|
||||
{
|
||||
globalImages->ambientOcclusionImage[i]->Resize( screenWidth, screenHeight );
|
||||
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->width = screenWidth;
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->height = screenHeight;
|
||||
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->Bind();
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->ambientOcclusionImage[i], 0 );
|
||||
globalFramebuffers.ambientOcclusionFBO[i]->Check();
|
||||
}
|
||||
|
||||
// HIERARCHICAL Z BUFFER
|
||||
|
||||
globalImages->hierarchicalZbufferImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
for( int i = 0; i < MAX_HIERARCHICAL_ZBUFFERS; i++ )
|
||||
{
|
||||
globalFramebuffers.csDepthFBO[i]->width = screenWidth / ( 1 << i );
|
||||
globalFramebuffers.csDepthFBO[i]->height = screenHeight / ( 1 << i );
|
||||
|
||||
globalFramebuffers.csDepthFBO[i]->Bind();
|
||||
globalFramebuffers.csDepthFBO[i]->AttachImage2D( GL_TEXTURE_2D, globalImages->hierarchicalZbufferImage, 0, i );
|
||||
globalFramebuffers.csDepthFBO[i]->Check();
|
||||
}
|
||||
|
||||
// GEOMETRY BUFFER
|
||||
|
||||
//globalImages->currentNormalsImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
//globalFramebuffers.geometryBufferFBO->width = screenWidth;
|
||||
//globalFramebuffers.geometryBufferFBO->height = screenHeight;
|
||||
|
||||
//globalFramebuffers.geometryBufferFBO->Bind();
|
||||
//globalFramebuffers.geometryBufferFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->currentNormalsImage, 0 );
|
||||
//globalFramebuffers.geometryBufferFBO->Check();
|
||||
|
||||
// SMAA
|
||||
|
||||
globalImages->smaaEdgesImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
globalFramebuffers.smaaEdgesFBO->width = screenWidth;
|
||||
globalFramebuffers.smaaEdgesFBO->height = screenHeight;
|
||||
|
||||
globalFramebuffers.smaaEdgesFBO->Bind();
|
||||
globalFramebuffers.smaaEdgesFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaEdgesImage, 0 );
|
||||
globalFramebuffers.smaaEdgesFBO->Check();
|
||||
|
||||
globalImages->smaaBlendImage->Resize( screenWidth, screenHeight );
|
||||
|
||||
globalFramebuffers.smaaBlendFBO->width = screenWidth;
|
||||
globalFramebuffers.smaaBlendFBO->height = screenHeight;
|
||||
|
||||
globalFramebuffers.smaaBlendFBO->Bind();
|
||||
globalFramebuffers.smaaBlendFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaBlendImage, 0 );
|
||||
globalFramebuffers.smaaBlendFBO->Check();
|
||||
|
||||
Unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void Framebuffer::Shutdown()
|
||||
{
|
||||
framebuffers.DeleteContents( true );
|
||||
}
|
||||
|
||||
void Framebuffer::Bind()
|
||||
{
|
||||
RENDERLOG_PRINTF( "Framebuffer::Bind( %s )\n", fboName.c_str() );
|
||||
|
||||
if( tr.backend.currentFramebuffer != this )
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, frameBuffer );
|
||||
tr.backend.currentFramebuffer = this;
|
||||
}
|
||||
}
|
||||
|
||||
bool Framebuffer::IsBound()
|
||||
{
|
||||
return ( tr.backend.currentFramebuffer == this );
|
||||
}
|
||||
|
||||
void Framebuffer::Unbind()
|
||||
{
|
||||
RENDERLOG_PRINTF( "Framebuffer::Unbind()\n" );
|
||||
|
||||
//if(tr.backend.framebuffer != NULL)
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
glBindRenderbuffer( GL_RENDERBUFFER, 0 );
|
||||
tr.backend.currentFramebuffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool Framebuffer::IsDefaultFramebufferActive()
|
||||
{
|
||||
return ( tr.backend.currentFramebuffer == NULL );
|
||||
}
|
||||
|
||||
void Framebuffer::AddColorBuffer( int format, int index, int multiSamples )
|
||||
{
|
||||
if( index < 0 || index >= glConfig.maxColorAttachments )
|
||||
{
|
||||
common->Warning( "Framebuffer::AddColorBuffer( %s ): bad index = %i", fboName.c_str(), index );
|
||||
return;
|
||||
}
|
||||
|
||||
colorFormat = format;
|
||||
|
||||
bool notCreatedYet = colorBuffers[index] == 0;
|
||||
if( notCreatedYet )
|
||||
{
|
||||
glGenRenderbuffers( 1, &colorBuffers[index] );
|
||||
}
|
||||
|
||||
glBindRenderbuffer( GL_RENDERBUFFER, colorBuffers[index] );
|
||||
|
||||
if( multiSamples > 0 )
|
||||
{
|
||||
glRenderbufferStorageMultisample( GL_RENDERBUFFER, multiSamples, format, width, height );
|
||||
|
||||
msaaSamples = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
glRenderbufferStorage( GL_RENDERBUFFER, format, width, height );
|
||||
}
|
||||
|
||||
if( notCreatedYet )
|
||||
{
|
||||
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_RENDERBUFFER, colorBuffers[index] );
|
||||
}
|
||||
|
||||
GL_CheckErrors();
|
||||
}
|
||||
|
||||
void Framebuffer::AddDepthBuffer( int format, int multiSamples )
|
||||
{
|
||||
depthFormat = format;
|
||||
|
||||
bool notCreatedYet = depthBuffer == 0;
|
||||
if( notCreatedYet )
|
||||
{
|
||||
glGenRenderbuffers( 1, &depthBuffer );
|
||||
}
|
||||
|
||||
glBindRenderbuffer( GL_RENDERBUFFER, depthBuffer );
|
||||
|
||||
if( multiSamples > 0 )
|
||||
{
|
||||
glRenderbufferStorageMultisample( GL_RENDERBUFFER, multiSamples, format, width, height );
|
||||
|
||||
msaaSamples = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
glRenderbufferStorage( GL_RENDERBUFFER, format, width, height );
|
||||
}
|
||||
|
||||
if( notCreatedYet )
|
||||
{
|
||||
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer );
|
||||
}
|
||||
|
||||
GL_CheckErrors();
|
||||
}
|
||||
|
||||
void Framebuffer::AttachImage2D( int target, const idImage* image, int index, int mipmapLod )
|
||||
{
|
||||
if( ( target != GL_TEXTURE_2D ) && ( target != GL_TEXTURE_2D_MULTISAMPLE ) && ( target < GL_TEXTURE_CUBE_MAP_POSITIVE_X || target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z ) )
|
||||
{
|
||||
common->Warning( "Framebuffer::AttachImage2D( %s ): invalid target", fboName.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
if( index < 0 || index >= glConfig.maxColorAttachments )
|
||||
{
|
||||
common->Warning( "Framebuffer::AttachImage2D( %s ): bad index = %i", fboName.c_str(), index );
|
||||
return;
|
||||
}
|
||||
|
||||
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, target, image->texnum, mipmapLod );
|
||||
}
|
||||
|
||||
void Framebuffer::AttachImageDepth( int target, const idImage* image )
|
||||
{
|
||||
if( ( target != GL_TEXTURE_2D ) && ( target != GL_TEXTURE_2D_MULTISAMPLE ) )
|
||||
{
|
||||
common->Warning( "Framebuffer::AttachImageDepth( %s ): invalid target", fboName.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target, image->texnum, 0 );
|
||||
}
|
||||
|
||||
void Framebuffer::AttachImageDepthLayer( const idImage* image, int layer )
|
||||
{
|
||||
glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, image->texnum, 0, layer );
|
||||
}
|
||||
|
||||
void Framebuffer::Check()
|
||||
{
|
||||
int prev;
|
||||
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prev );
|
||||
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, frameBuffer );
|
||||
|
||||
int status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
|
||||
if( status == GL_FRAMEBUFFER_COMPLETE )
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, prev );
|
||||
return;
|
||||
}
|
||||
|
||||
// something went wrong
|
||||
switch( status )
|
||||
{
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, incomplete attachment", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing attachment", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing draw buffer", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing read buffer", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing layer targets", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
|
||||
common->Error( "Framebuffer::Check( %s ): Framebuffer incomplete, missing multisample", fboName.c_str() );
|
||||
break;
|
||||
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
common->Error( "Framebuffer::Check( %s ): Unsupported framebuffer format", fboName.c_str() );
|
||||
break;
|
||||
|
||||
default:
|
||||
common->Error( "Framebuffer::Check( %s ): Unknown error 0x%X", fboName.c_str(), status );
|
||||
break;
|
||||
};
|
||||
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, prev );
|
||||
}
|
||||
|
||||
#endif // #if !defined(USE_VULKAN)
|
|
@ -72,6 +72,16 @@ idImage::~idImage()
|
|||
PurgeImage();
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
idImage::IsLoaded
|
||||
====================
|
||||
*/
|
||||
bool idImage::IsLoaded() const
|
||||
{
|
||||
return texnum != TEXTURE_NOT_LOADED;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
Bind
|
||||
|
@ -388,6 +398,23 @@ void idImage::SubImageUpload( int mipLevel, int x, int y, int z, int width, int
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idImage::SetSamplerState
|
||||
========================
|
||||
*/
|
||||
void idImage::SetSamplerState( textureFilter_t tf, textureRepeat_t tr )
|
||||
{
|
||||
if( tf == filter && tr == repeat )
|
||||
{
|
||||
return;
|
||||
}
|
||||
filter = tf;
|
||||
repeat = tr;
|
||||
glBindTexture( ( opts.textureType == TT_CUBIC ) ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, texnum );
|
||||
SetTexParameters();
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idImage::SetPixel
|
||||
|
|
|
@ -1062,6 +1062,190 @@ void idRenderBackend::CheckCVars()
|
|||
// RB end
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============================================================================================
|
||||
|
||||
STENCIL SHADOW RENDERING
|
||||
|
||||
==============================================================================================
|
||||
*/
|
||||
extern idCVar r_useStencilShadowPreload;
|
||||
|
||||
/*
|
||||
==================
|
||||
idRenderBackend::DrawStencilShadowPass
|
||||
==================
|
||||
*/
|
||||
void idRenderBackend::DrawStencilShadowPass( const drawSurf_t* drawSurf, const bool renderZPass )
|
||||
{
|
||||
// get vertex buffer
|
||||
const vertCacheHandle_t vbHandle = drawSurf->shadowCache;
|
||||
idVertexBuffer* vertexBuffer;
|
||||
if( vertexCache.CacheIsStatic( vbHandle ) )
|
||||
{
|
||||
vertexBuffer = &vertexCache.staticData.vertexBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint64 frameNum = ( int )( vbHandle >> VERTCACHE_FRAME_SHIFT ) & VERTCACHE_FRAME_MASK;
|
||||
if( frameNum != ( ( vertexCache.currentFrame - 1 ) & VERTCACHE_FRAME_MASK ) )
|
||||
{
|
||||
idLib::Warning( "DrawStencilShadowPass, vertexBuffer == NULL" );
|
||||
return;
|
||||
}
|
||||
vertexBuffer = &vertexCache.frameData[vertexCache.drawListNum].vertexBuffer;
|
||||
}
|
||||
const int vertOffset = ( int )( vbHandle >> VERTCACHE_OFFSET_SHIFT ) & VERTCACHE_OFFSET_MASK;
|
||||
|
||||
// get index buffer
|
||||
const vertCacheHandle_t ibHandle = drawSurf->indexCache;
|
||||
idIndexBuffer* indexBuffer;
|
||||
if( vertexCache.CacheIsStatic( ibHandle ) )
|
||||
{
|
||||
indexBuffer = &vertexCache.staticData.indexBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint64 frameNum = ( int )( ibHandle >> VERTCACHE_FRAME_SHIFT ) & VERTCACHE_FRAME_MASK;
|
||||
if( frameNum != ( ( vertexCache.currentFrame - 1 ) & VERTCACHE_FRAME_MASK ) )
|
||||
{
|
||||
idLib::Warning( "DrawStencilShadowPass, indexBuffer == NULL" );
|
||||
return;
|
||||
}
|
||||
indexBuffer = &vertexCache.frameData[vertexCache.drawListNum].indexBuffer;
|
||||
}
|
||||
const uint64 indexOffset = ( int )( ibHandle >> VERTCACHE_OFFSET_SHIFT ) & VERTCACHE_OFFSET_MASK;
|
||||
|
||||
RENDERLOG_PRINTF( "Binding Buffers: %p %p\n", vertexBuffer, indexBuffer );
|
||||
|
||||
// RB: 64 bit fixes, changed GLuint to GLintptr
|
||||
if( currentIndexBuffer != ( GLintptr )indexBuffer->GetAPIObject() || !r_useStateCaching.GetBool() )
|
||||
{
|
||||
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ( GLintptr )indexBuffer->GetAPIObject() );
|
||||
currentIndexBuffer = ( GLintptr )indexBuffer->GetAPIObject();
|
||||
}
|
||||
|
||||
if( drawSurf->jointCache )
|
||||
{
|
||||
assert( renderProgManager.ShaderUsesJoints() );
|
||||
|
||||
idUniformBuffer jointBuffer;
|
||||
if( !vertexCache.GetJointBuffer( drawSurf->jointCache, &jointBuffer ) )
|
||||
{
|
||||
idLib::Warning( "DrawStencilShadowPass, jointBuffer == NULL" );
|
||||
return;
|
||||
}
|
||||
assert( ( jointBuffer.GetOffset() & ( glConfig.uniformBufferOffsetAlignment - 1 ) ) == 0 );
|
||||
|
||||
const GLintptr ubo = jointBuffer.GetAPIObject();
|
||||
glBindBufferRange( GL_UNIFORM_BUFFER, 0, ubo, jointBuffer.GetOffset(), jointBuffer.GetSize() );
|
||||
|
||||
if( ( vertexLayout != LAYOUT_DRAW_SHADOW_VERT_SKINNED ) || ( currentVertexBuffer != ( GLintptr )vertexBuffer->GetAPIObject() ) || !r_useStateCaching.GetBool() )
|
||||
{
|
||||
glBindBuffer( GL_ARRAY_BUFFER, ( GLintptr )vertexBuffer->GetAPIObject() );
|
||||
currentVertexBuffer = ( GLintptr )vertexBuffer->GetAPIObject();
|
||||
|
||||
glEnableVertexAttribArray( PC_ATTRIB_INDEX_VERTEX );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_NORMAL );
|
||||
glEnableVertexAttribArray( PC_ATTRIB_INDEX_COLOR );
|
||||
glEnableVertexAttribArray( PC_ATTRIB_INDEX_COLOR2 );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_ST );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_TANGENT );
|
||||
|
||||
#if defined(USE_GLES2) || defined(USE_GLES3)
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_VERTEX, 4, GL_FLOAT, GL_FALSE, sizeof( idShadowVertSkinned ), ( void* )( vertOffset + SHADOWVERTSKINNED_XYZW_OFFSET ) );
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( idShadowVertSkinned ), ( void* )( vertOffset + SHADOWVERTSKINNED_COLOR_OFFSET ) );
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_COLOR2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( idShadowVertSkinned ), ( void* )( vertOffset + SHADOWVERTSKINNED_COLOR2_OFFSET ) );
|
||||
#else
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_VERTEX, 4, GL_FLOAT, GL_FALSE, sizeof( idShadowVertSkinned ), ( void* )( SHADOWVERTSKINNED_XYZW_OFFSET ) );
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( idShadowVertSkinned ), ( void* )( SHADOWVERTSKINNED_COLOR_OFFSET ) );
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_COLOR2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( idShadowVertSkinned ), ( void* )( SHADOWVERTSKINNED_COLOR2_OFFSET ) );
|
||||
#endif
|
||||
|
||||
vertexLayout = LAYOUT_DRAW_SHADOW_VERT_SKINNED;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( vertexLayout != LAYOUT_DRAW_SHADOW_VERT ) || ( currentVertexBuffer != ( GLintptr )vertexBuffer->GetAPIObject() ) || !r_useStateCaching.GetBool() )
|
||||
{
|
||||
glBindBuffer( GL_ARRAY_BUFFER, ( GLintptr )vertexBuffer->GetAPIObject() );
|
||||
currentVertexBuffer = ( GLintptr )vertexBuffer->GetAPIObject();
|
||||
|
||||
glEnableVertexAttribArray( PC_ATTRIB_INDEX_VERTEX );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_NORMAL );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_COLOR );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_COLOR2 );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_ST );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_TANGENT );
|
||||
|
||||
#if defined(USE_GLES2) || defined(USE_GLES3)
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_VERTEX, 4, GL_FLOAT, GL_FALSE, sizeof( idShadowVert ), ( void* )( vertOffset + SHADOWVERT_XYZW_OFFSET ) );
|
||||
#else
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_VERTEX, 4, GL_FLOAT, GL_FALSE, sizeof( idShadowVert ), ( void* )( SHADOWVERT_XYZW_OFFSET ) );
|
||||
#endif
|
||||
|
||||
vertexLayout = LAYOUT_DRAW_SHADOW_VERT;
|
||||
}
|
||||
}
|
||||
// RB end
|
||||
|
||||
renderProgManager.CommitUniforms();
|
||||
|
||||
if( drawSurf->jointCache )
|
||||
{
|
||||
#if defined(USE_GLES3) //defined(USE_GLES2)
|
||||
glDrawElements( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset );
|
||||
#else
|
||||
glDrawElementsBaseVertex( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset, vertOffset / sizeof( idShadowVertSkinned ) );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(USE_GLES3)
|
||||
glDrawElements( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset );
|
||||
#else
|
||||
glDrawElementsBaseVertex( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset, vertOffset / sizeof( idShadowVert ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
// RB: added stats
|
||||
pc.c_shadowElements++;
|
||||
pc.c_shadowIndexes += drawSurf->numIndexes;
|
||||
// RB end
|
||||
|
||||
if( !renderZPass && r_useStencilShadowPreload.GetBool() )
|
||||
{
|
||||
// render again with Z-pass
|
||||
glStencilOpSeparate( GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR );
|
||||
glStencilOpSeparate( GL_BACK, GL_KEEP, GL_KEEP, GL_DECR );
|
||||
|
||||
if( drawSurf->jointCache )
|
||||
{
|
||||
#if defined(USE_GLES3)
|
||||
glDrawElements( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset );
|
||||
#else
|
||||
glDrawElementsBaseVertex( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset, vertOffset / sizeof( idShadowVertSkinned ) );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(USE_GLES3)
|
||||
glDrawElements( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset );
|
||||
#else
|
||||
glDrawElementsBaseVertex( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset, vertOffset / sizeof( idShadowVert ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
// RB: added stats
|
||||
pc.c_shadowElements++;
|
||||
pc.c_shadowIndexes += drawSurf->numIndexes;
|
||||
// RB end
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
============================================================================
|
||||
|
||||
|
|
|
@ -2472,6 +2472,7 @@ void idRenderBackend::StencilShadowPass( const drawSurf_t* drawSurfs, const view
|
|||
const bool renderZPass = ( drawSurf->renderZFail == 0 ) || r_forceZPassStencilShadows.GetBool();
|
||||
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
if( renderZPass )
|
||||
{
|
||||
// Z-pass
|
||||
|
@ -2488,173 +2489,9 @@ void idRenderBackend::StencilShadowPass( const drawSurf_t* drawSurfs, const view
|
|||
{
|
||||
// Z-fail
|
||||
}
|
||||
|
||||
|
||||
// get vertex buffer
|
||||
const vertCacheHandle_t vbHandle = drawSurf->shadowCache;
|
||||
idVertexBuffer* vertexBuffer;
|
||||
if( vertexCache.CacheIsStatic( vbHandle ) )
|
||||
{
|
||||
vertexBuffer = &vertexCache.staticData.vertexBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint64 frameNum = ( int )( vbHandle >> VERTCACHE_FRAME_SHIFT ) & VERTCACHE_FRAME_MASK;
|
||||
if( frameNum != ( ( vertexCache.currentFrame - 1 ) & VERTCACHE_FRAME_MASK ) )
|
||||
{
|
||||
idLib::Warning( "RB_DrawElementsWithCounters, vertexBuffer == NULL" );
|
||||
continue;
|
||||
}
|
||||
vertexBuffer = &vertexCache.frameData[vertexCache.drawListNum].vertexBuffer;
|
||||
}
|
||||
const int vertOffset = ( int )( vbHandle >> VERTCACHE_OFFSET_SHIFT ) & VERTCACHE_OFFSET_MASK;
|
||||
|
||||
// get index buffer
|
||||
const vertCacheHandle_t ibHandle = drawSurf->indexCache;
|
||||
idIndexBuffer* indexBuffer;
|
||||
if( vertexCache.CacheIsStatic( ibHandle ) )
|
||||
{
|
||||
indexBuffer = &vertexCache.staticData.indexBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint64 frameNum = ( int )( ibHandle >> VERTCACHE_FRAME_SHIFT ) & VERTCACHE_FRAME_MASK;
|
||||
if( frameNum != ( ( vertexCache.currentFrame - 1 ) & VERTCACHE_FRAME_MASK ) )
|
||||
{
|
||||
idLib::Warning( "RB_DrawElementsWithCounters, indexBuffer == NULL" );
|
||||
continue;
|
||||
}
|
||||
indexBuffer = &vertexCache.frameData[vertexCache.drawListNum].indexBuffer;
|
||||
}
|
||||
const uint64 indexOffset = ( int )( ibHandle >> VERTCACHE_OFFSET_SHIFT ) & VERTCACHE_OFFSET_MASK;
|
||||
|
||||
RENDERLOG_PRINTF( "Binding Buffers: %p %p\n", vertexBuffer, indexBuffer );
|
||||
|
||||
// RB: 64 bit fixes, changed GLuint to GLintptr
|
||||
if( currentIndexBuffer != ( GLintptr )indexBuffer->GetAPIObject() || !r_useStateCaching.GetBool() )
|
||||
{
|
||||
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ( GLintptr )indexBuffer->GetAPIObject() );
|
||||
currentIndexBuffer = ( GLintptr )indexBuffer->GetAPIObject();
|
||||
}
|
||||
|
||||
if( drawSurf->jointCache )
|
||||
{
|
||||
assert( renderProgManager.ShaderUsesJoints() );
|
||||
|
||||
idUniformBuffer jointBuffer;
|
||||
if( !vertexCache.GetJointBuffer( drawSurf->jointCache, &jointBuffer ) )
|
||||
{
|
||||
idLib::Warning( "RB_DrawElementsWithCounters, jointBuffer == NULL" );
|
||||
continue;
|
||||
}
|
||||
assert( ( jointBuffer.GetOffset() & ( glConfig.uniformBufferOffsetAlignment - 1 ) ) == 0 );
|
||||
|
||||
const GLintptr ubo = jointBuffer.GetAPIObject();
|
||||
glBindBufferRange( GL_UNIFORM_BUFFER, 0, ubo, jointBuffer.GetOffset(), jointBuffer.GetSize() );
|
||||
|
||||
if( ( vertexLayout != LAYOUT_DRAW_SHADOW_VERT_SKINNED ) || ( currentVertexBuffer != ( GLintptr )vertexBuffer->GetAPIObject() ) || !r_useStateCaching.GetBool() )
|
||||
{
|
||||
glBindBuffer( GL_ARRAY_BUFFER, ( GLintptr )vertexBuffer->GetAPIObject() );
|
||||
currentVertexBuffer = ( GLintptr )vertexBuffer->GetAPIObject();
|
||||
|
||||
glEnableVertexAttribArray( PC_ATTRIB_INDEX_VERTEX );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_NORMAL );
|
||||
glEnableVertexAttribArray( PC_ATTRIB_INDEX_COLOR );
|
||||
glEnableVertexAttribArray( PC_ATTRIB_INDEX_COLOR2 );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_ST );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_TANGENT );
|
||||
|
||||
#if defined(USE_GLES2) || defined(USE_GLES3)
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_VERTEX, 4, GL_FLOAT, GL_FALSE, sizeof( idShadowVertSkinned ), ( void* )( vertOffset + SHADOWVERTSKINNED_XYZW_OFFSET ) );
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( idShadowVertSkinned ), ( void* )( vertOffset + SHADOWVERTSKINNED_COLOR_OFFSET ) );
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_COLOR2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( idShadowVertSkinned ), ( void* )( vertOffset + SHADOWVERTSKINNED_COLOR2_OFFSET ) );
|
||||
#else
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_VERTEX, 4, GL_FLOAT, GL_FALSE, sizeof( idShadowVertSkinned ), ( void* )( SHADOWVERTSKINNED_XYZW_OFFSET ) );
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( idShadowVertSkinned ), ( void* )( SHADOWVERTSKINNED_COLOR_OFFSET ) );
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_COLOR2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( idShadowVertSkinned ), ( void* )( SHADOWVERTSKINNED_COLOR2_OFFSET ) );
|
||||
#endif
|
||||
|
||||
vertexLayout = LAYOUT_DRAW_SHADOW_VERT_SKINNED;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( vertexLayout != LAYOUT_DRAW_SHADOW_VERT ) || ( currentVertexBuffer != ( GLintptr )vertexBuffer->GetAPIObject() ) || !r_useStateCaching.GetBool() )
|
||||
{
|
||||
glBindBuffer( GL_ARRAY_BUFFER, ( GLintptr )vertexBuffer->GetAPIObject() );
|
||||
currentVertexBuffer = ( GLintptr )vertexBuffer->GetAPIObject();
|
||||
|
||||
glEnableVertexAttribArray( PC_ATTRIB_INDEX_VERTEX );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_NORMAL );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_COLOR );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_COLOR2 );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_ST );
|
||||
glDisableVertexAttribArray( PC_ATTRIB_INDEX_TANGENT );
|
||||
|
||||
#if defined(USE_GLES2) || defined(USE_GLES3)
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_VERTEX, 4, GL_FLOAT, GL_FALSE, sizeof( idShadowVert ), ( void* )( vertOffset + SHADOWVERT_XYZW_OFFSET ) );
|
||||
#else
|
||||
glVertexAttribPointer( PC_ATTRIB_INDEX_VERTEX, 4, GL_FLOAT, GL_FALSE, sizeof( idShadowVert ), ( void* )( SHADOWVERT_XYZW_OFFSET ) );
|
||||
#endif
|
||||
|
||||
vertexLayout = LAYOUT_DRAW_SHADOW_VERT;
|
||||
}
|
||||
}
|
||||
// RB end
|
||||
|
||||
renderProgManager.CommitUniforms();
|
||||
|
||||
if( drawSurf->jointCache )
|
||||
{
|
||||
#if defined(USE_GLES3) //defined(USE_GLES2)
|
||||
glDrawElements( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset );
|
||||
#else
|
||||
glDrawElementsBaseVertex( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset, vertOffset / sizeof( idShadowVertSkinned ) );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(USE_GLES3)
|
||||
glDrawElements( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset );
|
||||
#else
|
||||
glDrawElementsBaseVertex( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset, vertOffset / sizeof( idShadowVert ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
// RB: added stats
|
||||
pc.c_shadowElements++;
|
||||
pc.c_shadowIndexes += drawSurf->numIndexes;
|
||||
// RB end
|
||||
|
||||
if( !renderZPass && r_useStencilShadowPreload.GetBool() )
|
||||
{
|
||||
// render again with Z-pass
|
||||
glStencilOpSeparate( GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR );
|
||||
glStencilOpSeparate( GL_BACK, GL_KEEP, GL_KEEP, GL_DECR );
|
||||
|
||||
if( drawSurf->jointCache )
|
||||
{
|
||||
#if defined(USE_GLES3)
|
||||
glDrawElements( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset );
|
||||
#else
|
||||
glDrawElementsBaseVertex( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset, vertOffset / sizeof( idShadowVertSkinned ) );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(USE_GLES3)
|
||||
glDrawElements( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset );
|
||||
#else
|
||||
glDrawElementsBaseVertex( GL_TRIANGLES, r_singleTriangle.GetBool() ? 3 : drawSurf->numIndexes, GL_INDEX_TYPE, ( triIndex_t* )indexOffset, vertOffset / sizeof( idShadowVert ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
// RB: added stats
|
||||
pc.c_shadowElements++;
|
||||
pc.c_shadowIndexes += drawSurf->numIndexes;
|
||||
// RB end
|
||||
}
|
||||
DrawStencilShadowPass( drawSurf, renderZPass );
|
||||
}
|
||||
|
||||
// cleanup the shadow specific rendering state
|
||||
|
@ -2718,9 +2555,11 @@ void idRenderBackend::StencilSelectLight( const viewLight_t* vLight )
|
|||
idRenderMatrix::Multiply( viewDef->worldSpace.mvp, vLight->inverseBaseLightProject, invProjectMVPMatrix );
|
||||
RB_SetMVP( invProjectMVPMatrix );
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
// two-sided stencil test
|
||||
glStencilOpSeparate( GL_FRONT, GL_KEEP, GL_REPLACE, GL_ZERO );
|
||||
glStencilOpSeparate( GL_BACK, GL_KEEP, GL_ZERO, GL_REPLACE );
|
||||
#endif
|
||||
|
||||
DrawElementsWithCounters( &zeroOneCubeSurface );
|
||||
|
||||
|
@ -3189,7 +3028,9 @@ void idRenderBackend::ShadowMapPass( const drawSurf_t* drawSurfs, const viewLigh
|
|||
|
||||
GL_ViewportAndScissor( 0, 0, shadowMapResolutions[vLight->shadowLOD], shadowMapResolutions[vLight->shadowLOD] );
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
glClear( GL_DEPTH_BUFFER_BIT );
|
||||
#endif
|
||||
|
||||
// process the chain of shadows with the current rendering state
|
||||
currentSpace = NULL;
|
||||
|
@ -5344,7 +5185,7 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste
|
|||
// normal face culling
|
||||
GL_Cull( CT_FRONT_SIDED );
|
||||
|
||||
#if defined(USE_CORE_PROFILE) && !defined(USE_GLES2) && !defined(USE_GLES3) && !defined(USE_VULKAN)
|
||||
#if defined(USE_CORE_PROFILE) && !defined(USE_VULKAN)
|
||||
// bind one global Vertex Array Object (VAO)
|
||||
glBindVertexArray( glConfig.global_vao );
|
||||
#endif
|
||||
|
|
|
@ -131,7 +131,7 @@ void RB_BakeTextureMatrixIntoTexgen( idPlane lightProject[3], const float* textu
|
|||
//bool ChangeDisplaySettingsIfNeeded( gfxImpParms_t parms );
|
||||
//bool CreateGameWindow( gfxImpParms_t parms );
|
||||
|
||||
#if defined( ID_VULKAN )
|
||||
#if defined( USE_VULKAN )
|
||||
|
||||
struct gpuInfo_t
|
||||
{
|
||||
|
|
|
@ -39,10 +39,7 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include "Font.h"
|
||||
#include "Framebuffer.h"
|
||||
|
||||
// everything that is needed by the backend needs
|
||||
// to be double buffered to allow it to run in
|
||||
// parallel on a dual cpu machine
|
||||
const int SMP_FRAMES = 1;
|
||||
|
||||
|
||||
// maximum texture units
|
||||
const int MAX_PROG_TEXTURE_PARMS = 16;
|
||||
|
@ -55,6 +52,7 @@ const float DEFAULT_FOG_DISTANCE = 500.0f;
|
|||
const int FOG_ENTER_SIZE = 64;
|
||||
const float FOG_ENTER = ( FOG_ENTER_SIZE + 1.0f ) / ( FOG_ENTER_SIZE * 2 );
|
||||
|
||||
|
||||
enum demoCommand_t
|
||||
{
|
||||
DC_BAD,
|
||||
|
|
|
@ -463,7 +463,10 @@ void idRenderProgManager::BindShader( int progIndex, int vIndex, int fIndex, boo
|
|||
{
|
||||
currentRenderProgram = vIndex;
|
||||
RENDERLOG_PRINTF( "Binding GLSL Program %s\n", glslPrograms[vIndex].name.c_str() );
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
glUseProgram( glslPrograms[vIndex].progId );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -488,7 +491,10 @@ void idRenderProgManager::BindShader( int progIndex, int vIndex, int fIndex, boo
|
|||
{
|
||||
currentRenderProgram = progIndex;
|
||||
RENDERLOG_PRINTF( "Binding GLSL Program %s\n", glslPrograms[progIndex].name.c_str() );
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
glUseProgram( glslPrograms[progIndex].progId );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -504,7 +510,9 @@ void idRenderProgManager::Unbind()
|
|||
currentVertexShader = -1;
|
||||
currentFragmentShader = -1;
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
glUseProgram( 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
// RB begin
|
||||
|
|
|
@ -649,6 +649,7 @@ void idRenderSystemLocal::SwapCommandBuffers_FinishRendering(
|
|||
backend.BlockingSwapBuffers();
|
||||
}
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
// read back the start and end timer queries from the previous frame
|
||||
if( glConfig.timerQueryAvailable )
|
||||
{
|
||||
|
@ -665,6 +666,7 @@ void idRenderSystemLocal::SwapCommandBuffers_FinishRendering(
|
|||
*gpuMicroSec = drawingTimeNanoseconds / 1000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------
|
||||
|
||||
|
@ -770,9 +772,12 @@ const emptyCommand_t* idRenderSystemLocal::SwapCommandBuffers_FinishCommandBuffe
|
|||
// set the time for shader effects in 2D rendering
|
||||
frameShaderTime = Sys_Milliseconds() * 0.001;
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
// RB: TODO RC_SET_BUFFER is not handled in OpenGL
|
||||
setBufferCommand_t* cmd2 = ( setBufferCommand_t* )R_GetCommandBuffer( sizeof( *cmd2 ) );
|
||||
cmd2->commandId = RC_SET_BUFFER;
|
||||
cmd2->buffer = ( int )GL_BACK;
|
||||
#endif
|
||||
|
||||
// the old command buffer can now be rendered, while the new one can
|
||||
// be built in parallel
|
||||
|
@ -987,6 +992,7 @@ void idRenderSystemLocal::CaptureRenderToFile( const char* fileName, bool fixAlp
|
|||
guiModel->Clear();
|
||||
RenderCommandBuffers( frameData->cmdHead );
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
glReadBuffer( GL_BACK );
|
||||
|
||||
// include extra space for OpenGL padding to word boundaries
|
||||
|
@ -1009,6 +1015,7 @@ void idRenderSystemLocal::CaptureRenderToFile( const char* fileName, bool fixAlp
|
|||
|
||||
R_StaticFree( data );
|
||||
R_StaticFree( data2 );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -838,7 +838,6 @@ and model information functions.
|
|||
*/
|
||||
void R_InitOpenGL()
|
||||
{
|
||||
|
||||
common->Printf( "----- R_InitOpenGL -----\n" );
|
||||
|
||||
if( R_IsInitialized() )
|
||||
|
@ -852,7 +851,6 @@ void R_InitOpenGL()
|
|||
|
||||
R_SetNewMode( true );
|
||||
|
||||
|
||||
// input and sound systems need to be tied to the new window
|
||||
Sys_InitInput();
|
||||
|
||||
|
@ -2540,15 +2538,7 @@ void R_TouchGui_f( const idCmdArgs& args )
|
|||
uiManager->Touch( gui );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
R_InitCvars
|
||||
=================
|
||||
*/
|
||||
void R_InitCvars()
|
||||
{
|
||||
// update latched cvars here
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=================
|
||||
|
@ -2851,8 +2841,6 @@ void idRenderSystemLocal::Init()
|
|||
|
||||
backend.Init();
|
||||
|
||||
R_InitCvars();
|
||||
|
||||
R_InitCommands();
|
||||
|
||||
guiModel = new( TAG_RENDER ) idGuiModel;
|
||||
|
|
|
@ -27,7 +27,9 @@ If you have questions concerning this license or the applicable additional terms
|
|||
===========================================================================
|
||||
*/
|
||||
#pragma hdrstop
|
||||
#include "../../idlib/precompiled.h"
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "../RenderCommon.h"
|
||||
#include "../RenderBackend.h"
|
||||
#include "Allocator_VK.h"
|
||||
|
||||
|
|
|
@ -44,10 +44,10 @@ idImage::idImage
|
|||
*/
|
||||
idImage::idImage( const char* name ) : imgName( name )
|
||||
{
|
||||
texnum = TEXTURE_NOT_LOADED;
|
||||
internalFormat = 0;
|
||||
dataFormat = 0;
|
||||
dataType = 0;
|
||||
//texnum = TEXTURE_NOT_LOADED;
|
||||
//internalFormat = 0;
|
||||
//dataFormat = 0;
|
||||
//dataType = 0;
|
||||
generatorFunction = NULL;
|
||||
filter = TF_DEFAULT;
|
||||
repeat = TR_REPEAT;
|
||||
|
@ -81,97 +81,7 @@ Automatically enables 2D mapping or cube mapping if needed
|
|||
*/
|
||||
void idImage::Bind()
|
||||
{
|
||||
RENDERLOG_PRINTF( "idImage::Bind( %s )\n", GetName() );
|
||||
|
||||
// load the image if necessary (FIXME: not SMP safe!)
|
||||
if( !IsLoaded() )
|
||||
{
|
||||
// load the image on demand here, which isn't our normal game operating mode
|
||||
ActuallyLoadImage( true );
|
||||
}
|
||||
|
||||
const int texUnit = tr.backend.GetCurrentTextureUnit();
|
||||
|
||||
// RB: added support for more types
|
||||
tmu_t* tmu = &glcontext.tmu[texUnit];
|
||||
// bind the texture
|
||||
if( opts.textureType == TT_2D )
|
||||
{
|
||||
if( tmu->current2DMap != texnum )
|
||||
{
|
||||
tmu->current2DMap = texnum;
|
||||
|
||||
#if !defined(USE_GLES2) && !defined(USE_GLES3)
|
||||
if( glConfig.directStateAccess )
|
||||
{
|
||||
glBindMultiTextureEXT( GL_TEXTURE0 + texUnit, GL_TEXTURE_2D, texnum );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
glActiveTexture( GL_TEXTURE0 + texUnit );
|
||||
glBindTexture( GL_TEXTURE_2D, texnum );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( opts.textureType == TT_CUBIC )
|
||||
{
|
||||
if( tmu->currentCubeMap != texnum )
|
||||
{
|
||||
tmu->currentCubeMap = texnum;
|
||||
|
||||
#if !defined(USE_GLES2) && !defined(USE_GLES3)
|
||||
if( glConfig.directStateAccess )
|
||||
{
|
||||
glBindMultiTextureEXT( GL_TEXTURE0 + texUnit, GL_TEXTURE_CUBE_MAP, texnum );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
glActiveTexture( GL_TEXTURE0 + texUnit );
|
||||
glBindTexture( GL_TEXTURE_CUBE_MAP, texnum );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( opts.textureType == TT_2D_ARRAY )
|
||||
{
|
||||
if( tmu->current2DArray != texnum )
|
||||
{
|
||||
tmu->current2DArray = texnum;
|
||||
|
||||
#if !defined(USE_GLES2) && !defined(USE_GLES3)
|
||||
if( glConfig.directStateAccess )
|
||||
{
|
||||
glBindMultiTextureEXT( GL_TEXTURE0 + texUnit, GL_TEXTURE_2D_ARRAY, texnum );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
glActiveTexture( GL_TEXTURE0 + texUnit );
|
||||
glBindTexture( GL_TEXTURE_2D_ARRAY, texnum );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( opts.textureType == TT_2D_MULTISAMPLE )
|
||||
{
|
||||
if( tmu->current2DMap != texnum )
|
||||
{
|
||||
tmu->current2DMap = texnum;
|
||||
|
||||
#if !defined(USE_GLES2) && !defined(USE_GLES3)
|
||||
if( glConfig.directStateAccess )
|
||||
{
|
||||
glBindMultiTextureEXT( GL_TEXTURE0 + texUnit, GL_TEXTURE_2D_MULTISAMPLE, texnum );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
glActiveTexture( GL_TEXTURE0 + texUnit );
|
||||
glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, texnum );
|
||||
}
|
||||
}
|
||||
}
|
||||
// RB end
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -181,82 +91,7 @@ CopyFramebuffer
|
|||
*/
|
||||
void idImage::CopyFramebuffer( int x, int y, int imageWidth, int imageHeight )
|
||||
{
|
||||
int target = GL_TEXTURE_2D;
|
||||
switch( opts.textureType )
|
||||
{
|
||||
case TT_2D:
|
||||
target = GL_TEXTURE_2D;
|
||||
break;
|
||||
case TT_CUBIC:
|
||||
target = GL_TEXTURE_CUBE_MAP;
|
||||
break;
|
||||
case TT_2D_ARRAY:
|
||||
target = GL_TEXTURE_2D_ARRAY;
|
||||
break;
|
||||
case TT_2D_MULTISAMPLE:
|
||||
target = GL_TEXTURE_2D_MULTISAMPLE;
|
||||
break;
|
||||
default:
|
||||
//idLib::FatalError( "%s: bad texture type %d", GetName(), opts.textureType );
|
||||
return;
|
||||
}
|
||||
|
||||
glBindTexture( target, texnum );
|
||||
|
||||
#if !defined(USE_GLES2)
|
||||
if( Framebuffer::IsDefaultFramebufferActive() )
|
||||
{
|
||||
glReadBuffer( GL_BACK );
|
||||
}
|
||||
#endif
|
||||
|
||||
opts.width = imageWidth;
|
||||
opts.height = imageHeight;
|
||||
|
||||
#if defined(USE_GLES2)
|
||||
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, x, y, imageWidth, imageHeight, 0 );
|
||||
#else
|
||||
if( r_useHDR.GetBool() && globalFramebuffers.hdrFBO->IsBound() )
|
||||
{
|
||||
|
||||
//if( backEnd.glState.currentFramebuffer != NULL && backEnd.glState.currentFramebuffer->IsMultiSampled() )
|
||||
|
||||
#if defined(USE_HDR_MSAA)
|
||||
if( globalFramebuffers.hdrFBO->IsMultiSampled() )
|
||||
{
|
||||
glBindFramebuffer( GL_READ_FRAMEBUFFER, globalFramebuffers.hdrFBO->GetFramebuffer() );
|
||||
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, globalFramebuffers.hdrNonMSAAFBO->GetFramebuffer() );
|
||||
glBlitFramebuffer( 0, 0, glConfig.nativeScreenWidth, glConfig.nativeScreenHeight,
|
||||
0, 0, glConfig.nativeScreenWidth, glConfig.nativeScreenHeight,
|
||||
GL_COLOR_BUFFER_BIT,
|
||||
GL_LINEAR );
|
||||
|
||||
globalFramebuffers.hdrNonMSAAFBO->Bind();
|
||||
|
||||
glCopyTexImage2D( target, 0, GL_RGBA16F, x, y, imageWidth, imageHeight, 0 );
|
||||
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
glCopyTexImage2D( target, 0, GL_RGBA16F, x, y, imageWidth, imageHeight, 0 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glCopyTexImage2D( target, 0, GL_RGBA8, x, y, imageWidth, imageHeight, 0 );
|
||||
}
|
||||
#endif
|
||||
|
||||
// these shouldn't be necessary if the image was initialized properly
|
||||
glTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
glTexParameterf( target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
|
||||
tr.backend.pc.c_copyFrameBuffer++;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -266,13 +101,7 @@ CopyDepthbuffer
|
|||
*/
|
||||
void idImage::CopyDepthbuffer( int x, int y, int imageWidth, int imageHeight )
|
||||
{
|
||||
glBindTexture( ( opts.textureType == TT_CUBIC ) ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, texnum );
|
||||
|
||||
opts.width = imageWidth;
|
||||
opts.height = imageHeight;
|
||||
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, x, y, imageWidth, imageHeight, 0 );
|
||||
|
||||
tr.backend.pc.c_copyFrameBuffer++;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -282,110 +111,7 @@ idImage::SubImageUpload
|
|||
*/
|
||||
void idImage::SubImageUpload( int mipLevel, int x, int y, int z, int width, int height, const void* pic, int pixelPitch ) const
|
||||
{
|
||||
assert( x >= 0 && y >= 0 && mipLevel >= 0 && width >= 0 && height >= 0 && mipLevel < opts.numLevels );
|
||||
|
||||
int compressedSize = 0;
|
||||
|
||||
if( IsCompressed() )
|
||||
{
|
||||
assert( !( x & 3 ) && !( y & 3 ) );
|
||||
|
||||
// compressed size may be larger than the dimensions due to padding to quads
|
||||
int quadW = ( width + 3 ) & ~3;
|
||||
int quadH = ( height + 3 ) & ~3;
|
||||
compressedSize = quadW * quadH * BitsForFormat( opts.format ) / 8;
|
||||
|
||||
int padW = ( opts.width + 3 ) & ~3;
|
||||
int padH = ( opts.height + 3 ) & ~3;
|
||||
|
||||
assert( x + width <= padW && y + height <= padH );
|
||||
// upload the non-aligned value, OpenGL understands that there
|
||||
// will be padding
|
||||
if( x + width > opts.width )
|
||||
{
|
||||
width = opts.width - x;
|
||||
}
|
||||
if( y + height > opts.height )
|
||||
{
|
||||
height = opts.height - x;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( x + width <= opts.width && y + height <= opts.height );
|
||||
}
|
||||
|
||||
int target;
|
||||
int uploadTarget;
|
||||
if( opts.textureType == TT_2D )
|
||||
{
|
||||
target = GL_TEXTURE_2D;
|
||||
uploadTarget = GL_TEXTURE_2D;
|
||||
}
|
||||
else if( opts.textureType == TT_CUBIC )
|
||||
{
|
||||
target = GL_TEXTURE_CUBE_MAP;
|
||||
uploadTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + z;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( !"invalid opts.textureType" );
|
||||
target = GL_TEXTURE_2D;
|
||||
uploadTarget = GL_TEXTURE_2D;
|
||||
}
|
||||
|
||||
glBindTexture( target, texnum );
|
||||
|
||||
if( pixelPitch != 0 )
|
||||
{
|
||||
glPixelStorei( GL_UNPACK_ROW_LENGTH, pixelPitch );
|
||||
}
|
||||
|
||||
if( opts.format == FMT_RGB565 )
|
||||
{
|
||||
#if !defined(USE_GLES3)
|
||||
glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_TRUE );
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(DEBUG) || defined(__ANDROID__)
|
||||
GL_CheckErrors();
|
||||
#endif
|
||||
if( IsCompressed() )
|
||||
{
|
||||
glCompressedTexSubImage2D( uploadTarget, mipLevel, x, y, width, height, internalFormat, compressedSize, pic );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// make sure the pixel store alignment is correct so that lower mips get created
|
||||
// properly for odd shaped textures - this fixes the mip mapping issues with
|
||||
// fonts
|
||||
int unpackAlignment = width * BitsForFormat( ( textureFormat_t )opts.format ) / 8;
|
||||
if( ( unpackAlignment & 3 ) == 0 )
|
||||
{
|
||||
glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
|
||||
}
|
||||
else
|
||||
{
|
||||
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
||||
}
|
||||
|
||||
glTexSubImage2D( uploadTarget, mipLevel, x, y, width, height, dataFormat, dataType, pic );
|
||||
}
|
||||
|
||||
#if defined(DEBUG) || defined(__ANDROID__)
|
||||
GL_CheckErrors();
|
||||
#endif
|
||||
|
||||
if( opts.format == FMT_RGB565 )
|
||||
{
|
||||
glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
|
||||
}
|
||||
if( pixelPitch != 0 )
|
||||
{
|
||||
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -405,188 +131,7 @@ idImage::SetTexParameters
|
|||
*/
|
||||
void idImage::SetTexParameters()
|
||||
{
|
||||
int target = GL_TEXTURE_2D;
|
||||
switch( opts.textureType )
|
||||
{
|
||||
case TT_2D:
|
||||
target = GL_TEXTURE_2D;
|
||||
break;
|
||||
case TT_CUBIC:
|
||||
target = GL_TEXTURE_CUBE_MAP;
|
||||
break;
|
||||
// RB begin
|
||||
case TT_2D_ARRAY:
|
||||
target = GL_TEXTURE_2D_ARRAY;
|
||||
break;
|
||||
case TT_2D_MULTISAMPLE:
|
||||
//target = GL_TEXTURE_2D_MULTISAMPLE;
|
||||
//break;
|
||||
// no texture parameters for MSAA FBO textures
|
||||
return;
|
||||
// RB end
|
||||
default:
|
||||
idLib::FatalError( "%s: bad texture type %d", GetName(), opts.textureType );
|
||||
return;
|
||||
}
|
||||
|
||||
// ALPHA, LUMINANCE, LUMINANCE_ALPHA, and INTENSITY have been removed
|
||||
// in OpenGL 3.2. In order to mimic those modes, we use the swizzle operators
|
||||
#if defined( USE_CORE_PROFILE )
|
||||
if( opts.colorFormat == CFM_GREEN_ALPHA )
|
||||
{
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_GREEN );
|
||||
}
|
||||
else if( opts.format == FMT_LUM8 )
|
||||
{
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_ONE );
|
||||
}
|
||||
else if( opts.format == FMT_L8A8 )
|
||||
{
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_GREEN );
|
||||
}
|
||||
else if( opts.format == FMT_ALPHA )
|
||||
{
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_RED );
|
||||
}
|
||||
else if( opts.format == FMT_INT8 )
|
||||
{
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_RED );
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_GREEN );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_BLUE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_ALPHA );
|
||||
}
|
||||
#else
|
||||
if( opts.colorFormat == CFM_GREEN_ALPHA )
|
||||
{
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_GREEN );
|
||||
}
|
||||
else if( opts.format == FMT_ALPHA )
|
||||
{
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ONE );
|
||||
glTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_RED );
|
||||
}
|
||||
#endif
|
||||
|
||||
switch( filter )
|
||||
{
|
||||
case TF_DEFAULT:
|
||||
if( r_useTrilinearFiltering.GetBool() )
|
||||
{
|
||||
glTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
|
||||
}
|
||||
glTexParameterf( target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
break;
|
||||
case TF_LINEAR:
|
||||
glTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
glTexParameterf( target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
break;
|
||||
case TF_NEAREST:
|
||||
case TF_NEAREST_MIPMAP:
|
||||
glTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
||||
glTexParameterf( target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
|
||||
break;
|
||||
default:
|
||||
common->FatalError( "%s: bad texture filter %d", GetName(), filter );
|
||||
}
|
||||
|
||||
if( glConfig.anisotropicFilterAvailable )
|
||||
{
|
||||
// only do aniso filtering on mip mapped images
|
||||
if( filter == TF_DEFAULT )
|
||||
{
|
||||
int aniso = r_maxAnisotropicFiltering.GetInteger();
|
||||
if( aniso > glConfig.maxTextureAnisotropy )
|
||||
{
|
||||
aniso = glConfig.maxTextureAnisotropy;
|
||||
}
|
||||
if( aniso < 0 )
|
||||
{
|
||||
aniso = 0;
|
||||
}
|
||||
glTexParameterf( target, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso );
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameterf( target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
// RB: disabled use of unreliable extension that can make the game look worse
|
||||
/*
|
||||
if( glConfig.textureLODBiasAvailable && ( usage != TD_FONT ) )
|
||||
{
|
||||
// use a blurring LOD bias in combination with high anisotropy to fix our aliasing grate textures...
|
||||
glTexParameterf( target, GL_TEXTURE_LOD_BIAS_EXT, 0.5 ); //r_lodBias.GetFloat() );
|
||||
}
|
||||
*/
|
||||
// RB end
|
||||
|
||||
// set the wrap/clamp modes
|
||||
switch( repeat )
|
||||
{
|
||||
case TR_REPEAT:
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_S, GL_REPEAT );
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
||||
break;
|
||||
case TR_CLAMP_TO_ZERO:
|
||||
{
|
||||
float color[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
glTexParameterfv( target, GL_TEXTURE_BORDER_COLOR, color );
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
|
||||
}
|
||||
break;
|
||||
case TR_CLAMP_TO_ZERO_ALPHA:
|
||||
{
|
||||
float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
glTexParameterfv( target, GL_TEXTURE_BORDER_COLOR, color );
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
|
||||
}
|
||||
break;
|
||||
case TR_CLAMP:
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
|
||||
glTexParameterf( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
break;
|
||||
default:
|
||||
common->FatalError( "%s: bad texture repeat %d", GetName(), repeat );
|
||||
}
|
||||
|
||||
// RB: added shadow compare parameters for shadow map textures
|
||||
if( opts.format == FMT_SHADOW_ARRAY )
|
||||
{
|
||||
//glTexParameteri( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
glTexParameteri( target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );
|
||||
glTexParameteri( target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -601,267 +146,7 @@ This should not be done during normal game-play, if you can avoid it.
|
|||
*/
|
||||
void idImage::AllocImage()
|
||||
{
|
||||
GL_CheckErrors();
|
||||
PurgeImage();
|
||||
|
||||
int sRGB = r_useSRGB.GetInteger();
|
||||
|
||||
switch( opts.format )
|
||||
{
|
||||
case FMT_RGBA8:
|
||||
//internalFormat = GL_RGBA8;
|
||||
//internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
|
||||
internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_XRGB8:
|
||||
internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB : GL_RGB;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_RGB565:
|
||||
//internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB : GL_RGB;
|
||||
internalFormat = GL_RGB;
|
||||
dataFormat = GL_RGB;
|
||||
dataType = GL_UNSIGNED_SHORT_5_6_5;
|
||||
break;
|
||||
case FMT_ALPHA:
|
||||
#if defined( USE_CORE_PROFILE )
|
||||
#if 1
|
||||
if( ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) )
|
||||
{
|
||||
internalFormat = GL_SRGB;
|
||||
dataFormat = GL_RED;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
internalFormat = GL_R8;
|
||||
dataFormat = GL_RED;
|
||||
}
|
||||
#else
|
||||
internalFormat = GL_ALPHA8;
|
||||
dataFormat = GL_ALPHA;
|
||||
#endif
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_L8A8:
|
||||
#if defined( USE_CORE_PROFILE )
|
||||
internalFormat = GL_RG8;
|
||||
dataFormat = GL_RG;
|
||||
#else
|
||||
internalFormat = GL_LUMINANCE8_ALPHA8;
|
||||
dataFormat = GL_LUMINANCE_ALPHA;
|
||||
#endif
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_LUM8:
|
||||
#if defined( USE_CORE_PROFILE )
|
||||
internalFormat = GL_R8;
|
||||
dataFormat = GL_RED;
|
||||
#else
|
||||
internalFormat = GL_LUMINANCE8;
|
||||
dataFormat = GL_LUMINANCE;
|
||||
#endif
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_INT8:
|
||||
#if defined( USE_CORE_PROFILE )
|
||||
internalFormat = GL_R8;
|
||||
dataFormat = GL_RED;
|
||||
#else
|
||||
internalFormat = GL_INTENSITY8;
|
||||
dataFormat = GL_LUMINANCE;
|
||||
#endif
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_DXT1:
|
||||
internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
//internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_DXT5:
|
||||
internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) && opts.colorFormat != CFM_YCOCG_DXT5 && opts.colorFormat != CFM_NORMAL_DXT5 ) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
//internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_DEPTH:
|
||||
internalFormat = GL_DEPTH_COMPONENT;
|
||||
dataFormat = GL_DEPTH_COMPONENT;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
case FMT_SHADOW_ARRAY:
|
||||
internalFormat = GL_DEPTH_COMPONENT;
|
||||
dataFormat = GL_DEPTH_COMPONENT;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
case FMT_RGBA16F:
|
||||
internalFormat = GL_RGBA16F;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
case FMT_RGBA32F:
|
||||
internalFormat = GL_RGBA32F;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
case FMT_R32F:
|
||||
internalFormat = GL_R32F;
|
||||
dataFormat = GL_RED;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
case FMT_X16:
|
||||
internalFormat = GL_INTENSITY16;
|
||||
dataFormat = GL_LUMINANCE;
|
||||
dataType = GL_UNSIGNED_SHORT;
|
||||
break;
|
||||
case FMT_Y16_X16:
|
||||
internalFormat = GL_LUMINANCE16_ALPHA16;
|
||||
dataFormat = GL_LUMINANCE_ALPHA;
|
||||
dataType = GL_UNSIGNED_SHORT;
|
||||
break;
|
||||
default:
|
||||
idLib::Error( "Unhandled image format %d in %s\n", opts.format, GetName() );
|
||||
}
|
||||
|
||||
// if we don't have a rendering context, just return after we
|
||||
// have filled in the parms. We must have the values set, or
|
||||
// an image match from a shader before OpenGL starts would miss
|
||||
// the generated texture
|
||||
if( !R_IsInitialized() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// generate the texture number
|
||||
glGenTextures( 1, ( GLuint* )&texnum );
|
||||
assert( texnum != TEXTURE_NOT_LOADED );
|
||||
|
||||
//----------------------------------------------------
|
||||
// allocate all the mip levels with NULL data
|
||||
//----------------------------------------------------
|
||||
|
||||
int numSides;
|
||||
int target;
|
||||
int uploadTarget;
|
||||
if( opts.textureType == TT_2D )
|
||||
{
|
||||
target = uploadTarget = GL_TEXTURE_2D;
|
||||
numSides = 1;
|
||||
}
|
||||
else if( opts.textureType == TT_CUBIC )
|
||||
{
|
||||
target = GL_TEXTURE_CUBE_MAP;
|
||||
uploadTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
|
||||
numSides = 6;
|
||||
}
|
||||
// RB begin
|
||||
else if( opts.textureType == TT_2D_ARRAY )
|
||||
{
|
||||
target = GL_TEXTURE_2D_ARRAY;
|
||||
uploadTarget = GL_TEXTURE_2D_ARRAY;
|
||||
numSides = 6;
|
||||
}
|
||||
else if( opts.textureType == TT_2D_MULTISAMPLE )
|
||||
{
|
||||
target = GL_TEXTURE_2D_MULTISAMPLE;
|
||||
uploadTarget = GL_TEXTURE_2D_MULTISAMPLE;
|
||||
numSides = 1;
|
||||
}
|
||||
// RB end
|
||||
else
|
||||
{
|
||||
assert( !"opts.textureType" );
|
||||
target = uploadTarget = GL_TEXTURE_2D;
|
||||
numSides = 1;
|
||||
}
|
||||
|
||||
glBindTexture( target, texnum );
|
||||
|
||||
if( opts.textureType == TT_2D_ARRAY )
|
||||
{
|
||||
glTexImage3D( uploadTarget, 0, internalFormat, opts.width, opts.height, numSides, 0, dataFormat, GL_UNSIGNED_BYTE, NULL );
|
||||
}
|
||||
else if( opts.textureType == TT_2D_MULTISAMPLE )
|
||||
{
|
||||
glTexImage2DMultisample( uploadTarget, opts.samples, internalFormat, opts.width, opts.height, GL_FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int side = 0; side < numSides; side++ )
|
||||
{
|
||||
int w = opts.width;
|
||||
int h = opts.height;
|
||||
if( opts.textureType == TT_CUBIC )
|
||||
{
|
||||
h = w;
|
||||
}
|
||||
for( int level = 0; level < opts.numLevels; level++ )
|
||||
{
|
||||
|
||||
// clear out any previous error
|
||||
GL_CheckErrors();
|
||||
|
||||
if( IsCompressed() )
|
||||
{
|
||||
int compressedSize = ( ( ( w + 3 ) / 4 ) * ( ( h + 3 ) / 4 ) * int64( 16 ) * BitsForFormat( opts.format ) ) / 8;
|
||||
|
||||
// Even though the OpenGL specification allows the 'data' pointer to be NULL, for some
|
||||
// drivers we actually need to upload data to get it to allocate the texture.
|
||||
// However, on 32-bit systems we may fail to allocate a large block of memory for large
|
||||
// textures. We handle this case by using HeapAlloc directly and allowing the allocation
|
||||
// to fail in which case we simply pass down NULL to glCompressedTexImage2D and hope for the best.
|
||||
// As of 2011-10-6 using NVIDIA hardware and drivers we have to allocate the memory with HeapAlloc
|
||||
// with the exact size otherwise large image allocation (for instance for physical page textures)
|
||||
// may fail on Vista 32-bit.
|
||||
|
||||
// RB begin
|
||||
#if defined(_WIN32)
|
||||
void* data = HeapAlloc( GetProcessHeap(), 0, compressedSize );
|
||||
glCompressedTexImage2D( uploadTarget + side, level, internalFormat, w, h, 0, compressedSize, data );
|
||||
if( data != NULL )
|
||||
{
|
||||
HeapFree( GetProcessHeap(), 0, data );
|
||||
}
|
||||
#else
|
||||
byte* data = ( byte* )Mem_Alloc( compressedSize, TAG_TEMP );
|
||||
glCompressedTexImage2D( uploadTarget + side, level, internalFormat, w, h, 0, compressedSize, data );
|
||||
if( data != NULL )
|
||||
{
|
||||
Mem_Free( data );
|
||||
}
|
||||
#endif
|
||||
// RB end
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexImage2D( uploadTarget + side, level, internalFormat, w, h, 0, dataFormat, dataType, NULL );
|
||||
}
|
||||
|
||||
GL_CheckErrors();
|
||||
|
||||
w = Max( 1, w >> 1 );
|
||||
h = Max( 1, h >> 1 );
|
||||
}
|
||||
}
|
||||
|
||||
glTexParameteri( target, GL_TEXTURE_MAX_LEVEL, opts.numLevels - 1 );
|
||||
}
|
||||
|
||||
// see if we messed anything up
|
||||
GL_CheckErrors();
|
||||
|
||||
SetTexParameters();
|
||||
|
||||
GL_CheckErrors();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -871,19 +156,7 @@ idImage::PurgeImage
|
|||
*/
|
||||
void idImage::PurgeImage()
|
||||
{
|
||||
if( texnum != TEXTURE_NOT_LOADED )
|
||||
{
|
||||
glDeleteTextures( 1, ( GLuint* )&texnum ); // this should be the ONLY place it is ever called!
|
||||
texnum = TEXTURE_NOT_LOADED;
|
||||
}
|
||||
|
||||
// clear all the current binding caches, so the next bind will do a real one
|
||||
for( int i = 0 ; i < MAX_MULTITEXTURE_UNITS ; i++ )
|
||||
{
|
||||
glcontext.tmu[i].current2DMap = TEXTURE_NOT_LOADED;
|
||||
glcontext.tmu[i].current2DArray = TEXTURE_NOT_LOADED;
|
||||
glcontext.tmu[i].currentCubeMap = TEXTURE_NOT_LOADED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -893,11 +166,5 @@ idImage::Resize
|
|||
*/
|
||||
void idImage::Resize( int width, int height )
|
||||
{
|
||||
if( opts.width == width && opts.height == height )
|
||||
{
|
||||
return;
|
||||
}
|
||||
opts.width = width;
|
||||
opts.height = height;
|
||||
AllocImage();
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -52,6 +52,16 @@ If you have questions concerning this license or the applicable additional terms
|
|||
|
||||
const char* VK_ErrorToString( VkResult result );
|
||||
|
||||
|
||||
static const int MAX_DESC_SETS = 16384;
|
||||
static const int MAX_DESC_UNIFORM_BUFFERS = 8192;
|
||||
static const int MAX_DESC_IMAGE_SAMPLERS = 12384;
|
||||
static const int MAX_DESC_SET_WRITES = 32;
|
||||
static const int MAX_DESC_SET_UNIFORMS = 48;
|
||||
static const int MAX_IMAGE_PARMS = 16;
|
||||
static const int MAX_UBO_PARMS = 2;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -55,7 +55,7 @@ idCVar r_useOpenGL32( "r_useOpenGL32", "1", CVAR_INTEGER, "0 = OpenGL 2.0, 1 = O
|
|||
|
||||
|
||||
|
||||
|
||||
#if !defined(USE_VULKAN)
|
||||
/*
|
||||
========================
|
||||
GLimp_TestSwapBuffers
|
||||
|
@ -99,6 +99,7 @@ void GLimp_TestSwapBuffers( const idCmdArgs& args )
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
========================
|
||||
|
|
|
@ -32,7 +32,9 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include <windows.h>
|
||||
|
||||
// RB: replaced QGL with GLEW
|
||||
#if !defined(USE_VULKAN)
|
||||
#include "../../libs/glew/include/GL/wglew.h" // windows OpenGL extensions
|
||||
#endif
|
||||
// RB end
|
||||
|
||||
#include "win_input.h"
|
||||
|
|
Loading…
Reference in a new issue