From 414a933ad24e11e9655dc00ae55d8753f2021fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 19 Oct 2007 11:37:45 +0100 Subject: Ignore generated files. --- progs/glsl/.gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 progs/glsl/.gitignore (limited to 'progs/glsl') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore new file mode 100644 index 0000000000..622e0417a8 --- /dev/null +++ b/progs/glsl/.gitignore @@ -0,0 +1,10 @@ +brick +bump +deriv +extfuncs.h +mandelbrot +noise +readtex.c +readtex.h +texdemo1 +toyball -- cgit v1.2.3 From b86cf714916d1bfdd6152839a8753cb3f3039cb2 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 16 May 2008 16:02:52 -0600 Subject: mesa: call glutDestroyWindow() on exit to help find mem leaks --- progs/glsl/texdemo1.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'progs/glsl') diff --git a/progs/glsl/texdemo1.c b/progs/glsl/texdemo1.c index d29ecf452b..3ceae14b96 100644 --- a/progs/glsl/texdemo1.c +++ b/progs/glsl/texdemo1.c @@ -48,6 +48,7 @@ static GLfloat TexXrot = 0, TexYrot = 0; static GLfloat Xrot = 20.0, Yrot = 20.0, Zrot = 0.0; static GLfloat EyeDist = 10; static GLboolean Anim = GL_TRUE; +static int win = 0; struct uniform_info { @@ -177,6 +178,7 @@ key(unsigned char k, int x, int y) EyeDist = 90; break; case 27: + glutDestroyWindow(win); exit(0); } glutPostRedisplay(); @@ -554,7 +556,7 @@ main(int argc, char *argv[]) glutInit(&argc, argv); glutInitWindowSize(500, 400); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); - glutCreateWindow(Demo); + win = glutCreateWindow(Demo); glutReshapeFunc(Reshape); glutKeyboardFunc(key); glutSpecialFunc(specialkey); -- cgit v1.2.3 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/glsl') 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 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 + 1 file changed, 1 insertion(+) (limited to 'progs/glsl') 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 -- cgit v1.2.3 From 4d38d86b2c5e572b1ea5ff4a5a84acb7ab5b87fc Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 16 Jun 2008 13:19:41 -0400 Subject: add edge detection to that example --- progs/glsl/convolutions.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'progs/glsl') diff --git a/progs/glsl/convolutions.c b/progs/glsl/convolutions.c index be887714c4..9b9ee53245 100644 --- a/progs/glsl/convolutions.c +++ b/progs/glsl/convolutions.c @@ -12,6 +12,7 @@ enum Filter { SHARPEN, MEAN_REMOVAL, EMBOSS, + EDGE_DETECT, NO_FILTER, LAST }; @@ -146,6 +147,17 @@ static void fillConvolution(GLint *k, color[2] = 0.5; color[3] = 0.5; break; + case EDGE_DETECT: + k[0] = 1; k[1] = 1; k[2] = 1; + k[3] = 0; k[4] = 0; k[5] = 0; + k[6] = -1; k[7] = -1; k[8] = -1; + + *scale = 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; @@ -294,6 +306,7 @@ static void menuInit() glutAddMenuEntry("Sharpen", SHARPEN); glutAddMenuEntry("Mean removal", MEAN_REMOVAL); glutAddMenuEntry("Emboss", EMBOSS); + glutAddMenuEntry("Edge detect", EDGE_DETECT); glutAddMenuEntry("None", NO_FILTER); glutAddMenuEntry("Quit", QUIT); -- cgit v1.2.3 From 90c93bbeeec1a8ca75b68004afc5d8cb689860bc Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 11 Sep 2008 11:00:54 -0600 Subject: define new APP_CC configuration variable for building apps/demos/tests For Cell, need to use different compilers for the libraries vs. the demos/tests to avoid strange link error regarding "_Unwind_GetIPInfo@GCC_4.2.0" --- progs/glsl/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index b9cae66815..9c1d3f8126 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -26,7 +26,7 @@ PROGS = \ # make executable from .c file: .c: $(LIB_DEP) - $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@ ##### TARGETS ##### @@ -47,7 +47,7 @@ readtex.h: $(TOP)/progs/util/readtex.h cp $< . readtex.o: readtex.c readtex.h - $(CC) -c -I$(INCDIR) $(CFLAGS) readtex.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) readtex.c brick.c: extfuncs.h @@ -58,16 +58,16 @@ mandelbrot.c: extfuncs.h toyball.c: extfuncs.h texdemo1: texdemo1.o readtex.o - $(CC) -I$(INCDIR) $(CFLAGS) texdemo1.o readtex.o $(APP_LIB_DEPS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) texdemo1.o readtex.o $(APP_LIB_DEPS) -o $@ texdemo1.o: texdemo1.c readtex.h extfuncs.h - $(CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c convolutions: convolutions.o readtex.o - $(CC) -I$(INCDIR) $(CFLAGS) convolutions.o readtex.o $(APP_LIB_DEPS) -o $@ + $(APP_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 + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c clean: -- cgit v1.2.3 From 52a9dfd4feae7d5d20519d48e72f3e38de4e2332 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 12 Sep 2008 10:02:16 +0100 Subject: use APP_CC, remove redundant target --- progs/glsl/Makefile | 67 ++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 37 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 5cb2a044c7..9999d6c08a 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -24,8 +24,7 @@ PROGS = \ toyball \ twoside \ trirast \ - texdemo1 \ - convolutions + texdemo1 ##### RULES ##### @@ -68,113 +67,107 @@ shaderutil.h: $(TOP)/progs/util/shaderutil.h cp $< . shaderutil.o: shaderutil.c shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) shaderutil.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) shaderutil.c bitmap.o: bitmap.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) bitmap.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bitmap.c bitmap: bitmap.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bitmap.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bitmap.o shaderutil.o $(LIBS) -o $@ brick.o: brick.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) brick.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) brick.c brick: brick.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) brick.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) brick.o shaderutil.o $(LIBS) -o $@ bump.o: bump.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) bump.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bump.c bump: bump.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bump.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bump.o shaderutil.o $(LIBS) -o $@ convolutions.o: convolutions.c readtex.h - $(CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c convolutions: convolutions.o readtex.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) convolutions.o readtex.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) convolutions.o readtex.o $(LIBS) -o $@ deriv.o: deriv.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) deriv.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) deriv.c deriv: deriv.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) deriv.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) deriv.o shaderutil.o $(LIBS) -o $@ mandelbrot.o: mandelbrot.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c mandelbrot: mandelbrot.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) mandelbrot.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) mandelbrot.o shaderutil.o $(LIBS) -o $@ multitex.o: multitex.c extfuncs.h readtex.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) multitex.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) multitex.c multitex: multitex.o readtex.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) multitex.o readtex.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) multitex.o readtex.o shaderutil.o $(LIBS) -o $@ noise.o: noise.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) noise.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) noise.c noise: noise.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise.o shaderutil.o $(LIBS) -o $@ points.o: points.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) points.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) points.c points: points.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) points.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) points.o shaderutil.o $(LIBS) -o $@ pointcoord.o: pointcoord.c readtex.h extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) pointcoord.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) pointcoord.c pointcoord: pointcoord.o readtex.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) pointcoord.o readtex.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) pointcoord.o readtex.o shaderutil.o $(LIBS) -o $@ texdemo1.o: texdemo1.c readtex.h extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c texdemo1: texdemo1.o readtex.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) texdemo1.o readtex.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) texdemo1.o readtex.o shaderutil.o $(LIBS) -o $@ toyball.o: toyball.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) toyball.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) toyball.c toyball: toyball.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) toyball.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) toyball.o shaderutil.o $(LIBS) -o $@ twoside.o: twoside.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) twoside.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) twoside.c twoside: twoside.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) twoside.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) twoside.o shaderutil.o $(LIBS) -o $@ trirast.o: trirast.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) trirast.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) trirast.c trirast: trirast.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ -convolutions: convolutions.o readtex.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) convolutions.o readtex.o $(APP_LIB_DEPS) -o $@ - -convolutions.o: convolutions.c readtex.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c - clean: -rm -f $(PROGS) -- cgit v1.2.3 From 4485ac87c2cf69bef443ac36cccaa70054c6a7bb Mon Sep 17 00:00:00 2001 From: Robert Ellison Date: Thu, 18 Sep 2008 16:36:37 -0600 Subject: CELL: mark several transient files as .gitignore progs/demos: added new demo "fbo_firecube" progs/glsl: added new demo "pointcoord" src/gallium/drivers/cell/spu: added the g3d_spu executable, a Cell SPU executable file, which seems to be occasionally built as part of the cell driver src/glu/sgi: added "exptmp", a byproduct of the "mklib" process that sometimes gets deleted and sometimes not. --- progs/glsl/.gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'progs/glsl') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 09340ff2ad..978e31c6cc 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -7,6 +7,7 @@ extfuncs.h mandelbrot multitex noise +pointcoord points readtex.c readtex.h -- cgit v1.2.3 From 4ccbee24391823cc559bbb341f62fa375af864f7 Mon Sep 17 00:00:00 2001 From: Stephane Marchesin Date: Tue, 7 Oct 2008 21:21:20 +0200 Subject: Progs: add a trivial glsl test, useful for gallium driver bringup/debug. --- progs/glsl/identity.c | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 progs/glsl/identity.c (limited to 'progs/glsl') diff --git a/progs/glsl/identity.c b/progs/glsl/identity.c new file mode 100644 index 0000000000..a2a1991529 --- /dev/null +++ b/progs/glsl/identity.c @@ -0,0 +1,282 @@ +/** + * Test very basic glsl functionality (identity vertex and fragment shaders). + * Brian Paul + * 2 May 2007 + * + * NOTE: resize the window to observe how the partial derivatives of + * the texcoords change. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "extfuncs.h" + + +static char *FragProgFile = NULL; +static char *VertProgFile = NULL; +static GLuint fragShader; +static GLuint vertShader; +static GLuint program; +static GLint win = 0; +static GLboolean anim = GL_TRUE; +static GLfloat xRot = 0.0f, yRot = 0.0f; +static int w,h; + +static void +Redisplay(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + glColor3f(.8,0,0); + glVertex3f(-0.9, -0.9, 0.0); + glColor3f(0,.9,0); + glVertex3f( 0.9, -0.9, 0.0); + glColor3f(0,0,.7); + glVertex3f( 0.0, 0.9, 0.0); + glEnd(); + + glutSwapBuffers(); +} + + +static void +Idle(void) +{ + yRot = glutGet(GLUT_ELAPSED_TIME) * 0.1; + glutPostRedisplay(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + w = width; + h = height; +} + + +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 ' ': + case 'a': + anim = !anim; + if (anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 27: + CleanUp(); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +SpecialKey(int key, int x, int y) +{ + const GLfloat step = 3.0f; + + (void) x; + (void) y; + + switch(key) { + case GLUT_KEY_UP: + xRot -= step; + break; + case GLUT_KEY_DOWN: + xRot += step; + break; + case GLUT_KEY_LEFT: + yRot -= step; + break; + case GLUT_KEY_RIGHT: + yRot += step; + break; + } + glutPostRedisplay(); +} + + + + +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 = + "void main() {\n" + " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n" + "}\n"; + static const char *vertShaderText = + "void main() {\n" + " gl_Position = gl_Vertex;\n" + "}\n"; + const char *version; + + 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); + } + + 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); + + /*assert(glGetError() == 0);*/ + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + glEnable(GL_DEPTH_TEST); + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + assert(glIsProgram_func(program)); + assert(glIsShader_func(fragShader)); + assert(glIsShader_func(vertShader)); + + glColor3f(1, 0, 0); +} + + +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(200, 200); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Redisplay); + if (anim) + glutIdleFunc(Idle); + ParseOptions(argc, argv); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 6f29c2ff2dc4b3aefe282133376caed68b65a3d0 Mon Sep 17 00:00:00 2001 From: Stephane Marchesin Date: Tue, 7 Oct 2008 23:42:36 +0200 Subject: Progs: hook the glsl identity example into the makefile. --- progs/glsl/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 9999d6c08a..eacd6dfe09 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -15,6 +15,7 @@ PROGS = \ bump \ convolutions \ deriv \ + identity \ mandelbrot \ multitex \ noise \ -- cgit v1.2.3 From b99c39ea7bf7ff3d6c0fe8599ce25a6b6bf154fd Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 7 Oct 2008 16:24:43 -0600 Subject: mesa: use the shaderutil.c helper functions --- progs/glsl/Makefile | 7 ++++ progs/glsl/identity.c | 94 ++++++--------------------------------------------- 2 files changed, 17 insertions(+), 84 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index eacd6dfe09..04c1d25ed7 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -107,6 +107,13 @@ deriv: deriv.o shaderutil.o $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) deriv.o shaderutil.o $(LIBS) -o $@ +identity.o: identity.c extfuncs.h shaderutil.h + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) identity.c + +identity: identity.o shaderutil.o + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) identity.o shaderutil.o $(LIBS) -o $@ + + mandelbrot.o: mandelbrot.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c diff --git a/progs/glsl/identity.c b/progs/glsl/identity.c index a2a1991529..dce140fc64 100644 --- a/progs/glsl/identity.c +++ b/progs/glsl/identity.c @@ -1,10 +1,6 @@ /** * Test very basic glsl functionality (identity vertex and fragment shaders). - * Brian Paul - * 2 May 2007 - * - * NOTE: resize the window to observe how the partial derivatives of - * the texcoords change. + * Brian Paul & Stephane Marchesin */ @@ -17,6 +13,7 @@ #include #include #include "extfuncs.h" +#include "shaderutil.h" static char *FragProgFile = NULL; @@ -29,6 +26,7 @@ static GLboolean anim = GL_TRUE; static GLfloat xRot = 0.0f, yRot = 0.0f; static int w,h; + static void Redisplay(void) { @@ -128,69 +126,6 @@ SpecialKey(int key, int x, int y) } - - -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) { @@ -202,33 +137,24 @@ Init(void) "void main() {\n" " gl_Position = gl_Vertex;\n" "}\n"; - const char *version; - version = (const char *) glGetString(GL_VERSION); - if (version[0] != '2' || version[1] != '.') { - printf("This program requires OpenGL 2.x, found %s\n", version); + if (!ShadersSupported()) exit(1); - } GetExtensionFuncs(); - fragShader = glCreateShader_func(GL_FRAGMENT_SHADER); if (FragProgFile) - ReadShader(fragShader, FragProgFile); + fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile); else - LoadAndCompileShader(fragShader, fragShaderText); + fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText); - vertShader = glCreateShader_func(GL_VERTEX_SHADER); if (VertProgFile) - ReadShader(vertShader, VertProgFile); + vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile); else - LoadAndCompileShader(vertShader, vertShaderText); + vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText); + + program = LinkShaders(vertShader, fragShader); - program = glCreateProgram_func(); - glAttachShader_func(program, fragShader); - glAttachShader_func(program, vertShader); - glLinkProgram_func(program); - CheckLink(program); glUseProgram_func(program); /*assert(glGetError() == 0);*/ -- cgit v1.2.3 From b3a68b24bd601a4fcffb701bbd73864ed92a05e1 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 10 Oct 2008 12:04:49 -0600 Subject: replace 1.0/sqrt() with inversesqrt() --- progs/glsl/CH11-bumpmap.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs/glsl') diff --git a/progs/glsl/CH11-bumpmap.frag b/progs/glsl/CH11-bumpmap.frag index 063576f5a3..e12c5d374c 100644 --- a/progs/glsl/CH11-bumpmap.frag +++ b/progs/glsl/CH11-bumpmap.frag @@ -24,7 +24,7 @@ void main() float d, f; d = p.x * p.x + p.y * p.y; - f = 1.0 / sqrt(d + 1.0); + f = inversesqrt(d + 1.0); if (d >= BumpSize) { p = vec2(0.0); f = 1.0; } -- cgit v1.2.3 From 0a8590e3cf9e9f671405343bcd1dc756a7296fc3 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 28 Oct 2008 18:18:31 -0600 Subject: mesa: don't continually redraw --- progs/glsl/identity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs/glsl') diff --git a/progs/glsl/identity.c b/progs/glsl/identity.c index dce140fc64..37579eb346 100644 --- a/progs/glsl/identity.c +++ b/progs/glsl/identity.c @@ -22,7 +22,7 @@ static GLuint fragShader; static GLuint vertShader; static GLuint program; static GLint win = 0; -static GLboolean anim = GL_TRUE; +static GLboolean anim = GL_FALSE; static GLfloat xRot = 0.0f, yRot = 0.0f; static int w,h; -- cgit v1.2.3 From 2c204bbf7749ed0517c5826e2aae66997a0c4623 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 5 Nov 2008 17:14:23 -0700 Subject: use APP_CC, not CC for skinning demo --- progs/glsl/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 0874cfc59e..c5d62d2370 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -150,10 +150,10 @@ pointcoord: pointcoord.o readtex.o shaderutil.o skinning.o: skinning.c readtex.h extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) skinning.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) skinning.c skinning: skinning.o readtex.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) skinning.o readtex.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) skinning.o readtex.o shaderutil.o $(LIBS) -o $@ texdemo1.o: texdemo1.c readtex.h extfuncs.h shaderutil.h -- cgit v1.2.3 From 51af35b7cc412b48d7753d94a7bdf72f435b16c9 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 24 Nov 2008 20:05:47 +0100 Subject: progs: Add ignores --- progs/glsl/.gitignore | 2 ++ 1 file changed, 2 insertions(+) (limited to 'progs/glsl') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 978e31c6cc..6cc7edc019 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -4,6 +4,7 @@ bump convolutions deriv extfuncs.h +identity mandelbrot multitex noise @@ -13,6 +14,7 @@ readtex.c readtex.h shaderutil.c shaderutil.h +skinning texdemo1 toyball trirast -- cgit v1.2.3 From 80301866f613960850ebd872a08e8fb03c4760c1 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 21 Nov 2008 10:03:19 -0700 Subject: added progs/demos/fragcoord.c - tests gl_FragCoord attribute in fragment shader Fragment's red/greenb/blue is a function gl_FragCoord.xyz --- progs/glsl/Makefile | 8 +++ progs/glsl/fragcoord.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 progs/glsl/fragcoord.c (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index c5d62d2370..9f5a2b7df5 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -16,6 +16,7 @@ PROGS = \ convolutions \ deriv \ identity \ + fragcoord \ mandelbrot \ multitex \ noise \ @@ -115,6 +116,13 @@ identity: identity.o shaderutil.o $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) identity.o shaderutil.o $(LIBS) -o $@ +fragcoord.o: fragcoord.c extfuncs.h shaderutil.h + $(CC) -c -I$(INCDIR) $(CFLAGS) fragcoord.c + +fragcoord: fragcoord.o shaderutil.o + $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) fragcoord.o shaderutil.o $(LIBS) -o $@ + + mandelbrot.o: mandelbrot.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c diff --git a/progs/glsl/fragcoord.c b/progs/glsl/fragcoord.c new file mode 100644 index 0000000000..0b7561f3e4 --- /dev/null +++ b/progs/glsl/fragcoord.c @@ -0,0 +1,185 @@ +/** + * Test GLSL gl_FragCoord fragment program attribute. + * Color the quad's fragments according to their window position. + * + * Brian Paul + * 20 Nov 2008 + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "extfuncs.h" +#include "shaderutil.h" + + +static GLint WinWidth = 200, WinHeight = 200; +static char *FragProgFile = NULL; +static char *VertProgFile = NULL; +static GLuint fragShader; +static GLuint vertShader; +static GLuint program; +static GLint win = 0; +static GLboolean Anim = GL_TRUE; +static GLfloat PosX = 0.0, PosY = 0.0; + + +static void +Idle(void) +{ + float r = (WinWidth < WinHeight) ? WinWidth : WinHeight; + float a = glutGet(GLUT_ELAPSED_TIME) * 0.001; + r *= 0.25; + PosX = WinWidth / 2 + r * cos(a); + PosY = WinHeight / 2 + r * sin(a); + + glutPostRedisplay(); +} + + +static void +Redisplay(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + glTranslatef(PosX, PosY, 0.0); +#if 0 + glBegin(GL_POLYGON); + glVertex2f(-50, -50); + glVertex2f( 50, -50); + glVertex2f( 50, 50); + glVertex2f(-50, 50); + glEnd(); +#else + glutSolidSphere(50, 20, 10); +#endif + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, 0, height, -55, 55); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + WinWidth = width; + WinHeight = height; +} + + +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 ' ': + case 'a': + Anim = !Anim; + glutIdleFunc(Anim ? Idle : NULL); + break; + case 27: + CleanUp(); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +Init(void) +{ + static const char *fragShaderText = + "void main() { \n" + " vec4 scale = vec4(.005, 0.005, 0.5, 1.0);\n" + " gl_FragColor = gl_FragCoord * scale; \n" + "}\n"; + static const char *vertShaderText = + "void main() {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + "}\n"; + + if (!ShadersSupported()) + exit(1); + + GetExtensionFuncs(); + + vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText); + fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText); + program = LinkShaders(vertShader, fragShader); + + glUseProgram_func(program); + + /*assert(glGetError() == 0);*/ + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + assert(glIsProgram_func(program)); + assert(glIsShader_func(fragShader)); + assert(glIsShader_func(vertShader)); + + glColor3f(1, 0, 0); +} + + +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(WinWidth, WinHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Redisplay); + ParseOptions(argc, argv); + Init(); + glutIdleFunc(Anim ? Idle : NULL); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 77762801bc260d1e9f43f684c35f4546350fc76d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 24 Nov 2008 14:31:41 -0700 Subject: remove some redundant rules from prev merge --- progs/glsl/Makefile | 7 ------- 1 file changed, 7 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 5419dfc7f4..9f5a2b7df5 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -123,13 +123,6 @@ fragcoord: fragcoord.o shaderutil.o $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) fragcoord.o shaderutil.o $(LIBS) -o $@ -fragcoord.o: fragcoord.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) fragcoord.c - -fragcoord: fragcoord.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) fragcoord.o shaderutil.o $(LIBS) -o $@ - - mandelbrot.o: mandelbrot.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c -- cgit v1.2.3 From 25eee19cd6e13b6682f4078681a367849c4a0fd5 Mon Sep 17 00:00:00 2001 From: Younes Manton Date: Tue, 2 Dec 2008 00:23:30 -0500 Subject: mesa: Update some .gitignore files. --- progs/glsl/.gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'progs/glsl') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 6cc7edc019..d5d9d915b6 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -4,6 +4,7 @@ bump convolutions deriv extfuncs.h +fragcoord identity mandelbrot multitex -- cgit v1.2.3 From e8a1b31ddf39f0b09eb85653cebb9808a5daf0a9 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Mon, 8 Dec 2008 15:03:29 +0000 Subject: fix conflict breakage --- progs/glsl/Makefile | 4 ---- 1 file changed, 4 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index ce82468168..488a4e9951 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -189,9 +189,6 @@ trirast.o: trirast.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) trirast.c trirast: trirast.o shaderutil.o -<<<<<<< HEAD:progs/glsl/Makefile - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ -======= $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ @@ -201,7 +198,6 @@ vert-tex.o: vert-tex.c extfuncs.h shaderutil.h vert-tex: vert-tex.o shaderutil.o $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-tex.o shaderutil.o $(LIBS) -o $@ ->>>>>>> origin/master:progs/glsl/Makefile -- cgit v1.2.3 From bde3b3a16487a3939b732e9fd53b6e347fa2f94b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Dec 2008 13:58:31 -0700 Subject: demos: add test of vertex-only and fragment-only shader programs --- progs/glsl/Makefile | 9 ++ progs/glsl/vert-or-frag-only.c | 191 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 progs/glsl/vert-or-frag-only.c (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 71ca0af941..d21dcb6560 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -28,6 +28,7 @@ PROGS = \ toyball \ twoside \ trirast \ + vert-or-frag-only \ vert-tex @@ -193,6 +194,14 @@ trirast: trirast.o shaderutil.o $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ +vert-or-frag-only.o: vert-or-frag-only.c extfuncs.h shaderutil.h + $(CC) -c -I$(INCDIR) $(CFLAGS) vert-or-frag-only.c + +vert-or-frag-only: vert-or-frag-only.o shaderutil.o + $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-or-frag-only.o shaderutil.o $(LIBS) -o $@ + + + vert-tex.o: vert-tex.c extfuncs.h shaderutil.h $(CC) -c -I$(INCDIR) $(CFLAGS) vert-tex.c diff --git a/progs/glsl/vert-or-frag-only.c b/progs/glsl/vert-or-frag-only.c new file mode 100644 index 0000000000..f6eedd8327 --- /dev/null +++ b/progs/glsl/vert-or-frag-only.c @@ -0,0 +1,191 @@ +/** + * Draw two quads, one using only a vertex shader, the other only with a + * fragment shader. They should appear the same. + * 17 Dec 2008 + * Brian Paul + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "extfuncs.h" +#include "shaderutil.h" + + +static char *FragProgFile = NULL; +static char *VertProgFile = NULL; +static GLuint FragShader; +static GLuint VertShader; +static GLuint VertProgram; /* w/out vertex shader */ +static GLuint FragProgram; /* w/out fragment shader */ +static GLint Win = 0; + + +static void +DrawQuadColor(void) +{ + glBegin(GL_QUADS); + glColor3f(1, 0, 0); glVertex2f(-1, -1); + glColor3f(0, 1, 0); glVertex2f( 1, -1); + glColor3f(0, 0, 1); glVertex2f( 1, 1); + glColor3f(1, 0, 1); glVertex2f(-1, 1); + glEnd(); +} + + +/** as above, but specify color via texcoords */ +static void +DrawQuadTex(void) +{ + glBegin(GL_QUADS); + glTexCoord3f(1, 0, 0); glVertex2f(-1, -1); + glTexCoord3f(0, 1, 0); glVertex2f( 1, -1); + glTexCoord3f(0, 0, 1); glVertex2f( 1, 1); + glTexCoord3f(1, 0, 1); glVertex2f(-1, 1); + glEnd(); +} + + +static void +Redisplay(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + /* render with vertex shader only */ + glUseProgram_func(VertProgram); + glPushMatrix(); + glTranslatef(-1.5, 0, 0); + DrawQuadTex(); + glPopMatrix(); + + /* render with fragment shader only */ + glUseProgram_func(FragProgram); + glPushMatrix(); + glTranslatef(+1.5, 0, 0); + DrawQuadColor(); + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-4, 4, -2, 2, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +CleanUp(void) +{ + glDeleteShader_func(FragShader); + glDeleteShader_func(VertShader); + glDeleteProgram_func(VertProgram); + glDeleteProgram_func(FragProgram); + 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 +Init(void) +{ + static const char *fragShaderText = + "void main() {\n" + " gl_FragColor = gl_Color;\n" + "}\n"; + static const char *vertShaderText = + "void main() {\n" + " gl_Position = ftransform();\n" + " gl_FrontColor = gl_MultiTexCoord0;\n" /* see DrawQuadTex() */ + "}\n"; + + if (!ShadersSupported()) + exit(1); + + GetExtensionFuncs(); + + if (FragProgFile) + FragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile); + else + FragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText); + + if (VertProgFile) + VertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile); + else + VertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText); + + VertProgram = LinkShaders(VertShader, 0); + FragProgram = LinkShaders(0, FragShader); + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + glEnable(GL_DEPTH_TEST); + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + assert(glIsProgram_func(VertProgram)); + assert(glIsProgram_func(FragProgram)); + assert(glIsShader_func(FragShader)); + assert(glIsShader_func(VertShader)); + + glColor3f(1, 0, 0); +} + + +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, 200); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Redisplay); + ParseOptions(argc, argv); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From aae74c36982b98f1f54a12a6512f78006bf4fd0d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 19 Dec 2008 07:57:09 -0700 Subject: mesa: s/CC/APP_CC/ in progs/glsl/Makefile --- progs/glsl/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index d21dcb6560..0849223cd8 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -191,22 +191,22 @@ trirast.o: trirast.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) trirast.c trirast: trirast.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ vert-or-frag-only.o: vert-or-frag-only.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) vert-or-frag-only.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-or-frag-only.c vert-or-frag-only: vert-or-frag-only.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-or-frag-only.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-or-frag-only.o shaderutil.o $(LIBS) -o $@ vert-tex.o: vert-tex.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) vert-tex.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-tex.c vert-tex: vert-tex.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-tex.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-tex.o shaderutil.o $(LIBS) -o $@ -- cgit v1.2.3 From 84cffc2e7fbeab8ed5dfb0b6b8d3829e0654ab02 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 2 Jan 2009 16:52:00 -0700 Subject: mesa: replace CC with APP_CC in progs/glsl/Makefile --- progs/glsl/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 9c31ef67b0..4d4da31dc1 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -120,10 +120,10 @@ identity: identity.o shaderutil.o fragcoord.o: fragcoord.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) fragcoord.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) fragcoord.c fragcoord: fragcoord.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) fragcoord.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) fragcoord.o shaderutil.o $(LIBS) -o $@ mandelbrot.o: mandelbrot.c extfuncs.h shaderutil.h @@ -161,10 +161,10 @@ pointcoord: pointcoord.o readtex.o shaderutil.o samplers.o: samplers.c readtex.h extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) samplers.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) samplers.c samplers: samplers.o readtex.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers.o readtex.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers.o readtex.o shaderutil.o $(LIBS) -o $@ skinning.o: skinning.c readtex.h extfuncs.h shaderutil.h @@ -211,10 +211,10 @@ vert-or-frag-only: vert-or-frag-only.o shaderutil.o vert-or-frag-only.o: vert-or-frag-only.c extfuncs.h shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) vert-or-frag-only.c + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-or-frag-only.c vert-or-frag-only: vert-or-frag-only.o shaderutil.o - $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-or-frag-only.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-or-frag-only.o shaderutil.o $(LIBS) -o $@ -- cgit v1.2.3 From fa4fec2d1bfa459d46601b2f1e104b9533bf679f Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 23 Dec 2008 15:46:25 -0600 Subject: demos: remove redundant Makefile lines from prev merge --- progs/glsl/Makefile | 8 -------- 1 file changed, 8 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 4d4da31dc1..69e15398dc 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -210,14 +210,6 @@ vert-or-frag-only: vert-or-frag-only.o shaderutil.o -vert-or-frag-only.o: vert-or-frag-only.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-or-frag-only.c - -vert-or-frag-only: vert-or-frag-only.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-or-frag-only.o shaderutil.o $(LIBS) -o $@ - - - vert-tex.o: vert-tex.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-tex.c -- cgit v1.2.3 From b2e9d415ed56b856289f4e815cc9c56e8b0cc401 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 5 Jan 2009 11:49:45 +0100 Subject: progs/glsl: Remove double target def for vert-or-frag-only --- progs/glsl/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 69e15398dc..a39170b8c9 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -209,7 +209,6 @@ vert-or-frag-only: vert-or-frag-only.o shaderutil.o $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-or-frag-only.o shaderutil.o $(LIBS) -o $@ - vert-tex.o: vert-tex.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-tex.c -- cgit v1.2.3 From 5256f94b1a64f9bb61ec2b627a71ff9a0fc7a484 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 5 Jan 2009 11:50:57 +0100 Subject: progs/glsl: Add ignores --- progs/glsl/.gitignore | 2 ++ 1 file changed, 2 insertions(+) (limited to 'progs/glsl') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 5d954519b2..40df5bb978 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -21,3 +21,5 @@ texdemo1 toyball trirast twoside +vert-or-frag-only +vert-tex -- cgit v1.2.3 From 6cee4b8d7ec8d9ab6cb04572a2203e2cff64c667 Mon Sep 17 00:00:00 2001 From: Younes Manton Date: Sat, 10 Jan 2009 14:11:30 -0500 Subject: mesa: Update .gitignore --- progs/glsl/.gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'progs/glsl') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 40df5bb978..04b679c521 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -14,6 +14,7 @@ pointcoord points readtex.c readtex.h +samplers shaderutil.c shaderutil.h skinning -- cgit v1.2.3 From e82784559e00cb534993c01309ad1832e9b3e56b Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Wed, 14 Jan 2009 17:01:16 +0000 Subject: mesa: add new samplers_array test --- progs/glsl/Makefile | 6 ++++++ progs/glsl/samplers.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) (limited to 'progs/glsl') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index a39170b8c9..7099eeadbd 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -24,6 +24,7 @@ PROGS = \ points \ pointcoord \ samplers \ + samplers_array \ skinning \ texdemo1 \ toyball \ @@ -166,6 +167,11 @@ samplers.o: samplers.c readtex.h extfuncs.h shaderutil.h samplers: samplers.o readtex.o shaderutil.o $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers.o readtex.o shaderutil.o $(LIBS) -o $@ +samplers_array.o: samplers.c readtex.h extfuncs.h shaderutil.h + $(APP_CC) -c -DSAMPLERS_ARRAY -I$(INCDIR) $(CFLAGS) samplers.c -o samplers_array.o + +samplers_array: samplers_array.o readtex.o shaderutil.o + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers_array.o readtex.o shaderutil.o $(LIBS) -o $@ skinning.o: skinning.c readtex.h extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) skinning.c diff --git a/progs/glsl/samplers.c b/progs/glsl/samplers.c index d214009729..3fb8577d5e 100644 --- a/progs/glsl/samplers.c +++ b/progs/glsl/samplers.c @@ -245,14 +245,22 @@ GenFragmentShader(GLint numSamplers) int s; p += sprintf(p, "// Generated fragment shader:\n"); +#ifndef SAMPLERS_ARRAY for (s = 0; s < numSamplers; s++) { p += sprintf(p, "uniform sampler2D tex%d;\n", s); } +#else + p += sprintf(p, "uniform sampler2D tex[%d];\n", numSamplers); +#endif p += sprintf(p, "void main()\n"); p += sprintf(p, "{\n"); p += sprintf(p, " vec4 color = vec4(0.0);\n"); for (s = 0; s < numSamplers; s++) { +#ifndef SAMPLERS_ARRAY p += sprintf(p, " color += texture2D(tex%d, gl_TexCoord[0].xy);\n", s); +#else + p += sprintf(p, " color += texture2D(tex[%d], gl_TexCoord[0].xy);\n", s); +#endif } p += sprintf(p, " gl_FragColor = color;\n"); p += sprintf(p, "}\n"); @@ -302,7 +310,11 @@ InitProgram(void) char uname[10]; GLint loc; +#ifndef SAMPLERS_ARRAY sprintf(uname, "tex%d", s); +#else + sprintf(uname, "tex[%d]", s); +#endif loc = glGetUniformLocation_func(Program, uname); assert(loc >= 0); -- cgit v1.2.3 From c14aac5530f3c9bf04f9b8dab3a3bae4362d216a Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 21 Jan 2009 15:01:13 +0100 Subject: progs: Ignores --- progs/glsl/.gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'progs/glsl') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 04b679c521..7a51c8cf6f 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -15,6 +15,7 @@ points readtex.c readtex.h samplers +samplers_array shaderutil.c shaderutil.h skinning -- cgit v1.2.3