Cleaned up code and added some parameter checks.
Removed some unused code fragments from older plans.
This commit is contained in:
parent
51cfc84cc7
commit
5e85eb5de1
@ -4,7 +4,6 @@ namespace SlatedGameToolkit.Framework.Exceptions
|
|||||||
{
|
{
|
||||||
public class OpenGLException : Exception {
|
public class OpenGLException : Exception {
|
||||||
public OpenGLException() : base() {
|
public OpenGLException() : base() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenGLException(string message) : base(message) {
|
public OpenGLException(string message) : base(message) {
|
||||||
|
@ -23,4 +23,5 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL
|
|||||||
internal delegate void GLDeleteProgramPipelines(uint size, UIntPtr[] pipelines);
|
internal delegate void GLDeleteProgramPipelines(uint size, UIntPtr[] pipelines);
|
||||||
internal delegate void GLBindProgramPipeline(UIntPtr pipeline);
|
internal delegate void GLBindProgramPipeline(UIntPtr pipeline);
|
||||||
internal delegate void GLUseProgramStages(UIntPtr pipeline, GLEnums bitField, UIntPtr program);
|
internal delegate void GLUseProgramStages(UIntPtr pipeline, GLEnums bitField, UIntPtr program);
|
||||||
|
internal delegate uint GLGetError();
|
||||||
}
|
}
|
@ -19,7 +19,6 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Programs
|
|||||||
|
|
||||||
public GLProgram(bool separable = true) {
|
public GLProgram(bool separable = true) {
|
||||||
this.context = WindowContextsManager.CurrentWindowContext();
|
this.context = WindowContextsManager.CurrentWindowContext();
|
||||||
context.MakeCurrent();
|
|
||||||
createProgram = Marshal.GetDelegateForFunctionPointer<GLCreateProgram>(SDL.SDL_GL_GetProcAddress("glCreateProgram"));
|
createProgram = Marshal.GetDelegateForFunctionPointer<GLCreateProgram>(SDL.SDL_GL_GetProcAddress("glCreateProgram"));
|
||||||
if (createProgram == null) throw new FrameworkSDLException();
|
if (createProgram == null) throw new FrameworkSDLException();
|
||||||
deleteProgram = Marshal.GetDelegateForFunctionPointer<GLDeleteProgram>(SDL.SDL_GL_GetProcAddress("glDeleteProgram"));
|
deleteProgram = Marshal.GetDelegateForFunctionPointer<GLDeleteProgram>(SDL.SDL_GL_GetProcAddress("glDeleteProgram"));
|
||||||
@ -39,7 +38,7 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Programs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Use() {
|
public virtual void Use() {
|
||||||
useProgram(handle);
|
useProgram(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Programs
|
|||||||
private readonly GLAttachShader attachShader;
|
private readonly GLAttachShader attachShader;
|
||||||
private readonly GLDetachShader detachShader;
|
private readonly GLDetachShader detachShader;
|
||||||
private GLBindAttribLocation bindAttribLocation;
|
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;
|
this.shaders = shaders;
|
||||||
attachShader = Marshal.GetDelegateForFunctionPointer<GLAttachShader>(SDL.SDL_GL_GetProcAddress("glAttachShader"));
|
attachShader = Marshal.GetDelegateForFunctionPointer<GLAttachShader>(SDL.SDL_GL_GetProcAddress("glAttachShader"));
|
||||||
if (attachShader == null) throw new FrameworkSDLException();
|
if (attachShader == null) throw new FrameworkSDLException();
|
||||||
|
@ -7,7 +7,7 @@ using SlatedGameToolkit.Framework.Graphics.Window;
|
|||||||
namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Shaders
|
namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Shaders
|
||||||
{
|
{
|
||||||
public class GLFragmentShader : GLShader {
|
public class GLFragmentShader : GLShader {
|
||||||
public GLFragmentShader(WindowContext context, string shader) : base() {
|
public GLFragmentShader(string shader) : base() {
|
||||||
Handle = createShader(GLEnums.GL_FRAGMENT_SHADER);
|
Handle = createShader(GLEnums.GL_FRAGMENT_SHADER);
|
||||||
shaderSource(Handle, 1, shader, null);
|
shaderSource(Handle, 1, shader, null);
|
||||||
compileShader(Handle);
|
compileShader(Handle);
|
||||||
|
@ -7,7 +7,7 @@ using SlatedGameToolkit.Framework.Graphics.Window;
|
|||||||
namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Shaders
|
namespace SlatedGameToolkit.Framework.Graphics.OpenGL.Shaders
|
||||||
{
|
{
|
||||||
public class GLVertexShader : GLShader {
|
public class GLVertexShader : GLShader {
|
||||||
public GLVertexShader(WindowContext context, string shader) : base() {
|
public GLVertexShader(string shader) : base() {
|
||||||
Handle = createShader(GLEnums.GL_VERTEX_SHADER);
|
Handle = createShader(GLEnums.GL_VERTEX_SHADER);
|
||||||
shaderSource(Handle, 1, shader, null);
|
shaderSource(Handle, 1, shader, null);
|
||||||
compileShader(Handle);
|
compileShader(Handle);
|
||||||
|
@ -25,6 +25,10 @@ namespace SlatedGameToolkit.Framework.StateSystem
|
|||||||
/// <param name="initialState">The name of the initial state.</param>
|
/// <param name="initialState">The name of the initial state.</param>
|
||||||
/// <param name="states">The initial set of game states to be added.</param>
|
/// <param name="states">The initial set of game states to be added.</param>
|
||||||
internal Manager(IState initialState) {
|
internal Manager(IState initialState) {
|
||||||
|
backgroundColour.r = 0.5f;
|
||||||
|
backgroundColour.g = 0.5f;
|
||||||
|
backgroundColour.b = 0.5f;
|
||||||
|
|
||||||
if (initialState == null) throw new ArgumentNullException("initialState");
|
if (initialState == null) throw new ArgumentNullException("initialState");
|
||||||
thread = Thread.CurrentThread;
|
thread = Thread.CurrentThread;
|
||||||
this.states = new Dictionary<string, IState>();
|
this.states = new Dictionary<string, IState>();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using SlatedGameToolkit.Framework;
|
|
||||||
using SlatedGameToolkit.Framework.Graphics.OpenGL.Programs;
|
using SlatedGameToolkit.Framework.Graphics.OpenGL.Programs;
|
||||||
|
using SlatedGameToolkit.Framework.Graphics.OpenGL.Shaders;
|
||||||
using SlatedGameToolkit.Framework.Graphics.Window;
|
using SlatedGameToolkit.Framework.Graphics.Window;
|
||||||
using SlatedGameToolkit.Framework.StateSystem;
|
using SlatedGameToolkit.Framework.StateSystem;
|
||||||
using SlatedGameToolkit.Framework.StateSystem.States;
|
using SlatedGameToolkit.Framework.StateSystem.States;
|
||||||
@ -37,6 +37,7 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground
|
|||||||
public void Initialize(Manager manager)
|
public void Initialize(Manager manager)
|
||||||
{
|
{
|
||||||
window = new WindowContext("SlatedGameToolkit Playground");
|
window = new WindowContext("SlatedGameToolkit Playground");
|
||||||
|
shader = new GLShaderProgram();
|
||||||
window.RaiseToTop();
|
window.RaiseToTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user