|
|
|
@ -7,6 +7,7 @@ using System.Runtime.InteropServices; |
|
|
|
using Avalonia; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.OpenGL; |
|
|
|
using Avalonia.Platform.Interop; |
|
|
|
using Avalonia.Threading; |
|
|
|
using static Avalonia.OpenGL.GlConsts; |
|
|
|
// ReSharper disable StringLiteralTypo
|
|
|
|
@ -88,6 +89,7 @@ namespace ControlCatalog.Pages |
|
|
|
private int _vertexBufferObject; |
|
|
|
private int _indexBufferObject; |
|
|
|
private int _vertexArrayObject; |
|
|
|
private GlExtrasInterface _glExt; |
|
|
|
|
|
|
|
private string GetShader(bool fragment, string shader) |
|
|
|
{ |
|
|
|
@ -255,6 +257,7 @@ namespace ControlCatalog.Pages |
|
|
|
protected unsafe override void OnOpenGlInit(GlInterface GL, int fb) |
|
|
|
{ |
|
|
|
CheckError(GL); |
|
|
|
_glExt = new GlExtrasInterface(GL); |
|
|
|
|
|
|
|
Info = $"Renderer: {GL.GetString(GL_RENDERER)} Version: {GL.GetString(GL_VERSION)}"; |
|
|
|
|
|
|
|
@ -294,8 +297,8 @@ namespace ControlCatalog.Pages |
|
|
|
GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, new IntPtr(_indices.Length * sizeof(ushort)), new IntPtr(pdata), |
|
|
|
GL_STATIC_DRAW); |
|
|
|
CheckError(GL); |
|
|
|
_vertexArrayObject = GL.GenVertexArray(); |
|
|
|
GL.BindVertexArray(_vertexArrayObject); |
|
|
|
_vertexArrayObject = _glExt.GenVertexArray(); |
|
|
|
_glExt.BindVertexArray(_vertexArrayObject); |
|
|
|
CheckError(GL); |
|
|
|
GL.VertexAttribPointer(positionLocation, 3, GL_FLOAT, |
|
|
|
0, vertexSize, IntPtr.Zero); |
|
|
|
@ -312,12 +315,12 @@ namespace ControlCatalog.Pages |
|
|
|
// Unbind everything
|
|
|
|
GL.BindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
|
|
|
GL.BindVertexArray(0); |
|
|
|
_glExt.BindVertexArray(0); |
|
|
|
GL.UseProgram(0); |
|
|
|
|
|
|
|
// Delete all resources.
|
|
|
|
GL.DeleteBuffers(2, new[] { _vertexBufferObject, _indexBufferObject }); |
|
|
|
GL.DeleteVertexArrays(1, new[] { _vertexArrayObject }); |
|
|
|
_glExt.DeleteVertexArrays(1, new[] { _vertexArrayObject }); |
|
|
|
GL.DeleteProgram(_shaderProgram); |
|
|
|
GL.DeleteShader(_fragmentShader); |
|
|
|
GL.DeleteShader(_vertexShader); |
|
|
|
@ -334,7 +337,7 @@ namespace ControlCatalog.Pages |
|
|
|
|
|
|
|
GL.BindBuffer(GL_ARRAY_BUFFER, _vertexBufferObject); |
|
|
|
GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferObject); |
|
|
|
GL.BindVertexArray(_vertexArrayObject); |
|
|
|
_glExt.BindVertexArray(_vertexArrayObject); |
|
|
|
GL.UseProgram(_shaderProgram); |
|
|
|
CheckError(GL); |
|
|
|
var projection = |
|
|
|
@ -365,5 +368,34 @@ namespace ControlCatalog.Pages |
|
|
|
if (_disco > 0.01) |
|
|
|
Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background); |
|
|
|
} |
|
|
|
|
|
|
|
class GlExtrasInterface : GlInterfaceBase<GlInterface.GlContextInfo> |
|
|
|
{ |
|
|
|
public GlExtrasInterface(GlInterface gl) : base(gl.GetProcAddress, gl.ContextInfo) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
public delegate void GlDeleteVertexArrays(int count, int[] buffers); |
|
|
|
[GlMinVersionEntryPoint("glDeleteVertexArrays", 3,0)] |
|
|
|
[GlExtensionEntryPoint("glDeleteVertexArraysOES", "GL_OES_vertex_array_object")] |
|
|
|
public GlDeleteVertexArrays DeleteVertexArrays { get; } |
|
|
|
|
|
|
|
public delegate void GlBindVertexArray(int array); |
|
|
|
[GlMinVersionEntryPoint("glBindVertexArray", 3,0)] |
|
|
|
[GlExtensionEntryPoint("glBindVertexArrayOES", "GL_OES_vertex_array_object")] |
|
|
|
public GlBindVertexArray BindVertexArray { get; } |
|
|
|
public delegate void GlGenVertexArrays(int n, int[] rv); |
|
|
|
|
|
|
|
[GlMinVersionEntryPoint("glGenVertexArrays",3,0)] |
|
|
|
[GlExtensionEntryPoint("glGenVertexArraysOES", "GL_OES_vertex_array_object")] |
|
|
|
public GlGenVertexArrays GenVertexArrays { get; } |
|
|
|
|
|
|
|
public int GenVertexArray() |
|
|
|
{ |
|
|
|
var rv = new int[1]; |
|
|
|
GenVertexArrays(1, rv); |
|
|
|
return rv[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|