From 959788563f63e21004a64f3679ecdde87622c464 Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Fri, 22 Sep 2023 21:23:59 +0300 Subject: [PATCH] Fix small errors in driver. --- Quik/OpenGL/GL.cs | 4 ++-- Quik/OpenGL/GL21Driver.cs | 23 +++++++++++++---------- Quik/OpenGL/GLEnum.cs | 2 ++ Quik/res/gl21.frag | 2 +- Quik/res/gl21.vert | 4 ++-- tests/QuikDemo/Program.cs | 15 ++++++++++++++- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Quik/OpenGL/GL.cs b/Quik/OpenGL/GL.cs index 7a2183c..e06250b 100644 --- a/Quik/OpenGL/GL.cs +++ b/Quik/OpenGL/GL.cs @@ -16,7 +16,7 @@ namespace Quik.OpenGL 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 size, 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); @@ -88,7 +88,7 @@ namespace Quik.OpenGL 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 count, int offset) => _drawArrays(primitive, count, (void*)offset); + 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) diff --git a/Quik/OpenGL/GL21Driver.cs b/Quik/OpenGL/GL21Driver.cs index c0bb24c..5d3cd81 100644 --- a/Quik/OpenGL/GL21Driver.cs +++ b/Quik/OpenGL/GL21Driver.cs @@ -93,7 +93,7 @@ namespace Quik.OpenGL QMat4.Orthographic(out QMat4 matrix, view); GL.UseProgram(program); - GL.Uniform1(iMaxZ, queue.ZDepth); + GL.Uniform1(iMaxZ, queue.ZDepth+1); GL.UniformMatrix4(m4Transforms, false, in matrix); GL.Uniform1(fSdfThreshold, 0.0f); GL.Uniform1(txTexture, 0); @@ -116,7 +116,7 @@ namespace Quik.OpenGL GL.Uniform1(iEnableTexture, 0); } - GL.DrawArrays(GL_TRIANGLES, call.Count, call.Start); + GL.DrawElements(GL_TRIANGLES, call.Count, GL_UNSIGNED_INT, sizeof(int)*call.Start); } } @@ -138,6 +138,7 @@ namespace Quik.OpenGL int shader = GL.CreateShader(type); GL.ShaderSource(shader, text); + GL.CompileShader(shader); if (CheckShader(shader, out string msg) == false) { @@ -157,7 +158,7 @@ namespace Quik.OpenGL GL.GetShader(shader, GL_COMPILE_STATUS, out int i); - if (i != (int)GL_OK) + if (i != (int)GL_TRUE) { message = GL.GetShaderInfoLog(shader); return false; @@ -229,15 +230,13 @@ namespace Quik.OpenGL public DrawData(GL21Driver driver, DrawQueue queue) { - int a = 0, b = 0, c = 0, d = 0; Queue = queue; this.driver = driver; VertexArray = GL.GenVertexArray(); - GL.GenBuffers(4, out a); - vbo1 = a; - vbo2 = b; - ebo1 = c; - ebo2 = d; + GL.GenBuffers(1, out vbo1); + GL.GenBuffers(1, out vbo2); + GL.GenBuffers(1, out ebo1); + GL.GenBuffers(1, out ebo2); isDisposed = false; } @@ -257,7 +256,11 @@ namespace Quik.OpenGL GL.VertexAttribPointer(driver.v2Position, 2, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.PositionOffset); GL.VertexAttribIPointer(driver.iZIndex, 1, GL_UNSIGNED_INT, QuikVertex.Stride, QuikVertex.ZIndexOffset); GL.VertexAttribPointer(driver.v2TexPos, 2, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.TextureCoordinatesOffset); - GL.VertexAttribPointer(driver.v4Color, 4, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.ColorOffset); + GL.VertexAttribPointer(driver.v4Color, 4, GL_UNSIGNED_BYTE, true, QuikVertex.Stride, QuikVertex.ColorOffset); + GL.EnableVertexAttribArray(driver.v2Position); + GL.EnableVertexAttribArray(driver.iZIndex); + GL.EnableVertexAttribArray(driver.v2TexPos); + GL.EnableVertexAttribArray(driver.v4Color); GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, Queue.ElementCount * sizeof(int), Queue.ElementArray, GL_STREAM_DRAW); diff --git a/Quik/OpenGL/GLEnum.cs b/Quik/OpenGL/GLEnum.cs index 5b87531..3fedce9 100644 --- a/Quik/OpenGL/GLEnum.cs +++ b/Quik/OpenGL/GLEnum.cs @@ -3,6 +3,8 @@ namespace Quik.OpenGL public enum GLEnum : int { GL_OK = 0, + GL_TRUE = 1, + GL_FALSE = 0, GL_MAJOR_VERSION = 0x821B, GL_MINOR_VERSION = 0x821C, GL_VENDOR = 0x1F00, diff --git a/Quik/res/gl21.frag b/Quik/res/gl21.frag index 5b1b251..d110c47 100644 --- a/Quik/res/gl21.frag +++ b/Quik/res/gl21.frag @@ -2,7 +2,7 @@ * QUIK: User Interface Kit * Copyright (C) 2023 Halit Utku Maden, et al. */ -#version 110 +#version 120 varying vec2 fv2TexPos; varying vec4 fv4Color; diff --git a/Quik/res/gl21.vert b/Quik/res/gl21.vert index a402bbd..53f1532 100644 --- a/Quik/res/gl21.vert +++ b/Quik/res/gl21.vert @@ -2,7 +2,7 @@ * QUIK: User Interface Kit * Copyright (C) 2023 Halit Utku Maden, et al. */ -#version 110 +#version 120 attribute vec2 v2Position; /**< The vertex position.*/ attribute int iZIndex; /**< The z index. */ @@ -21,5 +21,5 @@ void main(void) gl_Position = v * m4Transforms; fv2TexPos = v2TexPos; - fv4Color = fv4Color; + fv4Color = v4Color; } \ No newline at end of file diff --git a/tests/QuikDemo/Program.cs b/tests/QuikDemo/Program.cs index 2f10163..3b35b4a 100644 --- a/tests/QuikDemo/Program.cs +++ b/tests/QuikDemo/Program.cs @@ -1,6 +1,9 @@ using Quik; +using Quik.CommandMachine; +using Quik.Controls; using Quik.OpenTK; + namespace QuikDemo { public static class Program @@ -9,7 +12,17 @@ namespace QuikDemo public static void Main(string[] args) { - Application.Run(new Quik.Controls.View()); + Application.Run(new EmptyView()); + } + } + + public class EmptyView : View + { + protected override void PaintBegin(CommandQueue cmd) + { + base.PaintBegin(cmd); + + cmd.Rectangle(new QRectangle(0, 0, 16, 16)); } } } \ No newline at end of file