OpenGL Cropping

I read articles about circumcision for hours now, but I didn't seem to find a solution to my problem.

This is my scenario:

In the OpenGL ES environment (IOS, Android), I have a 2D scene graph consisting of paintable objects that make up a tree.

Each node tree has its own space with its own transformation matrix, and each node inherits its coordinate space from its children. Each node has a rectangular bounding box, but these bounding fields are not aligned along the axes.

This setting is great for rendering a 2D scene graph, iterating over a tree, rendering each object, and then its children.

Now my problem arises: I'm looking for a way to crop a node. If the clipping function is enabled, children from the node must be cropped when leaving the area of ​​the parent bounding box.

For example, I want a node to contain a set of text nodes in the form of child elements that can be scrolled up and down, restricting the frame of parental constraints, and should be cropped when leaving the area of ​​the parent bounding box.

Since the bounding fields are not aligned along the axis, I cannot use glScissor, which would be the easiest way.

I thought about using a stencil buffer and drew a filled bounding box into it when clipping is turned on and then the stencil buffer is turned on. This may work, but leads to another problem: what happens if the child inside the clipped node is clipped again? - The stencil mask should be set for the child by erasing the stencil mask of the parents.

Another solution that I was thinking about is to do a clipping in the software. This would be possible, because in each node, clipping could be done relatively easily in its own local coordinate space. The backdraw of this solution will be that clipping must be implemented for each new node type that is implemented.

Can someone here point me in the right direction? What I'm looking for is something like glscissor functionality for clipping rectangular areas that are not oriented along the axis.

+4
source share
1 answer

A box for scissors is a simple tool for simple needs. If you have fewer simple needs, you will have to use the less simple OpenGL mechanism to clip: the stencil buffer.

Assuming you are not using the stencil buffer for anything else at the moment, you have access to 8 bits of the stencil. By giving each level in the scene graph a higher number than the last, you can assign each level its own screen mask. Of course, if two brothers and sisters at the same depth level overlap or are just too close, then you have a problem.

Another alternative is to assign each node a number from 1 to 255. Using the GL_EQUAL screen test, you can prevent the overlap problem above. However, this means that you can have no more than 255 nodes in the entire scene graph. Depending on your specific needs, this may be too much of a limitation.

You can, of course, clear the stencil (and depth. Do not try to clear one of them) when you finish the bit using any of these methods. But this can be somewhat costly, and it requires you to clear the depth that you might not want to do.

Another method is to use an increasing number and the GL_EQUAL test only for nodes that are not oriented along the axis. You use a scissor block for most nodes, but if there is some rotation (whether on a node or inherited), then instead you use a stencil mask by pressing the mask counter when processing the graph. Again, you are limited to 256 nodes, but at least they are only for rotated nodes. Depending on your needs and the number of rotating nodes that may be sufficient.

+5
source

All Articles