Skip to content

Commit deb8ab4

Browse files
committed
ogc: reset cull mode, Z-buffering and alpha compare when drawing cursor
OpenGX might have set the GPU to perform Z-buffering, triangle culling and alpha compare in such a way that our mouse cursor will not be drawn. For that reason, reset them to ensure that our cursor will always be drawn. Extra care must be put to restore these registers to the same state in which SDL had set them before, in order not to break 2D applications.
1 parent f1d4573 commit deb8ab4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/video/ogc/SDL_ogcmouse.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "SDL_ogcpixels.h"
3232

3333
#include "../SDL_sysvideo.h"
34+
#include "../../render/SDL_sysrender.h"
3435

3536
#include <malloc.h>
3637
#include <ogc/cache.h>
@@ -203,6 +204,8 @@ void OGC_draw_cursor(_THIS)
203204
guMtxTransApply(mv, mv, mouse->x, mouse->y, 0);
204205
GX_LoadPosMtxImm(mv, GX_PNMTX1);
205206

207+
OGC_set_viewport(0, 0, screen_w, screen_h);
208+
206209
GX_ClearVtxDesc();
207210
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
208211
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
@@ -214,12 +217,28 @@ void OGC_draw_cursor(_THIS)
214217
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
215218
GX_SetNumTevStages(1);
216219
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
220+
GX_SetZMode(GX_DISABLE, GX_ALWAYS, GX_FALSE);
221+
GX_SetCullMode(GX_CULL_NONE);
222+
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
223+
217224

218225
GX_SetNumTexGens(1);
219226
GX_SetCurrentMtx(GX_PNMTX1);
220227
draw_cursor_rect(curdata);
221228
GX_SetCurrentMtx(GX_PNMTX0);
222229
GX_DrawDone();
230+
231+
/* Restore default state for SDL (opengx restores it at every frame, so we
232+
* don't care about it) */
233+
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
234+
if (_this->windows) {
235+
/* Restore previous viewport for the renderer */
236+
SDL_Renderer *renderer = SDL_GetRenderer(_this->windows);
237+
if (renderer) {
238+
OGC_set_viewport(renderer->viewport.x, renderer->viewport.y,
239+
renderer->viewport.w, renderer->viewport.h);
240+
}
241+
}
223242
}
224243

225244
#endif /* SDL_VIDEO_DRIVER_OGC */

0 commit comments

Comments
 (0)