From 5e85eb5de16b1d0030a32ef5a6b1adeaf5310ea9 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 29 May 2020 00:00:39 -0500 Subject: [PATCH] Cleaned up code and added some parameter checks. Removed some unused code fragments from older plans. --- src/SlatedGameToolkit.Framework/Exceptions/OpenGLException.cs | 1 - .../Graphics/OpenGL/GLFunctionDelegates.cs | 1 + .../Graphics/OpenGL/Programs/GLProgram.cs | 3 +-- .../Graphics/OpenGL/Programs/GLShaderProgram.cs | 3 ++- .../Graphics/OpenGL/Shaders/GLFragmentShader.cs | 2 +- .../Graphics/OpenGL/Shaders/GLVertexShader.cs | 2 +- src/SlatedGameToolkit.Framework/StateSystem/Manager.cs | 4 ++++ .../Utilities/GraphicalPlayground/MainState.cs | 3 ++- 8 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/SlatedGameToolkit.Framework/Exceptions/OpenGLException.cs b/src/SlatedGameToolkit.Framework/Exceptions/OpenGLException.cs index 18e6323..efaff0b 100644 --- a/src/SlatedGameToolkit.Framework/Exceptions/OpenGLException.cs +++ b/src/SlatedGameToolkit.Framework/Exceptions/OpenGLException.cs @@ -4,7 +4,6 @@ namespace SlatedGameToolkit.Framework.Exceptions { public class OpenGLException : Exception { public OpenGLException() : base() { - } public OpenGLException(string message) : base(message) { diff --git a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/GLFunctionDelegates.cs b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/GLFunctionDelegates.cs index 827ade4..be93cf4 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/GLFunctionDelegates.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/GLFunctionDelegates.cs @@ -23,4 +23,5 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL internal delegate void GLDeleteProgramPipelines(uint size, UIntPtr[] pipelines); internal delegate void GLBindProgramPipeline(UIntPtr pipeline); internal delegate void GLUseProgramStages(UIntPtr pipeline, GLEnums bitField, UIntPtr program); + internal delegate uint GLGetError(); } \ No newline at end of file diff --git a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Programs/GLProgram.cs b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Programs/GLProgram.cs index c9caa36..168023d 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Programs/GLProgram.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Programs/GLProgram.cs @@ -19,7 +19,6 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Programs public GLProgram(bool separable = true) { this.context = WindowContextsManager.CurrentWindowContext(); - context.MakeCurrent(); createProgram = Marshal.GetDelegateForFunctionPointer(SDL.SDL_GL_GetProcAddress("glCreateProgram")); if (createProgram == null) throw new FrameworkSDLException(); deleteProgram = Marshal.GetDelegateForFunctionPointer(SDL.SDL_GL_GetProcAddress("glDeleteProgram")); @@ -39,7 +38,7 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Programs } } - public void Use() { + public virtual void Use() { useProgram(handle); } diff --git a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Programs/GLShaderProgram.cs b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Programs/GLShaderProgram.cs index a5d1dee..a6b4823 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Programs/GLShaderProgram.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Programs/GLShaderProgram.cs @@ -13,7 +13,8 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Programs private readonly GLAttachShader attachShader; private readonly GLDetachShader detachShader; private GLBindAttribLocation bindAttribLocation; - public GLShaderProgram(WindowContext context, bool separable = true, params GLShader[] shaders) : base(separable) { + public GLShaderProgram(bool separable = true, params GLShader[] shaders) : base(separable) { + if (shaders.Length == 0) throw new ArgumentException("Requires at least one shader for shader program."); this.shaders = shaders; attachShader = Marshal.GetDelegateForFunctionPointer(SDL.SDL_GL_GetProcAddress("glAttachShader")); if (attachShader == null) throw new FrameworkSDLException(); diff --git a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Shaders/GLFragmentShader.cs b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Shaders/GLFragmentShader.cs index 0888279..0e50b8b 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Shaders/GLFragmentShader.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Shaders/GLFragmentShader.cs @@ -7,7 +7,7 @@ using SlatedGameToolkit.Framework.Graphics.Window; namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Shaders { public class GLFragmentShader : GLShader { - public GLFragmentShader(WindowContext context, string shader) : base() { + public GLFragmentShader(string shader) : base() { Handle = createShader(GLEnums.GL_FRAGMENT_SHADER); shaderSource(Handle, 1, shader, null); compileShader(Handle); diff --git a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Shaders/GLVertexShader.cs b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Shaders/GLVertexShader.cs index dc15b52..2c7b832 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Shaders/GLVertexShader.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/OpenGL/Shaders/GLVertexShader.cs @@ -7,7 +7,7 @@ using SlatedGameToolkit.Framework.Graphics.Window; namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Shaders { public class GLVertexShader : GLShader { - public GLVertexShader(WindowContext context, string shader) : base() { + public GLVertexShader(string shader) : base() { Handle = createShader(GLEnums.GL_VERTEX_SHADER); shaderSource(Handle, 1, shader, null); compileShader(Handle); diff --git a/src/SlatedGameToolkit.Framework/StateSystem/Manager.cs b/src/SlatedGameToolkit.Framework/StateSystem/Manager.cs index 5f65ef6..f70503c 100644 --- a/src/SlatedGameToolkit.Framework/StateSystem/Manager.cs +++ b/src/SlatedGameToolkit.Framework/StateSystem/Manager.cs @@ -25,6 +25,10 @@ namespace SlatedGameToolkit.Framework.StateSystem /// The name of the initial state. /// The initial set of game states to be added. internal Manager(IState initialState) { + backgroundColour.r = 0.5f; + backgroundColour.g = 0.5f; + backgroundColour.b = 0.5f; + if (initialState == null) throw new ArgumentNullException("initialState"); thread = Thread.CurrentThread; this.states = new Dictionary(); diff --git a/src/SlatedGameToolkit.Tools/Utilities/GraphicalPlayground/MainState.cs b/src/SlatedGameToolkit.Tools/Utilities/GraphicalPlayground/MainState.cs index 0a33c9c..7869dd4 100644 --- a/src/SlatedGameToolkit.Tools/Utilities/GraphicalPlayground/MainState.cs +++ b/src/SlatedGameToolkit.Tools/Utilities/GraphicalPlayground/MainState.cs @@ -1,6 +1,6 @@ using System; -using SlatedGameToolkit.Framework; using SlatedGameToolkit.Framework.Graphics.OpenGL.Programs; +using SlatedGameToolkit.Framework.Graphics.OpenGL.Shaders; using SlatedGameToolkit.Framework.Graphics.Window; using SlatedGameToolkit.Framework.StateSystem; using SlatedGameToolkit.Framework.StateSystem.States; @@ -37,6 +37,7 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground public void Initialize(Manager manager) { window = new WindowContext("SlatedGameToolkit Playground"); + shader = new GLShaderProgram(); window.RaiseToTop(); }