diff options
author | Michal Krol <[email protected]> | 2010-01-05 11:04:50 +0100 |
---|---|---|
committer | Michal Krol <[email protected]> | 2010-01-05 11:04:50 +0100 |
commit | 9b21b3c52a8a7d58d08151d1a6bf25c472dec213 (patch) | |
tree | d9083b6af4e2e9b70a7fa6cd31bac45a36e0f6b6 /progs | |
parent | 543b9566bdaa48fea2df1866fa1310c1cdbcde27 (diff) | |
parent | 1f9aa38f4e2be47229d92be2c1189c2b8d9c7133 (diff) |
Merge branch 'master' into instanced-arrays
Conflicts:
src/gallium/auxiliary/tgsi/tgsi_dump.c
src/gallium/include/pipe/p_shader_tokens.h
Diffstat (limited to 'progs')
37 files changed, 861 insertions, 375 deletions
diff --git a/progs/SConscript b/progs/SConscript index 66eaf9e5410..3b180d00bc2 100644 --- a/progs/SConscript +++ b/progs/SConscript @@ -1,5 +1,43 @@ SConscript([ 'util/SConscript', +]) + +Import('*') + +progs_env = env.Clone() + +if progs_env['platform'] == 'windows': + progs_env.Append(CPPDEFINES = ['NOMINMAX']) + progs_env.Prepend(LIBS = [ + 'winmm', + 'kernel32', + 'user32', + 'gdi32', + ]) + +# OpenGL +if progs_env['platform'] == 'windows': + progs_env.Prepend(LIBS = ['glu32', 'opengl32']) +else: + progs_env.Prepend(LIBS = ['GLU', 'GL']) + +# Glut +progs_env.Prepend(LIBS = [glut]) + +# GLEW +progs_env.Prepend(LIBS = [glew]) + +progs_env.Prepend(CPPPATH = [ + '#progs/util', +]) + +progs_env.Prepend(LIBS = [ + util, +]) + +Export('progs_env') + +SConscript([ 'demos/SConscript', 'glsl/SConscript', 'redbook/SConscript', diff --git a/progs/SConstruct b/progs/SConstruct deleted file mode 100644 index 4d268cc6d7b..00000000000 --- a/progs/SConstruct +++ /dev/null @@ -1,65 +0,0 @@ -import os -import os.path -import sys - -env = Environment( - tools = ['generic'], - toolpath = ['../scons'], - ENV = os.environ, -) - - -# Use Mesa's headers and libs -if 1: - build_topdir = 'build' - build_subdir = env['platform'] - if env['machine'] != 'generic': - build_subdir += '-' + env['machine'] - if env['debug']: - build_subdir += "-debug" - if env['profile']: - build_subdir += "-profile" - build_dir = os.path.join(build_topdir, build_subdir) - - env.Append(CPPDEFINES = ['GLEW_STATIC']) - env.Append(CPPPATH = ['#../include']) - env.Append(LIBPATH = [ - '#../' + build_dir + '/glew/', - '#../' + build_dir + '/glut/glx', - ]) - - -conf = Configure(env) - -# OpenGL -if env['platform'] == 'windows': - env.Prepend(LIBS = ['glu32', 'opengl32']) -else: - env.Prepend(LIBS = ['GLU', 'GL']) - -# Glut -env['GLUT'] = False -if conf.CheckCHeader('GL/glut.h'): - if env['platform'] == 'windows': - env['GLUT_LIB'] = 'glut32' - else: - env['GLUT_LIB'] = 'glut' - env['GLUT'] = True - -# GLEW -env['GLEW'] = False -if conf.CheckCHeader('GL/glew.h'): - env['GLEW_LIB'] = 'glew' - env['GLEW'] = True - env.Prepend(LIBS = ['glew']) - -conf.Finish() - - -Export('env') - -SConscript( - 'SConscript', - build_dir = env['build'], - duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html -) diff --git a/progs/demos/SConscript b/progs/demos/SConscript index f851870bcf3..742dd66f36f 100644 --- a/progs/demos/SConscript +++ b/progs/demos/SConscript @@ -1,84 +1,66 @@ Import('*') -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(CPPPATH = [ - '../util', -]) - -env.Prepend(LIBS = [ - util, - '$GLUT_LIB' -]) - -if env['platform'] == 'windows': - env.Append(CPPDEFINES = ['NOMINMAX']) - env.Prepend(LIBS = ['winmm']) - progs = [ - 'arbfplight', - 'arbfslight', - 'arbocclude', - 'bounce', - 'clearspd', - 'copypix', - 'cubemap', - 'drawpix', - 'engine', - 'fbo_firecube', - 'fire', - 'fogcoord', - 'fplight', - 'fslight', - 'gamma', - 'gearbox', - 'gears', - 'geartrain', - 'glinfo', - 'gloss', - 'gltestperf', - 'ipers', - 'isosurf', - 'lodbias', - 'morph3d', - 'multiarb', - 'paltex', - 'pointblast', - 'ray', - 'readpix', - 'reflect', - 'renormal', - 'shadowtex', - 'singlebuffer', - 'spectex', - 'spriteblast', - 'stex3d', - 'teapot', - 'terrain', - 'tessdemo', - 'texcyl', - 'texenv', - 'textures', - 'trispd', - 'tunnel', - 'tunnel2', - 'vao_demo', - 'winpos', - 'dinoshade', - 'fbotexture', - 'projtex', + 'arbfplight', + 'arbfslight', + 'arbocclude', + 'bounce', + 'clearspd', + 'copypix', + 'cubemap', + 'drawpix', + 'engine', + 'fbo_firecube', + 'fire', + 'fogcoord', + 'fplight', + 'fslight', + 'gamma', + 'gearbox', + 'gears', + 'geartrain', + 'glinfo', + 'gloss', + 'gltestperf', + 'ipers', + 'isosurf', + 'lodbias', + 'morph3d', + 'multiarb', + 'paltex', + 'pointblast', + 'ray', + 'readpix', + 'reflect', + 'renormal', + 'shadowtex', + 'singlebuffer', + 'spectex', + 'spriteblast', + 'stex3d', + 'teapot', + 'terrain', + 'tessdemo', + 'texcyl', + 'texenv', + 'textures', + 'trispd', + 'tunnel', + 'tunnel2', + 'vao_demo', + 'winpos', + 'dinoshade', + 'fbotexture', + 'projtex', ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = prog + '.c', ) -env.Program( +progs_env.Program( target = 'rain', source = [ 'rain.cxx', diff --git a/progs/demos/geartrain.c b/progs/demos/geartrain.c index d2a195f39a2..00b6e78b724 100644 --- a/progs/demos/geartrain.c +++ b/progs/demos/geartrain.c @@ -25,6 +25,7 @@ */ +#include <assert.h> #include <math.h> #include <stdlib.h> #include <GL/glut.h> @@ -129,8 +130,10 @@ Clear_Buffers () static void LoadTriplet (TDA A) { + int result; Clear_Buffers (); - fscanf (mainfile, "%s %s %s %s", Buf1, Buf2, Buf3, Buf4); + result = fscanf (mainfile, "%s %s %s %s", Buf1, Buf2, Buf3, Buf4); + assert(result != EOF); A[0] = atof (Buf2); A[1] = atof (Buf3); A[2] = atof (Buf4); @@ -140,8 +143,10 @@ LoadTriplet (TDA A) static void LoadReal (float *a) { + int result; Clear_Buffers (); - fscanf (mainfile, "%s %s", Buf1, Buf2); + result = fscanf (mainfile, "%s %s", Buf1, Buf2); + assert(result != EOF); *a = atof (Buf2); } @@ -149,8 +154,10 @@ LoadReal (float *a) static void LoadInteger (int *a) { + int result; Clear_Buffers (); - fscanf (mainfile, "%s %s", Buf1, Buf2); + result = fscanf (mainfile, "%s %s", Buf1, Buf2); + assert(result != EOF); *a = atoi (Buf2); } @@ -158,8 +165,10 @@ LoadInteger (int *a) static void LoadText (char *a) { + int result; Clear_Buffers (); - fscanf (mainfile, "%s %s", Buf1, Buf2); + result = fscanf (mainfile, "%s %s", Buf1, Buf2); + assert(result != EOF); strcpy (a, Buf2); } @@ -177,8 +186,10 @@ getdata (char filename[]) do { + int result; Clear_Buffers (); - fscanf (mainfile, "%s", Buf1); + result = fscanf (mainfile, "%s", Buf1); + (void) result; if (ferror (mainfile)) { printf ("\nError opening file !\n"); diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c index 56781f68189..dbe4d8d172a 100644 --- a/progs/demos/isosurf.c +++ b/progs/demos/isosurf.c @@ -132,9 +132,11 @@ static void read_surface( char *filename ) numverts = 0; while (!feof(f) && numverts<maxverts) { - fscanf( f, "%f %f %f %f %f %f", - &data[numverts][0], &data[numverts][1], &data[numverts][2], - &data[numverts][3], &data[numverts][4], &data[numverts][5] ); + int result; + result = fscanf( f, "%f %f %f %f %f %f", + &data[numverts][0], &data[numverts][1], &data[numverts][2], + &data[numverts][3], &data[numverts][4], &data[numverts][5] ); + (void) result; numverts++; } numverts--; diff --git a/progs/demos/terrain.c b/progs/demos/terrain.c index 627c3bfb57a..a72c8d3caea 100644 --- a/progs/demos/terrain.c +++ b/progs/demos/terrain.c @@ -8,6 +8,7 @@ * based on a Mikael SkiZoWalker's (MoDEL) / France ([email protected]) demo */ +#include <assert.h> #include <stdio.h> #include <math.h> #include <stdlib.h> @@ -559,12 +560,14 @@ loadpic(void) FILE *FilePic; int i, tmp; GLenum gluerr; + size_t result; if ((FilePic = fopen("terrain.dat", "r")) == NULL) { fprintf(stderr, "Error loading terrain.dat\n"); exit(-1); } - fread(bufferter, 256 * 256, 1, FilePic); + result = fread(bufferter, 256 * 256, 1, FilePic); + assert(result == 1); fclose(FilePic); for (i = 0; i < (256 * 256); i++) { diff --git a/progs/egl/eglgears.c b/progs/egl/eglgears.c index 052d0f9e25d..2d9b8cac7f7 100644 --- a/progs/egl/eglgears.c +++ b/progs/egl/eglgears.c @@ -374,7 +374,8 @@ main(int argc, char *argv[]) EGLint screenAttribs[10]; EGLModeMESA mode[MAX_MODES]; EGLScreenMESA screen; - EGLint count, chosenMode; + EGLint count; + EGLint chosenMode = 0; GLboolean printInfo = GL_FALSE; EGLint width = 0, height = 0; diff --git a/progs/egl/eglscreen.c b/progs/egl/eglscreen.c index 47b3ce3366f..520f76ea036 100644 --- a/progs/egl/eglscreen.c +++ b/progs/egl/eglscreen.c @@ -52,7 +52,8 @@ main(int argc, char *argv[]) EGLint screenAttribs[10]; EGLModeMESA mode[MAX_MODES]; EGLScreenMESA screen; - EGLint count, chosenMode; + EGLint count; + EGLint chosenMode = 0; EGLint width = 0, height = 0; d = eglGetDisplay(EGL_DEFAULT_DISPLAY); diff --git a/progs/fp/SConscript b/progs/fp/SConscript index a78318542c1..113e11ab54e 100644 --- a/progs/fp/SConscript +++ b/progs/fp/SConscript @@ -1,15 +1,4 @@ -Import('env') - -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(CPPPATH = [ - '../util', -]) - -env.Prepend(LIBS = ['$GLUT_LIB']) +Import('*') progs = [ 'fp-tri', @@ -24,7 +13,7 @@ progs = [ ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = [prog + '.c'], ) diff --git a/progs/glsl/SConscript b/progs/glsl/SConscript index 7a4549cd705..8f2ebcf69c4 100644 --- a/progs/glsl/SConscript +++ b/progs/glsl/SConscript @@ -1,23 +1,5 @@ Import('*') -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(CPPPATH = [ - '../util', -]) - -env.Prepend(LIBS = [ - util, - '$GLUT_LIB' -]) - -if env['platform'] == 'windows': - env.Append(CPPDEFINES = ['NOMINMAX']) - env.Prepend(LIBS = ['winmm']) - progs = [ 'array', 'bitmap', @@ -48,7 +30,7 @@ progs = [ ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = prog + '.c', ) diff --git a/progs/glsl/shtest.c b/progs/glsl/shtest.c index 88315d74614..e9800c307f3 100644 --- a/progs/glsl/shtest.c +++ b/progs/glsl/shtest.c @@ -492,9 +492,8 @@ ReadConfigFile(const char *filename, struct config_file *conf) conf->num_uniforms = 0; /* ugly but functional parser */ - while (!feof(f)) { - fgets(line, sizeof(line), f); - if (!feof(f) && line[0]) { + while (fgets(line, sizeof(line), f) != NULL) { + if (line[0]) { if (strncmp(line, "vs ", 3) == 0) { VertShaderFile = strdup(line + 3); VertShaderFile[strlen(VertShaderFile) - 1] = 0; diff --git a/progs/glsl/vert-tex.c b/progs/glsl/vert-tex.c index 4c8bfa587aa..2b93c788889 100644 --- a/progs/glsl/vert-tex.c +++ b/progs/glsl/vert-tex.c @@ -40,15 +40,6 @@ static GLboolean Anim = GL_TRUE; static GLboolean WireFrame = GL_TRUE; static GLfloat xRot = -70.0f, yRot = 0.0f, zRot = 0.0f; - -/* value[0] = tex unit */ -static struct uniform_info Uniforms[] = { - { "tex1", 1, GL_SAMPLER_2D, { 0, 0, 0, 0 }, -1 }, - END_OF_UNIFORMS -}; - - - static void Idle(void) { diff --git a/progs/objviewer/.gitignore b/progs/objviewer/.gitignore new file mode 100644 index 00000000000..ff094f833e4 --- /dev/null +++ b/progs/objviewer/.gitignore @@ -0,0 +1,8 @@ +extfuncs.h +objview +readtex.c +readtex.h +shaderutil.c +shaderutil.h +trackball.c +trackball.h diff --git a/progs/perf/SConscript b/progs/perf/SConscript index a5ec9a7c2a0..691478ab64d 100644 --- a/progs/perf/SConscript +++ b/progs/perf/SConscript @@ -1,11 +1,4 @@ -Import('env') - -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(LIBS = ['$GLUT_LIB']) +Import('*') progs = [ 'copytex', @@ -21,7 +14,7 @@ progs = [ ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = [ prog + '.c', diff --git a/progs/rbug/simple_server.c b/progs/rbug/simple_server.c index 04380c33109..3a842c06c4e 100644 --- a/progs/rbug/simple_server.c +++ b/progs/rbug/simple_server.c @@ -29,7 +29,7 @@ #include "rbug/rbug.h" -static void wait() +static void rbug_wait() { int s = u_socket_listen_on_port(13370); int c = u_socket_accept(s); @@ -57,6 +57,6 @@ static void wait() int main(int argc, char** argv) { - wait(); + rbug_wait(); return 0; } diff --git a/progs/redbook/SConscript b/progs/redbook/SConscript index 242cb6647fc..24d7cff1b67 100644 --- a/progs/redbook/SConscript +++ b/progs/redbook/SConscript @@ -1,23 +1,5 @@ Import('*') -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(CPPPATH = [ - '../util', -]) - -env.Prepend(LIBS = [ - util, - '$GLUT_LIB' -]) - -if env['platform'] == 'windows': - env.Append(CPPDEFINES = ['NOMINMAX']) - env.Prepend(LIBS = ['winmm']) - progs = [ 'aaindex', 'aapoly', @@ -85,7 +67,7 @@ progs = [ ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = prog + '.c', ) diff --git a/progs/samples/.gitignore b/progs/samples/.gitignore index f60d6e94eac..c15b886b884 100644 --- a/progs/samples/.gitignore +++ b/progs/samples/.gitignore @@ -36,6 +36,7 @@ prim quad readtex.c readtex.h +rgbtoppm select shape sphere diff --git a/progs/samples/SConscript b/progs/samples/SConscript index 7a8a0d62d81..134dfa99807 100644 --- a/progs/samples/SConscript +++ b/progs/samples/SConscript @@ -1,23 +1,5 @@ Import('*') -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(CPPPATH = [ - '../util', -]) - -env.Prepend(LIBS = [ - util, - '$GLUT_LIB' -]) - -if env['platform'] == 'windows': - env.Append(CPPDEFINES = ['NOMINMAX']) - env.Prepend(LIBS = ['winmm']) - progs = [ 'accum', 'bitmap1', @@ -52,7 +34,7 @@ progs = [ ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = prog + '.c', ) diff --git a/progs/samples/olympic.c b/progs/samples/olympic.c index 5385e487026..209a8c141b2 100644 --- a/progs/samples/olympic.c +++ b/progs/samples/olympic.c @@ -74,7 +74,7 @@ int iters[RINGS]; GLuint theTorus; -void FillTorus(float rc, int numc, float rt, int numt) +static void FillTorus(float rc, int numc, float rt, int numt) { int i, j, k; double s, t; @@ -106,7 +106,7 @@ void FillTorus(float rc, int numc, float rt, int numt) } } -float Clamp(int iters_left, float t) +static float Clamp(int iters_left, float t) { if (iters_left < 3) { return 0.0; @@ -114,7 +114,7 @@ float Clamp(int iters_left, float t) return (iters_left-2)*t/iters_left; } -void DrawScene(void) +static void DrawScene(void) { int i, j; GLboolean goIdle; @@ -172,7 +172,7 @@ void DrawScene(void) } } -float MyRand(void) +static float MyRand(void) { return 10.0 * ( (float) rand() / (float) RAND_MAX - 0.5 ); } @@ -181,12 +181,12 @@ float MyRand(void) #define GLUTCALLBACK #endif -void GLUTCALLBACK glut_post_redisplay_p(void) +static void GLUTCALLBACK glut_post_redisplay_p(void) { glutPostRedisplay(); } -void ReInit(void) +static void ReInit(void) { int i; float deviation; @@ -206,7 +206,7 @@ void ReInit(void) glutIdleFunc(glut_post_redisplay_p); } -void Init(void) +static void Init(void) { float base, height; float aspect, x, y; @@ -312,13 +312,13 @@ void Init(void) glMatrixMode(GL_MODELVIEW); } -void Reshape(int width, int height) +static void Reshape(int width, int height) { glViewport(0, 0, width, height); } -void Key(unsigned char key, int x, int y) +static void Key(unsigned char key, int x, int y) { switch (key) { @@ -330,7 +330,7 @@ void Key(unsigned char key, int x, int y) } } -GLenum Args(int argc, char **argv) +static GLenum Args(int argc, char **argv) { GLint i; diff --git a/progs/samples/overlay.c b/progs/samples/overlay.c index 23b5a4793ba..6087cef2815 100644 --- a/progs/samples/overlay.c +++ b/progs/samples/overlay.c @@ -69,19 +69,19 @@ starRec stars[MAXSTARS]; float sinTable[MAXANGLES]; -float Sin(float angle) +static float Sin(float angle) { return (sinTable[(GLint)angle]); } -float Cos(float angle) +static float Cos(float angle) { return (sinTable[((GLint)angle+(MAXANGLES/4))%MAXANGLES]); } -void NewStar(GLint n, GLint d) +static void NewStar(GLint n, GLint d) { if (rand()%4 == 0) { @@ -103,7 +103,7 @@ void NewStar(GLint n, GLint d) } } -void RotatePoint(float *x, float *y, float rotation) +static void RotatePoint(float *x, float *y, float rotation) { float tmpX, tmpY; @@ -113,7 +113,7 @@ void RotatePoint(float *x, float *y, float rotation) *y = tmpY; } -void MoveStars(void) +static void MoveStars(void) { float offset; GLint n; @@ -134,7 +134,7 @@ void MoveStars(void) } } -GLenum StarPoint(GLint n) +static GLenum StarPoint(GLint n) { float x0, y0, x1, y1, width; GLint i; @@ -182,7 +182,7 @@ GLenum StarPoint(GLint n) } } -void ShowStars(void) +static void ShowStars(void) { GLint n; @@ -221,7 +221,7 @@ static void Init(void) glDisable(GL_DITHER); } -void Reshape(int width, int height) +static void Reshape(int width, int height) { windW = (GLint)width; @@ -262,7 +262,7 @@ static void Key(unsigned char key, int x, int y) } } -void Idle(void) +static void Idle(void) { if (overlayInit == GL_FALSE) { diff --git a/progs/samples/rgbtoppm.c b/progs/samples/rgbtoppm.c index dcb74228dff..403578ef423 100644 --- a/progs/samples/rgbtoppm.c +++ b/progs/samples/rgbtoppm.c @@ -3,6 +3,7 @@ /* texload is a simplistic routine for reading an SGI .rgb image file. */ +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -25,7 +26,7 @@ typedef struct _ImageRec { int *rowSize; } ImageRec; -void +static void rgbtorgb(unsigned char *r,unsigned char *g,unsigned char *b,unsigned char *l,int n) { while(n--) { l[0] = r[0]; @@ -72,6 +73,7 @@ static ImageRec *ImageOpen(char *fileName) ImageRec *image; int swapFlag; int x; + int result; endianTest.testWord = 1; if (endianTest.testByte[0] == 1) { @@ -90,7 +92,8 @@ static ImageRec *ImageOpen(char *fileName) return NULL; } - fread(image, 1, 12, image->file); + result = fread(image, 1, 12, image->file); + assert(result == 12); if (swapFlag) { ConvertShort(&image->imagic, 1); @@ -117,8 +120,10 @@ static ImageRec *ImageOpen(char *fileName) } image->rleEnd = 512 + (2 * x); fseek(image->file, 512, SEEK_SET); - fread(image->rowStart, 1, x, image->file); - fread(image->rowSize, 1, x, image->file); + result = fread(image->rowStart, 1, x, image->file); + assert(result == x); + result = fread(image->rowSize, 1, x, image->file); + assert(result == x); if (swapFlag) { ConvertUint(image->rowStart, x/(int) sizeof(unsigned)); ConvertUint((unsigned *)image->rowSize, x/(int) sizeof(int)); @@ -138,11 +143,13 @@ static void ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z) { unsigned char *iPtr, *oPtr, pixel; int count; + int result; if ((image->type & 0xFF00) == 0x0100) { fseek(image->file, (long) image->rowStart[y+z*image->ysize], SEEK_SET); - fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize], - image->file); + result = fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize], + image->file); + assert(result == (unsigned int)image->rowSize[y+z*image->ysize]); iPtr = image->tmp; oPtr = buf; @@ -166,11 +173,13 @@ ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z) { } else { fseek(image->file, 512+(y*image->xsize)+(z*image->xsize*image->ysize), SEEK_SET); - fread(buf, 1, image->xsize, image->file); + result = fread(buf, 1, image->xsize, image->file); + assert(result == image->xsize); } } -GLubyte * +#if 0 +static GLubyte * read_alpha_texture(char *name, int *width, int *height) { unsigned char *base, *lptr; @@ -199,8 +208,9 @@ read_alpha_texture(char *name, int *width, int *height) return (unsigned char *) base; } +#endif -GLubyte * +static GLubyte * read_rgb_texture(char *name, int *width, int *height) { unsigned char *base, *ptr; @@ -261,7 +271,8 @@ read_rgb_texture(char *name, int *width, int *height) int main(int argc, char **argv) { - int width, height; + int width = 0; + int height = 0; GLubyte *data; char buff[32]; int n; diff --git a/progs/samples/sphere.c b/progs/samples/sphere.c index 7d0508dee9f..23d4fe32c02 100644 --- a/progs/samples/sphere.c +++ b/progs/samples/sphere.c @@ -445,7 +445,7 @@ GLfloat identity[16] = { }; -void BuildCylinder(int numEdges) +static void BuildCylinder(int numEdges) { int i, top = 1.0, bottom = -1.0; float x[100], y[100], angle; @@ -481,7 +481,7 @@ void BuildCylinder(int numEdges) glEndList(); } -void BuildTorus(float rc, int numc, float rt, int numt) +static void BuildTorus(float rc, int numc, float rt, int numt) { int i, j, k; double s, t; @@ -515,7 +515,7 @@ void BuildTorus(float rc, int numc, float rt, int numt) glEndList(); } -void BuildCage(void) +static void BuildCage(void) { int i; float inc; @@ -609,7 +609,7 @@ void BuildCage(void) glEndList(); } -void BuildCube(void) +static void BuildCube(void) { int i, j; @@ -628,7 +628,7 @@ void BuildCube(void) glEndList(); } -void BuildLists(void) +static void BuildLists(void) { cube = glGenLists(1); @@ -646,7 +646,7 @@ void BuildLists(void) genericObject = torus; } -void SetDefaultSettings(void) +static void SetDefaultSettings(void) { magFilter = nnearest; @@ -657,7 +657,7 @@ void SetDefaultSettings(void) autoRotate = GL_TRUE; } -unsigned char *AlphaPadImage(int bufSize, unsigned char *inData, int alpha) +static unsigned char *AlphaPadImage(int bufSize, unsigned char *inData, int alpha) { unsigned char *outData, *out_ptr, *in_ptr; int i; @@ -677,7 +677,7 @@ unsigned char *AlphaPadImage(int bufSize, unsigned char *inData, int alpha) return outData; } -void Init(void) +static void Init(void) { float ambient[] = {0.0, 0.0, 0.0, 1.0}; float diffuse[] = {1.0, 1.0, 1.0, 1.0}; @@ -753,7 +753,7 @@ void Init(void) BuildLists(); } -void ReInit(void) +static void ReInit(void) { if (genericObject == torus) { glEnable(GL_DEPTH_TEST); @@ -773,7 +773,7 @@ void ReInit(void) glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textureEnvironment); } -void Draw(void) +static void Draw(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); @@ -806,7 +806,7 @@ void Draw(void) glutSwapBuffers(); } -void Reshape(int width, int height) +static void Reshape(int width, int height) { W = width; H = height; @@ -818,7 +818,7 @@ void Reshape(int width, int height) glMatrixMode(GL_MODELVIEW); } -void Idle(void) +static void Idle(void) { static double t0 = -1.; double t, dt; @@ -833,7 +833,7 @@ void Idle(void) glutPostRedisplay(); } -void Key2(int key, int x, int y) +static void Key2(int key, int x, int y) { switch (key) { @@ -863,7 +863,7 @@ void Key2(int key, int x, int y) glutPostRedisplay(); } -void Key(unsigned char key, int x, int y) +static void Key(unsigned char key, int x, int y) { switch (key) { @@ -950,7 +950,7 @@ void Key(unsigned char key, int x, int y) glutPostRedisplay(); } -GLenum Args(int argc, char **argv) +static GLenum Args(int argc, char **argv) { GLint i; diff --git a/progs/samples/star.c b/progs/samples/star.c index 2cf470e2a2f..2c44ebfd49e 100644 --- a/progs/samples/star.c +++ b/progs/samples/star.c @@ -67,19 +67,19 @@ starRec stars[MAXSTARS]; float sinTable[MAXANGLES]; -float Sin(float angle) +static float Sin(float angle) { return (sinTable[(GLint)angle]); } -float Cos(float angle) +static float Cos(float angle) { return (sinTable[((GLint)angle+(MAXANGLES/4))%MAXANGLES]); } -void NewStar(GLint n, GLint d) +static void NewStar(GLint n, GLint d) { if (rand()%4 == 0) { @@ -101,7 +101,7 @@ void NewStar(GLint n, GLint d) } } -void RotatePoint(float *x, float *y, float rotation) +static void RotatePoint(float *x, float *y, float rotation) { float tmpX, tmpY; @@ -111,7 +111,7 @@ void RotatePoint(float *x, float *y, float rotation) *y = tmpY; } -void MoveStars(void) +static void MoveStars(void) { float offset; GLint n; @@ -142,7 +142,7 @@ void MoveStars(void) } } -GLenum StarPoint(GLint n) +static GLenum StarPoint(GLint n) { float x0, y0, x1, y1, width; GLint i; @@ -190,7 +190,7 @@ GLenum StarPoint(GLint n) } } -void ShowStars(void) +static void ShowStars(void) { GLint n; @@ -229,7 +229,7 @@ static void Init(void) glDisable(GL_DITHER); } -void Reshape(int width, int height) +static void Reshape(int width, int height) { windW = (GLint)width; @@ -260,7 +260,7 @@ static void Key(unsigned char key, int x, int y) } } -void Draw(void) +static void Draw(void) { MoveStars(); @@ -307,7 +307,7 @@ static GLenum Args(int argc, char **argv) #define GLUTCALLBACK #endif -void GLUTCALLBACK glut_post_redisplay_p(void) +static void GLUTCALLBACK glut_post_redisplay_p(void) { glutPostRedisplay(); } diff --git a/progs/samples/stretch.c b/progs/samples/stretch.c index 1fd015d794a..11201dca230 100644 --- a/progs/samples/stretch.c +++ b/progs/samples/stretch.c @@ -67,7 +67,7 @@ int cCount, cIndex[2], cStep; GLenum op = OP_NOOP; -void DrawImage(void) +static void DrawImage(void) { glRasterPos2i(0, 0); @@ -84,7 +84,7 @@ void DrawImage(void) image->data); } -void DrawPoint(void) +static void DrawPoint(void) { int i; @@ -102,7 +102,7 @@ void DrawPoint(void) } } -void InitVList(void) +static void InitVList(void) { vList[0].x = 0.0; @@ -141,7 +141,7 @@ void InitVList(void) vList[4].tY = cList[0].y / (float)imageSizeY; } -void ScaleImage(int sizeX, int sizeY) +static void ScaleImage(int sizeX, int sizeY) { GLubyte *buf; @@ -154,7 +154,7 @@ void ScaleImage(int sizeX, int sizeY) image->sizeY = sizeY; } -void SetPoint(int x, int y) +static void SetPoint(int x, int y) { cList[cCount].x = (float)x; @@ -162,7 +162,7 @@ void SetPoint(int x, int y) cCount++; } -void Stretch(void) +static void Stretch(void) { glBegin(GL_TRIANGLES); @@ -221,7 +221,7 @@ void Stretch(void) } } -void Key(unsigned char key, int x, int y) +static void Key(unsigned char key, int x, int y) { switch (key) { @@ -245,7 +245,7 @@ void Key(unsigned char key, int x, int y) glutPostRedisplay(); } -void Mouse(int button, int state, int mouseX, int mouseY) +static void Mouse(int button, int state, int mouseX, int mouseY) { if (state != GLUT_DOWN) @@ -263,7 +263,7 @@ void Mouse(int button, int state, int mouseX, int mouseY) glutPostRedisplay(); } -void Animate(void) +static void Animate(void) { static double t0 = -1.; double t, dt; @@ -322,7 +322,7 @@ static GLenum Args(int argc, char **argv) #define GLUTCALLBACK #endif -void GLUTCALLBACK glut_post_redisplay_p(void) +static void GLUTCALLBACK glut_post_redisplay_p(void) { glutPostRedisplay(); } diff --git a/progs/samples/wave.c b/progs/samples/wave.c index d3c4687459e..396a6943e33 100644 --- a/progs/samples/wave.c +++ b/progs/samples/wave.c @@ -92,7 +92,7 @@ GLubyte contourTexture2[] = { #endif -void GLUTCALLBACK glut_post_redisplay_p(void) +static void GLUTCALLBACK glut_post_redisplay_p(void) { static double t0 = -1.; double t, dt; diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 3e2541186b1..836396b2499 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -37,10 +37,12 @@ SOURCES = \ bug_3195.c \ bug_texstore_i8.c \ calibrate_rast.c \ + condrender.c \ copypixrate.c \ crossbar.c \ cva.c \ drawbuffers.c \ + drawbuffers2.c \ exactrast.c \ ext422square.c \ floattex.c \ diff --git a/progs/tests/SConscript b/progs/tests/SConscript index 3a0da62717c..e2c65382887 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -1,23 +1,5 @@ Import('*') -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(CPPPATH = [ - '../util', -]) - -env.Prepend(LIBS = [ - util, - '$GLUT_LIB' -]) - -if env['platform'] == 'windows': - env.Append(CPPDEFINES = ['NOMINMAX']) - env.Prepend(LIBS = ['winmm']) - linux_progs = [ 'api_speed', ] @@ -59,10 +41,12 @@ progs = [ 'bug_3195', 'bug_texstore_i8', 'calibrate_rast', + 'condrender', 'copypixrate', 'crossbar', 'cva', 'drawbuffers', + 'drawbuffers2', 'exactrast', 'ext422square', 'fbotest1', @@ -138,7 +122,7 @@ progs = [ ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = prog + '.c', ) diff --git a/progs/tests/condrender.c b/progs/tests/condrender.c new file mode 100644 index 00000000000..1db8a7c15af --- /dev/null +++ b/progs/tests/condrender.c @@ -0,0 +1,242 @@ +/* + * Test GL_NV_conditional_render + * + * Brian Paul + * 30 Dec 2009 + * + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + +#define TEST_DISPLAY_LISTS 0 + +static GLboolean Anim = GL_TRUE; +static GLfloat Xpos = 0; +static GLuint OccQuery; +static GLint Win = 0; + + +static void Idle(void) +{ + static int lastTime = 0; + static int sign = +1; + int time = glutGet(GLUT_ELAPSED_TIME); + float step; + + if (lastTime == 0) + lastTime = time; + else if (time - lastTime < 20) /* 50Hz update */ + return; + + step = (time - lastTime) / 1000.0 * sign; + lastTime = time; + + Xpos += step; + + if (Xpos > 2.5) { + Xpos = 2.5; + sign = -1; + } + else if (Xpos < -2.5) { + Xpos = -2.5; + sign = +1; + } + glutPostRedisplay(); +} + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glEnable(GL_DEPTH_TEST); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); + + /* draw the occluding polygons */ + glColor3f(0, 0.6, 0.8); + glBegin(GL_QUADS); + glVertex2f(-1.6, -1.5); + glVertex2f(-0.4, -1.5); + glVertex2f(-0.4, 1.5); + glVertex2f(-1.6, 1.5); + + glVertex2f( 0.4, -1.5); + glVertex2f( 1.6, -1.5); + glVertex2f( 1.6, 1.5); + glVertex2f( 0.4, 1.5); + glEnd(); + + /* draw the test polygon with occlusion testing */ + glPushMatrix(); + glTranslatef(Xpos, 0, -0.5); + glScalef(0.3, 0.3, 1.0); + glRotatef(-90.0 * Xpos, 0, 0, 1); + +#if TEST_DISPLAY_LISTS + glNewList(10, GL_COMPILE); + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); + glEndList(); + glCallList(10); +#else + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); +#endif + + glColorMask(0, 0, 0, 0); + glDepthMask(GL_FALSE); + + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + +#if TEST_DISPLAY_LISTS + glNewList(11, GL_COMPILE); + glEndQueryARB(GL_SAMPLES_PASSED_ARB); + glEndList(); + glCallList(11); +#else + glEndQueryARB(GL_SAMPLES_PASSED_ARB); +#endif + + glColorMask(1, 1, 1, 1); + glDepthMask(GL_TRUE); + + /* Note: disable depth test here so that we'll always see the orange + * box, except when it's totally culled. + */ + glDisable(GL_DEPTH_TEST); + + glBeginConditionalRenderNV(OccQuery, GL_QUERY_WAIT_NV); + /* draw the orange rect, so we can see what's going on */ + glColor3f(0.8, 0.5, 0); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + glEndConditionalRenderNV(); + + /* always draw white outline around orange box */ + glColor3f(1.0, 1.0, 1.0); + glBegin(GL_LINE_LOOP); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glDeleteQueriesARB(1, &OccQuery); + glutDestroyWindow(Win); + exit(0); + break; + case ' ': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + const GLfloat step = 0.1; + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_LEFT: + Xpos -= step; + break; + case GLUT_KEY_RIGHT: + Xpos += step; + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + if (!glutExtensionSupported("GL_ARB_occlusion_query") || + !glutExtensionSupported("GL_NV_conditional_render")) { + printf("Sorry, this demo requires the extensions:\n"); + printf(" GL_ARB_occlusion_query\n"); + printf(" GL_NV_conditional_render\n"); + exit(-1); + } + + glGenQueriesARB(1, &OccQuery); + assert(OccQuery > 0); +} + + +int main( int argc, char *argv[] ) +{ + glutInitWindowSize( 400, 400 ); + glutInit( &argc, argv ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutIdleFunc( Idle ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/drawbuffers2.c b/progs/tests/drawbuffers2.c new file mode 100644 index 00000000000..7b8cc5ca6a3 --- /dev/null +++ b/progs/tests/drawbuffers2.c @@ -0,0 +1,364 @@ +/* + * Test GL_ARB_draw_buffers2, GL_ARB_draw_buffers, GL_EXT_framebuffer_object + * and GLSL's gl_FragData[]. + * + * We draw to two color buffers and show the left half of the first + * color buffer on the left side of the window, and show the right + * half of the second color buffer on the right side of the window. + * + * Different color masks are used for the two color buffers. + * Blending is enabled for the second buffer only. + * + * Brian Paul + * 31 Dec 2009 + */ + + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> +#include "extfuncs.h" + +static int Win; +static int Width = 400, Height = 400; +static GLuint FBobject, RBobjects[3]; +static GLfloat Xrot = 0.0, Yrot = 0.0; +static GLuint Program; +static GLboolean Anim = GL_TRUE; + + +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("GL Error 0x%x at line %d\n", (int) err, line); + } +} + + +static void +Display(void) +{ + GLubyte *buffer = malloc(Width * Height * 4); + static const GLenum buffers[2] = { + GL_COLOR_ATTACHMENT0_EXT, + GL_COLOR_ATTACHMENT1_EXT + }; + + glUseProgram_func(Program); + + glEnable(GL_DEPTH_TEST); + + /* draw to user framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBobject); + + /* Clear color buffer 0 (blue) */ + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glClear(GL_COLOR_BUFFER_BIT); + + /* Clear color buffer 1 (1 - blue) */ + glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); + glClear(GL_COLOR_BUFFER_BIT); + + glClear(GL_DEPTH_BUFFER_BIT); + + /* draw to two buffers w/ fragment shader */ + glDrawBuffersARB(2, buffers); + + /* different color masks for each buffer */ + if (1) { + glColorMaskIndexedEXT(0, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); + glColorMaskIndexedEXT(1, GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); + } + + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + glPushMatrix(); + glTranslatef(1, 0, 0); + glutSolidTorus(1.0, 2.0, 10, 20); + glPopMatrix(); + glPushMatrix(); + glTranslatef(-1, 0, 0); + glRotatef(90, 1, 0, 0); + glutSolidTorus(1.0, 2.0, 10, 20); + glPopMatrix(); + glPopMatrix(); + + /* restore default color masks */ + glColorMaskIndexedEXT(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glColorMaskIndexedEXT(1, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + /* read from user framebuffer */ + /* left half = colorbuffer 0 */ + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glPixelStorei(GL_PACK_ROW_LENGTH, Width); + glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + glReadPixels(0, 0, Width / 2, Height, GL_RGBA, GL_UNSIGNED_BYTE, + buffer); + + /* right half = colorbuffer 1 */ + glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glPixelStorei(GL_PACK_SKIP_PIXELS, Width / 2); + glReadPixels(Width / 2, 0, Width - Width / 2, Height, + GL_RGBA, GL_UNSIGNED_BYTE, + buffer); + + /* draw to window */ + glUseProgram_func(0); + glDisable(GL_DEPTH_TEST); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glWindowPos2iARB(0, 0); + glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + free(buffer); + glutSwapBuffers(); + CheckError(__LINE__); +} + + +static void +Idle(void) +{ + Xrot = glutGet(GLUT_ELAPSED_TIME) * 0.05; + glutPostRedisplay(); +} + + +static void +Reshape(int width, int height) +{ + float ar = (float) width / (float) height; + + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1.0, 1.0, 5.0, 35.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -20.0); + + Width = width; + Height = height; + + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[0]); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[1]); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[2]); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, + Width, Height); +} + + +static void +CleanUp(void) +{ + glDeleteFramebuffersEXT(1, &FBobject); + glDeleteRenderbuffersEXT(3, RBobjects); + glutDestroyWindow(Win); + exit(0); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case ' ': + Anim = !Anim; + glutIdleFunc(Anim ? Idle : NULL); + break; + case 'x': + Xrot += 5.0; + break; + case 'X': + Xrot -= 5.0; + break; + case 'y': + Yrot += 5.0; + break; + case 'Y': + Yrot -= 5.0; + break; + case 27: + CleanUp(); + break; + } + glutPostRedisplay(); +} + + +static void +CheckExtensions(void) +{ + const char *req[] = { + "GL_EXT_framebuffer_object", + "GL_ARB_draw_buffers", + "GL_EXT_draw_buffers2" + }; + + const char *version = (const char *) glGetString(GL_VERSION); + GLint numBuf; + GLint i; + + for (i = 0; i < 3; i++) { + if (!glutExtensionSupported(req[i])) { + printf("Sorry, %s extension is required!\n", req[i]); + exit(1); + } + } + if (version[0] != '2') { + printf("Sorry, OpenGL 2.0 is required!\n"); + exit(1); + } + + glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &numBuf); + printf("GL_MAX_DRAW_BUFFERS_ARB = %d\n", numBuf); + if (numBuf < 2) { + printf("Sorry, GL_MAX_DRAW_BUFFERS_ARB needs to be >= 2\n"); + exit(1); + } + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); +} + + +static void +SetupRenderbuffers(void) +{ + glGenFramebuffersEXT(1, &FBobject); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBobject); + + glGenRenderbuffersEXT(3, RBobjects); + + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[0]); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[1]); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[2]); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, + Width, Height); + + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + GL_RENDERBUFFER_EXT, RBobjects[0]); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + GL_RENDERBUFFER_EXT, RBobjects[1]); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, + GL_RENDERBUFFER_EXT, RBobjects[2]); + + CheckError(__LINE__); +} + + +static GLuint +LoadAndCompileShader(GLenum target, const char *text) +{ + GLint stat; + GLuint shader = glCreateShader_func(target); + 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, "drawbuffers: problem compiling shader:\n%s\n", log); + exit(1); + } + return shader; +} + + +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, "drawbuffers: shader link error:\n%s\n", log); + } +} + + +static void +SetupShaders(void) +{ + /* emit same color to both draw buffers */ + static const char *fragShaderText = + "void main() {\n" + " gl_FragData[0] = gl_Color; \n" + " gl_FragData[1] = gl_Color; \n" + "}\n"; + + GLuint fragShader; + + fragShader = LoadAndCompileShader(GL_FRAGMENT_SHADER, fragShaderText); + Program = glCreateProgram_func(); + + glAttachShader_func(Program, fragShader); + glLinkProgram_func(Program); + CheckLink(Program); + glUseProgram_func(Program); +} + + +static void +SetupLighting(void) +{ + static const GLfloat ambient[4] = { 0.0, 0.0, 0.0, 0.0 }; + static const GLfloat diffuse[4] = { 1.0, 1.0, 1.0, 0.75 }; + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); + + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); +} + + +static void +Init(void) +{ + CheckExtensions(); + GetExtensionFuncs(); + SetupRenderbuffers(); + SetupShaders(); + SetupLighting(); + glEnable(GL_DEPTH_TEST); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnableIndexedEXT(GL_BLEND, 1); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(Width, Height); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutIdleFunc(Anim ? Idle : NULL); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Display); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/getprocaddress.c b/progs/tests/getprocaddress.c index b905eeaf81b..e699baf44bc 100644 --- a/progs/tests/getprocaddress.c +++ b/progs/tests/getprocaddress.c @@ -1188,7 +1188,7 @@ exercise_buffer_objects(enum Map_Buffer_Usage usage) GLuint bufferID; GLint bufferMapped; static GLubyte data[BUFFER_DATA_SIZE] = {0}; - float *dataPtr; + float *dataPtr = NULL; /* Get the function pointers we need. These are from * GL_ARB_vertex_buffer_object and are required in all diff --git a/progs/tests/vparray.c b/progs/tests/vparray.c index af9b62d33e6..fe168c6cd56 100644 --- a/progs/tests/vparray.c +++ b/progs/tests/vparray.c @@ -37,13 +37,16 @@ static void read_surface( char *filename ) } numverts = 0; - while (!feof(f) && numverts < MAXVERTS) { - fscanf( f, "%f %f %f %f %f %f", - &data[numverts][0], &data[numverts][1], &data[numverts][2], - &data[numverts][3], &data[numverts][4], &data[numverts][5] ); + while (numverts < MAXVERTS) { + int result; + result = fscanf( f, "%f %f %f %f %f %f", + &data[numverts][0], &data[numverts][1], &data[numverts][2], + &data[numverts][3], &data[numverts][4], &data[numverts][5] ); + if (result == EOF) { + break; + } numverts++; } - numverts--; printf("%d vertices, %d triangles\n", numverts, numverts-2); printf("data = %p\n", (void *) data); diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 9a1f3575bdc..613383c77b1 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -1,11 +1,4 @@ -Import('env') - -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(LIBS = ['$GLUT_LIB']) +Import('*') progs = [ 'clear-fbo-tex', @@ -154,7 +147,7 @@ progs = [ ] for prog in progs: - prog = env.Program( + prog = progs_env.Program( target = prog, source = prog + '.c', ) diff --git a/progs/util/readtex.c b/progs/util/readtex.c index d1c50a494aa..f6f511481ca 100644 --- a/progs/util/readtex.c +++ b/progs/util/readtex.c @@ -9,6 +9,7 @@ #include <GL/gl.h> #include <GL/glu.h> +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -89,6 +90,7 @@ static rawImageRec *RawImageOpen(const char *fileName) rawImageRec *raw; GLenum swapFlag; int x; + size_t result; endianTest.testWord = 1; if (endianTest.testByte[0] == 1) { @@ -114,7 +116,8 @@ static rawImageRec *RawImageOpen(const char *fileName) } } - fread(raw, 1, 12, raw->file); + result = fread(raw, 1, 12, raw->file); + assert(result == 12); if (swapFlag) { ConvertShort(&raw->imagic, 1); @@ -162,8 +165,10 @@ static rawImageRec *RawImageOpen(const char *fileName) } raw->rleEnd = 512 + (2 * x); fseek(raw->file, 512, SEEK_SET); - fread(raw->rowStart, 1, x, raw->file); - fread(raw->rowSize, 1, x, raw->file); + result = fread(raw->rowStart, 1, x, raw->file); + assert(result == x); + result = fread(raw->rowSize, 1, x, raw->file); + assert(result == x); if (swapFlag) { ConvertLong(raw->rowStart, (long) (x/sizeof(GLuint))); ConvertLong((GLuint *)raw->rowSize, (long) (x/sizeof(GLint))); @@ -193,11 +198,13 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) { unsigned char *iPtr, *oPtr, pixel; int count, done = 0; + size_t result; if ((raw->type & 0xFF00) == 0x0100) { fseek(raw->file, (long) raw->rowStart[y+z*raw->sizeY], SEEK_SET); - fread(raw->tmp, 1, (unsigned int)raw->rowSize[y+z*raw->sizeY], - raw->file); + result = fread(raw->tmp, 1, (unsigned int)raw->rowSize[y+z*raw->sizeY], + raw->file); + assert(result == (unsigned int)raw->rowSize[y+z*raw->sizeY]); iPtr = raw->tmp; oPtr = buf; @@ -222,7 +229,8 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) } else { fseek(raw->file, 512+(y*raw->sizeX)+(z*raw->sizeX*raw->sizeY), SEEK_SET); - fread(buf, 1, raw->sizeX, raw->file); + result = fread(buf, 1, raw->sizeX, raw->file); + assert(result == raw->sizeX); } } diff --git a/progs/vp/SConscript b/progs/vp/SConscript index 640c5dd8470..787cb793af2 100644 --- a/progs/vp/SConscript +++ b/progs/vp/SConscript @@ -1,13 +1,6 @@ -Import('env') +Import('*') -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(LIBS = ['$GLUT_LIB']) - -env.Program( +progs_env.Program( target = 'vp-tris', source = ['vp-tris.c'], ) diff --git a/progs/vp/vp-tris.c b/progs/vp/vp-tris.c index 29cd027b00c..09236c296f7 100644 --- a/progs/vp/vp-tris.c +++ b/progs/vp/vp-tris.c @@ -96,7 +96,8 @@ static void Init( void ) exit(1); } - sz = (GLuint) fread(buf, 1, sizeof(buf), f); + sz = (GLuint) fread(buf, 1, sizeof(buf) - 1, f); + buf[sizeof(buf) - 1] = '\0'; if (!feof(f)) { fprintf(stderr, "file too long\n"); fclose(f); diff --git a/progs/vpglsl/SConscript b/progs/vpglsl/SConscript index 640c5dd8470..787cb793af2 100644 --- a/progs/vpglsl/SConscript +++ b/progs/vpglsl/SConscript @@ -1,13 +1,6 @@ -Import('env') +Import('*') -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(LIBS = ['$GLUT_LIB']) - -env.Program( +progs_env.Program( target = 'vp-tris', source = ['vp-tris.c'], ) diff --git a/progs/wgl/SConscript b/progs/wgl/SConscript index 31f61676dec..248cc53a8d7 100644 --- a/progs/wgl/SConscript +++ b/progs/wgl/SConscript @@ -1,25 +1,17 @@ Import('*') -if env['platform'] != 'windows': +if progs_env['platform'] != 'windows': Return() -env = env.Clone() - -env.Append(LIBS = [ - 'kernel32', - 'user32', - 'gdi32', -]) - progs = [ 'sharedtex_mt', 'wglthreads', ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = prog + '/' + prog + '.c', ) -env.Program('wglinfo', ['wglinfo.c']) +progs_env.Program('wglinfo', ['wglinfo.c']) |