AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
24.76k stars 2.15k forks source link

glDebugMessageCallback for GLControl #6045

Open Darxoon opened 3 years ago

Darxoon commented 3 years ago

Is your feature request related to a problem? Please describe. I'm making a program where I embed an OpenGL Canvas using OpenGlControlBase. Debugging in OpenGL is pretty frustrating because you have to check for errors after every GL call and only get an error code back. An alternative to this is the function glDebugMessageCallback that got introduced in OpenGL 4.3. When an error occurs, it calls the callback given to the function with an error message, which is a lot easier to debug. However, Avalonia doesn't support this function at all.

Describe the solution you'd like Add the method GlInterface.DebugMessageCallback(DebugProc callback, object or IntPtr userParam) for OpenGL versions 4.3 and above, which is an alias for the OpenGL function glDebugMessageCallback. The type DebugProc should be a delegate with the parameters int source, int type, int id, int severity, IntPtr length, string message, object or IntPtr userParam. Where I wrote object or IntPtr, I'm not sure which option would be better.

Describe alternatives you've considered Using GlInterface.GetError is an alternative but not comparable in usability against glDebugMessageCallback.

Additional context https://docs.gl/gl4/glDebugMessageCallback

CalvinWilkinson commented 11 months ago

I also think this would be a good thing to provide in some capacity. It would not be too hard to implement.

Maybe add this as an override on the 'OpenGlControlBase' control so users can choose to use it or not? I think it would be nice for the incoming parameters to have the error code and message be returned as a string already without having to marshal the string.

maxkatz6 commented 11 months ago

In general, our GlInterface class is intended to be used internally for Avalonia needs, while it might not provide all APIs needed for consumers. Instead, we do recommend using OpenGlControlBase together with libraries like Silk.NET or manual bindings to opengl.

Maybe add this as an override on the 'OpenGlControlBase' control

But extending OpenGlControlBase with some debug information can be useful, right. If you have a specific API proposal.

CalvinWilkinson commented 11 months ago

In general, our GlInterface class is intended to be used internally for Avalonia needs, while it might not provide all APIs needed for consumers. Instead, we do recommend using OpenGlControlBase together with libraries like Silk.NET or manual bindings to opengl.

Maybe add this as an override on the 'OpenGlControlBase' control

But extending OpenGlControlBase with some debug information can be useful, right. If you have a specific API proposal.

I agree with the control. I think it is pretty much already what anybody would need to do anything they need with OpenGL. I myself have already rendered textures by "hooking" in my project Velaptor.

I am indeed using Silk.NET by doing:

this.gl = GL.GetAPI(gl.GetProcAddress);

As for the API proposal, I was thinking somewhere along the lines of this below:

// The severity of the error
public enum GLErrorSeverity
{
    Low,
    Medium,
    High,
    Notification
}

// Invoked every time there is an opengl error
public virtual void OnOpenGLError(string errorMessage, int errorCode, GLErrorSeverity errorSeverity)
{
}