From cd87aeae00e17e49e258d4d0db6524d808ba7d3f Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 20 May 2008 18:49:40 -0400 Subject: add a simple but nice example of convolution filters in glsl shows basics of image processing with glsl --- progs/glsl/Makefile | 9 +- progs/glsl/convolution.frag | 21 +++ progs/glsl/convolution.vert | 5 + progs/glsl/convolutions.c | 441 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 475 insertions(+), 1 deletion(-) create mode 100644 progs/glsl/convolution.frag create mode 100644 progs/glsl/convolution.vert create mode 100644 progs/glsl/convolutions.c (limited to 'progs') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 37fa312c30..b9cae66815 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -14,7 +14,8 @@ PROGS = \ mandelbrot \ noise \ toyball \ - texdemo1 + texdemo1 \ + convolutions ##### RULES ##### @@ -62,6 +63,12 @@ texdemo1: texdemo1.o readtex.o texdemo1.o: texdemo1.c readtex.h extfuncs.h $(CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c +convolutions: convolutions.o readtex.o + $(CC) -I$(INCDIR) $(CFLAGS) convolutions.o readtex.o $(APP_LIB_DEPS) -o $@ + +convolutions.o: convolutions.c readtex.h + $(CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c + clean: -rm -f $(PROGS) diff --git a/progs/glsl/convolution.frag b/progs/glsl/convolution.frag new file mode 100644 index 0000000000..e49b8acf54 --- /dev/null +++ b/progs/glsl/convolution.frag @@ -0,0 +1,21 @@ + +const int KernelSize = 9; + +//texture offsets +uniform vec2 Offset[KernelSize]; +//convolution kernel +uniform vec4 KernelValue[KernelSize]; +uniform sampler2D srcTex; +uniform vec4 ScaleFactor; +uniform vec4 BaseColor; + +void main(void) +{ + int i; + vec4 sum = vec4(0.0); + for (i = 0; i < KernelSize; ++i) { + vec4 tmp = texture2D(srcTex, gl_TexCoord[0].st + Offset[i]); + sum += tmp * KernelValue[i]; + } + gl_FragColor = sum * ScaleFactor + BaseColor; +} diff --git a/progs/glsl/convolution.vert b/progs/glsl/convolution.vert new file mode 100644 index 0000000000..752c54671c --- /dev/null +++ b/progs/glsl/convolution.vert @@ -0,0 +1,5 @@ +void main() { + gl_FrontColor = gl_Color; + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +} diff --git a/progs/glsl/convolutions.c b/progs/glsl/convolutions.c new file mode 100644 index 0000000000..be887714c4 --- /dev/null +++ b/progs/glsl/convolutions.c @@ -0,0 +1,441 @@ +#define GL_GLEXT_PROTOTYPES +#include "readtex.h" + +#include +#include +#include +#include +#include + +enum Filter { + GAUSSIAN_BLUR, + SHARPEN, + MEAN_REMOVAL, + EMBOSS, + NO_FILTER, + LAST +}; +#define QUIT LAST + +struct BoundingBox { + float minx, miny, minz; + float maxx, maxy, maxz; +}; +struct Texture { + GLuint id; + GLfloat x; + GLfloat y; + GLint width; + GLint height; + GLenum format; +}; + +static const char *textureLocation = "../images/girl2.rgb"; + +static GLfloat viewRotx = 0.0, viewRoty = 0.0, viewRotz = 0.0; +static struct BoundingBox box; +static struct Texture texture; +static GLuint program; +static GLint menuId; +static enum Filter filter = GAUSSIAN_BLUR; + + +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 loadAndCompileShader(GLuint shader, const char *text) +{ + GLint stat; + + glShaderSource(shader, 1, (const GLchar **) &text, NULL); + + glCompileShader(shader); + + glGetShaderiv(shader, GL_COMPILE_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetShaderInfoLog(shader, 1000, &len, log); + fprintf(stderr, "Problem compiling shader: %s\n", log); + exit(1); + } + else { + printf("Shader compiled OK\n"); + } +} + +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, "Unable to open shader file %s\n", filename); + exit(1); + } + + n = fread(buffer, 1, max, f); + printf("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(prog, GL_LINK_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetProgramInfoLog(prog, 1000, &len, log); + fprintf(stderr, "Linker error:\n%s\n", log); + } + else { + fprintf(stderr, "Link success!\n"); + } +} + +static void fillConvolution(GLint *k, + GLfloat *scale, + GLfloat *color) +{ + switch(filter) { + case GAUSSIAN_BLUR: + k[0] = 1; k[1] = 2; k[2] = 1; + k[3] = 2; k[4] = 4; k[5] = 2; + k[6] = 1; k[7] = 2; k[8] = 1; + + *scale = 1./16.; + break; + case SHARPEN: + k[0] = 0; k[1] = -2; k[2] = 0; + k[3] = -2; k[4] = 11; k[5] = -2; + k[6] = 0; k[7] = -2; k[8] = 0; + + *scale = 1./3.; + break; + case MEAN_REMOVAL: + k[0] = -1; k[1] = -1; k[2] = -1; + k[3] = -1; k[4] = 9; k[5] = -1; + k[6] = -1; k[7] = -1; k[8] = -1; + + *scale = 1./1.; + break; + case EMBOSS: + k[0] = -1; k[1] = 0; k[2] = -1; + k[3] = 0; k[4] = 4; k[5] = 0; + k[6] = -1; k[7] = 0; k[8] = -1; + + *scale = 1./1.; + color[0] = 0.5; + color[1] = 0.5; + color[2] = 0.5; + color[3] = 0.5; + break; + case NO_FILTER: + k[0] = 0; k[1] = 0; k[2] = 0; + k[3] = 0; k[4] = 1; k[5] = 0; + k[6] = 0; k[7] = 0; k[8] = 0; + + *scale = 1.; + break; + default: + assert(!"Unhandled switch value"); + } +} + +static void setupConvolution() +{ + GLint *kernel = (GLint*)malloc(sizeof(GLint) * 9); + GLfloat scale; + GLfloat *vecKer = (GLfloat*)malloc(sizeof(GLfloat) * 9 * 4); + GLuint loc; + GLuint i; + GLfloat baseColor[4]; + baseColor[0] = 0; + baseColor[1] = 0; + baseColor[2] = 0; + baseColor[3] = 0; + + fillConvolution(kernel, &scale, baseColor); + /*vector of 4*/ + for (i = 0; i < 9; ++i) { + vecKer[i*4 + 0] = kernel[i]; + vecKer[i*4 + 1] = kernel[i]; + vecKer[i*4 + 2] = kernel[i]; + vecKer[i*4 + 3] = kernel[i]; + } + + loc = glGetUniformLocationARB(program, "KernelValue"); + glUniform4fv(loc, 9, vecKer); + loc = glGetUniformLocationARB(program, "ScaleFactor"); + glUniform4f(loc, scale, scale, scale, scale); + loc = glGetUniformLocationARB(program, "BaseColor"); + glUniform4f(loc, baseColor[0], baseColor[1], + baseColor[2], baseColor[3]); + + free(vecKer); + free(kernel); +} + +static void createProgram(const char *vertProgFile, + const char *fragProgFile) +{ + GLuint fragShader = 0, vertShader = 0; + + program = glCreateProgram(); + if (vertProgFile) { + vertShader = glCreateShader(GL_VERTEX_SHADER); + readShader(vertShader, vertProgFile); + glAttachShader(program, vertShader); + } + + if (fragProgFile) { + fragShader = glCreateShader(GL_FRAGMENT_SHADER); + readShader(fragShader, fragProgFile); + glAttachShader(program, fragShader); + } + + glLinkProgram(program); + checkLink(program); + + glUseProgram(program); + + assert(glIsProgram(program)); + assert(glIsShader(fragShader)); + assert(glIsShader(vertShader)); + + checkError(__LINE__); + {/*texture*/ + GLuint texLoc = glGetUniformLocationARB(program, "srcTex"); + glUniform1iARB(texLoc, 0); + } + {/*setup offsets */ + float offsets[] = { 1.0 / texture.width, 1.0 / texture.height, + 0.0 , 1.0 / texture.height, + -1.0 / texture.width, 1.0 / texture.height, + 1.0 / texture.width, 0.0, + 0.0 , 0.0, + -1.0 / texture.width, 0.0, + 1.0 / texture.width, -1.0 / texture.height, + 0.0 , -1.0 / texture.height, + -1.0 / texture.width, -1.0 / texture.height }; + GLuint offsetLoc = glGetUniformLocationARB(program, "Offset"); + glUniform2fv(offsetLoc, 9, offsets); + } + setupConvolution(); + + checkError(__LINE__); +} + + +static void readTexture(const char *filename) +{ + GLubyte *data; + + texture.x = 0; + texture.y = 0; + + glGenTextures(1, &texture.id); + glBindTexture(GL_TEXTURE_2D, texture.id); + glTexParameteri(GL_TEXTURE_2D, + GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, + GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + data = LoadRGBImage(filename, &texture.width, &texture.height, + &texture.format); + if (!data) { + printf("Error: couldn't load texture image '%s'\n", filename); + exit(1); + } + printf("Texture %s (%d x %d)\n", + filename, texture.width, texture.height); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, + texture.width, texture.height, 0, texture.format, + GL_UNSIGNED_BYTE, data); +} + +static void menuSelected(int entry) +{ + switch (entry) { + case QUIT: + exit(0); + break; + default: + filter = (enum Filter)entry; + } + setupConvolution(); + + glutPostRedisplay(); +} + +static void menuInit() +{ + menuId = glutCreateMenu(menuSelected); + + glutAddMenuEntry("Gaussian blur", GAUSSIAN_BLUR); + glutAddMenuEntry("Sharpen", SHARPEN); + glutAddMenuEntry("Mean removal", MEAN_REMOVAL); + glutAddMenuEntry("Emboss", EMBOSS); + glutAddMenuEntry("None", NO_FILTER); + + glutAddMenuEntry("Quit", QUIT); + + glutAttachMenu(GLUT_RIGHT_BUTTON); +} + +static void init() +{ + 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)); + + menuInit(); + readTexture(textureLocation); + createProgram("convolution.vert", "convolution.frag"); + + glEnable(GL_TEXTURE_2D); + glClearColor(1.0, 1.0, 1.0, 1.0); + /*glShadeModel(GL_SMOOTH);*/ + glShadeModel(GL_FLAT); +} + +static void reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + box.minx = 0; + box.maxx = width; + box.miny = 0; + box.maxy = height; + box.minz = 0; + box.maxz = 1; + glOrtho(box.minx, box.maxx, box.miny, box.maxy, -999999, 999999); + glMatrixMode(GL_MODELVIEW); +} + +static void keyPress(unsigned char key, int x, int y) +{ + switch(key) { + case 27: + exit(0); + default: + return; + } + glutPostRedisplay(); +} + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_UP: + viewRotx += 2.0; + break; + case GLUT_KEY_DOWN: + viewRotx -= 2.0; + break; + case GLUT_KEY_LEFT: + viewRoty += 2.0; + break; + case GLUT_KEY_RIGHT: + viewRoty -= 2.0; + break; + default: + return; + } + glutPostRedisplay(); +} + + +static void draw() +{ + GLfloat center[2]; + GLfloat anchor[2]; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glLoadIdentity(); + glPushMatrix(); + + center[0] = box.maxx/2; + center[1] = box.maxy/2; + anchor[0] = center[0] - texture.width/2; + anchor[1] = center[1] - texture.height/2; + + glTranslatef(center[0], center[1], 0); + glRotatef(viewRotx, 1.0, 0.0, 0.0); + glRotatef(viewRoty, 0.0, 1.0, 0.0); + glRotatef(viewRotz, 0.0, 0.0, 1.0); + glTranslatef(-center[0], -center[1], 0); + + glTranslatef(anchor[0], anchor[1], 0); + glBegin(GL_TRIANGLE_STRIP); + { + glColor3f(1., 0., 0.); + glTexCoord2f(0, 0); + glVertex3f(0, 0, 0); + + glColor3f(0., 1., 0.); + glTexCoord2f(0, 1.0); + glVertex3f(0, texture.height, 0); + + glColor3f(1., 0., 0.); + glTexCoord2f(1.0, 0); + glVertex3f(texture.width, 0, 0); + + glColor3f(0., 1., 0.); + glTexCoord2f(1, 1); + glVertex3f(texture.width, texture.height, 0); + } + glEnd(); + + glPopMatrix(); + + glFlush(); + + glutSwapBuffers(); +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 400); + glutInitDisplayMode(GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE); + + if (!glutCreateWindow("Image Convolutions")) { + fprintf(stderr, "Couldn't create window!\n"); + exit(1); + } + + init(); + + glutReshapeFunc(reshape); + glutKeyboardFunc(keyPress); + glutSpecialFunc(special); + glutDisplayFunc(draw); + + + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 0a4867bd4c20faf96af2df6ae31b83854082a820 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sat, 29 Sep 2007 11:23:22 -0700 Subject: Ignore more generated files in progs/ Many of the directories in progs/ were missing .gitignore files or were tracking generated files. This patch is basically the process of running `make' in each directory and then finding the untracked files with `git-ls-files -o --exclude-per-directory=.gitignore'. The existing files were also sorted. --- progs/beos/.gitignore | 3 +++ progs/directfb/.gitignore | 4 ++++ progs/egl/.gitignore | 5 +++++ progs/fbdev/.gitignore | 1 + progs/miniglx/.gitignore | 6 ++++++ progs/osdemos/.gitignore | 8 ++++++++ progs/samples/.gitignore | 34 +++++++++++++++++----------------- progs/slang/.gitignore | 3 +++ progs/tests/.gitignore | 10 +++++++++- progs/tools/trace/.gitignore | 1 + progs/vp/.gitignore | 1 + 11 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 progs/beos/.gitignore create mode 100644 progs/directfb/.gitignore create mode 100644 progs/egl/.gitignore create mode 100644 progs/fbdev/.gitignore create mode 100644 progs/miniglx/.gitignore create mode 100644 progs/osdemos/.gitignore create mode 100644 progs/slang/.gitignore create mode 100644 progs/tools/trace/.gitignore create mode 100644 progs/vp/.gitignore (limited to 'progs') diff --git a/progs/beos/.gitignore b/progs/beos/.gitignore new file mode 100644 index 0000000000..53011ca2e6 --- /dev/null +++ b/progs/beos/.gitignore @@ -0,0 +1,3 @@ +demo +GLInfo +sample diff --git a/progs/directfb/.gitignore b/progs/directfb/.gitignore new file mode 100644 index 0000000000..55d65fb5b0 --- /dev/null +++ b/progs/directfb/.gitignore @@ -0,0 +1,4 @@ +df_gears +df_morph3d +df_reflect +multi_window diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore new file mode 100644 index 0000000000..1751108235 --- /dev/null +++ b/progs/egl/.gitignore @@ -0,0 +1,5 @@ +demo1 +demo2 +demo3 +eglgears +eglinfo diff --git a/progs/fbdev/.gitignore b/progs/fbdev/.gitignore new file mode 100644 index 0000000000..b9ddf559fd --- /dev/null +++ b/progs/fbdev/.gitignore @@ -0,0 +1 @@ +glfbdevtest diff --git a/progs/miniglx/.gitignore b/progs/miniglx/.gitignore new file mode 100644 index 0000000000..f630f591f6 --- /dev/null +++ b/progs/miniglx/.gitignore @@ -0,0 +1,6 @@ +manytex +miniglxsample +miniglxtest +sample_server +sample_server2 +texline diff --git a/progs/osdemos/.gitignore b/progs/osdemos/.gitignore new file mode 100644 index 0000000000..5c78f12481 --- /dev/null +++ b/progs/osdemos/.gitignore @@ -0,0 +1,8 @@ +osdemo +osdemo16 +osdemo32 +ostest1 +readtex.c +readtex.h +showbuffer.c +showbuffer.h diff --git a/progs/samples/.gitignore b/progs/samples/.gitignore index 9635c7f450..f60d6e94ea 100644 --- a/progs/samples/.gitignore +++ b/progs/samples/.gitignore @@ -1,24 +1,41 @@ .cvsignore accum +anywin +bdemo +binfo bitmap1 bitmap2 blendeq blendxor +bugger copy cursor +demo depth eval +ffset fog font +font +incopy line logo +lthreads +lxdemo +lxgears +lxheads +lxinfo +lxpixmap nurb oglinfo olympic overlay +pend point prim quad +readtex.c +readtex.h select shape sphere @@ -28,20 +45,3 @@ stretch texture tri wave -bugger -pend -lthreads -lxdemo -lxgears -lxheads -lxinfo -lxpixmap -anywin -ffset -bdemo -binfo -incopy -demo -font -readtex.c -readtex.h diff --git a/progs/slang/.gitignore b/progs/slang/.gitignore new file mode 100644 index 0000000000..8a42b018e6 --- /dev/null +++ b/progs/slang/.gitignore @@ -0,0 +1,3 @@ +cltest +sotest +vstest diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index 2c0e16c35e..2455d5e9f7 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -1,5 +1,5 @@ .cvsignore -getproclist.h +afsmultiarb antialias arbfpspec arbfptest1 @@ -25,13 +25,21 @@ fogcoord fptest1 fptexture getprocaddress +getproclist.h +interleave invert +jkrahntest manytex multipal no_s3tc packedpixels pbo +prog_parameter projtex +random +readrate +readtex.c +readtex.h seccolor sharedtex stencil_wrap diff --git a/progs/tools/trace/.gitignore b/progs/tools/trace/.gitignore new file mode 100644 index 0000000000..afe0c5829e --- /dev/null +++ b/progs/tools/trace/.gitignore @@ -0,0 +1 @@ +gltrace.cc diff --git a/progs/vp/.gitignore b/progs/vp/.gitignore new file mode 100644 index 0000000000..a5ff993525 --- /dev/null +++ b/progs/vp/.gitignore @@ -0,0 +1 @@ +vp-tris -- cgit v1.2.3 From f869ddf29771253e9f7634384a7354eb14f4cadd Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 20 May 2008 19:18:22 -0400 Subject: add new binaries to ignore to make 'git status' cleaner --- progs/glsl/.gitignore | 1 + progs/tests/.gitignore | 23 ++++++++++++++++++++++- progs/trivial/.gitignore | 4 ++++ progs/xdemos/.gitignore | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 622e0417a8..81ecf5bdd5 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -1,5 +1,6 @@ brick bump +convolutions deriv extfuncs.h mandelbrot diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index 2455d5e9f7..a72f552f10 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -5,20 +5,30 @@ arbfpspec arbfptest1 arbfptexture arbfptrig +arbnpot +arbnpot-mipmap arbvptest1 arbvptest3 arbvptorus arbvpwarpmesh +arraytexture blendminmax blendsquare bufferobj +bug_3050 bug_3101 bug_3195 +calibrate_rast +copypixrate crossbar cva dinoshade +drawbuffers +extfuncs.h fbotest1 +fbotest2 fbotexture +fillrate floattex fog fogcoord @@ -30,6 +40,9 @@ interleave invert jkrahntest manytex +minmag +mipmap_limits +mipmap_view multipal no_s3tc packedpixels @@ -42,15 +55,21 @@ readtex.c readtex.h seccolor sharedtex -stencil_wrap stencilwrap +stencil_wrap +subtex +subtexrate tex1d texcmp +texcompress2 +texfilt texgenmix texline texobjshare texrect texwrap +vao-01 +vao-02 vparray vptest1 vptest2 @@ -59,4 +78,6 @@ vptorus vpwarpmesh yuvrect yuvsquare +zcomp +zdrawpix zreaddraw diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index aafc4a7291..30f03e9103 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -14,6 +14,7 @@ fs-tri line line-clip line-cull +line-smooth line-stipple-wide line-userclip line-userclip-clip @@ -33,6 +34,7 @@ point-clip point-param point-sprite point-wide +point-wide-smooth poly poly-flat poly-unfilled @@ -77,6 +79,7 @@ tri-flat tri-flat-clip tri-fog tri-mask-tri +tri-orig tri-query tri-scissor-tri tri-stencil @@ -84,6 +87,7 @@ tri-tex-3d tri-tri tri-unfilled tri-unfilled-clip +tri-unfilled-edgeflag tri-unfilled-smooth tri-unfilled-userclip tri-unfilled-userclip-stip diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore index 250bc17d98..34551101cb 100644 --- a/progs/xdemos/.gitignore +++ b/progs/xdemos/.gitignore @@ -13,6 +13,7 @@ offset overlay pbdemo pbinfo +sharedtex texture_from_pixmap wincopy xdemo -- cgit v1.2.3 From e8d5be9c76b08ba423e3c635aae5178f2358169a Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 24 Oct 2007 13:55:22 -0600 Subject: fix assorted bugs, works now (cherry picked from commit 55d4f32fc211dbc37bd28c0e67da5ce5e0da5777) --- progs/demos/streaming_rect.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'progs') diff --git a/progs/demos/streaming_rect.c b/progs/demos/streaming_rect.c index 86e00803c0..4c1d8535fd 100644 --- a/progs/demos/streaming_rect.c +++ b/progs/demos/streaming_rect.c @@ -1,13 +1,9 @@ - /* - * GL_ARB_multitexture demo + * GL_ARB_pixel_buffer_object test * * Command line options: - * -info print GL implementation information - * + * -w WIDTH -h HEIGHT sets window size * - * Brian Paul November 1998 This program is in the public domain. - * Modified on 12 Feb 2002 for > 2 texture units. */ #define GL_GLEXT_PROTOTYPES @@ -25,6 +21,8 @@ #define PBO 11 #define QUIT 100 +static GLuint DrawPBO; + static GLboolean Animate = GL_TRUE; static GLboolean use_pbo = 1; static GLboolean whole_rect = 1; @@ -49,7 +47,7 @@ static void Idle( void ) } } -static int max( int a, int b ) { return a > b ? a : b; } +/*static int max( int a, int b ) { return a > b ? a : b; }*/ static int min( int a, int b ) { return a < b ? a : b; } static void DrawObject() @@ -62,6 +60,7 @@ static void DrawObject() * release the old copy of the texture and allocate a new one * without waiting for outstanding rendering to complete. */ + glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO); glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, size, NULL, GL_STREAM_DRAW_ARB); { @@ -69,7 +68,7 @@ static void DrawObject() printf("char %d\n", (unsigned char)(Drift * 255)); - memset(image, size, (unsigned char)(Drift * 255)); + memset(image, (unsigned char)(Drift * 255), size); glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT); } @@ -86,7 +85,9 @@ static void DrawObject() if (image == NULL) image = malloc(size); - memset(image, size, (unsigned char)(Drift * 255)); + glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); + + memset(image, (unsigned char)(Drift * 255), size); /* BGRA should be the fast path for regular uploads as well. */ @@ -227,12 +228,12 @@ static void SpecialKey( int key, int x, int y ) static void Init( int argc, char *argv[] ) { const char *exten = (const char *) glGetString(GL_EXTENSIONS); - GLuint texObj, DrawPBO; + GLuint texObj; GLint size; - if (!strstr(exten, "GL_ARB_multitexture")) { - printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n"); + if (!strstr(exten, "GL_ARB_pixel_buffer_object")) { + printf("Sorry, GL_ARB_pixel_buffer_object not supported by this renderer.\n"); exit(1); } -- cgit v1.2.3