added parameter -copytest-loop
[test_compression] / main.c
diff --git a/main.c b/main.c
index a023307..dc9ca52 100644 (file)
--- a/main.c
+++ b/main.c
@@ -20,22 +20,45 @@ int texcomp(unsigned char *compix, unsigned int tofmt, unsigned char *pixels,
 void disp(void);
 void reshape(int x, int y);
 void keyb(unsigned char key, int x, int y);
+void idle();
 void gen_image(unsigned char *pixels, int xsz, int ysz);
 unsigned char *load_compressed_image(const char *fname, int *cszptr, int *xszptr, int *yszptr);
 int dump_compressed_image(const char *fname, unsigned char *data, int size, int w, int h);
 void print_compressed_formats(void);
 
-unsigned int tex, comp_tex;
+unsigned int tex, tex2, comp_tex;
 const char *texfile;
+int subtest, copytest, loop;
 
 int main(int argc, char **argv)
 {
+       int i;
        unsigned int glut_flags = GLUT_RGB | GLUT_DOUBLE;
 #ifdef USE_SRGB
        glut_flags |= GLUT_SRGB;
 #endif
 
-       texfile = argv[1];
+       for(i=1; i<argc; i++) {
+               if(argv[i][0] == '-') {
+                       if(strcmp(argv[i], "-subtest") == 0) {
+                               subtest = 1;
+                       } else if(strcmp(argv[i], "-copytest") == 0) {
+                               copytest = 1;
+                       } else if(strcmp(argv[i], "-copytest-loop") == 0) {
+                               copytest = 1;
+                               loop = 1;
+                       } else {
+                               fprintf(stderr, "invalid option: %s\n", argv[i]);
+                               return 1;
+                       }
+               } else {
+                       if(texfile) {
+                               fprintf(stderr, "unexpected argument: %s\n", argv[i]);
+                               return 1;
+                       }
+                       texfile = argv[i];
+               }
+       }
 
        glutInit(&argc, argv);
        glutInitWindowSize(800, 600);
@@ -46,6 +69,9 @@ int main(int argc, char **argv)
        glutReshapeFunc(reshape);
        glutKeyboardFunc(keyb);
 
+       if (loop)
+               glutIdleFunc(idle);
+
        glewInit();
 
        if(init() == -1) {
@@ -120,6 +146,30 @@ int init(void)
        } else {
                printf("submitted and retrieved sizes match (%d bytes)\n", comp_size);
        }
+
+       if(subtest) {
+               printf("testing glGetCompressedTextureSubImage and glCompressedTexSubImage2D\n");
+               memset(buf, 0, comp_size);
+               glGetCompressedTextureSubImage(tex, 0, 192, 64, 0, 64, 64, 1, comp_size, buf);
+               glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 32, 32, 64, 64, COMP_FMT, 2048, buf);
+       }
+
+       if(copytest) {
+               printf("testing glCopyImageSubData\n");
+
+               glGenTextures(1, &tex2);
+               glBindTexture(GL_TEXTURE_2D, tex2);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+               glCompressedTexImage2D(GL_TEXTURE_2D, 0, COMP_FMT, xsz, ysz, 0, comp_size, pixels);
+               glBindTexture(GL_TEXTURE_2D, 0);
+
+               glCopyImageSubData(tex2, GL_TEXTURE_2D, 0, 128, 64, 0,
+                               tex, GL_TEXTURE_2D, 0, 32, 32, 0, 64, 64, 1);
+
+               glBindTexture(GL_TEXTURE_2D, tex);
+       }
+
        free(buf);
        free(pixels);
 
@@ -189,6 +239,11 @@ void keyb(unsigned char key, int x, int y)
        }
 }
 
+void idle()
+{
+       glutPostRedisplay();
+}
+
 void gen_image(unsigned char *pixels, int xsz, int ysz)
 {
        int i, j;
@@ -356,11 +411,10 @@ void print_compressed_formats(void)
        glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, fmtlist);
 
        for(i=0; i<num_fmt; i++) {
-               printf("\n");
-               printf(" %05x: %s\n", fmtlist[i], fmtstr(fmtlist[i]));
+               printf(" %05x: %s ", fmtlist[i], fmtstr(fmtlist[i]));
                GLint params;
                glGetInternalformativ(GL_TEXTURE_2D, fmtlist[i], GL_TEXTURE_COMPRESSED, 1, &params);
-               printf("the format is %s\n", params == GL_TRUE ? "compressed" : "not compressed");
+               printf("(%s format)\n", params == GL_TRUE ? "compressed" : "not compressed");
        }
        free(fmtlist);
 }