anyone know if there’s a way to cull a Mesh Rect?
basically i’m rewriting my bitmap fonts to use rects instead of individual meshes. the problem with this approach is if i have a long swath of texts, each rect will be looped for each character even if it’s off screen. at least that is what it appears like to me.
@skar It’s worth pointing out that offscreen geometry won’t be rendered. Between the vertex and fragment shader, offscreen pixels are culled so offscreen geometry only runs a vertex shader (which tends to be pretty fast for text).
Other than that, unless you modify the text mesh every frame to clip manually I don’t think there’s any other way.
@skar The mesh rect API just adds 2 triangles to the mesh to form a rect. So there’s no culling of individual rects when they are off screen. @Steppers is right that the GPU will cull offscreen geometry for you, but will still incur some kind of performance cost (memory bandwidth and vertex processing stage).
We have similar issues to contend with when it comes to rendering text in the Codea editor itself. A few things you could do are:
- group together big chunks of text into blocks (one mesh per block)
- manually cull blocks (lets save 50 lines of text was a block)
- only update meshes for blocks that you modify
So if you have 500 lines of text in a single textbox, you would have 10 meshes, of which only a few would be rendered each frame. And when you modify some text you only need to update one chunk at a time and perhaps update the overall offset of the other chunks to line everything up
This is only really needed if you have huge amounts of text and you may still get performance issues when you have 100k lines of text or something like that