diff options
Diffstat (limited to 'progs/tests')
-rw-r--r-- | progs/tests/.gitignore | 17 | ||||
-rw-r--r-- | progs/tests/Makefile | 1 | ||||
-rw-r--r-- | progs/tests/SConscript | 1 | ||||
-rw-r--r-- | progs/tests/fbotest1.c | 6 | ||||
-rw-r--r-- | progs/tests/fbotest2.c | 52 | ||||
-rw-r--r-- | progs/tests/fbotest3.c | 6 | ||||
-rw-r--r-- | progs/tests/stencil_twoside.c | 85 | ||||
-rw-r--r-- | progs/tests/stencilreaddraw.c | 187 |
8 files changed, 317 insertions, 38 deletions
diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index d905fab611..37be27fff2 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -1,4 +1,3 @@ -.cvsignore afsmultiarb antialias arbfpspec @@ -17,6 +16,7 @@ auxbuffer blendminmax blendsquare blendxor +blitfb bufferobj bug_3050 bug_3101 @@ -28,12 +28,16 @@ condrender copypixrate crossbar cva +cva_huge +cylwrap drawbuffers drawbuffers2 -extfuncs.h exactrast +ext422square +extfuncs.h fbotest1 fbotest2 +fbotest3 fillrate floattex fog @@ -58,10 +62,12 @@ mipmap_comp_tests mipmap_limits mipmap_view multipal +multitexarray +multiwindow no_s3tc packedpixels -persp_hint pbo +persp_hint prim prog_parameter quads @@ -77,6 +83,7 @@ shader_api shaderutil.c shaderutil.h sharedtex +stencilreaddraw stencil_twoside stencilwrap stencil_wrap @@ -84,10 +91,13 @@ streaming_rect subtex subtexrate tex1d +texcmp texcompress2 texcompsub texdown texfilt +texgenmix +texleak texline texobj texobjshare @@ -97,6 +107,7 @@ unfilledclip vao-01 vao-02 vparray +vpeval vptest1 vptest2 vptest3 diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 6bb0249e17..0f938f9b0c 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -90,6 +90,7 @@ SOURCES = \ seccolor.c \ shader_api.c \ sharedtex.c \ + stencilreaddraw.c \ stencil_twoside.c \ stencilwrap.c \ stencil_wrap.c \ diff --git a/progs/tests/SConscript b/progs/tests/SConscript index 037a0c35da..429d3bb957 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -89,6 +89,7 @@ progs = [ 'scissor-viewport', 'seccolor', 'shader_api', + 'stencilreaddraw', 'stencil_twoside', 'stencil_wrap', 'stencilwrap', diff --git a/progs/tests/fbotest1.c b/progs/tests/fbotest1.c index 0cd7f95c35..a95fdff74c 100644 --- a/progs/tests/fbotest1.c +++ b/progs/tests/fbotest1.c @@ -36,8 +36,8 @@ Display( void ) /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -161,7 +161,7 @@ Init( void ) assert(i == MyFB); CheckError(__LINE__); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, MyRB); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/fbotest2.c b/progs/tests/fbotest2.c index f9c506193f..faf0dd8748 100644 --- a/progs/tests/fbotest2.c +++ b/progs/tests/fbotest2.c @@ -33,15 +33,16 @@ CheckError(int line) static void Display( void ) { - GLubyte *buffer = malloc(Width * Height * 4); + GLboolean copyPix = GL_FALSE; + GLboolean blitPix = GL_FALSE; GLenum status; CheckError(__LINE__); /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -63,16 +64,43 @@ Display( void ) glutSolidTeapot(2.0); glPopMatrix(); - /* read from user framebuffer */ - glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + if (copyPix) { + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + glDrawBuffer(GL_BACK); - /* draw to window */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ - glWindowPos2iARB(0, 0); - glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + + glWindowPos2iARB(0, 0); + glCopyPixels(0, 0, Width, Height, GL_COLOR); + } + else if (blitPix) { + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + glDrawBuffer(GL_BACK); + + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + + glBlitFramebufferEXT(0, 0, Width, Height, + 0, 0, Width, Height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + else { + GLubyte *buffer = malloc(Width * Height * 4); + /* read from user framebuffer */ + glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + /* draw to window */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + glWindowPos2iARB(0, 0); + glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + free(buffer); + } - free(buffer); glutSwapBuffers(); CheckError(__LINE__); } @@ -163,7 +191,7 @@ Init( void ) glGenRenderbuffersEXT(1, &ColorRb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb); assert(glIsRenderbufferEXT(ColorRb)); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, ColorRb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/fbotest3.c b/progs/tests/fbotest3.c index 8e288b38b8..c176f82d2b 100644 --- a/progs/tests/fbotest3.c +++ b/progs/tests/fbotest3.c @@ -50,8 +50,8 @@ Display( void ) /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -189,7 +189,7 @@ Init( void ) glGenRenderbuffersEXT(1, &ColorRb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb); assert(glIsRenderbufferEXT(ColorRb)); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, ColorRb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/stencil_twoside.c b/progs/tests/stencil_twoside.c index 7d871e5877..1010139a20 100644 --- a/progs/tests/stencil_twoside.c +++ b/progs/tests/stencil_twoside.c @@ -26,7 +26,7 @@ * \file stencil_twoside.c * * Simple test of GL_ATI_separate_stencil (or the OGL 2.0 equivalent) functionality. - * Four squares are drawn + * Five squares (or six if stencil wrap is available) are drawn * with different stencil modes, but all should be rendered with the same * final color. */ @@ -37,7 +37,7 @@ #include <GL/glut.h> static int use20syntax = 1; -static int Width = 550; +static int Width = 650; static int Height = 200; static const GLfloat Near = 5.0, Far = 25.0; @@ -70,7 +70,7 @@ static void Display( void ) */ glDisable(GL_STENCIL_TEST); - glTranslatef(-6.0, 0, 0); + glTranslatef(-7.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); glVertex2f(-1, -1); @@ -85,6 +85,9 @@ static void Display( void ) /* Draw the first two squares using incr for the affected face */ + /************************************************************************* + * 2nd square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -98,8 +101,8 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - /* this should be front facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -107,6 +110,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -116,6 +120,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 3rd square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -129,9 +136,8 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); @@ -139,6 +145,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -148,6 +155,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 4th square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_NEVER, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -161,15 +171,13 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { - /* this should be back facing */ + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); glVertex2f( 1, -1); - /* this should be front facing */ + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -177,6 +185,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -186,6 +195,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 5th square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -193,21 +205,19 @@ static void Display( void ) else { stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0); } - stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR); - stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR); + stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR); + stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR); glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { - /* this should be back facing */ + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); glVertex2f( 1, -1); - /* this should be front facing */ + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -224,6 +234,47 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 6th square + */ + if (glutExtensionSupported("GL_EXT_stencil_wrap")) { + if (use20syntax) { + stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); + stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); + } + else { + stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0); + } + stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP); + stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP); + + glTranslatef(3.0, 0, 0); + glBegin(GL_QUADS); + glColor3f( 0.9, 0.9, 0.9 ); + for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be back facing */ + glVertex2f(-1, -1); + glVertex2f(-1, 1); + glVertex2f( 1, 1); + glVertex2f( 1, -1); + /* this should be front facing */ + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + } + glEnd(); + + glStencilFunc(GL_EQUAL, 260 - 255, ~0); + glBegin(GL_QUADS); + glColor3f( 0.5, 0.5, 0.5 ); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + } + glPopMatrix(); glutSwapBuffers(); @@ -278,7 +329,7 @@ static void Init( void ) stencil_func_separate_ati = (PFNGLSTENCILFUNCSEPARATEATIPROC) glutGetProcAddress( "glStencilFuncSeparateATI" ); stencil_op_separate = (PFNGLSTENCILOPSEPARATEPROC) glutGetProcAddress( "glStencilOpSeparate" ); - printf("\nAll 5 squares should be the same color.\n"); + printf("\nAll 5 (or 6) squares should be the same color.\n"); } diff --git a/progs/tests/stencilreaddraw.c b/progs/tests/stencilreaddraw.c new file mode 100644 index 0000000000..84a5a922a0 --- /dev/null +++ b/progs/tests/stencilreaddraw.c @@ -0,0 +1,187 @@ +/* + * Test glRead/DrawPixels for GL_STENCIL_INDEX, with pixelzoom. + * + * Brian Paul + * 8 April 2010 + */ + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + +static GLint WinWidth = 500, WinHeight = 500; +static GLboolean TestPacking = GL_FALSE; +static GLboolean TestList = GL_FALSE; + + +static GLuint StencilValue = 192; + +static void Display(void) +{ + GLubyte stencil[100 * 100 * 2]; + GLubyte stencil2[400 * 400]; /* *2 to test pixelstore stuff */ + GLuint list; + + glClearColor(0.5, 0.5, 0.5, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + glEnable(GL_DEPTH_TEST); + + glStencilOp(GL_INVERT, GL_KEEP, GL_REPLACE); + glStencilFunc(GL_ALWAYS, StencilValue, ~0); + glEnable(GL_STENCIL_TEST); + + /* draw a sphere */ + glViewport(0, 0, 100, 100); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1, 1, -1, 1, -1, 0); /* clip away back half of sphere */ + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glutSolidSphere(1.0, 20, 10); + + glDisable(GL_STENCIL_TEST); + + if (TestPacking) { + glPixelStorei(GL_PACK_ROW_LENGTH, 120); + glPixelStorei(GL_PACK_SKIP_PIXELS, 5); + } + + /* read the stencil image */ + glReadPixels(0, 0, 100, 100, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencil); + { + GLubyte min, max; + int i; + min = max = stencil[0]; + for (i = 1; i < 100 * 100; i++) { + if (stencil[i] < min) + min = stencil[i]; + if (stencil[i] > max) + max = stencil[i]; + } + printf("Stencil value range: [%u, %u]\n", min, max); + if (max != StencilValue) { + printf("Error: expected max stencil val of %u, found %u\n", + StencilValue, max); + } + } + + /* Draw the Z image as luminance above original rendering */ + glWindowPos2i(0, 100); + glDrawPixels(100, 100, GL_LUMINANCE, GL_UNSIGNED_BYTE, stencil); + + if (1) { + if (TestPacking) { + glPixelStorei(GL_PACK_ROW_LENGTH, 0); + glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 120); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 5); + } + + /* draw stencil image with scaling (into stencil buffer) */ + glPixelZoom(4.0, 4.0); + glColor4f(1, 0, 0, 0); + glWindowPos2i(100, 0); + + if (TestList) { + list = glGenLists(1); + glNewList(list, GL_COMPILE); + glDrawPixels(100, 100, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencil); + glEndList(); + glCallList(list); + glDeleteLists(list, 1); + } + else { + glDrawPixels(100, 100, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencil); + } + + if (TestPacking) { + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + } + + /* read back scaled stencil image */ + glReadPixels(100, 0, 400, 400, GL_STENCIL_INDEX, + GL_UNSIGNED_BYTE, stencil2); + /* draw as luminance */ + glPixelZoom(1.0, 1.0); + glWindowPos2i(100, 0); + glDrawPixels(400, 400, GL_LUMINANCE, GL_UNSIGNED_BYTE, stencil2); + } + + glutSwapBuffers(); +} + + +static void Reshape(int width, int height) +{ + WinWidth = width; + WinHeight = height; + glViewport(0, 0, width, height); +} + + +static void Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 'p': + TestPacking = !TestPacking; + printf("Test pixel pack/unpack: %d\n", TestPacking); + break; + case 'l': + TestList = !TestList; + printf("Test dlist: %d\n", TestList); + break; + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void Init(void) +{ + const GLfloat blue[4] = {.1, .1, 1.0, 1.0}; + const GLfloat gray[4] = {0.2, 0.2, 0.2, 1.0}; + const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0}; + const GLfloat pos[4] = {0, 0, 10, 0}; + GLint bits; + + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + glGetIntegerv(GL_STENCIL_BITS, &bits); + printf("Stencil bits: %d\n", bits); + + assert(bits >= 8); + + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue); + glLightfv(GL_LIGHT0, GL_AMBIENT, gray); + glLightfv(GL_LIGHT0, GL_DIFFUSE, white); + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); +} + + +int main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(WinWidth, WinHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL | GLUT_DOUBLE); + glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Display); + Init(); + glutMainLoop(); + return 0; +} |