progs/trivial: add -t (RTT) option for clear-fbo-scissor.c
authorBrian Paul <brianp@vmware.com>
Wed, 10 Mar 2010 19:19:26 +0000 (12:19 -0700)
committerBrian Paul <brianp@vmware.com>
Wed, 10 Mar 2010 19:19:41 +0000 (12:19 -0700)
progs/trivial/clear-fbo-scissor.c

index b0d9651772e85777b29d9df3ff010ee7577c0b20..5ec0b57328b4665f8b8121f46a71a149250419e5 100644 (file)
@@ -15,6 +15,7 @@
 
 static int Width = 512, Height = 512;
 static GLuint MyFB, MyRB;
+static GLboolean UseTex = GL_FALSE;
 
 
 #define CheckError() assert(glGetError() == 0)
@@ -38,12 +39,25 @@ Init(void)
 
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
 
-   glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRB);
+   if (UseTex) {
+      GLuint tex;
+      glGenTextures(1, &tex);
+      glBindTexture(GL_TEXTURE_2D, tex);
+      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0,
+                   GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+      glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
+                                GL_COLOR_ATTACHMENT0_EXT,
+                                GL_TEXTURE_2D, tex, 0);
+   }
+   else {
+      glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRB);
 
-   glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
-                                GL_RENDERBUFFER_EXT, MyRB);
+      glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
+                                   GL_COLOR_ATTACHMENT0_EXT,
+                                   GL_RENDERBUFFER_EXT, MyRB);
 
-   glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+      glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+   }
 
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
 }
@@ -60,7 +74,9 @@ Reshape(int width, int height)
 
    Width = width;
    Height = height;
-   glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+   if (!UseTex) {
+      glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+   }
 }
 
 
@@ -167,11 +183,23 @@ Draw(void)
 int
 main(int argc, char *argv[])
 {
+   int i;
+
    glutInit(&argc, argv);
    glutInitWindowPosition(100, 0);
    glutInitWindowSize(Width, Height);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
 
+   for (i = 1; i < argc; i++) {
+      if (strcmp(argv[i], "-t") == 0)
+         UseTex = GL_TRUE;
+   }
+
+   if (UseTex)
+      printf("Using render to texture\n");
+   else
+      printf("Using user-created render buffer\n");
+
    if (!glutCreateWindow(argv[0])) {
       exit(1);
    }