Commit Graph

4 Commits

Author SHA1 Message Date
Simon Anciaux e4a4910e6b Use the actual clip rectangle.
Use rect_overlap in draw_rectangle_outline.
Reorganized a bit to test earlier to avoid unnecessary work.
2025-07-07 13:09:10 -07:00
Simon Anciaux d926166630 Changed the fix a little to test only 4 vertex per characters (instead of 6).
Removed the "draw = true;" left from testing.
2025-07-07 13:05:18 -07:00
Simon Anciaux 52124edcd8 Avoid rendering rectangles (and characters) that are outside the window bounds.
While debugging an issue with the dx11 backend, I noticed that 4coder only clipped rectangles that are outside the screen vertically. Another potential issue (it might be the intended behavior) causes some things to not work with line wrapping, which means that we could have very long horizontal lines, causing a lot of vertices being sent through the render pipeline that will just be clipped after the vertex shader. This causes higher than necessary GPU memory usage, and low performance for things that aren't rendered in the end.

An example of problematic is:
```c
u8 data[ ] = {0,0,0,0,...,0}; // With a lot of zero, and no space between them.
```

This fix just checks that at least one vertex of each rectangle we try to draw is in the screen. It would be better to use the current clip rect, but it's not available at that point in the pipeline. If we want we can modify the API a little to pass it down, as a parameter to those functions.

Using RenderDoc, I saw the vertex count going from over 500K to 13K with this change, and the performance were from 57ms to 25ms. So perfs are not great (but still an improvement), but testing the bounds of 500K vertices is not free. Fixing the line wrapping issue would probably help getting back to reasonable frame rate.
2025-07-07 13:05:06 -07:00
Jack Punter 0e47ccd2ce Add 'code/' from commit '1459ef7cbce753b056ea148b29c9dc3f8a721261'
git-subtree-dir: code
git-subtree-mainline: cf6a50363e
git-subtree-split: 1459ef7cbc
2022-11-18 13:37:07 +00:00