PDA

View Full Version : Texture compression



Gremour
06-06-2007, 08:08 AM
I'm trying to compress a texture using OpenGL glTexImage2D function. Everything works fine under Windows, but under Linux compression just doesn't happen. I've made a simple test program to locate problem, here it is:


#define GLX_GLXEXT_PROTOTYPES

#include <GL/glx.h> // includes gl, glext
#include <GL/glu.h>
#include <stdio.h>
#include <string.h>

//----------------------------------------------------------------------------

int main (int argc, char *argv[])
{
int attributes[] =
{
GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_DEPTH_SIZE, 24,
0
};
Display *display = XOpenDisplay(NULL);
if (!display)
{
printf ("Cannot open display.\n");
return 1;
}
XVisualInfo *vinfo = glXChooseVisual(display, DefaultScreen(display), attributes);
if (!vinfo)
{
printf ("Cannot get visual.\n");
return 1;
}
GLXContext context = glXCreateContext(display, vinfo, 0, GL_TRUE);

XSetWindowAttributes winattrs;
winattrs.event_mask = 0;
winattrs.border_pixel = 0;
winattrs.bit_gravity = StaticGravity;
int winmask = CWBorderPixel | CWColormap | CWBitGravity | CWEventMask;

Window rw = DefaultRootWindow(display);
winattrs.colormap = XCreateColormap(display, rw, vinfo->visual, AllocNone);
Window window = XCreateWindow(display, rw,
0, 0, 100, 100, 0, vinfo->depth
,InputOutput
,vinfo->visual
,winmask
,&amp;winattrs);

glXMakeCurrent(display, window, context);


// -------------- Compressing texture here ----------------

unsigned char tx[] =
{
0x00, 0x00, 0xff, 0x00, 0xff, 0xff,
0xff, 0xff, 0x00, 0x00, 0xff, 0x00
};

// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_ARB, 2, 2,
0, GL_BGR_EXT, GL_UNSIGNED_BYTE, tx);

int compressed = -1;

glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &amp;compressed);

printf ("Compressed = %d\n", compressed);

// ---------------------------------------------------------

glXDestroyContext(display, context);
XCloseDisplay (display);

return 0;
}It prints "Compressed = 0" (analoguous code returns 1 in "compressed" variable under Windows).

Printed list of extensions, which contains GL_ARB_texture_compression. glTexImage2D produce "no error" code. Checked internal format of texture, it is equal to GL_COMPRESSED_RGB_ARB, yet GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB returns zero.

All other GL functions works fine.

Could anyone say what's happening, or at least point where to dig?

System: Fedora Core 6, gcc 4.1.1, Video Intel 945 (last drivers included in FC6, according to Intel)

Gremour
06-06-2007, 08:42 AM
Forgot to mention, glXCreateContext always prints a warning:

libGL warning: 3D driver claims to not support visual 0x5b

0x5b is visual type for 32 bit (TrueColor), and my desktop uses 24 bit (vinfo->visualid == 0x25).

Wonder, may it have any relevance.

ZbuffeR
06-06-2007, 09:01 AM
Maybe this is due to the patent on S3TC.
http://forum.worldwindcentral.com/showpo...20&postcount=16 (http://forum.worldwindcentral.com/showpost.php?s=5bc126e09127900bc6a436475804b39e&p=45020&postcount=16)

GL_ARB_texture_compression is not tied to a particular implementation, but the S3TC implementation is protected by a patent.

Check for the presence of GL_EXT_texture_compression_s3tc.

Gremour
06-07-2007, 01:48 AM
Thanks.

GL_EXT_texture_compression_s3tc wasn't in list of extensions under Linux. I've used driconf and enabled S3TC compression (even if software doesn't support it -- so it says) in driver (it was disabled). That extention now appears in list.

However, code above still do not work (returns 0 in compressed). :(

Tried it also on machine with ATI Radeon 9550, Fedora Core 6.

Gremour
06-07-2007, 03:31 AM
I've managed to make compression "work" by using GL_COMPRESSED_RGB_S3TC_DXT1_EXT instead of GL_COMPRESSED_RGB_ARB. However, I got another runtime warning:

Mesa 6.5.1 implementation error: external dxt library not available
Please report at bugzilla.freedesktop.org

And resulting compressed texture (it have normal size, 1/6 of uncompressed) is filled with zeroes.

I have bad feeling that GL libs on mys system is outdated (how come?!). Here's what I have in /usr/lib:

/usr/lib/libGL.so
/usr/lib/libGL.so.1.2
/usr/lib/libGLU.so.1
/usr/lib/libGL.so.1
/usr/lib/libGLU.so
/usr/lib/libGLU.so.1.3.060501

A hint how to get latest GL libs and install them would be greatly appreciated.

Thanks in advance.

P.S. System also has these libs:
/usr/lib/libdrm.so
/usr/lib/libdrm.so.2
/usr/lib/libdrm.so.2.0.0

And version string OpenGL returned:
Version: 1.3 Mesa 6.5.1

PkK
06-07-2007, 09:26 AM
Originally posted by Gremour:
Thanks.

GL_EXT_texture_compression_s3tc wasn't in list of extensions under Linux. I've used driconf and enabled S3TC compression (even if software doesn't support it -- so it says) in driver (it was disabled). That extention now appears in list.

However, code above still do not work (returns 0 in compressed). :(
That's normal: GL_EXT_texture_compression_s3tc was not in the extension string because it's not completely supported. The driconf option is an override to support software that needs S3TC, but not all of it. Decompression is often implemented in hardware and that's what most programs use.

PkK
06-07-2007, 09:31 AM
Originally posted by ZbuffeR:
Maybe this is due to the patent on S3TC.
It is due to the patent. if you don't care about it (or have a license or live somewhere where it's not patented like in the EU) just download the libdxtn from R. Scheidegger at http://homepage.hispeed.ch/rscheidegger/dri_experimental/s3tc_index.html ,install it and you'll get full S3TC support.

Philipp

Gremour
06-08-2007, 04:50 AM
I've ended up with precompressing textures under Windows.

Will take a look at the libtxc.

Thank you for your help.