<p>Imagine I render to an FBO some arbitrary geometry. Geometry can be rendered via single or multiple draw calls. For the sake of the question, assume I know nothing about geometry or transformation matrices.</p>

<p>I need to efficiently read back the minimal screen-space bounding box of all drawn geometry after the rendering to FBO is finished.</p>

<p>I imagine this can be done with via use of atomics on an image (imageLoad/imageStore) or SSBO, sadly these are not available to me. Is there any other mechanism I can try?</p>

CC BY-SA 4.0
2019-03-04T20:49:45.580Z
Do you care what happens to geometry that doesn't affect a pixel? e.g. it's degenerate or end-on to the camera
Dan Hulme
CC BY-SA 4.0
2019-03-04T21:12:27.467Z
Unless parts of my geometry happen to be outside of clip space, every fragment from geometry should end up being rendered to FBO. Geometry from different submissions may and will overlap. What I need a rectangular area within my FBO that covers pixels "affected" by rendering. This area may well cover whole FBO viewport or cover zero area (in case all geometry happen to miss clipspace of FBO)
lhog
CC BY-SA 4.0
2019-03-04T22:20:01.267Z
Well, what *is* available to you? Since you got FBOs I assume an old-school GPGPU ping-pong reduction with a fragment shader would be viable? In that case, either you can distinguish a "rendered" pixel from a "background" pixel in the color buffer or you use the stencil buffer and then just reduce it computing the minimum and maximum of all "set" fragment positions.
Christian Rau
CC BY-SA 4.0
2019-03-05T01:59:34.643Z
@lhog: "*read back the minimal screen-space bounding box of all drawn geometry after the rendering to FBO is finished.*" Did you pass the bounding box? If not, how do you expect to read back something you didn't provide?
Nicol Bolas
CC BY-SA 4.0
2019-03-05T20:01:09.013Z
@NicolBolas I am assuming what he means here is the minimal rectangle that contains all rasterized pixels. The obvious algorithm is to iterate over all pixels and find the rasterized ones with minimum x, minimum y, maximum x, maximum y. The thing is that he wants something efficient. The only thing I can think of is doing a vertical and horizontal pass to compute those (which can be parallelized), or alternatively use a divide and conquer approach (once again parallelized) which will yield $O(n\log n)$.
lightxbulb
CC BY-SA 4.0
2019-03-05T20:20:08.577Z
Yes @lightxbulb got it correct. I don't know beforehand what part of my FBO the rendered geometry will take, so I need to obtain bounding rectangle containing all pixels that have been changed/rendered to by geometry draw call afterwards. glReadPixels() is used for this currently, but it's rather slow and I was hoping to catch some trick to get minmax rect from GPU.
lhog
CC BY-SA 4.0
2019-03-05T21:41:22.290Z
@lhog I don't know about a trick from the gpu. The best I can think of is using the stencil buffer and using a procedure similar to the ones used to build summed-area tables on the gpu (if you look for fast SAT building you'll find those), but not with addition but rather with min/max.
lightxbulb
CC BY-SA 4.0
2019-03-06T04:31:11.067Z
Please don't [cross-post](https://gamedev.stackexchange.com/questions/168646/convey-screenspace-bounding-box-of-rendering-result) questions to multiple Stack Exchange sites.
user1118321
<opengl><glsl>
Convey screenspace bounding box of rendering result
lhog
# Convey screenspace bounding box of rendering result

(Asked by: username_0 on 2019-03-04)

Imagine I render to an FBO some arbitrary geometry. Geometry can be rendered via single or multiple draw calls. For the sake of the question, assume I know nothing about geometry or transformation matrices.

I need to efficiently read back the minimal screen-space bounding box of all drawn geometry after the rendering to FBO is finished.

I imagine this can be done with via use of atomics on an image (imageLoad/imageStore) or SSBO, sadly these are not available to me. Is there any other mechanism I can try?

**Tags:** opengl, glsl

> **Comments:**
> **username_1**: Do you care what happens to geometry that doesn't affect a pixel? e.g. it's degenerate or end-on to the camera  
> **username_0**: Unless parts of my geometry happen to be outside of clip space, every fragment from geometry should end up being rendered to FBO. Geometry from different submissions may and will overlap. What I need a rectangular area within my FBO that covers pixels "affected" by rendering. This area may well cover whole FBO viewport or cover zero area (in case all geometry happen to miss clipspace of FBO)  
> **username_2**: Well, what *is* available to you? Since you got FBOs I assume an old-school GPGPU ping-pong reduction with a fragment shader would be viable? In that case, either you can distinguish a "rendered" pixel from a "background" pixel in the color buffer or you use the stencil buffer and then just reduce it computing the minimum and maximum of all "set" fragment positions.  
> **username_3**: @username_0: "*read back the minimal screen-space bounding box of all drawn geometry after the rendering to FBO is finished.*" Did you pass the bounding box? If not, how do you expect to read back something you didn't provide?  
> **username_4**: @username_3 I am assuming what he means here is the minimal rectangle that contains all rasterized pixels. The obvious algorithm is to iterate over all pixels and find the rasterized ones with minimum x, minimum y, maximum x, maximum y. The thing is that he wants something efficient. The only thing I can think of is doing a vertical and horizontal pass to compute those (which can be parallelized), or alternatively use a divide and conquer approach (once again parallelized) which will yield $O(n\log n)$.  
> **username_0**: Yes @username_4 got it correct. I don't know beforehand what part of my FBO the rendered geometry will take, so I need to obtain bounding rectangle containing all pixels that have been changed/rendered to by geometry draw call afterwards. glReadPixels() is used for this currently, but it's rather slow and I was hoping to catch some trick to get minmax rect from GPU.  
> **username_4**: @username_0 I don't know about a trick from the gpu. The best I can think of is using the stencil buffer and using a procedure similar to the ones used to build summed-area tables on the gpu (if you look for fast SAT building you'll find those), but not with addition but rather with min/max.  
> **username_5**: Please don't [cross-post](https://gamedev.stackexchange.com/questions/168646/convey-screenspace-bounding-box-of-rendering-result) questions to multiple Stack Exchange sites.  

---

## 0 answers

