Hey,
I'm trying to wrap an existing GLuint texture created in Unity. Everything works as expected, except it only draws the first frame, and subsequent frames do not update, the texture remains static. Unless I recreate the GL interface and rebind everything each frame.
Since I'm new to C++, it seems to me that recreating a new surface each frame is not the correct approach.
Here is my simple setup, which only draws the first frame. Further frames do not render, even though the drawing function is called each frame.
static void UNITY_INTERFACE_API OnRenderEvent(int eventId)
{
if (!textureID || textureWidth == 0 || textureHeight == 0) {
return;
}
if (!skiaGrContext) {
// Initialize
sk_sp<const GrGLInterface> glInterface = GrGLMakeNativeInterface();
skiaGrContext = GrDirectContexts::MakeGL(glInterface);
GrGLTextureInfo textureInfo = GrGLTextureInfo();
textureInfo.fID = textureID;
textureInfo.fTarget = GL_TEXTURE_2D;
textureInfo.fFormat = GL_RGBA8;
GrBackendTexture backendTexture = GrBackendTextures::MakeGL(
textureWidth,
textureHeight,
skgpu::Mipmapped::kYes,
textureInfo,
"test"
);
skiaSurface = SkSurfaces::WrapBackendTexture(
skiaGrContext.get(),
backendTexture,
GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
0,
kRGBA_8888_SkColorType,
nullptr,
nullptr,
nullptr
);
}
else {
// Draw to the existing Skia surface
skiaCanvas = skiaSurface->getCanvas();
skiaCanvas->clear(SK_ColorBLACK);
SkPaint paint = SkPaint();
paint.setAntiAlias(true);
paint.setColor(SK_ColorRED);
skiaCanvas->drawCircle(SkPoint(), SkScalar(sin(unityTime) * 150), paint);
skiaGrContext.get()->flushAndSubmit(GrSyncCpu::kYes);
}
}
textureID is retrieved from Unity.
Is there anything am I missing? Any ideas what could be an issue?
Or rewrapping the texture each frame is a common practice?