-
Notifications
You must be signed in to change notification settings - Fork 555
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
Crash when trying to create surface from texture #413
Comments
@mattleibow I would really appreciate your help with this. |
Hi there... sorry about the delay - I had to edit the issue to show the code. It appears that angle brackets I had a look at this and I think I found out a few things. It appears that unlike the usual backend render target, the texture render target requires 2 pieces of information: struct GrGLTextureInfo {
GrGLenum fTarget;
GrGLuint fID;
}; As the description type only accepts an // declare the handle type
[StructLayout(LayoutKind.Sequential)]
public struct GRGlTextureInfo {
public uint Target;
public uint Id;
}
// create the handle
var textureInfo = new GRGlTextureInfo {
Id = (uint)textureId,
Target = (uint)TextureTarget.Texture2D
};
// pin the handle and pass it to the description
var textureHandle = GCHandle.Alloc(textureInfo, GCHandleType.Pinned);
var textureDesc = new GRBackendTextureDesc {
Width = textureSize.Width,
Height = textureSize.Height,
Config = GRPixelConfig.Rgba8888,
Flags = GRBackendTextureDescFlags.RenderTarget,
Origin = GRSurfaceOrigin.TopLeft,
SampleCount = 0,
TextureHandle = textureHandle.AddrOfPinnedObject(),
};
// create the SkiaSharp texture surface
textureSurface = SKSurface.CreateAsRenderTarget(context, textureDesc);
// free the pinned GC handle when we are done
textureHandle.Free(); Another thing I noticed was that I had to specify a texture image: textureId = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, textureId);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, textureSize.Width, textureSize.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); Here is my working sample: https://github.com/mattleibow/SkiaSharpTextures |
The work done in the commit will make textures much easier using the new var desc = new GRGlBackendTextureDesc {
...
TextureHandle = new GRGlTextureInfo {
Id = textureId,
Target = GL.Texture2D
}
};
var context = GRContext.Create(GRBackend.OpenGL);
var surface = SKSurface.CreateAsRenderTarget(context, desc); The pinning of the struct is now done automatically. |
Hi @mattleibow thank you very much for all your help. I still can't get it to work, though. Your sample shows nicely how to use skiasharp in a gamewindow (note that I had to upgrade OpenTK to 2.0 in your example otherwise it crashes, at least on mac), but it doesn't show how to actually combine normal rendering to OpenGL with skiasharp, and when I try that everything blows up. Working from your example (I'm working against your example, haven't tried the commit) I created an example trying to combine both drawing methods, here: https://github.com/tzachshabtay/SkiaSharpTextures I've taken the code you had in OnLoad and OnRenderFrame and refactored it to "PrepareSkia" and "DrawSkia" and then also added a "PrepareDirect" and "DrawDirect" to prepare a texture, buffer and shader and use it to draw a simple rectangle (I just use skia there to draw to a bitmap, but then draw it with glDrawElements). I've also added a "GL.Clear" call to the beginning of the render loop. Now, if I comment out "PrepareSkia" and DrawSkia", my OpenGL rectangle appear as expected. If I instead comment out "GL.Clear", "PrepareDirect" and "DrawDirect", your skia rendering appear as expected. If I uncomment stuff, noticed 3 problems:
|
I am closing this as I am not sure if skia can be mixed in with normal OpenGL drawing. I feel that this is possible, but might be better discussed on the skia forums: https://groups.google.com/forum/#!forum/skia-discuss In addition, it will also be better to open a issue that is specifically dedicated to any issues when mixing the drawings. |
I'm trying to create a surface from an OpenGL texture, and I'm trying to use an already existing OpenGL context (created by OpenTK's GameWindow).
I didn't really find any documentation on how to do that. I saw a test for
GRGlInterface.AssembleGlInterface
here: https://github.com/mono/SkiaSharp/blob/master/tests/Tests/GRGlInterfaceTest.cs, so I tried to use similar code for getting the existing context, no clue if that's how you actually should go about it.I didn't find anything on how to use
CreateAsRenderTarget
so I tried to guess.This is the code I used (currently on Mac only)
This is the error I'm getting (dialog box- mono crashed)
To reproduce:
Grab my code from this branch: https://github.com/tzachshabtay/MonoAGS/tree/SkiaSharp
From Visual Studio on Mac, run DemoQuest.Desktop. It will crash on startup.
The text was updated successfully, but these errors were encountered: