OpenGL backgrounds (splash, menu, options) and cursor#50
Conversation
77fc729 to
dd739f6
Compare
4378b54 to
7f00e8f
Compare
7f00e8f to
295480b
Compare
|
Btw I did have the thought also. But also, just better to use OpenGL. s25client doesn't even support 2D. |
Not sure what this means. |
|
s25client only supports 3D videodrivers like OpenGL. No 2D SDL support. |
Actually s25client draws everything (which is 2D) with OpenGL using 2D coordinates. There is no actual "3D" anywhere in a 2D game and consequently all (code) interfaces are 2D. It isn't actually better not using SDL: SDL could do caching of e.g. font textures instead of us rendering each char separately in every frame in s25client. We'd need to implement everything ourselves without SDL |
|
If I want to use libsidelder2 ctrlButton instead of s25edit CButton it uses Draw3D() Would also be nice to re-use terrain renderer and other things. With 4K monitor and my final gl2-terrain branch where everything is drawn with OpenGL I have 15% idle CPU usage with 60fps vs original 1-2fps @ >100% CPU usage. |
|
And OpenGL can be worth doing for 2D due to 4K 32bit surfaces being ~33MB/frame and to push 60fps it's ~2GB/s. |
|
This is my 3rd or 4th attempt at OpenGL btw. Earlier attempts made broader changes making more use of OpenGL and trying to use features that s25client uses or use different files and classes for rendering, but I now feel this was a mistake and causes too much divergence. |
Flamefire
left a comment
There was a problem hiding this comment.
If I want to use libsidelder2 ctrlButton instead of s25edit CButton it uses Draw3D()
That's still 2D ;-)
Would be nice to just use libsiedler2 UI components directly, eventually.
Just to avoid the name confusion: "libsiedler2" is purely the file format handling.
The UI components are in s25client and the dependencies can't be easily extracted, although yes, would be nice.
With 4K monitor and my final gl2-terrain branch where everything is drawn with OpenGL I have 15% idle CPU usage with 60fps vs original 1-2fps @ >100% CPU usage.
Tho the 2D renderer really doesn't need to draw 60fps tho, water animation is ~12fps. UI is mostly static otherwise. Mouse cursor is tiny part of screen to redraw.
Ok, so what you mean is not a 2D renderer but a software renderer
FTR: I'd have simply used Texture as the class name, but GlTexture is "ok enough". It's just my aversion of prefixed classes that easily go over board. See the archive items hierarchies.
Most points are naming and use of the Position/Extent classes we just introduced using.
1dd3c6e to
2b5d233
Compare
I think I will squash and force push before PR merge please. But will keep it incremental commits during review. |
2b5d233 to
934e919
Compare
|
Great feedback this is better, thank you! |
Flamefire
left a comment
There was a problem hiding this comment.
Nits only now, you asked for it ;-)
But: Did you test this? I see this now uses software rendering for some parts while it draws menu backgrounds directly.
Does that work correctly or cause wrong drawing order somewhere?
|
Yes this branch I test every time. But I missed some issues with window resize/resolution change which I just fixed.
Ok we're having fun now lolol
Yes, only CMenu backgrounds are OpenGL in this PR. There's 2 follow up PRs for UI components and terrain editor. This is just GL groundwork and CMenu backgrounds. "Smallest possible step into OpenGL." as I wrote first line in PR.
The CMenu/background needs to be drawn bottom, then SDL_Surface Surf_Display, then cursor last on top. Flamefire review feedback (round 3)
Bug fixesBug 1 — Cursor turns into white/corrupted rectangle after resolution change Two interrelated root causes:
Fix (in ReCreateWindow()):
Bug 2 — Window resize doesn't update drawn area Root cause: UpdateDisplaySize() (called on SDL_WINDOWEVENT_RESIZED) updated GameResolution and recreated Surf_Display + displayTexture_, but never called Fix: Added setGLViewport() call in UpdateDisplaySize(). |
|
Pushed another fix for full screen res switching. It's really hairy for me maybe cause of Wayland. |
This looks very brittle as you have to remember all textures created anywhere in the program and (re)create them in a single place. That will eventually become out-of-sync and fail, especially when you convert more to hardware-rendering If I see understand that correctly recreating the window is currently done only to change resolution on UI requests, while it is not invoked in regular window-resize-events. In s25client we handle that by changing the window in explicit requests with fallbacks when the request cannot be fulfilled, worst case ignoring it IIRC. |
|
s25client fullscreen resolution switching is broken for me. Maybe because I use wayland. The list is super long and the UI list scroll is doesn't do press and hold to keep scrolling, there's no block to drag to scroll. Have to click repeatedly to scroll one step at a time. |
Broken in which way and situations? E.g. fullscreen enabled already at start, then switching only resolution ingame. What happens/breaks? Does it work here (with the window recreation)? |
|
Also I did not reproduce corruption in gl2-ui branch. Maybe AI is being overly defensive with this. It doesn't actually run anything and does all changes by static analysis / reasoning about code. |
|
Hmm ok gl2-ui only adds displayTexture_ which replaces Surf_Display so there's only 1 texture which is re-loaded every frame. |
|
Ok I managed to remove ReCreateWindow() without breaking full screen resolution switching. |
I can remember someone reporting that too related to high-DPI settings: Return-To-The-Roots/s25client#1621
I guess it's easier to debug here where only SDL is used. It looks like we get wrong/stale data when (re)creating the viewport or internal sizes. Hard to debug when not having access to a machine that has this issue as I'd check variables and events involved and e.g. compare to what they are after a restart.
Same as for any other game: Someone might want a higher resolution for the game than for what they "normally" do on their computer. |
|
I can try to fix it in s25client too, but it doesn't actually bother me since I just use native resolution.
Doesn't make sense to me. Why would they run a lower than full/native resolution for either of desktop or s25edit. Latest commit I pushed keeps full screen switching working on wayland on my system, and removes ReCreateWindow() so don't need to invalidate textures. Also pushed PR #58 to query supported resolutions which should remove invalid resolutions from list. |
Flamefire
left a comment
There was a problem hiding this comment.
I can try to fix it in s25client too, but it doesn't actually bother me since I just use native resolution.
First I would like to know what exactly the issue and fix were. Then we can check how to best port it there.
Doesn't make sense to me. Why would they run a lower than full/native resolution for either of desktop or s25edit.
When games are released they are pushing the performance limits and some users may need lower resolution for performance reasons. This is not the case for us.
I don't know either. Just having the option avoids users complaining they wanted that for some reason ;-)
Latest commit I pushed keeps full screen switching working on wayland on my system, and removes ReCreateWindow() so don't need to invalidate textures.
Looks good, would be good to know what exactly fixed it. I.e. if you can experiment a bit to pinpoint the actual fix. Too much going on with the switch to recreating windows and back to clearly see it.
Also pushed PR #58 to query supported resolutions which should remove invalid resolutions from list.
Early feedback: "Make the same as s25client" isn't a goal in itself. So that shouldn't be mentioned in descriptions, code or comments. Either there is a reasonable change then we can check it or there isn't. If the (only) argument is "it's done somewhere else" then it's not worth even looking at it.
So please make sure you (or the AI) can argue everything on its own merit.
| setGLViewport(); | ||
| for(auto& menu : Menus) | ||
| { | ||
| menu->resetBgTexture(); |
There was a problem hiding this comment.
Why do we need this? Wasn't the point of the last change to keep the textures? How would they be recreated?
There was a problem hiding this comment.
I think it's rescaling as it's full screen and the size just changed. I already asked AI about this and this was reason it gave me but I can double check that it's not being lazy and making shit up lol
There was a problem hiding this comment.
Yeah making shit up. The texture has no notion of screen size. Only the surface has
There was a problem hiding this comment.
Ok you are right. Background rescales much smoother when resizing window now.
| } else if(GameResolution != appliedResolution_) | ||
| { | ||
| // Already fullscreen and the resolution changed. Toggle fullscreen off and | ||
| // back on so SDL/Wayland actually applies the new display mode. |
There was a problem hiding this comment.
Is that the part that fixed your issue with half-covered screen/rendering?
There was a problem hiding this comment.
I think this is the async events which can cause reverting of resolution switch.
Instead of the earlier suppressResizeEvents_ which was ugly but had no issues from it.
There was a problem hiding this comment.
And as for what the fix was. Honestly not completely sure.
If I worked on it by hand I would've had a eureka moment when it started working correctly.
My process is I prompt AI about issue, it reads code and reasons about it, makes changes, then I build, run and test, repeat.
AI doesn't get direct feedback except follow up prompts and toolcall results. It's a visual game it's not ideal to feed back to AI.
I suppose if AI could see and validate results directly then it could make more precise changes. Or a separate test program that proves correct implementation as resolution switching has proven quirky in both s25edit and s25client.
Anyway I kinda like it minimal and limited access and it's working mostly fine like this.
There was a problem hiding this comment.
The problem is that if we don't know what exactly caused and/or fixed the issue we cannot apply it to e.g. s25client or document it in code such that not in 2yrs someone sees strange code and decides to remove it.
I guess that if you try to change parts of this commit or ask your AI about what actually caused the fix and change that (with AI or manually) you'd get your eureka moment and we the fix for s25client ;-)
If it's too much work then we'll just need to keep it as-is
There was a problem hiding this comment.
I can do it again in s25client with AI or we can make a small test program that reproduces and validates best practice.
Wayland doesn't even allow apps to change native monitor resolution, it instead rescales them, presumably in hardware. Which is also what modern LCD monitors do.
If you want to keep improving res switching I can make a standalone test program for this purpose.
There was a problem hiding this comment.
If you can let your AI reduce the editor to a simple reproducer and minimal fix based on that commit that would great, yes. Like: Create fullscreen window with 2 textures, could be just red and blue where one rightclick you draw the other one and on leftclick you change the resolution. I expect this to be ~100 lines with most of it copied from s25edit.
There was a problem hiding this comment.
Also it can automatically proceed resolution switch, get window events, log what actually happened/didn't happen.
For us humans it might be extra work. For the AI it will save a lot of tokens making a tiny program it can work out without all the surrounding complexity in context.
|
Awesome. I'm also thinking. each UI component still draws to SDL_Surface, this was just to make changes smaller and the surfaces are small and have minimal penalty. |

Smallest possible step into OpenGL.
Terrain editor and UI components remain SDL/SGE/2D.
Tried to optimize for review by not maknig any refactorings.
Otherwise I might try to move closer to how s25client does things but that causes much bigger and messier PRs.
Don't have any experience with OpenGL I expect a lot of feedback.
Trying to improve and refactor usually ballons the size of the branch. Not sure what to improve other than what the AI gaslights me to think.