From 1301868269c916f7272c6d5a1bd7870b96f110d4 Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Sun, 28 Jul 2024 13:34:53 +0300 Subject: [PATCH] Remove old OpenGL bindings and just pull in OpenTK. --- Dashboard.OpenTK/OpenTKPlatform.cs | 16 +- Dashboard.OpenTK/OpenTKPort.cs | 3 +- Dashboard/Dashboard.csproj | 5 + Dashboard/OpenGL/GL.Buffer.cs | 77 --------- Dashboard/OpenGL/GL.Program.cs | 96 ----------- Dashboard/OpenGL/GL.Shader.cs | 110 ------------- Dashboard/OpenGL/GL.Texture.cs | 187 ---------------------- Dashboard/OpenGL/GL.Uniform.cs | 222 -------------------------- Dashboard/OpenGL/GL.VertexArray.cs | 78 --------- Dashboard/OpenGL/GL.cs | 128 --------------- Dashboard/OpenGL/GL21Driver.cs | 141 ++++++++-------- Dashboard/OpenGL/GLEnum.cs | 94 ----------- Dashboard/OpenGL/GraphicsException.cs | 16 +- 13 files changed, 93 insertions(+), 1080 deletions(-) delete mode 100644 Dashboard/OpenGL/GL.Buffer.cs delete mode 100644 Dashboard/OpenGL/GL.Program.cs delete mode 100644 Dashboard/OpenGL/GL.Shader.cs delete mode 100644 Dashboard/OpenGL/GL.Texture.cs delete mode 100644 Dashboard/OpenGL/GL.Uniform.cs delete mode 100644 Dashboard/OpenGL/GL.VertexArray.cs delete mode 100644 Dashboard/OpenGL/GL.cs delete mode 100644 Dashboard/OpenGL/GLEnum.cs diff --git a/Dashboard.OpenTK/OpenTKPlatform.cs b/Dashboard.OpenTK/OpenTKPlatform.cs index a025732..212cf18 100644 --- a/Dashboard.OpenTK/OpenTKPlatform.cs +++ b/Dashboard.OpenTK/OpenTKPlatform.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using OpenTK.Windowing.Desktop; -using OpenTK.Windowing.GraphicsLibraryFramework; using Dashboard.ImmediateDraw; using Dashboard.Media; -using Dashboard.OpenGL; using Dashboard.PAL; +using OpenTK.Graphics.OpenGL4; +using OpenTK.Windowing.Desktop; +using OpenTK.Windowing.GraphicsLibraryFramework; +using System; +using System.Collections.Generic; namespace Dashboard.OpenTK { @@ -34,7 +34,7 @@ namespace Dashboard.OpenTK if (!IsGLInitialized) { window.Context.MakeCurrent(); - GL.LoadBindings(GLFW.GetProcAddress); + GL.LoadBindings(new GLFWBindingsContext()); IsGLInitialized = true; } @@ -90,14 +90,14 @@ namespace Dashboard.OpenTK public void GetMaximumImage(out int width, out int height) { - GL.Get(GLEnum.GL_MAX_TEXTURE_SIZE, out int value); + GL.GetInteger(GetPName.MaxTextureSize, out int value); width = height = value; } public void GetMaximumImage(out int width, out int height, out int depth) { GetMaximumImage(out width, out height); - GL.Get(GLEnum.GL_MAX_ARRAY_TEXTURE_LAYERS, out int value); + GL.GetInteger(GetPName.MaxArrayTextureLayers, out int value); depth = value; } } diff --git a/Dashboard.OpenTK/OpenTKPort.cs b/Dashboard.OpenTK/OpenTKPort.cs index a4ac587..fbeb6f9 100644 --- a/Dashboard.OpenTK/OpenTKPort.cs +++ b/Dashboard.OpenTK/OpenTKPort.cs @@ -1,6 +1,7 @@ using System; using OpenTK.Mathematics; using OpenTK.Windowing.Desktop; +using OpenTK.Graphics.OpenGL4; using Dashboard.OpenGL; using Dashboard.ImmediateDraw; using Dashboard.PAL; @@ -78,7 +79,7 @@ namespace Dashboard.OpenTK if (!_glDriver.IsInit) _glDriver.Init(); - GL.Clear(GLEnum.GL_COLOR_BUFFER_BIT | GLEnum.GL_DEPTH_BUFFER_BIT); + GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _glDriver.Draw(_vertexEngine.DrawQueue, view); _window.Context.SwapBuffers(); diff --git a/Dashboard/Dashboard.csproj b/Dashboard/Dashboard.csproj index acd1c68..d8be64c 100644 --- a/Dashboard/Dashboard.csproj +++ b/Dashboard/Dashboard.csproj @@ -11,4 +11,9 @@ + + + + + diff --git a/Dashboard/OpenGL/GL.Buffer.cs b/Dashboard/OpenGL/GL.Buffer.cs deleted file mode 100644 index 3545d3a..0000000 --- a/Dashboard/OpenGL/GL.Buffer.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace Dashboard.OpenGL -{ - public unsafe static partial class GL - { - private delegate void BufferDataProc(GLEnum target, int size, void* data, GLEnum usageHint); - - private static GenObjectsProc? _genBuffers; - private static GenObjectsProc? _deleteBuffers; - private static BindSlottedProc? _bindBuffer; - private static BufferDataProc? _bufferData; - - private static void LoadBuffer() - { - _genBuffers = GetProcAddress("glGenBuffers"); - _deleteBuffers = GetProcAddress("glDeleteBuffers"); - _bindBuffer = GetProcAddress("glBindBuffer"); - _bufferData = GetProcAddress("glBufferData"); - } - - [MethodImpl(AggressiveInlining)] - public static void GenBuffers(int count, out int buffers) - { - fixed (int *ptr = &buffers) - _genBuffers!(count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void GenBuffers(int[] buffers) => GenBuffers(buffers.Length, out buffers[0]); - - [MethodImpl(AggressiveInlining)] - public static int GenBuffer() - { - GenBuffers(1, out int i); - return i; - } - - [MethodImpl(AggressiveInlining)] - public static void DeleteBuffers(int count, ref int buffers) - { - fixed (int *ptr = &buffers) - _deleteBuffers!(count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void DeleteBuffers(int[] buffers) => DeleteBuffers(buffers.Length, ref buffers[0]); - - [MethodImpl(AggressiveInlining)] - public static void DeleteBuffer(int buffer) => DeleteBuffers(1, ref buffer); - - [MethodImpl(AggressiveInlining)] - public static void BindBuffer(GLEnum target, int buffer) - { - _bindBuffer!(target, buffer); - } - - [MethodImpl(AggressiveInlining)] - public static void BufferData(GLEnum target, int size, IntPtr data, GLEnum usageHint) => - _bufferData!(target, size, (void*)data, usageHint); - - [MethodImpl(AggressiveInlining)] - public static void BufferData(GLEnum target, int size, ref T data, GLEnum usageHint) - where T : unmanaged - { - fixed (T* ptr = &data) - _bufferData!(target, size, ptr, usageHint); - } - - [MethodImpl(AggressiveInlining)] - public static void BufferData(GLEnum target, int size, T[] data, GLEnum usageHint) - where T : unmanaged => - BufferData(target, size, ref data[0], usageHint); - - } -} \ No newline at end of file diff --git a/Dashboard/OpenGL/GL.Program.cs b/Dashboard/OpenGL/GL.Program.cs deleted file mode 100644 index d7e5a6b..0000000 --- a/Dashboard/OpenGL/GL.Program.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System.Runtime.CompilerServices; -using System.Text; -using static Dashboard.OpenGL.GLEnum; - -namespace Dashboard.OpenGL -{ - public unsafe static partial class GL - { - private delegate int CreateProgramProc(); - private delegate void UseProgramProc(int program); - private delegate void AttachShaderProc(int program, int shader); - private delegate void DetachShaderProc(int program, int shader); - private delegate void LinkProgramProc(int program); - private delegate void GetProgramProc(int program, GLEnum pname, int *value); - private delegate void GetProgramInfoLogProc(int program, int maxLength, int * length, byte *infoLog); - private delegate void DeleteProgramProc(int program); - private delegate int GetShaderLocationProc(int program, byte *name); - - private static CreateProgramProc? _createProgram; - private static UseProgramProc? _useProgram; - private static AttachShaderProc? _attachShader; - private static DetachShaderProc? _detachShader; - private static LinkProgramProc? _linkProgram; - private static GetProgramProc? _getProgram; - private static GetProgramInfoLogProc? _getProgramInfoLog; - private static DeleteProgramProc? _deleteProgram; - private static GetShaderLocationProc? _getUniformLocation; - private static GetShaderLocationProc? _getAttribLocation; - - private static void LoadProgram() - { - _createProgram = GetProcAddress("glCreateProgram"); - _useProgram = GetProcAddress("glUseProgram"); - _attachShader = GetProcAddress("glAttachShader"); - _detachShader = GetProcAddress("glDetachShader"); - _linkProgram = GetProcAddress("glLinkProgram"); - _getProgram = GetProcAddress("glGetProgramiv"); - _getProgramInfoLog = GetProcAddress("glGetProgramInfoLog"); - _deleteProgram = GetProcAddress("glDeleteProgram"); - _getUniformLocation = GetProcAddress("glGetUniformLocation"); - _getAttribLocation = GetProcAddress("glGetAttribLocation"); - } - - [MethodImpl(AggressiveInlining)] - public static int CreateProgram() => _createProgram!(); - - [MethodImpl(AggressiveInlining)] - public static void UseProgram(int program) => _useProgram!(program); - - [MethodImpl(AggressiveInlining)] - public static void AttachShader(int program, int shader) => _attachShader!(program, shader); - - [MethodImpl(AggressiveInlining)] - public static void DetachShader(int program, int shader) => _detachShader!(program, shader); - - [MethodImpl(AggressiveInlining)] - public static void LinkProgram(int program) => _linkProgram!(program); - - [MethodImpl(AggressiveInlining)] - public static void GetProgram(int program, GLEnum pname, out int value) - { - value = default; - fixed (int* ptr = &value) - _getProgram!(program, pname, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static string GetProgramInfoLog(int program) - { - GetProgram(program, GL_INFO_LOG_LENGTH, out int length); - byte[] infoLog = new byte[length]; - - fixed (byte *ptr = infoLog) - _getProgramInfoLog!(program, length, &length, ptr); - - return Encoding.UTF8.GetString(infoLog); - } - - [MethodImpl(AggressiveInlining)] - public static void DeleteProgram(int program) => _deleteProgram!(program); - - [MethodImpl(AggressiveInlining)] - public static int GetUniformLocation(int program, string name) - { - fixed(byte* ptr = Encoding.UTF8.GetBytes(name)) - return _getUniformLocation!(program, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static int GetAttribLocation(int program, string name) - { - fixed(byte* ptr = Encoding.UTF8.GetBytes(name)) - return _getAttribLocation!(program, ptr); - } - } -} \ No newline at end of file diff --git a/Dashboard/OpenGL/GL.Shader.cs b/Dashboard/OpenGL/GL.Shader.cs deleted file mode 100644 index 36fbad5..0000000 --- a/Dashboard/OpenGL/GL.Shader.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Text; -using static Dashboard.OpenGL.GLEnum; - -namespace Dashboard.OpenGL -{ - public unsafe static partial class GL - { - private delegate int CreateShaderProc(GLEnum type); - private delegate void ShaderSourceProc(int shader, int count, byte** strings, int* length); - private delegate void CompileShaderProc(int shader); - private delegate void GetShaderProc(int shader, GLEnum pname, int* value); - private delegate void GetShaderInfoLogProc(int shader, int maxLength, int* length, byte* infoLog); - private delegate void DeleteShaderProc(int id); - - private static CreateShaderProc? _createShader; - private static ShaderSourceProc? _shaderSource; - private static CompileShaderProc? _compileShader; - private static GetShaderProc? _getShader; - private static GetShaderInfoLogProc? _getShaderInfoLog; - private static DeleteShaderProc? _deleteShader; - - private static void LoadShader() - { - _createShader = GetProcAddress("glCreateShader"); - _shaderSource = GetProcAddress("glShaderSource"); - _compileShader = GetProcAddress("glCompileShader"); - _getShader = GetProcAddress("glGetShaderiv"); - _getShaderInfoLog = GetProcAddress("glGetShaderInfoLog"); - _deleteShader = GetProcAddress("glDeleteShader"); - } - - [MethodImpl(AggressiveInlining)] - public static int CreateShader(GLEnum type) => _createShader!(type); - - [MethodImpl(AggressiveInlining)] - public static void ShaderSource(int shader, string source) - { - byte[] sourceUTF8 = Encoding.UTF8.GetBytes(source); - int length = sourceUTF8.Length; - - fixed (byte* ptr = &sourceUTF8[0]) - { - _shaderSource!(shader, 1, &ptr, &length); - } - } - - [MethodImpl(AggressiveInlining)] - public static void ShaderSource(int shader, string[] sources) - { - int count = sources.Length; - byte*[] pointers = new byte*[count]; - int[] lengths = new int[count]; - - for (int i = 0; i < count; i++) - { - byte[] decoded = Encoding.UTF8.GetBytes(sources[i]); - int length = lengths[i] = decoded.Length; - IntPtr memory = Marshal.AllocHGlobal(decoded.Length); - - Marshal.Copy(decoded, 0, memory, length); - pointers[i] = (byte*)memory; - } - - try - { - fixed (byte** ptr = &pointers[0]) - fixed (int * len = &lengths[0]) - { - _shaderSource!(shader, count, ptr, len); - } - } - finally - { - for (int i = 0; i < count; i++) - { - Marshal.FreeHGlobal((IntPtr)pointers[i]); - } - } - } - - [MethodImpl(AggressiveInlining)] - public static void CompileShader(int shader) => _compileShader!(shader); - - [MethodImpl(AggressiveInlining)] - public static void GetShader(int shader, GLEnum pname, out int value) - { - value = default; - fixed (int *ptr = &value) - _getShader!(shader, pname, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static string GetShaderInfoLog(int shader) - { - GetShader(shader, GL_INFO_LOG_LENGTH, out int length); - byte[] infoLog = new byte[length]; - - fixed (byte *ptr = infoLog) - _getShaderInfoLog!(shader, length, &length, ptr); - - return Encoding.UTF8.GetString(infoLog); - } - - [MethodImpl(AggressiveInlining)] - public static void DeleteShader(int shader) => _deleteShader!(shader); - } -} \ No newline at end of file diff --git a/Dashboard/OpenGL/GL.Texture.cs b/Dashboard/OpenGL/GL.Texture.cs deleted file mode 100644 index 0ba0867..0000000 --- a/Dashboard/OpenGL/GL.Texture.cs +++ /dev/null @@ -1,187 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace Dashboard.OpenGL -{ - public unsafe static partial class GL - { - private delegate void ActiveTextureProc(GLEnum unit); - private delegate void PixelStoreiProc(GLEnum pname, int param); - private delegate void PixelStorefProc(GLEnum pname, float param); - private delegate void TexImage2DProc(GLEnum target, int level, GLEnum internalFormat, int width, int height, int border, GLEnum format, GLEnum pixelType, void *data); - private delegate void TexImage3DProc(GLEnum target, int level, GLEnum internalFormat, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, void* data); - private delegate void TexSubImage2DProc(GLEnum target, int level, int x, int y, int width, int height, GLEnum format, GLEnum pixelType, void *data); - private delegate void TexSubImage3DProc(GLEnum target, int level, int x, int y, int z, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, void* data); - private delegate void TexParameteriProc(GLEnum target, GLEnum pname, int value); - private delegate void TexParameterfProc(GLEnum target, GLEnum pname, float value); - private delegate void TexParameterivProc(GLEnum target, GLEnum pname, int* value); - private delegate void TexParameterfvProc(GLEnum target, GLEnum pname, float* value); - private delegate void GenerateMipmapProc(GLEnum target); - - private static GenObjectsProc? _genTextures; - private static GenObjectsProc? _deleteTextures; - private static BindSlottedProc? _bindTexture; - private static ActiveTextureProc? _activeTexture; - private static PixelStoreiProc? _pixelStorei; - private static PixelStorefProc? _pixelStoref; - private static TexImage2DProc? _texImage2D; - private static TexImage3DProc? _texImage3D; - private static TexSubImage2DProc? _texSubImage2D; - private static TexSubImage3DProc? _texSubImage3D; - private static TexParameteriProc? _texParameteri; - private static TexParameterfProc? _texParameterf; - private static TexParameterivProc? _texParameteriv; - private static TexParameterfvProc? _texParameterfv; - private static GenerateMipmapProc? _generateMipmap; - - private static void LoadTexture() - { - _genTextures = GetProcAddress("glGenTextures"); - _deleteTextures = GetProcAddress("glDeleteTextures"); - _bindTexture = GetProcAddress("glBindTexture"); - _activeTexture = GetProcAddress("glActiveTexture"); - _pixelStorei = GetProcAddress("glPixelStorei"); - _pixelStoref = GetProcAddress("glPixelStoref"); - _texImage2D = GetProcAddress("glTexImage2D"); - _texImage3D = GetProcAddress("glTexImage3D"); - _texSubImage2D = GetProcAddress("glTexSubImage2D"); - _texSubImage3D = GetProcAddress("glTexSubImage3D"); - _texParameteri = GetProcAddress("glTexParameteri"); - _texParameterf = GetProcAddress("glTexParameterf"); - _texParameteriv = GetProcAddress("glTexParameteriv"); - _texParameterfv = GetProcAddress("glTexParameterfv"); - _generateMipmap = GetProcAddress("glGenerateMipmap"); - } - - [MethodImpl(AggressiveInlining)] - public static void GenTextures(int count, out int textures) - { - fixed (int *ptr = &textures) - _genTextures!(count, ptr); - } - [MethodImpl(AggressiveInlining)] - public static int GenTexture() - { - GenTextures(1, out int i); - return i; - } - [MethodImpl(AggressiveInlining)] - public static void GenTextures(int[] textures) => GenTextures(textures.Length, out textures[0]); - - [MethodImpl(AggressiveInlining)] - public static void DeleteTextures(int count, in int textures) - { - fixed (int* ptr = &textures) - _deleteTextures!(count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void DeleteTexture(int i) => DeleteTextures(1, i); - - [MethodImpl(AggressiveInlining)] - public static void DeleteTextures(int[] textures) => DeleteTextures(textures.Length, in textures[0]); - - [MethodImpl(AggressiveInlining)] - public static void BindTexture(GLEnum target, int texture) => _bindTexture!(target, texture); - - [MethodImpl(AggressiveInlining)] - public static void ActiveTexture(GLEnum unit) => _activeTexture!(unit); - - [MethodImpl(AggressiveInlining)] - public static void PixelStore(GLEnum pname, int value) => _pixelStorei!(pname, value); - - [MethodImpl(AggressiveInlining)] - public static void PixelStore(GLEnum pname, float value) => _pixelStoref!(pname, value); - - [MethodImpl(AggressiveInlining)] - public static void TexImage2D(GLEnum target, int level, GLEnum internalFormat, int width, int height, int border, GLEnum format, GLEnum pixelType, IntPtr data) => - _texImage2D!(target, level, internalFormat, width, height, border, format, pixelType, (void*)data); - - [MethodImpl(AggressiveInlining)] - public static void TexImage2D(GLEnum target, int level, GLEnum internalFormat, int width, int height, int border, GLEnum format, GLEnum pixelType, in T data) where T : unmanaged - { - fixed(T *ptr = &data) - _texImage2D!(target, level, internalFormat, width, height, border, format, pixelType, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void TexImage2D(GLEnum target, int level, GLEnum internalFormat, int width, int height, int border, GLEnum format, GLEnum pixelType, T[] data) where T : unmanaged => - TexImage2D(target, level, internalFormat, width, height, border, format, pixelType, in data[0]); - - [MethodImpl(AggressiveInlining)] - public static void TexImage3D(GLEnum target, int level, GLEnum internalFormat, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, void* data) => - _texImage3D!(target, level, internalFormat, width, height, depth, border, format, pixelType, data); - - [MethodImpl(AggressiveInlining)] - public static void TexImage3D(GLEnum target, int level, GLEnum internalFormat, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, in T data) - where T : unmanaged - { - fixed (T* ptr = &data) - _texImage3D!(target, level, internalFormat, width, height, depth, border, format, pixelType, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void TexImage3D(GLEnum target, int level, GLEnum internalFormat, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, T[] data) - where T : unmanaged => - TexImage3D(target, level, internalFormat, width, height, depth, border, format, pixelType, in data[0]); - - [MethodImpl(AggressiveInlining)] - public static void TexSubImage2D(GLEnum target, int level, int x, int y, int width, int height, GLEnum format, GLEnum pixelType, IntPtr data) => - _texSubImage2D!(target, level, x, y, width, height,format, pixelType, (void*)data); - - [MethodImpl(AggressiveInlining)] - public static void TexSubImage2d(GLEnum target, int level, int x, int y, int width, int height, GLEnum format, GLEnum pixelType, in T data) where T : unmanaged - { - fixed(T *ptr = &data) - _texSubImage2D!(target, level, x, y, width, height, format, pixelType, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void TexSubImage2D(GLEnum target, int level, int x, int y, int width, int height, GLEnum format, GLEnum pixelType, T[] data) where T : unmanaged => - TexSubImage2d(target, level, x, y, width, height, format, pixelType, in data[0]); - - [MethodImpl(AggressiveInlining)] - public static void TexSubImage3D(GLEnum target, int level, int x, int y, int z, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, void* data) => - _texSubImage3D!(target, level, x, y, z, width, height, depth, border, format, pixelType, data); - - [MethodImpl(AggressiveInlining)] - public static void TexSubImage3D(GLEnum target, int level, int x, int y, int z, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, in T data) - where T : unmanaged - { - fixed (T* ptr = &data) - _texSubImage3D!(target, level, x, y, z, width, height, depth, border, format, pixelType, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void TexSubImage3D(GLEnum target, int level, int x, int y, int z, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, T[] data) - where T : unmanaged => - TexSubImage3D(target, level, x, y, z, width, height, depth, border, format, pixelType, in data[0]); - - [MethodImpl(AggressiveInlining)] - public static void TexParameter(GLEnum target, GLEnum pname, int value) => _texParameteri!(target, pname, value); - [MethodImpl(AggressiveInlining)] - public static void TexParameter(GLEnum target, GLEnum pname, GLEnum value) => _texParameteri!(target, pname, (int)value); - [MethodImpl(AggressiveInlining)] - public static void TexParameter(GLEnum target, GLEnum pname, float value) => _texParameterf!(target, pname, value); - [MethodImpl(AggressiveInlining)] - public static void TexParameter(GLEnum target, GLEnum pname, ref int values) - { - fixed (int *ptr = &values) - _texParameteriv!(target, pname, ptr); - } - [MethodImpl(AggressiveInlining)] - public static void TexParameter(GLEnum target, GLEnum pname, int[] values) => TexParameter(target, pname, ref values[0]); - - [MethodImpl(AggressiveInlining)] - public static void TexParameter(GLEnum target, GLEnum pname, ref float values) - { - fixed (float *ptr = &values) - _texParameterfv!(target, pname, ptr); - } - [MethodImpl(AggressiveInlining)] - public static void TexParameter(GLEnum target, GLEnum pname, float[] values) => TexParameter(target, pname, ref values[0]); - - [MethodImpl(AggressiveInlining)] - public static void GenerateMipmap(GLEnum target) => _generateMipmap!(target); - } -} \ No newline at end of file diff --git a/Dashboard/OpenGL/GL.Uniform.cs b/Dashboard/OpenGL/GL.Uniform.cs deleted file mode 100644 index 01a0a87..0000000 --- a/Dashboard/OpenGL/GL.Uniform.cs +++ /dev/null @@ -1,222 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace Dashboard.OpenGL -{ - public unsafe static partial class GL - { - private delegate void Uniform1fProc(int location, float x); - private delegate void Uniform2fProc(int location, float x, float y); - private delegate void Uniform3fProc(int location, float x, float y, float z); - private delegate void Uniform4fProc(int location, float x, float y, float z, float w); - private delegate void Uniform1iProc(int location, int x); - private delegate void Uniform2iProc(int location, int x, int y); - private delegate void Uniform3iProc(int location, int x, int y, int z); - private delegate void Uniform4iProc(int location, int x, int y, int z, int w); - private delegate void UniformNfvProc(int location, int count, float* value); - private delegate void UniformNivProc(int location, int count, int* value); - private delegate void UniformMatrixNxNfvProc(int location, int count, bool transpose, float *value); - - private static Uniform1fProc? _uniform1f; - private static Uniform2fProc? _uniform2f; - private static Uniform3fProc? _uniform3f; - private static Uniform4fProc? _uniform4f; - private static Uniform1iProc? _uniform1i; - private static Uniform2iProc? _uniform2i; - private static Uniform3iProc? _uniform3i; - private static Uniform4iProc? _uniform4i; - private static UniformNfvProc? _uniform1fv; - private static UniformNfvProc? _uniform2fv; - private static UniformNfvProc? _uniform3fv; - private static UniformNfvProc? _uniform4fv; - private static UniformNivProc? _uniform1iv; - private static UniformNivProc? _uniform2iv; - private static UniformNivProc? _uniform3iv; - private static UniformNivProc? _uniform4iv; - private static UniformMatrixNxNfvProc? _uniformMatrix2fv; - private static UniformMatrixNxNfvProc? _uniformMatrix3fv; - private static UniformMatrixNxNfvProc? _uniformMatrix4fv; - - public static void LoadUniform() - { - _uniform1f = GetProcAddress("glUniform1f"); - _uniform2f = GetProcAddress("glUniform2f"); - _uniform3f = GetProcAddress("glUniform3f"); - _uniform4f = GetProcAddress("glUniform4f"); - _uniform1i = GetProcAddress("glUniform1i"); - _uniform2i = GetProcAddress("glUniform2i"); - _uniform3i = GetProcAddress("glUniform3i"); - _uniform4i = GetProcAddress("glUniform4i"); - _uniform1fv = GetProcAddress("glUniform1fv"); - _uniform2fv = GetProcAddress("glUniform2fv"); - _uniform3fv = GetProcAddress("glUniform3fv"); - _uniform4fv = GetProcAddress("glUniform4fv"); - _uniform1iv = GetProcAddress("glUniform1iv"); - _uniform2iv = GetProcAddress("glUniform2iv"); - _uniform3iv = GetProcAddress("glUniform3iv"); - _uniform4iv = GetProcAddress("glUniform4iv"); - _uniformMatrix2fv = GetProcAddress("glUniformMatrix2fv"); - _uniformMatrix3fv = GetProcAddress("glUniformMatrix3fv"); - _uniformMatrix4fv = GetProcAddress("glUniformMatrix4fv"); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform1(int location, float x) - { - _uniform1f!(location, x); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform2(int location, float x, float y) - { - _uniform2f!(location, x, y); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform3(int location, float x, float y, float z) - { - _uniform3f!(location, x, y, z); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform4(int location, float x, float y, float z, float w) - { - _uniform4f!(location, x, y, z, w); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform1(int location, int x) - { - _uniform1i!(location, x); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform2(int location, int x, int y) - { - _uniform2i!(location, x, y); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform3(int location, int x, int y, int z) - { - _uniform3i!(location, x, y, z); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform4(int location, int x, int y, int z, int w) - { - _uniform4i!(location, x, y, z, w); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform1(int location, int count, ref float first) - { - fixed(float *ptr = &first) - _uniform1fv!(location, count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform2(int location, int count, ref float first) - { - fixed(float *ptr = &first) - _uniform2fv!(location, count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform3(int location, int count, ref float first) - { - fixed(float *ptr = &first) - _uniform3fv!(location, count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform4(int location, int count, ref float first) - { - fixed(float *ptr = &first) - _uniform4fv!(location, count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform1(int location, int count, ref int first) - { - fixed(int *ptr = &first) - _uniform1iv!(location, count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform2(int location, int count, ref int first) - { - fixed(int *ptr = &first) - _uniform2iv!(location, count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform3(int location, int count, ref int first) - { - fixed(int *ptr = &first) - _uniform3iv!(location, count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void Uniform4(int location, int count, ref int first) - { - fixed(int *ptr = &first) - _uniform4iv!(location, count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void UniformMatrix2(int location, bool transpose, ref float m11) - { - fixed (float* ptr = &m11) - _uniformMatrix2fv!(location, 1, transpose, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void UniformMatrix3(int location, bool transpose, ref float m11) - { - fixed (float* ptr = &m11) - _uniformMatrix3fv!(location, 1, transpose, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void UniformMatrix4(int location, bool transpose, ref float m11) - { - fixed (float* ptr = &m11) - _uniformMatrix4fv!(location, 1, transpose, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void UniformMatrix2(int location, int count, bool transpose, ref float m11) - { - fixed (float* ptr = &m11) - _uniformMatrix2fv!(location, count, transpose, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void UniformMatrix3(int location, int count, bool transpose, ref float m11) - { - fixed (float* ptr = &m11) - _uniformMatrix3fv!(location, count, transpose, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void UniformMatrix4(int location, int count, bool transpose, ref float m11) - { - fixed (float* ptr = &m11) - _uniformMatrix4fv!(location, count, transpose, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void UniformMatrix4(int location, bool transpose, in QMat4 m4) - { - fixed (float* ptr = &m4.M11) - _uniformMatrix4fv!(location, 1, transpose, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void UniformMatrix4(int location, int count, bool transpose, ref QMat4 m4) - { - fixed (float* ptr = &m4.M11) - _uniformMatrix4fv!(location, count, transpose, ptr); - } - } -} \ No newline at end of file diff --git a/Dashboard/OpenGL/GL.VertexArray.cs b/Dashboard/OpenGL/GL.VertexArray.cs deleted file mode 100644 index 9cae3b4..0000000 --- a/Dashboard/OpenGL/GL.VertexArray.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace Dashboard.OpenGL -{ - public unsafe static partial class GL - { - private delegate void EnableVertexAttribArrayProc(int location); - private delegate void VertexAttribPointerProc(int location, int size, GLEnum type, bool normalized, int stride, IntPtr offset); - private delegate void VertexAttribIPointerProc(int location, int size, GLEnum type, int stride, IntPtr offset); - - private static GenObjectsProc? _genVertexArrays; - private static GenObjectsProc? _deleteVertexArrays; - private static BindObjectProc? _bindVertexArray; - private static EnableVertexAttribArrayProc? _enableVertexAttribArray; - private static EnableVertexAttribArrayProc? _disableVertexAttribArray; - private static VertexAttribPointerProc? _vertexAttribPointer; - private static VertexAttribIPointerProc? _vertexAttribIPointer; - - private static void LoadVertexArrays() - { - _genVertexArrays = GetProcAddress("glGenVertexArrays"); - _deleteVertexArrays = GetProcAddress("glDeleteVertexArrays"); - _bindVertexArray = GetProcAddress("glBindVertexArray"); - _enableVertexAttribArray = GetProcAddress("glEnableVertexAttribArray"); - _disableVertexAttribArray = GetProcAddress("glDisableVertexAttribArray"); - _vertexAttribPointer = GetProcAddress("glVertexAttribPointer"); - _vertexAttribIPointer = GetProcAddress("glVertexAttribIPointer"); - } - - [MethodImpl(AggressiveInlining)] - public static void GenVertexArrays(int count, out int vertexArrays) - { - fixed (int *ptr = &vertexArrays) - _genVertexArrays!(count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static int GenVertexArray() - { - GenVertexArrays(1, out int i); - return i; - } - - [MethodImpl(AggressiveInlining)] - public static void GenVertexArrays(int[] vertexArrays) => GenVertexArrays(vertexArrays.Length, out vertexArrays[0]); - - [MethodImpl(AggressiveInlining)] - public static void DeleteVertexArrays(int count, ref int vertexArrays) - { - fixed (int *ptr = &vertexArrays) - _deleteVertexArrays!(count, ptr); - } - - [MethodImpl(AggressiveInlining)] - public static void DeleteVertexArrays(int[] vertexArrays) => DeleteVertexArrays(vertexArrays.Length, ref vertexArrays[0]); - - [MethodImpl(AggressiveInlining)] - public static void DeleteVertexArray(int vertexArray) => DeleteVertexArrays(1, ref vertexArray); - - [MethodImpl(AggressiveInlining)] - public static void BindVertexArray(int vertexArray) => _bindVertexArray!(vertexArray); - - [MethodImpl(AggressiveInlining)] - public static void EnableVertexAttribArray(int location) => _enableVertexAttribArray!(location); - - [MethodImpl(AggressiveInlining)] - public static void DisableVertexAttribArray(int location) => _disableVertexAttribArray!(location); - - [MethodImpl(AggressiveInlining)] - public static void VertexAttribPointer(int location, int size, GLEnum type, bool normalized, int stride, int offset) => - _vertexAttribPointer!(location, size, type, normalized, stride, (IntPtr)offset); - - [MethodImpl(AggressiveInlining)] - public static void VertexAttribIPointer(int location, int size, GLEnum type, int stride, int offset) => - _vertexAttribIPointer!(location, size, type, stride, (IntPtr)offset); - } -} \ No newline at end of file diff --git a/Dashboard/OpenGL/GL.cs b/Dashboard/OpenGL/GL.cs deleted file mode 100644 index f1550ee..0000000 --- a/Dashboard/OpenGL/GL.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace Dashboard.OpenGL -{ - public delegate IntPtr GetProcAddressProc(string procName); - - public unsafe static partial class GL - { - private delegate void GenObjectsProc(int count, int *ids); - private delegate void BindObjectProc(int id); - private delegate void BindSlottedProc(GLEnum target, int id); - private delegate void GLEnum1Proc(GLEnum x); - private delegate void GLEnum2Proc(GLEnum x, GLEnum y); - private delegate void GLI4Proc(int x, int y, int z, int w); - private delegate void GLF4Proc(float x, float y, float z, float w); - private delegate void DrawElementsProc(GLEnum primitive, int size, GLEnum type, void *offset); - private delegate void DrawArraysProc(GLEnum primitive, int first, int offset); - private delegate void GetIntegervProc(GLEnum pname, int *data); - private delegate void GetFloatvProc(GLEnum pname, float *data); - private delegate byte* GetStringProc(GLEnum pname); - - private const short AggressiveInlining = (short)MethodImplOptions.AggressiveInlining; - - private static GetProcAddressProc? _getProcAddress; - private static GLEnum1Proc? _enable; - private static GLEnum1Proc? _disable; - private static GLEnum2Proc? _blendFunc; - private static GLEnum1Proc? _depthFunc; - private static GLEnum1Proc? _clear; - private static GLI4Proc? _viewport; - private static GLI4Proc? _scissor; - private static GLF4Proc? _clearColor; - private static DrawElementsProc? _drawElements; - private static DrawArraysProc? _drawArrays; - private static GetIntegervProc? _getIntegerv; - private static GetFloatvProc? _getFloatv; - private static GetStringProc? _getString; - - private static T GetProcAddress(string procName) - where T : Delegate - { - IntPtr funcptr = _getProcAddress!(procName); - return Marshal.GetDelegateForFunctionPointer(funcptr); - } - - public static void LoadBindings(GetProcAddressProc getProcAddress) - { - _getProcAddress = getProcAddress; - - _enable = GetProcAddress("glEnable"); - _disable = GetProcAddress("glDisable"); - _blendFunc = GetProcAddress("glBlendFunc"); - _depthFunc = GetProcAddress("glDepthFunc"); - _clear = GetProcAddress("glClear"); - _viewport = GetProcAddress("glViewport"); - _scissor = GetProcAddress("glScissor"); - _clearColor = GetProcAddress("glClearColor"); - _drawElements = GetProcAddress("glDrawElements"); - _drawArrays = GetProcAddress("glDrawArrays"); - _getIntegerv = GetProcAddress("glGetIntegerv"); - _getFloatv = GetProcAddress("glGetFloatv"); - _getString = GetProcAddress("glGetString"); - - LoadBuffer(); - LoadProgram(); - LoadShader(); - LoadTexture(); - LoadUniform(); - LoadVertexArrays(); - } - - [MethodImpl(AggressiveInlining)] - public static void Enable(GLEnum cap) => _enable!(cap); - [MethodImpl(AggressiveInlining)] - public static void Disable(GLEnum cap) => _disable!(cap); - [MethodImpl(AggressiveInlining)] - public static void BlendFunc(GLEnum src, GLEnum dst) => _blendFunc!(src, dst); - [MethodImpl(AggressiveInlining)] - public static void DepthFunc(GLEnum func) => _depthFunc!(func); - [MethodImpl(AggressiveInlining)] - public static void Clear(GLEnum buffer_bits) => _clear!(buffer_bits); - [MethodImpl(AggressiveInlining)] - public static void Viewport(int x, int y, int w, int h) => _viewport!(x, y, w, h); - [MethodImpl(AggressiveInlining)] - public static void Scissor(int x, int y, int w, int h) => _scissor!(x, y, w, h); - [MethodImpl(AggressiveInlining)] - public static void ClearColor(float r, float g, float b, float a) => _clearColor!(r, g, b, a); - - [MethodImpl(AggressiveInlining)] - public static void DrawElements(GLEnum primitive, int count, GLEnum type, int offset) => _drawElements!(primitive, count, type, (void*)offset); - - [MethodImpl(AggressiveInlining)] - public static void DrawArrays(GLEnum primitive, int offset, int count) => _drawArrays!(primitive, offset, count); - - [MethodImpl(AggressiveInlining)] - public static void Get(GLEnum pname, out int value) - { - value = default; - fixed(int* ptr = &value) - { - _getIntegerv!(pname, ptr); - } - } - - [MethodImpl(AggressiveInlining)] - public static void Get(GLEnum pname, out float value) - { - value = default; - fixed (float* ptr = &value) - { - _getFloatv!(pname, ptr); - } - } - - [MethodImpl(AggressiveInlining)] - public static string GetString(GLEnum pname) - { - int length; - byte* str = _getString!(pname); - - for (length = 0; str[length] == 0 || length < 256; length++); - - return System.Text.Encoding.UTF8.GetString(str, length); - } - } -} \ No newline at end of file diff --git a/Dashboard/OpenGL/GL21Driver.cs b/Dashboard/OpenGL/GL21Driver.cs index f6df059..6bdcb82 100644 --- a/Dashboard/OpenGL/GL21Driver.cs +++ b/Dashboard/OpenGL/GL21Driver.cs @@ -1,11 +1,10 @@ +using Dashboard.VertexGenerator; +using Dashboard.Media; +using OpenTK.Graphics.OpenGL4; using System; using System.IO; using System.Collections.Generic; -using Dashboard.VertexGenerator; -using static Dashboard.OpenGL.GLEnum; -using Dashboard.Media; using System.Linq; -using System.Diagnostics; namespace Dashboard.OpenGL { @@ -46,8 +45,8 @@ namespace Dashboard.OpenGL { if (IsInit) return; - int vs = CreateShader(GL_VERTEX_SHADER, "Dashboard.res.gl21.vert"); - int fs = CreateShader(GL_FRAGMENT_SHADER, "Dashboard.res.gl21.frag"); + int vs = CreateShader(ShaderType.VertexShader, "Dashboard.res.gl21.vert"); + int fs = CreateShader(ShaderType.FragmentShader, "Dashboard.res.gl21.frag"); program = GL.CreateProgram(); GL.AttachShader(program, vs); @@ -109,11 +108,11 @@ namespace Dashboard.OpenGL GL.Uniform1(fMaxZ, (float)(queue.ZDepth+1)); GL.Uniform1(fSdfThreshold, 0.5f); GL.Uniform1(tx2d, 0); - GL.Enable(GL_BLEND); - GL.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - GL.Enable(GL_SCISSOR_TEST); - GL.Enable(GL_DEPTH_TEST); - GL.DepthFunc(GL_LESS); + GL.Enable(EnableCap.Blend); + GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); + GL.Enable(EnableCap.ScissorTest); + GL.Enable(EnableCap.DepthTest); + GL.DepthFunc(DepthFunction.Less); foreach (DrawCall call in queue) { @@ -124,10 +123,10 @@ namespace Dashboard.OpenGL (int)MathF.Round(call.Bounds.Size.Y)); QMat4.Translation(out QMat4 modelMatrix, call.Bounds.Min.X, call.Bounds.Min.Y, 0); QMat4 modelView = viewMatrix * modelMatrix; - GL.UniformMatrix4(m4Transforms, false, in modelView); + GL.UniformMatrix4(m4Transforms, 1, false, ref modelView.M11); - GL.ActiveTexture(GL_TEXTURE0); - GL.BindTexture(GL_TEXTURE_2D, 0); + GL.ActiveTexture(TextureUnit.Texture0); + GL.BindTexture(TextureTarget.Texture2D, 0); if (call.Texture != null) { GL.Uniform1(iEnableSdf, call.Texture.IsSdf ? 1 : 0); @@ -136,14 +135,14 @@ namespace Dashboard.OpenGL if (call.Texture.Depth > 1) { GL.Uniform1(iEnableTexture, 3); - GL.ActiveTexture(GL_TEXTURE1); - GL.BindTexture(GL_TEXTURE_2D_ARRAY, textures.GetTexture(call.Texture)); + GL.ActiveTexture(TextureUnit.Texture1); + GL.BindTexture(TextureTarget.Texture2D, textures.GetTexture(call.Texture)); } else { GL.Uniform1(iEnableTexture, 2); - GL.ActiveTexture(GL_TEXTURE0); - GL.BindTexture(GL_TEXTURE_2D, textures.GetTexture(call.Texture)); + GL.ActiveTexture(TextureUnit.Texture0); + GL.BindTexture(TextureTarget.Texture2D, textures.GetTexture(call.Texture)); } } else @@ -151,12 +150,12 @@ namespace Dashboard.OpenGL GL.Uniform1(iEnableTexture, 0); } - GL.DrawElements(GL_TRIANGLES, call.Count, GL_UNSIGNED_INT, sizeof(int)*call.Start); + GL.DrawElements(PrimitiveType.Triangles, call.Count, DrawElementsType.UnsignedInt, sizeof(int)*call.Start); } - GL.Disable(GL_SCISSOR_TEST); - GL.Disable(GL_DEPTH_TEST); - GL.Disable(GL_BLEND); + GL.Disable(EnableCap.ScissorTest); + GL.Disable(EnableCap.DepthTest); + GL.Disable(EnableCap.Blend); } public void ClearDrawQueue(DrawCallQueue queue) @@ -169,7 +168,7 @@ namespace Dashboard.OpenGL data.Remove(queue); } - private static int CreateShader(GLEnum type, string name) + private static int CreateShader(ShaderType type, string name) { StreamReader source = new StreamReader(typeof(GL21Driver).Assembly.GetManifestResourceStream(name) ?? throw new Exception("Resource not found.")); string text = source.ReadToEnd(); @@ -195,9 +194,9 @@ namespace Dashboard.OpenGL { message = string.Empty; - GL.GetShader(shader, GL_COMPILE_STATUS, out int i); + GL.GetShader(shader, ShaderParameter.CompileStatus, out int i); - if (i != (int)GL_TRUE) + if (i == 0) { message = GL.GetShaderInfoLog(shader); return false; @@ -210,9 +209,9 @@ namespace Dashboard.OpenGL { message = string.Empty; - GL.GetProgram(program, GL_LINK_STATUS, out int i); + GL.GetProgram(program, GetProgramParameterName.LinkStatus, out int i); - if (i != (int)GL_OK) + if (i == 0) { message = GL.GetProgramInfoLog(program); @@ -289,22 +288,22 @@ namespace Dashboard.OpenGL return; GL.BindVertexArray(VertexArray); - GL.BindBuffer(GL_ARRAY_BUFFER, vbo); - GL.BufferData(GL_ARRAY_BUFFER, DbVertex.Stride * Queue.VertexCount, Queue.VertexArray, GL_STREAM_DRAW); + GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); + GL.BufferData(BufferTarget.ArrayBuffer, DbVertex.Stride * Queue.VertexCount, Queue.VertexArray, BufferUsageHint.StreamDraw); - GL.VertexAttribPointer(driver.v2Position, 2, GL_FLOAT, false, DbVertex.Stride, DbVertex.PositionOffset); - GL.VertexAttribPointer(driver.fZIndex, 1, GL_UNSIGNED_INT, false, DbVertex.Stride, DbVertex.ZIndexOffset); - GL.VertexAttribPointer(driver.v2TexPos, 2, GL_FLOAT, false, DbVertex.Stride, DbVertex.TextureCoordinatesOffset); - GL.VertexAttribPointer(driver.fTexLayer, 1, GL_FLOAT, false, DbVertex.Stride, DbVertex.TextureLayerOffset); - GL.VertexAttribPointer(driver.v4Color, 4, GL_UNSIGNED_BYTE, true, DbVertex.Stride, DbVertex.ColorOffset); + GL.VertexAttribPointer(driver.v2Position, 2, VertexAttribPointerType.Float, false, DbVertex.Stride, DbVertex.PositionOffset); + GL.VertexAttribPointer(driver.fZIndex, 1, VertexAttribPointerType.UnsignedInt, false, DbVertex.Stride, DbVertex.ZIndexOffset); + GL.VertexAttribPointer(driver.v2TexPos, 2, VertexAttribPointerType.Float, false, DbVertex.Stride, DbVertex.TextureCoordinatesOffset); + GL.VertexAttribPointer(driver.fTexLayer, 1, VertexAttribPointerType.Float, false, DbVertex.Stride, DbVertex.TextureLayerOffset); + GL.VertexAttribPointer(driver.v4Color, 4, VertexAttribPointerType.UnsignedByte, true, DbVertex.Stride, DbVertex.ColorOffset); GL.EnableVertexAttribArray(driver.v2Position); GL.EnableVertexAttribArray(driver.fZIndex); GL.EnableVertexAttribArray(driver.v2TexPos); GL.EnableVertexAttribArray(driver.v4Color); GL.EnableVertexAttribArray(driver.fTexLayer); - GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, Queue.ElementCount * sizeof(int), Queue.ElementArray, GL_STREAM_DRAW); + GL.BindBuffer(BufferTarget.ElementArrayBuffer, ebo); + GL.BufferData(BufferTarget.ElementArrayBuffer, Queue.ElementCount * sizeof(int), Queue.ElementArray, BufferUsageHint.StreamDraw); int Swap(ref int a, ref int b) { @@ -376,14 +375,14 @@ namespace Dashboard.OpenGL { int texture = GL.GenTexture(); - GL.BindTexture(GL_TEXTURE_2D_ARRAY, texture); + GL.BindTexture(TextureTarget.Texture2DArray, texture); image3d.LockBits3d(out QImageLock lck, QImageLockOptions.Default); - GL.TexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, lck.Width, lck.Height, lck.Depth, 0, s_InternalFormat[lck.Format], s_PixelType[lck.Format], lck.ImagePtr); + GL.TexImage3D(TextureTarget.Texture2DArray, 0, PixelInternalFormat.Rgba, lck.Width, lck.Height, lck.Depth, 0, s_InternalFormat[lck.Format], s_PixelType[lck.Format], lck.ImagePtr); image3d.UnlockBits(); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); + GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear); return texture; } @@ -392,30 +391,30 @@ namespace Dashboard.OpenGL { int texture = GL.GenTexture(); - GL.BindTexture(GL_TEXTURE_2D, texture); + GL.BindTexture(TextureTarget.Texture2D, texture); image2d.LockBits2d(out QImageLock lck, QImageLockOptions.Default); - GL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, lck.Width, lck.Height, 0, s_InternalFormat[lck.Format], s_PixelType[lck.Format], lck.ImagePtr); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, lck.Width, lck.Height, 0, s_InternalFormat[lck.Format], s_PixelType[lck.Format], lck.ImagePtr); image2d.UnlockBits(); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear); switch (image2d.InternalFormat) { case QImageFormat.RedU8: case QImageFormat.RedF: - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_RED); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ONE); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, (int)All.Red); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, (int)All.Red); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, (int)All.Red); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, (int)All.One); break; case QImageFormat.AlphaU8: case QImageFormat.AlphaF: - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ONE); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ONE); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE); - GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, (int)All.One); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, (int)All.One); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, (int)All.One); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, (int)All.Alpha); break; } @@ -430,31 +429,31 @@ namespace Dashboard.OpenGL isDisposed = true; int[] ids = textures.Values.ToArray(); - GL.DeleteTextures(ids); + GL.DeleteTextures(ids.Length, ref ids[0]); } - private static readonly Dictionary s_InternalFormat = new Dictionary() + private static readonly Dictionary s_InternalFormat = new Dictionary() { - [QImageFormat.AlphaF] = GL_ALPHA, - [QImageFormat.AlphaU8] = GL_ALPHA, - [QImageFormat.RedF] = GL_RED, - [QImageFormat.RedU8] = GL_RED, - [QImageFormat.RgbF] = GL_RGB, - [QImageFormat.RgbU8] = GL_RGB, - [QImageFormat.RgbaU8] = GL_RGBA, - [QImageFormat.RgbaF] = GL_RGBA, + [QImageFormat.AlphaF] = PixelFormat.Alpha, + [QImageFormat.AlphaU8] = PixelFormat.Alpha, + [QImageFormat.RedF] = PixelFormat.Red, + [QImageFormat.RedU8] = PixelFormat.Red, + [QImageFormat.RgbF] = PixelFormat.Rgb, + [QImageFormat.RgbU8] = PixelFormat.Rgb, + [QImageFormat.RgbaU8] = PixelFormat.Rgba, + [QImageFormat.RgbaF] = PixelFormat.Rgba, }; - private static readonly Dictionary s_PixelType = new Dictionary() + private static readonly Dictionary s_PixelType = new Dictionary() { - [QImageFormat.AlphaF] = GL_FLOAT, - [QImageFormat.RedF] = GL_FLOAT, - [QImageFormat.RgbF] = GL_FLOAT, - [QImageFormat.RgbaF] = GL_FLOAT, - [QImageFormat.AlphaU8] = GL_UNSIGNED_BYTE, - [QImageFormat.RedU8] = GL_UNSIGNED_BYTE, - [QImageFormat.RgbU8] = GL_UNSIGNED_BYTE, - [QImageFormat.RgbaU8] = GL_UNSIGNED_BYTE, + [QImageFormat.AlphaF] = PixelType.Float, + [QImageFormat.RedF] = PixelType.Float, + [QImageFormat.RgbF] = PixelType.Float, + [QImageFormat.RgbaF] = PixelType.Float, + [QImageFormat.AlphaU8] = PixelType.UnsignedByte, + [QImageFormat.RedU8] = PixelType.UnsignedByte, + [QImageFormat.RgbU8] = PixelType.UnsignedByte, + [QImageFormat.RgbaU8] = PixelType.UnsignedByte, }; } } \ No newline at end of file diff --git a/Dashboard/OpenGL/GLEnum.cs b/Dashboard/OpenGL/GLEnum.cs deleted file mode 100644 index 382586d..0000000 --- a/Dashboard/OpenGL/GLEnum.cs +++ /dev/null @@ -1,94 +0,0 @@ -namespace Dashboard.OpenGL -{ - public enum GLEnum : int - { - GL_OK = 0, - GL_TRUE = 1, - GL_FALSE = 0, - GL_ONE = 1, - GL_ZERO = 0, - GL_MAJOR_VERSION = 0x821B, - GL_MINOR_VERSION = 0x821C, - GL_VENDOR = 0x1F00, - GL_RENDERER = 0x1F01, - GL_VERSION = 0x1F02, - GL_EXTENSIONS = 0x1F03, - GL_MAX_TEXTURE_SIZE = 0x0D33, - GL_MAX_3D_TEXTURE_SIZE = 0x8073, - GL_MAX_ARRAY_TEXTURE_LAYERS = 0x88FF, - - GL_MULTISAMPLE = 0x809D, - GL_BLEND = 0x0BE2, - - GL_COLOR_BUFFER_BIT = 0x00004000, - GL_DEPTH_BUFFER_BIT = 0x00000100, - - GL_SRC_ALPHA = 0x0302, - GL_ONE_MINUS_SRC_ALPHA = 0x0303, - - GL_VERTEX_SHADER = 0x8B31, - GL_FRAGMENT_SHADER = 0x8B30, - GL_INFO_LOG_LENGTH = 0x8B84, - GL_COMPILE_STATUS = 0x8B81, - GL_LINK_STATUS = 0x8B82, - - GL_UNSIGNED_BYTE = 0x1401, - GL_UNSIGNED_SHORT = 0x1403, - GL_UNSIGNED_INT = 0x1405, - GL_FLOAT = 0x1406, - - GL_RED = 0x1903, - GL_GREEN = 0x1904, - GL_BLUE = 0x1905, - GL_ALPHA = 0x1906, - GL_RGB = 0x1907, - GL_RGBA = 0x1908, - - GL_ARRAY_BUFFER = 0x8892, - GL_ELEMENT_ARRAY_BUFFER = 0x8893, - - GL_STREAM_DRAW = 0x88E0, - - GL_TEXTURE0 = 0x84C0, - GL_TEXTURE1 = GL_TEXTURE0 + 1, - GL_TEXTURE2 = GL_TEXTURE0 + 2, - GL_TEXTURE3 = GL_TEXTURE0 + 3, - GL_TEXTURE4 = GL_TEXTURE0 + 4, - GL_TEXTURE5 = GL_TEXTURE0 + 5, - GL_TEXTURE6 = GL_TEXTURE0 + 6, - - GL_TEXTURE_2D = 0x0DE1, - GL_TEXTURE_2D_ARRAY = 0x8C1A, - GL_UNPACK_ALIGNMENT = 0x0CF5, - - GL_TEXTURE_MAG_FILTER = 0x2800, - GL_TEXTURE_MIN_FILTER = 0x2801, - GL_NEAREST = 0x2600, - GL_LINEAR = 0x2601, - GL_NEAREST_MIPMAP_NEAREST = 0x2700, - GL_LINEAR_MIPMAP_NEAREST = 0x2701, - GL_NEAREST_MIPMAP_LINEAR = 0x2702, - GL_LINEAR_MIPMAP_LINEAR = 0x2703, - - GL_TEXTURE_WRAP_S = 0x2802, - GL_TEXTURE_WRAP_T = 0x2803, - GL_CLAMP_TO_EDGE = 0x812F, - GL_CLAMP_TO_BORDER = 0x812D, - GL_MIRRORED_REPEAT = 0x8370, - GL_MIRROR_CLAMP_TO_EDGE = 0x8743, - GL_CLAMP = 0x2900, - GL_REPEAT = 0x2901, - - GL_TRIANGLES = 0x0004, - - GL_SCISSOR_TEST = 0x0C11, - GL_DEPTH_TEST = 0x0B71, - - GL_TEXTURE_SWIZZLE_R = 0x8E42, - GL_TEXTURE_SWIZZLE_G = 0x8E43, - GL_TEXTURE_SWIZZLE_B = 0x8E44, - GL_TEXTURE_SWIZZLE_A = 0x8E45, - - GL_LESS = 0x0201, - } -} \ No newline at end of file diff --git a/Dashboard/OpenGL/GraphicsException.cs b/Dashboard/OpenGL/GraphicsException.cs index 2fb9632..5dcfcf4 100644 --- a/Dashboard/OpenGL/GraphicsException.cs +++ b/Dashboard/OpenGL/GraphicsException.cs @@ -1,10 +1,10 @@ using System; -using static Dashboard.OpenGL.GLEnum; +using OpenTK.Graphics.OpenGL4; namespace Dashboard.OpenGL { [System.Serializable] - public class GraphicsException : System.Exception + public class GraphicsException : Exception { public GraphicsException() { @@ -16,7 +16,7 @@ namespace Dashboard.OpenGL AddExtraData(); } - public GraphicsException(string message, System.Exception inner) : base(message, inner) + public GraphicsException(string message, Exception inner) : base(message, inner) { AddExtraData(); } @@ -30,12 +30,12 @@ namespace Dashboard.OpenGL private void AddExtraData() { - GL.Get(GL_MAJOR_VERSION, out int major); - GL.Get(GL_MINOR_VERSION, out int minor); + GL.GetInteger(GetPName.MajorVersion, out int major); + GL.GetInteger(GetPName.MinorVersion, out int minor); - string version = GL.GetString(GL_VERSION); - string vendor = GL.GetString(GL_VENDOR); - string renderer = GL.GetString(GL_RENDERER); + string version = GL.GetString(StringName.Version); + string vendor = GL.GetString(StringName.Vendor); + string renderer = GL.GetString(StringName.Renderer); Data.Add("OpenGL Version", new Version(major, minor)); Data.Add("OpenGL Version String", version);