| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* Thanks Roman "Vortex" Marchenko |
| 31 |
*--------------------------------------------------------------------- |
| 32 |
*/ |
| 33 |
|
| 34 |
#ifdef HAVE_CONFIG_H |
| 35 |
#include "config.h" |
| 36 |
#endif |
| 37 |
|
| 38 |
#include "gl_opengl.h" |
| 39 |
|
| 40 |
#include <SDL.h> |
| 41 |
|
| 42 |
#include "gl_intern.h" |
| 43 |
|
| 44 |
#include "i_main.h" |
| 45 |
#include "lprintf.h" |
| 46 |
|
| 47 |
dboolean gl_use_FBO = false; |
| 48 |
|
| 49 |
GLuint glSceneImageFBOTexID = 0; |
| 50 |
GLuint glDepthBufferFBOTexID = 0; |
| 51 |
GLuint glSceneImageTextureFBOTexID = 0; |
| 52 |
int SceneInTexture = false; |
| 53 |
static dboolean gld_CreateScreenSizeFBO(void); |
| 54 |
|
| 55 |
void gld_InitFBO(void) |
| 56 |
{ |
| 57 |
gld_FreeScreenSizeFBO(); |
| 58 |
|
| 59 |
gl_use_FBO = gl_ext_framebuffer_object; |
| 60 |
|
| 61 |
if (gl_use_FBO) |
| 62 |
{ |
| 63 |
if (!gld_CreateScreenSizeFBO()) |
| 64 |
{ |
| 65 |
gld_FreeScreenSizeFBO(); |
| 66 |
gl_use_FBO = false; |
| 67 |
gl_ext_framebuffer_object = false; |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
static dboolean gld_CreateScreenSizeFBO(void) |
| 73 |
{ |
| 74 |
int status = 0; |
| 75 |
GLenum internalFormat; |
| 76 |
dboolean attach_stencil = gl_ext_packed_depth_stencil; |
| 77 |
|
| 78 |
if (!gl_ext_framebuffer_object) |
| 79 |
return false; |
| 80 |
|
| 81 |
GLEXT_glGenFramebuffersEXT(1, &glSceneImageFBOTexID); |
| 82 |
GLEXT_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, glSceneImageFBOTexID); |
| 83 |
|
| 84 |
GLEXT_glGenRenderbuffersEXT(1, &glDepthBufferFBOTexID); |
| 85 |
GLEXT_glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, glDepthBufferFBOTexID); |
| 86 |
|
| 87 |
internalFormat = (attach_stencil ? GL_DEPTH_STENCIL_EXT : GL_DEPTH_COMPONENT); |
| 88 |
GLEXT_glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalFormat, SCREENWIDTH, SCREENHEIGHT); |
| 89 |
|
| 90 |
// attach a renderbuffer to depth attachment point |
| 91 |
GLEXT_glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, glDepthBufferFBOTexID); |
| 92 |
|
| 93 |
if (attach_stencil) |
| 94 |
{ |
| 95 |
// attach a renderbuffer to stencil attachment point |
| 96 |
GLEXT_glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, glDepthBufferFBOTexID); |
| 97 |
} |
| 98 |
|
| 99 |
glGenTextures(1, &glSceneImageTextureFBOTexID); |
| 100 |
glBindTexture(GL_TEXTURE_2D, glSceneImageTextureFBOTexID); |
| 101 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCREENWIDTH, SCREENHEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
| 102 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
| 103 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
| 104 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 105 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 106 |
|
| 107 |
GLEXT_glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, glSceneImageTextureFBOTexID, 0); |
| 108 |
status = GLEXT_glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); |
| 109 |
|
| 110 |
if (status == GL_FRAMEBUFFER_COMPLETE_EXT) |
| 111 |
{ |
| 112 |
GLEXT_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
| 113 |
} |
| 114 |
else |
| 115 |
{ |
| 116 |
lprintf(LO_ERROR, "gld_CreateScreenSizeFBO: Cannot create framebuffer object (error code: %d)\n", status); |
| 117 |
} |
| 118 |
|
| 119 |
return (status == GL_FRAMEBUFFER_COMPLETE_EXT); |
| 120 |
} |
| 121 |
|
| 122 |
void gld_FreeScreenSizeFBO(void) |
| 123 |
{ |
| 124 |
if (!gl_ext_framebuffer_object) |
| 125 |
return; |
| 126 |
|
| 127 |
GLEXT_glDeleteFramebuffersEXT(1, &glSceneImageFBOTexID); |
| 128 |
glSceneImageFBOTexID = 0; |
| 129 |
|
| 130 |
GLEXT_glDeleteRenderbuffersEXT(1, &glDepthBufferFBOTexID); |
| 131 |
glDepthBufferFBOTexID = 0; |
| 132 |
|
| 133 |
glDeleteTextures(1, &glSceneImageTextureFBOTexID); |
| 134 |
glSceneImageTextureFBOTexID = 0; |
| 135 |
} |