View Full Version : Swap colors w/o color matrix?
06-30-2004, 08:59 PM
Is it possible to copy one color channel to another or to swap two color channels when GL_SGI_color_matrix is not available?
07-01-2004, 07:37 AM
OpenGL has a color matrix in the optional imaging extensions in the core functionality since version 1.2. Check for the GL_ARB_imaging extension instead. (See GL specs 1.5 chapter 3.6.2)
If that's also not available, you have to do it by other means, like glReadPixels(), swap, glDrawPixels() (slow).
If you need the swapping during drawing, you could use fragment programs swizzling the output to the fragment color.
07-01-2004, 08:00 AM
You could swap all color channels in your source data (textures, per-vertex colors, constants).
07-01-2004, 09:01 PM
Originally posted by Relic:
If you need the swapping during drawing, you could use fragment programs swizzling the output to the fragment color.How do I create "fragment programs"?
07-02-2004, 04:39 AM
Before you go there, explain a little more what the exact problem is. This is no beginner's stuff. Using fragment programs is either the solution to everything or shooting with cannons on sparrows.
Fragment programs, like vertex programs are user written GPU assembly programs which are converted to microcode and uploaded to the GPU by an OpenGL driver supporting the extensions necessary for it.
Those programs are capable of replacing parts of the standard OpenGL transform, lighting and rasterization pipeline inside the chip with your algorithms.
BTW, what hardware do you have? If you have no support for the ARB_imaging set, you might also have no progammable pipeline program support.
There are tons of docs about all that.
Look for the exact (complicated) extensions on http://oss.sgi.com/projects/ogl-sample/registry/
Look for "vertex_program" and "fragment_program" names and the like.
This gets easier with high level shading languages (GLSL). There's a forum for that too here.
For demos and detailed docs go to the developer relations sites of NVIDIA or ATI.
07-04-2004, 10:24 PM
Originally posted by Relic:
Before you go there, explain a little more what the exact problem is.I am just beginning with OpenGL and use it to overlay some image processing results (points and lines) on the original image and display it online. I have chosen OpenGL mainly because it is platform independent -- the hardware acceleration is only a "nice to have" feature but actually I am quite amazed by its performance!
My image processing involves some low level functions like convolution and some additional pixel arithmetic. When I found out that OpenGL supports convolution I decided to try to move the low level processing to the GPU in order to get better performance. The R, G and B channels are like three variables that can be processed in parallel. Intermediate results must be copied from one variable to another.
In the meantime I got the convolution running but it is very slow (slower than my CPU only version). This is not due to DrawPixels -- I get 50 fps with convolution disabled and about 3 fps with convolution enabled. Why is it so slow?
I found out that not every OpenGL driver supports ARB_IMAGING. As convolution is not fast anyway, I thought that it might be better to look for a solution that does not rely on this extension, but then a replacement for ColorMatrix must be found.
By the way, what is the fastest method to convolve an image with a Gaussian (blur) or a Sobel (gradient) kernel?
Fragment programs, like vertex programs are user written GPU assembly programs which are converted to microcode and uploaded to the GPU by an OpenGL driver supporting the extensions necessary for it.Are these fragment programs hardware dependent?
07-04-2004, 10:44 PM
is an extension that is pretty "fancy" ie since GeForce5 / Radeon 9600
07-05-2004, 03:49 AM
The ARB_imaging extensions might not be fully hardware accelerated.
The fastest method to do convolution filters are actually fragment programs. This is fully hardware accelerated on chips supporting the feature.
The implementations of such filters can vary greatly. You could either draw multiple times, use many texture lokups in one pass, use a hardware accelerated accumulation buffer, etc.
See the www.gpgpu.org (http://www.gpgpu.org) tutorial for a simple Laplace filter in Cg.
Such an implementation is really fast on today's graphics processors; fast like in hundreds frames per second.
Another site for shaders and the like is www.shadertech.com (http://www.shadertech.com) if you're hooked now.
07-05-2004, 05:16 AM
All this seems to be quite advanced. I am really amazed by all that can be done with the GPU. However, a lot of it is only possible when certain extensions are available. I guess that someday I will try to use the GPU more intensively, but now I seek solutions that are also compatible with older OpenGL versions.
So back to my original question: Is it possible to copy one color channel into another or to swap two color channels using only pre-ARB_IMAGING functionality?
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.