0
votes

So, I read in a texture into my fragment shader. I can output to "display"; but how do I output/write to another texture? Basically what I want to do is:

read in info from texture 1  // working
do stuff with data //working.
output to texture 2  // ??
display texture 2  // working.

second turn:

read in infom from texture 2  // working
do stuff with data //working.
output to texture 1 // ??
display texture 1 /// working.

I want to do this all on the GPU. It's easy enough to do on the CPU, but it kills performance (hence, why I'm doing it in a shader).

I think I want to use a frame, texture or pixel buffer?

More info if required, the textures are getting into the shader like this:


//housekeeping.
glUseProgram(theProgram); 
glUniform1i(glGetUniformLocation(theProgram, "TextureOne"), texId);

Shader:

#version 330 core

out vec4 outputColor;
in vec2 fragPosition;  // 2d texture
uniform sampler2D TextureOne;

void main() {
    outputColor = texture(TextureOne, fragPosition);  
    //outputColor goes to output display.
}
1

1 Answers

3
votes

You use Framebuffer Objects (FBO) to write to textures, they are used as custom draw buffers, you can attach a texture as a draw buffer (attachment) and the color writes will go to the texture.