74 r_state.frameBufferObjectsInitialized =
true;
98 unsigned int filters[2];
99 filters[0] = GL_NEAREST;
100 filters[1] = GL_LINEAR_MIPMAP_LINEAR;
109 filters[0] = GL_LINEAR;
112 const int h = (
int)((
float)
viddef.context.height / scales[
i]);
113 const int w = (
int)((
float)
viddef.context.width / scales[
i]);
129 qglDeleteRenderbuffersEXT(1, &
buf->depth);
133 for (
int i = 0;
i <
buf->nTextures;
i++)
140 qglDeleteFramebuffersEXT(1, &
buf->fbo);
150 if (!
r_state.frameBufferObjectsInitialized)
160 r_state.frameBufferObjectsInitialized =
false;
180 if (!
r_state.frameBufferObjectsInitialized) {
181 Com_Printf(
"Warning: framebuffer creation failed; framebuffers not initialized!\n");
186 Com_Printf(
"Warning: framebuffer creation failed; already created too many framebuffers!\n");
193 if (ntextures >
r_config.maxDrawBuffers) {
194 Com_Printf(
"Couldn't allocate requested number of drawBuffers in R_SetupFramebuffer!\n");
195 ntextures =
r_config.maxDrawBuffers;
201 buf->height = height;
204 buf->nTextures = ntextures;
207#ifdef GL_VERSION_ES_CM_1_0
208 buf->pixelFormat = GL_RGBA;
209 buf->byteFormat = GL_UNSIGNED_BYTE;
211 buf->pixelFormat = halfFloat ? GL_RGBA16F_ARB : GL_RGBA8;
212 buf->byteFormat = halfFloat ? GL_HALF_FLOAT_ARB : GL_UNSIGNED_BYTE;
218 if (qglRenderbufferStorageMultisampleEXT && qglBlitFramebuffer) {
221 buf->samples = samples;
225 for (
i = 0;
i <
buf->nTextures;
i++) {
230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filters[
i]);
231 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
232 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP);
233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP);
234 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
235 qglGenerateMipmapEXT(GL_TEXTURE_2D);
237 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
r_config.maxAnisotropic);
244 qglGenFramebuffersEXT(1, &
buf->fbo);
250 qglGenRenderbuffersEXT(1, &
buf->depth);
264 for (
i = 0;
i <
buf->nTextures;
i++) {
265 unsigned colorbuffer;
266 qglGenRenderbuffersEXT(1, &colorbuffer);
273 qglGenFramebuffersEXT(1, &
buf->proxyFBO);
279 for (
i = 0;
i <
buf->nTextures;
i++) {
303 for (
int i = 0;
i <
buf->nTextures;
i++) {
304#ifndef GL_VERSION_ES_CM_1_0
308 qglBlitFramebuffer(0, 0,
buf->width,
buf-> height, 0, 0,
buf->width,
buf->height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
328 if (!
r_state.frameBufferObjectsInitialized) {
329 Com_Printf(
"Can't bind framebuffer: framebuffers not initialized\n");
344 if (
buf->nTextures > 0)
347 glClearColor(
r_state.activeFramebuffer->clearColor[0],
r_state.activeFramebuffer->clearColor[1],
r_state.activeFramebuffer->clearColor[2],
r_state.activeFramebuffer->clearColor[3]);
348 glClear(GL_COLOR_BUFFER_BIT | (
buf->depth ? GL_DEPTH_BUFFER_BIT : 0));
369 buf->viewport.width = width;
370 buf->viewport.height = height;
385 glViewport(
buf->viewport.x,
buf->viewport.y,
buf->viewport.width,
buf->viewport.height);
414 if (
r_state.activeFramebuffer &&
r_state.activeFramebuffer->nTextures > 0)
415 qglDrawBuffers(n, attachments);
430 if (enable !=
r_state.renderbuffer_enabled) {
431 r_state.renderbuffer_enabled = enable;
445 return r_state.renderbuffer_enabled;
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
void Com_Error(int code, const char *fmt,...)
void Com_Printf(const char *const fmt,...)
void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *texels)
void glGenTextures(GLsizei n, GLuint *textures)
void glBindTexture(GLenum target, GLuint id)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
#define Mem_AllocTypeN(type, n)
void R_BindColorAttachments(unsigned int n, unsigned int *attachments)
Activate draw buffer(s).
static GLuint frameBufferTextures[MAX_GL_FRAMEBUFFERS]
void R_InitFBObjects(void)
void R_UseFramebuffer(const r_framebuffer_t *buf)
bind specified framebuffer object so we render to it
bool R_EnableRenderbuffer(bool enable)
Enable the render to the framebuffer.
void R_UseViewport(const r_framebuffer_t *buf)
Set the viewport to the dimensions of the given framebuffer.
static void R_FreeFBOTexture(int texnum)
void R_DrawBuffers(unsigned int drawBufferNum)
Activate draw buffer(s).
static int frameBufferObjectCount
void R_ResolveMSAA(const r_framebuffer_t *buf)
Forces multisample antialiasing resolve on given framebuffer, if needed.
static GLuint R_GetFreeFBOTexture(void)
void R_SetupViewport(r_framebuffer_t *buf, int x, int y, int width, int height)
Sets the framebuffer dimensions of the viewport.
void R_ShutdownFBObjects(void)
Delete all registered framebuffer and render buffer objects, clear memory.
void R_DeleteFBObject(r_framebuffer_t *buf)
Delete framebuffer object along with attached render buffer.
static r_framebuffer_t screenBuffer
r_framebuffer_t * R_CreateFramebuffer(int width, int height, int ntextures, bool depth, bool halfFloat, unsigned int *filters)
create a new framebuffer object
static r_framebuffer_t frameBufferObjects[MAX_GL_FRAMEBUFFERS]
static GLenum * colorAttachments
bool R_RenderbufferEnabled(void)
#define GL_READ_FRAMEBUFFER_EXT
#define GL_DRAW_FRAMEBUFFER_EXT
QGL_EXTERN const GLuint *QGL_EXTERN GLuint *QGL_EXTERN GLenum
#define GL_DEPTH_ATTACHMENT_EXT
#define GL_COLOR_ATTACHMENT0_EXT
#define GL_DEPTH_COMPONENT
#define GL_RENDERBUFFER_EXT
#define GL_FRAMEBUFFER_EXT
#define MAX_GL_FRAMEBUFFERS
local graphics definitions
#define DOWNSAMPLE_PASSES