View Full Version : How to both ADD and SUBTRACT with one operation

11-27-2005, 12:50 AM
Is it possible to draw a textured quad on the screen with values that can be interpreted as two's complement (e.g. -128...+127) and have the destination (framebuffer or texture) changed accordingly?

Perhaps if I render to a texture with a special format?

Rendering twice is really not an option, I'm afraid.

11-27-2005, 01:23 AM
you could grab the framebuffer into a texture A
and when you draw your quad, map it such a fashion that the texcoords match the viewport.
without using shaders you can do this using texgen.

so your quad uses
A: texgen, framebuffer tex
B: tescoords, your special tex

with arb_texture_env_combine extension you can perform the operation "ADD_SIGNED", which will do what you asked for.

11-27-2005, 05:03 AM
Thanks for the answer.

Unfortunately I am using vertex and fragment shaders. In fact the particles need to be written many times over the same places. Thus I can't afford copying the framebuffer to a texture each time :(

But I will try to render to a texture instead. Perhaps a float or signed_int can do the job?!

11-27-2005, 08:56 AM
I'm not too sure yet, but so far it seems that rendering to a RGBA16F texture (half float) would do the trick.

glGenFramebuffersEXT(1, &FinalFB);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FinalFB);

glGenTextures (1, &FinalTex);
glBindTexture (GL_TEXTURE_2D, FinalTex);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0, GL_RGBA,GL_HALF_FLOAT_ARB,0);

// Unbind framebuffer and render texture to screen

11-28-2005, 06:12 AM
Doesn't combine (http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt) mode have signed arithmetics? GL_ADD_SIGNED_ARB seems it could be used.