PolarWolf
PolarWolf

Reputation: 49

is it possible to partial update pvrtc texture

I created a 1024*1024 texture with

glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 1024, 1024, 0, nDataLen*4, pData1);

then update it's first 512*512 part like this

glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 512, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, nDataLen, pData2);

This update generated glerror 1282(invalid operation), if I update the whole 1024*1024 region all are ok, it seems that pvrtc texture cannot be partial updated.

Is it possible to partial update pvrtc textur, if it is how how?

Upvotes: 2

Views: 315

Answers (3)

Simon F
Simon F

Reputation: 1055

Rightly or wrongly, the reason PVRTC1 does not have CompressedTexSubImage2D support is that unlike, say, ETC* or S3TC, the texture data is not compressed as independent 4x4 squares of texels which, in turn, get represented as either 64 or 128 bits of data depending on the format. With ETC*/S3TC any aligned 4x4 block of texels can be replaced without affecting any other region of the texture simply by just replacing its corresponding 64- or 128-bit data block.

With PVRTC1, two aims were to avoid block artifacts and to take advantage of the fact that neighbouring areas are usually very similar and thus can share information. Although the compressed data is grouped into 64-bit units, these affect overlapping areas of texels. In the case of 4bpp they are ~7x7 and for 2bpp, 15x7.

As you later point out, you could copy the data yourself but there may be a fuzzy boundary: For example, I took these 64x64 and 32x32 textures (which have been compressed and decompressed with PVRTC1 @4bpp ) ...

enter image description here + enter image description here

and then did the equivalent of "TexSubImage" to get:

enter image description here

As you should be able to see, the border of the smaller texture has smudged as the colour information is shared across the boundaries.

In practice it might not matter but since it doesn't strictly match the requirements of TexSubImage, it's not supported.

PVRTC2 has facilities to do better subimage replacement but is not exposed on at least one well-known platform.

< Unsubtle plug > BTW if you want some more info on texture compression, there is a thread on the Stack Exchange Computer Graphics site < /Unsubtle plug >

Upvotes: 1

PolarWolf
PolarWolf

Reputation: 49

Surprisingly, i copyed a small pvrtc texture data into a large one, it works just like glCompressedTexSubImage2D.But i'am not sure whether it's safe to use this solution in my engine.

Upvotes: 1

Columbo
Columbo

Reputation: 6776

Sounds to me like you can't on GLES2 (link to spec, see 3.7.3.)

Calling CompressedTexSubImage2D will result in an INVALID_OPERATION error if xoffset or yoffset is not equal to zero, or if width and height do not match the width and height of the texture, respectively. The contents of any texel outside the region modified by the call are undefined. These restrictions may be relaxed for specific compressed internal formats whose images are easily modified

Makes glCompressedTexSubImage2D sound a bit useless to me, tbh, but I guess it's for updating individual mips or texture array levels.

Upvotes: 1

Related Questions