summaryrefslogtreecommitdiffstats
path: root/progs/demos/textures.c
diff options
context:
space:
mode:
authorYounes Manton <[email protected]>2010-04-30 20:42:30 -0400
committerYounes Manton <[email protected]>2010-04-30 20:42:30 -0400
commita8ea1dacc63ac567498049e5756c247b9fec6cd9 (patch)
tree4031e2e2b6166bd926b43fa4bbb3aab773a30ee5 /progs/demos/textures.c
parent404fb63b4649f58fce443615e49337d42b8ddece (diff)
parent35d960cc744c374ccaad48c3d80559b59c74e28a (diff)
Merge branch 'master' of ssh://git.freedesktop.org/git/mesa/mesa into pipe-video
Conflicts: src/gallium/auxiliary/Makefile src/gallium/auxiliary/SConscript src/gallium/auxiliary/util/u_format.csv src/gallium/auxiliary/vl/vl_compositor.c src/gallium/auxiliary/vl/vl_compositor.h src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h src/gallium/drivers/identity/id_objects.c src/gallium/drivers/identity/id_objects.h src/gallium/drivers/identity/id_screen.c src/gallium/drivers/nv40/Makefile src/gallium/drivers/nv40/nv40_screen.c src/gallium/drivers/softpipe/sp_texture.c src/gallium/drivers/softpipe/sp_texture.h src/gallium/drivers/softpipe/sp_video_context.c src/gallium/drivers/softpipe/sp_video_context.h src/gallium/include/pipe/p_format.h src/gallium/include/pipe/p_screen.h src/gallium/include/pipe/p_video_context.h src/gallium/include/pipe/p_video_state.h src/gallium/include/state_tracker/dri1_api.h src/gallium/include/state_tracker/drm_api.h src/gallium/state_trackers/dri/common/dri_context.c src/gallium/state_trackers/xorg/xvmc/attributes.c src/gallium/state_trackers/xorg/xvmc/block.c src/gallium/state_trackers/xorg/xvmc/context.c src/gallium/state_trackers/xorg/xvmc/subpicture.c src/gallium/state_trackers/xorg/xvmc/surface.c src/gallium/state_trackers/xorg/xvmc/tests/.gitignore src/gallium/state_trackers/xorg/xvmc/tests/Makefile src/gallium/state_trackers/xorg/xvmc/xvmc_private.h src/gallium/winsys/drm/radeon/core/radeon_drm.c src/gallium/winsys/g3dvl/vl_winsys.h src/gallium/winsys/g3dvl/xlib/xsp_winsys.c src/gallium/winsys/sw/Makefile
Diffstat (limited to 'progs/demos/textures.c')
-rw-r--r--progs/demos/textures.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/progs/demos/textures.c b/progs/demos/textures.c
index 1415ef1c43c..b668995aac1 100644
--- a/progs/demos/textures.c
+++ b/progs/demos/textures.c
@@ -6,11 +6,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
+#include <GL/glew.h>
#include <GL/glut.h>
#include "readtex.h"
#define TEST_CLAMP 0
#define TEST_MIPMAPS 0
+#define TEST_GEN_COMPRESSED_MIPMAPS 0
#define MAX_TEXTURES 8
@@ -304,6 +306,69 @@ LoadTextures(GLuint n, const char *files[])
GL_RGBA, GL_UNSIGNED_BYTE, image);
}
}
+#elif TEST_GEN_COMPRESSED_MIPMAPS
+ {
+ GLenum intFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
+ int f;
+ GLenum format;
+ GLubyte *img = LoadRGBImage(files[i], &w, &h, &format);
+ GLboolean write_compressed = GL_FALSE;
+ GLboolean read_compressed = GL_FALSE;
+
+ glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
+ glTexImage2D(GL_TEXTURE_2D, 0, intFormat, w, h, 0,
+ format, GL_UNSIGNED_BYTE, img);
+ glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
+ free(img);
+
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, i,
+ GL_TEXTURE_INTERNAL_FORMAT, &f);
+ printf("actual internal format 0x%x\n", f);
+
+ if (write_compressed) {
+ GLint i, sz, w, h;
+ int num_levels = 8;
+ for (i = 0; i < num_levels; i++) {
+ char name[20], *buf;
+ FILE *f;
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w);
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h);
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, i,
+ GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sz);
+ printf("Writing level %d: %d x %d bytes: %d\n", i, w, h, sz);
+ buf = malloc(sz);
+ glGetCompressedTexImageARB(GL_TEXTURE_2D, i, buf);
+ sprintf(name, "comp%d", i);
+ f = fopen(name, "w");
+ fwrite(buf, 1, sz, f);
+ fclose(f);
+ free(buf);
+ }
+ }
+
+ if (read_compressed) {
+ GLint i, sz, w, h;
+ int num_levels = 8;
+ for (i = 01; i < num_levels; i++) {
+ char name[20], *buf;
+ FILE *f;
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w);
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h);
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, i,
+ GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sz);
+ buf = malloc(sz);
+ sprintf(name, "comp%d", i);
+ printf("Reading level %d: %d x %d bytes: %d from %s\n",
+ i, w, h, sz, name);
+ f = fopen(name, "r");
+ fread(buf, 1, sz, f);
+ fclose(f);
+ glCompressedTexImage2DARB(GL_TEXTURE_2D, i, intFormat,
+ w, h, 0, sz, buf);
+ free(buf);
+ }
+ }
+ }
#else
if (!LoadRGBMipmaps2(files[i], GL_TEXTURE_2D, GL_RGB, &w, &h)) {
printf("Error: couldn't load %s\n", files[i]);
@@ -360,6 +425,7 @@ main(int argc, char *argv[])
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
Win = glutCreateWindow(argv[0]);
+ glewInit();
glutReshapeFunc(Reshape);
glutKeyboardFunc(Key);
glutSpecialFunc(SpecialKey);