diff options
Diffstat (limited to 'progs')
-rw-r--r-- | progs/demos/Makefile | 7 | ||||
-rw-r--r-- | progs/demos/fbotexture.c | 108 | ||||
-rw-r--r-- | progs/util/extfuncs.h | 81 |
3 files changed, 158 insertions, 38 deletions
diff --git a/progs/demos/Makefile b/progs/demos/Makefile index c17595ec794..65fdbaaad8e 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -145,6 +145,13 @@ engine.o: engine.c trackball.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) engine.c +fbotexture: fbotexture.o + $(APP_CC) $(CFLAGS) $(LDFLAGS) fbotexture.o $(LIBS) -o $@ + +fbotexture.o: fbotexture.c extfuncs.h + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) fbotexture.c + + fslight: fslight.o $(APP_CC) $(CFLAGS) $(LDFLAGS) fslight.o $(LIBS) -o $@ diff --git a/progs/demos/fbotexture.c b/progs/demos/fbotexture.c index 50a4b00afce..3b36f755a04 100644 --- a/progs/demos/fbotexture.c +++ b/progs/demos/fbotexture.c @@ -9,13 +9,13 @@ */ -#include <GL/glew.h> #include <GL/glut.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> +#include "extfuncs.h" /* For debug */ #define DEPTH 1 @@ -80,9 +80,9 @@ RenderTexture(void) glTranslatef(0.0, 0.0, -15.0); /* draw to texture image */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, MyFB); - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + status = glCheckFramebufferStatus_func(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { printf("Framebuffer incomplete!!!\n"); } @@ -171,7 +171,7 @@ RenderTexture(void) #if DRAW /* Bind normal framebuffer */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, 0); #endif CheckError(__LINE__); @@ -252,12 +252,12 @@ static void CleanUp(void) { #if DEPTH - glDeleteRenderbuffersEXT(1, &DepthRB); + glDeleteRenderbuffers_func(1, &DepthRB); #endif #if STENCIL - glDeleteRenderbuffersEXT(1, &StencilRB); + glDeleteRenderbuffers_func(1, &StencilRB); #endif - glDeleteFramebuffersEXT(1, &MyFB); + glDeleteFramebuffers_func(1, &MyFB); glDeleteTextures(1, &TexObj); @@ -318,14 +318,14 @@ AttachDepthAndStencilBuffers(GLuint fbo, *depthRbOut = *stencilRbOut = 0; - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, fbo); if (tryDepthStencil) { GLuint rb; - glGenRenderbuffersEXT(1, &rb); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, + glGenRenderbuffers_func(1, &rb); + glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, rb); + glRenderbufferStorage_func(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, width, height); if (glGetError()) @@ -333,7 +333,7 @@ AttachDepthAndStencilBuffers(GLuint fbo, if (bindDepthStencil) { /* attach to both depth and stencil at once */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, rb); if (glGetError()) @@ -341,21 +341,21 @@ AttachDepthAndStencilBuffers(GLuint fbo, } else { /* attach to depth attachment point */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb); if (glGetError()) return GL_FALSE; /* and attach to stencil attachment point */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb); if (glGetError()) return GL_FALSE; } - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + status = glCheckFramebufferStatus_func(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) return GL_FALSE; @@ -367,22 +367,22 @@ AttachDepthAndStencilBuffers(GLuint fbo, { GLuint rb; - glGenRenderbuffersEXT(1, &rb); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, + glGenRenderbuffers_func(1, &rb); + glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, rb); + glRenderbufferStorage_func(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height); if (glGetError()) return GL_FALSE; /* attach to depth attachment point */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb); if (glGetError()) return GL_FALSE; - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + status = glCheckFramebufferStatus_func(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) return GL_FALSE; @@ -393,26 +393,26 @@ AttachDepthAndStencilBuffers(GLuint fbo, { GLuint rb; - glGenRenderbuffersEXT(1, &rb); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, + glGenRenderbuffers_func(1, &rb); + glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, rb); + glRenderbufferStorage_func(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, width, height); if (glGetError()) return GL_FALSE; /* attach to depth attachment point */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb); if (glGetError()) return GL_FALSE; - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + status = glCheckFramebufferStatus_func(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - glDeleteRenderbuffersEXT(1, depthRbOut); + glDeleteRenderbuffers_func(1, depthRbOut); *depthRbOut = 0; - glDeleteRenderbuffersEXT(1, &rb); + glDeleteRenderbuffers_func(1, &rb); return GL_FALSE; } @@ -463,6 +463,37 @@ ParseArgs(int argc, char *argv[]) } +static void +SetupFunctionPointers(void) +{ + GetExtensionFuncs(); + + if (Use_ARB_fbo) { + /* no-op: use the ARB functions as-is */ + } + else { + /* set the ARB-flavor function pointers to point to the EXT functions */ + glIsRenderbuffer_func = glIsRenderbufferEXT_func; + glBindRenderbuffer_func = glBindRenderbufferEXT_func; + glDeleteRenderbuffers_func = glDeleteRenderbuffersEXT_func; + glGenRenderbuffers_func = glGenRenderbuffersEXT_func; + glRenderbufferStorage_func = glRenderbufferStorageEXT_func; + glGetRenderbufferParameteriv_func = glGetRenderbufferParameterivEXT_func; + glIsFramebuffer_func = glIsFramebufferEXT_func; + glBindFramebuffer_func = glBindFramebufferEXT_func; + glDeleteFramebuffers_func = glDeleteFramebuffersEXT_func; + glGenFramebuffers_func = glGenFramebuffersEXT_func; + glCheckFramebufferStatus_func = glCheckFramebufferStatusEXT_func; + glFramebufferTexture1D_func = glFramebufferTexture1DEXT_func; + glFramebufferTexture2D_func = glFramebufferTexture2DEXT_func; + glFramebufferTexture3D_func = glFramebufferTexture3DEXT_func; + glFramebufferRenderbuffer_func = glFramebufferRenderbufferEXT_func; + glGetFramebufferAttachmentParameteriv_func = glGetFramebufferAttachmentParameterivEXT_func; + glGenerateMipmap_func = glGenerateMipmapEXT_func; + } +} + + /* * Make FBO to render into given texture. */ @@ -472,10 +503,10 @@ MakeFBO_RenderTexture(GLuint TexObj) GLuint fb; GLint sizeFudge = 0; - glGenFramebuffersEXT(1, &fb); - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); + glGenFramebuffers_func(1, &fb); + glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, fb); /* Render color to texture */ - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + glFramebufferTexture2D_func(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, TexTarget, TexObj, TextureLevel); if (Use_ARB_fbo) { @@ -512,26 +543,26 @@ MakeFBO_RenderTexture(GLuint TexObj) { GLint bits, w, h; - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, DepthRB); - glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, + glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, DepthRB); + glGetRenderbufferParameteriv_func(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_WIDTH_EXT, &w); - glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, + glGetRenderbufferParameteriv_func(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_HEIGHT_EXT, &h); printf("Color/Texture size: %d x %d\n", TexWidth, TexHeight); printf("Depth buffer size: %d x %d\n", w, h); - glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, + glGetRenderbufferParameteriv_func(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_DEPTH_SIZE_EXT, &bits); printf("Depth renderbuffer size = %d bits\n", bits); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, StencilRB); - glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, + glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, StencilRB); + glGetRenderbufferParameteriv_func(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_STENCIL_SIZE_EXT, &bits); printf("Stencil renderbuffer size = %d bits\n", bits); } /* bind the regular framebuffer */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, 0); return fb; } @@ -547,6 +578,8 @@ Init(void) printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + SetupFunctionPointers(); + /* lighting */ { static const GLfloat mat[4] = { 1.0, 0.5, 0.5, 1.0 }; @@ -605,7 +638,6 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); - glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); diff --git a/progs/util/extfuncs.h b/progs/util/extfuncs.h index 238794d55a9..2bb57030a89 100644 --- a/progs/util/extfuncs.h +++ b/progs/util/extfuncs.h @@ -95,6 +95,47 @@ static PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB_func = NULL; static PFNGLMAPBUFFERARBPROC glMapBufferARB_func = NULL; static PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB_func = NULL; +/* GL_EXT_framebuffer_object */ +static PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT_func = NULL; +static PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT_func = NULL; +static PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT_func = NULL; +static PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT_func = NULL; +static PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT_func = NULL; +static PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT_func = NULL; +static PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT_func = NULL; +static PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT_func = NULL; +static PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT_func = NULL; +static PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT_func = NULL; +static PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT_func = NULL; +static PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT_func = NULL; +static PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT_func = NULL; +static PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT_func = NULL; +static PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT_func = NULL; +static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT_func = NULL; +static PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT_func = NULL; + +/* GL_ARB_framebuffer_object */ +static PFNGLISRENDERBUFFERPROC glIsRenderbuffer_func = NULL; +static PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer_func = NULL; +static PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers_func = NULL; +static PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers_func = NULL; +static PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage_func = NULL; +static PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv_func = NULL; +static PFNGLISFRAMEBUFFERPROC glIsFramebuffer_func = NULL; +static PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer_func = NULL; +static PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers_func = NULL; +static PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers_func = NULL; +static PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus_func = NULL; +static PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D_func = NULL; +static PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D_func = NULL; +static PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D_func = NULL; +static PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer_func = NULL; +static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv_func = NULL; +static PFNGLGENERATEMIPMAPPROC glGenerateMipmap_func = NULL; +static PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer_func = NULL; +static PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample_func = NULL; +static PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer_func = NULL; + static void GetExtensionFuncs(void) @@ -192,5 +233,45 @@ GetExtensionFuncs(void) glMapBufferARB_func = (PFNGLMAPBUFFERARBPROC) glutGetProcAddress("glMapBufferARB"); glUnmapBufferARB_func = (PFNGLUNMAPBUFFERARBPROC) glutGetProcAddress("glUnmapBufferARB"); + /* GL_EXT_framebuffer_object */ + glIsRenderbufferEXT_func = (PFNGLISRENDERBUFFEREXTPROC) glutGetProcAddress("glIsRenderbufferEXT"); + glBindRenderbufferEXT_func = (PFNGLBINDRENDERBUFFEREXTPROC) glutGetProcAddress("glBindRenderbufferEXT"); + glDeleteRenderbuffersEXT_func = (PFNGLDELETERENDERBUFFERSEXTPROC) glutGetProcAddress("glDeleteRenderbuffersEXT"); + glGenRenderbuffersEXT_func = (PFNGLGENRENDERBUFFERSEXTPROC) glutGetProcAddress("glGenRenderbuffersEXT"); + glRenderbufferStorageEXT_func = (PFNGLRENDERBUFFERSTORAGEEXTPROC) glutGetProcAddress("glRenderbufferStorageEXT"); + glGetRenderbufferParameterivEXT_func = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) glutGetProcAddress("glGetRenderbufferParameterivEXT"); + glIsFramebufferEXT_func = (PFNGLISFRAMEBUFFEREXTPROC) glutGetProcAddress("glIsFramebufferEXT"); + glBindFramebufferEXT_func = (PFNGLBINDFRAMEBUFFEREXTPROC) glutGetProcAddress("glBindFramebufferEXT"); + glDeleteFramebuffersEXT_func = (PFNGLDELETEFRAMEBUFFERSEXTPROC) glutGetProcAddress("glDeleteFramebuffersEXT"); + glGenFramebuffersEXT_func = (PFNGLGENFRAMEBUFFERSEXTPROC) glutGetProcAddress("glGenFramebuffersEXT"); + glCheckFramebufferStatusEXT_func = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) glutGetProcAddress("glCheckFramebufferStatusEXT"); + glFramebufferTexture1DEXT_func = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) glutGetProcAddress("glFramebufferTexture1DEXT"); + glFramebufferTexture2DEXT_func = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) glutGetProcAddress("glFramebufferTexture2DEXT"); + glFramebufferTexture3DEXT_func = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) glutGetProcAddress("glFramebufferTexture3DEXT"); + glFramebufferRenderbufferEXT_func = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) glutGetProcAddress("glFramebufferRenderbufferEXT"); + glGetFramebufferAttachmentParameterivEXT_func = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) glutGetProcAddress("glGetFramebufferAttachmentParameterivEXT"); + glGenerateMipmapEXT_func = (PFNGLGENERATEMIPMAPEXTPROC) glutGetProcAddress("glGenerateMipmapEXT"); + + /* GL_ARB_framebuffer_object */ + glIsRenderbuffer_func = (PFNGLISRENDERBUFFERPROC) glutGetProcAddress("glIsRenderbuffer"); + glBindRenderbuffer_func = (PFNGLBINDRENDERBUFFERPROC) glutGetProcAddress("glBindRenderbuffer"); + glDeleteRenderbuffers_func = (PFNGLDELETERENDERBUFFERSPROC) glutGetProcAddress("glDeleteRenderbuffers"); + glGenRenderbuffers_func = (PFNGLGENRENDERBUFFERSPROC) glutGetProcAddress("glGenRenderbuffers"); + glRenderbufferStorage_func = (PFNGLRENDERBUFFERSTORAGEPROC) glutGetProcAddress("glRenderbufferStorage"); + glGetRenderbufferParameteriv_func = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) glutGetProcAddress("glGetRenderbufferParameteriv"); + glIsFramebuffer_func = (PFNGLISFRAMEBUFFERPROC) glutGetProcAddress("glIsFramebuffer"); + glBindFramebuffer_func = (PFNGLBINDFRAMEBUFFERPROC) glutGetProcAddress("glBindFramebuffer"); + glDeleteFramebuffers_func = (PFNGLDELETEFRAMEBUFFERSPROC) glutGetProcAddress("glDeleteFramebuffers"); + glGenFramebuffers_func = (PFNGLGENFRAMEBUFFERSPROC) glutGetProcAddress("glGenFramebuffers"); + glCheckFramebufferStatus_func = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) glutGetProcAddress("glCheckFramebufferStatus"); + glFramebufferTexture1D_func = (PFNGLFRAMEBUFFERTEXTURE1DPROC) glutGetProcAddress("glFramebufferTexture1D"); + glFramebufferTexture2D_func = (PFNGLFRAMEBUFFERTEXTURE2DPROC) glutGetProcAddress("glFramebufferTexture2D"); + glFramebufferTexture3D_func = (PFNGLFRAMEBUFFERTEXTURE3DPROC) glutGetProcAddress("glFramebufferTexture3D"); + glFramebufferRenderbuffer_func = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) glutGetProcAddress("glFramebufferRenderbuffer"); + glGetFramebufferAttachmentParameteriv_func = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) glutGetProcAddress("glGetFramebufferAttachmentParameteriv"); + glGenerateMipmap_func = (PFNGLGENERATEMIPMAPPROC) glutGetProcAddress("glGenerateMipmap"); + glBlitFramebuffer_func = (PFNGLBLITFRAMEBUFFERPROC) glutGetProcAddress("glBlitFramebuffer"); + glRenderbufferStorageMultisample_func = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) glutGetProcAddress("glRenderbufferStorageMultisample"); + glFramebufferTextureLayer_func = (PFNGLFRAMEBUFFERTEXTURELAYERPROC) glutGetProcAddress("glFramebufferTextureLayer"); } |