How to both ADD and SUBTRACT with one operation

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.

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.

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 :frowning:

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

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

Doesn’t combine mode have signed arithmetics? GL_ADD_SIGNED_ARB seems it could be used.