<p>So i searched a lot after this and I think it was my confusion on FrameBuffer Objects.</p>

<p>I thought you could use FBO's just like a default FrameBuffer and display the texture image attached to it but you can't. It's only used for offscreen rendering. So while you can use rendering commands to draw something to a "texture image" attached to it, you can't "display the image" by making it default framebuffer or something like that.</p>

CC BY-SA 3.0
2017-09-18T10:47:51.960Z
If I understand correctly what you are trying to do, then, it is possible to do with FBO. Just create rendertexture instead of renderbuffer for color attachment (and call appropriate bind function). Then you'll be able to use this render texture as shader input.
alariq
CC BY-SA 3.0
2017-09-18T13:10:48.140Z
No i was thinking that i could use the FBO to display the texture image on the window. Like i was thinking if the texture image is already set in the compute shader, then the FBO it's attached to would just display it in the window if i make it default, but i don't think there's any command for that.
gallickgunner
CC BY-SA 3.0
2017-09-19T07:28:56.473Z
I guess internally opengl keeps a texture buffer for the default framebuffer. It's just the API does not allow you to consider it as a texture, so a draw/copy operation is needed.
PaulHK
CC BY-SA 3.0
2017-09-19T19:07:02.510Z
Yes that's what i was thinking. I thought opengl provided the functionality to use the FBO as a default one to display the texture directly attached but it doesn't i guess. They provided FBO for offscreen rendering only i guess for help with things like getting the reflection texture etc.
gallickgunner
CC BY-SA 3.0
2017-09-16T16:32:48.923Z
2017-09-16T16:32:48.923Z
gallickgunner
<p>The overhead on this is pretty miniscule anyway. Modern GPU raster and texture rates are on the order of tens of gigapixels per second. Compared to the cost of running a ray tracer, it's a rounding error.</p>

CC BY-SA 3.0
2017-09-17T09:12:04.343Z
2017-09-17T09:12:04.343Z
russ
<p>I Recently posted this question on SO but didn't got any response so i thought to post it here since it's somewhat related to Raytracing. </p>

<p>I am making a real time ray tracer in OpenGL using Compute Shaders for my project and was following this <a href="https://github.com/LWJGL/lwjgl3-wiki/wiki/2.6.1.-Ray-tracing-with-OpenGL-Compute-Shaders-(Part-I)" rel="nofollow noreferrer">link</a> as a reference. The link tells to first draw a full screen quad, then store all the individual pixel colors gotten through intersections in a texture and render the texture to the quad.</p>

<p>However i was thinking can't we use Frame Buffer Objects to display the texture image instead of rendering the quad and save the over head?</p>

<p>Like I save all the colors using <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/imageStore.xhtml" rel="nofollow noreferrer">ImageStore</a> and <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindImageTexture.xhtml" rel="nofollow noreferrer">GlBindImageTexture</a> in a texture, then attach it to a FBO to display it. And since I won't be using any rendering commands I won't be causing a Feedback loop as in writing and reading the same texture?</p>

<p>Here is the snippet</p>

<pre><code>  void initialization() {
  int tex = create new texture object

  setup min/mag NEAR filtering for that texture
  initialize texture as 2D rgba32f FLOAT and some width/height

  int vao = create VertexArrayObject of full-screen-quad
  // This quad is used to render our
  // "framebuffer" texture onto the screen.

  int computeProgram = create-and-link program with single compute shader object

  int quadProgram = create-and-link simple full-screen quad vertex and fragment shader
  // The fragment shader would fetch
  // texels from our "tex" texture.

  Setup constant uniforms in quad program, such as "tex" texture unit = 0
}



 The rendering process to produce one frame will be as follows:

Bind the Compute Shader
Setup camera properties in compute shader uniforms
Bind level 0 of framebuffer texture to image binding point 0
Start/dispatch the compute shader to generate a frame in the framebuffer image
Unbind image binding point
Bind the written framebuffer texture in OpenGL to texture unit 0
Bind the full-screen shader program
Bind the full-screen-quad VAO
Draw the VAO
Release all bindings
</code></pre>

