Skip to content

SDL3 OpenGL shared context with no stencil bits prevents stencil usage in window OpenGL context with stencil bits -- intended? #12787

@vittorioromeo

Description

@vittorioromeo

Is it normal that if I have a hidden base shared SDL OpenGL context with SDL_GL_STENCIL_SIZE=0 and then I create a window with its own SDL OpenGL context (that shares the base one) with SDL_GL_STENCIL_SIZE=8, then stencil testing doesn't work at all?

I also need to set the stencil size of the shared context to 8, but that doesn't make much sense as I'm not creating/using any framebuffer on the shared context.

As an additional data point, when recreating the same situation under SFML 3.x, the behavior is as I expect -- the shared context doesn't need to set any stencil or depth bits, and as long as the window context sets the correct amount, it works properly. SFML's internals also pass 0 to the shared context settings, so this seems like a SDL quirk.

Is it intended or a bug?


This is how I create my hidden base shared context:

SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
// ...other attributes...

// Create a hidden window for the context
m_window = SDL_CreateWindow("", 1, 1, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
if (m_window == nullptr) { /* ...error handling... */ }

// Create the OpenGL context
m_context = SDL_GL_CreateContext(m_window);
if (!m_context) { /* ...error handling... */ }

And this is how I create my window context:

SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
// ...other attributes...

// Activate shared context
SDL_GL_MakeCurrent(sharedCtx->m_window, sharedCtx->m_context);
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);

// ...create window...

// Create the OpenGL context
m_context = SDL_GL_CreateContext(m_window);
if (!m_context) { /* ...error handling... */ }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions