PDA

View Full Version : Problem with glCompressedTexImage3D....



th3w1zard
04-12-2011, 02:16 PM
hello everyone,

im having a problem with a compressed 3D texture in the format DXT5... the data uploaded to the graphics card seems to be ok but the final result is a bit "mad", let em show you a render of whats happening...

http://img690.imageshack.us/i/3dproblem.png/

now lets look at the code...im doing this for loading...




glGenTextures(1, &TextureID);
glEnable( GL_TEXTURE_3D );
glBindTexture( GL_TEXTURE_3D , TextureID);

glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER,GL_LINEAR );

glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER,GL_LINEAR );

glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);

glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);

glCompressedTexImage3DARB(GL_TEXTURE_3D, 0, format, width,
height, depth, 0, size, data);



the image is 256*256*256 , it doesnt have any mipmaps, just the textures, decompressing the image using a software it all seems good...but here is terrible...

any way the debug values are all good, but i canīt see whats wrong... am i missing something here? for sure.. but i donīt know what... help me... :\

one of the problems is that the texcoords are in 0-1 so i should see only a slice at the time, and im seeing 4*4 of each slice, and thatīs not good at all....

Alfonse Reinheart
04-12-2011, 02:38 PM
im having a problem with a compressed 3D texture in the format DXT5

I'm not sure such a thing (DXT5 on 3D textures) exists. Or that it is allowed by OpenGL.

The standard S3TC extension does not allow for compression on 3D textures. Only the NV_texture_compression_vtc does, which is an NVIDIA-only extension.

th3w1zard
04-12-2011, 02:52 PM
hello,

thanks for the answer... so taken from the spec... im pretty sure it works and is avaliable....and i have that extension as well, so quoting from the spec...




GL_NV_texture_compression_vtc

Overview

This extension adds support for the VTC 3D texture compression
formats, which are analogous to the S3TC texture compression formats,
with the addition of some retiling in the Z direction. VTC has the
same compression ratio as S3TC and uses 4x4x1, 4x4x2, or 4x4x4
blocks.



a bit more....


New Tokens

Accepted by the <internalformat> parameter of TexImage3D and
CompressedTexImage3DARB and the <format> parameter of
CompressedTexSubImage2DARB:

COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3



and the blocks




VTC Compressed Texture Image Formats

Each VTC compression format is similar to a corresponding S3TC
compression format, but where an S3TC block encodes a 4x4 block of
texels, a VTC block encodes a 4x4x1, 4x4x2, or 4x4x4 block of texels.
If the depth of the image is four or greater, 4x4x4 blocks are used,
and if the depth is 1 or 2, 4x4x1 or 4x4x2 blocks are used.




like they say its pretty equal to the standard S3TC compression, so it should be pretty straight forward, to use it...but some how, it gets a bit messes up...
the 2d cases work fine....so the 3D was just suposed to be a simple step...and it seems that it isnīt... :\

YarUnderoaker
04-13-2011, 06:38 AM
Unfortunately NV_texture_compression_vtc is can be turned off,
so you must shuffle blocks of image.

th3w1zard
04-14-2011, 02:14 AM
hello YarUnderoaker,

thanks for your answer, i think i know what you mean... iīll see if i can make it work.

Best Regards

YarUnderoaker
04-14-2011, 02:12 PM
My algo to do this



function blockOffset(x, y, z: Integer): Integer;
begin
if z >= (d and -4) then
Result := fElementSize * (cw * ch * (d and -4) + x + cw * (y + ch * (z - 4 * ch)))
else
Result := fElementSize * (4 * (x + cw * (y + ch * floor(z / 4))) + (z and 3));
if Result < 0 then
Result := 0;
end;
-----------------------------------------------------------------------
if NV_texture_compression_vtc then
begin
// Shufle blocks for Volume Texture Compression
if Assigned(p) then
begin
cw := (w + 3) div 4;
ch := (h + 3) div 4;
if Level = 0 then
GetMem(vtcBuffer, GetLevelSizeInByte(0));
top := p;
for k := 0 to d - 1 do
for i := 0 to ch - 1 do
for j := 0 to cw - 1 do
begin
bottom := vtcBuffer;
Inc(bottom, blockOffset(j, i, k));
Move(top^, bottom^, fElementSize);
Inc(top, fElementSize);
end;
end;
if EXT_direct_state_access then
CompressedTextureImage3D(glHandle, glTarget, Level, aTexFormat, w, h, d, 0, GetLevelSizeInByte(Level), vtcBuffer)
else
CompressedTexImage3D(glTarget, Level, aTexFormat, w, h, d, 0, GetLevelSizeInByte(Level), vtcBuffer);

Where
w, h, d - sizes of image
p - image address
fElementSize - 2D block size in byte