Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 24 additions & 210 deletions src/engine/renderer/tr_fbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ bool R_CheckFBO( const FBO_t *fbo )
int id;

glGetIntegerv( GL_FRAMEBUFFER_BINDING, &id );
GL_fboShim.glBindFramebuffer( GL_FRAMEBUFFER, fbo->frameBuffer );
GL_fboShim.glBindFramebuffer( GL_DRAW_FRAMEBUFFER, fbo->frameBuffer );

code = GL_fboShim.glCheckFramebufferStatus( GL_FRAMEBUFFER );
code = GL_fboShim.glCheckFramebufferStatus( GL_DRAW_FRAMEBUFFER );

if ( code == GL_FRAMEBUFFER_COMPLETE )
{
GL_fboShim.glBindFramebuffer( GL_FRAMEBUFFER, id );
GL_fboShim.glBindFramebuffer( GL_DRAW_FRAMEBUFFER, id );
return true;
}

Expand Down Expand Up @@ -85,7 +85,7 @@ bool R_CheckFBO( const FBO_t *fbo )
break;
}

GL_fboShim.glBindFramebuffer( GL_FRAMEBUFFER, id );
GL_fboShim.glBindFramebuffer( GL_DRAW_FRAMEBUFFER, id );

return false;
}
Expand All @@ -104,12 +104,12 @@ FBO_t *R_CreateFBO( const char *name, int width, int height )
Sys::Drop( "R_CreateFBO: \"%s\" is too long", name );
}

if ( width <= 0 || width > glConfig.maxRenderbufferSize )
if ( width <= 0 )
{
Sys::Drop( "R_CreateFBO: bad width %i", width );
}

if ( height <= 0 || height > glConfig.maxRenderbufferSize )
if ( height <= 0 )
{
Sys::Drop( "R_CreateFBO: bad height %i", height );
}
Expand All @@ -121,7 +121,6 @@ FBO_t *R_CreateFBO( const char *name, int width, int height )

fbo = tr.fbos[ tr.numFBOs ] = (FBO_t*) ri.Hunk_Alloc( sizeof( *fbo ), ha_pref::h_low );
Q_strncpyz( fbo->name, name, sizeof( fbo->name ) );
fbo->index = tr.numFBOs++;
fbo->width = width;
fbo->height = height;

Expand All @@ -130,157 +129,6 @@ FBO_t *R_CreateFBO( const char *name, int width, int height )
return fbo;
}

/*
================
R_CreateFBOColorBuffer

Framebuffer must be bound
================
*/
void R_CreateFBOColorBuffer( FBO_t *fbo, int format, int index )
{
bool absent;

if ( index < 0 || index >= glConfig.maxColorAttachments )
{
Log::Warn("R_CreateFBOColorBuffer: invalid attachment index %i", index );
return;
}

fbo->colorFormat = format;

absent = fbo->colorBuffers[ index ] == 0;

if ( absent )
{
GL_fboShim.glGenRenderbuffers( 1, &fbo->colorBuffers[ index ] );
}

GL_fboShim.glBindRenderbuffer( GL_RENDERBUFFER, fbo->colorBuffers[ index ] );
GL_fboShim.glRenderbufferStorage( GL_RENDERBUFFER, format, fbo->width, fbo->height );

if ( absent )
{
GL_fboShim.glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_RENDERBUFFER,
fbo->colorBuffers[ index ] );
}

GL_CheckErrors();
}

/*
================
R_CreateFBODepthBuffer
================
*/
void R_CreateFBODepthBuffer( FBO_t *fbo, int format )
{
bool absent;

if ( format != GL_DEPTH_COMPONENT &&
format != GL_DEPTH_COMPONENT16 && format != GL_DEPTH_COMPONENT24 && format != GL_DEPTH_COMPONENT32_ARB )
{
Log::Warn("R_CreateFBODepthBuffer: format %i is not depth-renderable", format );
return;
}

fbo->depthFormat = format;

absent = fbo->depthBuffer == 0;

if ( absent )
{
GL_fboShim.glGenRenderbuffers( 1, &fbo->depthBuffer );
}

GL_fboShim.glBindRenderbuffer( GL_RENDERBUFFER, fbo->depthBuffer );
GL_fboShim.glRenderbufferStorage( GL_RENDERBUFFER, fbo->depthFormat, fbo->width, fbo->height );

if ( absent )
{
GL_fboShim.glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->depthBuffer );
}

