Hey guys,
I posted a thread last night which was really code heavy, and nobody has replied yet, so I thought I’d post another, which just contained my understanding of how to tackle a multipass shader program using 2 sets of different shaders, and then I’d post my questions at the end. No code attached, only thought process.
-
Create an enum of unsigned int TextureIDs
-
Generate textures based on the number of TextureIDs created. In my case, 4
-
Bind textures to IDs and attach images to them if needed. In my case 3 of the 4 textures get images, the fourth one gets NULL data. Textures are unbound(?) after they are updated.
–Every time the screen needs to be updated–
-
Create a framebuffer object, and bind it. First parameter is 1 so that it does not draw to the screen
-
Create and set shaders for pass 1, and update them with the correct information. (in my case, the 3 textures with images are passed in as uniforms. Some data is sent to the vertex shader too)
-
Bind empty (data = NULL) texture to the framebuffer as GL_COLOR_ATTACHMENT_0 using a glFrameBufferTexture call
-
set location 0 to be GL_COLOR_ATTACHMENT_0 using a glDrawBuffers call
-
draw, which handles drawing, and also calls active and bind on all 4 textures in a loop. The fragment shader outputs a vec3 to location 0 using layout(location = 0)
-
create and setup new shaders for pass 2, and pass them the appropriate information(in my case, pass the previously empty texture to the fragment shader as a uniform)
-
switch to the default framebuffer
-
draw, which once again calls active and bind on all 4 textures, output final data using data from uniform passed in.
Now for my questions:
-
I am unsure if attaching my texture to GL_COLOR_ATTACHMENT_0 and attaching location 0 to GL_COLOR_ATTACHMENT_0 outputs the data into my texture or if it does not.
-
If that does output data to the texture, I am unsure if it is being clobbered by switching to the default framebuffer.
-
I am unsure if I should create a separate draw function for the second pass, which only calls active and bind on the one texture I am using in that pass, or if I can keep it the way it is now.
-
Why is there a call to glBindTexture(GL_TEXTURE_2D, 0) after each new texture is created?
Thanks to anyone who can tell me if my though process sounds correct, and/or can answer any of these questions