@@ -820,6 +820,35 @@ static SceGxmTextureAddrMode TranslateAddressMode(SDL_TextureAddressMode mode)
820
820
}
821
821
}
822
822
823
+ static void ClampCliprectToViewport (SDL_Rect * clip , const SDL_Rect * viewport )
824
+ {
825
+ int max_x_v , max_y_v , max_x_c , max_y_c ;
826
+
827
+ if (clip -> x < 0 ) {
828
+ clip -> w += clip -> x ;
829
+ clip -> x = 0 ;
830
+ }
831
+
832
+ if (clip -> y < 0 ) {
833
+ clip -> h += clip -> y ;
834
+ clip -> y = 0 ;
835
+ }
836
+
837
+ max_x_c = clip -> x + clip -> w ;
838
+ max_y_c = clip -> y + clip -> h ;
839
+
840
+ max_x_v = viewport -> x + viewport -> w ;
841
+ max_y_v = viewport -> y + viewport -> h ;
842
+
843
+ if (max_x_c > max_x_v ) {
844
+ clip -> w -= (max_x_v - max_x_c );
845
+ }
846
+
847
+ if (max_y_c > max_y_v ) {
848
+ clip -> h -= (max_y_v - max_y_c );
849
+ }
850
+ }
851
+
823
852
static bool SetDrawState (VITA_GXM_RenderData * data , const SDL_RenderCommand * cmd )
824
853
{
825
854
SDL_Texture * texture = cmd -> data .draw .texture ;
@@ -863,8 +892,12 @@ static bool SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd
863
892
}
864
893
865
894
if ((data -> drawstate .cliprect_enabled || data -> drawstate .viewport_is_set ) && data -> drawstate .cliprect_dirty ) {
866
- const SDL_Rect * rect = & data -> drawstate .cliprect ;
867
- set_clip_rectangle (data , rect -> x , rect -> y , rect -> x + rect -> w , rect -> y + rect -> h );
895
+ SDL_Rect rect ;
896
+ SDL_copyp (& rect , & data -> drawstate .cliprect );
897
+ if (data -> drawstate .viewport_is_set ) {
898
+ ClampCliprectToViewport (& rect , & data -> drawstate .viewport );
899
+ }
900
+ set_clip_rectangle (data , rect .x , rect .y , rect .x + rect .w , rect .y + rect .h );
868
901
data -> drawstate .cliprect_dirty = false;
869
902
}
870
903
0 commit comments