Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] GPU acceleration makes canvas background go black #1875

Open
CluckCluckChicken opened this issue Nov 29, 2021 · 2 comments
Open

Comments

@CluckCluckChicken
Copy link

CluckCluckChicken commented Nov 29, 2021

This is quite a long question.

Drawing with GPU acceleration makes canvas background black (regardless of flushed or not), and SKSurface.Snapshot() is empty after second SKCanvas.Flush().

I am creating an SKCanvas like this:

private GRGlInterface grGlInterface;
private GRContext grContext;
private GRBackendRenderTarget renderTarget;

private SKSurface surface;
protected SKCanvas canvas;

...

grGlInterface = GRGlInterface.Create();
grContext = GRContext.CreateGl(grGlInterface);
renderTarget = new((int)size.x, (int)size.y, 0, 8, new GRGlFramebufferInfo(0, 0x8058));

surface = SKSurface.Create(grContext, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
canvas = surface.Canvas;

And rendering to it like this:

canvas.Clear();

using SKPaint primary = new SKPaint();
primary.Color = SKColor.Parse("#1abc9c");
primary.IsAntialias = true;

using SKRoundRect rect = new SKRoundRect(new(0, 0, 140, 40), 15f);
canvas.DrawRoundRect(rect, primary);

canvas.Flush();

Then finally drawing it to another canvas that uses a Silk.NET GLFW window GLContext:

using SKImage image = surface.Snapshot();
target.DrawImage(image, position);

After the first render (the red circled area is the entire canvas is having the problem. the other canvas is the entire window):
image
After the second render:
image

If I take SKSnapshot straight after second flush, the snapshot is empty, but if I do the drawing-and-flushing process multiple times at some other point in the program and not directly before the snapshot, there isn't an issue.

@CluckCluckChicken
Copy link
Author

CluckCluckChicken commented Nov 30, 2021

I'm now using SKSurface.Draw() instead of Snapshot but the problems persist.

@taublast
Copy link
Contributor

taublast commented Feb 26, 2024

Just a quick thought maybe in some specific cases when canvas.Clear(); passes a transparent color somewhere internally it treats it as Black instead of Transparent.
That empty second frame makes me think of double-buffering where the second buffer was shown but not filled..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants