Skip to content

Commit 7f07fe1

Browse files
authored
ogc: add OpenGL stencil support (#86)
* ogc: add OpenGL stencil support opengx needs to be informed if a stencil buffer is desired (and about its desired depth, too). Also inform opengx when we want to swap a frame, to ensure that the drawing buffer is currently selected (and not the stencil one).
1 parent 76b9c04 commit 7f07fe1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/video/ogc/SDL_ogcgl.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,26 @@ void __attribute__((weak)) ogx_initialize(void)
4343
"%s() called but opengx not used in build!", __func__);
4444
}
4545

46+
void __attribute__((weak)) ogx_stencil_create(OgxStencilFlags)
47+
{
48+
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO,
49+
"%s() called but opengx not used in build!", __func__);
50+
}
51+
4652
void __attribute__((weak)) *ogx_get_proc_address(const char *)
4753
{
4854
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO,
4955
"%s() called but opengx not used in build!", __func__);
5056
return NULL;
5157
}
5258

59+
int __attribute__((weak)) ogx_prepare_swap_buffers()
60+
{
61+
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO,
62+
"%s() called but opengx not used in build!", __func__);
63+
return 0;
64+
}
65+
5366
int SDL_OGC_GL_LoadLibrary(_THIS, const char *path)
5467
{
5568
return 0;
@@ -71,6 +84,11 @@ SDL_GLContext SDL_OGC_GL_CreateContext(_THIS, SDL_Window * window)
7184
context->window = window;
7285
context->swap_interval = 1;
7386
ogx_initialize();
87+
if (_this->gl_config.stencil_size > 0) {
88+
OgxStencilFlags flags = 0; /* Don't care if Z gets dirty on discarded fragments */
89+
if (_this->gl_config.stencil_size > 4) flags |= OGX_STENCIL_8BIT;
90+
ogx_stencil_create(flags);
91+
}
7492
return context;
7593
}
7694

src/video/ogc/SDL_ogcvideo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include <ogc/system.h>
4343
#include <ogc/video.h>
4444

45+
#include <opengx.h>
46+
4547
#define DEFAULT_FIFO_SIZE 256 * 1024
4648

4749
// Inverse of the VI_TVMODE macro
@@ -343,6 +345,8 @@ void OGC_video_flip(_THIS, bool vsync)
343345
SDL_VideoData *videodata = _this->driverdata;
344346
void *xfb = OGC_video_get_xfb(_this);
345347

348+
if (ogx_prepare_swap_buffers() < 0) return;
349+
346350
#ifdef __wii__
347351
OGC_draw_cursor(_this);
348352
#endif

0 commit comments

Comments
 (0)