Mercurial > mplayer.hg
comparison TOOLS/GL-test/gltest.c @ 1:3b5f5d1c5041
Initial revision
author | arpi_esp |
---|---|
date | Sat, 24 Feb 2001 20:28:24 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:c1bb2c071d63 | 1:3b5f5d1c5041 |
---|---|
1 // OpenGL glTexSubImage() test/benchmark prg (C) 2001. by A'rpi/ESP-team | |
2 | |
3 #include <GL/glut.h> | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <math.h> | |
7 #include <inttypes.h> | |
8 | |
9 // pixel size: 3 or 4 | |
10 #define BYTES_PP 3 | |
11 | |
12 // blit by lines (defined) or frames (not defined) | |
13 #define FAST_BLIT | |
14 | |
15 static uint32_t image_width=720; // DVD size | |
16 static uint32_t image_height=576; | |
17 | |
18 static uint32_t image_format; | |
19 static uint32_t image_bpp; | |
20 static uint32_t image_bytes; | |
21 | |
22 static uint32_t texture_width=512; | |
23 static uint32_t texture_height=512; | |
24 | |
25 static unsigned char *ImageData=NULL; | |
26 | |
27 static GLvoid resize(int x,int y){ | |
28 printf("Resize: %dx%d\n",x,y); | |
29 glViewport( 0, 0, x, y ); | |
30 | |
31 glMatrixMode(GL_PROJECTION); | |
32 glLoadIdentity(); | |
33 glOrtho(0, image_width, image_height, 0, -1,1); | |
34 | |
35 glMatrixMode(GL_MODELVIEW); | |
36 glLoadIdentity(); | |
37 } | |
38 | |
39 float akarmi=0; | |
40 | |
41 int counter=0; | |
42 float gen_time=0; | |
43 float up_time=0; | |
44 float render_time=0; | |
45 | |
46 unsigned char sintable[4096]; | |
47 | |
48 extern float GetRelativeTime(); | |
49 | |
50 static void redraw(void) | |
51 { | |
52 // glClear(GL_COLOR_BUFFER_BIT); | |
53 int x,y,i; | |
54 unsigned char *d=ImageData; | |
55 int dstride=BYTES_PP*image_width; | |
56 | |
57 GetRelativeTime(); | |
58 | |
59 // generate some image: | |
60 for(y=0;y<image_height;y++){ | |
61 int y1=2048*sin(akarmi*0.36725+y*0.0165); | |
62 int y2=2048*sin(akarmi*0.45621+y*0.02753); | |
63 int y3=2048*sin(akarmi*0.15643+y*0.03732); | |
64 for(x=0;x<image_width;x++){ | |
65 d[0]=sintable[(y1+x*135)&4095]; | |
66 d[1]=sintable[(y2+x*62)&4095]; | |
67 d[2]=sintable[(y3+x*23)&4095]; | |
68 d+=BYTES_PP; | |
69 } | |
70 } | |
71 | |
72 gen_time+=GetRelativeTime(); | |
73 | |
74 #ifdef FAST_BLIT | |
75 // upload texture: | |
76 for(i=0;i<image_height;i++){ | |
77 glTexSubImage2D( GL_TEXTURE_2D, // target | |
78 0, // level | |
79 0, // x offset | |
80 i, // y offset | |
81 image_width, // width | |
82 1, // height | |
83 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format | |
84 GL_UNSIGNED_BYTE, // type | |
85 ImageData+i*dstride ); // *pixels | |
86 } | |
87 #else | |
88 glTexSubImage2D( GL_TEXTURE_2D, // target | |
89 0, // level | |
90 0, // x offset | |
91 0, // y offset | |
92 image_width, // width | |
93 image_height, // height | |
94 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format | |
95 GL_UNSIGNED_BYTE, // type | |
96 ImageData ); // *pixels | |
97 #endif | |
98 | |
99 up_time+=GetRelativeTime(); | |
100 | |
101 glColor3f(1,1,1); | |
102 glBegin(GL_QUADS); | |
103 glTexCoord2f(0,0);glVertex2i(0,0); | |
104 glTexCoord2f(0,1);glVertex2i(0,texture_height); | |
105 glTexCoord2f(1,1);glVertex2i(texture_width,texture_height); | |
106 glTexCoord2f(1,0);glVertex2i(texture_width,0); | |
107 glEnd(); | |
108 | |
109 glFinish(); | |
110 glutSwapBuffers(); | |
111 | |
112 render_time+=GetRelativeTime(); | |
113 | |
114 ++counter; | |
115 { float total=gen_time+up_time+render_time; | |
116 if(total>2.0){ | |
117 printf("%8.3f fps (gen: %2d%% upload: %2d%% render: %2d%%)\n", | |
118 (float)counter/total, | |
119 (int)(100.0*gen_time/total), | |
120 (int)(100.0*up_time/total), | |
121 (int)(100.0*render_time/total) | |
122 ); | |
123 gen_time=up_time=render_time=0; | |
124 counter=0; | |
125 } } | |
126 | |
127 } | |
128 | |
129 static GLvoid IdleFunc(){ | |
130 akarmi+=0.1; | |
131 glutPostRedisplay(); | |
132 } | |
133 | |
134 int | |
135 main(int argc, char **argv) | |
136 { | |
137 int i; | |
138 | |
139 glutInit(&argc, argv); | |
140 glutInitWindowSize(640, 480); | |
141 glutInitDisplayMode(GLUT_DOUBLE); | |
142 (void) glutCreateWindow("csg"); | |
143 | |
144 glutDisplayFunc(redraw); | |
145 glutReshapeFunc(resize); | |
146 glutIdleFunc(IdleFunc); | |
147 | |
148 texture_width=32; | |
149 while(texture_width<image_width) texture_width*=2; | |
150 while(texture_width<image_height) texture_width*=2; | |
151 texture_height=texture_width; | |
152 | |
153 image_bpp=8*BYTES_PP; | |
154 image_bytes=BYTES_PP; | |
155 | |
156 ImageData=malloc(texture_width*texture_height*image_bytes); | |
157 memset(ImageData,128,texture_width*texture_height*image_bytes); | |
158 | |
159 glDisable(GL_BLEND); | |
160 glDisable(GL_DEPTH_TEST); | |
161 glDepthMask(GL_FALSE); | |
162 glDisable(GL_CULL_FACE); | |
163 | |
164 glEnable(GL_TEXTURE_2D); | |
165 | |
166 printf("Creating %dx%d texture...\n",texture_width,texture_height); | |
167 | |
168 #if 1 | |
169 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
170 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
171 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
172 #ifdef TEXTUREFORMAT_32BPP | |
173 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0, | |
174 #else | |
175 glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0, | |
176 #endif | |
177 (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData); | |
178 #endif | |
179 | |
180 resize(640,480); | |
181 | |
182 glClearColor( 1.0f,0.0f,1.0f,0.0f ); | |
183 glClear( GL_COLOR_BUFFER_BIT ); | |
184 | |
185 for(i=0;i<4096;i++) sintable[i]=128+127*sin(2.0*3.14159265*i/4096.0); | |
186 | |
187 glutMainLoop(); | |
188 return 0; /* ANSI C requires main to return int. */ | |
189 } |