PDA

View Full Version : Compressing a texture that's already in VRAM



VelociChicken
12-06-2012, 11:04 AM
Hello, is it possible to compress a texture that's already in vram?

I'm creating textures using fractals so I have to render to them uncompressed, I then load them back into CPU memory, and then send them over again compressed.
Something like this:-

glGetTexImage(GL_TEXTURE_2D, 0, colour_format, colour_type, image);
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB, width, height, 0, colour_format, colour_type, image);

It seems like wasteful bandwidth to me, is there any other way of doing this without the transfer? I'm guessing not, but I'd like to be certain.

Thanks again,
Dave.

VelociChicken
12-07-2012, 10:03 AM
Hello, is it possible to compress a texture that's already in vram?

I'm creating textures using fractals so I have to render to them uncompressed, I then load them back into CPU memory, and then send them over again compressed.
Something like this:-

glGetTexImage(GL_TEXTURE_2D, 0, colour_format, colour_type, image);
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB, width, height, 0, colour_format, colour_type, image);

It seems like wasteful bandwidth to me, is there any other way of doing this without the transfer? I'm guessing not, but I'd like to be certain.

Thanks again,
Dave.

OK I got a great reply from the comp.graphics.api.opengl newsgroup:-

GLuint buf;
glGenBuffers(1, &buf);
glBindBuffer(GL_PIXEL_PACK_BUFFER, buf);
glBufferData(GL_PIXEL_PACK_BUFFER, width * height * bytes_per_pixel,
(const GLvoid*)0, GL_STREAM_COPY);
glGetTexImage(GL_TEXTURE_2D, 0, colour_format, colour_type, (GLvoid*)0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf);
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB, width, height, 0, colour_format, colour_type, (const GLvoid*)0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);