Commit b9d45ba
committed
gfx/gl3: reuse menu texture across set_texture_frame calls
gl3_set_texture_frame unconditionally destroyed and recreated the GPU
texture object on every call via glDeleteTextures + glGenTextures +
glTexStorage2D. Menu dimensions rarely change after the first call,
so this burned GPU driver overhead and allocator bandwidth every menu
frame for no reason. The gl2 driver already handles this correctly
(via gl_load_texture_data, which reuses the texture when possible).
Cache the last-used (width, height, rgb32) tuple on the driver
handle; recreate the texture only when one of those changes, otherwise
keep the existing texture and stream new pixel data via
glTexSubImage2D. glTexStorage2D is immutable per GL spec so the
texture *must* be recreated on dim/format change, but for same-size
same-format updates (the overwhelmingly common case) no such
recreation is needed.
Filter, wrap, and swizzle parameters are still set every call. The
menu_linear_filter setting can toggle at runtime, and these calls are
negligible compared to the pixel upload.
Thread-safety: unchanged. set_texture_frame and the frame read-site
both run on the video thread (threaded video) or main thread
(non-threaded), sequentially within the same loop iteration. No
synchronization required, none added. The existing shared-context
bind/unbind wrapping is preserved.
gl3_t is calloc'd at init and freed entire on teardown, so the three
new cache fields (menu_texture_width, menu_texture_height,
menu_texture_rgb32) start at zero on every re-init. On first call
menu_texture is 0, which triggers the recreate branch — correct.1 parent 0f6a3e2 commit b9d45ba
1 file changed
Lines changed: 33 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
171 | 173 | | |
172 | 174 | | |
173 | 175 | | |
| |||
182 | 184 | | |
183 | 185 | | |
184 | 186 | | |
| 187 | + | |
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
| |||
4722 | 4725 | | |
4723 | 4726 | | |
4724 | 4727 | | |
| 4728 | + | |
| 4729 | + | |
4725 | 4730 | | |
4726 | 4731 | | |
4727 | 4732 | | |
4728 | 4733 | | |
4729 | 4734 | | |
4730 | 4735 | | |
4731 | | - | |
4732 | | - | |
4733 | | - | |
4734 | | - | |
4735 | | - | |
4736 | | - | |
| 4736 | + | |
| 4737 | + | |
| 4738 | + | |
| 4739 | + | |
| 4740 | + | |
| 4741 | + | |
| 4742 | + | |
| 4743 | + | |
| 4744 | + | |
| 4745 | + | |
| 4746 | + | |
| 4747 | + | |
| 4748 | + | |
| 4749 | + | |
| 4750 | + | |
| 4751 | + | |
| 4752 | + | |
| 4753 | + | |
| 4754 | + | |
| 4755 | + | |
| 4756 | + | |
| 4757 | + | |
| 4758 | + | |
| 4759 | + | |
4737 | 4760 | | |
4738 | 4761 | | |
4739 | 4762 | | |
| |||
4742 | 4765 | | |
4743 | 4766 | | |
4744 | 4767 | | |
| 4768 | + | |
| 4769 | + | |
| 4770 | + | |
| 4771 | + | |
4745 | 4772 | | |
4746 | 4773 | | |
4747 | 4774 | | |
| |||
0 commit comments