Setting up an OpenGL surface with MSAA on Windows

153 views
Skip to first unread message

Ian Waters

unread,
Sep 29, 2023, 3:44:01 AM9/29/23
to skia-discuss
Hi all,
I’m wondering if anyone could shed some light on why the following works on macOS, but not on Windows.

* I’ve removed all error checking for brevity.
* The context and target both look to create correctly (they pass validity tests).
* In the below m_msaaSamples is set to 4.
* The error comes with generating the Surface (SkSurface::MakeFromBackendRenderTarget), this just silently fails.

I would appreciate any tips 🫠

// glfw setup
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// … creating window/ making context current omitted.

// Configure Multisample Renderbuffer for color attachment
GLuint msaaColorRBO;
glGenRenderbuffers(1, &msaaColorRBO);
glBindRenderbuffer(GL_RENDERBUFFER, msaaColorRBO);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_msaaSamples, GL_RGBA8, width,
height);

// Configure depth and stencil buffers as an RBO
glGenRenderbuffers(1, &m_rbo);
glBindRenderbuffer(GL_RENDERBUFFER, m_rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_msaaSamples,
GL_DEPTH24_STENCIL8, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);

// Configure FBO
glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
msaaColorRBO);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, m_rbo);

glBindFramebuffer(GL_FRAMEBUFFER, 0);

// Configure color buffers as 2D Texture for resolving
glGenTextures(1, &m_tex2d);
glBindTexture(GL_TEXTURE_2D, m_tex2d);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_INT_8_8_8_8, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);

auto options = GrContextOptions();
options.fShaderErrorHandler = &gLogShaderErrorHandler;
options.fSuppressPrints = false;
options.fSkipGLErrorChecks = GrContextOptions::Enable::kNo;
m_context = GrDirectContext::MakeGL(options);

auto target = GrBackendRenderTarget(width, height, m_msaaSamples, 8, {m_fbo, GL_RGBA8});

glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);

// This call silently fails
m_surface = SkSurface::MakeFromBackendRenderTarget(
m_context.get(),
target,
kBottomLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
nullptr,
nullptr);

Greg Daniel

unread,
Sep 29, 2023, 7:29:38 AM9/29/23
to skia-discuss
First quick glance nothing is sticking out to me as wrong. Have you tried stepping through SkSurface::MakeFromBackendRenderTarget to see where it is failing?

I assume in the removed error checking you have confirmed the color and stencil buffers are getting created and bound to an fbo without errors?

Also do you need the MSAA color buffer yourself on the non skia side of things? If you just want skia to use MSAA for rendering an easier approach could be too just create a single sampled GLTexture and then wrap that with a GrBackendTexture, and pass in a requested sample count in the SkSurface wrap call. But either approach should work.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/A102B3A8-C482-45EC-9A7B-B2E9DC882552%40gmail.com.

Ian Waters

unread,
Sep 29, 2023, 9:13:45 AM9/29/23
to skia-d...@googlegroups.com
Greg you absolute legend; it’s all is sorted and working now. 

I never even realised you could set up MSAA via a GLTexture that way, what an excellent abstraction and a wonderful way to end the week.

Thanks again!


Reply all
Reply to author
Forward
0 new messages