Black Screen When Drawing on SkSurface after Creating Texture in Skia with OpenGL Context

172 views
Skip to first unread message

stephane

unread,
Feb 21, 2024, 12:18:12 PM2/21/24
to skia-discuss
I am working on an OpenGL and Skia integration in my application, and I'm encountering an issue where the screen remains black when I try to draw on SkSurface. Here's a simplified version of my setup:

Lcontext = eglCreateContext(...);
LSurface = eglCreatePbufferSurface(...);
eglMakeCurrent(LDisplay, Lsurface, Lcontext);
LGrDirectContext = GrDirectContext::MakeGl(...);

// Code where the issue seems to arise
LGrBackEndTexture = grdirectcontext::createtexture(LGrDirectContext, ...);
sksurface::makefromtexture(LGrDirectContext, LGrBackEndTexture, ...);

LMainSurface = eglCreateWindowSurface(...);
eglMakeCurrent(LDisplay, Lsurface, Lcontext);
eglSwapInterval(LDisplay, 1);

LGrBackendRenderTarget = GrBackendRenderTarget::CreateGl(...);
FBackBufferSurface = SkSurface.MakeFromRenderTarget(LGrDirectContext, LGrBackendRenderTarget);

When I try to paint on SkSurface, nothing is shown on the screen, only a black screen appears. However, if I remove the following lines:

LGrBackEndTexture = grdirectcontext::createtexture(LGrDirectContext, ...);
sksurface::makefromtexture(LGrDirectContext, LGrBackEndTexture, ...);

everything works fine, and I can see the rendered content.

Could someone help me understand why this is happening? Is there a problem with how I am creating and using the texture with Skia? Or is it an issue related to the OpenGL context state or the way Skia integrates with it?

Any insights or suggestions would be greatly appreciated!

Greg Daniel

unread,
Feb 21, 2024, 1:40:18 PM2/21/24
to skia-d...@googlegroups.com
Which SkSurface are you drawing to? FBackBufferSurface? What FBO id are you passing into GrBackendRenderTarget::CreateGl?

Is it the intention that the two lines you removed shouldn't be doing anything? Because reading the code I don't believe they should be doing anything (which then is weird why having them in there makes things not draw).

--
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/28e5b2af-75d6-469c-8bc5-da52bacb1869n%40googlegroups.com.

stephane

unread,
Feb 21, 2024, 6:06:08 PM2/21/24
to skia-discuss
Thanks!

I draw on the FBackBufferSurface, which is bound to the native windows. Regarding the FBO, here's what I do (I'm using Android):

glGetIntegerv(GL_FRAMEBUFFER_BINDING, @GLuint(LGrGlFramebufferInfo.FBOID));
LGrGlFramebufferInfo.Format := GL_RGBA8_OES;
LGrBackendRenderTarget := TGrBackendRenderTarget.CreateGl(Width, Height, .... , LGrGlFramebufferInfo);

This issue is driving me crazy because I can't understand where the problem lies. When the app starts, and the main SKSurface (i.e., FBackBufferSurface) has not yet been created, at this point, I simply create an off-screen GPU surface ( sksurface::makefromtexture) . I don't do anything with it, but later, when I create the main SKSurface (FBackBufferSurface)  and try to render on it, I only get a black screen.

* If I create this off-screen GPU surface and then immediately destroy it, everything works fine later when I try to render on the main GPU surface.
* If I create this off-screen GPU surface after the main SKSurface is created, then everything also works fine.

What could be the reason that creating an off-screen GPU surface very early in the app's lifecycle breaks the rendering on the future main SKSurface?
Reply all
Reply to author
Forward
0 new messages