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;
111 PrintString(const char *s
)
114 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
121 MakeTexture(const struct pixel_format
*format
, GLenum intFormat
, GLboolean swap
)
123 GLubyte texBuffer
[1000];
126 glPixelStorei(GL_UNPACK_SWAP_BYTES
, swap
);
128 if (format
->bytes
== 1) {
129 for (i
= 0; i
< 8; i
++) {
130 texBuffer
[i
] = format
->redTexel
;
132 for (i
= 8; i
< 16; i
++) {
133 texBuffer
[i
] = format
->greenTexel
;
136 else if (format
->bytes
== 2) {
137 GLushort
*us
= (GLushort
*) texBuffer
;
138 for (i
= 0; i
< 8; i
++) {
139 us
[i
] = format
->redTexel
;
141 for (i
= 8; i
< 16; i
++) {
142 us
[i
] = format
->greenTexel
;
145 for (i
= 0; i
< 16; i
++)
146 us
[i
] = (us
[i
] << 8) | (us
[i
] >> 8);
149 else if (format
->bytes
== 4) {
150 GLuint
*ui
= (GLuint
*) texBuffer
;
151 for (i
= 0; i
< 8; i
++) {
152 ui
[i
] = format
->redTexel
;
154 for (i
= 8; i
< 16; i
++) {
155 ui
[i
] = format
->greenTexel
;
158 for (i
= 0; i
< 16; i
++) {
161 | ((b
>> 8) & 0xff00)
162 | ((b
<< 8) & 0xff0000)
163 | ((b
<< 24) & 0xff000000);
170 glTexImage2D(GL_TEXTURE_2D
, 0, intFormat
, 4, 4, 0,
171 format
->format
, format
->type
, texBuffer
);
174 printf("GL Error for %s\n", format
->name
);
175 memset(texBuffer
, 255, 1000);
176 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 4, 4, 0,
177 GL_RGB
, GL_UNSIGNED_BYTE
, texBuffer
);
190 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
192 for (swap
= 0; swap
< 2; swap
++) {
193 for (i
= 0; Formats
[i
].name
; i
++) {
195 glTranslatef(swap
* (w
+ 2), i
* (h
+ 2), 0);
197 MakeTexture(Formats
+ i
, IntFormats
[CurFormat
].format
, swap
);
199 glEnable(GL_TEXTURE_2D
);
201 glTexCoord2f(0, 0); glVertex2f(0, 0);
202 glTexCoord2f(1, 0); glVertex2f(w
, 0);
203 glTexCoord2f(1, 1); glVertex2f(w
, h
);
204 glTexCoord2f(0, 1); glVertex2f(0, h
);
207 glDisable(GL_TEXTURE_2D
);
210 PrintString(Formats
[i
].name
);
217 glTranslatef(2, i
* (h
+ 2), 0);
220 PrintString("Normal");
221 glRasterPos2i(w
+ 2, 6);
222 PrintString("Byte Swapped");
226 glTranslatef(2, (i
+ 1) * (h
+ 2), 0);
228 sprintf(s
, "Internal Texture Format [f/F]: %s (%d of %d)",
229 IntFormats
[CurFormat
].name
, CurFormat
+ 1, NUM_INT_FORMATS
);
238 Reshape(int width
, int height
)
240 glViewport(0, 0, width
, height
);
241 glMatrixMode(GL_PROJECTION
);
243 glOrtho(0, width
, 0, height
, -1, 1);
244 glMatrixMode(GL_MODELVIEW
);
250 Key(unsigned char key
, int x
, int y
)
257 CurFormat
= NUM_INT_FORMATS
- 1;
263 if (CurFormat
== NUM_INT_FORMATS
)
277 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
278 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
279 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
280 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
281 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
286 main(int argc
, char *argv
[])
288 glutInit(&argc
, argv
);
289 glutInitWindowPosition(0, 0);
290 glutInitWindowSize(700, 800);
291 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
292 glutCreateWindow(argv
[0]);
293 glutReshapeFunc(Reshape
);
294 glutKeyboardFunc(Key
);
295 glutDisplayFunc(Draw
);