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);