UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
r_framebuffer.cpp File Reference

Framebuffer Objects support. More...

#include "r_local.h"
#include "r_framebuffer.h"
#include "r_error.h"

Go to the source code of this file.

Functions

static GLuint R_GetFreeFBOTexture (void)
 
static void R_FreeFBOTexture (int texnum)
 
void R_InitFBObjects (void)
 
void R_DeleteFBObject (r_framebuffer_t *buf)
 Delete framebuffer object along with attached render buffer. More...
 
void R_ShutdownFBObjects (void)
 Delete all registered framebuffer and render buffer objects, clear memory. More...
 
r_framebuffer_tR_CreateFramebuffer (int width, int height, int ntextures, bool depth, bool halfFloat, unsigned int *filters)
 create a new framebuffer object More...
 
void R_ResolveMSAA (const r_framebuffer_t *buf)
 Forces multisample antialiasing resolve on given framebuffer, if needed. More...
 
void R_UseFramebuffer (const r_framebuffer_t *buf)
 bind specified framebuffer object so we render to it More...
 
void R_SetupViewport (r_framebuffer_t *buf, int x, int y, int width, int height)
 Sets the framebuffer dimensions of the viewport. More...
 
void R_UseViewport (const r_framebuffer_t *buf)
 Set the viewport to the dimensions of the given framebuffer. More...
 
void R_DrawBuffers (unsigned int drawBufferNum)
 Activate draw buffer(s) More...
 
void R_BindColorAttachments (unsigned int n, unsigned int *attachments)
 Activate draw buffer(s) More...
 
bool R_EnableRenderbuffer (bool enable)
 Enable the render to the framebuffer. More...
 
bool R_RenderbufferEnabled (void)
 

Variables

static int frameBufferObjectCount
 
static r_framebuffer_t frameBufferObjects [MAX_GL_FRAMEBUFFERS]
 
static GLuint frameBufferTextures [MAX_GL_FRAMEBUFFERS]
 
static r_framebuffer_t screenBuffer
 
static GLenumcolorAttachments
 

Detailed Description

Framebuffer Objects support.

Definition in file r_framebuffer.cpp.

Function Documentation

void R_BindColorAttachments ( unsigned int  n,
unsigned int attachments 
)

Activate draw buffer(s)

Parameters
nThe number of buffers to activate
attachmentsThe buffers we are rendering into
Note
The order of the attachments define the gl_FragData order in the shaders

Definition at line 404 of file r_framebuffer.cpp.

References rstate_s::activeFramebuffer, Com_DPrintf(), DEBUG_RENDERER, rconfig_t::frameBufferObject, rstate_s::frameBufferObjectsInitialized, cvar_s::integer, rconfig_t::maxDrawBuffers, r_framebuffer_t::nTextures, r_config, r_postprocess, r_programs, and r_state.

Referenced by R_DrawBuffers(), and R_UpdateGlowBufferBinding().

r_framebuffer_t* R_CreateFramebuffer ( int  width,
int  height,
int  ntextures,
bool  depth,
bool  halfFloat,
unsigned int filters 
)

create a new framebuffer object

Parameters
[in]widthThe width of the framebuffer
[in]heightThe height of the framebuffer
[in]ntexturesThe amount of textures for this framebuffer. See also the filters array.
[in]depthAlso generate a depth buffer
[in]halfFloatUse half float pixel format
[in]filtersFilters for the textures. Must have ntextures entries
Todo:
also check if we are running on older (SM2.0) hardware, which doesn't support antialiased MRT

Definition at line 175 of file r_framebuffer.cpp.

References rconfig_t::anisotropic, r_framebuffer_t::byteFormat, r_framebuffer_t::clearColor, colorAttachments, Com_Printf(), r_framebuffer_t::depth, r_framebuffer_t::fbo, frameBufferObjectCount, rstate_s::frameBufferObjectsInitialized, GL_CLAMP, GL_DEPTH_ATTACHMENT_EXT, GL_DEPTH_COMPONENT, GL_FRAMEBUFFER_EXT, GL_RENDERBUFFER_EXT, glBindTexture(), glTexImage2D(), r_framebuffer_t::height, i, cvar_s::integer, lengthof, rconfig_t::maxAnisotropic, rconfig_t::maxDrawBuffers, Mem_AllocTypeN, r_framebuffer_t::nTextures, OBJZERO, r_framebuffer_t::pixelFormat, r_framebuffer_t::proxyFBO, R_CheckError, r_config, R_GetFreeFBOTexture(), r_multisample, R_SetupViewport(), r_state, r_framebuffer_t::samples, r_framebuffer_t::textures, Vector4Clear, and r_framebuffer_t::width.

Referenced by R_InitFBObjects().

void R_DeleteFBObject ( r_framebuffer_t buf)

Delete framebuffer object along with attached render buffer.

Definition at line 126 of file r_framebuffer.cpp.

References r_framebuffer_t::depth, r_framebuffer_t::fbo, i, Mem_Free, r_framebuffer_t::nTextures, R_FreeFBOTexture(), and r_framebuffer_t::textures.

Referenced by R_ShutdownFBObjects().

