Opengl: texture operation & drawing questions

Common task: I’m trying to do complete hardware accelerated JPEG viewer from this example.

(
http://download.nvidia.com/developer/SDK/Individual_Samples/vidimaging_samples.html
Discrete Cosine Transform
) But it’s not so important…

There is 3 color components in jpeg stream ( luminance and 2 chromaticity components ). By using OpenGl I have an opportunity create texture with some data. Then by means of GPU to do some operation() (IDC for example - inverse discrete cosine transform) and then draw it. The problem is I need to do operation () with each of 3 color components.

I know how to put data into texture, how to do operation(*) under this data and the how to draw this results. By using this way I can draw each components SEPARATELY. But I want to combine drawing of all 3 color components to draw color ( not luminance ) picture. Here is pseudo code ( I can give more details if it’s not enough)

// obtaining luminance
void * component1 = …

glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_R32_NV, width, height, 0, GL_LUMINANCE, GL_FLOAT, component1);

DoSomeOperationWithTheTexture(); // idct, by means of CG (video card)

DrawTexture();

How can I draw all 3 components of the color at the same time ?

In other words: I can create buffer/texture, to do some operation with it and display it. But I don’t know how can I draw 3 buffers at the same time.

Thanks in advance.

You may want to have a peek at GPU Gems 2. They present a method for calculating the FFT on the GPU, and the DCT is just a special case of that, as I recall.

Cheers

FFT or DCT - never mind. In common it’s some operation. I don’t have problem with it. See my question.

Why don’t you use RGB texture instead of luminance texture?

glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB32F, width, height, 0 , GL_RGB, GL_FLOAT, components_1_to_3);

Of course you’ll need to put all 3 components in one array (components_1_to_3) on CPU.

If you want to avoid that, then you can still use 3 luminance textures and in shader you would compose color out of them:

vec3 color;
color.r = texture2D(tex1, gl_TexCoord[0].xy).r;
color.g = texture2D(tex2, gl_TexCoord[0].xy).r;
color.b = texture2D(tex3, gl_TexCoord[0].xy).r;

You could also use glColorMask to write one luminance texture to red component, second to green, third to blue and then use glCopyTexSubImage2D to make final texture out of it (or render directly to such texture using FBO). This way you remain OpenGL 1.1 compatible.

Or is there something I didn’t understand in your post and the solution isn’t that obvious?

Originally posted by k_szczech:
Why don’t you use RGB texture instead of luminance texture?

In jpeg I have a dial with some coefficients … After IDCT have being done this coefficients become a luminance and chrominance. And I want to do IDCT by means of GPU. So I have to use 3 different texture.

[b]

If you want to avoid that, then you can still use 3 luminance textures and in shader you would compose color out of them:
[/b]

Can you tell more words about it? I have not had a dial with opengl befor.
As I understood, the best way is to have 3 textures, combine it to one and then display. Do you think so ?

There is 3 color components in jpeg stream ( luminance and 2 chromaticity components )
I am not expert in the jpeg format, but I knew that there are 3 components per pixel : RGB
Or I would like that someone explain me how it can works.

If you want to do a complete hardware accelerated JPEG viewer You have just to load the jpeg picture’s data in an array and give it to the glTexImage2D function to create a texture that you could draw on a quad if you want to see the picture’s color…

You can find easily on the web some code that create a data array that contains successively RGB component of the picture, and then you can you the glTexImage2D like that:

  glTexImage2D(GL_TEXTURE_2D, 
            0,                        //mimap level
            3,                // number of color components
            w, 
            h, 
            0,                        //border
            GL_RGB, 
            GL_UNSIGNED_BYTE, 
            image);

where ‘image’ is the data array of the picture.


If you want to do a complete hardware accelerated JPEG viewer You have just to load the jpeg picture’s data in an array and give it to the glTexImage2D function to create a texture that you could draw on a quad if you want to see the picture’s color…

Hardware accelerated JPEG viewer - means that videocard (not CPU!!!) will be obtain different components of the color. And I have an opportunity do obtain 3 different texture. In each texture will be one component of the color.

In simple words (it’s not actually true ) in texture1 I’ll have RED color. In texture2 – BLUE, texture3 – RED. Now I have to create texture4 in witch I have to combine first 3 textures. Do you know how can I do it by means of CG ?

Sergey, just create an RGB texture such that R channel has the luminance, G channel has the chromaticity 1 and B channel has teh chromaticity 2. Then, in your Cg shader, you can lookup all three channels by on etexture call like

data = texture2D(sampler, coords).rgb
lum = data.r
chr1 = data.b
chr2 = data.g

Then you somehow compute the R,B and G components from that three and put them into output like gl_Color = vec3(r, g, b)

That’s just like usual C…

That’s just like usual C…

Can I try to write a simple program witch aimed to combine 3 textures to one and have some consultation with you ? Can we have a conversation on email or icq or skype or gtalk ?
I guess I’ll not still a lot of your time…

Thanks in advance.

Bystrov Sergey,

I don’t understand…
How do you load the texture’s data at the beginning?
Even though you load each channel separately, you need to load texture’s data with any kind of code that could transform jpeg picture into an array! No?

So, you need to use CPU, inevitably at the beginning. Then, when you show the picture, I agree with you, it is hardware accelerated.

Just for shedding me some lights… Can’t someone just use a single texture for that point, and do all the job within the shader ?