-
-
Notifications
You must be signed in to change notification settings - Fork 17
[OGC] Add support for Custom Aspect Ratios #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ogc-sdl-2.28
Are you sure you want to change the base?
Conversation
I believe this is now ready for review |
Stuff was setting the viewport and scissor to 854 Renderer now only adjusts projection if it's trying to set the viewport to 640*480 (this feels like not the intended way but I haven't found a better one)
Co-authored-by: Alberto Mardegan <[email protected]>
Fix 4:3 Make mouse actually unstreched on 16:9 Fix SDL_DisplayMode 16:9 width (for real this time)
Btw there's something wrong with the code for centering the window, on widescreen VVVVVVV is setting the window x pos to 207, seems related to SDL_WINDOWPOS_CENTERED_DISPLAY (the x was smaller when I sent the picture above but it changed and I haven't found out why ) |
Makes sense! |
By the way just curious, why did you use the std lib directly for OGC_JoystickInit? I thougth that SDL was meant to use the SDL stdlib (as in getenv and strcmp instead of SDL_getenv and SDL_strcmp like the rest of the lib) |
Because who doesn't want to make a Wii App that outputs at 21:9?
By the way, something that is really bothering me is that when I set the window to widescreen the mouse starts having pixels jitter, like depending where it is some pixels get cut off in one of the sides |
SDL is trying to be as portable as possible, so it redefines these functions to allow platforms to reimplement them, if needed. But for us it just introduces a slow-down, since while the stdlib functions can be optimized away from the compiler, the SDL equivalent can not (that's my guess, at least, since it does not know them). I would suggest avoiding them, unless you are writing code in the SDL common modules and you plan to submit it upstream. |
src/video/ogc/SDL_ogcmouse.c
Outdated
if (aspect_w > 4.0f && aspect_h > 3.0f) | ||
OGC_load_texture(curdata->texels, curdata->w, curdata->h, GX_TF_RGBA8, | ||
SDL_ScaleModeLinear); | ||
else | ||
OGC_load_texture(curdata->texels, curdata->w, curdata->h, GX_TF_RGBA8, | ||
SDL_ScaleModeNearest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this does, and I'm not sure that the if
is correct (what if the ratio is 3:2? -- by the way, for this type of checks it appears that using a single float for the aspect ratio instead of two ints would be better).
Note that the scaling is done either by the TV or by the VI interface, so I don't think we should be changing how the texture is being filtered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cursor looks very jittery on other aspect ratios, so I changed it to Linear since it wouldn't be as noticeable, but it's still noticeable and I have no idea why it's cutting pixels from the image depending on where it is
src/video/ogc/SDL_ogcmouse.c
Outdated
|
||
guMtxIdentity(mv); | ||
guMtxScaleApply(mv, mv, screen_w / 640.0f, screen_h / 480.0f, 1.0f); | ||
guMtxScaleApply(mv, mv, screen_w / (480.0f * aspect_w / aspect_h), screen_h / 480.0f, 1.0f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot do this on the modelview matrix, because then you are actually changing the cursor width, and then if the cursor then gets rotated it will appear wrong. I think that all this code should stay unchanged, and we should only operate on how the OGX_set_viewport function gets called.
It sounds a bit silly, since it was me who introduces this scaling, but looking at it now, it appears wrong: we already have the viewport to do the scaling; can you try to just remove this line?
And in the call to OGC_set_viewport() below, we should probably pass the EFB dimensions, not the screen dimensions adjusted for the aspect ratio (at least if you follow my suggestion about retrieving the aspect ratio from OGC_set_viewport).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would I retrieve the aspect ratio from the viewport function tough? I stopped doing a different width for the matrix because it's more correct, an app will look right if it's widescreen
If an app doesn't try to use widescreen, doing work arounds so maybe it'll look right felt wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i made the resize be sceen height dependant
src/video/ogc/SDL_ogcvideo.c
Outdated
@@ -157,6 +167,20 @@ static void setup_video_mode(_THIS, GXRModeObj *vmode) | |||
{ | |||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; | |||
|
|||
// TODO: Should I make this only happen if the aspect ratio isn't 4:3? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To simplify things I suggest forgetting about the VI changes for now (have them in a separate PR later), because handing of the CONF_GetAspectRatio() is a bit orthogonal to setting the best video mode. It will make testing and reviewing easier, if we tackle one issue at a time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
GX_SetViewport(x, y, (w > 640) ? 640 : w, h, 0, 1); | ||
GX_SetScissor(x, y, (w > 640) ? 640 : w, h); | ||
|
||
// matrix, t, b, l, r, n, f | ||
guOrtho(proj, 0, h, 0, w, 0, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that GX_SetViewport and GX_SetScissor can be set to the EFB size (that is, we can consider w
and h
to be in pixels), and if we want to play with the aspect ratio we can play with the width parameter passed to guOrtho.
In other words, I would set leave the calls to GX_SetViewport and GX_SetScissor exactly as they were, then call OGC_get_aspect_ratio_dimensions right from within this function and call
const float ratio4_3 = 4.0f / 3.0f;
guOrtho(proj, 0, h, 0, w * ratio / ratio4_3, 0, 1);
Of course, this needs to be checked. :-) The thing is, if you pass the same values to both functions (GX_SetViewport and guOrtho) you get a 1:1 mapping, which is not what we want for widescreen cases (or for any case where the ratio is not 4/3).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave up aspect correcting apps that aren't using 16:9
Fixing this here would cause issues, as I've showed before it makes VVVVVVV less wide than it should.
The whole guOrtho thing being a new var really felt like a hack, and I think leaving it as is is the best approach, especially since some apps resize the viewport twice every frame and it will distort the image more than it should if we do it
I just tested Wii screen on my TV |
So since I can't just correct all viewports, what changes do I need to do appart from aspect ratio caching? |
I've been quiet on the last few days because I've got several conflicting thoughts, and I'm not even sure what the original problem is (or maybe, there's more than one). I've wanted to test this myself, but I'm busy with some other stuff now, so I've to wait a few more days to get my hands on this. Meanwhile, if you have time, you might be able to answer this question: how does the TV detects aspect ratio? If the TV is set to auto-detect the aspect ratio, is it possible from the Wii to set the mode in such a way that the TV detects it with the aspect ratio we want (4:3 and 16:9 only, obviously)? As for the cursor being cut, well, that is because you are shrinking the image in order to compensate for the stretching operated by the TV set. I think that your change which sets the interpolation mode to linear should fix it, doesn't it? |
It's understandable to not have time The cursor being set to linear made it be less noticeable but not 100% like it should, the homebrew channel cursor behaves much less weirdly |
Any chance for a new review of this? |
that should be depended @mardy i think. they are basically the sdl->ogc expert here i think :p |
src/video/ogc/SDL_ogcvideo.c
Outdated
vmode->viWidth = VI_MAX_WIDTH_NTSC; // VI_MAX_WIDTH is the same for all regions | ||
// set Center point | ||
if (VI_FORMAT_FROM_MODE(vmode->viTVMode) == VI_PAL) { | ||
vmode->viXOrigin = (VI_MAX_WIDTH_PAL - vmode->viWidth) / 2; | ||
vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - vmode->viHeight) / 2; | ||
} else { | ||
vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth) / 2; | ||
vmode->viYOrigin = (VI_MAX_HEIGHT_NTSC - vmode->viHeight) / 2; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look correct: why are we setting the width to the max here? What if an application wants to have a 4:3 ratio and is therefore fine with viWidth and viHeight set to 640x480?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, actually, this is correct, but only if the Wii conf setting for the aspect ratio is set to 16:9. Do you agree, @Fancy2209 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? It's been so long I don't remeber why I did this change 😅
Oh, actually now I would have some time to test this, so thanks for the ping :-) By the way do you have some tests apps for this, or did you only try with VVVVVV? |
I used Neverball and had a Raylib Hello World sample working with it |
Should I make a test app? |
That would be helpful indeed! |
How would I allow the aspect ratio to be changed if that has to happen before init though? |
Just hardcode an aspect ratio, build the app, save it under a different name, change the aspect ratio in the code, build again :-) So we get two apps we can test. |
ah I see |
I would only care about 4:3 and 16:9, personally. |
Fair |
Description
Adds a video mode for widescreen
Existing Issue(s)
Fixes #73