diff options
Diffstat (limited to 'progs')
83 files changed, 4643 insertions, 359 deletions
diff --git a/progs/demos/.gitignore b/progs/demos/.gitignore index d59d1752124..f3c7091bcc2 100644 --- a/progs/demos/.gitignore +++ b/progs/demos/.gitignore @@ -5,10 +5,12 @@ bounce clearspd copypix cubemap +dinoshade drawpix engine extfuncs.h fbo_firecube +fbotexture fire fogcoord fplight @@ -27,11 +29,9 @@ isosurf lodbias morph3d multiarb -occlude -osdemo paltex -pixeltex pointblast +projtex rain ray readpix @@ -61,4 +61,5 @@ trispd tunnel tunnel2 vao_demo +Windows winpos diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 32c60721232..c17595ec794 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -19,9 +19,11 @@ PROGS = \ clearspd \ copypix \ cubemap \ + dinoshade \ drawpix \ engine \ fbo_firecube \ + fbotexture \ fire \ fogcoord \ fplight \ @@ -32,9 +34,7 @@ PROGS = \ geartrain \ glinfo \ gloss \ - glslnoise \ gltestperf \ - glutfx \ isosurf \ ipers \ lodbias \ @@ -42,6 +42,7 @@ PROGS = \ multiarb \ paltex \ pointblast \ + projtex \ rain \ ray \ readpix \ @@ -49,7 +50,6 @@ PROGS = \ renormal \ shadowtex \ singlebuffer \ - streaming_rect \ spectex \ spriteblast \ stex3d \ @@ -57,9 +57,7 @@ PROGS = \ terrain \ tessdemo \ texcyl \ - texdown \ texenv \ - texobj \ textures \ trispd \ tunnel \ diff --git a/progs/demos/SConscript b/progs/demos/SConscript index bc166dd7895..f851870bcf3 100644 --- a/progs/demos/SConscript +++ b/progs/demos/SConscript @@ -39,11 +39,9 @@ progs = [ 'geartrain', 'glinfo', 'gloss', - 'glslnoise', 'gltestperf', - 'glutfx', - 'isosurf', 'ipers', + 'isosurf', 'lodbias', 'morph3d', 'multiarb', @@ -55,7 +53,6 @@ progs = [ 'renormal', 'shadowtex', 'singlebuffer', - 'streaming_rect', 'spectex', 'spriteblast', 'stex3d', @@ -63,15 +60,16 @@ progs = [ 'terrain', 'tessdemo', 'texcyl', - 'texdown', 'texenv', - 'texobj', 'textures', 'trispd', 'tunnel', 'tunnel2', 'vao_demo', 'winpos', + 'dinoshade', + 'fbotexture', + 'projtex', ] for prog in progs: diff --git a/progs/tests/dinoshade.c b/progs/demos/dinoshade.c index fb7c3f4535c..cbf8751e257 100644 --- a/progs/tests/dinoshade.c +++ b/progs/demos/dinoshade.c @@ -165,7 +165,7 @@ enum { }; /* Create a matrix that will project the desired shadow. */ -void +static void shadowMatrix(GLfloat shadowMat[4][4], GLfloat groundplane[4], GLfloat lightpos[4]) @@ -201,7 +201,7 @@ shadowMatrix(GLfloat shadowMat[4][4], } /* Find the plane equation given 3 points. */ -void +static void findPlane(GLfloat plane[4], GLfloat v0[3], GLfloat v1[3], GLfloat v2[3]) { @@ -224,7 +224,7 @@ findPlane(GLfloat plane[4], plane[D] = -(plane[A] * v0[X] + plane[B] * v0[Y] + plane[C] * v0[Z]); } -void +static void extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize, GLdouble thickness, GLuint side, GLuint edge, GLuint whole) { @@ -382,7 +382,7 @@ static GLfloat floorShadow[4][4]; static void redraw(void) { - int start, end; + int start = 0, end = 0; if (reportSpeed) { start = glutGet(GLUT_ELAPSED_TIME); @@ -624,6 +624,7 @@ redraw(void) glFinish(); end = glutGet(GLUT_ELAPSED_TIME); printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start); + fflush(stdout); } glutSwapBuffers(); @@ -878,6 +879,7 @@ main(int argc, char **argv) polygonOffsetVersion = MISSING; printf("\ndinoshine: Missing polygon offset.\n"); printf(" Expect shadow depth aliasing artifacts.\n\n"); + fflush(stdout); } } diff --git a/progs/tests/fbotexture.c b/progs/demos/fbotexture.c index 50a4b00afce..50a4b00afce 100644 --- a/progs/tests/fbotexture.c +++ b/progs/demos/fbotexture.c diff --git a/progs/demos/ipers.c b/progs/demos/ipers.c index 6e153c04e15..5d82b0dc924 100644 --- a/progs/demos/ipers.c +++ b/progs/demos/ipers.c @@ -237,10 +237,27 @@ special(int k, int x, int y) } static void +cleanup(void) +{ + int i; + + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); + + glDeleteLists(skydlist, 1); + for (i = 0; i < MAX_LOD; i++) { + glDeleteLists(LODdlist[i], 1); + glDeleteLists(LODnumpoly[i], 1); + } +} + + +static void key(unsigned char k, int x, int y) { switch (k) { case 27: + cleanup(); exit(0); break; @@ -707,6 +724,7 @@ main(int ac, char **av) glutIdleFunc(draw); glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/tests/projtex.c b/progs/demos/projtex.c index 800d81ecd67..99154d7bdc8 100644 --- a/progs/tests/projtex.c +++ b/progs/demos/projtex.c @@ -20,11 +20,7 @@ #include <math.h> #include <GL/glew.h> #include <GL/glut.h> -#if 0 -#include "texture.h" -#else -#include "../util/readtex.c" -#endif +#include "readtex.h" /* Some <math.h> files do not define M_PI... */ @@ -67,14 +63,15 @@ GLfloat zoomFactor = 1.0; /*****************************************************************/ -void ActiveTexture(int i) +static void +ActiveTexture(int i) { glActiveTextureARB(i); } /* matrix = identity */ -void +static void matrixIdentity(GLfloat matrix[16]) { matrix[0] = 1.0; @@ -96,7 +93,7 @@ matrixIdentity(GLfloat matrix[16]) } /* matrix2 = transpose(matrix1) */ -void +static void matrixTranspose(GLfloat matrix2[16], GLfloat matrix1[16]) { matrix2[0] = matrix1[0]; @@ -167,7 +164,7 @@ imgLoad(char *filenameIn, int borderIn, GLfloat borderColorIn[4], /*****************************************************************/ /* Load the image file specified on the command line as the current texture */ -void +static void loadImageTextures(void) { GLfloat borderColor[4] = @@ -252,7 +249,7 @@ loadImageTextures(void) } /* Create a simple spotlight pattern and make it the current texture */ -void +static void loadSpotlightTexture(void) { static int texWidth = 64, texHeight = 64; @@ -302,7 +299,7 @@ loadSpotlightTexture(void) /*****************************************************************/ -void +static void checkErrors(void) { GLenum error; @@ -311,7 +308,7 @@ checkErrors(void) } } -void +static void drawCube(void) { glBegin(GL_QUADS); @@ -360,7 +357,7 @@ drawCube(void) glEnd(); } -void +static void drawDodecahedron(void) { #define A (0.5 * 1.61803) /* (sqrt(5) + 1) / 2 */ @@ -446,7 +443,7 @@ drawDodecahedron(void) } } -void +static void drawSphere(void) { int numMajor = 24; @@ -573,7 +570,7 @@ drawTextureProjection(void) /*****************************************************************/ -void +static void initialize(void) { GLfloat light0Pos[4] = @@ -670,7 +667,7 @@ initialize(void) } } -void +static void display(void) { int i; @@ -755,10 +752,10 @@ display(void) /*****************************************************************/ /* simple trackball-like motion control */ -float lastPos[3]; -int lastTime; +static float lastPos[3]; +static int lastTime; -void +static void ptov(int x, int y, int width, int height, float v[3]) { float d, a; @@ -774,7 +771,7 @@ ptov(int x, int y, int width, int height, float v[3]) v[2] *= a; } -void +static void startMotion(int x, int y, int but, int time) { if (but == GLUT_LEFT_BUTTON) { @@ -789,13 +786,13 @@ startMotion(int x, int y, int but, int time) ptov(x, y, winWidth, winHeight, lastPos); } -void +static void animate(void) { glutPostRedisplay(); } -void +static void vis(int visible) { if (visible == GLUT_VISIBLE) { @@ -807,7 +804,7 @@ vis(int visible) } } -void +static void stopMotion(int but, int time) { if ((but == GLUT_LEFT_BUTTON && mode == MoveView) || @@ -829,7 +826,7 @@ stopMotion(int but, int time) } } -void +static void trackMotion(int x, int y) { float curPos[3], dx, dy, dz; @@ -854,7 +851,7 @@ trackMotion(int x, int y) /*****************************************************************/ -void +static void object(void) { static int object; @@ -881,7 +878,7 @@ nop(void) { } -void +static void texture(void) { static int texture = 0; @@ -912,7 +909,7 @@ texture(void) } } -void +static void help(void) { printf("'h' - help\n"); @@ -927,7 +924,7 @@ help(void) } /* ARGSUSED1 */ -void +static void key(unsigned char key, int x, int y) { switch (key) { @@ -966,7 +963,7 @@ key(unsigned char key, int x, int y) glutPostRedisplay(); } -void +static void mouse(int button, int state, int x, int y) { if (state == GLUT_DOWN) @@ -976,7 +973,7 @@ mouse(int button, int state, int x, int y) glutPostRedisplay(); } -void +static void reshape(int w, int h) { winWidth = w; @@ -985,7 +982,7 @@ reshape(int w, int h) } -void +static void menu(int selection) { if (selection == 666) { @@ -1005,6 +1002,7 @@ main(int argc, char **argv) assert(NumTextures <= MAX_TEX); glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); + glutInitWindowSize(500,500); (void) glutCreateWindow("projtex"); glewInit(); diff --git a/progs/demos/readpix.c b/progs/demos/readpix.c index c0aac2272f7..bbb3a68effa 100644 --- a/progs/demos/readpix.c +++ b/progs/demos/readpix.c @@ -17,6 +17,7 @@ #define IMAGE_FILE "../images/girl.rgb" static int ImgWidth, ImgHeight; +static int WinWidth, WinHeight; static GLenum ImgFormat; static GLubyte *Image = NULL; @@ -27,6 +28,7 @@ static int CPosX, CPosY; /* copypixels */ static GLboolean DrawFront = GL_FALSE; static GLboolean ScaleAndBias = GL_FALSE; static GLboolean Benchmark = GL_FALSE; +static GLboolean Triangle = GL_FALSE; static GLubyte *TempImage = NULL; #define COMBO 1 @@ -150,11 +152,60 @@ Display( void ) /* draw original image */ glRasterPos2i(APosX, 5); PrintString("Original"); - glRasterPos2i(APosX, APosY); - glEnable(GL_DITHER); - SetupPixelTransfer(GL_FALSE); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + if (!Triangle) { + glRasterPos2i(APosX, APosY); + glEnable(GL_DITHER); + SetupPixelTransfer(GL_FALSE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + } + else { + float z = 0; + + glViewport(APosX, APosY, ImgWidth, ImgHeight); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glDisable(GL_CULL_FACE); + + /* Red should never be seen + */ + glBegin(GL_POLYGON); + glColor3f(1,0,0); + glVertex3f(-2, -2, z); + glVertex3f(-2, 2, z); + glVertex3f(2, 2, z); + glVertex3f(2, -2, z); + glEnd(); + + /* Blue background + */ + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-1, -1, z); + glVertex3f(-1, 1, z); + glVertex3f(1, 1, z); + glVertex3f(1, -1, z); + glEnd(); + + /* Triangle + */ + glBegin(GL_TRIANGLES); + glColor3f(.8,0,0); + glVertex3f(-0.9, -0.9, z); + glColor3f(0,.9,0); + glVertex3f( 0.9, -0.9, z); + glColor3f(0,0,.7); + glVertex3f( 0.0, 0.9, z); + glEnd(); + + glColor3f(1,1,1); + + glViewport( 0, 0, WinWidth, WinHeight ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0.0, WinWidth, 0.0, WinHeight, -1.0, 1.0 ); + } /* might try alignment=4 here for testing */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -218,6 +269,9 @@ Display( void ) static void Reshape( int width, int height ) { + WinWidth = width; + WinHeight = height; + glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); @@ -236,6 +290,9 @@ Key( unsigned char key, int x, int y ) case 'b': Benchmark = GL_TRUE; break; + case 't': + Triangle = !Triangle; + break; case 's': ScaleAndBias = !ScaleAndBias; break; diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c index f10a01ec265..dc5a4bbc480 100644 --- a/progs/demos/shadowtex.c +++ b/progs/demos/shadowtex.c @@ -788,6 +788,7 @@ Key(unsigned char key, int x, int y) exit(0); break; } + fflush(stdout); glutPostRedisplay(); } @@ -1014,6 +1015,7 @@ PrintHelp(void) printf(" <shift> + cursor keys = rotate light source\n"); if (HaveEXTshadowFuncs) printf(" o = cycle through comparison modes\n"); + fflush(stdout); } diff --git a/progs/demos/teapot.c b/progs/demos/teapot.c index 38ede7ac3e1..6bf6e064095 100644 --- a/progs/demos/teapot.c +++ b/progs/demos/teapot.c @@ -173,10 +173,20 @@ static void special(int k, int x, int y) } } +static void cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); + glDeleteLists(teapotdlist, 1); + glDeleteLists(basedlist, 1); + glDeleteLists(lightdlist, 1); +} + static void key(unsigned char k, int x, int y) { switch(k) { case 27: + cleanup(); exit(0); break; @@ -670,6 +680,7 @@ int main(int ac, char **av) glutIdleFunc(draw); glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c index 6a240580e8a..6981da32988 100644 --- a/progs/demos/tunnel.c +++ b/progs/demos/tunnel.c @@ -203,10 +203,18 @@ special(int k, int x, int y) } static void +cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); +} + +static void key(unsigned char k, int x, int y) { switch (k) { case 27: + cleanup(); exit(0); break; @@ -531,5 +539,6 @@ main(int ac, char **av) glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/tunnel2.c b/progs/demos/tunnel2.c index f4171a8346d..0288ea0f8ce 100644 --- a/progs/demos/tunnel2.c +++ b/progs/demos/tunnel2.c @@ -201,12 +201,20 @@ special(int k, int x, int y) } static void +cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); +} + +static void key(unsigned char k, int x, int y) { switch (k) { case 27: glutDestroyWindow(channel[0]); glutDestroyWindow(channel[1]); + cleanup(); exit(0); break; @@ -602,6 +610,7 @@ main(int ac, char **av) calcposobs(); glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/vao_demo.c b/progs/demos/vao_demo.c index ce416712fe2..206e06fc6c7 100644 --- a/progs/demos/vao_demo.c +++ b/progs/demos/vao_demo.c @@ -260,6 +260,8 @@ static void Key( unsigned char key, int x, int y ) (void) y; switch (key) { case 27: + (*delete_vertex_arrays)( 1, & cube_array_obj ); + (*delete_vertex_arrays)( 1, & oct_array_obj ); glutDestroyWindow(Win); exit(0); break; diff --git a/progs/fp/SConscript b/progs/fp/SConscript index 553799758b0..a78318542c1 100644 --- a/progs/fp/SConscript +++ b/progs/fp/SConscript @@ -11,7 +11,20 @@ env.Prepend(CPPPATH = [ env.Prepend(LIBS = ['$GLUT_LIB']) -env.Program( - target = 'fp-tri', - source = ['fp-tri.c'], +progs = [ + 'fp-tri', + 'tri-depth', + 'tri-depth2', + 'tri-depthwrite', + 'tri-depthwrite2', + 'tri-inv', + 'tri-param', + 'tri-tex', + 'point-position', +] + +for prog in progs: + env.Program( + target = prog, + source = [prog + '.c'], ) diff --git a/progs/fp/fp-tri.c b/progs/fp/fp-tri.c index 6c15540d38d..52a8fcfc22a 100644 --- a/progs/fp/fp-tri.c +++ b/progs/fp/fp-tri.c @@ -89,7 +89,7 @@ static void Init( void ) } fprintf(stderr, "%.*s\n", sz, buf); - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } diff --git a/progs/fp/point-position.c b/progs/fp/point-position.c index c352a939cb1..c0963d7a0b5 100644 --- a/progs/fp/point-position.c +++ b/progs/fp/point-position.c @@ -2,9 +2,8 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> -#include "GL/gl.h" @@ -17,7 +16,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -109,6 +108,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/swz3.txt b/progs/fp/swz3.txt new file mode 100644 index 00000000000..382f5880d3c --- /dev/null +++ b/progs/fp/swz3.txt @@ -0,0 +1,5 @@ +!!ARBfp1.0 +TEMP R0, R1; +MOV R0, -fragment.color; +SWZ result.color, R0, -y, -x, z, 1; +END diff --git a/progs/fp/tri-depth.c b/progs/fp/tri-depth.c index a1f0579c8e1..5488469e806 100644 --- a/progs/fp/tri-depth.c +++ b/progs/fp/tri-depth.c @@ -2,9 +2,8 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> -#include "GL/gl.h" @@ -19,7 +18,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -89,8 +88,6 @@ int main(int argc, char **argv) glutInit(&argc, argv); - - glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); type = GLUT_RGB; @@ -101,6 +98,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-depth2.c b/progs/fp/tri-depth2.c index f3096282833..6ed23071157 100644 --- a/progs/fp/tri-depth2.c +++ b/progs/fp/tri-depth2.c @@ -2,9 +2,8 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> -#include "GL/gl.h" @@ -21,7 +20,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -106,6 +105,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-depthwrite.c b/progs/fp/tri-depthwrite.c index fedeec4577d..8e4f3e62451 100644 --- a/progs/fp/tri-depthwrite.c +++ b/progs/fp/tri-depthwrite.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -16,7 +16,7 @@ static void Init(void) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -97,6 +97,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-depthwrite2.c b/progs/fp/tri-depthwrite2.c index 5547092ec9b..3c0b4d30c97 100644 --- a/progs/fp/tri-depthwrite2.c +++ b/progs/fp/tri-depthwrite2.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -16,7 +16,7 @@ static void Init(void) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -97,6 +97,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-inv.c b/progs/fp/tri-inv.c index e9023323862..7e8d8c5ce29 100644 --- a/progs/fp/tri-inv.c +++ b/progs/fp/tri-inv.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -17,7 +17,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -99,6 +99,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-param.c b/progs/fp/tri-param.c index f3e55af3f1b..57443d71bd0 100644 --- a/progs/fp/tri-param.c +++ b/progs/fp/tri-param.c @@ -2,9 +2,9 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> -#include "GL/gl.h" + static void Init( void ) { @@ -15,7 +15,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -104,6 +104,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-tex.c b/progs/fp/tri-tex.c index 87f63894ce9..1dbbb201cef 100644 --- a/progs/fp/tri-tex.c +++ b/progs/fp/tri-tex.c @@ -3,7 +3,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.c" @@ -23,7 +23,7 @@ static void Init( void ) GLuint modulateProg; GLuint Texture; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -120,6 +120,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index d3e31163d8e..39d90c23ac5 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -1,3 +1,4 @@ +array bitmap brick bump @@ -11,6 +12,7 @@ mandelbrot multinoise multitex noise +noise2 pointcoord points readtex.c @@ -21,6 +23,7 @@ shaderutil.c shaderutil.h shadow_sampler skinning +texaaline texdemo1 toyball trirast diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 0f1a299570f..f97cdb69429 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -5,46 +5,69 @@ include $(TOP)/configs/current INCDIR = $(TOP)/include -LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) +LIB_DEP = \ + $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) \ + $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) \ + $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) -PROGS = \ - bitmap \ - brick \ - bump \ - convolutions \ - deriv \ - identity \ - fragcoord \ - linktest \ - mandelbrot \ - multinoise \ - multitex \ - noise \ - points \ - pointcoord \ - samplers \ - samplers_array \ - shadow_sampler \ - skinning \ - texdemo1 \ - toyball \ - twoside \ - trirast \ - vert-or-frag-only \ - vert-tex +INCLUDE_DIRS = -I$(TOP)/progs/util + +DEMO_SOURCES = \ + array.c \ + bitmap.c \ + brick.c \ + bump.c \ + convolutions.c \ + deriv.c \ + fragcoord.c \ + identity.c \ + linktest.c \ + mandelbrot.c \ + multinoise.c \ + multitex.c \ + noise.c \ + noise2.c \ + pointcoord.c \ + points.c \ + samplers.c \ + shadow_sampler.c \ + skinning.c \ + texaaline.c \ + texdemo1.c \ + toyball.c \ + trirast.c \ + twoside.c \ + vert-or-frag-only.c \ + vert-tex.c + +UTIL_HEADERS = \ + extfuncs.h \ + shaderutil.h \ + readtex.h + +UTIL_SOURCES = \ + shaderutil.c \ + readtex.c + +UTIL_OBJS = $(UTIL_SOURCES:.c=.o) + + +PROGS = $(DEMO_SOURCES:%.c=%) + ##### RULES ##### -.SUFFIXES: -.SUFFIXES: .c +# make .o file from .c file: +.c.o: + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) $< -o $@ -# make executable from .c file: -.c: $(LIB_DEP) - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@ +# make executable from .o files +.o: + $(APP_CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(UTIL_OBJS) $(LIBS) -o $@ ##### TARGETS ##### @@ -52,188 +75,164 @@ PROGS = \ default: $(PROGS) +clean: + -rm -f $(PROGS) + -rm -f *.o *~ + -rm -f extfuncs.h + -rm -f shaderutil.* + -rm -f readtex.* + + ##### Extra dependencies -extfuncs.h: $(TOP)/progs/util/extfuncs.h +extfuncs.h: $(TOP)/progs/util/extfuncs.h cp $< . - readtex.c: $(TOP)/progs/util/readtex.c cp $< . readtex.h: $(TOP)/progs/util/readtex.h cp $< . -readtex.o: readtex.c readtex.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) readtex.c - - shaderutil.c: $(TOP)/progs/util/shaderutil.c cp $< . shaderutil.h: $(TOP)/progs/util/shaderutil.h cp $< . -shaderutil.o: shaderutil.c shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) shaderutil.c +array.o: $(UTIL_HEADERS) -bitmap.o: bitmap.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bitmap.c +array: array.o $(UTIL_OBJS) -bitmap: bitmap.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bitmap.o shaderutil.o $(LIBS) -o $@ +bitmap.o: $(UTIL_HEADERS) -brick.o: brick.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) brick.c +bitmap: bitmap.o $(UTIL_OBJS) -brick: brick.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) brick.o shaderutil.o $(LIBS) -o $@ +brick.o: $(UTIL_HEADERS) -bump.o: bump.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bump.c +brick: brick.o $(UTIL_OBJS) -bump: bump.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bump.o shaderutil.o $(LIBS) -o $@ +bump.o: $(UTIL_HEADERS) -convolutions.o: convolutions.c readtex.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c +bump: bump.o $(UTIL_OBJS) -convolutions: convolutions.o readtex.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) convolutions.o readtex.o $(LIBS) -o $@ +convolutions.o: $(UTIL_HEADERS) -deriv.o: deriv.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) deriv.c +convolutions: convolutions.o $(UTIL_OBJS) -deriv: deriv.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) deriv.o shaderutil.o $(LIBS) -o $@ +deriv.o: deriv.c $(UTIL_HEADERS) -identity.o: identity.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) identity.c +deriv: deriv.o $(UTIL_OBJS) -identity: identity.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) identity.o shaderutil.o $(LIBS) -o $@ +identity.o: $(UTIL_HEADERS) -fragcoord.o: fragcoord.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) fragcoord.c +identity: identity.o $(UTIL_OBJS) -fragcoord: fragcoord.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) fragcoord.o shaderutil.o $(LIBS) -o $@ +fragcoord.o: $(UTIL_HEADERS) -linktest.o: linktest.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) linktest.c +fragcoord: fragcoord.o $(UTIL_OBJS) -linktest: linktest.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) linktest.o shaderutil.o $(LIBS) -o $@ -mandelbrot.o: mandelbrot.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c +linktest.o: $(UTIL_HEADERS) -mandelbrot: mandelbrot.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) mandelbrot.o shaderutil.o $(LIBS) -o $@ +linktest: linktest.o $(UTIL_OBJS) -multitex.o: multitex.c extfuncs.h readtex.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) multitex.c -multitex: multitex.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) multitex.o readtex.o shaderutil.o $(LIBS) -o $@ +mandelbrot.o: $(UTIL_HEADERS) +mandelbrot: mandelbrot.o $(UTIL_OBJS) -noise.o: noise.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) noise.c -noise: noise.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise.o shaderutil.o $(LIBS) -o $@ +multinoise.o: $(UTIL_HEADERS) +multinoise: multinoise.o $(UTIL_OBJS) -points.o: points.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) points.c -points: points.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) points.o shaderutil.o $(LIBS) -o $@ +multitex.o: $(UTIL_HEADERS) +multitex: multitex.o $(UTIL_OBJS) -pointcoord.o: pointcoord.c readtex.h extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) pointcoord.c -pointcoord: pointcoord.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) pointcoord.o readtex.o shaderutil.o $(LIBS) -o $@ +noise.o: $(UTIL_HEADERS) +noise: noise.o $(UTIL_OBJS) -samplers.o: samplers.c readtex.h extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) samplers.c -samplers: samplers.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers.o readtex.o shaderutil.o $(LIBS) -o $@ +noise2.o: $(UTIL_HEADERS) -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 +noise2: noise2.o $(UTIL_OBJS) -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 +points.o: $(UTIL_HEADERS) -skinning: skinning.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) skinning.o readtex.o shaderutil.o $(LIBS) -o $@ +points: points.o $(UTIL_OBJS) -texdemo1.o: texdemo1.c readtex.h extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c +pointcoord.o: $(UTIL_HEADERS) -texdemo1: texdemo1.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) texdemo1.o readtex.o shaderutil.o $(LIBS) -o $@ +pointcoord: pointcoord.o $(UTIL_OBJS) -toyball.o: toyball.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) toyball.c +samplers.o: $(UTIL_HEADERS) -toyball: toyball.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) toyball.o shaderutil.o $(LIBS) -o $@ +samplers: samplers.o $(UTIL_OBJS) -twoside.o: twoside.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) twoside.c +samplers_array.o: $(UTIL_HEADERS) -twoside: twoside.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) twoside.o shaderutil.o $(LIBS) -o $@ +samplers_array: samplers_array.o $(UTIL_OBJS) -trirast.o: trirast.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) trirast.c +shadow_sampler.o: $(UTIL_HEADERS) -trirast: trirast.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ +shadow_sampler: shadow_sampler.o $(UTIL_OBJS) -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 +skinning.o: $(UTIL_HEADERS) -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 $@ +skinning: skinning.o $(UTIL_OBJS) -vert-tex.o: vert-tex.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-tex.c +texaaline.o: $(UTIL_HEADERS) -vert-tex: vert-tex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-tex.o shaderutil.o $(LIBS) -o $@ +texaaline: texaaline.o $(UTIL_OBJS) +texdemo1.o: $(UTIL_HEADERS) +texdemo1: texdemo1.o $(UTIL_OBJS) -clean: - -rm -f $(PROGS) - -rm -f *.o *~ - -rm -f extfuncs.h - -rm -f shaderutil.* + +toyball.o: $(UTIL_HEADERS) + +toyball: toyball.o $(UTIL_OBJS) + + +twoside.o: $(UTIL_HEADERS) + +twoside: twoside.o $(UTIL_OBJS) + + +trirast.o: $(UTIL_HEADERS) + +trirast: trirast.o $(UTIL_OBJS) + + +vert-or-frag-only.o: $(UTIL_HEADERS) + +vert-or-frag-only: vert-or-frag-only.o $(UTIL_OBJS) + + +vert-tex.o: $(UTIL_HEADERS) + +vert-tex: vert-tex.o $(UTIL_OBJS) diff --git a/progs/glsl/array.c b/progs/glsl/array.c new file mode 100644 index 00000000000..46ef8043bcf --- /dev/null +++ b/progs/glsl/array.c @@ -0,0 +1,261 @@ +/** + * Test variable array indexing in a vertex shader. + * Brian Paul + * 17 April 2009 + */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> +#include "extfuncs.h" +#include "shaderutil.h" + + +/** + * The vertex position.z is used as a (variable) index into an + * array which returns a new Z value. + */ +static const char *VertShaderText = + "uniform sampler2D tex1; \n" + "uniform float HeightArray[20]; \n" + "void main() \n" + "{ \n" + " vec4 pos = gl_Vertex; \n" + " int i = int(pos.z * 9.5); \n" + " pos.z = HeightArray[i]; \n" + " gl_Position = gl_ModelViewProjectionMatrix * pos; \n" + " gl_FrontColor = pos; \n" + "} \n"; + +static const char *FragShaderText = + "void main() \n" + "{ \n" + " gl_FragColor = gl_Color; \n" + "} \n"; + + +static GLuint fragShader; +static GLuint vertShader; +static GLuint program; + +static GLint win = 0; +static GLboolean Anim = GL_TRUE; +static GLboolean WireFrame = GL_TRUE; +static GLfloat xRot = -70.0f, yRot = 0.0f, zRot = 0.0f; + + +static void +Idle(void) +{ + zRot = 90 + glutGet(GLUT_ELAPSED_TIME) * 0.05; + glutPostRedisplay(); +} + + +/** z=f(x,y) */ +static float +fz(float x, float y) +{ + return fabs(cos(1.5*x) + cos(1.5*y)); +} + + +static void +DrawMesh(void) +{ + GLfloat xmin = -2.0, xmax = 2.0; + GLfloat ymin = -2.0, ymax = 2.0; + GLuint xdivs = 20, ydivs = 20; + GLfloat dx = (xmax - xmin) / xdivs; + GLfloat dy = (ymax - ymin) / ydivs; + GLfloat ds = 1.0 / xdivs, dt = 1.0 / ydivs; + GLfloat x, y, s, t; + GLuint i, j; + + y = ymin; + t = 0.0; + for (i = 0; i < ydivs; i++) { + x = xmin; + s = 0.0; + glBegin(GL_QUAD_STRIP); + for (j = 0; j < xdivs; j++) { + float z0 = fz(x, y), z1 = fz(x, y + dy); + + glTexCoord2f(s, t); + glVertex3f(x, y, z0); + + glTexCoord2f(s, t + dt); + glVertex3f(x, y + dy, z1); + x += dx; + s += ds; + } + glEnd(); + y += dy; + t += dt; + } +} + + +static void +Redisplay(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (WireFrame) + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glPushMatrix(); + glRotatef(xRot, 1.0f, 0.0f, 0.0f); + glRotatef(yRot, 0.0f, 1.0f, 0.0f); + glRotatef(zRot, 0.0f, 0.0f, 1.0f); + + glPushMatrix(); + DrawMesh(); + glPopMatrix(); + + glPopMatrix(); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -15.0f); +} + + +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) +{ + const GLfloat step = 2.0; + (void) x; + (void) y; + + switch(key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'w': + WireFrame = !WireFrame; + break; + case 'z': + zRot += step; + break; + case 'Z': + zRot -= step; + break; + case 27: + CleanUp(); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +SpecialKey(int key, int x, int y) +{ + const GLfloat step = 2.0; + + (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 +Init(void) +{ + GLfloat HeightArray[20]; + GLint u, i; + + if (!ShadersSupported()) + exit(1); + + GetExtensionFuncs(); + + vertShader = CompileShaderText(GL_VERTEX_SHADER, VertShaderText); + fragShader = CompileShaderText(GL_FRAGMENT_SHADER, FragShaderText); + program = LinkShaders(vertShader, fragShader); + + glUseProgram_func(program); + + /* Setup the HeightArray[] uniform */ + for (i = 0; i < 20; i++) + HeightArray[i] = i / 20.0; + u = glGetUniformLocation_func(program, "HeightArray"); + glUniform1fv_func(u, 20, HeightArray); + + assert(glGetError() == 0); + + glClearColor(0.4f, 0.4f, 0.8f, 0.0f); + glEnable(GL_DEPTH_TEST); + glColor3f(1, 1, 1); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowSize(500, 500); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Redisplay); + Init(); + if (Anim) + glutIdleFunc(Idle); + glutMainLoop(); + return 0; +} + diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c index b93ab44b5b9..0ea1f8331ff 100644 --- a/progs/glsl/bump.c +++ b/progs/glsl/bump.c @@ -150,10 +150,11 @@ Redisplay(void) static void Reshape(int width, int height) { + float ar = (float) width / (float) height; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -15.0f); diff --git a/progs/glsl/linktest.c b/progs/glsl/linktest.c index 601b24e893e..988d0823418 100644 --- a/progs/glsl/linktest.c +++ b/progs/glsl/linktest.c @@ -242,7 +242,7 @@ int main(int argc, char *argv[]) { glutInit(&argc, argv); - glutInitWindowPosition( 0, 0); + glutInitWindowSize(300, 300); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); Win = glutCreateWindow(argv[0]); glutReshapeFunc(Reshape); diff --git a/progs/glsl/multitex.c b/progs/glsl/multitex.c index b4be463787a..1a1c63aaf48 100644 --- a/progs/glsl/multitex.c +++ b/progs/glsl/multitex.c @@ -51,6 +51,8 @@ static GLfloat Xrot = 0.0, Yrot = .0, Zrot = 0.0; static GLfloat EyeDist = 10; static GLboolean Anim = GL_TRUE; static GLboolean UseArrays = GL_TRUE; +static GLboolean UseVBO = GL_TRUE; +static GLuint VBO = 0; static GLint VertCoord_attr = -1, TexCoord0_attr = -1, TexCoord1_attr = -1; @@ -76,28 +78,81 @@ static const GLfloat VertCoords[4][2] = { }; + +static void +SetupVertexBuffer(void) +{ + glGenBuffersARB_func(1, &VBO); + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, VBO); + + glBufferDataARB_func(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords) + + sizeof(Tex0Coords) + + sizeof(Tex1Coords), + NULL, + GL_STATIC_DRAW_ARB); + + /* non-interleaved vertex arrays */ + + glBufferSubDataARB_func(GL_ARRAY_BUFFER_ARB, + 0, /* offset */ + sizeof(VertCoords), /* size */ + VertCoords); /* data */ + + glBufferSubDataARB_func(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords), /* offset */ + sizeof(Tex0Coords), /* size */ + Tex0Coords); /* data */ + + glBufferSubDataARB_func(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords) + + sizeof(Tex0Coords), /* offset */ + sizeof(Tex1Coords), /* size */ + Tex1Coords); /* data */ + + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, 0); +} + + static void DrawPolygonArray(void) { + void *vertPtr, *tex0Ptr, *tex1Ptr; + + if (UseVBO) { + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, VBO); + vertPtr = (void *) 0; + tex0Ptr = (void *) sizeof(VertCoords); + tex1Ptr = (void *) (sizeof(VertCoords) + sizeof(Tex0Coords)); + } + else { + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, 0); + vertPtr = VertCoords; + tex0Ptr = Tex0Coords; + tex1Ptr = Tex1Coords; + } + if (VertCoord_attr >= 0) { glVertexAttribPointer_func(VertCoord_attr, 2, GL_FLOAT, GL_FALSE, - 0, VertCoords); + 0, vertPtr); glEnableVertexAttribArray_func(VertCoord_attr); } else { - glVertexPointer(2, GL_FLOAT, 0, VertCoords); + glVertexPointer(2, GL_FLOAT, 0, vertPtr); glEnable(GL_VERTEX_ARRAY); } glVertexAttribPointer_func(TexCoord0_attr, 2, GL_FLOAT, GL_FALSE, - 0, Tex0Coords); + 0, tex0Ptr); glEnableVertexAttribArray_func(TexCoord0_attr); glVertexAttribPointer_func(TexCoord1_attr, 2, GL_FLOAT, GL_FALSE, - 0, Tex1Coords); + 0, tex1Ptr); glEnableVertexAttribArray_func(TexCoord1_attr); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, 0); } @@ -163,6 +218,10 @@ key(unsigned char k, int x, int y) UseArrays = !UseArrays; printf("Arrays: %d\n", UseArrays); break; + case 'v': + UseVBO = !UseVBO; + printf("Use VBO: %d\n", UseVBO); + break; case ' ': Anim = !Anim; if (Anim) @@ -271,9 +330,24 @@ CreateProgram(const char *vertProgFile, const char *fragProgFile, InitUniforms(program, uniforms); + VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + if (VertCoord_attr > 0) { + /* We want the VertCoord attrib to have position zero so that + * the call to glVertexAttrib(0, xyz) triggers vertex processing. + * Otherwise, if TexCoord0 or TexCoord1 gets position 0 we'd have + * to set that attribute last (which is a PITA to manage). + */ + glBindAttribLocation_func(program, 0, "VertCoord"); + /* re-link */ + glLinkProgram_func(program); + /* VertCoord_attr should be zero now */ + VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + assert(VertCoord_attr == 0); + } + TexCoord0_attr = glGetAttribLocation_func(program, "TexCoord0"); TexCoord1_attr = glGetAttribLocation_func(program, "TexCoord1"); - VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + printf("TexCoord0_attr = %d\n", TexCoord0_attr); printf("TexCoord1_attr = %d\n", TexCoord1_attr); printf("VertCoord_attr = %d\n", VertCoord_attr); @@ -299,12 +373,19 @@ InitGL(void) /*exit(1);*/ } printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); - + printf("Usage:\n"); + printf(" a - toggle arrays vs. immediate mode rendering\n"); + printf(" v - toggle VBO usage for array rendering\n"); + printf(" z/Z - change viewing distance\n"); + printf(" SPACE - toggle animation\n"); + printf(" Esc - exit\n"); GetExtensionFuncs(); InitTextures(); InitPrograms(); + SetupVertexBuffer(); + glEnable(GL_DEPTH_TEST); glClearColor(.6, .6, .9, 0); diff --git a/progs/demos/glslnoise.c b/progs/glsl/noise2.c index e972b62673f..e972b62673f 100644 --- a/progs/demos/glslnoise.c +++ b/progs/glsl/noise2.c diff --git a/progs/glsl/texaaline.c b/progs/glsl/texaaline.c new file mode 100644 index 00000000000..0b3cc849586 --- /dev/null +++ b/progs/glsl/texaaline.c @@ -0,0 +1,369 @@ +/** + * AA lines with texture mapped quads + * + * Brian Paul + * 9 Feb 2008 + */ + + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> +#include "extfuncs.h" + + +static GLint WinWidth = 300, WinHeight = 300; +static GLint win = 0; +static GLfloat Width = 8.; + +/* + * Quad strip for line from v0 to v1: + * + 1 3 5 7 + +---+---------------------+---+ + | | + | *v0 v1* | + | | + +---+---------------------+---+ + 0 2 4 6 + */ +static void +QuadLine(const GLfloat *v0, const GLfloat *v1, GLfloat width) +{ + GLfloat dx = v1[0] - v0[0]; + GLfloat dy = v1[1] - v0[1]; + GLfloat len = sqrt(dx*dx + dy*dy); + float dx0, dx1, dx2, dx3, dx4, dx5, dx6, dx7; + float dy0, dy1, dy2, dy3, dy4, dy5, dy6, dy7; + + dx /= len; + dy /= len; + + width *= 0.5; /* half width */ + dx = dx * (width + 0.0); + dy = dy * (width + 0.0); + + dx0 = -dx+dy; dy0 = -dy-dx; + dx1 = -dx-dy; dy1 = -dy+dx; + + dx2 = 0+dy; dy2 = -dx+0; + dx3 = 0-dy; dy3 = +dx+0; + + dx4 = 0+dy; dy4 = -dx+0; + dx5 = 0-dy; dy5 = +dx+0; + + dx6 = dx+dy; dy6 = dy-dx; + dx7 = dx-dy; dy7 = dy+dx; + + /* + printf("dx, dy = %g, %g\n", dx, dy); + printf(" dx0, dy0: %g, %g\n", dx0, dy0); + printf(" dx1, dy1: %g, %g\n", dx1, dy1); + printf(" dx2, dy2: %g, %g\n", dx2, dy2); + printf(" dx3, dy3: %g, %g\n", dx3, dy3); + */ + + glBegin(GL_QUAD_STRIP); + glTexCoord2f(0, 0); + glVertex2f(v0[0] + dx0, v0[1] + dy0); + glTexCoord2f(0, 1); + glVertex2f(v0[0] + dx1, v0[1] + dy1); + + glTexCoord2f(0.5, 0); + glVertex2f(v0[0] + dx2, v0[1] + dy2); + glTexCoord2f(0.5, 1); + glVertex2f(v0[0] + dx3, v0[1] + dy3); + + glTexCoord2f(0.5, 0); + glVertex2f(v1[0] + dx2, v1[1] + dy2); + glTexCoord2f(0.5, 1); + glVertex2f(v1[0] + dx3, v1[1] + dy3); + + glTexCoord2f(1, 0); + glVertex2f(v1[0] + dx6, v1[1] + dy6); + glTexCoord2f(1, 1); + glVertex2f(v1[0] + dx7, v1[1] + dy7); + glEnd(); +} + + +static float Cos(float a) +{ + return cos(a * M_PI / 180.); +} + +static float Sin(float a) +{ + return sin(a * M_PI / 180.); +} + +static void +Redisplay(void) +{ + int i; + + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f(1, 1, 1); + + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + + for (i = 0; i < 360; i+=5) { + float v0[2], v1[2]; + v0[0] = 150 + 40 * Cos(i); + v0[1] = 150 + 40 * Sin(i); + v1[0] = 150 + 130 * Cos(i); + v1[1] = 150 + 130 * Sin(i); + QuadLine(v0, v1, Width); + } + + { + float v0[2], v1[2], x; + for (x = 0; x < 1.0; x += 0.2) { + v0[0] = 150 + x; + v0[1] = 150 + x * 40 - 20; + v1[0] = 150 + x + 5.0; + v1[1] = 150 + x * 40 - 20; + QuadLine(v0, v1, Width); + } + } + + glDisable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, 0, height, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +CleanUp(void) +{ + glutDestroyWindow(win); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch(key) { + case 'w': + Width -= 0.5; + break; + case 'W': + Width += 0.5; + break; + case 27: + CleanUp(); + exit(0); + break; + } +#if 0 + if (Width < 3) + Width = 3; +#endif + printf("Width = %g\n", Width); + glutPostRedisplay(); +} + + +static float +ramp4(GLint i, GLint size) +{ + float d; + if (i < 4 ) { + d = i / 4.0; + } + else if (i >= size - 5) { + d = 1.0 - (i - (size - 5)) / 4.0; + } + else { + d = 1.0; + } + return d; +} + +static float +ramp2(GLint i, GLint size) +{ + float d; + if (i < 2 ) { + d = i / 2.0; + } + else if (i >= size - 3) { + d = 1.0 - (i - (size - 3)) / 2.0; + } + else { + d = 1.0; + } + return d; +} + +static float +ramp1(GLint i, GLint size) +{ + float d; + if (i == 0 || i == size-1) { + d = 0.0; + } + else { + d = 1.0; + } + return d; +} + + +/** + * Make an alpha texture for antialiasing lines. + * Just a linear fall-off ramp for now. + * Should have a number of different textures for different line widths. + * Could try a bell-like-curve.... + */ +static void +MakeTexture(void) +{ +#define SZ 8 + GLfloat tex[SZ][SZ]; /* alpha tex */ + int i, j; + for (i = 0; i < SZ; i++) { + for (j = 0; j < SZ; j++) { +#if 0 + float k = (SZ-1) / 2.0; + float dx = fabs(i - k) / k; + float dy = fabs(j - k) / k; + float d; + + dx = 1.0 - dx; + dy = 1.0 - dy; + d = dx * dy; + +#else + float d = ramp1(i, SZ) * ramp1(j, SZ); + printf("%d, %d: %g\n", i, j, d); +#endif + tex[i][j] = d; + } + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, SZ, SZ, 0, GL_ALPHA, GL_FLOAT, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#undef SZ +} + + +static void +MakeMipmap(void) +{ +#define SZ 64 + GLfloat tex[SZ][SZ]; /* alpha tex */ + int level; + + glPixelStorei(GL_UNPACK_ROW_LENGTH, SZ); + for (level = 0; level < 7; level++) { + int sz = 1 << (6 - level); + int i, j; + for (i = 0; i < sz; i++) { + for (j = 0; j < sz; j++) { + if (level == 6) + tex[i][j] = 1.0; + else if (level == 5) + tex[i][j] = 0.5; + else + tex[i][j] = ramp1(i, sz) * ramp1(j, sz); + } + } + + glTexImage2D(GL_TEXTURE_2D, level, GL_ALPHA, + sz, sz, 0, GL_ALPHA, GL_FLOAT, tex); + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); + ////glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#undef SZ +} + + +static void +Init(void) +{ + const char *version; + + (void) MakeTexture; + (void) ramp4; + (void) ramp2; + + 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(); + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#if 0 + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); +#elif 0 + MakeTexture(); +#else + MakeMipmap(); +#endif +} + + +static void +ParseOptions(int argc, char *argv[]) +{ +} + + +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(); + glutMainLoop(); + return 0; +} diff --git a/progs/rbug/.gitignore b/progs/rbug/.gitignore new file mode 100644 index 00000000000..26a561c8290 --- /dev/null +++ b/progs/rbug/.gitignore @@ -0,0 +1,11 @@ +bin_to_bmp +simple_client +simple_server +shdr_info +shdr_dump +shdr_disable +ctx_info +tex_dump +tex_info +*.bmp +*.bin diff --git a/progs/rbug/Makefile b/progs/rbug/Makefile new file mode 100644 index 00000000000..718f7a2bb52 --- /dev/null +++ b/progs/rbug/Makefile @@ -0,0 +1,47 @@ +# progs/rbug/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + $(PROG_INCLUDES) + +LINKS = \ + $(GALLIUM_AUXILIARIES) \ + $(PROG_LINKS) + +SOURCES = \ + bin_to_bmp.c \ + simple_client.c \ + simple_server.c \ + shdr_info.c \ + shdr_dump.c \ + shdr_disable.c \ + ctx_info.c \ + tex_info.c \ + tex_dump.c + + +OBJECTS = $(SOURCES:.c=.o) + +PROGS = $(OBJECTS:.o=) + +##### TARGETS ##### + +default: $(OBJECTS) $(PROGS) + +clean: + -rm -f $(PROGS) + -rm -f *.o + +##### RULES ##### + +$(OBJECTS): %.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@ + +$(PROGS): %: %.o + $(CC) $(LDFLAGS) $< $(LINKS) -o $@ diff --git a/progs/rbug/README b/progs/rbug/README new file mode 100644 index 00000000000..0eb0a5de9a5 --- /dev/null +++ b/progs/rbug/README @@ -0,0 +1,39 @@ + REMOTE DEBUGGING CLI APPLICATIONS + + += About = + +This directory contains a Gallium3D remote debugging cli applications. + + += Build Instructions = + +To build, build a normal gallium build and from this directory do the following. + + make + += Usage = + +Make sure that you driver has trace integration, see +src/gallium/driver/trace/README for more information about that. Then from on +the computer that you want to debug do: + + export GALLIUM_RBUG=true + + <launch app> + +From the debugging computer launch apps form this directory. Currently ip +addresses are hardcoded and you need to edit the application, but that will +change in the future. + += Testing = + +The two apps simple_client and simple_server. Are unit testing of the +connection and (de)marsheler. Just run the server first and then the client: + + ./simple_server & + ./simple_client + + +-- +Jakob Bornecrantz <[email protected]> diff --git a/progs/rbug/bin_to_bmp.c b/progs/rbug/bin_to_bmp.c new file mode 100644 index 00000000000..cdae3486ce0 --- /dev/null +++ b/progs/rbug/bin_to_bmp.c @@ -0,0 +1,110 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" +#include "util/u_tile.h" + +static uint8_t* read(const char *filename, unsigned size); +static void dump(unsigned src_width, unsigned src_height, + unsigned src_stride, enum pipe_format src_format, + uint8_t *data, unsigned src_size); + +int main(int argc, char** argv) +{ + /* change these */ + unsigned width = 64; + unsigned height = 64; + unsigned stride = width * 4; + unsigned size = stride * height; + const char *filename = "mybin.bin"; + enum pipe_format format = PIPE_FORMAT_A8R8G8B8_UNORM; + + dump(width, height, stride, format, read(filename, size), size); + + return 0; +} + +static void dump(unsigned width, unsigned height, + unsigned src_stride, enum pipe_format src_format, + uint8_t *data, unsigned src_size) +{ + struct pipe_format_block src_block; + + enum pipe_format dst_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + struct pipe_format_block dst_block; + unsigned dst_stride; + unsigned dst_size; + float *rgba; + int i; + char filename[512]; + + { + pf_get_block(src_format, &src_block); + assert(src_stride >= pf_get_stride(&src_block, width)); + assert(src_size >= pf_get_2d_size(&src_block, src_stride, width)); + } + { + pf_get_block(dst_format, &dst_block); + dst_stride = pf_get_stride(&dst_block, width); + dst_size = pf_get_2d_size(&dst_block, dst_stride, width); + rgba = MALLOC(dst_size); + } + + util_snprintf(filename, 512, "%s.bmp", pf_name(src_format)); + + if (pf_is_compressed(src_format)) { + debug_printf("skipping: %s\n", filename); + return; + } + + debug_printf("saving: %s\n", filename); + + for (i = 0; i < height; i++) { + pipe_tile_raw_to_rgba(src_format, data + src_stride * i, + width, 1, + &rgba[width*4*i], dst_stride); + } + + debug_dump_float_rgba_bmp(filename, width, height, rgba, width); + + FREE(rgba); +} + +static uint8_t* read(const char *filename, unsigned size) +{ + uint8_t *data; + FILE *file = fopen(filename, "rb"); + + data = MALLOC(size); + + fread(data, 1, size, file); + fclose(file); + + return data; +} diff --git a/progs/rbug/ctx_info.c b/progs/rbug/ctx_info.c new file mode 100644 index 00000000000..d72c3267196 --- /dev/null +++ b/progs/rbug/ctx_info.c @@ -0,0 +1,80 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + struct rbug_proto_context_info_reply *info; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { +#if 0 + rbug_send_contexts_info(con, list->contexts[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_INFO_REPLY); + info = (struct rbug_proto_context_info_reply *)header; +#else + (void)info; + header = NULL; +#endif + + debug_printf("%llu\n", + (unsigned long long)list->contexts[i]); + rbug_free_header(header); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/shdr_disable.c b/progs/rbug/shdr_disable.c new file mode 100644 index 00000000000..e6b12073d86 --- /dev/null +++ b/progs/rbug/shdr_disable.c @@ -0,0 +1,82 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk(rbug_context_t ctx, rbug_shader_t shdr) +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + rbug_send_shader_disable(con, ctx, shdr, true, NULL); + + rbug_send_ping(con, NULL); + + debug_printf("Sent waiting for reply\n"); + header = rbug_get_message(con, NULL); + + if (header->opcode != RBUG_OP_PING_REPLY) + debug_printf("Error\n"); + else + debug_printf("Ok!\n"); + + rbug_free_header(header); + rbug_disconnect(con); +} + +static void print_usage() +{ + printf("Usage shdr_disable <context> <shader>\n"); + exit(-1); +} + +int main(int argc, char** argv) +{ + long ctx; + long shdr; + + if (argc < 3) + print_usage(); + + ctx = atol(argv[1]); + shdr = atol(argv[2]); + + if (ctx <= 0 && ctx <= 0) + print_usage(); + + talk((uint64_t)ctx, (uint64_t)shdr); + + return 0; +} diff --git a/progs/rbug/shdr_dump.c b/progs/rbug/shdr_dump.c new file mode 100644 index 00000000000..8f9d758d513 --- /dev/null +++ b/progs/rbug/shdr_dump.c @@ -0,0 +1,115 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +#include "tgsi/tgsi_dump.h" + +static void shader_info(struct rbug_connection *con, rbug_context_t ctx) +{ + struct rbug_header *header; + struct rbug_proto_shader_list_reply *list; + struct rbug_proto_shader_info_reply *info; + int i; + + debug_printf("Sending get shaders to %llu\n", (unsigned long long)ctx); + rbug_send_shader_list(con, ctx, NULL); + + debug_printf("Waiting for shaders from %llu\n", (unsigned long long)ctx); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_LIST_REPLY); + list = (struct rbug_proto_shader_list_reply *)header; + + debug_printf("Got shaders:\n"); + for (i = 0; i < list->shaders_len; i++) { + rbug_send_shader_info(con, ctx, list->shaders[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_INFO_REPLY); + info = (struct rbug_proto_shader_info_reply *)header; + + debug_printf("#####################################################\n"); + debug_printf("ctx: %llu shdr: %llu disabled %u\n", + (unsigned long long)ctx, + (unsigned long long)list->shaders[i], + info->disabled); + + /* just to be sure */ + assert(sizeof(struct tgsi_token) == 4); + + debug_printf("-----------------------------------------------------\n"); + tgsi_dump((struct tgsi_token *)info->original, 0); + + if (info->replaced_len > 0) { + debug_printf("-----------------------------------------------------\n"); + tgsi_dump((struct tgsi_token *)info->replaced, 0); + } + + rbug_free_header(header); + } + + debug_printf("#####################################################\n"); + rbug_free_header(&list->header); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { + shader_info(con, list->contexts[i]); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/shdr_info.c b/progs/rbug/shdr_info.c new file mode 100644 index 00000000000..b6864e988e5 --- /dev/null +++ b/progs/rbug/shdr_info.c @@ -0,0 +1,98 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void shader_info(struct rbug_connection *con, rbug_context_t ctx) +{ + struct rbug_header *header; + struct rbug_proto_shader_list_reply *list; + struct rbug_proto_shader_info_reply *info; + int i; + + rbug_send_shader_list(con, ctx, NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_LIST_REPLY); + list = (struct rbug_proto_shader_list_reply *)header; + + debug_printf(" context | shader | disabled |\n"); + for (i = 0; i < list->shaders_len; i++) { + rbug_send_shader_info(con, ctx, list->shaders[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_INFO_REPLY); + info = (struct rbug_proto_shader_info_reply *)header; + + debug_printf("% 15llu |% 15llu |% 15u |\n", + (unsigned long long)ctx, + (unsigned long long)list->shaders[i], + (unsigned)info->disabled); + + rbug_free_header(header); + } + + rbug_free_header(&list->header); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { + shader_info(con, list->contexts[i]); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/simple_client.c b/progs/rbug/simple_client.c new file mode 100644 index 00000000000..38929fa796e --- /dev/null +++ b/progs/rbug/simple_client.c @@ -0,0 +1,64 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_texture_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) + debug_printf("\ttex %llu\n", (unsigned long long)list->textures[i]); + + rbug_free_header(header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/simple_server.c b/progs/rbug/simple_server.c new file mode 100644 index 00000000000..04380c33109 --- /dev/null +++ b/progs/rbug/simple_server.c @@ -0,0 +1,62 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void wait() +{ + int s = u_socket_listen_on_port(13370); + int c = u_socket_accept(s); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + rbug_texture_t texs[2]; + uint32_t serial; + texs[0] = 1337; + texs[1] = 7331; + + assert(s >= 0); + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Waiting for get textures\n"); + header = rbug_get_message(con, &serial); + assert(header); + assert(header->opcode == RBUG_OP_TEXTURE_LIST); + rbug_free_header(header); + + rbug_send_texture_list_reply(con, serial, texs, 2, NULL); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + wait(); + return 0; +} diff --git a/progs/rbug/tex_dump.c b/progs/rbug/tex_dump.c new file mode 100644 index 00000000000..f9e06ee994a --- /dev/null +++ b/progs/rbug/tex_dump.c @@ -0,0 +1,127 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" +#include "util/u_tile.h" +#include "rbug/rbug.h" + +static void dump(rbug_texture_t tex, + struct rbug_proto_texture_info_reply *info, + struct rbug_proto_texture_read_reply *read, + int mip) +{ + enum pipe_format format = info->format; + uint8_t *data = read->data; + unsigned width = info->width[mip]; + unsigned height = info->height[mip]; + unsigned dst_stride = width * 4 * 4; + unsigned src_stride = read->stride; + float *rgba = MALLOC(dst_stride * height); + int i; + char filename[512]; + + util_snprintf(filename, 512, "%llu_%s_%u.bmp", + (unsigned long long)tex, pf_name(info->format), mip); + + if (pf_is_compressed(info->format)) { + debug_printf("skipping: %s\n", filename); + return; + } + + debug_printf("saving: %s\n", filename); + + for (i = 0; i < height; i++) { + pipe_tile_raw_to_rgba(format, data + src_stride * i, + width, 1, + &rgba[width*4*i], dst_stride); + } + + debug_dump_float_rgba_bmp(filename, width, height, rgba, width); + + FREE(rgba); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_header *header2; + struct rbug_proto_texture_list_reply *list; + struct rbug_proto_texture_info_reply *info; + struct rbug_proto_texture_read_reply *read; + int i, j; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) { + rbug_send_texture_info(con, list->textures[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY); + info = (struct rbug_proto_texture_info_reply *)header; + + for (j = 0; j <= info->last_level; j++) { + rbug_send_texture_read(con, list->textures[i], + 0, j, 0, + 0, 0, info->width[j], info->height[j], + NULL); + + header2 = rbug_get_message(con, NULL); + assert(header2->opcode == RBUG_OP_TEXTURE_READ_REPLY); + read = (struct rbug_proto_texture_read_reply *)header2; + + dump(list->textures[i], info, read, j); + + rbug_free_header(header2); + } + + rbug_free_header(header); + + } + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/tex_info.c b/progs/rbug/tex_info.c new file mode 100644 index 00000000000..4a21bae3596 --- /dev/null +++ b/progs/rbug/tex_info.c @@ -0,0 +1,78 @@ +/* + * Copyright 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_texture_list_reply *list; + struct rbug_proto_texture_info_reply *info; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) { + rbug_send_texture_info(con, list->textures[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY); + info = (struct rbug_proto_texture_info_reply *)header; + + debug_printf("%llu %s %u x %u x %u, block(%ux%u %u), last_level: %u, nr_samples: %u, usage: %u\n", + (unsigned long long)list->textures[i], pf_name(info->format), + info->width[0], info->height[0], info->depth[0], + info->blockw, info->blockh, info->blocksize, + info->last_level, info->nr_samples, info->tex_usage); + rbug_free_header(header); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/redbook/polyoff.c b/progs/redbook/polyoff.c index 2017b4d8eed..de34b2e7675 100644 --- a/progs/redbook/polyoff.c +++ b/progs/redbook/polyoff.c @@ -153,6 +153,7 @@ static void Benchmark( float xdiff, float ydiff ) double seconds, fps; printf("Benchmarking...\n"); + fflush(stdout); draws = 0; startTime = glutGet(GLUT_ELAPSED_TIME); @@ -169,6 +170,7 @@ static void Benchmark( float xdiff, float ydiff ) seconds = (double) (endTime - startTime) / 1000.0; fps = draws / seconds; printf("Result: fps: %g\n", fps); + fflush(stdout); } @@ -263,6 +265,7 @@ void keyboard (unsigned char key, int x, int y) default: break; } + fflush(stdout); } static void diff --git a/progs/samples/blendeq.c b/progs/samples/blendeq.c index cd0474c5cea..037d06fa528 100644 --- a/progs/samples/blendeq.c +++ b/progs/samples/blendeq.c @@ -100,7 +100,7 @@ static void PrintColorStrings( void ) { GLubyte ubbuf[3]; int i, xleft, xright; - char colorString[18]; + char colorString[100]; xleft = 5 + windW/4; xright = 5 + windW/2; diff --git a/progs/samples/prim.c b/progs/samples/prim.c index f47c60faefd..c04750725fb 100644 --- a/progs/samples/prim.c +++ b/progs/samples/prim.c @@ -466,25 +466,22 @@ static void Draw(void) } else { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } -#if 01 + Viewport(0, 0); Point(); Viewport(0, 1); Lines(); Viewport(0, 2); LineStrip(); Viewport(0, 3); LineLoop(); Viewport(1, 0); Bitmap(); - Viewport(1, 1); TriangleFan(); Viewport(1, 2); Triangles(); Viewport(1, 3); TriangleStrip(); Viewport(2, 0); Rect(); -#endif Viewport(2, 1); PolygonFunc(); -#if 01 Viewport(2, 2); Quads(); Viewport(2, 3); QuadStrip(); -#endif + glFlush(); if (doubleBuffer) { diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index e6369de3ab2..d6a85387676 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -16,22 +16,20 @@ blendminmax blendsquare blendxor bufferobj -bumpmap bug_3050 bug_3101 bug_3195 bug_texstore_i8 +bumpmap calibrate_rast copypixrate crossbar cva -dinoshade drawbuffers extfuncs.h exactrast fbotest1 fbotest2 -fbotexture fillrate floattex fog @@ -40,6 +38,7 @@ fptest1 fptexture getprocaddress getproclist.h +glutfx interleave invert jkrahntest @@ -49,6 +48,7 @@ mapbufrange mapvbo minmag mipgen +mipmap_comp mipmap_limits mipmap_view multipal @@ -56,30 +56,31 @@ no_s3tc packedpixels pbo prog_parameter -projtex quads random readrate readtex.c readtex.h rubberband +scissor +scissor-viewport seccolor -sharedtex shader_api shaderutil.c shaderutil.h +sharedtex stencil_twoside -stencil_wrap stencilwrap stencil_wrap +streaming_rect subtex subtexrate tex1d -texcmp texcompress2 +texdown texfilt -texgenmix texline +texobj texobjshare texrect texwrap diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 58ea5690df6..5069817be3e 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -37,19 +37,19 @@ SOURCES = \ copypixrate.c \ crossbar.c \ cva.c \ - dinoshade.c \ drawbuffers.c \ exactrast.c \ floattex.c \ fbotest1.c \ fbotest2.c \ - fbotexture.c \ fillrate.c \ fog.c \ fogcoord.c \ fptest1.c \ fptexture.c \ getprocaddress.c \ + getteximage.c \ + glutfx.c \ interleave.c \ invert.c \ jkrahntest.c \ @@ -59,6 +59,7 @@ SOURCES = \ mapvbo.c \ minmag.c \ mipgen.c \ + mipmap_comp.c \ mipmap_limits.c \ mipmap_view.c \ multipal.c \ @@ -66,23 +67,27 @@ SOURCES = \ packedpixels.c \ pbo.c \ prog_parameter.c \ - projtex.c \ quads.c \ random.c \ readrate.c \ rubberband.c \ + scissor.c \ + scissor-viewport.c \ seccolor.c \ shader_api.c \ sharedtex.c \ stencil_twoside.c \ stencilwrap.c \ stencil_wrap.c \ + streaming_rect \ subtex \ subtexrate.c \ tex1d.c \ texcompress2.c \ + texdown \ texfilt.c \ texline.c \ + texobj.c \ texobjshare.c \ texrect.c \ texwrap.c \ @@ -201,10 +206,10 @@ fillrate.o: fillrate.c readtex.h floattex: floattex.o readtex.o shaderutil.o - $(CC) $(CFLAGS) $(LDFLAGS) floattex.o readtex.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) $(CFLAGS) $(LDFLAGS) floattex.o readtex.o shaderutil.o $(LIBS) -o $@ floattex.o: floattex.c readtex.h shaderutil.h - $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) floattex.c -o $@ + $(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) floattex.c -o $@ readtex.o: readtex.c @@ -230,7 +235,7 @@ 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) $(INCLUDES) $(CFLAGS) shaderutil.c diff --git a/progs/tests/SConscript b/progs/tests/SConscript index bf1e7f8a7d8..9d89ff6a0d0 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -42,8 +42,8 @@ progs = [ 'arbfptest1', 'arbfptexture', 'arbfptrig', - 'arbnpot-mipmap', 'arbnpot', + 'arbnpot-mipmap', 'arbvptest1', 'arbvptest3', 'arbvptorus', @@ -61,19 +61,18 @@ progs = [ 'copypixrate', 'crossbar', 'cva', - 'dinoshade', 'drawbuffers', 'exactrast', 'ext422square', 'fbotest1', 'fbotest2', - 'fbotexture', 'fillrate', 'floattex', 'fog', 'fogcoord', 'fptest1', 'fptexture', + 'glutfx', 'interleave', 'invert', 'lineclip', @@ -82,6 +81,7 @@ progs = [ 'mapvbo', 'minmag', 'mipgen', + 'mipmap_comp', 'mipmap_limits', 'mipmap_view', 'multipal', @@ -91,24 +91,28 @@ progs = [ 'packedpixels', 'pbo', 'prog_parameter', - 'projtex', 'quads', 'random', 'readrate', 'rubberband', + 'scissor', + 'scissor-viewport', 'seccolor', 'shader_api', 'stencil_twoside', 'stencil_wrap', 'stencilwrap', + 'streaming_rect', 'subtex', 'subtexrate', 'tex1d', 'texcmp', 'texcompress2', + 'texdown', 'texfilt', 'texgenmix', 'texline', + 'texobj', 'texrect', 'texwrap', 'unfilledclip', diff --git a/progs/tests/afsmultiarb.c b/progs/tests/afsmultiarb.c index 162ab19493c..ca25a4d75bf 100644 --- a/progs/tests/afsmultiarb.c +++ b/progs/tests/afsmultiarb.c @@ -442,8 +442,8 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 300, 300 ); glutInitWindowPosition( 0, 0 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); - glewInit(); glutCreateWindow(argv[0] ); + glewInit(); Init( argc, argv ); diff --git a/progs/tests/floattex.c b/progs/tests/floattex.c index dd99d836c64..ad14cacdcbb 100644 --- a/progs/tests/floattex.c +++ b/progs/tests/floattex.c @@ -1,6 +1,5 @@ /* * Test floating point textures. - * No actual rendering, yet. */ @@ -103,7 +102,6 @@ Key(unsigned char key, int x, int y) } - static void InitTexture(void) { @@ -141,6 +139,8 @@ InitTexture(void) GL_RGB, GL_FLOAT, ftex); + CheckError(__LINE__); + /* sanity checks */ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_TYPE_ARB, &t); assert(t == GL_FLOAT); @@ -152,32 +152,26 @@ InitTexture(void) assert(t == GL_FLOAT); free(image); - free(ftex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); -#if 0 - /* read back the texture and make sure values are correct */ - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, tex2); - CheckError(__LINE__); - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { - if (tex[i][j][0] != tex2[i][j][0] || - tex[i][j][1] != tex2[i][j][1] || - tex[i][j][2] != tex2[i][j][2] || - tex[i][j][3] != tex2[i][j][3]) { - printf("tex[%d][%d] %g %g %g %g != tex2[%d][%d] %g %g %g %g\n", - i, j, - tex[i][j][0], tex[i][j][1], tex[i][j][2], tex[i][j][3], - i, j, - tex2[i][j][0], tex2[i][j][1], tex2[i][j][2], tex2[i][j][3]); + if (1) { + /* read back the texture and make sure values are correct */ + GLfloat *tex2 = (GLfloat *) + malloc(imgWidth * imgHeight * 4 * sizeof(GLfloat)); + glGetTexImage(GL_TEXTURE_2D, 0, imgFormat, GL_FLOAT, tex2); + CheckError(__LINE__); + for (i = 0; i < imgWidth * imgHeight * 4; i++) { + if (ftex[i] != tex2[i]) { + printf("tex[%d] %g != tex2[%d] %g\n", + i, ftex[i], i, tex2[i]); } } } -#endif + + free(ftex); } @@ -193,7 +187,9 @@ CreateProgram(void) assert(program); - // InitUniforms(program, Uniforms); + glUseProgram_func(program); + + InitUniforms(program, Uniforms); return program; } @@ -211,8 +207,9 @@ Init(void) exit(1); } - if (!glutExtensionSupported("GL_MESAX_texture_float")) { - printf("Sorry, this test requires GL_MESAX_texture_float\n"); + if (!glutExtensionSupported("GL_MESAX_texture_float") && + !glutExtensionSupported("GL_ARB_texture_float")) { + printf("Sorry, this test requires GL_MESAX/ARB_texture_float\n"); exit(1); } diff --git a/progs/tests/getteximage.c b/progs/tests/getteximage.c new file mode 100644 index 00000000000..e4818a8fabb --- /dev/null +++ b/progs/tests/getteximage.c @@ -0,0 +1,217 @@ +/** + * Test glGetTexImage() + * Brian Paul + * 9 June 2009 + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + +static int Win; + + +static void +TestGetTexImage(void) +{ + GLuint iter; + GLubyte *data = (GLubyte *) malloc(1024 * 1024 * 4); + GLubyte *data2 = (GLubyte *) malloc(1024 * 1024 * 4); + + glEnable(GL_TEXTURE_2D); + + printf("glTexImage2D + glGetTexImage:\n"); + + for (iter = 0; iter < 8; iter++) { + GLint p = (iter % 8) + 3; + GLint w = (1 << p); + GLint h = (1 << p); + GLuint i; + GLint level = 0; + + printf(" Testing %d x %d tex image\n", w, h); + + /* fill data */ + for (i = 0; i < w * h * 4; i++) { + data[i] = i & 0xff; + data2[i] = 0; + } + + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, data); + + glBegin(GL_POINTS); + glVertex2f(0, 0); + glEnd(); + + /* get */ + glGetTexImage(GL_TEXTURE_2D, level, GL_RGBA, GL_UNSIGNED_BYTE, data2); + + /* compare */ + for (i = 0; i < w * h * 4; i++) { + if (data2[i] != data[i]) { + printf("glTexImage + glGetTexImage failure!\n"); + printf("Expected value %d, found %d\n", data[i], data2[i]); + abort(); + } + } + } + + printf("Passed\n"); + glDisable(GL_TEXTURE_2D); + free(data); + free(data2); +} + + +static GLboolean +ColorsEqual(const GLubyte ref[4], const GLubyte act[4]) +{ + if (abs((int) ref[0] - (int) act[0]) > 1 || + abs((int) ref[1] - (int) act[1]) > 1 || + abs((int) ref[2] - (int) act[2]) > 1 || + abs((int) ref[3] - (int) act[3]) > 1) { + printf("expected %d %d %d %d\n", ref[0], ref[1], ref[2], ref[3]); + printf("found %d %d %d %d\n", act[0], act[1], act[2], act[3]); + return GL_FALSE; + } + return GL_TRUE; +} + + +static void +TestGetTexImageRTT(void) +{ + GLuint iter; + GLuint fb, tex; + GLint w = 512; + GLint h = 256; + GLint level = 0; + + glGenTextures(1, &tex); + glGenFramebuffersEXT(1, &fb); + + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, tex, level); + + printf("Render to texture + glGetTexImage:\n"); + printf(" Testing %d x %d tex image\n", w, h); + for (iter = 0; iter < 8; iter++) { + GLubyte color[4]; + GLubyte *data2 = (GLubyte *) malloc(w * h * 4); + GLuint i; + + /* random clear color */ + for (i = 0; i < 4; i++) { + color[i] = rand() % 256; + } + + glClearColor(color[0] / 255.0, + color[1] / 255.0, + color[2] / 255.0, + color[3] / 255.0); + + glClear(GL_COLOR_BUFFER_BIT); + + /* get */ + glGetTexImage(GL_TEXTURE_2D, level, GL_RGBA, GL_UNSIGNED_BYTE, data2); + + /* compare */ + for (i = 0; i < w * h; i += 4) { + if (!ColorsEqual(color, data2 + i * 4)) { + printf("Render to texture failure!\n"); + abort(); + } + } + + free(data2); + } + + glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + glDeleteFramebuffersEXT(1, &fb); + glDeleteTextures(1, &tex); + + printf("Passed\n"); +} + + + + +static void +Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + TestGetTexImage(); + + if (glutExtensionSupported("GL_EXT_framebuffer_object") || + glutExtensionSupported("GL_ARB_framebuffer_object")) + TestGetTexImageRTT(); + + glutDestroyWindow(Win); + exit(0); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + 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); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glutDestroyWindow(Win); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +Init(void) +{ +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 400); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/glutfx.c b/progs/tests/glutfx.c index 8bf55823897..8bf55823897 100644 --- a/progs/demos/glutfx.c +++ b/progs/tests/glutfx.c diff --git a/progs/tests/jkrahntest.c b/progs/tests/jkrahntest.c index 08660b8932e..3fef105fc2c 100644 --- a/progs/tests/jkrahntest.c +++ b/progs/tests/jkrahntest.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) if (argc < 2) { fprintf(stderr, "This program tests GLX context switching.\n"); - fprintf(stderr, "Usage: cxbug <n>\n"); + fprintf(stderr, "Usage: jkrahntest <n>\n"); fprintf(stderr, "Where n is:\n"); fprintf(stderr, "\t1) Use two contexts and swap only when the context is current (typical case).\n"); fprintf(stderr, "\t2) Use two contexts and swap at the same time.\n"); diff --git a/progs/tests/mipmap_comp.c b/progs/tests/mipmap_comp.c new file mode 100644 index 00000000000..5842e2b8805 --- /dev/null +++ b/progs/tests/mipmap_comp.c @@ -0,0 +1,295 @@ +/* Copyright (c) Mark J. Kilgard, 1994. */ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ + +/* mipmap_comp + * Test compressed texture mipmaps + * + * Based on mipmap_limits + */ + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <GL/glew.h> +#include <GL/glut.h> + +#include "readtex.h" + +#define SIZE 16 /* not larger then 16 */ + +static GLint BaseLevel = 0, MaxLevel = 9; +static GLfloat MinLod = -1, MaxLod = 9; +static GLfloat LodBias = 0.0; +static GLboolean NearestFilter = GL_TRUE; +static GLuint texImage; + + +static void +initValues(void) +{ + BaseLevel = 0; + MaxLevel = 9; + MinLod = -1; + MaxLod = 2; + LodBias = 5.0; + NearestFilter = GL_TRUE; +} + + +static void +makeImage(int level, int width, int height) +{ +#if 0 + GLubyte img[SIZE*SIZE*3]; + int i, j; + + (void)size; + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + int k = (i * width + j) * 3; + img[k + 0] = 255 * ((level + 1) % 2); + img[k + 1] = 255 * ((level + 1) % 2); + img[k + 2] = 255 * ((level + 1) % 2); + } + } + + glTexImage2D(GL_TEXTURE_2D, level, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, width, height, 0, + GL_RGB, GL_UNSIGNED_BYTE, img); +#else + GLubyte img[128]; + GLint size[] = { + 128, /* 16x16 */ + 32, /* 8x8 */ + 8, /* 4x4 */ + 8, /* 2x2 */ + 8, /* 1x1 */ + }; + int i; + int value = ((level + 1) % 2) * 0xffffffff; + memset(img, 0, 128); + + /* generate black and white mipmap levels */ + if (value) + for (i = 0; i < size[level] / 4; i += 2) + ((int*)img)[i] = value; + + glCompressedTexImage2D(GL_TEXTURE_2D, level, + GL_COMPRESSED_RGB_S3TC_DXT1_EXT, + width, height, 0, + size[level], img); +#endif +} + + +static void +makeImages(void) +{ + int i, sz; + + for (i = 0, sz = SIZE; sz >= 1; i++, sz /= 2) { + makeImage(i, sz, sz); + printf("Level %d size: %d x %d\n", i, sz, sz); + } +} + + +static void +myInit(void) +{ + + initValues(); + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glShadeModel(GL_FLAT); + + glTranslatef(0.0, 0.0, -3.6); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glGenTextures(1, &texImage); + glBindTexture(GL_TEXTURE_2D, texImage); + makeImages(); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glEnable(GL_TEXTURE_2D); +} + + +static void +display(void) +{ + GLfloat tcm = 1.0; + glBindTexture(GL_TEXTURE_2D, texImage); + + printf("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n", + BaseLevel, MaxLevel, MinLod, MaxLod, LodBias, + NearestFilter ? "NEAREST" : "LINEAR"); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, MinLod); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, MaxLod); + + if (NearestFilter) { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST_MIPMAP_NEAREST); + } + else { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + } + + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(tcm * 3000.0, tcm); glVertex3f(3000.0, 1.0, -6000.0); + glTexCoord2f(tcm * 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0); + glEnd(); + glFlush(); +} + + +static void +myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +key(unsigned char k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case 'b': + BaseLevel--; + if (BaseLevel < 0) + BaseLevel = 0; + break; + case 'B': + BaseLevel++; + if (BaseLevel > 10) + BaseLevel = 10; + break; + case 'm': + MaxLevel--; + if (MaxLevel < 0) + MaxLevel = 0; + break; + case 'M': + MaxLevel++; + if (MaxLevel > 10) + MaxLevel = 10; + break; + case 'l': + LodBias -= 0.25; + break; + case 'L': + LodBias += 0.25; + break; + case 'n': + MinLod -= 0.25; + break; + case 'N': + MinLod += 0.25; + break; + case 'x': + MaxLod -= 0.25; + break; + case 'X': + MaxLod += 0.25; + break; + case 'f': + NearestFilter = !NearestFilter; + break; + case ' ': + initValues(); + break; + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + + +static void +usage(void) +{ + printf("usage:\n"); + printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n"); + printf(" m/M decrease/increase GL_TEXTURE_MAX_LEVEL\n"); + printf(" n/N decrease/increase GL_TEXTURE_MIN_LOD\n"); + printf(" x/X decrease/increase GL_TEXTURE_MAX_LOD\n"); + printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n"); + printf(" f toggle nearest/linear filtering\n"); + printf(" SPACE reset values\n"); +} + + +int +main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (600, 600); + glutCreateWindow (argv[0]); + glewInit(); + myInit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutKeyboardFunc(key); + usage(); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/tests/mipmap_view.c b/progs/tests/mipmap_view.c index 16f3584f703..808d348699c 100644 --- a/progs/tests/mipmap_view.c +++ b/progs/tests/mipmap_view.c @@ -18,11 +18,27 @@ #define TEXTURE_FILE "../images/arch.rgb" -static int TexWidth = 256, TexHeight = 256; +#define LEVELS 8 +#define SIZE (1<<LEVELS) +static int TexWidth = SIZE, TexHeight = SIZE; static int WinWidth = 1044, WinHeight = 900; static GLfloat Bias = 0.0; static GLboolean ScaleQuads = GL_FALSE; +static GLboolean Linear = GL_FALSE; static GLint Win = 0; +static GLint RenderTextureLevel = 0; +static GLuint TexObj; + + + +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("GL Error 0x%x at line %d\n", (int) err, line); + } +} @@ -36,6 +52,178 @@ PrintString(const char *s) } + + +static void +MipGenTexture( void ) +{ + /* test auto mipmap generation */ + GLint width, height, i; + GLenum format; + GLubyte *image = LoadRGBImage(TEXTURE_FILE, &width, &height, &format); + if (!image) { + printf("Error: could not load texture image %s\n", TEXTURE_FILE); + exit(1); + } + /* resize to TexWidth x TexHeight */ + if (width != TexWidth || height != TexHeight) { + GLubyte *newImage = malloc(TexWidth * TexHeight * 4); + + fprintf(stderr, "rescale %d %d to %d %d\n", width, height, + TexWidth, TexHeight); + fflush(stderr); + + gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, + TexWidth, TexHeight, GL_UNSIGNED_BYTE, newImage); + free(image); + image = newImage; + } + printf("Using GL_SGIS_generate_mipmap\n"); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, format, TexWidth, TexHeight, 0, + format, GL_UNSIGNED_BYTE, image); + free(image); + + /* make sure mipmap was really generated correctly */ + width = TexWidth; + height = TexHeight; + for (i = 0; i < 9; i++) { + GLint w, h; + glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); + glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); + printf("Level %d size: %d x %d\n", i, w, h); + assert(w == width); + assert(h == height); + width /= 2; + height /= 2; + } + + + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE); +} + + + +static void +ResetTextureLevel( int i ) +{ + GLubyte tex2d[SIZE*SIZE][4]; + + { + GLint Width = TexWidth / (1 << i); + GLint Height = TexHeight / (1 << i); + GLint s, t; + + for (s = 0; s < Width; s++) { + for (t = 0; t < Height; t++) { + tex2d[t*Width+s][0] = ((s / 16) % 2) ? 0 : 255; + tex2d[t*Width+s][1] = ((t / 16) % 2) ? 0 : 255; + tex2d[t*Width+s][2] = 128; + tex2d[t*Width+s][3] = 255; + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glTexImage2D(GL_TEXTURE_2D, i, GL_RGB, Width, Height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, tex2d); + } +} + + +static void +ResetTexture( void ) +{ +#if 0 + /* This doesn't work so well as the arch texture is 512x512. + */ + LoadRGBMipmaps(TEXTURE_FILE, GL_RGB); +#else + { + int i; + + for (i = 0; i <= LEVELS; i++) + { + ResetTextureLevel(i); + } + } +#endif +} + + + + + + + +static void +RenderTexture( void ) +{ + GLenum status; + GLuint MyFB; + + fprintf(stderr, "RenderTextureLevel %d\n", RenderTextureLevel); + fflush(stderr); + + /* gen framebuffer id, delete it, do some assertions, just for testing */ + glGenFramebuffersEXT(1, &MyFB); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + assert(glIsFramebufferEXT(MyFB)); + + CheckError(__LINE__); + + /* Render color to texture */ + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, TexObj, + RenderTextureLevel); + + + + CheckError(__LINE__); + + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -15.0); + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + printf("Framebuffer incomplete!!!\n"); + } + + glViewport(0, 0, + TexWidth / (1 << RenderTextureLevel), + TexHeight / (1 << RenderTextureLevel)); + + glClearColor(0.5, 0.5, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + CheckError(__LINE__); + + glBegin(GL_POLYGON); + glColor3f(1, 0, 0); + glVertex2f(-1, -1); + glColor3f(0, 1, 0); + glVertex2f(1, -1); + glColor3f(0, 0, 1); + glVertex2f(0, 1); + glEnd(); + + + /* Bind normal framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + CheckError(__LINE__); + + glDeleteFramebuffersEXT(1, &MyFB); + CheckError(__LINE__); + + glClearColor(0, 0, 0, 0); +} + static void Display(void) { @@ -43,6 +231,8 @@ Display(void) char str[100]; int texWidth = TexWidth, texHeight = TexHeight; + glViewport(0, 0, WinHeight, WinHeight); + glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); @@ -53,6 +243,15 @@ Display(void) glColor3f(1,1,1); + if (Linear) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + y = WinHeight - 300; x = 4; @@ -116,7 +315,6 @@ Reshape(int width, int height) { WinWidth = width; WinHeight = height; - glViewport(0, 0, width, height); } @@ -132,6 +330,24 @@ Key(unsigned char key, int x, int y) case 'B': Bias += 10; break; + case 'l': + Linear = !Linear; + break; + case 'v': + RenderTextureLevel++; + break; + case 'V': + RenderTextureLevel--; + break; + case 'r': + RenderTexture(); + break; + case 'X': + ResetTexture(); + break; + case 'x': + ResetTextureLevel(RenderTextureLevel); + break; case '0': case '1': case '2': @@ -147,6 +363,14 @@ Key(unsigned char key, int x, int y) case 's': ScaleQuads = !ScaleQuads; break; + case ' ': + MipGenTexture(); + Bias = 0; + Linear = 0; + RenderTextureLevel = 0; + ScaleQuads = 0; + break; + case 27: glutDestroyWindow(Win); exit(0); @@ -173,57 +397,15 @@ Init(void) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (1) { - /* test auto mipmap generation */ - GLint width, height, i; - GLenum format; - GLubyte *image = LoadRGBImage(TEXTURE_FILE, &width, &height, &format); - if (!image) { - printf("Error: could not load texture image %s\n", TEXTURE_FILE); - exit(1); - } - /* resize to TexWidth x TexHeight */ - if (width != TexWidth || height != TexHeight) { - GLubyte *newImage = malloc(TexWidth * TexHeight * 4); - gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, - TexWidth, TexHeight, GL_UNSIGNED_BYTE, newImage); - free(image); - image = newImage; - } - printf("Using GL_SGIS_generate_mipmap\n"); - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); - glTexImage2D(GL_TEXTURE_2D, 0, format, TexWidth, TexHeight, 0, - format, GL_UNSIGNED_BYTE, image); - free(image); - - /* make sure mipmap was really generated correctly */ - width = TexWidth; - height = TexHeight; - for (i = 0; i < 9; i++) { - GLint w, h; - glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); - glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); - printf("Level %d size: %d x %d\n", i, w, h); - assert(w == width); - assert(h == height); - width /= 2; - height /= 2; - } - } - else { - if (LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { - printf("Using gluBuildMipmaps()\n"); - } - else { - printf("Error: could not load texture image %s\n", TEXTURE_FILE); - exit(1); - } - } + glGenTextures(1, &TexObj); + glBindTexture(GL_TEXTURE_2D, TexObj); + if (1) + MipGenTexture(); + else + ResetTexture(); /* mipmapping required for this extension */ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &maxBias); diff --git a/progs/demos/occlude.c b/progs/tests/occlude.c index 8f7b90984e0..8f7b90984e0 100644 --- a/progs/demos/occlude.c +++ b/progs/tests/occlude.c diff --git a/progs/tests/scissor-viewport.c b/progs/tests/scissor-viewport.c new file mode 100644 index 00000000000..582e65fb72b --- /dev/null +++ b/progs/tests/scissor-viewport.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * Copyright (c) 2009 VMware, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + +struct program +{ + unsigned width; + unsigned height; + int i; +}; + +struct program prog; + +static void init(void) +{ + 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)); + fflush(stderr); + + prog.i = 0; +} + +static void reshape(int width, int height) +{ + glViewport(0, 0, 100, 100); + + prog.width = width; + prog.height = height; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + glutPostRedisplay(); + return; + } +} + +static void drawQuad(void) +{ + glBegin(GL_QUADS); + glVertex2d(-1.0, -1.0); + glVertex2d( 1.0, -1.0); + glVertex2d( 1.0, 1.0); + glVertex2d(-1.0, 1.0); + glEnd(); +} + +static void draw(void) +{ + int i; + + glClearColor(0.0, 0.0, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + i = prog.i++; + if (prog.i >= 3) + prog.i = 0; + + glEnable(GL_SCISSOR_TEST); + + { + glColor4d(1.0, 0.0, 0.0, 1.0); + + glScissor(i, i, 10 - 2*i, 10 - 2*i); + drawQuad(); + } + + glDisable(GL_SCISSOR_TEST); + + //glutSwapBuffers(); + glFlush(); +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + prog.width = 200; + prog.height = 200; + + glutInitWindowPosition(100, 0); + glutInitWindowSize(prog.width, prog.height); + + //type = GLUT_RGB | GLUT_DOUBLE; + type = GLUT_RGB | GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + init(); + + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutDisplayFunc(draw); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/scissor.c b/progs/tests/scissor.c new file mode 100644 index 00000000000..2dfd2174e82 --- /dev/null +++ b/progs/tests/scissor.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * Copyright (c) 2009 VMware, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + +struct program +{ + unsigned width; + unsigned height; + unsigned quads; +}; + +struct program prog; + +static void init(void) +{ + 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)); + fflush(stderr); +} + +static void reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + prog.width = width; + prog.height = height; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + prog.quads = !prog.quads; + glutPostRedisplay(); + return; + } +} + +static void drawQuad(void) +{ + + if (prog.quads) { + glBegin(GL_QUADS); + glVertex2d(-1.0, -1.0); + glVertex2d( 1.0, -1.0); + glVertex2d( 1.0, 1.0); + glVertex2d(-1.0, 1.0); + glEnd(); + } else { + glClear(GL_COLOR_BUFFER_BIT); + } +} + +static void draw(void) +{ + glClearColor(0.0, 0.0, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + printf("drawing with %s\n", prog.quads ? "quads" : "clears"); + + glEnable(GL_SCISSOR_TEST); + + { + glClearColor(1.0, 0.0, 0.0, 1.0); + glColor4d(1.0, 0.0, 0.0, 1.0); + + glScissor(1, 1, 10, 10); + drawQuad(); + glScissor(1, prog.height - 11, 10, 10); + drawQuad(); + glScissor(prog.width - 11, prog.height - 11, 10, 10); + drawQuad(); + } + + { + glClearColor(0.0, 1.0, 0.0, 1.0); + glColor4d(0.0, 1.0, 0.0, 1.0); + + glScissor(12, 1, 10, 10); + drawQuad(); + glScissor(12, prog.height - 11, 10, 10); + drawQuad(); + glScissor(prog.width - 22, prog.height - 11, 10, 10); + drawQuad(); + } + + { + glClearColor(1.0, 1.0, 0.0, 1.0); + glColor4d(1.0, 1.0, 0.0, 1.0); + + glScissor(1, 12, 10, 10); + drawQuad(); + glScissor(1, prog.height - 22, 10, 10); + drawQuad(); + glScissor(prog.width - 11, prog.height - 22, 10, 10); + drawQuad(); + } + + glDisable(GL_SCISSOR_TEST); + + //glutSwapBuffers(); + glFlush(); +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + prog.width = 200; + prog.height = 200; + + glutInitWindowPosition(100, 0); + glutInitWindowSize(prog.width, prog.height); + + //type = GLUT_RGB | GLUT_DOUBLE; + type = GLUT_RGB | GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + init(); + + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutDisplayFunc(draw); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/shader_api.c b/progs/tests/shader_api.c index a513ca6ba1f..6453856345c 100644 --- a/progs/tests/shader_api.c +++ b/progs/tests/shader_api.c @@ -321,10 +321,18 @@ static void run_test(const char *name, void (*callback)(void)) int main(int argc, char **argv) { + const char *version; + glutInit(&argc, argv); glutCreateWindow("Mesa bug demo"); glewInit(); + version = (const char *) glGetString(GL_VERSION); + if (version[0] == '1') { + printf("Sorry, this test requires OpenGL 2.x GLSL support\n"); + exit(0); + } + RUN_TEST(test_uniform_size_type); RUN_TEST(test_attrib_size_type); RUN_TEST(test_uniform_array_overflow); diff --git a/progs/demos/streaming_rect.c b/progs/tests/streaming_rect.c index f65ac4ce36c..f65ac4ce36c 100644 --- a/progs/demos/streaming_rect.c +++ b/progs/tests/streaming_rect.c diff --git a/progs/tests/texcompress2.c b/progs/tests/texcompress2.c index cbb8f1d3a22..b95aca9fb98 100644 --- a/progs/tests/texcompress2.c +++ b/progs/tests/texcompress2.c @@ -51,7 +51,6 @@ TestSubTex(void) GLboolean all = 0*GL_TRUE; GLubyte *buffer; GLint size, fmt; - int i; glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &size); @@ -83,6 +82,23 @@ TestSubTex(void) static void +TestGetTex(void) +{ + GLubyte *buffer; + + buffer = (GLubyte *) malloc(3 * ImgWidth * ImgHeight); + + glGetTexImage(GL_TEXTURE_2D, + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + buffer); + + free(buffer); +} + + +static void LoadCompressedImage(const char *file) { const GLenum filter = GL_LINEAR; @@ -146,7 +162,10 @@ LoadCompressedImage(const char *file) glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, filter); - TestSubTex(); + if (0) + TestSubTex(); + else + TestGetTex(); } diff --git a/progs/demos/texdown.c b/progs/tests/texdown.c index 7e460458325..7e460458325 100644 --- a/progs/demos/texdown.c +++ b/progs/tests/texdown.c diff --git a/progs/demos/texobj.c b/progs/tests/texobj.c index 40bce6e5695..40bce6e5695 100644 --- a/progs/demos/texobj.c +++ b/progs/tests/texobj.c diff --git a/progs/tests/vparray.c b/progs/tests/vparray.c index 9c2fad97d9d..af9b62d33e6 100644 --- a/progs/tests/vparray.c +++ b/progs/tests/vparray.c @@ -280,9 +280,9 @@ int main(int argc, char **argv) glutInitWindowPosition(0, 0); glutInitWindowSize(400, 400); if (glutCreateWindow("Isosurface") <= 0) { - glewInit(); exit(0); } + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/vptest1.c b/progs/tests/vptest1.c index 51629192923..6e32b033468 100644 --- a/progs/tests/vptest1.c +++ b/progs/tests/vptest1.c @@ -128,7 +128,7 @@ static void Init( void ) glLoadProgramNV(GL_VERTEX_PROGRAM_NV, 1, strlen(prog1), (const GLubyte *) prog1); - assert(!glIsProgramNV(1)); + assert(glIsProgramNV(1)); glLoadProgramNV(GL_VERTEX_PROGRAM_NV, 2, strlen(prog2), diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index 8dcb20a68ff..dce733a70ae 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -19,6 +19,7 @@ fs-tri line line-clip line-cull +line-flat line-smooth line-stipple-wide line-userclip @@ -130,6 +131,7 @@ tristrip-flat vbo-drawarrays vbo-drawelements vbo-drawrange +vbo-noninterleaved vp-array vp-array-int vp-clip @@ -139,6 +141,7 @@ vp-tri-cb vp-tri-cb-pos vp-tri-cb-tex vp-tri-imm +vp-tri-invariant vp-tri-swap vp-tri-tex vp-unfilled diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 69c71cbaf61..22de83fa790 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -30,6 +30,7 @@ SOURCES = \ fs-tri.c \ line-clip.c \ line-cull.c \ + line-flat.c \ line-smooth.c \ line-stipple-wide.c \ line-userclip-clip.c \ @@ -138,6 +139,7 @@ SOURCES = \ tristrip-flat.c \ tristrip.c \ vbo-drawarrays.c \ + vbo-noninterleaved.c \ vbo-drawelements.c \ vbo-drawrange.c \ vp-array.c \ @@ -145,6 +147,7 @@ SOURCES = \ vp-clip.c \ vp-line-clip.c \ vp-tri.c \ + vp-tri-invariant.c \ vp-tri-swap.c \ vp-tri-tex.c \ vp-tri-imm.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 480630e210e..9a1f3575bdc 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -26,6 +26,7 @@ progs = [ 'fs-tri', 'line-clip', 'line-cull', + 'line-flat', 'line-smooth', 'line-stipple-wide', 'line-userclip-clip', @@ -134,6 +135,7 @@ progs = [ 'tristrip-flat', 'tristrip', 'vbo-drawarrays', + 'vbo-noninterleaved', 'vbo-drawelements', 'vbo-drawrange', 'vp-array', @@ -141,6 +143,7 @@ progs = [ 'vp-clip', 'vp-line-clip', 'vp-tri', + 'vp-tri-invariant', 'vp-tri-swap', 'vp-tri-tex', 'vp-tri-imm', diff --git a/progs/trivial/line-flat.c b/progs/trivial/line-flat.c new file mode 100644 index 00000000000..14f0ac07825 --- /dev/null +++ b/progs/trivial/line-flat.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + 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)); + fflush(stderr); + + glClearColor(0.0, 0.0, 1.0, 0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glShadeModel(GL_FLAT); + + glBegin(GL_LINES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + + + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 8e5f155c7dd..3e52449b470 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -29,6 +29,20 @@ GLenum doubleBuffer = 1; int win; +static float tx = 0; +static float ty = 0; +static float tw = 0; +static float th = 0; +static float z = -5; + + +static float win_width = 250; +static float win_height = 250; +static enum { + ORTHO, + FRUSTUM, + MODE_MAX +} mode = ORTHO; static void Init(void) { @@ -37,44 +51,195 @@ static void Init(void) fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); fflush(stderr); - glClearColor(0.3, 0.1, 0.3, 0.0); + glClearColor(0, 0, 0, 0.0); } static void Reshape(int width, int height) { - glViewport(width / -2.0, height / -2.0, width, height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + win_width = width; + win_height = height; + glutPostRedisplay(); } + static void Key(unsigned char key, int x, int y) { switch (key) { - case 27: - exit(0); - default: - glutPostRedisplay(); - return; + case 27: + exit(0); + case 'w': + tw += 1.0; + break; + case 'W': + tw -= 1.0; + break; + case 'h': + th += 1.0; + break; + case 'H': + th -= 1.0; + break; + + case 'z': + z += 1.0; + break; + case 'Z': + z -= 1.0; + break; + case 'm': + mode++; + mode %= MODE_MAX; + break; + case ' ': + tw = th = tx = ty = 0; + z = -5; + mode = ORTHO; + break; + default: + break; } + glutPostRedisplay(); } + static void Draw(void) { + int i; + float w = tw + win_width; + float h = th + win_height; + + fprintf(stderr, "glViewport(%f %f %f %f)\n", tx, ty, w, h); + fprintf(stderr, "mode: %s\n", mode == FRUSTUM ? "FRUSTUM" : "ORTHO"); + fprintf(stderr, "z: %f\n", z); + fflush(stderr); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + switch (mode) { + case FRUSTUM: + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + break; + case ORTHO: + default: + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + break; + } + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glClear(GL_COLOR_BUFFER_BIT); + + /*********************************************************************** + * Should be clipped to be no larger than the triangles: + */ + glViewport(tx, ty, w, h); + + glBegin(GL_POLYGON); + glColor3f(1,1,0); + glVertex3f(-100, -100, z); + glVertex3f(-100, 100, z); + glVertex3f(100, 100, z); + glVertex3f(100, -100, z); + glEnd(); + + glBegin(GL_POLYGON); + glColor3f(0,1,1); + glVertex3f(-10, -10, z); + glVertex3f(-10, 10, z); + glVertex3f(10, 10, z); + glVertex3f(10, -10, z); + glEnd(); + + glBegin(GL_POLYGON); + glColor3f(1,0,0); + glVertex3f(-2, -2, z); + glVertex3f(-2, 2, z); + glVertex3f(2, 2, z); + glVertex3f(2, -2, z); + glEnd(); + + + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-1, -1, z); + glVertex3f(-1, 1, z); + glVertex3f(1, 1, z); + glVertex3f(1, -1, z); + glEnd(); + + /*********************************************************************** + */ + glViewport(0, 0, win_width, win_height); + glBegin(GL_LINES); + glColor3f(1,1,0); + glVertex3f(-1, 0, z); + glVertex3f(1, 0, z); + + glVertex3f(0, -1, z); + glVertex3f(0, 1, z); + glEnd(); + + + /*********************************************************************** + */ + glViewport(tx, ty, w, h); glBegin(GL_TRIANGLES); - glColor3f(.8,0,0); - glVertex3f(-0.9, 0.9, -30.0); - glColor3f(0,.9,0); - glVertex3f( 0.9, 0.9, -30.0); - glColor3f(0,0,.7); - glVertex3f( 0.0, -0.9, -30.0); + glColor3f(1,0,0); + glVertex3f(-1, -1, z); + glVertex3f(0, -1, z); + glVertex3f(-.5, -.5, z); + + glColor3f(1,1,1); + glVertex3f(0, -1, z); + glVertex3f(1, -1, z); + glVertex3f(.5, -.5, z); + + glVertex3f(-.5, -.5, z); + glVertex3f(.5, -.5, z); + glVertex3f(0, 0, z); + + + glColor3f(0,1,0); + glVertex3f(1, 1, z); + glVertex3f(0, 1, z); + glVertex3f(.5, .5, z); + + glColor3f(1,1,1); + glVertex3f(0, 1, z); + glVertex3f(-1, 1, z); + glVertex3f(-.5, .5, z); + + glVertex3f(.5, .5, z); + glVertex3f(-.5, .5, z); + glVertex3f( 0, 0, z); + glEnd(); + + glViewport(0, 0, win_width, win_height); + + glBegin(GL_LINES); + glColor3f(.5,.5,0); + for (i = -10; i < 10; i++) { + float f = i / 10.0; + + if (i == 0) + continue; + + glVertex3f(-1, f, z); + glVertex3f(1, f, z); + + glVertex3f(f, -1, z); + glVertex3f(f, 1, z); + } + glEnd(); + + + glFlush(); if (doubleBuffer) { @@ -86,6 +251,13 @@ static GLenum Args(int argc, char **argv) { GLint i; + if (getenv("VPX")) + tx = atof(getenv("VPX")); + + if (getenv("VPY")) + ty = atof(getenv("VPY")); + + for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-sb") == 0) { doubleBuffer = GL_FALSE; @@ -99,6 +271,30 @@ static GLenum Args(int argc, char **argv) return GL_TRUE; } + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_UP: + ty += 1.0; + break; + case GLUT_KEY_DOWN: + ty -= 1.0; + break; + case GLUT_KEY_LEFT: + tx -= 1.0; + break; + case GLUT_KEY_RIGHT: + tx += 1.0; + break; + default: + break; + } + glutPostRedisplay(); +} + + int main(int argc, char **argv) { GLenum type; @@ -123,7 +319,8 @@ int main(int argc, char **argv) Init(); glutReshapeFunc(Reshape); - glutKeyboardFunc(Key); + glutKeyboardFunc(Key); + glutSpecialFunc(special); glutDisplayFunc(Draw); glutMainLoop(); return 0; diff --git a/progs/trivial/tri-z.c b/progs/trivial/tri-z.c index 335d2b90e2b..014aaa071a5 100644 --- a/progs/trivial/tri-z.c +++ b/progs/trivial/tri-z.c @@ -57,13 +57,19 @@ static struct { GLenum func; const char *str; } funcs[] = static int curFunc = 0; static double clearVal = 1.0; - +static float minZ = 0.0; +static float maxZ = 1.0; static void usage(void) { - printf("t - toggle rendering order of triangles\n"); - printf("c - toggle Z clear value between 0, 1\n"); - printf("f - cycle through depth test functions\n"); + printf("t - toggle rendering order of triangles\n"); + printf("c - toggle Z clear value between 0, 1\n"); + printf("f - cycle through depth test functions\n"); + printf("n/N - decrease/increase depthrange minZ\n"); + printf("x/X - decrease/increase depthrange maxZ\n"); + printf("spc - reset\n"); + printf("z - set to reverse-direction (ztrick) mode\n"); + fflush(stdout); } @@ -97,9 +103,11 @@ static void drawRightTriangle(void) void display(void) { - printf("GL_CLEAR_DEPTH = %f GL_DEPTH_FUNC = %s\n", - clearVal, funcs[curFunc].str); + printf("GL_CLEAR_DEPTH = %.2f, GL_DEPTH_FUNC = %s, DepthRange(%.1f, %.1f)\n", + clearVal, funcs[curFunc].str, minZ, maxZ); + fflush(stdout); glClearDepth(clearVal); + glDepthRange(minZ, maxZ); glDepthFunc(funcs[curFunc].func); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -131,27 +139,49 @@ void reshape(int w, int h) void keyboard(unsigned char key, int x, int y) { switch (key) { + case 'n': + minZ -= .1; + break; + case 'N': + minZ += .1; + break; + case 'x': + maxZ -= .1; + break; + case 'X': + maxZ += .1; + break; case 'c': case 'C': clearVal = 1.0 - clearVal; - glutPostRedisplay(); break; case 'f': case 'F': curFunc = (curFunc + 1) % NUM_FUNCS; - glutPostRedisplay(); break; case 't': case 'T': leftFirst = !leftFirst; - glutPostRedisplay(); + break; + case ' ': + curFunc = 0; + clearVal = 1.0; + minZ = 0.0; + maxZ = 1.0; + break; + case 'z': + curFunc = 2; + clearVal = 0.0; + minZ = 1.0; + maxZ = 0.0; break; case 27: /* Escape key */ exit(0); break; default: - break; + return; } + glutPostRedisplay(); } /* Main Loop diff --git a/progs/trivial/tri.c b/progs/trivial/tri.c index d44cb6a9fe3..cac3fcb7d9c 100644 --- a/progs/trivial/tri.c +++ b/progs/trivial/tri.c @@ -60,6 +60,7 @@ static void Key(unsigned char key, int x, int y) { switch (key) { case 27: + glutDestroyWindow(win); exit(0); default: glutPostRedisplay(); diff --git a/progs/trivial/vbo-noninterleaved.c b/progs/trivial/vbo-noninterleaved.c new file mode 100644 index 00000000000..0672ca50ff1 --- /dev/null +++ b/progs/trivial/vbo-noninterleaved.c @@ -0,0 +1,139 @@ +/* Basic VBO */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + + +struct { + GLfloat pos[4][4]; + GLfloat col[4][4]; +} verts = +{ + /* Position: a quad + */ + { + { 0.9, -0.9, 0.0, 1.0 }, + { 0.9, 0.9, 0.0, 1.0 }, + { -0.9, 0.9, 0.0, 1.0 }, + { -0.9, -0.9, 0.0, 1.0 }, + }, + + /* Color: all red + */ + { + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + }, + + +}; + +GLuint arrayObj, elementObj; + +static void Init( void ) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "MOV result.color, vertex.color;\n" + "MOV result.position, vertex.position;\n" + "END\n"; + + glGenProgramsARB(1, &prognum); + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + assert(glIsProgramARB(prognum)); + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + glGenBuffersARB(1, &arrayObj); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), &verts, GL_STATIC_DRAW_ARB); + + glVertexPointer( 4, GL_FLOAT, sizeof(verts.pos[0]), 0 ); + glColorPointer( 4, GL_FLOAT, sizeof(verts.col[0]), (void *)(4*4*sizeof(float)) ); + +} + + + +static void Display( void ) +{ + glClearColor(0.3, 0.3, 0.3, 1); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glEnable(GL_VERTEX_PROGRAM_ARB); + +// glDrawArrays( GL_TRIANGLES, 0, 3 ); +// glDrawArrays( GL_TRIANGLES, 1, 3 ); + glDrawArrays( GL_QUADS, 0, 4 ); + + glFlush(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + /*glTranslatef( 0.0, 0.0, -15.0 );*/ +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 250, 250 ); + glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/vp-tri-invariant.c b/progs/trivial/vp-tri-invariant.c new file mode 100644 index 00000000000..ff241393659 --- /dev/null +++ b/progs/trivial/vp-tri-invariant.c @@ -0,0 +1,147 @@ +/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "OPTION ARB_position_invariant ;" + "MOV result.color, vertex.color;\n" + "END\n"; + + + glGenProgramsARB(1, &prognum); + + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + 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)); + fflush(stderr); + + glClearColor(0.0, 0.0, 1.0, 0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); +/* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */ + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glEnable(GL_VERTEX_PROGRAM_ARB); + + glBegin(GL_TRIANGLES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -0.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -0.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -0.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB | GLUT_ALPHA; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + glewInit(); + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/util/extfuncs.h b/progs/util/extfuncs.h index 070414e2943..238794d55a9 100644 --- a/progs/util/extfuncs.h +++ b/progs/util/extfuncs.h @@ -86,6 +86,15 @@ 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; + static void GetExtensionFuncs(void) @@ -173,5 +182,15 @@ 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"); + } diff --git a/progs/vpglsl/psiz-imm.glsl b/progs/vpglsl/psiz-imm.glsl new file mode 100644 index 00000000000..101d314d584 --- /dev/null +++ b/progs/vpglsl/psiz-imm.glsl @@ -0,0 +1,6 @@ + +void main() { + gl_FrontColor = gl_Color; + gl_PointSize = 2.0; + gl_Position = gl_Vertex; +} diff --git a/progs/vpglsl/psiz-mul.glsl b/progs/vpglsl/psiz-mul.glsl new file mode 100644 index 00000000000..77f4a46b520 --- /dev/null +++ b/progs/vpglsl/psiz-mul.glsl @@ -0,0 +1,6 @@ + +void main() { + gl_FrontColor = gl_Color; + gl_PointSize = 10 * gl_Color.x; + gl_Position = gl_Vertex; +} diff --git a/progs/vpglsl/vp-tris.c b/progs/vpglsl/vp-tris.c index 9ae410bf984..b2b05080910 100644 --- a/progs/vpglsl/vp-tris.c +++ b/progs/vpglsl/vp-tris.c @@ -10,6 +10,10 @@ static const char *filename = NULL; static GLuint nr_steps = 4; +static GLuint prim = GL_TRIANGLES; +static GLfloat psz = 1.0; +static GLboolean pointsmooth = 0; +static GLboolean program_point_size = 0; static GLuint fragShader; static GLuint vertShader; @@ -229,6 +233,14 @@ static void subdiv( union vert *v0, } } +static void enable( GLenum value, GLboolean flag ) +{ + if (flag) + glEnable(value); + else + glDisable(value); +} + /** Assignment */ #define ASSIGN_3V( V, V0, V1, V2 ) \ do { \ @@ -241,10 +253,13 @@ static void Display( void ) { glClearColor(0.3, 0.3, 0.3, 1); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glPointSize(psz); glUseProgram(program); + enable( GL_POINT_SMOOTH, pointsmooth ); + enable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB, program_point_size ); - glBegin(GL_TRIANGLES); + glBegin(prim); { @@ -291,10 +306,41 @@ static void Key( unsigned char key, int x, int y ) (void) x; (void) y; switch (key) { - case 27: - CleanUp(); - exit(0); - break; + case 'p': + prim = GL_POINTS; + break; + case 't': + prim = GL_TRIANGLES; + break; + case 's': + psz += .5; + break; + case 'S': + if (psz > .5) + psz -= .5; + break; + case 'm': + pointsmooth = !pointsmooth; + break; + case 'z': + program_point_size = !program_point_size; + break; + case '+': + nr_steps++; + break; + case '-': + if (nr_steps) + nr_steps--; + break; + case ' ': + psz = 1.0; + prim = GL_TRIANGLES; + nr_steps = 4; + break; + case 27: + CleanUp(); + exit(0); + break; } glutPostRedisplay(); } @@ -305,7 +351,7 @@ int main( int argc, char *argv[] ) glutInitWindowPosition( 0, 0 ); glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); - glutCreateWindow(argv[0]); + glutCreateWindow(argv[argc-1]); glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); diff --git a/progs/wgl/SConscript b/progs/wgl/SConscript index b7cf35b7fce..31f61676dec 100644 --- a/progs/wgl/SConscript +++ b/progs/wgl/SConscript @@ -21,3 +21,5 @@ for prog in progs: target = prog, source = prog + '/' + prog + '.c', ) + +env.Program('wglinfo', ['wglinfo.c']) diff --git a/progs/wgl/wglinfo.c b/progs/wgl/wglinfo.c new file mode 100644 index 00000000000..864372c2f94 --- /dev/null +++ b/progs/wgl/wglinfo.c @@ -0,0 +1,736 @@ +/* + * Copyright (C) 2009 VMware, Inc. + * Copyright (C) 1999-2006 Brian Paul + * 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. + */ + + +/* + * This program is a work-alike of the GLX glxinfo program. + * Command line options: + * -t print wide table + * -v print verbose information + * -b only print ID of "best" visual on screen 0 + * -l print interesting OpenGL limits (added 5 Sep 2002) + */ + +#include <windows.h> + +#include <GL/gl.h> +#include <GL/glext.h> +#include <GL/wglext.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +typedef enum +{ + Normal, + Wide, + Verbose +} InfoMode; + + +/* + * Print a list of extensions, with word-wrapping. + */ +static void +print_extension_list(const char *ext) +{ + const char *indentString = " "; + const int indent = 4; + const int max = 79; + int width, i, j; + + if (!ext || !ext[0]) + return; + + width = indent; + printf(indentString); + i = j = 0; + while (1) { + if (ext[j] == ' ' || ext[j] == 0) { + /* found end of an extension name */ + const int len = j - i; + if (width + len > max) { + /* start a new line */ + printf("\n"); + width = indent; + printf(indentString); + } + /* print the extension name between ext[i] and ext[j] */ + while (i < j) { + printf("%c", ext[i]); + i++; + } + /* either we're all done, or we'll continue with next extension */ + width += len + 1; + if (ext[j] == 0) { + break; + } + else { + i++; + j++; + if (ext[j] == 0) + break; + printf(", "); + width += 2; + } + } + j++; + } + printf("\n"); +} + + +/** + * Print interesting limits for vertex/fragment programs. + */ +static void +print_program_limits(GLenum target) +{ +#if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program) + struct token_name { + GLenum token; + const char *name; + }; + static const struct token_name limits[] = { + { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" }, + { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" }, + { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" }, + { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" }, + { (GLenum) 0, NULL } + }; + PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC) + wglGetProcAddress("glGetProgramivARB"); + GLint max[1]; + int i; + + if (target == GL_VERTEX_PROGRAM_ARB) { + printf(" GL_VERTEX_PROGRAM_ARB:\n"); + } + else if (target == GL_FRAGMENT_PROGRAM_ARB) { + printf(" GL_FRAGMENT_PROGRAM_ARB:\n"); + } + else { + return; /* something's wrong */ + } + + for (i = 0; limits[i].token; i++) { + GetProgramivARB_func(target, limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", limits[i].name, max[0]); + } + } +#endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */ +} + + +/** + * Print interesting limits for vertex/fragment shaders. + */ +static void +print_shader_limits(GLenum target) +{ + struct token_name { + GLenum token; + const char *name; + }; +#if defined(GL_ARB_vertex_shader) + static const struct token_name vertex_limits[] = { + { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" }, + { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" }, + { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" }, + { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" }, + { (GLenum) 0, NULL } + }; +#endif +#if defined(GL_ARB_fragment_shader) + static const struct token_name fragment_limits[] = { + { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" }, + { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" }, + { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" }, + { (GLenum) 0, NULL } + }; +#endif + GLint max[1]; + int i; + +#if defined(GL_ARB_vertex_shader) + if (target == GL_VERTEX_SHADER_ARB) { + printf(" GL_VERTEX_SHADER_ARB:\n"); + for (i = 0; vertex_limits[i].token; i++) { + glGetIntegerv(vertex_limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", vertex_limits[i].name, max[0]); + } + } + } +#endif +#if defined(GL_ARB_fragment_shader) + if (target == GL_FRAGMENT_SHADER_ARB) { + printf(" GL_FRAGMENT_SHADER_ARB:\n"); + for (i = 0; fragment_limits[i].token; i++) { + glGetIntegerv(fragment_limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", fragment_limits[i].name, max[0]); + } + } + } +#endif +} + + +/** + * Print interesting OpenGL implementation limits. + */ +static void +print_limits(const char *extensions) +{ + struct token_name { + GLuint count; + GLenum token; + const char *name; + }; + static const struct token_name limits[] = { + { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" }, + { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" }, + { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" }, + { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" }, + { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" }, + { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" }, + { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" }, + { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" }, + { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" }, + { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" }, + { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" }, + { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" }, + { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" }, + { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" }, + { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" }, + { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" }, + { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" }, + { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" }, + { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" }, + { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" }, + { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" }, +#if defined(GL_ARB_texture_cube_map) + { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" }, +#endif +#if defined(GLX_NV_texture_rectangle) + { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" }, +#endif +#if defined(GL_ARB_texture_compression) + { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" }, +#endif +#if defined(GL_ARB_multitexture) + { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" }, +#endif +#if defined(GL_EXT_texture_lod_bias) + { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" }, +#endif +#if defined(GL_EXT_texture_filter_anisotropic) + { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" }, +#endif +#if defined(GL_ARB_draw_buffers) + { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" }, +#endif + { 0, (GLenum) 0, NULL } + }; + GLint i, max[2]; + + printf("OpenGL limits:\n"); + for (i = 0; limits[i].count; i++) { + glGetIntegerv(limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + if (limits[i].count == 1) + printf(" %s = %d\n", limits[i].name, max[0]); + else /* XXX fix if we ever query something with more than 2 values */ + printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]); + } + } + +#if defined(GL_EXT_convolution) + { + PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC glGetConvolutionParameterivEXT_func = + (PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC)wglGetProcAddress("glGetConvolutionParameterivEXT"); + if(glGetConvolutionParameterivEXT_func) { + /* these don't fit into the above mechanism, unfortunately */ + glGetConvolutionParameterivEXT_func(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max); + glGetConvolutionParameterivEXT_func(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1); + if (glGetError() == GL_NONE) { + printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]); + } + } + } +#endif + +#if defined(GL_ARB_vertex_program) + if (strstr(extensions, "GL_ARB_vertex_program")) { + print_program_limits(GL_VERTEX_PROGRAM_ARB); + } +#endif +#if defined(GL_ARB_fragment_program) + if (strstr(extensions, "GL_ARB_fragment_program")) { + print_program_limits(GL_FRAGMENT_PROGRAM_ARB); + } +#endif +#if defined(GL_ARB_vertex_shader) + if (strstr(extensions, "GL_ARB_vertex_shader")) { + print_shader_limits(GL_VERTEX_SHADER_ARB); + } +#endif +#if defined(GL_ARB_fragment_shader) + if (strstr(extensions, "GL_ARB_fragment_shader")) { + print_shader_limits(GL_FRAGMENT_SHADER_ARB); + } +#endif +} + + +static LRESULT CALLBACK +WndProc(HWND hWnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam ) +{ + switch (uMsg) { + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + + return 0; +} + + +static void +print_screen_info(HDC _hdc, GLboolean limits) +{ + WNDCLASS wc; + HWND win; + HGLRC ctx; + int visinfo; + HDC hdc; + PIXELFORMATDESCRIPTOR pfd; + + memset(&wc, 0, sizeof wc); + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.lpfnWndProc = WndProc; + wc.lpszClassName = "wglinfo"; + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); + + win = CreateWindowEx(0, + wc.lpszClassName, + "wglinfo", + WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + NULL, + NULL, + wc.hInstance, + NULL); + if (!win) { + fprintf(stderr, "Couldn't create window"); + return; + } + + hdc = GetDC(win); + if (!hdc) { + fprintf(stderr, "Couldn't obtain HDC"); + return; + } + + pfd.cColorBits = 3; + pfd.cRedBits = 1; + pfd.cGreenBits = 1; + pfd.cBlueBits = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pfd.iLayerType = PFD_MAIN_PLANE; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + + visinfo = ChoosePixelFormat(hdc, &pfd); + if (!visinfo) { + pfd.dwFlags |= PFD_DOUBLEBUFFER; + visinfo = ChoosePixelFormat(hdc, &pfd); + } + + if (!visinfo) { + fprintf(stderr, "Error: couldn't find RGB WGL visual\n"); + return; + } + + SetPixelFormat(hdc, visinfo, &pfd); + ctx = wglCreateContext(hdc); + if (!ctx) { + fprintf(stderr, "Error: wglCreateContext failed\n"); + return; + } + + if (wglMakeCurrent(hdc, ctx)) { +#if defined(WGL_ARB_extensions_string) + PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB_func = + (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); +#endif + const char *glVendor = (const char *) glGetString(GL_VENDOR); + const char *glRenderer = (const char *) glGetString(GL_RENDERER); + const char *glVersion = (const char *) glGetString(GL_VERSION); + const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); + +#if defined(WGL_ARB_extensions_string) + if(wglGetExtensionsStringARB_func) { + const char *wglExtensions = wglGetExtensionsStringARB_func(hdc); + if(wglExtensions) { + printf("WGL extensions:\n"); + print_extension_list(wglExtensions); + } + } +#endif + printf("OpenGL vendor string: %s\n", glVendor); + printf("OpenGL renderer string: %s\n", glRenderer); + printf("OpenGL version string: %s\n", glVersion); +#ifdef GL_VERSION_2_0 + if (glVersion[0] >= '2' && glVersion[1] == '.') { + char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION); + printf("OpenGL shading language version string: %s\n", v); + } +#endif + + printf("OpenGL extensions:\n"); + print_extension_list(glExtensions); + if (limits) + print_limits(glExtensions); + } + else { + fprintf(stderr, "Error: wglMakeCurrent failed\n"); + } + + DestroyWindow(win); +} + + +static const char * +visual_render_type_name(BYTE iPixelType) +{ + switch (iPixelType) { + case PFD_TYPE_RGBA: + return "rgba"; + case PFD_TYPE_COLORINDEX: + return "ci"; + default: + return ""; + } +} + +static void +print_visual_attribs_verbose(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd) +{ + printf("Visual ID: %x generic=%d native=%d\n", + iPixelFormat, + ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0, + ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0); + printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", + 0 /* ppfd->bufferSize */, 0 /* ppfd->level */, + visual_render_type_name(ppfd->iPixelType), + ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0, + ppfd->dwFlags & PFD_STEREO ? 1 : 0); + printf(" rgba: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n", + ppfd->cRedBits, ppfd->cGreenBits, + ppfd->cBlueBits, ppfd->cAlphaBits); + printf(" cAuxBuffers=%d cDepthBits=%d cStencilBits=%d\n", + ppfd->cAuxBuffers, ppfd->cDepthBits, ppfd->cStencilBits); + printf(" accum: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n", + ppfd->cAccumRedBits, ppfd->cAccumGreenBits, + ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits); + printf(" multiSample=%d multiSampleBuffers=%d\n", + 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */); +} + + +static void +print_visual_attribs_short_header(void) +{ + printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n"); + printf(" id gen nat sp sz l ci b ro r g b a bf th cl r g b a ns b eat\n"); + printf("-----------------------------------------------------------------------\n"); +} + + +static void +print_visual_attribs_short(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd) +{ + char *caveat = "None"; + + printf("0x%02x %2d %2d %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d", + iPixelFormat, + ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0, + ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0, + 0, + 0 /* ppfd->bufferSize */, + 0 /* ppfd->level */, + ppfd->iPixelType == PFD_TYPE_RGBA ? 'r' : ' ', + ppfd->iPixelType == PFD_TYPE_COLORINDEX ? 'c' : ' ', + ppfd->dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.', + ppfd->dwFlags & PFD_STEREO ? 'y' : '.', + ppfd->cRedBits, ppfd->cGreenBits, + ppfd->cBlueBits, ppfd->cAlphaBits, + ppfd->cAuxBuffers, + ppfd->cDepthBits, + ppfd->cStencilBits + ); + + printf(" %2d %2d %2d %2d %2d %1d %s\n", + ppfd->cAccumRedBits, ppfd->cAccumGreenBits, + ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits, + 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */, + caveat + ); +} + + +static void +print_visual_attribs_long_header(void) +{ + printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n"); + printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n"); + printf("----------------------------------------------------------------------------------------------------\n"); +} + + +static void +print_visual_attribs_long(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd) +{ + printf("0x%2x %2d %11d %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d", + iPixelFormat, + ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0, + ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0, + 0, + 0 /* ppfd->bufferSize */, + 0 /* ppfd->level */, + visual_render_type_name(ppfd->iPixelType), + ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0, + ppfd->dwFlags & PFD_STEREO ? 1 : 0, + ppfd->cRedBits, ppfd->cGreenBits, + ppfd->cBlueBits, ppfd->cAlphaBits + ); + + printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n", + ppfd->cAuxBuffers, + ppfd->cDepthBits, + ppfd->cStencilBits, + ppfd->cAccumRedBits, ppfd->cAccumGreenBits, + ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits, + 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */ + ); +} + + +static void +print_visual_info(HDC hdc, InfoMode mode) +{ + PIXELFORMATDESCRIPTOR pfd; + int numVisuals, numWglVisuals; + int i; + + numVisuals = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); + if (numVisuals == 0) + return; + + numWglVisuals = 0; + for (i = 0; i < numVisuals; i++) { + if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) + continue; + + //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) + // continue; + + ++numWglVisuals; + } + + printf("%d WGL Visuals\n", numWglVisuals); + + if (mode == Normal) + print_visual_attribs_short_header(); + else if (mode == Wide) + print_visual_attribs_long_header(); + + for (i = 0; i < numVisuals; i++) { + if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) + continue; + + //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) + // continue; + + if (mode == Verbose) + print_visual_attribs_verbose(i, &pfd); + else if (mode == Normal) + print_visual_attribs_short(i, &pfd); + else if (mode == Wide) + print_visual_attribs_long(i, &pfd); + } + printf("\n"); +} + + +/* + * Examine all visuals to find the so-called best one. + * We prefer deepest RGBA buffer with depth, stencil and accum + * that has no caveats. + */ +static int +find_best_visual(HDC hdc) +{ +#if 0 + XVisualInfo theTemplate; + XVisualInfo *visuals; + int numVisuals; + long mask; + int i; + struct visual_attribs bestVis; + + /* get list of all visuals on this screen */ + theTemplate.screen = scrnum; + mask = VisualScreenMask; + visuals = XGetVisualInfo(hdc, mask, &theTemplate, &numVisuals); + + /* init bestVis with first visual info */ + get_visual_attribs(hdc, &visuals[0], &bestVis); + + /* try to find a "better" visual */ + for (i = 1; i < numVisuals; i++) { + struct visual_attribs vis; + + get_visual_attribs(hdc, &visuals[i], &vis); + + /* always skip visuals with caveats */ + if (vis.visualCaveat != GLX_NONE_EXT) + continue; + + /* see if this vis is better than bestVis */ + if ((!bestVis.supportsGL && vis.supportsGL) || + (bestVis.visualCaveat != GLX_NONE_EXT) || + (bestVis.iPixelType != vis.iPixelType) || + (!bestVis.doubleBuffer && vis.doubleBuffer) || + (bestVis.cRedBits < vis.cRedBits) || + (bestVis.cGreenBits < vis.cGreenBits) || + (bestVis.cBlueBits < vis.cBlueBits) || + (bestVis.cAlphaBits < vis.cAlphaBits) || + (bestVis.cDepthBits < vis.cDepthBits) || + (bestVis.cStencilBits < vis.cStencilBits) || + (bestVis.cAccumRedBits < vis.cAccumRedBits)) { + /* found a better visual */ + bestVis = vis; + } + } + + return bestVis.id; +#else + return 0; +#endif +} + + +static void +usage(void) +{ + printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n"); + printf("\t-v: Print visuals info in verbose form.\n"); + printf("\t-t: Print verbose table.\n"); + printf("\t-h: This information.\n"); + printf("\t-b: Find the 'best' visual and print it's number.\n"); + printf("\t-l: Print interesting OpenGL limits.\n"); +} + + +int +main(int argc, char *argv[]) +{ + HDC hdc; + InfoMode mode = Normal; + GLboolean findBest = GL_FALSE; + GLboolean limits = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-t") == 0) { + mode = Wide; + } + else if (strcmp(argv[i], "-v") == 0) { + mode = Verbose; + } + else if (strcmp(argv[i], "-b") == 0) { + findBest = GL_TRUE; + } + else if (strcmp(argv[i], "-l") == 0) { + limits = GL_TRUE; + } + else if (strcmp(argv[i], "-h") == 0) { + usage(); + return 0; + } + else { + printf("Unknown option `%s'\n", argv[i]); + usage(); + return 0; + } + } + + hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); + + if (findBest) { + int b; + b = find_best_visual(hdc); + printf("%d\n", b); + } + else { + print_screen_info(hdc, limits); + printf("\n"); + print_visual_info(hdc, mode); + } + + return 0; +} diff --git a/progs/xdemos/glxcontexts.c b/progs/xdemos/glxcontexts.c index a9ff326ed5e..a97b62a9081 100644 --- a/progs/xdemos/glxcontexts.c +++ b/progs/xdemos/glxcontexts.c @@ -385,6 +385,10 @@ draw( Display *dpy, Window win ) } else do_draw(); + glDeleteLists(gear1, 1); + glDeleteLists(gear2, 1); + glDeleteLists(gear3, 1); + glXSwapBuffers(dpy, win); glXDestroyContext(dpy, ctx); } |