summaryrefslogtreecommitdiff
path: root/progs/util
diff options
context:
space:
mode:
Diffstat (limited to 'progs/util')
-rw-r--r--progs/util/SConscript15
-rw-r--r--progs/util/descrip.mms42
-rw-r--r--progs/util/extfuncs.h115
-rw-r--r--progs/util/glutskel.c64
-rw-r--r--progs/util/readtex.c12
-rw-r--r--progs/util/shaderutil.c233
-rw-r--r--progs/util/shaderutil.h35
7 files changed, 394 insertions, 122 deletions
diff --git a/progs/util/SConscript b/progs/util/SConscript
new file mode 100644
index 0000000000..8ad2466291
--- /dev/null
+++ b/progs/util/SConscript
@@ -0,0 +1,15 @@
+Import('env')
+
+env = env.Clone()
+
+util = env.StaticLibrary(
+ target = ['util'],
+ source = [
+ 'readtex.c',
+ 'trackball.c',
+ 'showbuffer.c',
+ 'shaderutil.c',
+ ],
+)
+
+Export('util')
diff --git a/progs/util/descrip.mms b/progs/util/descrip.mms
deleted file mode 100644
index 21dec4b9be..0000000000
--- a/progs/util/descrip.mms
+++ /dev/null
@@ -1,42 +0,0 @@
-# Makefile for GLUT-based demo programs for VMS
-# contributed by Jouk Jansen joukj@crys.chem.uva.nl
-
-
-.first
- define gl [--.include.gl]
-
-.include [--]mms-config.
-
-##### MACROS #####
-
-INCDIR = ([--.include],[-.util])
-CFLAGS = /include=$(INCDIR)/prefix=all/name=(as_is,short)/float=ieee/ieee=denorm
-
-.ifdef SHARE
-GL_LIBS = $(XLIBS)
-LIB_DEP = [--.lib]$(GL_SHAR) [--.lib]$(GLU_SHAR) [--.lib]$(GLUT_SHAR)
-.else
-GL_LIBS = [--.lib]libGLUT/l,libMesaGLU/l,libMesaGL/l,$(XLIBS)
-LIB_DEP = [--.lib]$(GL_LIB) [--.lib]$(GLU_LIB) [--.lib]$(GLUT_LIB)
-.endif
-
-
-OBJS =readtex.obj,showbuffer.obj
-
-
-##### RULES #####
-.obj.exe :
- cxxlink $(MMS$TARGET_NAME),$(GL_LIBS)
-
-##### TARGETS #####
-default :
- $(MMS)$(MMSQUALIFIERS) $(OBJS)
-
-clean :
- delete *.obj;*
-
-realclean :
- delete *.obj;*
-
-readtex.obj : readtex.c
-showbuffer.obj : showbuffer.c
diff --git a/progs/util/extfuncs.h b/progs/util/extfuncs.h
index cf6b29d0e3..2bb57030a8 100644
--- a/progs/util/extfuncs.h
+++ b/progs/util/extfuncs.h
@@ -46,6 +46,13 @@ static PFNGLVERTEXATTRIB1FPROC glVertexAttrib1f_func = NULL;
static PFNGLVERTEXATTRIB2FPROC glVertexAttrib2f_func = NULL;
static PFNGLVERTEXATTRIB3FPROC glVertexAttrib3f_func = NULL;
static PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f_func = NULL;
+static PFNGLVERTEXATTRIB1FVPROC glVertexAttrib1fv_func = NULL;
+static PFNGLVERTEXATTRIB2FVPROC glVertexAttrib2fv_func = NULL;
+static PFNGLVERTEXATTRIB3FVPROC glVertexAttrib3fv_func = NULL;
+static PFNGLVERTEXATTRIB4FVPROC glVertexAttrib4fv_func = NULL;
+static PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer_func = NULL;
+static PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray_func = NULL;
+static PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray_func = NULL;
/* OpenGL 2.1 */
static PFNGLUNIFORMMATRIX2X3FVPROC glUniformMatrix2x3fv_func = NULL;
@@ -79,6 +86,56 @@ static PFNGLISVERTEXARRAYAPPLEPROC glIsVertexArrayAPPLE_func = NULL;
/* GL_EXT_stencil_two_side */
static PFNGLACTIVESTENCILFACEEXTPROC glActiveStencilFaceEXT_func = NULL;
+/* GL_ARB_buffer_object */
+static PFNGLGENBUFFERSARBPROC glGenBuffersARB_func = NULL;
+static PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB_func = NULL;
+static PFNGLBINDBUFFERARBPROC glBindBufferARB_func = NULL;
+static PFNGLBUFFERDATAARBPROC glBufferDataARB_func = NULL;
+static PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB_func = NULL;
+static PFNGLMAPBUFFERARBPROC glMapBufferARB_func = NULL;
+static PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB_func = NULL;
+
+/* GL_EXT_framebuffer_object */
+static PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT_func = NULL;
+static PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT_func = NULL;
+static PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT_func = NULL;
+static PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT_func = NULL;
+static PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT_func = NULL;
+static PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT_func = NULL;
+static PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT_func = NULL;
+static PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT_func = NULL;
+static PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT_func = NULL;
+static PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT_func = NULL;
+static PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT_func = NULL;
+static PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT_func = NULL;
+static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT_func = NULL;
+static PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT_func = NULL;
+
+/* GL_ARB_framebuffer_object */
+static PFNGLISRENDERBUFFERPROC glIsRenderbuffer_func = NULL;
+static PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer_func = NULL;
+static PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers_func = NULL;
+static PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers_func = NULL;
+static PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage_func = NULL;
+static PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv_func = NULL;
+static PFNGLISFRAMEBUFFERPROC glIsFramebuffer_func = NULL;
+static PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer_func = NULL;
+static PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers_func = NULL;
+static PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers_func = NULL;
+static PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D_func = NULL;
+static PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer_func = NULL;
+static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv_func = NULL;
+static PFNGLGENERATEMIPMAPPROC glGenerateMipmap_func = NULL;
+static PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer_func = NULL;
+static PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer_func = NULL;
+
static void
GetExtensionFuncs(void)
@@ -126,6 +183,14 @@ GetExtensionFuncs(void)
glVertexAttrib2f_func = (PFNGLVERTEXATTRIB2FPROC) glutGetProcAddress("glVertexAttrib2f");
glVertexAttrib3f_func = (PFNGLVERTEXATTRIB3FPROC) glutGetProcAddress("glVertexAttrib3f");
glVertexAttrib4f_func = (PFNGLVERTEXATTRIB4FPROC) glutGetProcAddress("glVertexAttrib4f");
+ glVertexAttrib1fv_func = (PFNGLVERTEXATTRIB1FVPROC) glutGetProcAddress("glVertexAttrib1fv");
+ glVertexAttrib2fv_func = (PFNGLVERTEXATTRIB2FVPROC) glutGetProcAddress("glVertexAttrib2fv");
+ glVertexAttrib3fv_func = (PFNGLVERTEXATTRIB3FVPROC) glutGetProcAddress("glVertexAttrib3fv");
+ glVertexAttrib4fv_func = (PFNGLVERTEXATTRIB4FVPROC) glutGetProcAddress("glVertexAttrib4fv");
+
+ glVertexAttribPointer_func = (PFNGLVERTEXATTRIBPOINTERPROC) glutGetProcAddress("glVertexAttribPointer");
+ glEnableVertexAttribArray_func = (PFNGLENABLEVERTEXATTRIBARRAYPROC) glutGetProcAddress("glEnableVertexAttribArray");
+ glDisableVertexAttribArray_func = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) glutGetProcAddress("glDisableVertexAttribArray");
/* OpenGL 2.1 */
glUniformMatrix2x3fv_func = (PFNGLUNIFORMMATRIX2X3FVPROC) glutGetProcAddress("glUniformMatrix2x3fv");
@@ -158,5 +223,55 @@ GetExtensionFuncs(void)
/* GL_EXT_stencil_two_side */
glActiveStencilFaceEXT_func = (PFNGLACTIVESTENCILFACEEXTPROC) glutGetProcAddress("glActiveStencilFaceEXT");
+
+ /* GL_ARB_vertex_buffer_object */
+ glGenBuffersARB_func = (PFNGLGENBUFFERSARBPROC) glutGetProcAddress("glGenBuffersARB");
+ glDeleteBuffersARB_func = (PFNGLDELETEBUFFERSARBPROC) glutGetProcAddress("glDeleteBuffersARB");
+ glBindBufferARB_func = (PFNGLBINDBUFFERARBPROC) glutGetProcAddress("glBindBufferARB");
+ glBufferDataARB_func = (PFNGLBUFFERDATAARBPROC) glutGetProcAddress("glBufferDataARB");
+ glBufferSubDataARB_func = (PFNGLBUFFERSUBDATAARBPROC) glutGetProcAddress("glBufferSubDataARB");
+ glMapBufferARB_func = (PFNGLMAPBUFFERARBPROC) glutGetProcAddress("glMapBufferARB");
+ glUnmapBufferARB_func = (PFNGLUNMAPBUFFERARBPROC) glutGetProcAddress("glUnmapBufferARB");
+
+ /* GL_EXT_framebuffer_object */
+ glIsRenderbufferEXT_func = (PFNGLISRENDERBUFFEREXTPROC) glutGetProcAddress("glIsRenderbufferEXT");
+ glBindRenderbufferEXT_func = (PFNGLBINDRENDERBUFFEREXTPROC) glutGetProcAddress("glBindRenderbufferEXT");
+ glDeleteRenderbuffersEXT_func = (PFNGLDELETERENDERBUFFERSEXTPROC) glutGetProcAddress("glDeleteRenderbuffersEXT");
+ glGenRenderbuffersEXT_func = (PFNGLGENRENDERBUFFERSEXTPROC) glutGetProcAddress("glGenRenderbuffersEXT");
+ glRenderbufferStorageEXT_func = (PFNGLRENDERBUFFERSTORAGEEXTPROC) glutGetProcAddress("glRenderbufferStorageEXT");
+ glGetRenderbufferParameterivEXT_func = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) glutGetProcAddress("glGetRenderbufferParameterivEXT");
+ glIsFramebufferEXT_func = (PFNGLISFRAMEBUFFEREXTPROC) glutGetProcAddress("glIsFramebufferEXT");
+ glBindFramebufferEXT_func = (PFNGLBINDFRAMEBUFFEREXTPROC) glutGetProcAddress("glBindFramebufferEXT");
+ glDeleteFramebuffersEXT_func = (PFNGLDELETEFRAMEBUFFERSEXTPROC) glutGetProcAddress("glDeleteFramebuffersEXT");
+ glGenFramebuffersEXT_func = (PFNGLGENFRAMEBUFFERSEXTPROC) glutGetProcAddress("glGenFramebuffersEXT");
+ glCheckFramebufferStatusEXT_func = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) glutGetProcAddress("glCheckFramebufferStatusEXT");
+ glFramebufferTexture1DEXT_func = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) glutGetProcAddress("glFramebufferTexture1DEXT");
+ glFramebufferTexture2DEXT_func = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) glutGetProcAddress("glFramebufferTexture2DEXT");
+ glFramebufferTexture3DEXT_func = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) glutGetProcAddress("glFramebufferTexture3DEXT");
+ glFramebufferRenderbufferEXT_func = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) glutGetProcAddress("glFramebufferRenderbufferEXT");
+ glGetFramebufferAttachmentParameterivEXT_func = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) glutGetProcAddress("glGetFramebufferAttachmentParameterivEXT");
+ glGenerateMipmapEXT_func = (PFNGLGENERATEMIPMAPEXTPROC) glutGetProcAddress("glGenerateMipmapEXT");
+
+ /* GL_ARB_framebuffer_object */
+ glIsRenderbuffer_func = (PFNGLISRENDERBUFFERPROC) glutGetProcAddress("glIsRenderbuffer");
+ glBindRenderbuffer_func = (PFNGLBINDRENDERBUFFERPROC) glutGetProcAddress("glBindRenderbuffer");
+ glDeleteRenderbuffers_func = (PFNGLDELETERENDERBUFFERSPROC) glutGetProcAddress("glDeleteRenderbuffers");
+ glGenRenderbuffers_func = (PFNGLGENRENDERBUFFERSPROC) glutGetProcAddress("glGenRenderbuffers");
+ glRenderbufferStorage_func = (PFNGLRENDERBUFFERSTORAGEPROC) glutGetProcAddress("glRenderbufferStorage");
+ glGetRenderbufferParameteriv_func = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) glutGetProcAddress("glGetRenderbufferParameteriv");
+ glIsFramebuffer_func = (PFNGLISFRAMEBUFFERPROC) glutGetProcAddress("glIsFramebuffer");
+ glBindFramebuffer_func = (PFNGLBINDFRAMEBUFFERPROC) glutGetProcAddress("glBindFramebuffer");
+ glDeleteFramebuffers_func = (PFNGLDELETEFRAMEBUFFERSPROC) glutGetProcAddress("glDeleteFramebuffers");
+ glGenFramebuffers_func = (PFNGLGENFRAMEBUFFERSPROC) glutGetProcAddress("glGenFramebuffers");
+ glCheckFramebufferStatus_func = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) glutGetProcAddress("glCheckFramebufferStatus");
+ glFramebufferTexture1D_func = (PFNGLFRAMEBUFFERTEXTURE1DPROC) glutGetProcAddress("glFramebufferTexture1D");
+ glFramebufferTexture2D_func = (PFNGLFRAMEBUFFERTEXTURE2DPROC) glutGetProcAddress("glFramebufferTexture2D");
+ glFramebufferTexture3D_func = (PFNGLFRAMEBUFFERTEXTURE3DPROC) glutGetProcAddress("glFramebufferTexture3D");
+ glFramebufferRenderbuffer_func = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) glutGetProcAddress("glFramebufferRenderbuffer");
+ glGetFramebufferAttachmentParameteriv_func = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) glutGetProcAddress("glGetFramebufferAttachmentParameteriv");
+ glGenerateMipmap_func = (PFNGLGENERATEMIPMAPPROC) glutGetProcAddress("glGenerateMipmap");
+ glBlitFramebuffer_func = (PFNGLBLITFRAMEBUFFERPROC) glutGetProcAddress("glBlitFramebuffer");
+ glRenderbufferStorageMultisample_func = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) glutGetProcAddress("glRenderbufferStorageMultisample");
+ glFramebufferTextureLayer_func = (PFNGLFRAMEBUFFERTEXTURELAYERPROC) glutGetProcAddress("glFramebufferTextureLayer");
}
diff --git a/progs/util/glutskel.c b/progs/util/glutskel.c
index 273ed9a2f5..8499e12a9d 100644
--- a/progs/util/glutskel.c
+++ b/progs/util/glutskel.c
@@ -11,6 +11,7 @@
#include <GL/glut.h>
static int Win;
+static int WinWidth = 400, WinHeight = 400;
static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
static GLboolean Anim = GL_FALSE;
@@ -46,6 +47,8 @@ Draw(void)
static void
Reshape(int width, int height)
{
+ WinWidth = width;
+ WinHeight = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@@ -63,23 +66,23 @@ Key(unsigned char key, int x, int y)
(void) x;
(void) y;
switch (key) {
- case 'a':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(Idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'z':
- Zrot -= step;
- break;
- case 'Z':
- Zrot += step;
- break;
- case 27:
- glutDestroyWindow(Win);
- exit(0);
- break;
+ case 'a':
+ Anim = !Anim;
+ if (Anim)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
+ case 'z':
+ Zrot -= step;
+ break;
+ case 'Z':
+ Zrot += step;
+ break;
+ case 27:
+ glutDestroyWindow(Win);
+ exit(0);
+ break;
}
glutPostRedisplay();
}
@@ -92,18 +95,18 @@ SpecialKey(int key, int x, int y)
(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;
+ 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();
}
@@ -123,8 +126,7 @@ int
main(int argc, char *argv[])
{
glutInit(&argc, argv);
- glutInitWindowPosition(0, 0);
- glutInitWindowSize(400, 400);
+ glutInitWindowSize(WinWidth, WinHeight);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
Win = glutCreateWindow(argv[0]);
glutReshapeFunc(Reshape);
diff --git a/progs/util/readtex.c b/progs/util/readtex.c
index 37d5fcd0d3..8e923b6eb4 100644
--- a/progs/util/readtex.c
+++ b/progs/util/readtex.c
@@ -102,9 +102,15 @@ static rawImageRec *RawImageOpen(const char *fileName)
fprintf(stderr, "Out of memory!\n");
return NULL;
}
- if ((raw->file = fopen(fileName, "rb")) == NULL) {
- perror(fileName);
- return NULL;
+ raw->file = fopen(fileName, "rb");
+ if (raw->file == NULL) {
+ const char *baseName = strrchr(fileName, '/');
+ if(baseName)
+ raw->file = fopen(baseName + 1, "rb");
+ if(raw->file == NULL) {
+ perror(fileName);
+ return NULL;
+ }
}
fread(raw, 1, 12, raw->file);
diff --git a/progs/util/shaderutil.c b/progs/util/shaderutil.c
index 2f1c4e38b3..4db950016b 100644
--- a/progs/util/shaderutil.c
+++ b/progs/util/shaderutil.c
@@ -9,20 +9,16 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <GL/glew.h>
#include <GL/glut.h>
-#include "extfuncs.h"
#include "shaderutil.h"
+/** time to compile previous shader */
+static GLdouble CompileTime = 0.0;
-static void
-Init(void)
-{
- static GLboolean firstCall = GL_TRUE;
- if (firstCall) {
- GetExtensionFuncs();
- firstCall = GL_FALSE;
- }
-}
+/** time to linke previous program */
+static GLdouble LinkTime = 0.0;
GLboolean
@@ -47,17 +43,22 @@ CompileShaderText(GLenum shaderType, const char *text)
{
GLuint shader;
GLint stat;
+ GLdouble t0, t1;
+
+ shader = glCreateShader(shaderType);
+ glShaderSource(shader, 1, (const GLchar **) &text, NULL);
+
+ t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
+ glCompileShader(shader);
+ t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
- Init();
+ CompileTime = t1 - t0;
- shader = glCreateShader_func(shaderType);
- glShaderSource_func(shader, 1, (const GLchar **) &text, NULL);
- glCompileShader_func(shader);
- glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat);
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &stat);
if (!stat) {
GLchar log[1000];
GLsizei len;
- glGetShaderInfoLog_func(shader, 1000, &len, log);
+ glGetShaderInfoLog(shader, 1000, &len, log);
fprintf(stderr, "Error: problem compiling shader: %s\n", log);
exit(1);
}
@@ -78,8 +79,9 @@ CompileShaderFile(GLenum shaderType, const char *filename)
int n;
char *buffer = (char*) malloc(max);
GLuint shader;
+ FILE *f;
- FILE *f = fopen(filename, "r");
+ f = fopen(filename, "r");
if (!f) {
fprintf(stderr, "Unable to open shader file %s\n", filename);
return 0;
@@ -105,24 +107,30 @@ CompileShaderFile(GLenum shaderType, const char *filename)
GLuint
LinkShaders(GLuint vertShader, GLuint fragShader)
{
- GLuint program = glCreateProgram_func();
+ GLuint program = glCreateProgram();
+ GLdouble t0, t1;
assert(vertShader || fragShader);
if (fragShader)
- glAttachShader_func(program, fragShader);
+ glAttachShader(program, fragShader);
if (vertShader)
- glAttachShader_func(program, vertShader);
- glLinkProgram_func(program);
+ glAttachShader(program, vertShader);
+
+ t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
+ glLinkProgram(program);
+ t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
+
+ LinkTime = t1 - t0;
/* check link */
{
GLint stat;
- glGetProgramiv_func(program, GL_LINK_STATUS, &stat);
+ glGetProgramiv(program, GL_LINK_STATUS, &stat);
if (!stat) {
GLchar log[1000];
GLsizei len;
- glGetProgramInfoLog_func(program, 1000, &len, log);
+ glGetProgramInfoLog(program, 1000, &len, log);
fprintf(stderr, "Shader link error:\n%s\n", log);
return 0;
}
@@ -132,37 +140,176 @@ LinkShaders(GLuint vertShader, GLuint fragShader)
}
+GLboolean
+ValidateShaderProgram(GLuint program)
+{
+ GLint stat;
+ glValidateProgramARB(program);
+ glGetProgramiv(program, GL_VALIDATE_STATUS, &stat);
+
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetProgramInfoLog(program, 1000, &len, log);
+ fprintf(stderr, "Program validation error:\n%s\n", log);
+ return 0;
+ }
+
+ return (GLboolean) stat;
+}
+
+
+GLdouble
+GetShaderCompileTime(void)
+{
+ return CompileTime;
+}
+
+
+GLdouble
+GetShaderLinkTime(void)
+{
+ return LinkTime;
+}
+
+
void
-InitUniforms(GLuint program, struct uniform_info uniforms[])
+SetUniformValues(GLuint program, struct uniform_info uniforms[])
{
GLuint i;
for (i = 0; uniforms[i].name; i++) {
uniforms[i].location
- = glGetUniformLocation_func(program, uniforms[i].name);
-
- printf("Uniform %s location: %d\n", uniforms[i].name,
- uniforms[i].location);
-
- switch (uniforms[i].size) {
- case 1:
- if (uniforms[i].type == GL_INT)
- glUniform1i_func(uniforms[i].location,
- (GLint) uniforms[i].value[0]);
- else
- glUniform1fv_func(uniforms[i].location, 1, uniforms[i].value);
+ = glGetUniformLocation(program, uniforms[i].name);
+
+ switch (uniforms[i].type) {
+ case GL_INT:
+ case GL_SAMPLER_1D:
+ case GL_SAMPLER_2D:
+ case GL_SAMPLER_3D:
+ case GL_SAMPLER_CUBE:
+ case GL_SAMPLER_2D_RECT_ARB:
+ assert(uniforms[i].value[0] >= 0.0F);
+ glUniform1i(uniforms[i].location,
+ (GLint) uniforms[i].value[0]);
+ break;
+ case GL_FLOAT:
+ glUniform1fv(uniforms[i].location, 1, uniforms[i].value);
break;
- case 2:
- glUniform2fv_func(uniforms[i].location, 1, uniforms[i].value);
+ case GL_FLOAT_VEC2:
+ glUniform2fv(uniforms[i].location, 1, uniforms[i].value);
break;
- case 3:
- glUniform3fv_func(uniforms[i].location, 1, uniforms[i].value);
+ case GL_FLOAT_VEC3:
+ glUniform3fv(uniforms[i].location, 1, uniforms[i].value);
break;
- case 4:
- glUniform4fv_func(uniforms[i].location, 1, uniforms[i].value);
+ case GL_FLOAT_VEC4:
+ glUniform4fv(uniforms[i].location, 1, uniforms[i].value);
break;
default:
- abort();
+ if (strncmp(uniforms[i].name, "gl_", 3) == 0) {
+ /* built-in uniform: ignore */
+ }
+ else {
+ fprintf(stderr,
+ "Unexpected uniform data type in SetUniformValues\n");
+ abort();
+ }
}
}
}
+
+
+/** Get list of uniforms used in the program */
+GLuint
+GetUniforms(GLuint program, struct uniform_info uniforms[])
+{
+ GLint n, max, i;
+
+ glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &n);
+ glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max);
+
+ for (i = 0; i < n; i++) {
+ GLint size, len;
+ GLenum type;
+ char name[100];
+
+ glGetActiveUniform(program, i, 100, &len, &size, &type, name);
+
+ uniforms[i].name = strdup(name);
+ uniforms[i].size = size;
+ uniforms[i].type = type;
+ uniforms[i].location = glGetUniformLocation(program, name);
+ }
+
+ uniforms[i].name = NULL; /* end of list */
+
+ return n;
+}
+
+
+void
+PrintUniforms(const struct uniform_info uniforms[])
+{
+ GLint i;
+
+ printf("Uniforms:\n");
+
+ for (i = 0; uniforms[i].name; i++) {
+ printf(" %d: %s size=%d type=0x%x loc=%d value=%g, %g, %g, %g\n",
+ i,
+ uniforms[i].name,
+ uniforms[i].size,
+ uniforms[i].type,
+ uniforms[i].location,
+ uniforms[i].value[0],
+ uniforms[i].value[1],
+ uniforms[i].value[2],
+ uniforms[i].value[3]);
+ }
+}
+
+
+/** Get list of attribs used in the program */
+GLuint
+GetAttribs(GLuint program, struct attrib_info attribs[])
+{
+ GLint n, max, i;
+
+ glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &n);
+ glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max);
+
+ for (i = 0; i < n; i++) {
+ GLint size, len;
+ GLenum type;
+ char name[100];
+
+ glGetActiveAttrib(program, i, 100, &len, &size, &type, name);
+
+ attribs[i].name = strdup(name);
+ attribs[i].size = size;
+ attribs[i].type = type;
+ attribs[i].location = glGetAttribLocation(program, name);
+ }
+
+ attribs[i].name = NULL; /* end of list */
+
+ return n;
+}
+
+
+void
+PrintAttribs(const struct attrib_info attribs[])
+{
+ GLint i;
+
+ printf("Attribs:\n");
+
+ for (i = 0; attribs[i].name; i++) {
+ printf(" %d: %s size=%d type=0x%x loc=%d\n",
+ i,
+ attribs[i].name,
+ attribs[i].size,
+ attribs[i].type,
+ attribs[i].location);
+ }
+}
diff --git a/progs/util/shaderutil.h b/progs/util/shaderutil.h
index cfb8c1f3b0..98c7181156 100644
--- a/progs/util/shaderutil.h
+++ b/progs/util/shaderutil.h
@@ -6,8 +6,8 @@
struct uniform_info
{
const char *name;
- GLuint size;
- GLenum type; /**< GL_FLOAT or GL_INT */
+ GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */
+ GLenum type; /**< GL_FLOAT, GL_FLOAT_VEC4, GL_INT, etc */
GLfloat value[4];
GLint location; /**< filled in by InitUniforms() */
};
@@ -15,6 +15,15 @@ struct uniform_info
#define END_OF_UNIFORMS { NULL, 0, GL_NONE, { 0, 0, 0, 0 }, -1 }
+struct attrib_info
+{
+ const char *name;
+ GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */
+ GLenum type; /**< GL_FLOAT, GL_FLOAT_VEC4, GL_INT, etc */
+ GLint location;
+};
+
+
extern GLboolean
ShadersSupported(void);
@@ -27,8 +36,28 @@ CompileShaderFile(GLenum shaderType, const char *filename);
extern GLuint
LinkShaders(GLuint vertShader, GLuint fragShader);
+extern GLboolean
+ValidateShaderProgram(GLuint program);
+
+extern GLdouble
+GetShaderCompileTime(void);
+
+extern GLdouble
+GetShaderLinkTime(void);
+
+extern void
+SetUniformValues(GLuint program, struct uniform_info uniforms[]);
+
+extern GLuint
+GetUniforms(GLuint program, struct uniform_info uniforms[]);
+
extern void
-InitUniforms(GLuint program, struct uniform_info uniforms[]);
+PrintUniforms(const struct uniform_info uniforms[]);
+
+extern GLuint
+GetAttribs(GLuint program, struct attrib_info attribs[]);
+extern void
+PrintAttribs(const struct attrib_info attribs[]);
#endif /* SHADER_UTIL_H */