<opengl><raytracing><compute-shader>
Raytracing in OpenGL using Compute Shaders
gallickgunner
# Raytracing in OpenGL using Compute Shaders

(Asked by: username_0 on 2017-09-13)

I Recently posted this question on SO but didn't got any response so i thought to post it here since it's somewhat related to Raytracing.

I am making a real time ray tracer in OpenGL using Compute Shaders for my project and was following this [link](https://github.com/LWJGL/lwjgl3-wiki/wiki/2.6.1.-Ray-tracing-with-OpenGL-Compute-Shaders-(Part-I)) as a reference. The link tells to first draw a full screen quad, then store all the individual pixel colors gotten through intersections in a texture and render the texture to the quad.

However i was thinking can't we use Frame Buffer Objects to display the texture image instead of rendering the quad and save the over head?

Like I save all the colors using [ImageStore](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/imageStore.xhtml) and [GlBindImageTexture](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindImageTexture.xhtml) in a texture, then attach it to a FBO to display it. And since I won't be using any rendering commands I won't be causing a Feedback loop as in writing and reading the same texture?

Here is the snippet

```
  void initialization() {
  int tex = create new texture object

  setup min/mag NEAR filtering for that texture
  initialize texture as 2D rgba32f FLOAT and some width/height

  int vao = create VertexArrayObject of full-screen-quad
  // This quad is used to render our
  // "framebuffer" texture onto the screen.

  int computeProgram = create-and-link program with single compute shader object

  int quadProgram = create-and-link simple full-screen quad vertex and fragment shader
  // The fragment shader would fetch
  // texels from our "tex" texture.

  Setup constant uniforms in quad program, such as "tex" texture unit = 0
}

 The rendering process to produce one frame will be as follows:

Bind the Compute Shader
Setup camera properties in compute shader uniforms
Bind level 0 of framebuffer texture to image binding point 0
Start/dispatch the compute shader to generate a frame in the framebuffer image
Unbind image binding point
Bind the written framebuffer texture in OpenGL to texture unit 0
Bind the full-screen shader program
Bind the full-screen-quad VAO
Draw the VAO
Release all bindings

```

**Tags:** opengl, raytracing, compute-shader


---

## 2 answers

### Answer by username_0 on 2017-09-16. Score: 2 | Accepted answer

So i searched a lot after this and I think it was my confusion on FrameBuffer Objects.

I thought you could use FBO's just like a default FrameBuffer and display the texture image attached to it but you can't. It's only used for offscreen rendering. So while you can use rendering commands to draw something to a "texture image" attached to it, you can't "display the image" by making it default framebuffer or something like that.

> **Comments:**
> **username_1**: If I understand correctly what you are trying to do, then, it is possible to do with FBO. Just create rendertexture instead of renderbuffer for color attachment (and call appropriate bind function). Then you'll be able to use this render texture as shader input.  
> **username_0**: No i was thinking that i could use the FBO to display the texture image on the window. Like i was thinking if the texture image is already set in the compute shader, then the FBO it's attached to would just display it in the window if i make it default, but i don't think there's any command for that.  
> **username_2**: I guess internally opengl keeps a texture buffer for the default framebuffer. It's just the API does not allow you to consider it as a texture, so a draw/copy operation is needed.  
> **username_0**: Yes that's what i was thinking. I thought opengl provided the functionality to use the FBO as a default one to display the texture directly attached but it doesn't i guess. They provided FBO for offscreen rendering only i guess for help with things like getting the reflection texture etc.  

---

### Answer by username_3 on 2017-09-17. Score: 1

The overhead on this is pretty miniscule anyway. Modern GPU raster and texture rates are on the order of tens of gigapixels per second. Compared to the cost of running a ray tracer, it's a rounding error.


---

