diff --git a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/GLContext.cs b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/GLContext.cs index 643197c..de571a3 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/GLContext.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/GLContext.cs @@ -1150,12 +1150,13 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void PFNGLBUFFERSUBDATAPROC(BufferTargetARB target, IntPtr offset, IntPtr size, IntPtr data); + private delegate void PFNGLBUFFERSUBDATAPROC(BufferTargetARB target, IntPtr offset, UIntPtr size, IntPtr data); private PFNGLBUFFERSUBDATAPROC glBufferSubData; - public void BufferSubData(BufferTargetARB target, IntPtr offset, IntPtr size, IntPtr data) + public void BufferSubData(BufferTargetARB target, IntPtr offset, UIntPtr size, IntPtr data) { glBufferSubData.Invoke(target, offset, size, data); + DetectGLError(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -1165,6 +1166,7 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL public void GetBufferSubData(BufferTargetARB target, IntPtr offset, IntPtr size, out IntPtr data) { glGetBufferSubData.Invoke(target, offset, size, out data); + DetectGLError(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] diff --git a/src/SlatedGameToolkit.Framework/Graphics/Render/MeshBatch.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/MeshBatch.cs index c20a8eb..aac0cae 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Render/MeshBatch.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Render/MeshBatch.cs @@ -11,6 +11,7 @@ using SlatedGameToolkit.Framework.Utilities; namespace SlatedGameToolkit.Framework.Graphics.Render { public class MeshBatch : IDisposable { + public bool Debug { get; set; } private const int VERTEX_LENGTH = 9; private bool disposed; private float batchDelta; @@ -122,10 +123,10 @@ namespace SlatedGameToolkit.Framework.Graphics.Render } int elementsCount = indices.Length; Array.Copy(indices, 0, this.indices, indicesIndex, elementsCount); + indiceOffsets[offsetIndex] = indicesIndex * sizeof(uint); indicesIndex += elementsCount; if (offsetIndex + 1 < verticeOffsets.Length) { verticeOffsets[offsetIndex + 1] = verticeOffsets[offsetIndex] + vertices.Length; - indiceOffsets[offsetIndex + 1] = indicesIndex * sizeof(int); } lengths[offsetIndex] = elementsCount; offsetIndex++; @@ -153,6 +154,12 @@ namespace SlatedGameToolkit.Framework.Graphics.Render GLContext.UniformMatrix4fv(modelALoc, 1, false, modelsMatrix.ToColumnMajorArray()); if (camera.ViewChanged) GLContext.UniformMatrix4fv(viewALoc, 1, false, camera.ViewMatrix.ToColumnMajorArray()); if (camera.ProjectionChanged) GLContext.UniformMatrix4fv(projALoc, 1, false, camera.ProjectionMatrix.ToColumnMajorArray()); + + if (Debug) { + GLContext.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); + } else { + GLContext.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); + } GLContext.MultiDrawElementsBaseVertex(PrimitiveType.Triangles, lengths, DrawElementsType.UnsignedInt, indiceOffsets, offsetIndex, verticeOffsets); dataIndex = 0; indicesIndex = 0; diff --git a/src/SlatedGameToolkit.Framework/Graphics/Render/VertexArrayBuffers.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/VertexArrayBuffers.cs index 4a54bb9..c35a3bb 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Render/VertexArrayBuffers.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Render/VertexArrayBuffers.cs @@ -47,7 +47,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render glContext.BufferData(BufferTargetARB.ArrayBuffer, requiredLength, new IntPtr(pointer), dynamic ? OpenGL.BufferUsageARB.DynamicDraw : OpenGL.BufferUsageARB.StaticDraw); vertexBufferLength = requiredLength; } else { - glContext.BufferSubData(BufferTargetARB.ArrayBuffer, IntPtr.Zero, new IntPtr(requiredLength), new IntPtr(pointer)); + glContext.BufferSubData(BufferTargetARB.ArrayBuffer, IntPtr.Zero, new UIntPtr(requiredLength), new IntPtr(pointer)); } } } @@ -60,7 +60,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render glContext.BufferData(OpenGL.BufferTargetARB.ElementArrayBuffer, requiredLength, new IntPtr(pointer), dynamic ? OpenGL.BufferUsageARB.DynamicDraw : OpenGL.BufferUsageARB.StaticDraw); indexBufferLength = requiredLength; } else { - glContext.BufferSubData(BufferTargetARB.ElementArrayBuffer, IntPtr.Zero, new IntPtr(requiredLength), new IntPtr(pointer)); + glContext.BufferSubData(BufferTargetARB.ElementArrayBuffer, IntPtr.Zero, new UIntPtr(requiredLength), new IntPtr(pointer)); } } } diff --git a/src/SlatedGameToolkit.Framework/Resources/default.frag b/src/SlatedGameToolkit.Framework/Resources/default.frag index 15c20d9..1806fba 100644 --- a/src/SlatedGameToolkit.Framework/Resources/default.frag +++ b/src/SlatedGameToolkit.Framework/Resources/default.frag @@ -12,8 +12,7 @@ void main() { if (textured) { if (singleChanneled) { - float singleVal = texture(texture0, vec2(texCoord.x, 1 - texCoord.y)).r; - outputColor = vec4(singleVal); + outputColor = vec4(color.xyz, texture(texture0, vec2(texCoord.x, 1 - texCoord.y)).r); } else { outputColor = texture(texture0, vec2(texCoord.x, 1 - texCoord.y)) * color; } diff --git a/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs b/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs index ae7e089..38b723f 100644 --- a/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs +++ b/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs @@ -86,7 +86,8 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground renderer.Draw(logo); renderer.Draw(textureTester); renderer.Draw(untextured); - font.Draw(renderer, delta, 0.25f, -0.25f, "123", Color.White); + font.Draw(renderer, delta, 0.25f, -0.25f, "1234", Color.White); + font.Draw(renderer, delta, 0.25f, -0.35f, "abcd", Color.White); renderer.End(); }