2 * Test packed pixel formats for textures.
19 GLuint redTexel
, greenTexel
;
22 static const struct pixel_format Formats
[] = {
24 { "GL_RGBA/GL_UNSIGNED_INT_8_8_8_8",
25 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, 4, 0xff000000, 0x00ff0000 },
26 { "GL_RGBA/GL_UNSIGNED_INT_8_8_8_8_REV",
27 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4, 0x000000ff, 0x0000ff00 },
28 { "GL_RGBA/GL_UNSIGNED_INT_10_10_10_2",
29 GL_RGBA
, GL_UNSIGNED_INT_10_10_10_2
, 4, 0xffc00000, 0x3ff000 },
30 { "GL_RGBA/GL_UNSIGNED_INT_2_10_10_10_REV",
31 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 4, 0x3ff, 0xffc00 },
32 { "GL_RGBA/GL_UNSIGNED_SHORT_4_4_4_4",
33 GL_RGBA
, GL_UNSIGNED_SHORT_4_4_4_4
, 2, 0xf000, 0x0f00 },
34 { "GL_RGBA/GL_UNSIGNED_SHORT_4_4_4_4_REV",
35 GL_RGBA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 2, 0x000f, 0x00f0 },
36 { "GL_RGBA/GL_UNSIGNED_SHORT_5_5_5_1",
37 GL_RGBA
, GL_UNSIGNED_SHORT_5_5_5_1
, 2, 0xf800, 0x7c0 },
38 { "GL_RGBA/GL_UNSIGNED_SHORT_1_5_5_5_REV",
39 GL_RGBA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 2, 0x1f, 0x3e0 },
41 { "GL_BGRA/GL_UNSIGNED_INT_8_8_8_8",
42 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8
, 4, 0x0000ff00, 0x00ff0000 },
43 { "GL_BGRA/GL_UNSIGNED_INT_8_8_8_8_REV",
44 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4, 0x00ff0000, 0x0000ff00 },
45 { "GL_BGRA/GL_UNSIGNED_SHORT_4_4_4_4",
46 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4
, 2, 0x00f0, 0x0f00 },
47 { "GL_BGRA/GL_UNSIGNED_SHORT_4_4_4_4_REV",
48 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 2, 0x0f00, 0x00f0 },
49 { "GL_BGRA/GL_UNSIGNED_SHORT_5_5_5_1",
50 GL_BGRA
, GL_UNSIGNED_SHORT_5_5_5_1
, 2, 0x3e, 0x7c0 },
51 { "GL_BGRA/GL_UNSIGNED_SHORT_1_5_5_5_REV",
52 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 2, 0x7c00, 0x3e0 },
54 { "GL_ABGR_EXT/GL_UNSIGNED_INT_8_8_8_8",
55 GL_ABGR_EXT
, GL_UNSIGNED_INT_8_8_8_8
, 4, 0x000000ff, 0x0000ff00 },
56 { "GL_ABGR_EXT/GL_UNSIGNED_INT_8_8_8_8_REV",
57 GL_ABGR_EXT
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4, 0xff000000, 0x00ff0000 },
58 { "GL_ABGR_EXT/GL_UNSIGNED_SHORT_4_4_4_4",
59 GL_ABGR_EXT
, GL_UNSIGNED_SHORT_4_4_4_4
, 2, 0x000f, 0x00f0 },
60 { "GL_ABGR_EXT/GL_UNSIGNED_SHORT_4_4_4_4_REV",
61 GL_ABGR_EXT
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 2, 0xf000, 0x0f00 },
62 { "GL_ABGR_EXT/GL_UNSIGNED_SHORT_5_5_5_1",
63 GL_ABGR_EXT
, GL_UNSIGNED_SHORT_5_5_5_1
, 2, 0x1, 0x3e },
64 { "GL_ABGR_EXT/GL_UNSIGNED_SHORT_1_5_5_5_REV",
65 GL_ABGR_EXT
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 2, 0x8000, 0x7c00 },
67 { "GL_RGB/GL_UNSIGNED_SHORT_5_6_5",
68 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2, 0xf800, 0x7e0 },
69 { "GL_RGB/GL_UNSIGNED_SHORT_5_6_5_REV",
70 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5_REV
, 2, 0x1f, 0x7e0 },
71 { "GL_RGB/GL_UNSIGNED_BYTE_3_3_2",
72 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 1, 0xe0, 0x1c },
73 { "GL_RGB/GL_UNSIGNED_BYTE_2_3_3_REV",
74 GL_RGB
, GL_UNSIGNED_BYTE_2_3_3_REV
, 1, 0x7, 0x38 },
76 { NULL
, 0, 0, 0, 0, 0 }
85 static const struct name_format IntFormats
[] = {
86 { "GL_RGBA", GL_RGBA
},
87 { "GL_RGBA2", GL_RGBA2
},
88 { "GL_RGBA4", GL_RGBA4
},
89 { "GL_RGB5_A1", GL_RGB5_A1
},
90 { "GL_RGBA8", GL_RGBA8
},
91 { "GL_RGBA12", GL_RGBA12
},
92 { "GL_RGBA16", GL_RGBA16
},
93 { "GL_RGB10_A2", GL_RGB10_A2
},
96 { "GL_R3_G3_B2", GL_R3_G3_B2
},
97 { "GL_RGB4", GL_RGB4
},
98 { "GL_RGB5", GL_RGB5
},
99 { "GL_RGB8", GL_RGB8
},
100 { "GL_RGB10", GL_RGB10
},
101 { "GL_RGB12", GL_RGB12
},
102 { "GL_RGB16", GL_RGB16
},
106 #define NUM_INT_FORMATS (sizeof(IntFormats) / sizeof(IntFormats[0]))
107 static GLuint CurFormat
= 0;
109 static GLboolean Test3D
= GL_FALSE
;
114 PrintString(const char *s
)
117 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
124 MakeTexture(const struct pixel_format
*format
, GLenum intFormat
, GLboolean swap
)
126 GLubyte texBuffer
[1000];
129 glPixelStorei(GL_UNPACK_SWAP_BYTES
, swap
);
131 if (format
->bytes
== 1) {
132 for (i
= 0; i
< 8; i
++) {
133 texBuffer
[i
] = format
->redTexel
;
135 for (i
= 8; i
< 16; i
++) {
136 texBuffer
[i
] = format
->greenTexel
;
139 else if (format
->bytes
== 2) {
140 GLushort
*us
= (GLushort
*) texBuffer
;
141 for (i
= 0; i
< 8; i
++) {
142 us
[i
] = format
->redTexel
;
144 for (i
= 8; i
< 16; i
++) {
145 us
[i
] = format
->greenTexel
;
148 for (i
= 0; i
< 16; i
++)
149 us
[i
] = (us
[i
] << 8) | (us
[i
] >> 8);
152 else if (format
->bytes
== 4) {
153 GLuint
*ui
= (GLuint
*) texBuffer
;
154 for (i
= 0; i
< 8; i
++) {
155 ui
[i
] = format
->redTexel
;
157 for (i
= 8; i
< 16; i
++) {
158 ui
[i
] = format
->greenTexel
;
161 for (i
= 0; i
< 16; i
++) {
164 | ((b
>> 8) & 0xff00)
165 | ((b
<< 8) & 0xff0000)
166 | ((b
<< 24) & 0xff000000);
175 /* 4 x 4 x 4 texture, undefined data */
176 glTexImage3D(GL_TEXTURE_3D
, 0, intFormat
, 4, 4, 4, 0,
177 format
->format
, format
->type
, NULL
);
178 /* fill in Z=1 and Z=2 slices with the real texture data */
179 glTexSubImage3D(GL_TEXTURE_3D
, 0,
180 0, 0, 1, /* offset */
182 format
->format
, format
->type
, texBuffer
);
183 glTexSubImage3D(GL_TEXTURE_3D
, 0,
184 0, 0, 2, /* offset */
186 format
->format
, format
->type
, texBuffer
);
189 glTexImage2D(GL_TEXTURE_2D
, 0, intFormat
, 4, 4, 0,
190 format
->format
, format
->type
, texBuffer
);
194 printf("GL Error for %s\n", format
->name
);
195 memset(texBuffer
, 255, 1000);
196 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 4, 4, 0,
197 GL_RGB
, GL_UNSIGNED_BYTE
, texBuffer
);
210 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
212 for (swap
= 0; swap
< 2; swap
++) {
213 for (i
= 0; Formats
[i
].name
; i
++) {
215 glTranslatef(swap
* (w
+ 2), i
* (h
+ 2), 0);
217 MakeTexture(Formats
+ i
, IntFormats
[CurFormat
].format
, swap
);
220 glEnable(GL_TEXTURE_3D
);
222 glEnable(GL_TEXTURE_2D
);
224 glTexCoord3f(0, 0, 0.5); glVertex2f(0, 0);
225 glTexCoord3f(1, 0, 0.5); glVertex2f(w
, 0);
226 glTexCoord3f(1, 1, 0.5); glVertex2f(w
, h
);
227 glTexCoord3f(0, 1, 0.5); glVertex2f(0, h
);
231 glDisable(GL_TEXTURE_3D
);
233 glDisable(GL_TEXTURE_2D
);
236 PrintString(Formats
[i
].name
);
243 glTranslatef(2, i
* (h
+ 2), 0);
246 PrintString("Normal");
247 glRasterPos2i(w
+ 2, 6);
248 PrintString("Byte Swapped");
252 glTranslatef(2, (i
+ 1) * (h
+ 2), 0);
254 sprintf(s
, "Internal Texture Format [f/F]: %s (%d of %d)",
255 IntFormats
[CurFormat
].name
, CurFormat
+ 1, NUM_INT_FORMATS
);
260 glTranslatef(2, (i
+ 2) * (h
+ 2), 0);
263 PrintString("Target [2/3]: GL_TEXTURE_3D");
265 PrintString("Target [2/3]: GL_TEXTURE_2D");
273 Reshape(int width
, int height
)
275 glViewport(0, 0, width
, height
);
276 glMatrixMode(GL_PROJECTION
);
278 glOrtho(0, width
, 0, height
, -1, 1);
279 glMatrixMode(GL_MODELVIEW
);
285 Key(unsigned char key
, int x
, int y
)
292 CurFormat
= NUM_INT_FORMATS
- 1;
298 if (CurFormat
== NUM_INT_FORMATS
)
318 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
319 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
320 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
321 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
322 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
323 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
324 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
329 main(int argc
, char *argv
[])
331 glutInit(&argc
, argv
);
332 glutInitWindowPosition(0, 0);
333 glutInitWindowSize(700, 800);
334 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
335 glutCreateWindow(argv
[0]);
336 glutReshapeFunc(Reshape
);
337 glutKeyboardFunc(Key
);
338 glutDisplayFunc(Draw
);