uploading textures with only certain components using glTexImage2D

Started by
12 comments, last by Majestik_666 17 years ago
Hi, for some image processing reasons, I need to upload "special" textures into the vid card ram to apply shaders and render. Those textures are stored in the cpu memory but they can contain a limited number of components , for example R , RB, GA, RGB, etc ... all the combinations of 1 to 4 channels. I've been looking at glTexImage2D to upload those textures onto the gpu ram, for 1 and 4 components it's quite easy and doesn't cause any problem, but my concern is for 2 or 3 channels, the formats offered by glTexImage2D are pretty limited and if I choose to use GL_LUMINANCE_ALPHA for a 2 components image, the channels won't be set properly .... anyone has done this kind of things before ? Thanks !
Advertisement
I would say there is quite a few formats to choose from

internalformat  Specifies the	number of color	components in			  the texture.	Must be	1, 2, 3, or 4, or one			  of the following symbolic constants:			  GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_ALPHA12,			  GL_ALPHA16, GL_LUMINANCE, GL_LUMINANCE4,			  GL_LUMINANCE8, GL_LUMINANCE12,			  GL_LUMINANCE16, GL_LUMINANCE_ALPHA,			  GL_LUMINANCE4_ALPHA4,	GL_LUMINANCE6_ALPHA2,			  GL_LUMINANCE8_ALPHA8,	GL_LUMINANCE12_ALPHA4,			  GL_LUMINANCE12_ALPHA12,			  GL_LUMINANCE16_ALPHA16, GL_INTENSITY,			  GL_INTENSITY4, GL_INTENSITY8,			  GL_INTENSITY12, GL_INTENSITY16, GL_R3_G3_B2,			  GL_RGB, GL_RGB4, GL_RGB5, GL_RGB8, GL_RGB10,			  GL_RGB12, GL_RGB16, GL_RGBA, GL_RGBA2,			  GL_RGBA4, GL_RGB5_A1,	GL_RGBA8, GL_RGB10_A2,			  GL_RGBA12, or	GL_RGBA16.

yes there are quite a lot of formats ...
but let's say i have an 8bits image with Red and Blue channels only
and I want to upload it, with the correct data in red and blue and
0.0 for green and alpha...
that's the sort of things i want to do
Quote:Original post by Majestik_666
yes there are quite a lot of formats ...
but let's say i have an 8bits image with Red and Blue channels only
and I want to upload it, with the correct data in red and blue and
0.0 for green and alpha...
that's the sort of things i want to do
Why don't you just use RGB, and fill the 0.0f in the green for yourself when acquiring the original image data?
well for memory saving purposes i do not ...
my buffers can have only 2 channels and use only the exact required space
for it ...
Quote:Original post by Majestik_666
well for memory saving purposes i do not ...
my buffers can have only 2 channels and use only the exact required space
for it ...
Why?

Don't some of the drivers expand everything to 32 bits anyways as an optimization? I read that somewhere a long time ago, I don't remember where.

yes that's fair enough but
I only upload the buffer to the video card ram when I need to
some processing is done on the gpu, 90% of the time the buffers
will be in CPU ram and not video card ram
and when you have 8Kx8K float textures , well removing some channels
from the buffer can make quite a big difference ...
Quote:Original post by Majestik_666
...I only upload the buffer to the video card ram when I need to
some processing is done on the gpu, 90% of the time the buffers
will be in CPU ram and not video card ram
...


I think you are answering your own question. Keep it in one format in system memory, and another in video memory. Just simply fill in the missing components when uploading to the card.

well that's always been the plan ...
but my question is how to upload one buffer from main memory to gpu memory
when it only has a subset of the RGBA ?

the ideal solution would be something like that :
only R Channel : GL_RED
R and B Channels : GL_RED | GL_GREEN
R and A Channels : GL_RED | GL_ALPHA
RGB Channels : GL_RGB
etc...

it'd be nice if this glTexImage was a bit more versatile in terms
of channels ...


Does it matter that much what you label the channels as? If you're using shaders, I thought that for most purposes you could interpret the channels any way you wanted. For example you could have RGB really be CMY or something. There's no CMY texture format, but I don't think that would matter if you fine with
Quote:Original post by Majestik_666
R and B Channels : GL_RED | GL_GREEN

This topic is closed to new replies.

Advertisement