GL_CheckErrors();
}

/*
================
R_CreateFBOStencilBuffer
================
*/
void R_CreateFBOStencilBuffer( FBO_t *fbo, int format )
{
bool absent;

if ( format != GL_STENCIL_INDEX &&
format != GL_STENCIL_INDEX1_EXT &&
format != GL_STENCIL_INDEX4_EXT && format != GL_STENCIL_INDEX8_EXT && format != GL_STENCIL_INDEX16_EXT )
{
Log::Warn("R_CreateFBOStencilBuffer: format %i is not stencil-renderable", format );
return;
}

fbo->stencilFormat = format;

absent = fbo->stencilBuffer == 0;

if ( absent )
{
GL_fboShim.glGenRenderbuffers( 1, &fbo->stencilBuffer );
}

GL_fboShim.glBindRenderbuffer( GL_RENDERBUFFER, fbo->stencilBuffer );
GL_fboShim.glRenderbufferStorage( GL_RENDERBUFFER, fbo->stencilFormat, fbo->width, fbo->height );
GL_CheckErrors();

if ( absent )
{
GL_fboShim.glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->stencilBuffer );
}

GL_CheckErrors();
}

/*
================
R_CreateFBOPackedDepthStencilBuffer
================
*/
void R_CreateFBOPackedDepthStencilBuffer( FBO_t *fbo, int format )
{
bool absent;

if ( format != GL_DEPTH_STENCIL && format != GL_DEPTH24_STENCIL8 )
{
Log::Warn("R_CreateFBOPackedDepthStencilBuffer: format %i is not depth-stencil-renderable", format );
return;
}

fbo->packedDepthStencilFormat = format;

absent = fbo->packedDepthStencilBuffer == 0;

if ( absent )
{
GL_fboShim.glGenRenderbuffers( 1, &fbo->packedDepthStencilBuffer );
}

GL_fboShim.glBindRenderbuffer( GL_RENDERBUFFER, fbo->packedDepthStencilBuffer );
GL_fboShim.glRenderbufferStorage( GL_RENDERBUFFER, fbo->packedDepthStencilFormat, fbo->width, fbo->height );
GL_CheckErrors();

if ( absent )
{
GL_fboShim.glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
fbo->packedDepthStencilBuffer );
GL_fboShim.glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
fbo->packedDepthStencilBuffer );
}

GL_CheckErrors();
}

/*
=================
R_AttachFBOTexture1D
Expand All @@ -294,7 +142,7 @@ void R_AttachFBOTexture1D( int texId, int index )
return;
}

glFramebufferTexture1D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_1D, texId, 0 );
GL_fboShim.glFramebufferTexture1D( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_1D, texId, 0 );
}

/*
Expand All @@ -316,7 +164,7 @@ void R_AttachFBOTexture2D( int target, int texId, int index )
return;
}

GL_fboShim.glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, target, texId, 0 );
GL_fboShim.glFramebufferTexture2D( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, target, texId, 0 );
}

/*
Expand All @@ -332,17 +180,7 @@ void R_AttachFBOTexture3D( int texId, int index, int zOffset )
return;
}

glFramebufferTexture3D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_3D, texId, 0, zOffset );
}

/*
=================
R_AttachFBOTextureDepth
=================
*/
void R_AttachFBOTextureDepth( int texId )
{
GL_fboShim.glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texId, 0 );
GL_fboShim.glFramebufferTexture3D( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_3D, texId, 0, zOffset );
}

