Fixed issue with incorrect delegate signature.

This commit is contained in:
Harrison Deng 2020-06-01 16:31:56 -05:00
parent e59e78e08c
commit 484dbbece3
11 changed files with 227 additions and 130 deletions

View File

@ -15,6 +15,7 @@ namespace SlatedGameToolkit.Framework {
/// The main engine that will host the game loop.
/// </summary>
public static class GameEngine {
public static bool Debugging { get; set; }
public static Logger Logger { get; private set; }
private static readonly object ignitionLock = new object();
private static readonly object deltaUpdateLock = new object();
@ -77,103 +78,106 @@ namespace SlatedGameToolkit.Framework {
if (!(o is IState)) throw new InternalFrameworkException(String.Format("Expected initial state object for asynchronous loop. Got {0}", o));
IState initialState = (IState) o;
Manager manager = new Manager(initialState);
DateTime currentTime = DateTime.Now;
TimeSpan timePassedFromLastUpdate = TimeSpan.Zero;
TimeSpan timePassedFromLastRender = TimeSpan.Zero;
TimeSpan updateDeltaTime = GameEngine.updateDeltaTime;
TimeSpan frameDeltaTime = GameEngine.frameDeltaTime;
deltaChanged = true;
stopped = false;
Logger.Information("Game engine initiated.");
while (!exit) {
//Pull latest deltas.
if (deltaChanged) {
lock (deltaUpdateLock) {
updateDeltaTime = GameEngine.updateDeltaTime;
frameDeltaTime = GameEngine.frameDeltaTime;
Logger.Information(String.Format("Deltas were set. Update Delta: {0}, Render target Delta: {1}", updateDeltaTime.TotalSeconds, frameDeltaTime.TotalSeconds));
try {
DateTime currentTime = DateTime.Now;
TimeSpan timePassedFromLastUpdate = TimeSpan.Zero;
TimeSpan timePassedFromLastRender = TimeSpan.Zero;
TimeSpan updateDeltaTime = GameEngine.updateDeltaTime;
TimeSpan frameDeltaTime = GameEngine.frameDeltaTime;
deltaChanged = true;
stopped = false;
Logger.Information("Game engine initiated.");
while (!exit) {
//Pull latest deltas.
if (deltaChanged) {
lock (deltaUpdateLock) {
updateDeltaTime = GameEngine.updateDeltaTime;
frameDeltaTime = GameEngine.frameDeltaTime;
Logger.Information(String.Format("Deltas were set. Update Delta: {0}, Render target Delta: {1}", updateDeltaTime.TotalSeconds, frameDeltaTime.TotalSeconds));
}
deltaChanged = false;
}
deltaChanged = false;
}
//Events
SDL.SDL_Event SDL_Event;
while (SDL.SDL_PollEvent(out SDL_Event) != 0) {
switch (SDL_Event.type) {
case SDL.SDL_EventType.SDL_MOUSEMOTION:
Mouse.OnMouseMoved(SDL_Event.motion.x, SDL_Event.motion.y);
break;
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
Mouse.OnScroll(SDL_Event.wheel.x, SDL_Event.wheel.y);
break;
case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
if (SDL.SDL_BUTTON_LEFT == SDL_Event.button.button) {
Mouse.OnLeftChange(true);
} else if (SDL.SDL_BUTTON_RIGHT == SDL_Event.button.button) {
Mouse.OnRightChange(true);
} else if (SDL.SDL_BUTTON_MIDDLE == SDL_Event.button.button) {
Mouse.OnMiddleChange(true);
}
break;
case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
if (SDL.SDL_BUTTON_LEFT == SDL_Event.button.button) {
Mouse.OnLeftChange(false);
} else if (SDL.SDL_BUTTON_RIGHT == SDL_Event.button.button) {
Mouse.OnRightChange(false);
} else if (SDL.SDL_BUTTON_MIDDLE == SDL_Event.button.button) {
Mouse.OnMiddleChange(false);
}
break;
case SDL.SDL_EventType.SDL_KEYDOWN:
Keyboard.OnKeyPressed((Key) SDL_Event.key.keysym.sym);
break;
case SDL.SDL_EventType.SDL_KEYUP:
Keyboard.OnKeyReleased((Key) SDL_Event.key.keysym.sym);
break;
case SDL.SDL_EventType.SDL_WINDOWEVENT:
WindowContext handle = WindowContextsManager.ContextFromWindowID(SDL_Event.window.windowID);
switch (SDL_Event.window.windowEvent)
{
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
handle.OnResize(SDL_Event.window.data1, SDL_Event.window.data2);
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
handle.OnFocusLost();
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
handle.OnFocusGained();
break;
}
//Events
SDL.SDL_Event SDL_Event;
while (SDL.SDL_PollEvent(out SDL_Event) != 0) {
switch (SDL_Event.type) {
case SDL.SDL_EventType.SDL_MOUSEMOTION:
Mouse.OnMouseMoved(SDL_Event.motion.x, SDL_Event.motion.y);
break;
case SDL.SDL_EventType.SDL_QUIT:
Stop();
break;
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
Mouse.OnScroll(SDL_Event.wheel.x, SDL_Event.wheel.y);
break;
case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
if (SDL.SDL_BUTTON_LEFT == SDL_Event.button.button) {
Mouse.OnLeftChange(true);
} else if (SDL.SDL_BUTTON_RIGHT == SDL_Event.button.button) {
Mouse.OnRightChange(true);
} else if (SDL.SDL_BUTTON_MIDDLE == SDL_Event.button.button) {
Mouse.OnMiddleChange(true);
}
break;
case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
if (SDL.SDL_BUTTON_LEFT == SDL_Event.button.button) {
Mouse.OnLeftChange(false);
} else if (SDL.SDL_BUTTON_RIGHT == SDL_Event.button.button) {
Mouse.OnRightChange(false);
} else if (SDL.SDL_BUTTON_MIDDLE == SDL_Event.button.button) {
Mouse.OnMiddleChange(false);
}
break;
case SDL.SDL_EventType.SDL_KEYDOWN:
Keyboard.OnKeyPressed((Key) SDL_Event.key.keysym.sym);
break;
case SDL.SDL_EventType.SDL_KEYUP:
Keyboard.OnKeyReleased((Key) SDL_Event.key.keysym.sym);
break;
case SDL.SDL_EventType.SDL_WINDOWEVENT:
WindowContext handle = WindowContextsManager.ContextFromWindowID(SDL_Event.window.windowID);
switch (SDL_Event.window.windowEvent)
{
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
handle.OnResize(SDL_Event.window.data1, SDL_Event.window.data2);
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
handle.OnFocusLost();
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
handle.OnFocusGained();
break;
}
break;
case SDL.SDL_EventType.SDL_QUIT:
Stop();
break;
}
}
DateTime frameStart = DateTime.Now;
TimeSpan difference = frameStart - currentTime;
currentTime = frameStart;
timePassedFromLastUpdate += difference;
while (timePassedFromLastUpdate > updateDeltaTime) {
//Updates.
manager.update(updateDeltaTime.TotalMilliseconds <= 0 ? timePassedFromLastUpdate.TotalSeconds : updateDeltaTime.TotalSeconds);
timePassedFromLastUpdate -= updateDeltaTime;
if (updateDeltaTime.TotalSeconds <= 0) break;
}
timePassedFromLastRender += difference;
if (timePassedFromLastRender > frameDeltaTime) {
//Draw calls.
manager.render(timePassedFromLastUpdate.TotalSeconds);
timePassedFromLastRender = TimeSpan.Zero;
}
}
DateTime frameStart = DateTime.Now;
TimeSpan difference = frameStart - currentTime;
currentTime = frameStart;
timePassedFromLastUpdate += difference;
while (timePassedFromLastUpdate > updateDeltaTime) {
//Updates.
manager.update(updateDeltaTime.TotalMilliseconds <= 0 ? timePassedFromLastUpdate.TotalSeconds : updateDeltaTime.TotalSeconds);
timePassedFromLastUpdate -= updateDeltaTime;
if (updateDeltaTime.TotalSeconds <= 0) break;
}
timePassedFromLastRender += difference;
if (timePassedFromLastRender > frameDeltaTime) {
//Draw calls.
manager.render(timePassedFromLastUpdate.TotalSeconds);
timePassedFromLastRender = TimeSpan.Zero;
}
} finally {
stopped = true;
manager.Dispose();
SDL.SDL_Quit();
Logger.Information("Game engine has stopped.");
Logger.Dispose();
Logger = null;
}
stopped = true;
manager.Dispose();
SDL.SDL_Quit();
Logger.Information("Game engine has stopped.");
Logger.Dispose();
Logger = null;
}
/// <summary>

View File

@ -5,55 +5,102 @@ using SlatedGameToolkit.Framework.Exceptions;
namespace SlatedGameToolkit.Framework.Graphics
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLClearColour(float r, float g, float b);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLClear(GLEnums flags);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLViewport(int x, int y, int width, int height);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate UIntPtr GLCreateShader(GLEnums type);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate UIntPtr GLShaderSource(UIntPtr shaderHandle, uint count, string program, int[] length);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLCompileShader(UIntPtr shaderHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLGetShaderLogInfo(UIntPtr shader, uint maxLength, out uint writtenLength, out string output);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate UIntPtr GLCreateProgram();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate UIntPtr GLDeleteProgram(UIntPtr program);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLAttachShader(UIntPtr program, UIntPtr shader);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDetachShader(UIntPtr program, UIntPtr shader);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDeleteShader(UIntPtr shader);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLBindAttribLocation(UIntPtr program, uint index, string name);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLGetProgramInfoLog(UIntPtr program, uint maxLength, out uint writtenLength, out string output);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLLinkProgram(UIntPtr program);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLProgramParameter(UIntPtr program, GLEnums parameterName, int value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLUseProgram(UIntPtr program);
internal delegate void GLGenProgramPipelines(uint size, out UIntPtr[] pipelines);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLGenProgramPipelines(uint size, UIntPtr[] pipelines);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDeleteProgramPipelines(uint size, UIntPtr[] pipelines);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLBindProgramPipeline(UIntPtr pipeline);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLUseProgramStages(UIntPtr pipeline, GLEnums bitField, UIntPtr program);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate uint GLGetError();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int GLGetAttribLocation(UIntPtr program, string attribName);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLBindBuffer(GLEnums target, UIntPtr buffer);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLGenBuffers(uint size, UIntPtr[] buffers);
internal unsafe delegate void GLBufferData(GLEnums target, uint size, void* data, GLEnums usage);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate void GLBufferData(GLEnums target, uint size, Array data, GLEnums usage);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDeleteBuffers(uint size, UIntPtr[] buffers);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLVertexAttribPointer(uint index, int size, GLEnums type, bool normalized, uint stride, uint offset);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLGenVertexArrays(uint amount, UIntPtr[] arrays);
internal delegate void GLDeleteVertexArrays(uint amount, UIntPtr[] arrays);
internal delegate void GLBindVertexArray(UIntPtr array);
internal delegate void GLEnableVertexAttribArray(uint attribIndex);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDeleteVertexArrays(uint amount, UIntPtr[] arrays);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLBindVertexArray(UIntPtr array);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLEnableVertexAttribArray(uint attribIndex);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDisableVertexAttribArray(uint attribIndex);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDrawArrays(GLEnums mode, int first, uint count);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDrawElements(GLEnums mode, uint count, int offset);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLMultiDrawArrays(GLEnums mode, int[] first, uint[] count, uint primout);
internal delegate void GLMultiDrawElements(GLEnums mode, uint[] count, GLEnums type, uint[] indices);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLMultiDrawElements(GLEnums mode, uint[] count, GLEnums type, IntPtr indices, int length);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLGenTextures(uint n, UIntPtr[] textureHandles);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLBindTexture(GLEnums target, UIntPtr texture);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLDeleteTextures(uint n, UIntPtr[] textureHandles);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLTexParameteri(GLEnums target, GLEnums pname, int value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLTexParameterf(GLEnums target, GLEnums pname, float value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLTexParameteriv(GLEnums target, GLEnums pname, int[] values);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLTexParameterfv(GLEnums target, GLEnums pname, float[] values);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLTexImage2D(GLEnums target, int level, int internalFormat, uint width, uint height, int border, GLEnums format, GLEnums type, byte[] data);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GLGenerateMipMap(GLEnums target);
internal static class GLFunctionUtils {
public static T RetrieveGLDelegate<T>(string functionName) where T : Delegate {
GameEngine.Logger.Debug(String.Format("Retrieving function with name: {0}", functionName));
IntPtr functionAddress = SDL.SDL_GL_GetProcAddress(functionName);
if (functionAddress == null) throw new FrameworkSDLException();
return Marshal.GetDelegateForFunctionPointer<T>(functionAddress);

View File

@ -12,9 +12,11 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
/// </summary>
/// <value></value>
ValueTuple<Vector3, Vector2>[] Vertices { get; }
/// <summary>
/// Returns indicies representing the vertices to use to create the mesh.
/// </summary>
/// <value>unsigned integers that are the indices of the vertices to use.</value>
uint[] Elements { get; }
Vector3 Rotation { get; set; }
Vector3 Translation { get; set; }
Vector3 Scale { get; set; }
}
}

View File

@ -4,13 +4,13 @@ using System.Numerics;
namespace SlatedGameToolkit.Framework.Graphics.Meshes
{
public class RectangleMesh : IMeshable
public abstract class RectangleMesh : IMeshable
{
private bool changed = true;
private Matrix4x4 matRot, matTrans, matScale;
private Vector3 rotation, translation, scale;
private Vector2 origin, dimensions;
public readonly Vector2[] texCoords = new Vector2[4];
protected readonly Vector2[] textureCoords = new Vector2[4];
private ValueTuple<Vector3, Vector2>[] vertices = new ValueTuple<Vector3, Vector2>[4];
private uint[] indices = new uint[] {0, 1, 3, 1, 2, 3};
@ -28,8 +28,9 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
return origin.X;
}
set
protected set
{
changed = true;
origin.X = X;
}
}
@ -40,8 +41,9 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
return origin.Y;
}
set
protected set
{
changed = true;
origin.Y = value;
}
}
@ -53,7 +55,9 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
return dimensions.X;
}
set {
protected set
{
changed = true;
dimensions.X = value;
}
}
@ -65,8 +69,9 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
return dimensions.Y;
}
set
protected set
{
changed = true;
dimensions.Y = value;
}
}
@ -75,10 +80,12 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
public Vector3 Translation
{
get {
get
{
return rotation;
}
set {
set
{
changed = true;
translation = value;
matTrans = Matrix4x4.CreateTranslation(value);
@ -87,11 +94,13 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
public Vector3 Scale
{
get {
get
{
return scale;
}
set {
set
{
changed = true;
scale = value;
matScale = Matrix4x4.CreateScale(value);
@ -122,7 +131,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
Matrix4x4 transform = matTrans * matRot * matScale;
for (int i = 0; i < vertices.Length; i++)
{
vertices[i] = new ValueTuple<Vector3, Vector2>(Vector3.Transform(baseVerts[i], transform), texCoords[i]);
vertices[i] = new ValueTuple<Vector3, Vector2>(Vector3.Transform(baseVerts[i], transform), textureCoords[i]);
}
changed = false;
}

View File

@ -22,7 +22,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
private uint dataIndex, indicesIndex, lengthsIndex;
public Batch(uint BatchVertexSize = 4096) {
multiDrawElements = GLFunctionUtils.RetrieveGLDelegate<GLMultiDrawElements>("glMultDrawElements");
multiDrawElements = GLFunctionUtils.RetrieveGLDelegate<GLMultiDrawElements>("glMultiDrawElements");
indices = new uint[BatchVertexSize];
lengths = new uint[BatchVertexSize];
offsets = new uint[BatchVertexSize];
@ -50,7 +50,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
vertexArray.Dispose();
}
public virtual void Draw(IMeshable meshable, Color color) {
public virtual void Add(IMeshable meshable, Color color) {
ValueTuple<Vector3, Vector2>[] vertices = meshable.Vertices;
uint[] indices = meshable.Elements;
if (vertices.Length * VERTEX_LENGTH + dataIndex >= data.Length || indices.Length + indicesIndex >= indicesIndex) Flush();
@ -93,7 +93,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
dataIndex = 0;
indicesIndex = 0;
lengthsIndex = 0;
multiDrawElements(GLEnums.GL_TRIANGLE_STRIP, lengths, GLEnums.GL_UNSIGNED_INT, offsets);
multiDrawElements(GLEnums.GL_TRIANGLE_STRIP, lengths, GLEnums.GL_UNSIGNED_INT, IntPtr.Zero, lengths.Length);
}
}
}

View File

@ -1,13 +1,27 @@
using System;
using System.Drawing;
using SlatedGameToolkit.Framework.Graphics.Textures;
namespace SlatedGameToolkit.Framework.Graphics.Render
{
public class Renderer
public class Renderer : IDisposable
{
private Batch batch;
private Texture currentTexture;
public Renderer(Batch batch) {
this.batch = batch;
}
public Renderer() {
this.batch = new Batch();
}
public void Dispose()
{
batch.Dispose();
}
public void Queue(IRenderable renderable, Color color) {
if (renderable.Texture != currentTexture) {
if (batch.Batching) batch.End();
@ -15,7 +29,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
currentTexture.Use();
batch.Begin(currentTexture);
}
batch.Draw(renderable, color);
batch.Add(renderable, color);
}
public void Render() {

View File

@ -1,6 +1,24 @@
using SlatedGameToolkit.Framework.Graphics.Meshes;
using SlatedGameToolkit.Framework.Graphics.Textures;
namespace SlatedGameToolkit.Framework.Graphics.Render
{
public class Sprite2D
public class Sprite2D : RectangleMesh, IRenderable
{
public Texture Texture { get; private set; }
public Sprite2D(Texture texture) {
this.Texture = texture;
this.textureCoords[0].X = -1;
this.textureCoords[0].Y = -1;
this.textureCoords[1].X = 1;
this.textureCoords[1].Y = -1;
this.textureCoords[2].X = 1;
this.textureCoords[2].Y = 1;
this.textureCoords[3].X = -1;
this.textureCoords[3].Y = 1;
}
}
}

View File

@ -20,7 +20,6 @@ namespace SlatedGameToolkit.Framework.Graphics.Shaders
private GLEnableVertexAttribArray enableVertexAttribArray;
private GLDisableVertexAttribArray disableVertexAttribArray;
private GLBufferData bufferData;
public GLVertexArraySet(uint amount) {
if (amount > int.MaxValue) throw new ArgumentOutOfRangeException("amount");
this.Count = (int)amount;
@ -34,12 +33,15 @@ namespace SlatedGameToolkit.Framework.Graphics.Shaders
enableVertexAttribArray = GLFunctionUtils.RetrieveGLDelegate<GLEnableVertexAttribArray>("glEnableVertexAttribArray");
disableVertexAttribArray = GLFunctionUtils.RetrieveGLDelegate<GLDisableVertexAttribArray>("glDisableVertexAttribArray");
bufferData = GLFunctionUtils.RetrieveGLDelegate<GLBufferData>("glBufferData");
arrayBufferHandles = new UIntPtr[amount];
vertexArrayHandles = new UIntPtr[amount];
indexArrayHandles = new UIntPtr[amount];
genBuffers(amount, arrayBufferHandles);
OpenGLErrorException.CheckGLErrorStatus();
genVertexArrays(amount, vertexArrayHandles);
OpenGLErrorException.CheckGLErrorStatus();
genBuffers(amount, indexArrayHandles);
OpenGLErrorException.CheckGLErrorStatus();
}
public void Use(uint index) {
@ -52,17 +54,13 @@ namespace SlatedGameToolkit.Framework.Graphics.Shaders
public unsafe void BufferVertices(uint index, float[] data, bool dynamic) {
Use(index);
fixed (void* arrayData = &data[0]) {
bufferData(GLEnums.GL_ARRAY_BUFFER, (uint) (sizeof(float) * data.Length), arrayData, dynamic ? GLEnums.GL_DYNAMIC_DRAW : GLEnums.GL_STATIC_DRAW);
}
bufferData(GLEnums.GL_ARRAY_BUFFER, (uint) (sizeof(float) * data.Length), data, dynamic ? GLEnums.GL_DYNAMIC_DRAW : GLEnums.GL_STATIC_DRAW);
OpenGLErrorException.CheckGLErrorStatus();
}
public unsafe void BufferIndices(uint index, uint[] data, bool dynamic) {
Use(index);
fixed (void* arrayData = &data[0]) {
bufferData(GLEnums.GL_ELEMENT_ARRAY_BUFFER, (uint) (sizeof(float) * data.Length), arrayData, dynamic ? GLEnums.GL_DYNAMIC_DRAW : GLEnums.GL_STATIC_DRAW);
}
bufferData(GLEnums.GL_ELEMENT_ARRAY_BUFFER, (uint) (sizeof(float) * data.Length), data, dynamic ? GLEnums.GL_DYNAMIC_DRAW : GLEnums.GL_STATIC_DRAW);
OpenGLErrorException.CheckGLErrorStatus();
}

View File

@ -17,11 +17,11 @@ namespace SlatedGameToolkit.Framework.Graphics.Shaders
this.index = 0;
}
public unsafe void BufferVertices(float[] data, bool dynamic = true) {
public void BufferVertices(float[] data, bool dynamic = true) {
glVertexArraySet.BufferVertices(index, data, dynamic);
}
public unsafe void BufferIndices(uint[] data, bool dynamic = true) {
public void BufferIndices(uint[] data, bool dynamic = true) {
glVertexArraySet.BufferIndices(index, data, dynamic);
}

View File

@ -22,6 +22,7 @@ namespace SlatedGameToolkit.Framework.Graphics
public GLTexture2DSet(TextureData[] textureDatas, bool linear = false, bool mipmap = false)
{
this.linear = linear;
this.mipmap = mipmap;
genTextures = GLFunctionUtils.RetrieveGLDelegate<GLGenTextures>("glGenTextures");
deleteTextures = GLFunctionUtils.RetrieveGLDelegate<GLDeleteTextures>("glDeleteTextures");
bindTexture = GLFunctionUtils.RetrieveGLDelegate<GLBindTexture>("glBindTexture");
@ -29,7 +30,7 @@ namespace SlatedGameToolkit.Framework.Graphics
texParameterfv = GLFunctionUtils.RetrieveGLDelegate<GLTexParameterfv>("glTexParameterfv");
texImage2D = GLFunctionUtils.RetrieveGLDelegate<GLTexImage2D>("glTexImage2D");
generateMipMap = GLFunctionUtils.RetrieveGLDelegate<GLGenerateMipMap>("glGenerateMipMap");
handle = new UIntPtr[textureDatas.Length];
genTextures((uint)textureDatas.Length, handle);
for (uint i = 0; i < textureDatas.Length; i++) {
Setup(i, textureDatas[i]);

View File

@ -1,6 +1,8 @@
using System;
using SlatedGameToolkit.Framework.Graphics.Programs;
using SlatedGameToolkit.Framework.Graphics.Render;
using SlatedGameToolkit.Framework.Graphics.Shaders;
using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Graphics.Window;
using SlatedGameToolkit.Framework.StateSystem;
using SlatedGameToolkit.Framework.StateSystem.States;
@ -10,6 +12,8 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground
public class MainState : IState
{
private WindowContext window;
private Renderer renderer;
private Sprite2D sprite;
public WindowContext CurrentWindow { get { return window;}}
@ -36,7 +40,7 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground
public void Initialize(Manager manager)
{
window = new WindowContext("SlatedGameToolkit Playground");
window.RaiseToTop();
renderer = new Renderer();
}
public void Render(double delta)