diff options
author | José Fonseca <jfonseca@vmware.com> | 2009-03-02 13:27:46 +0000 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2009-03-02 13:27:46 +0000 |
commit | 97a1fd158c9acfaa3a8deda7eb5bf0b253e85c15 (patch) | |
tree | 37e6c11507c1ef044aa8f0ee009136bb1d8b5bbc /progs | |
parent | 60e5fe65067da76dea816535bec1e9073adc0ba7 (diff) | |
parent | b70f344e223fc10df8df08a6d82a813505225712 (diff) |
Merge commit 'origin/master' into gallium-map-range
Diffstat (limited to 'progs')
-rw-r--r-- | progs/demos/arbfplight.c | 1 | ||||
-rw-r--r-- | progs/demos/arbfslight.c | 1 | ||||
-rw-r--r-- | progs/demos/fslight.c | 1 | ||||
-rw-r--r-- | progs/demos/gearbox.c | 1 | ||||
-rw-r--r-- | progs/demos/gears.c | 1 | ||||
-rw-r--r-- | progs/demos/geartrain.c | 1 | ||||
-rw-r--r-- | progs/demos/gloss.c | 1 | ||||
-rw-r--r-- | progs/demos/glslnoise.c | 1 | ||||
-rw-r--r-- | progs/demos/reflect.c | 1 | ||||
-rw-r--r-- | progs/demos/streaming_rect.c | 1 | ||||
-rw-r--r-- | progs/demos/texcyl.c | 1 | ||||
-rw-r--r-- | progs/glsl/Makefile | 1 | ||||
-rw-r--r-- | progs/glsl/shadow_sampler.c | 341 | ||||
-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 | ||||
-rw-r--r-- | progs/trivial/.gitignore | 1 | ||||
-rw-r--r-- | progs/trivial/Makefile | 1 | ||||
-rw-r--r-- | progs/trivial/SConscript | 1 | ||||
-rw-r--r-- | progs/trivial/tri-viewport.c | 129 | ||||
-rw-r--r-- | progs/trivial/tri.c | 86 |
22 files changed, 762 insertions, 68 deletions
diff --git a/progs/demos/arbfplight.c b/progs/demos/arbfplight.c index 401bfb4968..7b7a12bf88 100644 --- a/progs/demos/arbfplight.c +++ b/progs/demos/arbfplight.c @@ -92,6 +92,7 @@ static void Redisplay( void ) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/demos/arbfslight.c b/progs/demos/arbfslight.c index a84491d34f..275c85105e 100644 --- a/progs/demos/arbfslight.c +++ b/progs/demos/arbfslight.c @@ -105,6 +105,7 @@ static void Redisplay (void) GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; GLfloat fps = frames / seconds; printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } diff --git a/progs/demos/fslight.c b/progs/demos/fslight.c index e79b5cc197..41a13cc9f4 100644 --- a/progs/demos/fslight.c +++ b/progs/demos/fslight.c @@ -105,6 +105,7 @@ Redisplay(void) GLfloat fps = frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } diff --git a/progs/demos/gearbox.c b/progs/demos/gearbox.c index 35bde04417..2dcf32f92f 100644 --- a/progs/demos/gearbox.c +++ b/progs/demos/gearbox.c @@ -314,6 +314,7 @@ draw(void) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/demos/gears.c b/progs/demos/gears.c index 2a9fefefb5..6016162d6f 100644 --- a/progs/demos/gears.c +++ b/progs/demos/gears.c @@ -219,6 +219,7 @@ draw(void) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; if ((t >= 999.0 * autoexit) && (autoexit)) { diff --git a/progs/demos/geartrain.c b/progs/demos/geartrain.c index 8363f2abc6..8fe405e807 100644 --- a/progs/demos/geartrain.c +++ b/progs/demos/geartrain.c @@ -905,6 +905,7 @@ draw (void) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/demos/gloss.c b/progs/demos/gloss.c index b2126e3267..69694b23a0 100644 --- a/progs/demos/gloss.c +++ b/progs/demos/gloss.c @@ -132,6 +132,7 @@ static void Display( void ) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/demos/glslnoise.c b/progs/demos/glslnoise.c index 4ee1292816..e972b62673 100644 --- a/progs/demos/glslnoise.c +++ b/progs/demos/glslnoise.c @@ -65,6 +65,7 @@ static void Redisplay (void) GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; GLfloat fps = frames / seconds; printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } diff --git a/progs/demos/reflect.c b/progs/demos/reflect.c index 0bec0663bc..b72af12885 100644 --- a/progs/demos/reflect.c +++ b/progs/demos/reflect.c @@ -401,6 +401,7 @@ DrawWindow(void) GLfloat seconds = (t - t0) / 1000.0; GLfloat fps = frames / seconds; printf("%d frames in %g seconds = %g FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } diff --git a/progs/demos/streaming_rect.c b/progs/demos/streaming_rect.c index 294f9c3060..f65ac4ce36 100644 --- a/progs/demos/streaming_rect.c +++ b/progs/demos/streaming_rect.c @@ -153,6 +153,7 @@ static void Display( void ) GLfloat fps = Frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); drift_increment = 2.2 * seconds / Frames; T0 = t; diff --git a/progs/demos/texcyl.c b/progs/demos/texcyl.c index e3b0303975..0e6089bced 100644 --- a/progs/demos/texcyl.c +++ b/progs/demos/texcyl.c @@ -79,6 +79,7 @@ static void Display( void ) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 7099eeadbd..8061277033 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -25,6 +25,7 @@ PROGS = \ pointcoord \ samplers \ samplers_array \ + shadow_sampler \ skinning \ texdemo1 \ toyball \ diff --git a/progs/glsl/shadow_sampler.c b/progs/glsl/shadow_sampler.c new file mode 100644 index 0000000000..2902b53552 --- /dev/null +++ b/progs/glsl/shadow_sampler.c @@ -0,0 +1,341 @@ +/** + * Test shadow2DRectProj() and shadow2D() functions. + * Brian Paul + * 11 April 2007 + */ + +#define GL_GLEXT_PROTOTYPES +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> +#include "extfuncs.h" + + +/** Use GL_RECTANGLE texture (with projective texcoords)? */ +#define USE_RECT 01 + +#define TEXSIZE 16 + + +static char *FragProgFile = NULL; +static char *VertProgFile = NULL; + +static GLuint fragShader; +static GLuint vertShader; +static GLuint program; + +static GLint uTexture2D; +static GLint uTextureRect; + +static GLint win = 0; + +static GLenum Filter = GL_LINEAR; + +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("GL Error %s (0x%x) at line %d\n", + gluErrorString(err), (int) err, line); + } +} + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + +static void +Redisplay(void) +{ + CheckError(__LINE__); + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + + CheckError(__LINE__); + glUseProgram_func(program); + CheckError(__LINE__); + + glBegin(GL_POLYGON); +#if USE_RECT + /* scale coords by two to test projection */ + glTexCoord4f( 0, 0, 0, 2.0); glVertex2f(-1, -1); + glTexCoord4f(2*TEXSIZE, 0, 2*1, 2.0); glVertex2f( 1, -1); + glTexCoord4f(2*TEXSIZE, 2*TEXSIZE, 2*1, 2.0); glVertex2f( 1, 1); + glTexCoord4f( 0, 2*TEXSIZE, 0, 2.0); glVertex2f(-1, 1); +#else + glTexCoord3f(0, 0, 0); glVertex2f(-1, -1); + glTexCoord3f(1, 0, 1); glVertex2f( 1, -1); + glTexCoord3f(1, 1, 1); glVertex2f( 1, 1); + glTexCoord3f(0, 1, 0); glVertex2f(-1, 1); +#endif + glEnd(); + + glPopMatrix(); + + glUseProgram_func(0); + glWindowPos2iARB(80, 20); + PrintString("white black white black"); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -8.0f); +} + + +static void +CleanUp(void) +{ + glDeleteShader_func(fragShader); + glDeleteShader_func(vertShader); + glDeleteProgram_func(program); + glutDestroyWindow(win); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch(key) { + case 27: + CleanUp(); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +MakeTexture(void) +{ + GLfloat image[TEXSIZE][TEXSIZE]; + GLuint i, j; + + for (i = 0; i < TEXSIZE; i++) { + for (j = 0; j < TEXSIZE; j++) { + if (j < (TEXSIZE / 2)) { + image[i][j] = 0.25; + } + else { + image[i][j] = 0.75; + } + } + } + + glActiveTexture(GL_TEXTURE0); /* unit 0 */ + glBindTexture(GL_TEXTURE_2D, 42); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, TEXSIZE, TEXSIZE, 0, + GL_DEPTH_COMPONENT, GL_FLOAT, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, + GL_COMPARE_R_TO_TEXTURE_ARB); + CheckError(__LINE__); + + glActiveTexture(GL_TEXTURE1); /* unit 1 */ + glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 43); + glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT, + TEXSIZE, 10, 0,/*16x10*/ + GL_DEPTH_COMPONENT, GL_FLOAT, image); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, Filter); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, Filter); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_COMPARE_MODE_ARB, + GL_COMPARE_R_TO_TEXTURE_ARB); + CheckError(__LINE__); +} + + +static void +LoadAndCompileShader(GLuint shader, const char *text) +{ + GLint stat; + glShaderSource_func(shader, 1, (const GLchar **) &text, NULL); + glCompileShader_func(shader); + glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetShaderInfoLog_func(shader, 1000, &len, log); + fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log); + exit(1); + } +} + + +/** + * Read a shader from a file. + */ +static void +ReadShader(GLuint shader, const char *filename) +{ + const int max = 100*1000; + int n; + char *buffer = (char*) malloc(max); + FILE *f = fopen(filename, "r"); + if (!f) { + fprintf(stderr, "fslight: Unable to open shader file %s\n", filename); + exit(1); + } + + n = fread(buffer, 1, max, f); + printf("fslight: read %d bytes from shader file %s\n", n, filename); + if (n > 0) { + buffer[n] = 0; + LoadAndCompileShader(shader, buffer); + } + + fclose(f); + free(buffer); +} + + +static void +CheckLink(GLuint prog) +{ + GLint stat; + glGetProgramiv_func(prog, GL_LINK_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetProgramInfoLog_func(prog, 1000, &len, log); + fprintf(stderr, "Linker error:\n%s\n", log); + } +} + + +static void +Init(void) +{ + static const char *fragShaderText = + "uniform sampler2DShadow shadowTex2D; \n" + "uniform sampler2DRectShadow shadowTexRect; \n" + "void main() {\n" +#if USE_RECT + " gl_FragColor = shadow2DRectProj(shadowTexRect, gl_TexCoord[0]); \n" +#else + " gl_FragColor = shadow2D(shadowTex2D, gl_TexCoord[0].xyz); \n" +#endif + "}\n"; + static const char *vertShaderText = + "void main() {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " gl_TexCoord[0] = gl_MultiTexCoord0; \n" + "}\n"; + const char *version; + +#if USE_RECT + if (!glutExtensionSupported("GL_ARB_texture_rectangle")) { + printf("This program requires GL_ARB_texture_rectangle\n"); + exit(1); + } +#endif + + version = (const char *) glGetString(GL_VERSION); + if (version[0] != '2' || version[1] != '.') { + printf("This program requires OpenGL 2.x, found %s\n", version); + exit(1); + } + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + GetExtensionFuncs(); + + fragShader = glCreateShader_func(GL_FRAGMENT_SHADER); + if (FragProgFile) + ReadShader(fragShader, FragProgFile); + else + LoadAndCompileShader(fragShader, fragShaderText); + + vertShader = glCreateShader_func(GL_VERTEX_SHADER); + if (VertProgFile) + ReadShader(vertShader, VertProgFile); + else + LoadAndCompileShader(vertShader, vertShaderText); + + program = glCreateProgram_func(); + glAttachShader_func(program, fragShader); + glAttachShader_func(program, vertShader); + glLinkProgram_func(program); + CheckLink(program); + glUseProgram_func(program); + + uTexture2D = glGetUniformLocation_func(program, "shadowTex2D"); + uTextureRect = glGetUniformLocation_func(program, "shadowTexRect"); + printf("uTexture2D %d uTextureRect %d\n", uTexture2D, uTextureRect); + if (uTexture2D >= 0) { + glUniform1i_func(uTexture2D, 0); /* use texture unit 0 */ + } + if (uTextureRect >= 0) { + glUniform1i_func(uTextureRect, 1); /* use texture unit 0 */ + } + CheckError(__LINE__); + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + glColor3f(1, 1, 1); + + MakeTexture(); + CheckError(__LINE__); +} + + +static void +ParseOptions(int argc, char *argv[]) +{ + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-fs") == 0) { + FragProgFile = argv[i+1]; + } + else if (strcmp(argv[i], "-vs") == 0) { + VertProgFile = argv[i+1]; + } + } +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition( 0, 0); + glutInitWindowSize(400, 300); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Redisplay); + ParseOptions(argc, argv); + Init(); + glutMainLoop(); + return 0; +} + + 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; +} diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index dadd535591..5159e31aa2 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -110,6 +110,7 @@ tri-unfilled-tri-lit tri-unfilled-userclip tri-unfilled-userclip-stip tri-userclip +tri-viewport tri-z tri-z-eq trifan diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 6ba41a7895..3300fce636 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -119,6 +119,7 @@ SOURCES = \ tri-unfilled-userclip.c \ tri-unfilled.c \ tri-userclip.c \ + tri-viewport.c \ tri-z-eq.c \ tri-z.c \ tri.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 8a7fb6be30..dc84a0550b 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -114,6 +114,7 @@ progs = [ 'tri-unfilled-userclip', 'tri-unfilled', 'tri-userclip', + 'tri-viewport', 'tri-z-eq', 'tri-z', 'tri', diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c new file mode 100644 index 0000000000..3205b9ee9c --- /dev/null +++ b/progs/trivial/tri-viewport.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + +GLenum doubleBuffer = 1; +int win; + +static void Init(void) +{ + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + + glClearColor(0.3, 0.1, 0.3, 0.0); +} + +static void Reshape(int width, int height) +{ + glViewport(width / -2.0, height / -2.0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static void Key(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + default: + glutPostRedisplay(); + return; + } +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + glColor3f(.8,0,0); + glVertex3f(-0.9, 0.9, -30.0); + glColor3f(0,.9,0); + glVertex3f( 0.9, 0.9, -30.0); + glColor3f(0,0,.7); + glVertex3f( 0.0, -0.9, -30.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB | GLUT_ALPHA; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + win = glutCreateWindow(*argv); + if (!win) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/tri.c b/progs/trivial/tri.c index 033d6ceae2..d99d5872a9 100644 --- a/progs/trivial/tri.c +++ b/progs/trivial/tri.c @@ -41,28 +41,28 @@ static void Init(void) fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - glClearColor(0.3, 0.1, 0.3, 0.0); + glClearColor(0.3, 0.1, 0.3, 0.0); } static void Reshape(int width, int height) { - glViewport(0, 0, (GLint)width, (GLint)height); + glViewport(0, 0, (GLint)width, (GLint)height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); - glMatrixMode(GL_MODELVIEW); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); } static void Key(unsigned char key, int x, int y) { switch (key) { - case 27: - exit(0); - default: - glutPostRedisplay(); - return; + case 27: + exit(0); + default: + glutPostRedisplay(); + return; } } @@ -88,47 +88,47 @@ static void Draw(void) static GLenum Args(int argc, char **argv) { - GLint i; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-sb") == 0) { - doubleBuffer = GL_FALSE; - } else if (strcmp(argv[i], "-db") == 0) { - doubleBuffer = GL_TRUE; - } else { - fprintf(stderr, "%s (Bad option).\n", argv[i]); - return GL_FALSE; - } - } - return GL_TRUE; + GLint i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; } int main(int argc, char **argv) { - GLenum type; + GLenum type; - glutInit(&argc, argv); + glutInit(&argc, argv); - if (Args(argc, argv) == GL_FALSE) { - exit(1); - } + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } - glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); - type = GLUT_RGB | GLUT_ALPHA; - type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; - glutInitDisplayMode(type); + type = GLUT_RGB | GLUT_ALPHA; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); - win = glutCreateWindow(*argv); - if (!win) { - exit(1); - } + win = glutCreateWindow(*argv); + if (!win) { + exit(1); + } - Init(); + Init(); - glutReshapeFunc(Reshape); - glutKeyboardFunc(Key); - glutDisplayFunc(Draw); - glutMainLoop(); - return 0; + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; } |