void R_DrawBuffers ( unsigned int  drawBufferNum)

Activate draw buffer(s)

Parameters
[in]drawBufferNumThe number of buffers to activate
Todo:
introduce enum or speaking constants for the buffer numbers that are drawn here and elsewhere

Definition at line 393 of file r_framebuffer.cpp.

References colorAttachments, and R_BindColorAttachments().

Referenced by R_Draw3DGlobe(), R_EnableRenderbuffer(), and R_UpdateGlowBufferBinding().

bool R_EnableRenderbuffer ( bool  enable)

Enable the render to the framebuffer.

Parameters
enableIf true we are enabling the rendering to fbo_render, if false we are rendering to fbo that represents the screen
See also
R_DrawBuffers
Returns
true if the fbo was bound, false if not supported or deactivated

Definition at line 425 of file r_framebuffer.cpp.

References fbo_render, fbo_screen, rconfig_t::frameBufferObject, rstate_s::frameBufferObjectsInitialized, cvar_s::integer, r_config, R_DrawBuffers(), r_postprocess, r_programs, r_state, R_UseFramebuffer(), and rstate_s::renderbuffer_enabled.

Referenced by uiGeoscapeNode::draw(), R_DrawBloom(), R_Setup2D(), and R_Setup3D().

static void R_FreeFBOTexture ( int  texnum)
static

Definition at line 50 of file r_framebuffer.cpp.

References frameBufferTextures, i, and MAX_GL_FRAMEBUFFERS.

Referenced by R_DeleteFBObject().

static GLuint R_GetFreeFBOTexture ( void  )
static
bool R_RenderbufferEnabled ( void  )

Definition at line 443 of file r_framebuffer.cpp.

References r_state, and rstate_s::renderbuffer_enabled.

Referenced by R_DrawBloom().

void R_ResolveMSAA ( const r_framebuffer_t buf)

Forces multisample antialiasing resolve on given framebuffer, if needed.

Parameters
[in]bufthe framebuffer to use

Definition at line 296 of file r_framebuffer.cpp.

References r_framebuffer_t::fbo, GL_COLOR_ATTACHMENT0_EXT, GL_DRAW_FRAMEBUFFER_EXT, GL_FRAMEBUFFER_EXT, GL_READ_FRAMEBUFFER_EXT, r_framebuffer_t::height, i, r_framebuffer_t::nTextures, r_framebuffer_t::proxyFBO, R_CheckError, r_framebuffer_t::samples, and r_framebuffer_t::width.

Referenced by R_DrawBloom().

void R_SetupViewport ( r_framebuffer_t buf,
int  x,
int  y,
int  width,
int  height 
)

Sets the framebuffer dimensions of the viewport.

Parameters
[out]bufThe framebuffer to initialize the viewport for. If nullptr the screen buffer will be taken.
[in]x,yThe position
[in]width,heightThe dimensions
See also
R_UseViewport

Definition at line 362 of file r_framebuffer.cpp.

References r_viewport_t::height, screenBuffer, r_framebuffer_t::viewport, r_viewport_t::width, r_viewport_t::x, and r_viewport_t::y.

Referenced by R_CreateFramebuffer(), and R_InitFBObjects().

void R_ShutdownFBObjects ( void  )

Delete all registered framebuffer and render buffer objects, clear memory.

Definition at line 148 of file r_framebuffer.cpp.

References colorAttachments, frameBufferObjectCount, rstate_s::frameBufferObjectsInitialized, i, Mem_Free, OBJZERO, R_DeleteFBObject(), r_state, and R_UseFramebuffer().

Referenced by R_ReinitOpenglContext(), R_SetMode(), and R_Shutdown().

void R_UseFramebuffer ( const r_framebuffer_t buf)
void R_UseViewport ( const r_framebuffer_t buf)

Set the viewport to the dimensions of the given framebuffer.

Parameters
[out]bufThe framebuffer to set the viewport for. If nullptr the screen buffer will be taken.
See also
R_SetupViewport

Definition at line 378 of file r_framebuffer.cpp.

References rconfig_t::frameBufferObject, rstate_s::frameBufferObjectsInitialized, r_viewport_t::height, cvar_s::integer, r_config, r_postprocess, r_programs, r_state, screenBuffer, r_framebuffer_t::viewport, r_viewport_t::width, r_viewport_t::x, and r_viewport_t::y.

Referenced by R_Blur(), R_BlurStack(), and R_DrawBloom().

Variable Documentation

GLenum* colorAttachments
static
int frameBufferObjectCount
static

Definition at line 29 of file r_framebuffer.cpp.

Referenced by R_CreateFramebuffer(), R_InitFBObjects(), and R_ShutdownFBObjects().

r_framebuffer_t frameBufferObjects[MAX_GL_FRAMEBUFFERS]
static

Definition at line 30 of file r_framebuffer.cpp.

GLuint frameBufferTextures[MAX_GL_FRAMEBUFFERS]
static

Definition at line 31 of file r_framebuffer.cpp.

Referenced by R_FreeFBOTexture(), R_GetFreeFBOTexture(), and R_InitFBObjects().

r_framebuffer_t screenBuffer
static