From: havoc Date: Wed, 2 Nov 2011 09:05:20 +0000 (+0000) Subject: support GL_ARB_framebuffer_object, with GL_EXT_framebuffer_object as fallback, use... X-Git-Tag: xonotic-v0.6.0~163^2~38 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b3c585f8ede96616ebb47beb2986583c41929150;p=xonotic%2Fdarkplaces.git support GL_ARB_framebuffer_object, with GL_EXT_framebuffer_object as fallback, use GL_DEPTH_STENCIL_ATTACHMENT_ARB to fix fbo init errors git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11519 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_backend.c b/gl_backend.c index bfc5c968..c182ad3b 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -1259,24 +1259,75 @@ int R_Mesh_CreateFramebufferObject(rtexture_t *depthtexture, rtexture_t *colorte case RENDERPATH_GL20: case RENDERPATH_GLES1: case RENDERPATH_GLES2: - if (vid.support.ext_framebuffer_object) + if (vid.support.arb_framebuffer_object) + { + int temp; + GLuint status; + qglGenFramebuffers(1, (GLuint*)&temp);CHECKGLERROR + R_Mesh_SetRenderTargets(temp, NULL, NULL, NULL, NULL, NULL); + // GL_ARB_framebuffer_object (GL3-class hardware) - depth stencil attachment + if (depthtexture && depthtexture->texnum ) qglFramebufferTexture2D(GL_FRAMEBUFFER, depthtexture->glisdepthstencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT , depthtexture->gltexturetypeenum , depthtexture->texnum , 0);CHECKGLERROR + if (depthtexture && depthtexture->renderbuffernum ) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, depthtexture->glisdepthstencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER, depthtexture->renderbuffernum );CHECKGLERROR + if (colortexture && colortexture->texnum ) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , colortexture->gltexturetypeenum , colortexture->texnum , 0);CHECKGLERROR + if (colortexture2 && colortexture2->texnum) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 , colortexture2->gltexturetypeenum, colortexture2->texnum, 0);CHECKGLERROR + if (colortexture3 && colortexture3->texnum) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2 , colortexture3->gltexturetypeenum, colortexture3->texnum, 0);CHECKGLERROR + if (colortexture4 && colortexture4->texnum) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3 , colortexture4->gltexturetypeenum, colortexture4->texnum, 0);CHECKGLERROR + if (colortexture && colortexture->renderbuffernum ) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , GL_RENDERBUFFER, colortexture->renderbuffernum );CHECKGLERROR + if (colortexture2 && colortexture2->renderbuffernum) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 , GL_RENDERBUFFER, colortexture2->renderbuffernum);CHECKGLERROR + if (colortexture3 && colortexture3->renderbuffernum) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2 , GL_RENDERBUFFER, colortexture3->renderbuffernum);CHECKGLERROR + if (colortexture4 && colortexture4->renderbuffernum) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3 , GL_RENDERBUFFER, colortexture4->renderbuffernum);CHECKGLERROR + + if (colortexture4 && qglDrawBuffersARB) + { + qglDrawBuffersARB(4, drawbuffers);CHECKGLERROR + qglReadBuffer(GL_NONE);CHECKGLERROR + } + else if (colortexture3 && qglDrawBuffersARB) + { + qglDrawBuffersARB(3, drawbuffers);CHECKGLERROR + qglReadBuffer(GL_NONE);CHECKGLERROR + } + else if (colortexture2 && qglDrawBuffersARB) + { + qglDrawBuffersARB(2, drawbuffers);CHECKGLERROR + qglReadBuffer(GL_NONE);CHECKGLERROR + } + else if (colortexture && qglDrawBuffer) + { + qglDrawBuffer(GL_COLOR_ATTACHMENT0);CHECKGLERROR + qglReadBuffer(GL_COLOR_ATTACHMENT0);CHECKGLERROR + } + else if (qglDrawBuffer) + { + qglDrawBuffer(GL_NONE);CHECKGLERROR + qglReadBuffer(GL_NONE);CHECKGLERROR + } + status = qglCheckFramebufferStatus(GL_FRAMEBUFFER);CHECKGLERROR + if (status != GL_FRAMEBUFFER_COMPLETE) + { + Con_Printf("R_Mesh_CreateFramebufferObject: glCheckFramebufferStatus returned %i\n", status); + qglDeleteFramebuffers(1, (GLuint*)&temp); + temp = 0; + } + return temp; + } + else if (vid.support.ext_framebuffer_object) { int temp; GLuint status; - qglGenFramebuffersEXT(1, (GLuint*)&temp);CHECKGLERROR + qglGenFramebuffers(1, (GLuint*)&temp);CHECKGLERROR R_Mesh_SetRenderTargets(temp, NULL, NULL, NULL, NULL, NULL); - if (depthtexture && depthtexture->texnum ) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT , depthtexture->gltexturetypeenum , depthtexture->texnum , 0);CHECKGLERROR - // if (depthtexture && depthtexture->texnum ) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, depthtexture->gltexturetypeenum , depthtexture->texnum , 0);CHECKGLERROR - if (colortexture && colortexture->texnum ) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , colortexture->gltexturetypeenum , colortexture->texnum , 0);CHECKGLERROR - if (colortexture2 && colortexture2->texnum) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 , colortexture2->gltexturetypeenum, colortexture2->texnum, 0);CHECKGLERROR - if (colortexture3 && colortexture3->texnum) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2 , colortexture3->gltexturetypeenum, colortexture3->texnum, 0);CHECKGLERROR - if (colortexture4 && colortexture4->texnum) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3 , colortexture4->gltexturetypeenum, colortexture4->texnum, 0);CHECKGLERROR - if (depthtexture && depthtexture->renderbuffernum ) qglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER, depthtexture->renderbuffernum );CHECKGLERROR - if (depthtexture && depthtexture->renderbuffernum ) qglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthtexture->renderbuffernum );CHECKGLERROR - if (colortexture && colortexture->renderbuffernum ) qglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , GL_RENDERBUFFER, colortexture->renderbuffernum );CHECKGLERROR - if (colortexture2 && colortexture2->renderbuffernum) qglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 , GL_RENDERBUFFER, colortexture2->renderbuffernum);CHECKGLERROR - if (colortexture3 && colortexture3->renderbuffernum) qglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2 , GL_RENDERBUFFER, colortexture3->renderbuffernum);CHECKGLERROR - if (colortexture4 && colortexture4->renderbuffernum) qglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3 , GL_RENDERBUFFER, colortexture4->renderbuffernum);CHECKGLERROR + // GL_EXT_framebuffer_object (GL2-class hardware) - no depth stencil attachment, let it break stencil + if (depthtexture && depthtexture->texnum ) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT , depthtexture->gltexturetypeenum , depthtexture->texnum , 0);CHECKGLERROR + if (depthtexture && depthtexture->renderbuffernum ) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER, depthtexture->renderbuffernum );CHECKGLERROR + if (colortexture && colortexture->texnum ) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , colortexture->gltexturetypeenum , colortexture->texnum , 0);CHECKGLERROR + if (colortexture2 && colortexture2->texnum) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 , colortexture2->gltexturetypeenum, colortexture2->texnum, 0);CHECKGLERROR + if (colortexture3 && colortexture3->texnum) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2 , colortexture3->gltexturetypeenum, colortexture3->texnum, 0);CHECKGLERROR + if (colortexture4 && colortexture4->texnum) qglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3 , colortexture4->gltexturetypeenum, colortexture4->texnum, 0);CHECKGLERROR + if (colortexture && colortexture->renderbuffernum ) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , GL_RENDERBUFFER, colortexture->renderbuffernum );CHECKGLERROR + if (colortexture2 && colortexture2->renderbuffernum) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 , GL_RENDERBUFFER, colortexture2->renderbuffernum);CHECKGLERROR + if (colortexture3 && colortexture3->renderbuffernum) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2 , GL_RENDERBUFFER, colortexture3->renderbuffernum);CHECKGLERROR + if (colortexture4 && colortexture4->renderbuffernum) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3 , GL_RENDERBUFFER, colortexture4->renderbuffernum);CHECKGLERROR if (colortexture4 && qglDrawBuffersARB) { @@ -1295,7 +1346,7 @@ int R_Mesh_CreateFramebufferObject(rtexture_t *depthtexture, rtexture_t *colorte } else if (colortexture && qglDrawBuffer) { - qglDrawBuffer(drawbuffers[0]);CHECKGLERROR + qglDrawBuffer(GL_COLOR_ATTACHMENT0);CHECKGLERROR qglReadBuffer(GL_COLOR_ATTACHMENT0);CHECKGLERROR } else if (qglDrawBuffer) @@ -1303,11 +1354,11 @@ int R_Mesh_CreateFramebufferObject(rtexture_t *depthtexture, rtexture_t *colorte qglDrawBuffer(GL_NONE);CHECKGLERROR qglReadBuffer(GL_NONE);CHECKGLERROR } - status = qglCheckFramebufferStatusEXT(GL_FRAMEBUFFER);CHECKGLERROR + status = qglCheckFramebufferStatus(GL_FRAMEBUFFER);CHECKGLERROR if (status != GL_FRAMEBUFFER_COMPLETE) { - Con_Printf("R_Mesh_CreateFramebufferObject: glCheckFramebufferStatusEXT returned %i\n", status); - qglDeleteFramebuffersEXT(1, (GLuint*)&temp); + Con_Printf("R_Mesh_CreateFramebufferObject: glCheckFramebufferStatus returned %i\n", status); + qglDeleteFramebuffers(1, (GLuint*)&temp); temp = 0; } return temp; @@ -1333,7 +1384,7 @@ void R_Mesh_DestroyFramebufferObject(int fbo) case RENDERPATH_GLES1: case RENDERPATH_GLES2: if (fbo) - qglDeleteFramebuffersEXT(1, (GLuint*)&fbo); + qglDeleteFramebuffers(1, (GLuint*)&fbo); break; case RENDERPATH_D3D9: case RENDERPATH_D3D10: @@ -1400,7 +1451,7 @@ void R_Mesh_SetRenderTargets(int fbo, rtexture_t *depthtexture, rtexture_t *colo if (gl_state.framebufferobject != fbo) { gl_state.framebufferobject = fbo; - qglBindFramebufferEXT(GL_FRAMEBUFFER, gl_state.framebufferobject ? gl_state.framebufferobject : gl_state.defaultframebufferobject); + qglBindFramebuffer(GL_FRAMEBUFFER, gl_state.framebufferobject ? gl_state.framebufferobject : gl_state.defaultframebufferobject); } break; case RENDERPATH_D3D9: @@ -1558,8 +1609,8 @@ static void GL_Backend_ResetState(void) if (vid.support.ext_framebuffer_object) { - //qglBindRenderbufferEXT(GL_RENDERBUFFER, 0); - qglBindFramebufferEXT(GL_FRAMEBUFFER, 0); + //qglBindRenderbuffer(GL_RENDERBUFFER, 0); + qglBindFramebuffer(GL_FRAMEBUFFER, 0); } qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), NULL);CHECKGLERROR @@ -1570,7 +1621,7 @@ static void GL_Backend_ResetState(void) qglColor4f(1, 1, 1, 1);CHECKGLERROR if (vid.support.ext_framebuffer_object) - qglBindFramebufferEXT(GL_FRAMEBUFFER, gl_state.framebufferobject); + qglBindFramebuffer(GL_FRAMEBUFFER, gl_state.framebufferobject); gl_state.unit = MAX_TEXTUREUNITS; gl_state.clientunit = MAX_TEXTUREUNITS; @@ -1629,7 +1680,7 @@ static void GL_Backend_ResetState(void) qglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0); } if (vid.support.ext_framebuffer_object) - qglBindFramebufferEXT(GL_FRAMEBUFFER, gl_state.defaultframebufferobject); + qglBindFramebuffer(GL_FRAMEBUFFER, gl_state.defaultframebufferobject); qglEnableVertexAttribArray(GLSLATTRIB_POSITION); qglVertexAttribPointer(GLSLATTRIB_POSITION, 3, GL_FLOAT, false, sizeof(float[3]), NULL);CHECKGLERROR qglDisableVertexAttribArray(GLSLATTRIB_COLOR); diff --git a/gl_textures.c b/gl_textures.c index 37c135ed..3ce6755b 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -175,6 +175,7 @@ typedef struct gltexture_s int texnum; // GL texture slot number int renderbuffernum; // GL renderbuffer slot number qboolean dirty; // indicates that R_RealGetTexture should be called + qboolean glisdepthstencil; // indicates that FBO attachment has to be GL_DEPTH_STENCIL_ATTACHMENT int gltexturetypeenum; // used by R_Mesh_TexBind // d3d stuff the backend needs void *d3dtexture; @@ -370,7 +371,7 @@ void R_FreeTexture(rtexture_t *rt) if (glt->renderbuffernum) { CHECKGLERROR - qglDeleteRenderbuffersEXT(1, (GLuint *)&glt->renderbuffernum);CHECKGLERROR + qglDeleteRenderbuffers(1, (GLuint *)&glt->renderbuffernum);CHECKGLERROR } break; case RENDERPATH_D3D9: @@ -1758,6 +1759,7 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden glt->sides = glt->texturetype == GLTEXTURETYPE_CUBEMAP ? 6 : 1; glt->texnum = 0; glt->dirty = false; + glt->glisdepthstencil = false; glt->gltexturetypeenum = gltexturetypeenums[glt->texturetype]; // init the dynamic texture attributes, too [11/22/2007 Black] glt->updatecallback = NULL; @@ -1929,6 +1931,7 @@ rtexture_t *R_LoadTextureRenderBuffer(rtexturepool_t *rtexturepool, const char * glt->sides = glt->texturetype == GLTEXTURETYPE_CUBEMAP ? 6 : 1; glt->texnum = 0; glt->dirty = false; + glt->glisdepthstencil = glt->texturetype == TEXTYPE_DEPTHBUFFER24STENCIL8; glt->gltexturetypeenum = gltexturetypeenums[glt->texturetype]; // init the dynamic texture attributes, too [11/22/2007 Black] glt->updatecallback = NULL; @@ -1946,11 +1949,11 @@ rtexture_t *R_LoadTextureRenderBuffer(rtexturepool_t *rtexturepool, const char * case RENDERPATH_GLES1: case RENDERPATH_GLES2: CHECKGLERROR - qglGenRenderbuffersEXT(1, (GLuint *)&glt->renderbuffernum);CHECKGLERROR - qglBindRenderbufferEXT(GL_RENDERBUFFER, glt->renderbuffernum);CHECKGLERROR - qglRenderbufferStorageEXT(GL_RENDERBUFFER, glt->glinternalformat, glt->tilewidth, glt->tileheight);CHECKGLERROR + qglGenRenderbuffers(1, (GLuint *)&glt->renderbuffernum);CHECKGLERROR + qglBindRenderbuffer(GL_RENDERBUFFER, glt->renderbuffernum);CHECKGLERROR + qglRenderbufferStorage(GL_RENDERBUFFER, glt->glinternalformat, glt->tilewidth, glt->tileheight);CHECKGLERROR // note we can query the renderbuffer for info with glGetRenderbufferParameteriv for GL_WIDTH, GL_HEIGHt, GL_RED_SIZE, GL_GREEN_SIZE, GL_BLUE_SIZE, GL_GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_INTERNAL_FORMAT - qglBindRenderbufferEXT(GL_RENDERBUFFER, 0);CHECKGLERROR + qglBindRenderbuffer(GL_RENDERBUFFER, 0);CHECKGLERROR break; case RENDERPATH_D3D9: #ifdef SUPPORTD3D diff --git a/glquake.h b/glquake.h index ba27242e..9686dc59 100644 --- a/glquake.h +++ b/glquake.h @@ -519,77 +519,104 @@ extern GLboolean (GLAPIENTRY *qglUnmapBufferARB) (GLenum target); extern void (GLAPIENTRY *qglBufferDataARB) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); extern void (GLAPIENTRY *qglBufferSubDataARB) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); -//GL_EXT_framebuffer_object +//GL_ARB_framebuffer_object +// (slight differences from GL_EXT_framebuffer_object as this integrates GL_EXT_packed_depth_stencil) #ifndef GL_FRAMEBUFFER -#define GL_FRAMEBUFFER 0x8D40 -#define GL_RENDERBUFFER 0x8D41 -#define GL_STENCIL_INDEX1 0x8D46 -#define GL_STENCIL_INDEX4 0x8D47 -#define GL_STENCIL_INDEX8 0x8D48 -#define GL_STENCIL_INDEX16 0x8D49 -#define GL_RENDERBUFFER_WIDTH 0x8D42 -#define GL_RENDERBUFFER_HEIGHT 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 -#define GL_RENDERBUFFER_RED_SIZE 0x8D50 -#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 -#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 -#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 -#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 -#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_RENDERBUFFER 0x8D41 +#define GL_STENCIL_INDEX1 0x8D46 +#define GL_STENCIL_INDEX4 0x8D47 +#define GL_STENCIL_INDEX8 0x8D48 +#define GL_STENCIL_INDEX16 0x8D49 +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 +#define GL_RENDERBUFFER_SAMPLES 0x8CAB #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET 0x8CD4 -#define GL_COLOR_ATTACHMENT0 0x8CE0 -#define GL_COLOR_ATTACHMENT1 0x8CE1 -#define GL_COLOR_ATTACHMENT2 0x8CE2 -#define GL_COLOR_ATTACHMENT3 0x8CE3 -#define GL_COLOR_ATTACHMENT4 0x8CE4 -#define GL_COLOR_ATTACHMENT5 0x8CE5 -#define GL_COLOR_ATTACHMENT6 0x8CE6 -#define GL_COLOR_ATTACHMENT7 0x8CE7 -#define GL_COLOR_ATTACHMENT8 0x8CE8 -#define GL_COLOR_ATTACHMENT9 0x8CE9 -#define GL_COLOR_ATTACHMENT10 0x8CEA -#define GL_COLOR_ATTACHMENT11 0x8CEB -#define GL_COLOR_ATTACHMENT12 0x8CEC -#define GL_COLOR_ATTACHMENT13 0x8CED -#define GL_COLOR_ATTACHMENT14 0x8CEE -#define GL_COLOR_ATTACHMENT15 0x8CEF -#define GL_DEPTH_ATTACHMENT 0x8D00 -#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_SRGB 0x8C40 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_INDEX 0x8222 +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_MAX_SAMPLES 0x8D57 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5 #define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 -#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 -#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS 0x8CDA #define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB #define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC #define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD -#define GL_FRAMEBUFFER_BINDING 0x8CA6 -#define GL_RENDERBUFFER_BINDING 0x8CA7 -#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF -#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 -#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_FRAMEBUFFER_BINDING 0x8CA6 // alias DRAW_FRAMEBUFFER_BINDING +#define GL_DRAW_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE 0x88F1 #endif -extern GLboolean (GLAPIENTRY *qglIsRenderbufferEXT)(GLuint renderbuffer); -extern void (GLAPIENTRY *qglBindRenderbufferEXT)(GLenum target, GLuint renderbuffer); -extern void (GLAPIENTRY *qglDeleteRenderbuffersEXT)(GLsizei n, const GLuint *renderbuffers); -extern void (GLAPIENTRY *qglGenRenderbuffersEXT)(GLsizei n, GLuint *renderbuffers); -extern void (GLAPIENTRY *qglRenderbufferStorageEXT)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -extern void (GLAPIENTRY *qglGetRenderbufferParameterivEXT)(GLenum target, GLenum pname, GLint *params); -extern GLboolean (GLAPIENTRY *qglIsFramebufferEXT)(GLuint framebuffer); -extern void (GLAPIENTRY *qglBindFramebufferEXT)(GLenum target, GLuint framebuffer); -extern void (GLAPIENTRY *qglDeleteFramebuffersEXT)(GLsizei n, const GLuint *framebuffers); -extern void (GLAPIENTRY *qglGenFramebuffersEXT)(GLsizei n, GLuint *framebuffers); -extern GLenum (GLAPIENTRY *qglCheckFramebufferStatusEXT)(GLenum target); -//extern void (GLAPIENTRY *qglFramebufferTexture1DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -extern void (GLAPIENTRY *qglFramebufferTexture2DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -extern void (GLAPIENTRY *qglFramebufferTexture3DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -extern void (GLAPIENTRY *qglFramebufferRenderbufferEXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -extern void (GLAPIENTRY *qglGetFramebufferAttachmentParameterivEXT)(GLenum target, GLenum attachment, GLenum pname, GLint *params); -extern void (GLAPIENTRY *qglGenerateMipmapEXT)(GLenum target); +extern GLboolean (GLAPIENTRY *qglIsRenderbuffer)(GLuint renderbuffer); +extern GLvoid (GLAPIENTRY *qglBindRenderbuffer)(GLenum target, GLuint renderbuffer); +extern GLvoid (GLAPIENTRY *qglDeleteRenderbuffers)(GLsizei n, const GLuint *renderbuffers); +extern GLvoid (GLAPIENTRY *qglGenRenderbuffers)(GLsizei n, GLuint *renderbuffers); +extern GLvoid (GLAPIENTRY *qglRenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +extern GLvoid (GLAPIENTRY *qglRenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +extern GLvoid (GLAPIENTRY *qglGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint *params); +extern GLboolean (GLAPIENTRY *qglIsFramebuffer)(GLuint framebuffer); +extern GLvoid (GLAPIENTRY *qglBindFramebuffer)(GLenum target, GLuint framebuffer); +extern GLvoid (GLAPIENTRY *qglDeleteFramebuffers)(GLsizei n, const GLuint *framebuffers); +extern GLvoid (GLAPIENTRY *qglGenFramebuffers)(GLsizei n, GLuint *framebuffers); +extern GLenum (GLAPIENTRY *qglCheckFramebufferStatus)(GLenum target); +extern GLvoid (GLAPIENTRY *qglFramebufferTexture1D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +extern GLvoid (GLAPIENTRY *qglFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +extern GLvoid (GLAPIENTRY *qglFramebufferTexture3D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer); +extern GLvoid (GLAPIENTRY *qglFramebufferTextureLayer)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +extern GLvoid (GLAPIENTRY *qglFramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +extern GLvoid (GLAPIENTRY *qglGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment, GLenum pname, GLint *params); +extern GLvoid (GLAPIENTRY *qglBlitFramebuffer)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +extern GLvoid (GLAPIENTRY *qglGenerateMipmap)(GLenum target); // GL_ARB_draw_buffers #ifndef GL_MAX_DRAW_BUFFERS_ARB @@ -1113,8 +1140,8 @@ void GL_PrintError(int errornumber, const char *filename, int linenumber); //#define qglEndQueryARB glEndQuery #define qglFinish glFinish #define qglFlush glFlush -#define qglFramebufferRenderbufferEXT glFramebufferRenderbuffer -#define qglFramebufferTexture2DEXT glFramebufferTexture2D +#define qglFramebufferRenderbuffer glFramebufferRenderbuffer +#define qglFramebufferTexture2D glFramebufferTexture2D #define qglFramebufferTexture3DEXT glFramebufferTexture3D #define qglGenBuffersARB glGenBuffers #define qglGenFramebuffersEXT glGenFramebuffers diff --git a/r_textures.h b/r_textures.h index a79b607c..594fcad2 100644 --- a/r_textures.h +++ b/r_textures.h @@ -111,6 +111,7 @@ typedef struct rtexture_s int texnum; // GL texture slot number int renderbuffernum; // GL renderbuffer slot number qboolean dirty; // indicates that R_RealGetTexture should be called + qboolean glisdepthstencil; // indicates that FBO attachment has to be GL_DEPTH_STENCIL_ATTACHMENT int gltexturetypeenum; // used by R_Mesh_TexBind // d3d stuff the backend needs void *d3dtexture; diff --git a/vid.h b/vid.h index 0bca4c0a..bceb210b 100644 --- a/vid.h +++ b/vid.h @@ -49,6 +49,7 @@ typedef struct viddef_support_s qboolean amd_texture_texture4; qboolean arb_depth_texture; qboolean arb_draw_buffers; + qboolean arb_framebuffer_object; qboolean arb_multitexture; qboolean arb_occlusion_query; qboolean arb_shadow; diff --git a/vid_shared.c b/vid_shared.c index 85d3ec37..9f24869d 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -465,24 +465,27 @@ GLboolean (GLAPIENTRY *qglUnmapBufferARB) (GLenum target); void (GLAPIENTRY *qglBufferDataARB) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); void (GLAPIENTRY *qglBufferSubDataARB) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); -//GL_EXT_framebuffer_object -GLboolean (GLAPIENTRY *qglIsRenderbufferEXT)(GLuint renderbuffer); -void (GLAPIENTRY *qglBindRenderbufferEXT)(GLenum target, GLuint renderbuffer); -void (GLAPIENTRY *qglDeleteRenderbuffersEXT)(GLsizei n, const GLuint *renderbuffers); -void (GLAPIENTRY *qglGenRenderbuffersEXT)(GLsizei n, GLuint *renderbuffers); -void (GLAPIENTRY *qglRenderbufferStorageEXT)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -void (GLAPIENTRY *qglGetRenderbufferParameterivEXT)(GLenum target, GLenum pname, GLint *params); -GLboolean (GLAPIENTRY *qglIsFramebufferEXT)(GLuint framebuffer); -void (GLAPIENTRY *qglBindFramebufferEXT)(GLenum target, GLuint framebuffer); -void (GLAPIENTRY *qglDeleteFramebuffersEXT)(GLsizei n, const GLuint *framebuffers); -void (GLAPIENTRY *qglGenFramebuffersEXT)(GLsizei n, GLuint *framebuffers); -GLenum (GLAPIENTRY *qglCheckFramebufferStatusEXT)(GLenum target); -//void (GLAPIENTRY *qglFramebufferTexture1DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -void (GLAPIENTRY *qglFramebufferTexture2DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -void (GLAPIENTRY *qglFramebufferTexture3DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -void (GLAPIENTRY *qglFramebufferRenderbufferEXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -void (GLAPIENTRY *qglGetFramebufferAttachmentParameterivEXT)(GLenum target, GLenum attachment, GLenum pname, GLint *params); -void (GLAPIENTRY *qglGenerateMipmapEXT)(GLenum target); +//GL_ARB_framebuffer_object +GLboolean (GLAPIENTRY *qglIsRenderbuffer)(GLuint renderbuffer); +GLvoid (GLAPIENTRY *qglBindRenderbuffer)(GLenum target, GLuint renderbuffer); +GLvoid (GLAPIENTRY *qglDeleteRenderbuffers)(GLsizei n, const GLuint *renderbuffers); +GLvoid (GLAPIENTRY *qglGenRenderbuffers)(GLsizei n, GLuint *renderbuffers); +GLvoid (GLAPIENTRY *qglRenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLvoid (GLAPIENTRY *qglRenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLvoid (GLAPIENTRY *qglGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint *params); +GLboolean (GLAPIENTRY *qglIsFramebuffer)(GLuint framebuffer); +GLvoid (GLAPIENTRY *qglBindFramebuffer)(GLenum target, GLuint framebuffer); +GLvoid (GLAPIENTRY *qglDeleteFramebuffers)(GLsizei n, const GLuint *framebuffers); +GLvoid (GLAPIENTRY *qglGenFramebuffers)(GLsizei n, GLuint *framebuffers); +GLenum (GLAPIENTRY *qglCheckFramebufferStatus)(GLenum target); +GLvoid (GLAPIENTRY *qglFramebufferTexture1D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLvoid (GLAPIENTRY *qglFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLvoid (GLAPIENTRY *qglFramebufferTexture3D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer); +GLvoid (GLAPIENTRY *qglFramebufferTextureLayer)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLvoid (GLAPIENTRY *qglFramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLvoid (GLAPIENTRY *qglGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLvoid (GLAPIENTRY *qglBlitFramebuffer)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLvoid (GLAPIENTRY *qglGenerateMipmap)(GLenum target); void (GLAPIENTRY *qglDrawBuffersARB)(GLsizei n, const GLenum *bufs); @@ -862,25 +865,50 @@ static dllfunction_t vbofuncs[] = {NULL, NULL} }; -static dllfunction_t fbofuncs[] = +static dllfunction_t arbfbofuncs[] = { - {"glIsRenderbufferEXT" , (void **) &qglIsRenderbufferEXT}, - {"glBindRenderbufferEXT" , (void **) &qglBindRenderbufferEXT}, - {"glDeleteRenderbuffersEXT" , (void **) &qglDeleteRenderbuffersEXT}, - {"glGenRenderbuffersEXT" , (void **) &qglGenRenderbuffersEXT}, - {"glRenderbufferStorageEXT" , (void **) &qglRenderbufferStorageEXT}, - {"glGetRenderbufferParameterivEXT" , (void **) &qglGetRenderbufferParameterivEXT}, - {"glIsFramebufferEXT" , (void **) &qglIsFramebufferEXT}, - {"glBindFramebufferEXT" , (void **) &qglBindFramebufferEXT}, - {"glDeleteFramebuffersEXT" , (void **) &qglDeleteFramebuffersEXT}, - {"glGenFramebuffersEXT" , (void **) &qglGenFramebuffersEXT}, - {"glCheckFramebufferStatusEXT" , (void **) &qglCheckFramebufferStatusEXT}, -// {"glFramebufferTexture1DEXT" , (void **) &qglFramebufferTexture1DEXT}, - {"glFramebufferTexture2DEXT" , (void **) &qglFramebufferTexture2DEXT}, - {"glFramebufferTexture3DEXT" , (void **) &qglFramebufferTexture3DEXT}, - {"glFramebufferRenderbufferEXT" , (void **) &qglFramebufferRenderbufferEXT}, - {"glGetFramebufferAttachmentParameterivEXT" , (void **) &qglGetFramebufferAttachmentParameterivEXT}, - {"glGenerateMipmapEXT" , (void **) &qglGenerateMipmapEXT}, + {"glIsRenderbufferARB" , (void **) &qglIsRenderbuffer}, + {"glBindRenderbufferARB" , (void **) &qglBindRenderbuffer}, + {"glDeleteRenderbuffersARB" , (void **) &qglDeleteRenderbuffers}, + {"glGenRenderbuffersARB" , (void **) &qglGenRenderbuffers}, + {"glRenderbufferStorageARB" , (void **) &qglRenderbufferStorage}, + {"glRenderbufferStorageMultisampleARB" , (void **) &qglRenderbufferStorageMultisample}, // not in GL_EXT_framebuffer_object + {"glGetRenderbufferParameterivARB" , (void **) &qglGetRenderbufferParameteriv}, + {"glIsFramebufferARB" , (void **) &qglIsFramebuffer}, + {"glBindFramebufferARB" , (void **) &qglBindFramebuffer}, + {"glDeleteFramebuffersARB" , (void **) &qglDeleteFramebuffers}, + {"glGenFramebuffersARB" , (void **) &qglGenFramebuffers}, + {"glCheckFramebufferStatusARB" , (void **) &qglCheckFramebufferStatus}, + {"glFramebufferTexture1DARB" , (void **) &qglFramebufferTexture1D}, + {"glFramebufferTexture2DARB" , (void **) &qglFramebufferTexture2D}, + {"glFramebufferTexture3DARB" , (void **) &qglFramebufferTexture3D}, + {"glFramebufferTextureLayerARB" , (void **) &qglFramebufferTextureLayer}, // not in GL_EXT_framebuffer_object + {"glFramebufferRenderbufferARB" , (void **) &qglFramebufferRenderbuffer}, + {"glGetFramebufferAttachmentParameterivARB" , (void **) &qglGetFramebufferAttachmentParameteriv}, + {"glBlitFramebufferARB" , (void **) &qglBlitFramebuffer}, // not in GL_EXT_framebuffer_object + {"glGenerateMipmapARB" , (void **) &qglGenerateMipmap}, + {NULL, NULL} +}; + +static dllfunction_t extfbofuncs[] = +{ + {"glIsRenderbufferEXT" , (void **) &qglIsRenderbuffer}, + {"glBindRenderbufferEXT" , (void **) &qglBindRenderbuffer}, + {"glDeleteRenderbuffersEXT" , (void **) &qglDeleteRenderbuffers}, + {"glGenRenderbuffersEXT" , (void **) &qglGenRenderbuffers}, + {"glRenderbufferStorageEXT" , (void **) &qglRenderbufferStorage}, + {"glGetRenderbufferParameterivEXT" , (void **) &qglGetRenderbufferParameteriv}, + {"glIsFramebufferEXT" , (void **) &qglIsFramebuffer}, + {"glBindFramebufferEXT" , (void **) &qglBindFramebuffer}, + {"glDeleteFramebuffersEXT" , (void **) &qglDeleteFramebuffers}, + {"glGenFramebuffersEXT" , (void **) &qglGenFramebuffers}, + {"glCheckFramebufferStatusEXT" , (void **) &qglCheckFramebufferStatus}, + {"glFramebufferTexture1DEXT" , (void **) &qglFramebufferTexture1D}, + {"glFramebufferTexture2DEXT" , (void **) &qglFramebufferTexture2D}, + {"glFramebufferTexture3DEXT" , (void **) &qglFramebufferTexture3D}, + {"glFramebufferRenderbufferEXT" , (void **) &qglFramebufferRenderbuffer}, + {"glGetFramebufferAttachmentParameterivEXT" , (void **) &qglGetFramebufferAttachmentParameteriv}, + {"glGenerateMipmapEXT" , (void **) &qglGenerateMipmap}, {NULL, NULL} }; @@ -951,7 +979,7 @@ void VID_ClearExtensions(void) qglFlush = NULL; qglActiveTexture = NULL; qglGetCompressedTexImageARB = NULL; - qglFramebufferTexture2DEXT = NULL; + qglFramebufferTexture2D = NULL; qglDrawBuffersARB = NULL; #endif } @@ -1005,7 +1033,11 @@ void VID_CheckExtensions(void) vid.support.ext_blend_minmax = GL_CheckExtension("GL_EXT_blend_minmax", blendequationfuncs, "-noblendminmax", false); vid.support.ext_blend_subtract = GL_CheckExtension("GL_EXT_blend_subtract", blendequationfuncs, "-noblendsubtract", false); vid.support.ext_draw_range_elements = GL_CheckExtension("drawrangeelements", drawrangeelementsfuncs, "-nodrawrangeelements", true) || GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false); - vid.support.ext_framebuffer_object = GL_CheckExtension("GL_EXT_framebuffer_object", fbofuncs, "-nofbo", false); + vid.support.arb_framebuffer_object = GL_CheckExtension("GL_ARB_framebuffer_object", arbfbofuncs, "-nofbo", false); + if (vid.support.arb_framebuffer_object) + vid.support.ext_framebuffer_object = true; + else + vid.support.ext_framebuffer_object = GL_CheckExtension("GL_EXT_framebuffer_object", extfbofuncs, "-nofbo", false); vid.support.ext_packed_depth_stencil = GL_CheckExtension("GL_EXT_packed_depth_stencil", NULL, "-nopackeddepthstencil", false); vid.support.ext_stencil_two_side = GL_CheckExtension("GL_EXT_stencil_two_side", stenciltwosidefuncs, "-nostenciltwoside", false); vid.support.ext_texture_3d = GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);