diff options
Diffstat (limited to 'progs/tests')
-rw-r--r-- | progs/tests/Makefile | 1 | ||||
-rw-r--r-- | progs/tests/bufferobj.c | 89 | ||||
-rw-r--r-- | progs/tests/fbotexture.c | 31 | ||||
-rw-r--r-- | progs/tests/mapvbo.c | 138 |
4 files changed, 234 insertions, 25 deletions
diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 34c9ab1dce..a70a6ab9ab 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -54,6 +54,7 @@ SOURCES = \ jkrahntest.c \ lineclip.c \ manytex.c \ + mapvbo.c \ minmag.c \ mipmap_limits.c \ mipmap_view.c \ diff --git a/progs/tests/bufferobj.c b/progs/tests/bufferobj.c index d1a85392e1..9edb86e575 100644 --- a/progs/tests/bufferobj.c +++ b/progs/tests/bufferobj.c @@ -17,7 +17,8 @@ struct object { - GLuint BufferID; + GLuint VertexBufferID; + GLuint ColorBufferID; GLuint ElementsBufferID; GLuint NumVerts; GLuint VertexOffset; @@ -47,7 +48,7 @@ static void CheckError(int line) static void DrawObject( const struct object *obj ) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->BufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); glVertexPointer(3, GL_FLOAT, obj->VertexStride, (void *) obj->VertexOffset); glEnable(GL_VERTEX_ARRAY); @@ -62,6 +63,7 @@ static void DrawObject( const struct object *obj ) glPopClientAttrib(); } #endif + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->ColorBufferID); glColorPointer(3, GL_FLOAT, obj->ColorStride, (void *) obj->ColorOffset); glEnable(GL_COLOR_ARRAY); @@ -92,7 +94,7 @@ static void Display( void ) glClear( GL_COLOR_BUFFER_BIT ); for (i = 0; i < NumObjects; i++) { - float x = 5.0 * ((float) i / (NumObjects-1) - 0.5); + float x = 7.0 * ((float) i / (NumObjects-1) - 0.5); glPushMatrix(); glTranslatef(x, 0, 0); glRotatef(Xrot, 1, 0, 0); @@ -125,8 +127,11 @@ static void Reshape( int width, int height ) static void FreeBuffers(void) { int i; - for (i = 0; i < NUM_OBJECTS; i++) - glDeleteBuffersARB(1, &Objects[i].BufferID); + for (i = 0; i < NUM_OBJECTS; i++) { + glDeleteBuffersARB(1, &Objects[i].VertexBufferID); + glDeleteBuffersARB(1, &Objects[i].ColorBufferID); + glDeleteBuffersARB(1, &Objects[i].ElementsBufferID); + } } @@ -182,7 +187,9 @@ static void SpecialKey( int key, int x, int y ) } - +/* + * Non-interleaved position/color data. + */ static void MakeObject1(struct object *obj) { GLfloat *v, *c; @@ -193,10 +200,11 @@ static void MakeObject1(struct object *obj) for (i = 0; i < 500; i++) buffer[i] = i & 0xff; - obj->BufferID = 0; - glGenBuffersARB(1, &obj->BufferID); - assert(obj->BufferID != 0); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->BufferID); + obj->VertexBufferID = 0; + glGenBuffersARB(1, &obj->VertexBufferID); + obj->ColorBufferID = obj->VertexBufferID; + assert(obj->VertexBufferID != 0); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); glBufferDataARB(GL_ARRAY_BUFFER_ARB, 500, buffer, GL_STATIC_DRAW_ARB); for (i = 0; i < 500; i++) @@ -257,13 +265,18 @@ static void MakeObject1(struct object *obj) } +/* + * Interleaved position/color data. + */ static void MakeObject2(struct object *obj) { GLfloat *v; int start = 40; /* bytes, to test non-zero array offsets */ - glGenBuffersARB(1, &obj->BufferID); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->BufferID); + glGenBuffersARB(1, &obj->VertexBufferID); + obj->ColorBufferID = obj->VertexBufferID; + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); glBufferDataARB(GL_ARRAY_BUFFER_ARB, 1000, NULL, GL_STATIC_DRAW_ARB); v = (GLfloat *) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); @@ -287,6 +300,9 @@ static void MakeObject2(struct object *obj) } +/* + * Use an index buffer and glDrawElements(). + */ static void MakeObject3(struct object *obj) { GLfloat vertexData[1000]; @@ -314,8 +330,10 @@ static void MakeObject3(struct object *obj) bytes = obj->NumVerts * (3 + 3) * sizeof(GLfloat); /* Don't use glMap/UnmapBuffer for this object */ - glGenBuffersARB(1, &obj->BufferID); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->BufferID); + glGenBuffersARB(1, &obj->VertexBufferID); + obj->ColorBufferID = obj->VertexBufferID; + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); glBufferDataARB(GL_ARRAY_BUFFER_ARB, bytes, vertexData, GL_STATIC_DRAW_ARB); /* Setup a buffer of indices to test the ELEMENTS path */ @@ -332,6 +350,46 @@ static void MakeObject3(struct object *obj) } +/* + * Vertex and color data in different buffers. + */ +static void MakeObject4(struct object *obj) +{ + static const GLfloat vertexData[] = { + 0, -1, 0, + 0.5, 0, 0, + 0, 1, 0, + -0.5, 0, 0 + }; + static const GLfloat colorData[] = { + 1, 1, 1, + 1, 1, 0, + .5, .5, 0, + 1, 1, 0 + }; + + obj->VertexOffset = 0; + obj->VertexStride = 0; + obj->ColorOffset = 0; + obj->ColorStride = 0; + obj->NumVerts = 4; + + glGenBuffersARB(1, &obj->VertexBufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertexData), vertexData, + GL_STATIC_DRAW_ARB); + + glGenBuffersARB(1, &obj->ColorBufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->ColorBufferID); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(colorData), colorData, + GL_STATIC_DRAW_ARB); + + /* Setup a buffer of indices to test the ELEMENTS path */ + obj->ElementsBufferID = 0; + obj->NumElements = 0; +} + + static void Init( void ) { @@ -358,7 +416,8 @@ static void Init( void ) MakeObject1(Objects + 0); MakeObject2(Objects + 1); MakeObject3(Objects + 2); - NumObjects = 3; + MakeObject4(Objects + 3); + NumObjects = 4; } diff --git a/progs/tests/fbotexture.c b/progs/tests/fbotexture.c index 1f7c45fc79..ae993576b0 100644 --- a/progs/tests/fbotexture.c +++ b/progs/tests/fbotexture.c @@ -26,9 +26,16 @@ static int Win = 0; static int Width = 400, Height = 400; -static GLenum TexTarget = GL_TEXTURE_2D; /*GL_TEXTURE_RECTANGLE_ARB;*/ +#if 1 +static GLenum TexTarget = GL_TEXTURE_2D; static int TexWidth = 512, TexHeight = 512; -/*static int TexWidth = 600, TexHeight = 600;*/ +static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */ +#else +static GLenum TexTarget = GL_TEXTURE_RECTANGLE_ARB; +static int TexWidth = 200, TexHeight = 200; +static GLenum TexIntFormat = GL_RGB5; /* either GL_RGB or GL_RGBA */ +#endif +static GLuint TextureLevel = 0; /* which texture level to render to */ static GLuint MyFB; static GLuint TexObj; @@ -38,8 +45,6 @@ static GLfloat Rot = 0.0; static GLboolean UsePackedDepthStencil = GL_FALSE; static GLboolean UsePackedDepthStencilBoth = GL_FALSE; static GLboolean Use_ARB_fbo = GL_FALSE; -static GLuint TextureLevel = 0; /* which texture level to render to */ -static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */ static GLboolean Cull = GL_FALSE; static GLboolean Wireframe = GL_FALSE; @@ -404,8 +409,12 @@ AttachDepthAndStencilBuffers(GLuint fbo, return GL_FALSE; status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + glDeleteRenderbuffersEXT(1, depthRbOut); + *depthRbOut = 0; + glDeleteRenderbuffersEXT(1, &rb); return GL_FALSE; + } *stencilRbOut = rb; } @@ -554,15 +563,17 @@ Init(void) /* 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; + if (TexTarget == GL_TEXTURE_2D) { + 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_MAX_LEVEL, TextureLevel); + } glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(TexTarget, GL_TEXTURE_BASE_LEVEL, TextureLevel); - glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } diff --git a/progs/tests/mapvbo.c b/progs/tests/mapvbo.c new file mode 100644 index 0000000000..49e120de73 --- /dev/null +++ b/progs/tests/mapvbo.c @@ -0,0 +1,138 @@ +/* + * Test glMapBuffer() call immediately after glDrawArrays(). + * See details below. + * + * NOTE: Do not use freeglut with this test! It calls the Display() + * callback twice right away instead of just once. + * + * Brian Paul + * 27 Feb 2009 + */ + + +#define GL_GLEXT_PROTOTYPES +#include <stdio.h> +#include <stdlib.h> +#include <GL/glut.h> + +static GLuint BufferID; + + +static GLuint Win; + + + + +/* + * Create VBO (position and color) and load with data. + */ +static void +SetupBuffers(void) +{ + static const GLfloat data[] = { + /* vertex */ /* color */ + 0, -1, 0, 1, 1, 0, + 1, 0, 0, 1, 1, 0, + 0, 1, 0, 1, 1, 0, + -1, 0, 0, 1, 1, 0 + }; + + glGenBuffersARB(1, &BufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(data), data, + GL_STATIC_DRAW_ARB); +} + + +static void +Draw(void) +{ + static int count = 1; + + printf("Draw Frame %d\n", count); + count++; + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); + glVertexPointer(3, GL_FLOAT, 24, 0); + glEnable(GL_VERTEX_ARRAY); + + glColorPointer(3, GL_FLOAT, 24, (void*) 12); + glEnable(GL_COLOR_ARRAY); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + if (0) + glFinish(); + + /* Immediately map the color buffer and change something. + * This should not effect the first glDrawArrays above, but the + * next time we draw we should see a black vertex. + */ + if (1) { + GLfloat *m = (GLfloat *) glMapBufferARB(GL_ARRAY_BUFFER_ARB, + GL_WRITE_ONLY_ARB); + m[3] = m[4] = m[5] = 0.0f; /* black vertex */ + glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + } +} + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT ); + Draw(); + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + float ar = (float) width / (float) height; + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -ar, ar, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + if (key == 27) { + glutDestroyWindow(Win); + exit(0); + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + if (!glutExtensionSupported("GL_ARB_vertex_buffer_object")) { + printf("GL_ARB_vertex_buffer_object not found!\n"); + exit(0); + } + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + SetupBuffers(); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 300, 300 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} |