diff options
author | Brian Paul <[email protected]> | 2008-10-07 16:24:43 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2008-10-07 16:24:43 -0600 |
commit | b99c39ea7bf7ff3d6c0fe8599ce25a6b6bf154fd (patch) | |
tree | 6079dfa1928c8d4d7a8d6e2510f7ae8c711bf45c /progs/glsl | |
parent | 800c350d71132bbb5126bd89310df540332978f4 (diff) |
mesa: use the shaderutil.c helper functions
Diffstat (limited to 'progs/glsl')
-rw-r--r-- | progs/glsl/Makefile | 7 | ||||
-rw-r--r-- | progs/glsl/identity.c | 94 |
2 files changed, 17 insertions, 84 deletions
diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index eacd6dfe098..04c1d25ed7f 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 a2a19915297..dce140fc640 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 <GL/glut.h> #include <GL/glext.h> #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);*/ |