Skip to content

Vita: Fixed absence of clipping when viewport is set #13194

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

Merged
merged 2 commits into from
Jun 20, 2025

Conversation

Wohlstand
Copy link
Contributor

Resolves a problem of viewport on the Vita set by SDL_RenderSetViewport() that doesn't sets any clipping by default.

How it looked before the fix:
изображение

How it supposed to look everywhere (after fix):
изображение

Description

This solution sets the cliprect in shadow when real cliprect is unused. And when cliprect gets reset, the viewport's rect gets set when viewport is set (the width and height gets compared to the size of the drawable area such as screen or texture).

Existing Issue(s)

#13034

@Wohlstand Wohlstand force-pushed the fix-vita-viewport branch from 43b4d75 to c433cbf Compare June 8, 2025 22:44
@ds-sloth
Copy link
Contributor

ds-sloth commented Jun 9, 2025

This fix is much better than the existing behavior, but I think it might not handle the case where a manually-specified clip rect is larger than the viewport.

@Wohlstand
Copy link
Contributor Author

This fix is much better than the existing behavior, but I think it might not handle the case where a manually-specified clip rect is larger than the viewport.

A good case, then it's need to cut down the clip rect when viewport is set, and rectangle is out of viewport's range.

@Wohlstand
Copy link
Contributor Author

@slouken, ping? I also made the limiting of the scope so true croprect will never go out of viewport's range. And I tested that behaviour on my end already. Now it should be ready to merge, but if any objections, please tell me what I should to change in the code, and I'll apply that as fast as possible.

@@ -826,6 +826,35 @@ static int VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
return 0;
}

static void ClamCliprectToViewport(SDL_Rect *clip, const SDL_Rect *viewport)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ClampCliprectToViewport?

Copy link
Collaborator

@slouken slouken Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just use SDL_GetRectIntersection()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downstream application is using SDL2 which I think doesn't currentlyinclude this routine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ClampCliprectToViewport?

I just forgot the word (you know I am not English speaker), ye, it was "clamp", not "clam" (which is a mollusk).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just use SDL_GetRectIntersection()?

If it does the same as my ClamCliprectToViewport, then I definitely should use that. Let me check that first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look what happens if just use SDL_IntersectRect in silly way without preparation of rects:
2025-06-20_22-13-56

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I checked this twice more, and result is still the same messy, it absolutely not what should be. Let me try to reformat my code so it can be better compared to yours...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s fine, I was just curious whether a rect intersection is what you were doing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is more specific, and it's required to do this very carefully, otherwise thing will glitch as I shown. In the scope of viewport, cliprect must be aligned to the viewport's 0, and then clamped in a different way. I just do subtract the difference of max points from the width, and that works just fine.

Copy link
Contributor Author

@Wohlstand Wohlstand Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, my summary:

  • Use of SDL_IntersectRect requires overcomplication outside to comply with the required output.
  • The current output of SDL_IntersectRect is totally not same as expected by the current logic.

The custom function was done in order to don't duplicate multiple modified rectangle copies and just use existing values of existing rectangles to fill the proper pre-computed result without overcopmlication.

Don't allow cliprect be larger than viewport's scope
@Wohlstand Wohlstand force-pushed the fix-vita-viewport branch from 85edf9c to 732a72f Compare June 19, 2025 01:13
@slouken slouken merged commit 6701f93 into libsdl-org:SDL2 Jun 20, 2025
35 checks passed
@slouken
Copy link
Collaborator

slouken commented Jun 20, 2025

I went ahead and merged this. Can you make a similar PR for SDL3?

@Wohlstand
Copy link
Contributor Author

I went ahead and merged this. Can you make a similar PR for SDL3?

Let me make an attempt...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants