#include #include #include #include #include #include #define ARRAY_SIZE(ary) (sizeof(ary) / sizeof((ary)[0])) static void test_r16(void) { GLushort buf[65536]; GLubyte without_pbo[65536], with_pbo[65536]; GLuint i; GLuint tex; GLuint pbo; float expected; GLuint expected_int; for (i = 0; i < ARRAY_SIZE(buf); i++) buf[i] = i; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, /* level */ GL_R16, 256, 256, /* width/height */ 0, /* border */ GL_RED, GL_UNSIGNED_SHORT, buf); glGetTexImage(GL_TEXTURE_2D, 0, /* level */ GL_RED, GL_UNSIGNED_BYTE, without_pbo); glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); glBufferData(GL_PIXEL_PACK_BUFFER, sizeof without_pbo, NULL, /* data */ GL_STATIC_READ); glGetTexImage(GL_TEXTURE_2D, 0, /* level */ GL_RED, GL_UNSIGNED_BYTE, NULL); glGetBufferSubData(GL_PIXEL_PACK_BUFFER, 0, /* offset */ sizeof with_pbo, with_pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glDeleteBuffers(1, &pbo); for (i = 0; i < ARRAY_SIZE(buf); i++) { expected = i * 255.0f / 65535.0f; expected_int = roundf(expected); if (expected_int != without_pbo[i] || expected_int != with_pbo[i]) { printf("source_value=%i float=%f expected=%i " "without_pbo=%i with_pbo=%i\n", i, expected, expected_int, without_pbo[i], with_pbo[i]); } } } int main(int argc, char **argv) { glutInit(&argc, argv); glutCreateWindow("GL_R16 to unsigned byte test"); test_r16(); return EXIT_SUCCESS; }