/*
Expand All @@ -352,8 +190,8 @@ R_AttachFBOTexturePackedDepthStencil
*/
void R_AttachFBOTexturePackedDepthStencil( int texId )
{
GL_fboShim.glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texId, 0 );
GL_fboShim.glFramebufferTexture2D( GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texId, 0 );
GL_fboShim.glFramebufferTexture2D( GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texId, 0 );
GL_fboShim.glFramebufferTexture2D( GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texId, 0 );
}

/*
Expand All @@ -363,18 +201,20 @@ R_BindFBO
*/
void R_BindFBO( FBO_t *fbo )
{
if ( !fbo )
{
R_BindNullFBO();
return;
}
R_BindFBO( GL_DRAW_FRAMEBUFFER, fbo );
}

GLIMP_LOGCOMMENT( "--- R_BindFBO( %s ) ---", fbo->name );
void R_BindFBO( GLenum target, FBO_t *fbo )
{
GLuint handle = fbo == nullptr ? 0 : fbo->frameBuffer;

if ( glState.currentFBO != fbo )
if ( target != GL_DRAW_FRAMEBUFFER )
{
GL_fboShim.glBindFramebuffer( GL_FRAMEBUFFER, fbo->frameBuffer );

GL_fboShim.glBindFramebuffer( target, handle );
}
else if ( glState.currentFBO != fbo )
{
GL_fboShim.glBindFramebuffer( target, handle );
glState.currentFBO = fbo;
}
}
Expand All @@ -386,14 +226,7 @@ R_BindNullFBO
*/
void R_BindNullFBO()
{
GLIMP_LOGCOMMENT( "--- R_BindNullFBO ---" );

if ( glState.currentFBO )
{
GL_fboShim.glBindFramebuffer( GL_FRAMEBUFFER, 0 );
GL_fboShim.glBindRenderbuffer( GL_RENDERBUFFER, 0 );
glState.currentFBO = nullptr;
}
R_BindFBO( nullptr );
}

/*
Expand Down Expand Up @@ -499,35 +332,16 @@ R_ShutdownFBOs
*/
void R_ShutdownFBOs()
{
int i, j;
FBO_t *fbo;

Log::Debug("------- R_ShutdownFBOs -------" );

R_BindNullFBO();

for ( i = 0; i < tr.numFBOs; i++ )
for ( int i = 0; i < tr.numFBOs; i++ )
{
fbo = tr.fbos[ i ];

for ( j = 0; j < glConfig.maxColorAttachments; j++ )
{
if ( fbo->colorBuffers[ j ] )
{
GL_fboShim.glDeleteRenderbuffers( 1, &fbo->colorBuffers[ j ] );
}
}

if ( fbo->depthBuffer )
{
GL_fboShim.glDeleteRenderbuffers( 1, &fbo->depthBuffer );
}

if ( fbo->stencilBuffer )
{
GL_fboShim.glDeleteRenderbuffers( 1, &fbo->stencilBuffer );
}

if ( fbo->frameBuffer )
{
GL_fboShim.glDeleteFramebuffers( 1, &fbo->frameBuffer );
Expand Down
4 changes: 1 addition & 3 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
bound.
*/

GL_fboShim.glBindFramebuffer( GL_FRAMEBUFFER, 0 );
GL_fboShim.glBindRenderbuffer( GL_RENDERBUFFER, 0 );
GL_fboShim.glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
glState.currentFBO = nullptr;

GL_PolygonMode( GL_FRONT_AND_BACK, GL_FILL );
Expand Down Expand Up @@ -949,7 +948,6 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
Log::Notice("GL_TEXTURE_MAX_ANISOTROPY_EXT: %f", glConfig.maxTextureAnisotropy );
}

Log::Notice("GL_MAX_RENDERBUFFER_SIZE: %d", glConfig.maxRenderbufferSize );
Log::Notice("GL_MAX_COLOR_ATTACHMENTS: %d", glConfig.maxColorAttachments );

Log::Notice("PIXELFORMAT: color(%d-bits)", glConfig.colorBits );
Expand Down
Loading