annotate TOOLS/GL-test/gltest.c @ 7426:d4aee62822b1

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