Mercurial > mplayer.hg
changeset 22737:6ce48e36dc01
Move gltest and bmovl-test into the main TOOLS directory, subdirectories
for single files are silly.
author | diego |
---|---|
date | Tue, 20 Mar 2007 01:06:51 +0000 |
parents | 69c9abd89634 |
children | 2852487b2f8d |
files | TOOLS/GL-test/compile.sh TOOLS/GL-test/gltest.c TOOLS/Makefile TOOLS/bmovl-test.c TOOLS/bmovl-test/Makefile TOOLS/bmovl-test/bmovl-test.c TOOLS/gltest.c |
diffstat | 7 files changed, 312 insertions(+), 315 deletions(-) [+] |
line wrap: on
line diff
--- a/TOOLS/GL-test/compile.sh Mon Mar 19 22:09:53 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ - -gcc -g -O4 gltest.c ../../osdep/timer-lx.o -o gltest -L/usr/X11/lib -L/usr/X11R6/lib -lglut -lGL -lGLU -lX11 -lXext -lXmu -lXi -lm
--- a/TOOLS/GL-test/gltest.c Mon Mar 19 22:09:53 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ -// OpenGL glTexSubImage() test/benchmark prg (C) 2001. by A'rpi/ESP-team - -#include <GL/glut.h> -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <inttypes.h> - -// pixel size: 3 or 4 -#define BYTES_PP 3 - -// blit by lines (defined) or frames (not defined) -#define FAST_BLIT - -static uint32_t image_width=720; // DVD size -static uint32_t image_height=576; - -static uint32_t image_format; -static uint32_t image_bpp; -static uint32_t image_bytes; - -static uint32_t texture_width=512; -static uint32_t texture_height=512; - -static unsigned char *ImageData=NULL; - -static GLvoid resize(int x,int y){ - printf("Resize: %dx%d\n",x,y); - glViewport( 0, 0, x, y ); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, image_width, image_height, 0, -1,1); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - -float akarmi=0; - -int counter=0; -float gen_time=0; -float up_time=0; -float render_time=0; - -unsigned char sintable[4096]; - -extern float GetRelativeTime(); - -static void redraw(void) -{ -// glClear(GL_COLOR_BUFFER_BIT); - int x,y,i; - unsigned char *d=ImageData; - int dstride=BYTES_PP*image_width; - - GetRelativeTime(); - - // generate some image: - for(y=0;y<image_height;y++){ - int y1=2048*sin(akarmi*0.36725+y*0.0165); - int y2=2048*sin(akarmi*0.45621+y*0.02753); - int y3=2048*sin(akarmi*0.15643+y*0.03732); - for(x=0;x<image_width;x++){ - d[0]=sintable[(y1+x*135)&4095]; - d[1]=sintable[(y2+x*62)&4095]; - d[2]=sintable[(y3+x*23)&4095]; - d+=BYTES_PP; - } - } - - gen_time+=GetRelativeTime(); - -#ifdef FAST_BLIT - // upload texture: - for(i=0;i<image_height;i++){ - glTexSubImage2D( GL_TEXTURE_2D, // target - 0, // level - 0, // x offset - i, // y offset - image_width, // width - 1, // height - (BYTES_PP==4)?GL_RGBA:GL_RGB, // format - GL_UNSIGNED_BYTE, // type - ImageData+i*dstride ); // *pixels - } -#else - glTexSubImage2D( GL_TEXTURE_2D, // target - 0, // level - 0, // x offset - 0, // y offset - image_width, // width - image_height, // height - (BYTES_PP==4)?GL_RGBA:GL_RGB, // format - GL_UNSIGNED_BYTE, // type - ImageData ); // *pixels -#endif - - up_time+=GetRelativeTime(); - - glColor3f(1,1,1); - glBegin(GL_QUADS); - glTexCoord2f(0,0);glVertex2i(0,0); - glTexCoord2f(0,1);glVertex2i(0,texture_height); - glTexCoord2f(1,1);glVertex2i(texture_width,texture_height); - glTexCoord2f(1,0);glVertex2i(texture_width,0); - glEnd(); - - glFinish(); - glutSwapBuffers(); - - render_time+=GetRelativeTime(); - - ++counter; - { float total=gen_time+up_time+render_time; - if(total>2.0){ - printf("%8.3f fps (gen: %2d%% upload: %2d%% render: %2d%%)\n", - (float)counter/total, - (int)(100.0*gen_time/total), - (int)(100.0*up_time/total), - (int)(100.0*render_time/total) - ); - gen_time=up_time=render_time=0; - counter=0; - } } - -} - -static GLvoid IdleFunc(){ - akarmi+=0.1; - glutPostRedisplay(); -} - -int -main(int argc, char **argv) -{ - int i; - - glutInit(&argc, argv); - glutInitWindowSize(640, 480); - glutInitDisplayMode(GLUT_DOUBLE); - (void) glutCreateWindow("csg"); - - glutDisplayFunc(redraw); - glutReshapeFunc(resize); - glutIdleFunc(IdleFunc); - - texture_width=32; - while(texture_width<image_width) texture_width*=2; - while(texture_width<image_height) texture_width*=2; - texture_height=texture_width; - - image_bpp=8*BYTES_PP; - image_bytes=BYTES_PP; - - ImageData=malloc(texture_width*texture_height*image_bytes); - memset(ImageData,128,texture_width*texture_height*image_bytes); - - glDisable(GL_BLEND); - glDisable(GL_DEPTH_TEST); - glDepthMask(GL_FALSE); - glDisable(GL_CULL_FACE); - - glEnable(GL_TEXTURE_2D); - - printf("Creating %dx%d texture...\n",texture_width,texture_height); - -#if 1 -// glBindTexture(GL_TEXTURE_2D, texture_id); - glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); -#ifdef TEXTUREFORMAT_32BPP - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0, -#else - glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0, -#endif - (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData); -#endif - - resize(640,480); - - glClearColor( 1.0f,0.0f,1.0f,0.0f ); - glClear( GL_COLOR_BUFFER_BIT ); - - for(i=0;i<4096;i++) sintable[i]=128+127*sin(2.0*3.14159265*i/4096.0); - - glutMainLoop(); - return 0; /* ANSI C requires main to return int. */ -}
--- a/TOOLS/Makefile Mon Mar 19 22:09:53 2007 +0000 +++ b/TOOLS/Makefile Tue Mar 20 01:06:51 2007 +0000 @@ -45,7 +45,13 @@ $(CC) $(CFLAGS) -g $< -o fastmem2-k7$(EXESUF) ../libvo/aclib.o -DNAME=\"mga-k7\ \" -DHAVE_MGA -DHAVE_MMX -DHAVE_3DNOW -DHAVE_MMX2 $(CC) $(CFLAGS) -g $< -o fastmem2-sse$(EXESUF) ../libvo/aclib.o -DNAME=\"mga-sse\" -DHAVE_MGA -DHAVE_MMX -DHAVE_SSE -DHAVE_MMX2 +bmovl-test$(EXESUF): bmovl-test.c + $(CC) -O3 -I/usr/include/SDL -lSDL_image -o $@ $< + +gltest: gltest.c ../osdep/timer-lx.o + $(CC) -O4 -g -o $@ $^ -lglut + clean distclean: rm -f $(OBJS) rm -f fastmem-* fastmem2-* - rm -f cpuinfo$(EXESUF) fastmemcpybench + rm -f cpuinfo$(EXESUF) fastmemcpybench bmovl-test$(EXESUF) gltest
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TOOLS/bmovl-test.c Tue Mar 20 01:06:51 2007 +0000 @@ -0,0 +1,116 @@ +/* Small program to test the features of vf_bmovl */ + +#include <unistd.h> +#include <fcntl.h> +#include <SDL.h> +#include <SDL_image.h> + +#define DEBUG 0 + +static void +blit(int fifo, unsigned char *bitmap, int width, int height, + int xpos, int ypos, int alpha, int clear) +{ + char str[100]; + int nbytes; + + sprintf(str, "RGBA32 %d %d %d %d %d %d\n", + width, height, xpos, ypos, alpha, clear); + + if(DEBUG) printf("Sending %s", str); + + write(fifo, str, strlen(str)); + nbytes = write(fifo, bitmap, width*height*4); + + if(DEBUG) printf("Sent %d bytes of bitmap data...\n", nbytes); +} + +static void +set_alpha(int fifo, int width, int height, int xpos, int ypos, int alpha) { + char str[100]; + + sprintf(str, "ALPHA %d %d %d %d %d\n", + width, height, xpos, ypos, alpha); + + if(DEBUG) printf("Sending %s", str); + + write(fifo, str, strlen(str)); +} + +static void +paint(unsigned char* bitmap, int size, int red, int green, int blue, int alpha) { + + int i; + + for(i=0; i < size; i+=4) { + bitmap[i+0] = red; + bitmap[i+1] = green; + bitmap[i+2] = blue; + bitmap[i+3] = alpha; + } +} + +int main(int argc, char **argv) { + + int fifo=-1; + int width=0, height=0, xpos=0, ypos=0, alpha=0, clear=0; + unsigned char *bitmap; + SDL_Surface *image; + int i; + + if(argc<3) { + printf("Usage: %s <bmovl fifo> <image file> <width> <height>\n", argv[0]); + printf("width and height are w/h of MPlayer's screen!\n"); + exit(10); + } + + width = atoi(argv[3]); + height = atoi(argv[4]); + + fifo = open( argv[1], O_RDWR ); + if(!fifo) { + fprintf(stderr, "Error opening FIFO %s!\n", argv[1]); + exit(10); + } + + image = IMG_Load(argv[2]); + if(!image) { + fprintf(stderr, "Couldn't load image %s!\n", argv[2]); + exit(10); + } + + printf("Loaded image %s: width=%d, height=%d\n", argv[2], image->w, image->h); + + // Display and move image + for(i=0; (i < (width - image->w)) && (i < (height - image->h)); i += 5) + blit(fifo, image->pixels, image->w, image->h, i, i, 0, 1); + + // Create a 75x75 bitmap + bitmap = (unsigned char*)malloc(75*75*4); + + // Paint bitmap red, 50% transparent and blit at position 50,50 + paint(bitmap, (75*75*4), 255, 0, 0, 128); + blit(fifo, bitmap, 75, 75, 50, 50, 0, 0); + + // Paint bitmap green, 50% transparent and blit at position -50,50 + paint(bitmap, (75*75*4), 0, 255, 0, 128); + blit(fifo, bitmap, 75, 75, width-50-75, 50, 0, 0); + + // Paint bitmap blue, 50% transparent and blit at position -50,50 + paint(bitmap, (75*75*4), 0, 0, 255, 128); + blit(fifo, bitmap, 75, 75, 50, height-50-75, 0, 0); + + // Blit another image in the middle, completly transparent + blit(fifo, image->pixels, image->w, image->h, + (width/2)-(image->w/2), (height/2)-(image->h/2), -255, 0); + + // Fade in image + for(i=-255; i <= 0; i++) + set_alpha(fifo, image->w, image->h, + (width/2)-(image->w/2), (height/2)-(image->h/2), i); + + + // Clean up + free(bitmap); + SDL_FreeSurface(image); +}
--- a/TOOLS/bmovl-test/Makefile Mon Mar 19 22:09:53 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -include ../../config.mak - -bmovl-test$(EXESUF): bmovl-test.c - $(CC) -O3 $(EXTRA_INC) -lSDL_image -o $@ bmovl-test.c - -clean: - rm -f bmovl-test
--- a/TOOLS/bmovl-test/bmovl-test.c Mon Mar 19 22:09:53 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* Small program to test the features of vf_bmovl */ - -#include <unistd.h> -#include <fcntl.h> -#include <SDL.h> -#include <SDL_image.h> - -#define DEBUG 0 - -static void -blit(int fifo, unsigned char *bitmap, int width, int height, - int xpos, int ypos, int alpha, int clear) -{ - char str[100]; - int nbytes; - - sprintf(str, "RGBA32 %d %d %d %d %d %d\n", - width, height, xpos, ypos, alpha, clear); - - if(DEBUG) printf("Sending %s", str); - - write(fifo, str, strlen(str)); - nbytes = write(fifo, bitmap, width*height*4); - - if(DEBUG) printf("Sent %d bytes of bitmap data...\n", nbytes); -} - -static void -set_alpha(int fifo, int width, int height, int xpos, int ypos, int alpha) { - char str[100]; - - sprintf(str, "ALPHA %d %d %d %d %d\n", - width, height, xpos, ypos, alpha); - - if(DEBUG) printf("Sending %s", str); - - write(fifo, str, strlen(str)); -} - -static void -paint(unsigned char* bitmap, int size, int red, int green, int blue, int alpha) { - - int i; - - for(i=0; i < size; i+=4) { - bitmap[i+0] = red; - bitmap[i+1] = green; - bitmap[i+2] = blue; - bitmap[i+3] = alpha; - } -} - -int main(int argc, char **argv) { - - int fifo=-1; - int width=0, height=0, xpos=0, ypos=0, alpha=0, clear=0; - unsigned char *bitmap; - SDL_Surface *image; - int i; - - if(argc<3) { - printf("Usage: %s <bmovl fifo> <image file> <width> <height>\n", argv[0]); - printf("width and height are w/h of MPlayer's screen!\n"); - exit(10); - } - - width = atoi(argv[3]); - height = atoi(argv[4]); - - fifo = open( argv[1], O_RDWR ); - if(!fifo) { - fprintf(stderr, "Error opening FIFO %s!\n", argv[1]); - exit(10); - } - - image = IMG_Load(argv[2]); - if(!image) { - fprintf(stderr, "Couldn't load image %s!\n", argv[2]); - exit(10); - } - - printf("Loaded image %s: width=%d, height=%d\n", argv[2], image->w, image->h); - - // Display and move image - for(i=0; (i < (width - image->w)) && (i < (height - image->h)); i += 5) - blit(fifo, image->pixels, image->w, image->h, i, i, 0, 1); - - // Create a 75x75 bitmap - bitmap = (unsigned char*)malloc(75*75*4); - - // Paint bitmap red, 50% transparent and blit at position 50,50 - paint(bitmap, (75*75*4), 255, 0, 0, 128); - blit(fifo, bitmap, 75, 75, 50, 50, 0, 0); - - // Paint bitmap green, 50% transparent and blit at position -50,50 - paint(bitmap, (75*75*4), 0, 255, 0, 128); - blit(fifo, bitmap, 75, 75, width-50-75, 50, 0, 0); - - // Paint bitmap blue, 50% transparent and blit at position -50,50 - paint(bitmap, (75*75*4), 0, 0, 255, 128); - blit(fifo, bitmap, 75, 75, 50, height-50-75, 0, 0); - - // Blit another image in the middle, completly transparent - blit(fifo, image->pixels, image->w, image->h, - (width/2)-(image->w/2), (height/2)-(image->h/2), -255, 0); - - // Fade in image - for(i=-255; i <= 0; i++) - set_alpha(fifo, image->w, image->h, - (width/2)-(image->w/2), (height/2)-(image->h/2), i); - - - // Clean up - free(bitmap); - SDL_FreeSurface(image); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TOOLS/gltest.c Tue Mar 20 01:06:51 2007 +0000 @@ -0,0 +1,189 @@ +// OpenGL glTexSubImage() test/benchmark prg (C) 2001. by A'rpi/ESP-team + +#include <GL/glut.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <inttypes.h> + +// pixel size: 3 or 4 +#define BYTES_PP 3 + +// blit by lines (defined) or frames (not defined) +#define FAST_BLIT + +static uint32_t image_width=720; // DVD size +static uint32_t image_height=576; + +static uint32_t image_format; +static uint32_t image_bpp; +static uint32_t image_bytes; + +static uint32_t texture_width=512; +static uint32_t texture_height=512; + +static unsigned char *ImageData=NULL; + +static GLvoid resize(int x,int y){ + printf("Resize: %dx%d\n",x,y); + glViewport( 0, 0, x, y ); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, image_width, image_height, 0, -1,1); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +float akarmi=0; + +int counter=0; +float gen_time=0; +float up_time=0; +float render_time=0; + +unsigned char sintable[4096]; + +extern float GetRelativeTime(); + +static void redraw(void) +{ +// glClear(GL_COLOR_BUFFER_BIT); + int x,y,i; + unsigned char *d=ImageData; + int dstride=BYTES_PP*image_width; + + GetRelativeTime(); + + // generate some image: + for(y=0;y<image_height;y++){ + int y1=2048*sin(akarmi*0.36725+y*0.0165); + int y2=2048*sin(akarmi*0.45621+y*0.02753); + int y3=2048*sin(akarmi*0.15643+y*0.03732); + for(x=0;x<image_width;x++){ + d[0]=sintable[(y1+x*135)&4095]; + d[1]=sintable[(y2+x*62)&4095]; + d[2]=sintable[(y3+x*23)&4095]; + d+=BYTES_PP; + } + } + + gen_time+=GetRelativeTime(); + +#ifdef FAST_BLIT + // upload texture: + for(i=0;i<image_height;i++){ + glTexSubImage2D( GL_TEXTURE_2D, // target + 0, // level + 0, // x offset + i, // y offset + image_width, // width + 1, // height + (BYTES_PP==4)?GL_RGBA:GL_RGB, // format + GL_UNSIGNED_BYTE, // type + ImageData+i*dstride ); // *pixels + } +#else + glTexSubImage2D( GL_TEXTURE_2D, // target + 0, // level + 0, // x offset + 0, // y offset + image_width, // width + image_height, // height + (BYTES_PP==4)?GL_RGBA:GL_RGB, // format + GL_UNSIGNED_BYTE, // type + ImageData ); // *pixels +#endif + + up_time+=GetRelativeTime(); + + glColor3f(1,1,1); + glBegin(GL_QUADS); + glTexCoord2f(0,0);glVertex2i(0,0); + glTexCoord2f(0,1);glVertex2i(0,texture_height); + glTexCoord2f(1,1);glVertex2i(texture_width,texture_height); + glTexCoord2f(1,0);glVertex2i(texture_width,0); + glEnd(); + + glFinish(); + glutSwapBuffers(); + + render_time+=GetRelativeTime(); + + ++counter; + { float total=gen_time+up_time+render_time; + if(total>2.0){ + printf("%8.3f fps (gen: %2d%% upload: %2d%% render: %2d%%)\n", + (float)counter/total, + (int)(100.0*gen_time/total), + (int)(100.0*up_time/total), + (int)(100.0*render_time/total) + ); + gen_time=up_time=render_time=0; + counter=0; + } } + +} + +static GLvoid IdleFunc(){ + akarmi+=0.1; + glutPostRedisplay(); +} + +int +main(int argc, char **argv) +{ + int i; + + glutInit(&argc, argv); + glutInitWindowSize(640, 480); + glutInitDisplayMode(GLUT_DOUBLE); + (void) glutCreateWindow("csg"); + + glutDisplayFunc(redraw); + glutReshapeFunc(resize); + glutIdleFunc(IdleFunc); + + texture_width=32; + while(texture_width<image_width) texture_width*=2; + while(texture_width<image_height) texture_width*=2; + texture_height=texture_width; + + image_bpp=8*BYTES_PP; + image_bytes=BYTES_PP; + + ImageData=malloc(texture_width*texture_height*image_bytes); + memset(ImageData,128,texture_width*texture_height*image_bytes); + + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); + glDisable(GL_CULL_FACE); + + glEnable(GL_TEXTURE_2D); + + printf("Creating %dx%d texture...\n",texture_width,texture_height); + +#if 1 +// glBindTexture(GL_TEXTURE_2D, texture_id); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); +#ifdef TEXTUREFORMAT_32BPP + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0, +#else + glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0, +#endif + (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData); +#endif + + resize(640,480); + + glClearColor( 1.0f,0.0f,1.0f,0.0f ); + glClear( GL_COLOR_BUFFER_BIT ); + + for(i=0;i<4096;i++) sintable[i]=128+127*sin(2.0*3.14159265*i/4096.0); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +}