From 6494541eaa375bdf4241ea7b8f8a881cbb0debda Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 24 Mar 2006 23:17:06 +0000 Subject: lots of debug options, some code movement, etc --- progs/tests/fbotexture.c | 122 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 30 deletions(-) (limited to 'progs/tests/fbotexture.c') diff --git a/progs/tests/fbotexture.c b/progs/tests/fbotexture.c index ca6d3935112..13a29db3f35 100644 --- a/progs/tests/fbotexture.c +++ b/progs/tests/fbotexture.c @@ -17,15 +17,26 @@ #include #include +/* For debug */ +#define DEPTH 1 +#define STENCIL 1 +#define DRAW 1 + static int Width = 400, Height = 400; + +static GLenum TexTarget = GL_TEXTURE_2D; /*GL_TEXTURE_RECTANGLE_ARB;*/ static int TexWidth = 512, TexHeight = 512; +/*static int TexWidth = 600, TexHeight = 600;*/ + static GLuint MyFB; static GLuint TexObj; static GLuint DepthRB, StencilRB; static GLboolean Anim = GL_FALSE; static GLfloat Rot = 0.0; static GLboolean UsePackedDepthStencil = GL_FALSE; +static GLuint TextureLevel = 1; /* which texture level to render to */ +static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */ static void @@ -41,7 +52,7 @@ CheckError(int line) static void Idle(void) { - Rot = glutGet(GLUT_ELAPSED_TIME) * 0.05; + Rot = glutGet(GLUT_ELAPSED_TIME) * 0.1; glutPostRedisplay(); } @@ -49,7 +60,6 @@ Idle(void) static void RenderTexture(void) { - GLint level = 0; GLenum status; glMatrixMode(GL_PROJECTION); @@ -60,10 +70,7 @@ RenderTexture(void) glTranslatef(0.0, 0.0, -15.0); /* draw to texture image */ - glBindTexture(GL_TEXTURE_2D, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, - GL_TEXTURE_2D, TexObj, level); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -76,13 +83,19 @@ RenderTexture(void) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); CheckError(__LINE__); +#if DEPTH glEnable(GL_DEPTH_TEST); +#endif + +#if STENCIL glEnable(GL_STENCIL_TEST); glStencilFunc(GL_NEVER, 1, ~0); glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE); +#endif CheckError(__LINE__); +#if DEPTH || STENCIL /* draw diamond-shaped stencil pattern */ glColor3f(0, 1, 0); glBegin(GL_POLYGON); @@ -91,10 +104,13 @@ RenderTexture(void) glVertex2f( 0.2, 0.0); glVertex2f( 0.0, 0.2); glEnd(); +#endif /* draw teapot where stencil != 1 */ +#if STENCIL glStencilFunc(GL_NOTEQUAL, 1, ~0); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); +#endif CheckError(__LINE__); @@ -115,12 +131,18 @@ RenderTexture(void) glutSolidTeapot(0.5); glPopMatrix(); glDisable(GL_LIGHTING); + /* + PrintStencilHistogram(TexWidth, TexHeight); + */ #endif + glDisable(GL_DEPTH_TEST); glDisable(GL_STENCIL_TEST); +#if DRAW /* Bind normal framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); +#endif CheckError(__LINE__); } @@ -135,7 +157,7 @@ Display(void) RenderTexture(); /* draw textured quad in the window */ - +#if DRAW glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0); @@ -150,23 +172,38 @@ Display(void) glPushMatrix(); glRotatef(Rot, 0, 1, 0); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, TexObj); + glEnable(TexTarget); + glBindTexture(TexTarget, TexObj); glBegin(GL_POLYGON); glColor3f(0.25, 0.25, 0.25); - glTexCoord2f(0, 0); - glVertex2f(-1, -1); - glTexCoord2f(1, 0); - glVertex2f(1, -1); - glColor3f(1.0, 1.0, 1.0); - glTexCoord2f(1, 1); - glVertex2f(1, 1); - glTexCoord2f(0, 1); - glVertex2f(-1, 1); + if (TexTarget == GL_TEXTURE_2D) { + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(1, 0); + glVertex2f(1, -1); + glColor3f(1.0, 1.0, 1.0); + glTexCoord2f(1, 1); + glVertex2f(1, 1); + glTexCoord2f(0, 1); + glVertex2f(-1, 1); + } + else { + assert(TexTarget == GL_TEXTURE_RECTANGLE_ARB); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(TexWidth, 0); + glVertex2f(1, -1); + glColor3f(1.0, 1.0, 1.0); + glTexCoord2f(TexWidth, TexHeight); + glVertex2f(1, 1); + glTexCoord2f(0, TexHeight); + glVertex2f(-1, 1); + } glEnd(); glPopMatrix(); - glDisable(GL_TEXTURE_2D); - + glDisable(TexTarget); +#endif + glutSwapBuffers(); CheckError(__LINE__); } @@ -184,9 +221,13 @@ Reshape(int width, int height) static void CleanUp(void) { +#if DEPTH glDeleteRenderbuffersEXT(1, &DepthRB); +#endif +#if STENCIL if (!UsePackedDepthStencil) glDeleteRenderbuffersEXT(1, &StencilRB); +#endif glDeleteFramebuffersEXT(1, &MyFB); glDeleteTextures(1, &TexObj); @@ -222,6 +263,7 @@ Key(unsigned char key, int x, int y) static void Init(int argc, char *argv[]) { + static const GLfloat mat[4] = { 1.0, 0.5, 0.5, 1.0 }; GLint i; if (!glutExtensionSupported("GL_EXT_framebuffer_object")) { @@ -253,6 +295,31 @@ Init(int argc, char *argv[]) glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &i); assert(i == MyFB); + /* Make texture object/image */ + glGenTextures(1, &TexObj); + glBindTexture(TexTarget, TexObj); + /* make two image levels */ + glTexImage2D(TexTarget, 0, TexIntFormat, TexWidth, TexHeight, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(TexTarget, 1, TexIntFormat, TexWidth/2, TexHeight/2, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + TexWidth = TexWidth >> TextureLevel; + TexHeight = TexHeight >> TextureLevel; + + glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexParameteri(TexTarget, GL_TEXTURE_BASE_LEVEL, TextureLevel); + glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel); + + CheckError(__LINE__); + + /* Render color to texture */ + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + TexTarget, TexObj, TextureLevel); + + +#if DEPTH /* make depth renderbuffer */ glGenRenderbuffersEXT(1, &DepthRB); assert(DepthRB); @@ -275,9 +342,11 @@ Init(int argc, char *argv[]) /* attach DepthRB to MyFB */ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, DepthRB); +#endif CheckError(__LINE__); +#if STENCIL if (UsePackedDepthStencil) { /* DepthRb is a combined depth/stencil renderbuffer */ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, @@ -303,23 +372,16 @@ Init(int argc, char *argv[]) CheckError(__LINE__); printf("Stencil renderbuffer size = %d bits\n", i); assert(i > 0); +#endif + CheckError(__LINE__); /* bind regular framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - CheckError(__LINE__); - - /* Make texture object/image */ - glGenTextures(1, &TexObj); - glBindTexture(GL_TEXTURE_2D, TexObj); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - CheckError(__LINE__); + /* lighting */ + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat); } -- cgit v1.2.3