Basic rendering with camera controls are functional.

This commit is contained in:
Harrison Deng 2020-06-23 20:07:12 -05:00
parent 1c4ca6c97b
commit 6a19d1f5c7
58 changed files with 8386 additions and 2224 deletions

View File

@ -4,26 +4,18 @@ using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Exceptions namespace SlatedGameToolkit.Framework.Exceptions
{ {
public class OpenGLErrorException : OpenGLException { public class OpenGLErrorException : Exception {
public uint ErrorCode { get; private set; } public Graphics.OpenGL.ErrorCode ErrorCode {get; private set;}
public OpenGLErrorException(uint errorCode) : base() { public OpenGLErrorException(Graphics.OpenGL.ErrorCode error) : base(string.Format("OpenGL error: {0}", error)) {
this.ErrorCode = error;
} }
public OpenGLErrorException(uint errorCode, string message) : base(message) { public OpenGLErrorException(Graphics.OpenGL.ErrorCode error, string message) : base(string.Format("OpenGL error: {0}. \"{1}\"", error, message)) {
this.ErrorCode = error;
} }
public OpenGLErrorException(uint errorCode, string message, Exception inner) : base(message, inner) { public OpenGLErrorException(Graphics.OpenGL.ErrorCode error, string message, Exception inner) : base(string.Format("OpenGL error: {0}. \"{1}\"", error, message), inner) {
} this.ErrorCode = error;
/// <summary>
/// Checks the current context for OpenGL errors that has occurred and throws an exception if there is one.
/// </summary>
public static void CheckGLErrorStatus() {
uint errorCode = WindowContextsManager.CurrentWindowContext.GetGLStatus();
if (errorCode != (uint) GLEnum.GL_NO_ERROR) {
throw new OpenGLErrorException(errorCode, string.Format("OpenGL error ({0}): {1}", errorCode, ((GLEnum) errorCode)));
}
} }
} }
} }

View File

@ -1,18 +0,0 @@
using System;
using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Exceptions
{
public class OpenGLException : Exception {
public OpenGLException() : base() {
}
public OpenGLException(string message) : base(message) {
}
public OpenGLException(string message, Exception inner) : base(message, inner) {
}
}
}

View File

@ -1,21 +1,25 @@
using System; using System;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using SDL2; using SDL2;
using Serilog; using Serilog;
using Serilog.Core; using Serilog.Core;
using SlatedGameToolkit.Framework.Exceptions; using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics; using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Graphics.Window; using SlatedGameToolkit.Framework.Graphics.Window;
using SlatedGameToolkit.Framework.Input; using SlatedGameToolkit.Framework.Input;
using SlatedGameToolkit.Framework.Input.Devices; using SlatedGameToolkit.Framework.Input.Devices;
using SlatedGameToolkit.Framework.StateSystem; using SlatedGameToolkit.Framework.StateSystem;
using SlatedGameToolkit.Framework.StateSystem.States; using SlatedGameToolkit.Framework.StateSystem.States;
using SlatedGameToolkit.Framework.Utilities;
namespace SlatedGameToolkit.Framework { namespace SlatedGameToolkit.Framework {
/// <summary> /// <summary>
/// The main engine that will host the game loop. /// The main engine that will host the game loop.
/// </summary> /// </summary>
public static class GameEngine { public static class GameEngine {
private const int GL_MAJOR_VER = 3, GL_MINOR_VER = 3;
public static TextureData FillerTextureData {get; private set;}
public static bool Debugging { get; set; } public static bool Debugging { get; set; }
public static Logger Logger { get; private set; } public static Logger Logger { get; private set; }
private static readonly object ignitionLock = new object(); private static readonly object ignitionLock = new object();
@ -128,10 +132,10 @@ namespace SlatedGameToolkit.Framework {
} }
break; break;
case SDL.SDL_EventType.SDL_KEYDOWN: case SDL.SDL_EventType.SDL_KEYDOWN:
Keyboard.OnKeyPressed((Key) SDL_Event.key.keysym.sym); Keyboard.OnKeyPressed(SDL_Event.key.keysym.sym);
break; break;
case SDL.SDL_EventType.SDL_KEYUP: case SDL.SDL_EventType.SDL_KEYUP:
Keyboard.OnKeyReleased((Key) SDL_Event.key.keysym.sym); Keyboard.OnKeyReleased(SDL_Event.key.keysym.sym);
break; break;
case SDL.SDL_EventType.SDL_WINDOWEVENT: case SDL.SDL_EventType.SDL_WINDOWEVENT:
WindowContext handle = WindowContextsManager.ContextFromWindowID(SDL_Event.window.windowID); WindowContext handle = WindowContextsManager.ContextFromWindowID(SDL_Event.window.windowID);
@ -180,6 +184,7 @@ namespace SlatedGameToolkit.Framework {
SDL.SDL_Quit(); SDL.SDL_Quit();
Logger.Information("Game engine has stopped."); Logger.Information("Game engine has stopped.");
Logger.Dispose(); Logger.Dispose();
WindowContextsManager.DisposeAllWindowContexts();
Logger = null; Logger = null;
} }
} }
@ -232,18 +237,45 @@ namespace SlatedGameToolkit.Framework {
throw new FrameworkSDLException(); throw new FrameworkSDLException();
} }
if (SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, OpenGL.OpenGLMajorVersion) < 0) throw new FrameworkSDLException(); if (SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, GL_MAJOR_VER) < 0 ||
if (SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, OpenGL.OpenGLMinorVersion) < 0) throw new FrameworkSDLException(); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, GL_MINOR_VER) < 0 ||
if (SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE) < 0) throw new FrameworkSDLException(); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE) < 0)
throw new FrameworkSDLException(string.Format("Unable to load correct OpenGL version {0}.{1}.0 Core.", GL_MINOR_VER, GL_MAJOR_VER));
LoadEngineAssets();
thread = new Thread(Loop); thread = new Thread(Loop);
thread.Name = "SlatedGameToolkit Engine"; thread.Name = "SGTK-Engine";
thread.Priority = ThreadPriority.AboveNormal; thread.Priority = ThreadPriority.AboveNormal;
thread.Start(initialState); thread.Start(initialState);
return true; return true;
} }
} }
private unsafe static void LoadEngineAssets() {
byte[] buffer = EmbeddedResourceUtils.ReadEmbeddedResourceData("filler.png");
fixed (void* ptr = &buffer[0]) {
IntPtr rwOps = SDL.SDL_RWFromConstMem(new IntPtr(ptr), buffer.Length * sizeof(byte));
IntPtr surfacePtr = SDL_image.IMG_Load_RW(rwOps, 1);
SDL.SDL_Surface surface = Marshal.PtrToStructure<SDL.SDL_Surface>(surfacePtr);
SDL.SDL_PixelFormat pixelFormat = Marshal.PtrToStructure<SDL.SDL_PixelFormat>(surface.format);
if (pixelFormat.format != SDL.SDL_PIXELFORMAT_RGBA8888) {
IntPtr convertedPtr = SDL.SDL_ConvertSurfaceFormat(surfacePtr, SDL.SDL_PIXELFORMAT_RGBA8888, 0);
if (convertedPtr == null) throw new OptionalSDLException();
SDL.SDL_FreeSurface(surfacePtr);
surfacePtr = convertedPtr;
surface = Marshal.PtrToStructure<SDL.SDL_Surface>(surfacePtr);
}
byte[] data = new byte[surface.pitch * surface.h];
Marshal.Copy(surface.pixels, data, 0, data.Length);
FillerTextureData = new TextureData(surface.w, surface.h, data);
SDL.SDL_FreeSurface(surfacePtr);
}
}
public static bool IsRunning() { public static bool IsRunning() {
return !stopped; return !stopped;
} }

View File

@ -1,811 +0,0 @@
namespace SlatedGameToolkit.Framework.Graphics
{
public enum GLEnum: uint {
GL_DEPTH_BUFFER_BIT = 0x00000100,
GL_STENCIL_BUFFER_BIT = 0x00000400,
GL_COLOR_BUFFER_BIT = 0x00004000,
GL_FALSE = 0,
GL_TRUE = 1,
GL_POINTS = 0x0000,
GL_LINES = 0x0001,
GL_LINE_LOOP = 0x0002,
GL_LINE_STRIP = 0x0003,
GL_TRIANGLES = 0x0004,
GL_TRIANGLE_STRIP = 0x0005,
GL_TRIANGLE_FAN = 0x0006,
GL_QUADS = 0x0007,
GL_NEVER = 0x0200,
GL_LESS = 0x0201,
GL_EQUAL = 0x0202,
GL_LEQUAL = 0x0203,
GL_GREATER = 0x0204,
GL_NOTEQUAL = 0x0205,
GL_GEQUAL = 0x0206,
GL_ALWAYS = 0x0207,
GL_ZERO = 0,
GL_ONE = 1,
GL_SRC_COLOR = 0x0300,
GL_ONE_MINUS_SRC_COLOR = 0x0301,
GL_SRC_ALPHA = 0x0302,
GL_ONE_MINUS_SRC_ALPHA = 0x0303,
GL_DST_ALPHA = 0x0304,
GL_ONE_MINUS_DST_ALPHA = 0x0305,
GL_DST_COLOR = 0x0306,
GL_ONE_MINUS_DST_COLOR = 0x0307,
GL_SRC_ALPHA_SATURATE = 0x0308,
GL_NONE = 0,
GL_FRONT_LEFT = 0x0400,
GL_FRONT_RIGHT = 0x0401,
GL_BACK_LEFT = 0x0402,
GL_BACK_RIGHT = 0x0403,
GL_FRONT = 0x0404,
GL_BACK = 0x0405,
GL_LEFT = 0x0406,
GL_RIGHT = 0x0407,
GL_FRONT_AND_BACK = 0x0408,
GL_NO_ERROR = 0,
GL_INVALID_ENUM = 0x0500,
GL_INVALID_VALUE = 0x0501,
GL_INVALID_OPERATION = 0x0502,
GL_OUT_OF_MEMORY = 0x0505,
GL_CW = 0x0900,
GL_CCW = 0x0901,
GL_POINT_SIZE = 0x0B11,
GL_POINT_SIZE_RANGE = 0x0B12,
GL_POINT_SIZE_GRANULARITY = 0x0B13,
GL_LINE_SMOOTH = 0x0B20,
GL_LINE_WIDTH = 0x0B21,
GL_LINE_WIDTH_RANGE = 0x0B22,
GL_LINE_WIDTH_GRANULARITY = 0x0B23,
GL_POLYGON_MODE = 0x0B40,
GL_POLYGON_SMOOTH = 0x0B41,
GL_CULL_FACE = 0x0B44,
GL_CULL_FACE_MODE = 0x0B45,
GL_FRONT_FACE = 0x0B46,
GL_DEPTH_RANGE = 0x0B70,
GL_DEPTH_TEST = 0x0B71,
GL_DEPTH_WRITEMASK = 0x0B72,
GL_DEPTH_CLEAR_VALUE = 0x0B73,
GL_DEPTH_FUNC = 0x0B74,
GL_STENCIL_TEST = 0x0B90,
GL_STENCIL_CLEAR_VALUE = 0x0B91,
GL_STENCIL_FUNC = 0x0B92,
GL_STENCIL_VALUE_MASK = 0x0B93,
GL_STENCIL_FAIL = 0x0B94,
GL_STENCIL_PASS_DEPTH_FAIL = 0x0B95,
GL_STENCIL_PASS_DEPTH_PASS = 0x0B96,
GL_STENCIL_REF = 0x0B97,
GL_STENCIL_WRITEMASK = 0x0B98,
GL_VIEWPORT = 0x0BA2,
GL_DITHER = 0x0BD0,
GL_BLEND_DST = 0x0BE0,
GL_BLEND_SRC = 0x0BE1,
GL_BLEND = 0x0BE2,
GL_LOGIC_OP_MODE = 0x0BF0,
GL_DRAW_BUFFER = 0x0C01,
GL_READ_BUFFER = 0x0C02,
GL_SCISSOR_BOX = 0x0C10,
GL_SCISSOR_TEST = 0x0C11,
GL_COLOR_CLEAR_VALUE = 0x0C22,
GL_COLOR_WRITEMASK = 0x0C23,
GL_DOUBLEBUFFER = 0x0C32,
GL_STEREO = 0x0C33,
GL_LINE_SMOOTH_HINT = 0x0C52,
GL_POLYGON_SMOOTH_HINT = 0x0C53,
GL_UNPACK_SWAP_BYTES = 0x0CF0,
GL_UNPACK_LSB_FIRST = 0x0CF1,
GL_UNPACK_ROW_LENGTH = 0x0CF2,
GL_UNPACK_SKIP_ROWS = 0x0CF3,
GL_UNPACK_SKIP_PIXELS = 0x0CF4,
GL_UNPACK_ALIGNMENT = 0x0CF5,
GL_PACK_SWAP_BYTES = 0x0D00,
GL_PACK_LSB_FIRST = 0x0D01,
GL_PACK_ROW_LENGTH = 0x0D02,
GL_PACK_SKIP_ROWS = 0x0D03,
GL_PACK_SKIP_PIXELS = 0x0D04,
GL_PACK_ALIGNMENT = 0x0D05,
GL_MAX_TEXTURE_SIZE = 0x0D33,
GL_MAX_VIEWPORT_DIMS = 0x0D3A,
GL_SUBPIXEL_BITS = 0x0D50,
GL_TEXTURE_1D = 0x0DE0,
GL_TEXTURE_2D = 0x0DE1,
GL_TEXTURE_WIDTH = 0x1000,
GL_TEXTURE_HEIGHT = 0x1001,
GL_TEXTURE_BORDER_COLOR = 0x1004,
GL_DONT_CARE = 0x1100,
GL_FASTEST = 0x1101,
GL_NICEST = 0x1102,
GL_BYTE = 0x1400,
GL_UNSIGNED_BYTE = 0x1401,
GL_SHORT = 0x1402,
GL_UNSIGNED_SHORT = 0x1403,
GL_INT = 0x1404,
GL_UNSIGNED_INT = 0x1405,
GL_FLOAT = 0x1406,
GL_STACK_OVERFLOW = 0x0503,
GL_STACK_UNDERFLOW = 0x0504,
GL_CLEAR = 0x1500,
GL_AND = 0x1501,
GL_AND_REVERSE = 0x1502,
GL_COPY = 0x1503,
GL_AND_INVERTED = 0x1504,
GL_NOOP = 0x1505,
GL_XOR = 0x1506,
GL_OR = 0x1507,
GL_NOR = 0x1508,
GL_EQUIV = 0x1509,
GL_INVERT = 0x150A,
GL_OR_REVERSE = 0x150B,
GL_COPY_INVERTED = 0x150C,
GL_OR_INVERTED = 0x150D,
GL_NAND = 0x150E,
GL_SET = 0x150F,
GL_TEXTURE = 0x1702,
GL_COLOR = 0x1800,
GL_DEPTH = 0x1801,
GL_STENCIL = 0x1802,
GL_STENCIL_INDEX = 0x1901,
GL_DEPTH_COMPONENT = 0x1902,
GL_RED = 0x1903,
GL_GREEN = 0x1904,
GL_BLUE = 0x1905,
GL_ALPHA = 0x1906,
GL_RGB = 0x1907,
GL_RGBA = 0x1908,
GL_POINT = 0x1B00,
GL_LINE = 0x1B01,
GL_FILL = 0x1B02,
GL_KEEP = 0x1E00,
GL_REPLACE = 0x1E01,
GL_INCR = 0x1E02,
GL_DECR = 0x1E03,
GL_VENDOR = 0x1F00,
GL_RENDERER = 0x1F01,
GL_VERSION = 0x1F02,
GL_EXTENSIONS = 0x1F03,
GL_NEAREST = 0x2600,
GL_LINEAR = 0x2601,
GL_NEAREST_MIPMAP_NEAREST = 0x2700,
GL_LINEAR_MIPMAP_NEAREST = 0x2701,
GL_NEAREST_MIPMAP_LINEAR = 0x2702,
GL_LINEAR_MIPMAP_LINEAR = 0x2703,
GL_TEXTURE_MAG_FILTER = 0x2800,
GL_TEXTURE_MIN_FILTER = 0x2801,
GL_TEXTURE_WRAP_S = 0x2802,
GL_TEXTURE_WRAP_T = 0x2803,
GL_REPEAT = 0x2901,
GL_COLOR_LOGIC_OP = 0x0BF2,
GL_POLYGON_OFFSET_UNITS = 0x2A00,
GL_POLYGON_OFFSET_POINT = 0x2A01,
GL_POLYGON_OFFSET_LINE = 0x2A02,
GL_POLYGON_OFFSET_FILL = 0x8037,
GL_POLYGON_OFFSET_FACTOR = 0x8038,
GL_TEXTURE_BINDING_1D = 0x8068,
GL_TEXTURE_BINDING_2D = 0x8069,
GL_TEXTURE_INTERNAL_FORMAT = 0x1003,
GL_TEXTURE_RED_SIZE = 0x805C,
GL_TEXTURE_GREEN_SIZE = 0x805D,
GL_TEXTURE_BLUE_SIZE = 0x805E,
GL_TEXTURE_ALPHA_SIZE = 0x805F,
GL_DOUBLE = 0x140A,
GL_PROXY_TEXTURE_1D = 0x8063,
GL_PROXY_TEXTURE_2D = 0x8064,
GL_R3_G3_B2 = 0x2A10,
GL_RGB4 = 0x804F,
GL_RGB5 = 0x8050,
GL_RGB8 = 0x8051,
GL_RGB10 = 0x8052,
GL_RGB12 = 0x8053,
GL_RGB16 = 0x8054,
GL_RGBA2 = 0x8055,
GL_RGBA4 = 0x8056,
GL_RGB5_A1 = 0x8057,
GL_RGBA8 = 0x8058,
GL_RGB10_A2 = 0x8059,
GL_RGBA12 = 0x805A,
GL_RGBA16 = 0x805B,
GL_VERTEX_ARRAY = 0x8074,
GL_UNSIGNED_BYTE_3_3_2 = 0x8032,
GL_UNSIGNED_SHORT_4_4_4_4 = 0x8033,
GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034,
GL_UNSIGNED_INT_8_8_8_8 = 0x8035,
GL_UNSIGNED_INT_10_10_10_2 = 0x8036,
GL_TEXTURE_BINDING_3D = 0x806A,
GL_PACK_SKIP_IMAGES = 0x806B,
GL_PACK_IMAGE_HEIGHT = 0x806C,
GL_UNPACK_SKIP_IMAGES = 0x806D,
GL_UNPACK_IMAGE_HEIGHT = 0x806E,
GL_TEXTURE_3D = 0x806F,
GL_PROXY_TEXTURE_3D = 0x8070,
GL_TEXTURE_DEPTH = 0x8071,
GL_TEXTURE_WRAP_R = 0x8072,
GL_MAX_3D_TEXTURE_SIZE = 0x8073,
GL_UNSIGNED_BYTE_2_3_3_REV = 0x8362,
GL_UNSIGNED_SHORT_5_6_5 = 0x8363,
GL_UNSIGNED_SHORT_5_6_5_REV = 0x8364,
GL_UNSIGNED_SHORT_4_4_4_4_REV = 0x8365,
GL_UNSIGNED_SHORT_1_5_5_5_REV = 0x8366,
GL_UNSIGNED_INT_8_8_8_8_REV = 0x8367,
GL_UNSIGNED_INT_2_10_10_10_REV = 0x8368,
GL_BGR = 0x80E0,
GL_BGRA = 0x80E1,
GL_MAX_ELEMENTS_VERTICES = 0x80E8,
GL_MAX_ELEMENTS_INDICES = 0x80E9,
GL_CLAMP_TO_EDGE = 0x812F,
GL_TEXTURE_MIN_LOD = 0x813A,
GL_TEXTURE_MAX_LOD = 0x813B,
GL_TEXTURE_BASE_LEVEL = 0x813C,
GL_TEXTURE_MAX_LEVEL = 0x813D,
GL_SMOOTH_POINT_SIZE_RANGE = 0x0B12,
GL_SMOOTH_POINT_SIZE_GRANULARITY = 0x0B13,
GL_SMOOTH_LINE_WIDTH_RANGE = 0x0B22,
GL_SMOOTH_LINE_WIDTH_GRANULARITY = 0x0B23,
GL_ALIASED_LINE_WIDTH_RANGE = 0x846E,
GL_TEXTURE0 = 0x84C0,
GL_TEXTURE1 = 0x84C1,
GL_TEXTURE2 = 0x84C2,
GL_TEXTURE3 = 0x84C3,
GL_TEXTURE4 = 0x84C4,
GL_TEXTURE5 = 0x84C5,
GL_TEXTURE6 = 0x84C6,
GL_TEXTURE7 = 0x84C7,
GL_TEXTURE8 = 0x84C8,
GL_TEXTURE9 = 0x84C9,
GL_TEXTURE10 = 0x84CA,
GL_TEXTURE11 = 0x84CB,
GL_TEXTURE12 = 0x84CC,
GL_TEXTURE13 = 0x84CD,
GL_TEXTURE14 = 0x84CE,
GL_TEXTURE15 = 0x84CF,
GL_TEXTURE16 = 0x84D0,
GL_TEXTURE17 = 0x84D1,
GL_TEXTURE18 = 0x84D2,
GL_TEXTURE19 = 0x84D3,
GL_TEXTURE20 = 0x84D4,
GL_TEXTURE21 = 0x84D5,
GL_TEXTURE22 = 0x84D6,
GL_TEXTURE23 = 0x84D7,
GL_TEXTURE24 = 0x84D8,
GL_TEXTURE25 = 0x84D9,
GL_TEXTURE26 = 0x84DA,
GL_TEXTURE27 = 0x84DB,
GL_TEXTURE28 = 0x84DC,
GL_TEXTURE29 = 0x84DD,
GL_TEXTURE30 = 0x84DE,
GL_TEXTURE31 = 0x84DF,
GL_ACTIVE_TEXTURE = 0x84E0,
GL_MULTISAMPLE = 0x809D,
GL_SAMPLE_ALPHA_TO_COVERAGE = 0x809E,
GL_SAMPLE_ALPHA_TO_ONE = 0x809F,
GL_SAMPLE_COVERAGE = 0x80A0,
GL_SAMPLE_BUFFERS = 0x80A8,
GL_SAMPLES = 0x80A9,
GL_SAMPLE_COVERAGE_VALUE = 0x80AA,
GL_SAMPLE_COVERAGE_INVERT = 0x80AB,
GL_TEXTURE_CUBE_MAP = 0x8513,
GL_TEXTURE_BINDING_CUBE_MAP = 0x8514,
GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A,
GL_PROXY_TEXTURE_CUBE_MAP = 0x851B,
GL_MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C,
GL_COMPRESSED_RGB = 0x84ED,
GL_COMPRESSED_RGBA = 0x84EE,
GL_TEXTURE_COMPRESSION_HINT = 0x84EF,
GL_TEXTURE_COMPRESSED_IMAGE_SIZE = 0x86A0,
GL_TEXTURE_COMPRESSED = 0x86A1,
GL_NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2,
GL_COMPRESSED_TEXTURE_FORMATS = 0x86A3,
GL_CLAMP_TO_BORDER = 0x812D,
GL_BLEND_DST_RGB = 0x80C8,
GL_BLEND_SRC_RGB = 0x80C9,
GL_BLEND_DST_ALPHA = 0x80CA,
GL_BLEND_SRC_ALPHA = 0x80CB,
GL_POINT_FADE_THRESHOLD_SIZE = 0x8128,
GL_DEPTH_COMPONENT16 = 0x81A5,
GL_DEPTH_COMPONENT24 = 0x81A6,
GL_DEPTH_COMPONENT32 = 0x81A7,
GL_MIRRORED_REPEAT = 0x8370,
GL_MAX_TEXTURE_LOD_BIAS = 0x84FD,
GL_TEXTURE_LOD_BIAS = 0x8501,
GL_INCR_WRAP = 0x8507,
GL_DECR_WRAP = 0x8508,
GL_TEXTURE_DEPTH_SIZE = 0x884A,
GL_TEXTURE_COMPARE_MODE = 0x884C,
GL_TEXTURE_COMPARE_FUNC = 0x884D,
GL_BLEND_COLOR = 0x8005,
GL_BLEND_EQUATION = 0x8009,
GL_CONSTANT_COLOR = 0x8001,
GL_ONE_MINUS_CONSTANT_COLOR = 0x8002,
GL_CONSTANT_ALPHA = 0x8003,
GL_ONE_MINUS_CONSTANT_ALPHA = 0x8004,
GL_FUNC_ADD = 0x8006,
GL_FUNC_REVERSE_SUBTRACT = 0x800B,
GL_FUNC_SUBTRACT = 0x800A,
GL_MIN = 0x8007,
GL_MAX = 0x8008,
GL_BUFFER_SIZE = 0x8764,
GL_BUFFER_USAGE = 0x8765,
GL_QUERY_COUNTER_BITS = 0x8864,
GL_CURRENT_QUERY = 0x8865,
GL_QUERY_RESULT = 0x8866,
GL_QUERY_RESULT_AVAILABLE = 0x8867,
GL_ARRAY_BUFFER = 0x8892,
GL_ELEMENT_ARRAY_BUFFER = 0x8893,
GL_ARRAY_BUFFER_BINDING = 0x8894,
GL_ELEMENT_ARRAY_BUFFER_BINDING = 0x8895,
GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
GL_READ_ONLY = 0x88B8,
GL_WRITE_ONLY = 0x88B9,
GL_READ_WRITE = 0x88BA,
GL_BUFFER_ACCESS = 0x88BB,
GL_BUFFER_MAPPED = 0x88BC,
GL_BUFFER_MAP_POINTER = 0x88BD,
GL_STREAM_DRAW = 0x88E0,
GL_STREAM_READ = 0x88E1,
GL_STREAM_COPY = 0x88E2,
GL_STATIC_DRAW = 0x88E4,
GL_STATIC_READ = 0x88E5,
GL_STATIC_COPY = 0x88E6,
GL_DYNAMIC_DRAW = 0x88E8,
GL_DYNAMIC_READ = 0x88E9,
GL_DYNAMIC_COPY = 0x88EA,
GL_SAMPLES_PASSED = 0x8914,
GL_SRC1_ALPHA = 0x8589,
GL_BLEND_EQUATION_RGB = 0x8009,
GL_VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622,
GL_VERTEX_ATTRIB_ARRAY_SIZE = 0x8623,
GL_VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624,
GL_VERTEX_ATTRIB_ARRAY_TYPE = 0x8625,
GL_CURRENT_VERTEX_ATTRIB = 0x8626,
GL_VERTEX_PROGRAM_POINT_SIZE = 0x8642,
GL_VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
GL_STENCIL_BACK_FUNC = 0x8800,
GL_STENCIL_BACK_FAIL = 0x8801,
GL_STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802,
GL_STENCIL_BACK_PASS_DEPTH_PASS = 0x8803,
GL_MAX_DRAW_BUFFERS = 0x8824,
GL_DRAW_BUFFER0 = 0x8825,
GL_DRAW_BUFFER1 = 0x8826,
GL_DRAW_BUFFER2 = 0x8827,
GL_DRAW_BUFFER3 = 0x8828,
GL_DRAW_BUFFER4 = 0x8829,
GL_DRAW_BUFFER5 = 0x882A,
GL_DRAW_BUFFER6 = 0x882B,
GL_DRAW_BUFFER7 = 0x882C,
GL_DRAW_BUFFER8 = 0x882D,
GL_DRAW_BUFFER9 = 0x882E,
GL_DRAW_BUFFER10 = 0x882F,
GL_DRAW_BUFFER11 = 0x8830,
GL_DRAW_BUFFER12 = 0x8831,
GL_DRAW_BUFFER13 = 0x8832,
GL_DRAW_BUFFER14 = 0x8833,
GL_DRAW_BUFFER15 = 0x8834,
GL_BLEND_EQUATION_ALPHA = 0x883D,
GL_MAX_VERTEX_ATTRIBS = 0x8869,
GL_VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
GL_MAX_TEXTURE_IMAGE_UNITS = 0x8872,
GL_FRAGMENT_SHADER = 0x8B30,
GL_VERTEX_SHADER = 0x8B31,
GL_MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49,
GL_MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A,
GL_MAX_VARYING_FLOATS = 0x8B4B,
GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C,
GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D,
GL_SHADER_TYPE = 0x8B4F,
GL_FLOAT_VEC2 = 0x8B50,
GL_FLOAT_VEC3 = 0x8B51,
GL_FLOAT_VEC4 = 0x8B52,
GL_INT_VEC2 = 0x8B53,
GL_INT_VEC3 = 0x8B54,
GL_INT_VEC4 = 0x8B55,
GL_BOOL = 0x8B56,
GL_BOOL_VEC2 = 0x8B57,
GL_BOOL_VEC3 = 0x8B58,
GL_BOOL_VEC4 = 0x8B59,
GL_FLOAT_MAT2 = 0x8B5A,
GL_FLOAT_MAT3 = 0x8B5B,
GL_FLOAT_MAT4 = 0x8B5C,
GL_SAMPLER_1D = 0x8B5D,
GL_SAMPLER_2D = 0x8B5E,
GL_SAMPLER_3D = 0x8B5F,
GL_SAMPLER_CUBE = 0x8B60,
GL_SAMPLER_1D_SHADOW = 0x8B61,
GL_SAMPLER_2D_SHADOW = 0x8B62,
GL_DELETE_STATUS = 0x8B80,
GL_COMPILE_STATUS = 0x8B81,
GL_LINK_STATUS = 0x8B82,
GL_VALIDATE_STATUS = 0x8B83,
GL_INFO_LOG_LENGTH = 0x8B84,
GL_ATTACHED_SHADERS = 0x8B85,
GL_ACTIVE_UNIFORMS = 0x8B86,
GL_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
GL_SHADER_SOURCE_LENGTH = 0x8B88,
GL_ACTIVE_ATTRIBUTES = 0x8B89,
GL_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
GL_FRAGMENT_SHADER_DERIVATIVE_HINT = 0x8B8B,
GL_SHADING_LANGUAGE_VERSION = 0x8B8C,
GL_CURRENT_PROGRAM = 0x8B8D,
GL_POINT_SPRITE_COORD_ORIGIN = 0x8CA0,
GL_LOWER_LEFT = 0x8CA1,
GL_UPPER_LEFT = 0x8CA2,
GL_STENCIL_BACK_REF = 0x8CA3,
GL_STENCIL_BACK_VALUE_MASK = 0x8CA4,
GL_STENCIL_BACK_WRITEMASK = 0x8CA5,
GL_PIXEL_PACK_BUFFER = 0x88EB,
GL_PIXEL_UNPACK_BUFFER = 0x88EC,
GL_PIXEL_PACK_BUFFER_BINDING = 0x88ED,
GL_PIXEL_UNPACK_BUFFER_BINDING = 0x88EF,
GL_FLOAT_MAT2x3 = 0x8B65,
GL_FLOAT_MAT2x4 = 0x8B66,
GL_FLOAT_MAT3x2 = 0x8B67,
GL_FLOAT_MAT3x4 = 0x8B68,
GL_FLOAT_MAT4x2 = 0x8B69,
GL_FLOAT_MAT4x3 = 0x8B6A,
GL_SRGB = 0x8C40,
GL_SRGB8 = 0x8C41,
GL_SRGB_ALPHA = 0x8C42,
GL_SRGB8_ALPHA8 = 0x8C43,
GL_COMPRESSED_SRGB = 0x8C48,
GL_COMPRESSED_SRGB_ALPHA = 0x8C49,
GL_COMPARE_REF_TO_TEXTURE = 0x884E,
GL_CLIP_DISTANCE0 = 0x3000,
GL_CLIP_DISTANCE1 = 0x3001,
GL_CLIP_DISTANCE2 = 0x3002,
GL_CLIP_DISTANCE3 = 0x3003,
GL_CLIP_DISTANCE4 = 0x3004,
GL_CLIP_DISTANCE5 = 0x3005,
GL_CLIP_DISTANCE6 = 0x3006,
GL_CLIP_DISTANCE7 = 0x3007,
GL_MAX_CLIP_DISTANCES = 0x0D32,
GL_MAJOR_VERSION = 0x821B,
GL_MINOR_VERSION = 0x821C,
GL_NUM_EXTENSIONS = 0x821D,
GL_CONTEXT_FLAGS = 0x821E,
GL_COMPRESSED_RED = 0x8225,
GL_COMPRESSED_RG = 0x8226,
GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT = 0x00000001,
GL_RGBA32F = 0x8814,
GL_RGB32F = 0x8815,
GL_RGBA16F = 0x881A,
GL_RGB16F = 0x881B,
GL_VERTEX_ATTRIB_ARRAY_INTEGER = 0x88FD,
GL_MAX_ARRAY_TEXTURE_LAYERS = 0x88FF,
GL_MIN_PROGRAM_TEXEL_OFFSET = 0x8904,
GL_MAX_PROGRAM_TEXEL_OFFSET = 0x8905,
GL_CLAMP_READ_COLOR = 0x891C,
GL_FIXED_ONLY = 0x891D,
GL_MAX_VARYING_COMPONENTS = 0x8B4B,
GL_TEXTURE_1D_ARRAY = 0x8C18,
GL_PROXY_TEXTURE_1D_ARRAY = 0x8C19,
GL_TEXTURE_2D_ARRAY = 0x8C1A,
GL_PROXY_TEXTURE_2D_ARRAY = 0x8C1B,
GL_TEXTURE_BINDING_1D_ARRAY = 0x8C1C,
GL_TEXTURE_BINDING_2D_ARRAY = 0x8C1D,
GL_R11F_G11F_B10F = 0x8C3A,
GL_UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B,
GL_RGB9_E5 = 0x8C3D,
GL_UNSIGNED_INT_5_9_9_9_REV = 0x8C3E,
GL_TEXTURE_SHARED_SIZE = 0x8C3F,
GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH = 0x8C76,
GL_TRANSFORM_FEEDBACK_BUFFER_MODE = 0x8C7F,
GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 0x8C80,
GL_TRANSFORM_FEEDBACK_VARYINGS = 0x8C83,
GL_TRANSFORM_FEEDBACK_BUFFER_START = 0x8C84,
GL_TRANSFORM_FEEDBACK_BUFFER_SIZE = 0x8C85,
GL_PRIMITIVES_GENERATED = 0x8C87,
GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN = 0x8C88,
GL_RASTERIZER_DISCARD = 0x8C89,
GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 0x8C8A,
GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 0x8C8B,
GL_INTERLEAVED_ATTRIBS = 0x8C8C,
GL_SEPARATE_ATTRIBS = 0x8C8D,
GL_TRANSFORM_FEEDBACK_BUFFER = 0x8C8E,
GL_TRANSFORM_FEEDBACK_BUFFER_BINDING = 0x8C8F,
GL_RGBA32UI = 0x8D70,
GL_RGB32UI = 0x8D71,
GL_RGBA16UI = 0x8D76,
GL_RGB16UI = 0x8D77,
GL_RGBA8UI = 0x8D7C,
GL_RGB8UI = 0x8D7D,
GL_RGBA32I = 0x8D82,
GL_RGB32I = 0x8D83,
GL_RGBA16I = 0x8D88,
GL_RGB16I = 0x8D89,
GL_RGBA8I = 0x8D8E,
GL_RGB8I = 0x8D8F,
GL_RED_INTEGER = 0x8D94,
GL_GREEN_INTEGER = 0x8D95,
GL_BLUE_INTEGER = 0x8D96,
GL_RGB_INTEGER = 0x8D98,
GL_RGBA_INTEGER = 0x8D99,
GL_BGR_INTEGER = 0x8D9A,
GL_BGRA_INTEGER = 0x8D9B,
GL_SAMPLER_1D_ARRAY = 0x8DC0,
GL_SAMPLER_2D_ARRAY = 0x8DC1,
GL_SAMPLER_1D_ARRAY_SHADOW = 0x8DC3,
GL_SAMPLER_2D_ARRAY_SHADOW = 0x8DC4,
GL_SAMPLER_CUBE_SHADOW = 0x8DC5,
GL_UNSIGNED_INT_VEC2 = 0x8DC6,
GL_UNSIGNED_INT_VEC3 = 0x8DC7,
GL_UNSIGNED_INT_VEC4 = 0x8DC8,
GL_INT_SAMPLER_1D = 0x8DC9,
GL_INT_SAMPLER_2D = 0x8DCA,
GL_INT_SAMPLER_3D = 0x8DCB,
GL_INT_SAMPLER_CUBE = 0x8DCC,
GL_INT_SAMPLER_1D_ARRAY = 0x8DCE,
GL_INT_SAMPLER_2D_ARRAY = 0x8DCF,
GL_UNSIGNED_INT_SAMPLER_1D = 0x8DD1,
GL_UNSIGNED_INT_SAMPLER_2D = 0x8DD2,
GL_UNSIGNED_INT_SAMPLER_3D = 0x8DD3,
GL_UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4,
GL_UNSIGNED_INT_SAMPLER_1D_ARRAY = 0x8DD6,
GL_UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7,
GL_QUERY_WAIT = 0x8E13,
GL_QUERY_NO_WAIT = 0x8E14,
GL_QUERY_BY_REGION_WAIT = 0x8E15,
GL_QUERY_BY_REGION_NO_WAIT = 0x8E16,
GL_BUFFER_ACCESS_FLAGS = 0x911F,
GL_BUFFER_MAP_LENGTH = 0x9120,
GL_BUFFER_MAP_OFFSET = 0x9121,
GL_DEPTH_COMPONENT32F = 0x8CAC,
GL_DEPTH32F_STENCIL8 = 0x8CAD,
GL_FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD,
GL_INVALID_FRAMEBUFFER_OPERATION = 0x0506,
GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING = 0x8210,
GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE = 0x8211,
GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE = 0x8212,
GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE = 0x8213,
GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE = 0x8214,
GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE = 0x8215,
GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE = 0x8216,
GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE = 0x8217,
GL_FRAMEBUFFER_DEFAULT = 0x8218,
GL_FRAMEBUFFER_UNDEFINED = 0x8219,
GL_DEPTH_STENCIL_ATTACHMENT = 0x821A,
GL_MAX_RENDERBUFFER_SIZE = 0x84E8,
GL_DEPTH_STENCIL = 0x84F9,
GL_UNSIGNED_INT_24_8 = 0x84FA,
GL_DEPTH24_STENCIL8 = 0x88F0,
GL_TEXTURE_STENCIL_SIZE = 0x88F1,
GL_TEXTURE_RED_TYPE = 0x8C10,
GL_TEXTURE_GREEN_TYPE = 0x8C11,
GL_TEXTURE_BLUE_TYPE = 0x8C12,
GL_TEXTURE_ALPHA_TYPE = 0x8C13,
GL_TEXTURE_DEPTH_TYPE = 0x8C16,
GL_UNSIGNED_NORMALIZED = 0x8C17,
GL_FRAMEBUFFER_BINDING = 0x8CA6,
GL_DRAW_FRAMEBUFFER_BINDING = 0x8CA6,
GL_RENDERBUFFER_BINDING = 0x8CA7,
GL_READ_FRAMEBUFFER = 0x8CA8,
GL_DRAW_FRAMEBUFFER = 0x8CA9,
GL_READ_FRAMEBUFFER_BINDING = 0x8CAA,
GL_RENDERBUFFER_SAMPLES = 0x8CAB,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1,
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2,
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3,
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER = 0x8CD4,
GL_FRAMEBUFFER_COMPLETE = 0x8CD5,
GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7,
GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = 0x8CDB,
GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER = 0x8CDC,
GL_FRAMEBUFFER_UNSUPPORTED = 0x8CDD,
GL_MAX_COLOR_ATTACHMENTS = 0x8CDF,
GL_COLOR_ATTACHMENT0 = 0x8CE0,
GL_COLOR_ATTACHMENT1 = 0x8CE1,
GL_COLOR_ATTACHMENT2 = 0x8CE2,
GL_COLOR_ATTACHMENT3 = 0x8CE3,
GL_COLOR_ATTACHMENT4 = 0x8CE4,
GL_COLOR_ATTACHMENT5 = 0x8CE5,
GL_COLOR_ATTACHMENT6 = 0x8CE6,
GL_COLOR_ATTACHMENT7 = 0x8CE7,
GL_COLOR_ATTACHMENT8 = 0x8CE8,
GL_COLOR_ATTACHMENT9 = 0x8CE9,
GL_COLOR_ATTACHMENT10 = 0x8CEA,
GL_COLOR_ATTACHMENT11 = 0x8CEB,
GL_COLOR_ATTACHMENT12 = 0x8CEC,
GL_COLOR_ATTACHMENT13 = 0x8CED,
GL_COLOR_ATTACHMENT14 = 0x8CEE,
GL_COLOR_ATTACHMENT15 = 0x8CEF,
GL_COLOR_ATTACHMENT16 = 0x8CF0,
GL_COLOR_ATTACHMENT17 = 0x8CF1,
GL_COLOR_ATTACHMENT18 = 0x8CF2,
GL_COLOR_ATTACHMENT19 = 0x8CF3,
GL_COLOR_ATTACHMENT20 = 0x8CF4,
GL_COLOR_ATTACHMENT21 = 0x8CF5,
GL_COLOR_ATTACHMENT22 = 0x8CF6,
GL_COLOR_ATTACHMENT23 = 0x8CF7,
GL_COLOR_ATTACHMENT24 = 0x8CF8,
GL_COLOR_ATTACHMENT25 = 0x8CF9,
GL_COLOR_ATTACHMENT26 = 0x8CFA,
GL_COLOR_ATTACHMENT27 = 0x8CFB,
GL_COLOR_ATTACHMENT28 = 0x8CFC,
GL_COLOR_ATTACHMENT29 = 0x8CFD,
GL_COLOR_ATTACHMENT30 = 0x8CFE,
GL_COLOR_ATTACHMENT31 = 0x8CFF,
GL_DEPTH_ATTACHMENT = 0x8D00,
GL_STENCIL_ATTACHMENT = 0x8D20,
GL_FRAMEBUFFER = 0x8D40,
GL_RENDERBUFFER = 0x8D41,
GL_RENDERBUFFER_WIDTH = 0x8D42,
GL_RENDERBUFFER_HEIGHT = 0x8D43,
GL_RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
GL_STENCIL_INDEX1 = 0x8D46,
GL_STENCIL_INDEX4 = 0x8D47,
GL_STENCIL_INDEX8 = 0x8D48,
GL_STENCIL_INDEX16 = 0x8D49,
GL_RENDERBUFFER_RED_SIZE = 0x8D50,
GL_RENDERBUFFER_GREEN_SIZE = 0x8D51,
GL_RENDERBUFFER_BLUE_SIZE = 0x8D52,
GL_RENDERBUFFER_ALPHA_SIZE = 0x8D53,
GL_RENDERBUFFER_DEPTH_SIZE = 0x8D54,
GL_RENDERBUFFER_STENCIL_SIZE = 0x8D55,
GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56,
GL_MAX_SAMPLES = 0x8D57,
GL_FRAMEBUFFER_SRGB = 0x8DB9,
GL_HALF_FLOAT = 0x140B,
GL_MAP_READ_BIT = 0x0001,
GL_MAP_WRITE_BIT = 0x0002,
GL_MAP_INVALIDATE_RANGE_BIT = 0x0004,
GL_MAP_INVALIDATE_BUFFER_BIT = 0x0008,
GL_MAP_FLUSH_EXPLICIT_BIT = 0x0010,
GL_MAP_UNSYNCHRONIZED_BIT = 0x0020,
GL_COMPRESSED_RED_RGTC1 = 0x8DBB,
GL_COMPRESSED_SIGNED_RED_RGTC1 = 0x8DBC,
GL_COMPRESSED_RG_RGTC2 = 0x8DBD,
GL_COMPRESSED_SIGNED_RG_RGTC2 = 0x8DBE,
GL_RG = 0x8227,
GL_RG_INTEGER = 0x8228,
GL_R8 = 0x8229,
GL_R16 = 0x822A,
GL_RG8 = 0x822B,
GL_RG16 = 0x822C,
GL_R16F = 0x822D,
GL_R32F = 0x822E,
GL_RG16F = 0x822F,
GL_RG32F = 0x8230,
GL_R8I = 0x8231,
GL_R8UI = 0x8232,
GL_R16I = 0x8233,
GL_R16UI = 0x8234,
GL_R32I = 0x8235,
GL_R32UI = 0x8236,
GL_RG8I = 0x8237,
GL_RG8UI = 0x8238,
GL_RG16I = 0x8239,
GL_RG16UI = 0x823A,
GL_RG32I = 0x823B,
GL_RG32UI = 0x823C,
GL_VERTEX_ARRAY_BINDING = 0x85B5,
GL_SAMPLER_2D_RECT = 0x8B63,
GL_SAMPLER_2D_RECT_SHADOW = 0x8B64,
GL_SAMPLER_BUFFER = 0x8DC2,
GL_INT_SAMPLER_2D_RECT = 0x8DCD,
GL_INT_SAMPLER_BUFFER = 0x8DD0,
GL_UNSIGNED_INT_SAMPLER_2D_RECT = 0x8DD5,
GL_UNSIGNED_INT_SAMPLER_BUFFER = 0x8DD8,
GL_TEXTURE_BUFFER = 0x8C2A,
GL_MAX_TEXTURE_BUFFER_SIZE = 0x8C2B,
GL_TEXTURE_BINDING_BUFFER = 0x8C2C,
GL_TEXTURE_BUFFER_DATA_STORE_BINDING = 0x8C2D,
GL_TEXTURE_RECTANGLE = 0x84F5,
GL_TEXTURE_BINDING_RECTANGLE = 0x84F6,
GL_PROXY_TEXTURE_RECTANGLE = 0x84F7,
GL_MAX_RECTANGLE_TEXTURE_SIZE = 0x84F8,
GL_R8_SNORM = 0x8F94,
GL_RG8_SNORM = 0x8F95,
GL_RGB8_SNORM = 0x8F96,
GL_RGBA8_SNORM = 0x8F97,
GL_R16_SNORM = 0x8F98,
GL_RG16_SNORM = 0x8F99,
GL_RGB16_SNORM = 0x8F9A,
GL_RGBA16_SNORM = 0x8F9B,
GL_SIGNED_NORMALIZED = 0x8F9C,
GL_PRIMITIVE_RESTART = 0x8F9D,
GL_PRIMITIVE_RESTART_INDEX = 0x8F9E,
GL_COPY_READ_BUFFER = 0x8F36,
GL_COPY_WRITE_BUFFER = 0x8F37,
GL_UNIFORM_BUFFER = 0x8A11,
GL_UNIFORM_BUFFER_BINDING = 0x8A28,
GL_UNIFORM_BUFFER_START = 0x8A29,
GL_UNIFORM_BUFFER_SIZE = 0x8A2A,
GL_MAX_VERTEX_UNIFORM_BLOCKS = 0x8A2B,
GL_MAX_GEOMETRY_UNIFORM_BLOCKS = 0x8A2C,
GL_MAX_FRAGMENT_UNIFORM_BLOCKS = 0x8A2D,
GL_MAX_COMBINED_UNIFORM_BLOCKS = 0x8A2E,
GL_MAX_UNIFORM_BUFFER_BINDINGS = 0x8A2F,
GL_MAX_UNIFORM_BLOCK_SIZE = 0x8A30,
GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = 0x8A31,
GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS = 0x8A32,
GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = 0x8A33,
GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34,
GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH = 0x8A35,
GL_ACTIVE_UNIFORM_BLOCKS = 0x8A36,
GL_UNIFORM_TYPE = 0x8A37,
GL_UNIFORM_SIZE = 0x8A38,
GL_UNIFORM_NAME_LENGTH = 0x8A39,
GL_UNIFORM_BLOCK_INDEX = 0x8A3A,
GL_UNIFORM_OFFSET = 0x8A3B,
GL_UNIFORM_ARRAY_STRIDE = 0x8A3C,
GL_UNIFORM_MATRIX_STRIDE = 0x8A3D,
GL_UNIFORM_IS_ROW_MAJOR = 0x8A3E,
GL_UNIFORM_BLOCK_BINDING = 0x8A3F,
GL_UNIFORM_BLOCK_DATA_SIZE = 0x8A40,
GL_UNIFORM_BLOCK_NAME_LENGTH = 0x8A41,
GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS = 0x8A42,
GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8A43,
GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8A44,
GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER = 0x8A45,
GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46,
GL_INVALID_INDEX = 0xFFFFFFFFu,
GL_CONTEXT_CORE_PROFILE_BIT = 0x00000001,
GL_CONTEXT_COMPATIBILITY_PROFILE_BIT = 0x00000002,
GL_LINES_ADJACENCY = 0x000A,
GL_LINE_STRIP_ADJACENCY = 0x000B,
GL_TRIANGLES_ADJACENCY = 0x000C,
GL_TRIANGLE_STRIP_ADJACENCY = 0x000D,
GL_PROGRAM_POINT_SIZE = 0x8642,
GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS = 0x8C29,
GL_FRAMEBUFFER_ATTACHMENT_LAYERED = 0x8DA7,
GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS = 0x8DA8,
GL_GEOMETRY_SHADER = 0x8DD9,
GL_GEOMETRY_VERTICES_OUT = 0x8916,
GL_GEOMETRY_INPUT_TYPE = 0x8917,
GL_GEOMETRY_OUTPUT_TYPE = 0x8918,
GL_MAX_GEOMETRY_UNIFORM_COMPONENTS = 0x8DDF,
GL_MAX_GEOMETRY_OUTPUT_VERTICES = 0x8DE0,
GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS = 0x8DE1,
GL_MAX_VERTEX_OUTPUT_COMPONENTS = 0x9122,
GL_MAX_GEOMETRY_INPUT_COMPONENTS = 0x9123,
GL_MAX_GEOMETRY_OUTPUT_COMPONENTS = 0x9124,
GL_MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125,
GL_CONTEXT_PROFILE_MASK = 0x9126,
GL_DEPTH_CLAMP = 0x864F,
GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION = 0x8E4C,
GL_FIRST_VERTEX_CONVENTION = 0x8E4D,
GL_LAST_VERTEX_CONVENTION = 0x8E4E,
GL_PROVOKING_VERTEX = 0x8E4F,
GL_TEXTURE_CUBE_MAP_SEAMLESS = 0x884F,
GL_MAX_SERVER_WAIT_TIMEOUT = 0x9111,
GL_OBJECT_TYPE = 0x9112,
GL_SYNC_CONDITION = 0x9113,
GL_SYNC_STATUS = 0x9114,
GL_SYNC_FLAGS = 0x9115,
GL_SYNC_FENCE = 0x9116,
GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117,
GL_UNSIGNALED = 0x9118,
GL_SIGNALED = 0x9119,
GL_ALREADY_SIGNALED = 0x911A,
GL_TIMEOUT_EXPIRED = 0x911B,
GL_CONDITION_SATISFIED = 0x911C,
GL_WAIT_FAILED = 0x911D,
// GL_TIMEOUT_IGNORED = 0xFFFFFFFFFFFFFFFFull,
GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001,
GL_SAMPLE_POSITION = 0x8E50,
GL_SAMPLE_MASK = 0x8E51,
GL_SAMPLE_MASK_VALUE = 0x8E52,
GL_MAX_SAMPLE_MASK_WORDS = 0x8E59,
GL_TEXTURE_2D_MULTISAMPLE = 0x9100,
GL_PROXY_TEXTURE_2D_MULTISAMPLE = 0x9101,
GL_TEXTURE_2D_MULTISAMPLE_ARRAY = 0x9102,
GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY = 0x9103,
GL_TEXTURE_BINDING_2D_MULTISAMPLE = 0x9104,
GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY = 0x9105,
GL_TEXTURE_SAMPLES = 0x9106,
GL_TEXTURE_FIXED_SAMPLE_LOCATIONS = 0x9107,
GL_SAMPLER_2D_MULTISAMPLE = 0x9108,
GL_INT_SAMPLER_2D_MULTISAMPLE = 0x9109,
GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE = 0x910A,
GL_SAMPLER_2D_MULTISAMPLE_ARRAY = 0x910B,
GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY = 0x910C,
GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY = 0x910D,
GL_MAX_COLOR_TEXTURE_SAMPLES = 0x910E,
GL_MAX_DEPTH_TEXTURE_SAMPLES = 0x910F,
GL_MAX_INTEGER_SAMPLES = 0x9110,
}
}

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Drawing;
using System.Numerics; using System.Numerics;
using SlatedGameToolkit.Framework.Graphics.Textures;
namespace SlatedGameToolkit.Framework.Graphics.Meshes namespace SlatedGameToolkit.Framework.Graphics.Meshes
{ {
@ -18,5 +20,17 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
/// </summary> /// </summary>
/// <value>unsigned integers that are the indices of the vertices to use.</value> /// <value>unsigned integers that are the indices of the vertices to use.</value>
uint[] Elements { get; } uint[] Elements { get; }
/// <summary>
/// The texture for this mesh.
/// </summary>
/// <value>Texture for this mesh.</value>
Texture Texture { get; }
/// <summary>
/// The blended color of this mesh.
/// </summary>
/// <value>A color for this mesh.</value>
Color Color { get; }
} }
} }

View File

@ -1,17 +1,18 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Numerics; using System.Numerics;
using SlatedGameToolkit.Framework.Graphics.Textures;
namespace SlatedGameToolkit.Framework.Graphics.Meshes namespace SlatedGameToolkit.Framework.Graphics.Meshes
{ {
public abstract class RectangleMesh : IMeshable public class RectangleMesh : IMeshable
{ {
private Matrix4x4 matRot; private Matrix4x4 matRot = Matrix4x4.Identity;
private bool changed; private bool changed;
private Vector3 rotation; private Vector3 rotation;
private Vector2 origin, dimensions; private Vector2 origin, dimensions;
protected readonly Vector2[] textureCoords = new Vector2[4]; public readonly Vector2[] textureCoords = new Vector2[4];
private ValueTuple<Vector3, Vector2>[] vertices = new ValueTuple<Vector3, Vector2>[4]; public ValueTuple<Vector3, Vector2>[] vertices = new ValueTuple<Vector3, Vector2>[4];
private uint[] indices = new uint[] {0, 1, 3, 1, 2, 3}; private uint[] indices = new uint[] {0, 1, 3, 1, 2, 3};
public ValueTuple<Vector3, Vector2>[] Vertices public ValueTuple<Vector3, Vector2>[] Vertices
@ -28,10 +29,10 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
return origin.X; return origin.X;
} }
protected set set
{ {
changed = true; changed = true;
origin.X = X; origin.X = value;
} }
} }
@ -41,7 +42,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
return origin.Y; return origin.Y;
} }
protected set set
{ {
changed = true; changed = true;
origin.Y = value; origin.Y = value;
@ -55,7 +56,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
return dimensions.X; return dimensions.X;
} }
protected set set
{ {
changed = true; changed = true;
dimensions.X = value; dimensions.X = value;
@ -69,7 +70,8 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
return dimensions.Y; return dimensions.Y;
} }
protected set
set
{ {
changed = true; changed = true;
dimensions.Y = value; dimensions.Y = value;
@ -92,6 +94,11 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes
matRot = Matrix4x4.CreateFromYawPitchRoll(value.X, value.Y, value.Z); matRot = Matrix4x4.CreateFromYawPitchRoll(value.X, value.Y, value.Z);
} }
} }
public Texture Texture { get; set; }
public Color Color { get; set; }
private void CalculateVertices() { private void CalculateVertices() {
if (!changed) return; if (!changed) return;
Vector3[] baseVerts = new Vector3[4]; Vector3[] baseVerts = new Vector3[4];

View File

@ -1,127 +0,0 @@
using System;
using System.Runtime.InteropServices;
using SDL2;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.Programs;
using SlatedGameToolkit.Framework.Graphics.Shaders;
namespace SlatedGameToolkit.Framework.Graphics
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLClearColour(float r, float g, float b);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLClear(GLEnum flags);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLViewport(int x, int y, int width, int height);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate UIntPtr GLCreateShader(GLEnum type);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate UIntPtr GLShaderSource(UIntPtr shaderHandle, uint count, string[] program, int[] length);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLCompileShader(UIntPtr shaderHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLGetShaderInfoLog(UIntPtr shader, uint maxLength, out uint writtenLength, byte[] output);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate UIntPtr GLCreateProgram();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate UIntPtr GLDeleteProgram(UIntPtr program);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLAttachShader(UIntPtr program, UIntPtr shader);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDetachShader(UIntPtr program, UIntPtr shader);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDeleteShader(UIntPtr shader);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLBindAttribLocation(UIntPtr program, uint index, string name);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLGetProgramInfoLog(UIntPtr program, uint maxLength, out uint writtenLength, byte[] output);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLLinkProgram(UIntPtr program);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLProgramParameter(UIntPtr program, GLEnum parameterName, int value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLUseProgram(UIntPtr program);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLGenProgramPipelines(uint size, UIntPtr[] pipelines);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDeleteProgramPipelines(uint size, UIntPtr[] pipelines);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLBindProgramPipeline(UIntPtr pipeline);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLUseProgramStages(UIntPtr pipeline, GLEnum bitField, UIntPtr program);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate uint GLGetError();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int GLGetAttribLocation(UIntPtr program, string attribName);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLBindBuffer(GLEnum target, UIntPtr buffer);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLGenBuffers(uint size, UIntPtr[] buffers);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void GLBufferData(GLEnum target, uint size, Array data, GLEnum usage);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDeleteBuffers(uint size, UIntPtr[] buffers);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLVertexAttribPointer(uint index, int size, GLEnum type, bool normalized, uint stride, uint offset);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLGenVertexArrays(uint amount, UIntPtr[] arrays);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDeleteVertexArrays(uint amount, UIntPtr[] arrays);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLBindVertexArray(UIntPtr array);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLEnableVertexAttribArray(uint attribIndex);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDisableVertexAttribArray(uint attribIndex);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDrawArrays(GLEnum mode, int first, uint count);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDrawElements(GLEnum mode, uint count, int offset);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLMultiDrawArrays(GLEnum mode, int[] first, uint[] count, uint primout);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLMultiDrawElements(GLEnum mode, uint[] count, GLEnum type, uint[] indiceOffsets, int length);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLGenTextures(uint n, UIntPtr[] textureHandles);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLBindTexture(GLEnum target, UIntPtr texture);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLDeleteTextures(uint n, UIntPtr[] textureHandles);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLTexParameteri(GLEnum target, GLEnum pname, int value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLTexParameterf(GLEnum target, GLEnum pname, float value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLTexParameteriv(GLEnum target, GLEnum pname, int[] values);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLTexParameterfv(GLEnum target, GLEnum pname, float[] values);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLTexImage2D(GLEnum target, int level, int publicFormat, uint width, uint height, int border, GLEnum format, GLEnum type, byte[] data);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLGenerateMipmap(GLEnum target);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int GLGetUniformLocation(UIntPtr program, string name);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GLUniformMatrix4fv(int index, uint count, bool transpose, float[] matrix);
public static class OpenGL {
public const int OpenGLMajorVersion = 3;
public const int OpenGLMinorVersion = 3;
/// <summary>
/// Attempts to retrieve and instantiate an OpenGL function as a C# delegate.
/// Make sure the delegates signature is correct as failing to do so will potentially
/// lead to a CLR error on usage.
///
/// Uses SDL2 as the function address retriever.
/// </summary>
/// <param name="functionName">The process name, case sensitive, exactly as OpenGL defines it.</param>
/// <typeparam name="T">The delegate type to cast to.</typeparam>
/// <returns>The delegate associated with the retrieved path.</returns>
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.Equals(IntPtr.Zero)) throw new FrameworkSDLException();
return Marshal.GetDelegateForFunctionPointer<T>(functionAddress);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,105 +0,0 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using SDL2;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Graphics.Programs
{
/// <summary>
/// Represents a GL Program.
/// This class is abstract and serves as a parent to the possible types of programs.
/// Gives access to common OpenGL program associated function calls.
/// </summary>
public abstract class GLProgram : IDisposable
{
private WindowContext context;
protected readonly UIntPtr handle;
protected GLCreateProgram createProgram;
protected GLDeleteProgram deleteProgram;
protected GLLinkProgram linkProgram;
protected GLGetProgramInfoLog getProgramInfoLog;
protected GLProgramParameter programParameter;
private GLUseProgram useProgram;
private readonly GLGetAttribLocation getAttribLocation;
private readonly GLGetUniformLocation getUniformLocation;
private readonly GLUniformMatrix4fv uniformMatrix4Fv;
/// <summary>
/// Creates an OpenGL program.
///
/// This is bound to the current context.
/// </summary>
internal GLProgram() {
this.context = WindowContextsManager.CurrentWindowContext;
createProgram = OpenGL.RetrieveGLDelegate<GLCreateProgram>("glCreateProgram");
deleteProgram = OpenGL.RetrieveGLDelegate<GLDeleteProgram>("glDeleteProgram");
linkProgram = OpenGL.RetrieveGLDelegate<GLLinkProgram>("glLinkProgram");
getProgramInfoLog = OpenGL.RetrieveGLDelegate<GLGetProgramInfoLog>("glGetProgramInfoLog");
programParameter = OpenGL.RetrieveGLDelegate<GLProgramParameter>("glProgramParameteri");
useProgram = OpenGL.RetrieveGLDelegate<GLUseProgram>("glUseProgram");
getAttribLocation = OpenGL.RetrieveGLDelegate<GLGetAttribLocation>("glGetAttribLocation");
getUniformLocation = OpenGL.RetrieveGLDelegate<GLGetUniformLocation>("glGetUniformLocation");
uniformMatrix4Fv = OpenGL.RetrieveGLDelegate<GLUniformMatrix4fv>("glUniformMatrix4fv");
handle = createProgram();
OpenGLErrorException.CheckGLErrorStatus();
}
public int GetAttributeLocation(string name) {
int res = getAttribLocation(handle, name);
OpenGLErrorException.CheckGLErrorStatus();
return res;
}
public int GetUniformLocation(string name) {
int res = getUniformLocation(handle, name);
OpenGLErrorException.CheckGLErrorStatus();
return res;
}
public void SetUniformMatrix4x4(int location, Matrix4x4 matrix, bool transpose = false) {
Use();
float[] mat4 = new float[] {
matrix.M11, matrix.M21, matrix.M31, matrix.M41,
matrix.M21, matrix.M22, matrix.M23, matrix.M24,
matrix.M31, matrix.M32, matrix.M33, matrix.M34,
matrix.M41, matrix.M42, matrix.M43, matrix.M44
};
uniformMatrix4Fv(location, 1, transpose, mat4);
OpenGLErrorException.CheckGLErrorStatus();
}
/// <summary>
/// Binds this program.
/// </summary>
public virtual void Use() {
useProgram(handle);
uint written;
byte[] log = new byte[2048];
getProgramInfoLog(handle, (uint)log.Length, out written, log);
if (written > 0) {
throw new OpenGLException(Encoding.UTF8.GetString(log));
}
OpenGLErrorException.CheckGLErrorStatus();
}
/// <summary>
/// Disposes of the program.
/// </summary>
public virtual void Dispose()
{
deleteProgram(handle);
OpenGLErrorException.CheckGLErrorStatus();
}
~GLProgram() {
Dispose();
}
}
}

View File

@ -1,61 +0,0 @@
using System;
using System.Text;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.Shaders;
namespace SlatedGameToolkit.Framework.Graphics.Programs
{
public class GLShaderProgram : GLProgram
{
private readonly GLShader[] shaders;
private readonly GLAttachShader attachShader;
private readonly GLDetachShader detachShader;
public GLShaderProgram(params GLShader[] shaders) : base() {
if (shaders.Length == 0) throw new ArgumentException("Requires at least one shader for shader program.");
this.shaders = shaders;
attachShader = OpenGL.RetrieveGLDelegate<GLAttachShader>("glAttachShader");
detachShader = OpenGL.RetrieveGLDelegate<GLDetachShader>("glDetachShader");
foreach (GLShader shader in shaders)
{
attachShader(handle, shader.Handle);
OpenGLErrorException.CheckGLErrorStatus();
}
linkProgram(handle);
uint length;
byte[] log = new byte[2048];
getProgramInfoLog(handle, (uint)log.Length, out length, log);
if (length > 0) {
Dispose();
throw new OpenGLException(Encoding.UTF8.GetString(log));
}
OpenGLErrorException.CheckGLErrorStatus();
foreach (GLShader shader in shaders)
{
detachShader(handle, shader.Handle);
OpenGLErrorException.CheckGLErrorStatus();
}
}
/// <summary>
/// Disposes of the shaders and this program.
/// </summary>
public override void Dispose() {
foreach (GLShader shader in shaders)
{
shader.Dispose();
}
base.Dispose();
}
~GLShaderProgram() {
Dispose();
}
}
}

View File

@ -1,121 +0,0 @@
using System;
using System.Drawing;
using System.Numerics;
using SlatedGameToolkit.Framework.Graphics.Meshes;
using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Graphics.Shaders;
using SlatedGameToolkit.Framework.Graphics.Programs;
using SlatedGameToolkit.Framework.Exceptions;
namespace SlatedGameToolkit.Framework.Graphics.Render
{
public class Batch : IDisposable {
private int projLoc, viewLoc, modelLoc;
private Camera camera;
private GLShaderProgram shaderProgram;
private Texture texture;
private bool disposed;
private VertexArray vertexArray;
private const int VERTEX_LENGTH = 9;
private GLMultiDrawElements multiDrawElements;
public bool Batching { get; private set; }
private Matrix4x4 modelsMatrix;
private float[] data;
private uint[] indices;
private uint[] lengths;
private uint[] offsets;
private uint dataIndex, indicesIndex, lengthsIndex;
public Batch(Camera camera, GLShaderProgram shaderProgram, uint BatchVertexSize = 4096) {
multiDrawElements = OpenGL.RetrieveGLDelegate<GLMultiDrawElements>("glMultiDrawElements");
this.camera = camera;
this.shaderProgram = shaderProgram;
indices = new uint[BatchVertexSize];
lengths = new uint[BatchVertexSize];
offsets = new uint[BatchVertexSize];
data = new float[BatchVertexSize * VERTEX_LENGTH];
vertexArray = new VertexArray();
GLGetAttribLocation attribLocation = OpenGL.RetrieveGLDelegate<GLGetAttribLocation>("glGetAttribLocation");
VertexAttributeDefinition[] definitions = new VertexAttributeDefinition[3];
definitions[0] = new VertexAttributeDefinition((uint)shaderProgram.GetAttributeLocation("aPosition"), 3, 3 * sizeof(float), 0);
definitions[1] = new VertexAttributeDefinition((uint)shaderProgram.GetAttributeLocation("aColor"), 4, 4 * sizeof(float), 3 * sizeof(float));
definitions[2] = new VertexAttributeDefinition((uint)shaderProgram.GetAttributeLocation("aTexCoord"), 2, 2 * sizeof(float), (4 + 3) * sizeof(float));
modelLoc = shaderProgram.GetUniformLocation("models");
viewLoc = shaderProgram.GetUniformLocation("view");
projLoc = shaderProgram.GetUniformLocation("projection");
vertexArray.defineVertexAttributes(definitions: definitions);
}
public virtual void Begin(Texture texture, Matrix4x4 modelsMatrix) {
if (Batching) throw new InvalidOperationException("This batch is already started.");
this.texture = texture ?? throw new ArgumentNullException("texture");
this.Batching = true;
this.modelsMatrix = modelsMatrix;
}
public virtual void Dispose()
{
if (disposed) return;
if (Batching) End();
disposed = true;
vertexArray.Dispose();
}
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();
for (int i = 0; i < vertices.Length; i++) {
data[dataIndex] = vertices[i].Item1.X;
dataIndex++;
data[dataIndex] = vertices[i].Item1.Y;
dataIndex++;
data[dataIndex] = vertices[i].Item1.Z;
dataIndex++;
data[dataIndex] = (float) color.A / byte.MaxValue;
dataIndex++;
data[dataIndex] = (float) color.R / byte.MaxValue;
dataIndex++;
data[dataIndex] = (float) color.G / byte.MaxValue;
dataIndex++;
data[dataIndex] = (float) color.B / byte.MaxValue;
dataIndex++;
data[dataIndex] = vertices[i].Item2.X;
dataIndex++;
data[dataIndex] = vertices[i].Item2.Y;
dataIndex++;
uint elementsCount = (uint)indices.Length;
Array.Copy(indices, indices, elementsCount);
indicesIndex += elementsCount;
lengths[lengthsIndex] = elementsCount;
lengthsIndex ++;
}
}
public virtual void End() {
if (!Batching) throw new InvalidOperationException("This batch was never started.");
this.Batching = false;
Flush();
}
protected virtual void Flush() {
texture.Use();
vertexArray.Use();
vertexArray.BufferVertices(data);
vertexArray.BufferIndices(indices);
dataIndex = 0;
indicesIndex = 0;
lengthsIndex = 0;
shaderProgram.SetUniformMatrix4x4(modelLoc, modelsMatrix);
shaderProgram.SetUniformMatrix4x4(viewLoc, camera.ViewMatrix);
shaderProgram.SetUniformMatrix4x4(projLoc, camera.ProjectionMatrix);
multiDrawElements(GLEnum.GL_TRIANGLE_STRIP, lengths, GLEnum.GL_UNSIGNED_INT, offsets, lengths.Length);
}
}
}

View File

@ -1,36 +1,53 @@
using System;
using System.Numerics; using System.Numerics;
using SlatedGameToolkit.Framework.Utilities;
namespace SlatedGameToolkit.Framework.Graphics.Render namespace SlatedGameToolkit.Framework.Graphics.Render
{ {
public class Camera { public class Camera {
private bool viewUpdated, projectionUpdated; private bool viewUpdated = true, projectionUpdated = true, orthographic;
public virtual Vector3 Up { get; set; } public virtual Vector3 Up { get; set; } = Vector3.UnitY;
private Vector3 trans, lookAt; private Vector3 position, lookAt;
private float nearField, farField; private float nearField = 0.01f, farField = 100f;
private float width, height; private float width, height;
private Matrix4x4 lookAtMatrix; private Matrix4x4 lookAtMatrix = Matrix4x4.Identity;
private Matrix4x4 view, projection; private Matrix4x4 view = Matrix4x4.Identity, projection;
public virtual bool Orthographic { get; set; } public bool Orthographic {
public virtual Vector3 Position {
get { get {
return trans; return orthographic;
} }
set { set {
this.trans = value; orthographic = value;
projectionUpdated = true;
}
}
public Vector3 Position {
get {
return position;
}
set {
this.position = value;
viewUpdated = true; viewUpdated = true;
} }
} }
public Vector3 CameraFront {
get {
return (LookAt - Position).NormalizeSafe(default(Vector3));
}
set {
LookAt = (position + value.NormalizeSafe(default(Vector3)));
}
}
public Vector3 LookAt { public Vector3 LookAt {
get { get {
return lookAt; return lookAt;
} }
set { set {
this.lookAt = value; this.lookAt = value;
lookAtMatrix = Matrix4x4.CreateLookAt(-trans, value, Up);
viewUpdated = true; viewUpdated = true;
} }
} }
@ -61,10 +78,10 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
get { get {
return width; return width;
} }
set { set {
width = value; width = value;
projectionUpdated = true; projectionUpdated = true;
} }
} }
public virtual float Height { public virtual float Height {
get { get {
@ -79,7 +96,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
public Matrix4x4 ViewMatrix { public Matrix4x4 ViewMatrix {
get { get {
if (viewUpdated) { if (viewUpdated) {
view = Matrix4x4.CreateTranslation(-trans) * lookAtMatrix; view = Matrix4x4.CreateLookAt(Position, LookAt, Up);
viewUpdated = false; viewUpdated = false;
} }
return view; return view;
@ -99,5 +116,14 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
return projection; return projection;
} }
} }
public Camera(float width, float height) {
if (width <= 0) throw new ArgumentException("Width can't be less than or equal to 0.");
if (height <= 0) throw new ArgumentException("Height can't be less than or equal to 0.");
this.Width = width;
this.Height = height;
this.Position = new Vector3(0, 0, 3);
this.CameraFront = -Vector3.UnitZ;
}
} }
} }

View File

@ -9,14 +9,13 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
} }
set { set {
base.Position = new Vector3(value, 0); base.Position = new Vector3(value, base.Position.Z);
base.CameraFront = -Vector3.UnitZ;
} }
} }
public Camera2D() { public Camera2D(int width, int height) : base(width, height) {
this.Orthographic = true; this.Orthographic = true;
this.Up = Vector3.UnitY;
this.LookAt = new Vector3(0, 0, 1);
} }
} }
} }

View File

@ -1,12 +0,0 @@
using System.Drawing;
using SlatedGameToolkit.Framework.Graphics.Meshes;
using SlatedGameToolkit.Framework.Graphics.Textures;
namespace SlatedGameToolkit.Framework.Graphics.Render
{
public interface IRenderable : IMeshable
{
Texture Texture { get; }
Color Color { get; }
}
}

View File

@ -0,0 +1,166 @@
using System;
using System.Drawing;
using System.Numerics;
using SlatedGameToolkit.Framework.Graphics.Meshes;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Render.Programs;
using SlatedGameToolkit.Framework.Graphics.Render.Shaders;
using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Graphics.Window;
using SlatedGameToolkit.Framework.Utilities;
namespace SlatedGameToolkit.Framework.Graphics.Render
{
public class MeshBatch : IDisposable {
public GLContext GLContext {get; private set; }
private const int VERTEX_LENGTH = 9;
private int projLoc, viewLoc, modelLoc;
private Camera camera;
private RenderProgram renderProgram;
private Texture texture;
private Texture fillerTexture;
private bool disposed;
private VertexArrayBuffers vertexBuffers;
public bool Batching { get; private set; }
private Matrix4x4 modelsMatrix;
private float[] data;
private uint[] indices;
private int[] lengths;
private int[] indiceOffsets;
private int[] verticeOffsets;
private int dataIndex, indicesIndex, offsetIndex;
public MeshBatch(Camera camera, RenderProgram renderProgram = null, uint BatchVertexSize = 4096) {
if (renderProgram == null) {
VertexShader vert = new VertexShader(EmbeddedResourceUtils.ReadEmbeddedResourceText("default.vert"));
FragmentShader frag = new FragmentShader(EmbeddedResourceUtils.ReadEmbeddedResourceText("default.frag"));
renderProgram = new RenderProgram(null, vert, frag);
}
this.renderProgram = renderProgram;
this.GLContext = renderProgram.GLContext;
this.camera = camera;
indices = new uint[BatchVertexSize];
lengths = new int[BatchVertexSize];
indiceOffsets = new int[BatchVertexSize];
data = new float[BatchVertexSize * VERTEX_LENGTH];
verticeOffsets = new int[BatchVertexSize];
vertexBuffers = new VertexArrayBuffers(GLContext);
VertexAttributeDefinition[] definitions = new VertexAttributeDefinition[3];
definitions[0] = new VertexAttributeDefinition((uint)GLContext.GetAttribLocation(renderProgram.Handle, "aPosition"), 3);
definitions[1] = new VertexAttributeDefinition((uint)GLContext.GetAttribLocation(renderProgram.Handle, "aColor"), 4);
definitions[2] = new VertexAttributeDefinition((uint)GLContext.GetAttribLocation(renderProgram.Handle, "aTexCoord"), 2);
renderProgram.Use();
modelLoc = GLContext.GetUniformLocation(renderProgram.Handle, "models");
viewLoc = GLContext.GetUniformLocation(renderProgram.Handle, "view");
projLoc = GLContext.GetUniformLocation(renderProgram.Handle, "projection");
vertexBuffers.defineVertexAttributes(definitions: definitions);
fillerTexture = new Texture(GameEngine.FillerTextureData);
}
public virtual void Begin(Matrix4x4 modelsMatrix) {
if (Batching) throw new InvalidOperationException("This batch is already started.");
this.Batching = true;
this.modelsMatrix = modelsMatrix;
}
public virtual void Draw(IMeshable meshable) {
if (meshable.Texture != this.texture) {
if (this.texture != null) {
Flush();
}
this.texture = meshable.Texture ?? fillerTexture;
}
ValueTuple<Vector3, Vector2>[] vertices = meshable.Vertices;
uint[] indices = meshable.Elements;
if (vertices.Length * VERTEX_LENGTH + dataIndex >= data.Length || indices.Length + indicesIndex >= this.indices.Length)
Flush();
for (int i = 0; i < vertices.Length; i++) {
data[dataIndex] = vertices[i].Item1.X;
dataIndex++;
data[dataIndex] = vertices[i].Item1.Y;
dataIndex++;
data[dataIndex] = vertices[i].Item1.Z;
dataIndex++;
data[dataIndex] = meshable.Color.RedAsFloat();
dataIndex++;
data[dataIndex] = meshable.Color.GreenAsFloat();
dataIndex++;
data[dataIndex] = meshable.Color.BlueAsFloat();
dataIndex++;
data[dataIndex] = meshable.Color.AlphaAsFloat();
dataIndex++;
data[dataIndex] = vertices[i].Item2.X;
dataIndex++;
data[dataIndex] = vertices[i].Item2.Y;
dataIndex++;
}
int elementsCount = indices.Length;
Array.Copy(indices, 0, this.indices, indicesIndex, elementsCount);
indicesIndex += elementsCount;
if (offsetIndex + 1 < verticeOffsets.Length) {
verticeOffsets[offsetIndex + 1] = verticeOffsets[offsetIndex] + vertices.Length;
indiceOffsets[offsetIndex + 1] = indicesIndex * sizeof(int);
}
lengths[offsetIndex] = elementsCount;
offsetIndex++;
}
public virtual void End() {
if (!Batching) throw new InvalidOperationException("This batch was never started.");
this.Batching = false;
Flush();
}
protected virtual void Flush() {
texture.Use();
renderProgram.Use();
vertexBuffers.BufferVertices(data, true);
vertexBuffers.BufferIndices(indices, true);
GLContext.UniformMatrix4fv(modelLoc, 1, false, modelsMatrix.ToColumnMajorArray());
GLContext.UniformMatrix4fv(viewLoc, 1, false, camera.ViewMatrix.ToColumnMajorArray());
GLContext.UniformMatrix4fv(projLoc, 1, false, camera.ProjectionMatrix.ToColumnMajorArray());
// GLContext.UniformMatrix4fv(modelLoc, 1, false, Matrix4x4.Identity.ToColumnMajorArray());
// GLContext.UniformMatrix4fv(viewLoc, 1, false, Matrix4x4.Identity.ToColumnMajorArray());
// GLContext.UniformMatrix4fv(projLoc, 1, false, Matrix4x4.Identity.ToColumnMajorArray());
GLContext.MultiDrawElementsBaseVertex(PrimitiveType.Triangles, lengths, DrawElementsType.UnsignedInt, indiceOffsets, offsetIndex, verticeOffsets);
dataIndex = 0;
indicesIndex = 0;
offsetIndex = 0;
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
}
if (disposed) return;
if (Batching) End();
disposed = true;
vertexBuffers.Dispose();
renderProgram.Dispose();
fillerTexture.Dispose();
data = null;
indices = null;
lengths = null;
verticeOffsets = null;
}
}
~MeshBatch()
{
Dispose(disposing: false);
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@ -0,0 +1,70 @@
using System;
using System.Text;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Render.Shaders;
using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Graphics.Render.Programs
{
public class RenderProgram : IDisposable
{
public GLContext GLContext {get; private set; }
private bool disposed;
public uint Handle { get; private set; }
public RenderProgram(GLContext context = null, params IShadeable[] shaders) {
this.GLContext = context ?? WindowContextsManager.CurrentGL;
Handle = GLContext.CreateProgram();
foreach (IShadeable shader in shaders)
{
if (this.GLContext != shader.GLContext) throw new FrameworkUsageException("OpenGL contexts between attached shaders and program must match.");
GLContext.AttachShader(Handle, shader.Handle);
}
GLContext.LinkProgram(Handle);
int status;
GLContext.GetProgramiv(Handle, ProgramPropertyARB.LinkStatus, out status);
if ((OpenGL.Boolean)status == OpenGL.Boolean.False) {
int logLength;
GLContext.GetProgramiv(Handle, ProgramPropertyARB.InfoLogLength, out logLength);
byte[] logData = new byte[logLength];
int byteCount;
GLContext.GetProgramInfoLog(Handle, logLength, out byteCount, logData);
throw new FrameworkUsageException(Encoding.UTF8.GetString(logData));
}
foreach (IShadeable shader in shaders)
{
shader.Dispose();
}
}
public void Use() {
GLContext.UseProgram(Handle);
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
}
GLContext.DeleteProgram(Handle);
disposed = true;
}
}
~RenderProgram()
{
Dispose(false);
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@ -1,41 +0,0 @@
using System;
using System.Drawing;
using System.Numerics;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.Programs;
using SlatedGameToolkit.Framework.Graphics.Textures;
namespace SlatedGameToolkit.Framework.Graphics.Render
{
public class Renderer : IDisposable
{
private Batch batch;
private Texture currentTexture;
public Renderer(Batch batch) {
this.batch = batch;
}
public Renderer(Camera camera, GLShaderProgram program, uint BatchVertexSize = 4096) {
this.batch = new Batch(camera, program, BatchVertexSize);
}
public void Dispose()
{
batch.Dispose();
}
public void Queue(IRenderable renderable, Matrix4x4 modelsMatrix) {
if (renderable.Texture != currentTexture) {
if (batch.Batching) batch.End();
currentTexture = renderable.Texture;
batch.Begin(currentTexture, modelsMatrix);
}
batch.Add(renderable, renderable.Color);
}
public void Render() {
if (batch.Batching) batch.End();
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Text;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Graphics.Render.Shaders
{
public class FragmentShader : IShadeable
{
public GLContext GLContext {get; private set; }
private bool disposed;
public uint Handle { get; private set; }
public FragmentShader(string program, GLContext context = null) {
this.GLContext = context ?? WindowContextsManager.CurrentGL;
Handle = GLContext.CreateShader(ShaderType.FragmentShader);
GLContext.ShaderSource(Handle, 1, new string[] {program}, null);
GLContext.CompileShader(Handle);
int status;
GLContext.GetShaderiv(Handle, ShaderParameterName.CompileStatus, out status);
if ((OpenGL.Boolean)status == OpenGL.Boolean.False) {
int logLength;
GLContext.GetShaderiv(Handle, ShaderParameterName.InfoLogLength, out logLength);
byte[] logData = new byte[logLength];
int byteCount;
GLContext.GetShaderInfoLog(Handle, logLength, out byteCount, logData);
throw new FrameworkUsageException(string.Format("Error compiling shader: {0}", Encoding.UTF8.GetString(logData)));
}
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
}
GLContext.DeleteShader(Handle);
disposed = true;
}
}
~FragmentShader()
{
Dispose(disposing: false);
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@ -0,0 +1,11 @@
using System;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
namespace SlatedGameToolkit.Framework.Graphics.Render.Shaders
{
public interface IShadeable : IDisposable
{
GLContext GLContext {get;}
uint Handle { get; }
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Text;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Graphics.Render.Shaders
{
public class VertexShader : IShadeable
{
public GLContext GLContext {get; private set;}
private bool disposed;
public uint Handle { get; private set; }
public VertexShader(string program, GLContext context = null) {
this.GLContext = context ?? WindowContextsManager.CurrentGL;
Handle = GLContext.CreateShader(ShaderType.VertexShader);
GLContext.ShaderSource(Handle, 1, new string[] {program}, null);
GLContext.CompileShader(Handle);
int status;
GLContext.GetShaderiv(Handle, ShaderParameterName.CompileStatus, out status);
if ((OpenGL.Boolean)status == OpenGL.Boolean.False) {
int logLength;
GLContext.GetShaderiv(Handle, ShaderParameterName.InfoLogLength, out logLength);
byte[] logData = new byte[logLength];
int byteCount;
GLContext.GetShaderInfoLog(Handle, logLength, out byteCount, logData);
throw new FrameworkUsageException(string.Format("Error compiling shader: {0}", Encoding.UTF8.GetString(logData)));
}
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
}
GLContext.DeleteShader(Handle);
disposed = true;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~VertexShader() {
Dispose(false);
}
}
}

View File

@ -4,27 +4,25 @@ using SlatedGameToolkit.Framework.Graphics.Textures;
namespace SlatedGameToolkit.Framework.Graphics.Render namespace SlatedGameToolkit.Framework.Graphics.Render
{ {
public class Sprite2D : RectangleMesh, IRenderable public class Sprite2D : RectangleMesh
{ {
public Texture Texture { get; private set; }
public Color Color { get; private set; }
public Sprite2D(Texture texture, Color color) { public Sprite2D(Texture texture, Color color) {
this.Texture = texture; this.Texture = texture;
this.textureCoords[0].X = -1; this.textureCoords[0].X = 0;
this.textureCoords[0].Y = -1; this.textureCoords[0].Y = 1;
this.textureCoords[1].X = 1; this.textureCoords[1].X = 1;
this.textureCoords[1].Y = -1; this.textureCoords[1].Y = 1;
this.textureCoords[2].X = 1; this.textureCoords[2].X = 1;
this.textureCoords[2].Y = 1; this.textureCoords[2].Y = 0;
this.textureCoords[3].X = -1; this.textureCoords[3].X = 0;
this.textureCoords[3].Y = 1; this.textureCoords[3].Y = 0;
this.Color = color; this.Color = color;
this.Width = 1f;
this.Height = 1f;
} }
} }
} }

View File

@ -0,0 +1,123 @@
using System;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Graphics.Render
{
/// <summary>
/// A set of two buffers, one for the vertices, and one for the indices. Also defines an vertex array that defines the attributes of the buffers.
/// </summary>
public class VertexArrayBuffers : IDisposable {
private GLContext glContext;
private bool disposed;
private uint vertexBufferHandle, vertexArrayHandle, indexBufferHandle;
public VertexArrayBuffers(GLContext context) {
this.glContext = context ?? WindowContextsManager.CurrentGL;
uint[] vertexArrays = new uint[1];
glContext.GenVertexArrays(1, vertexArrays);
vertexArrayHandle = vertexArrays[0];
uint[] vertexBuffers = new uint[2];
glContext.GenBuffers(2, vertexBuffers);
vertexBufferHandle = vertexBuffers[0];
indexBufferHandle = vertexBuffers[1];
}
public void Use() {
if (disposed) throw new ObjectDisposedException("VertexArrayBuffers");
glContext.BindVertexArray(vertexArrayHandle);
glContext.BindBuffer(BufferTargetARB.ElementArrayBuffer, indexBufferHandle);
glContext.BindBuffer(BufferTargetARB.ArrayBuffer, vertexBufferHandle);
}
public unsafe void BufferVertices(float[] data, bool dynamic) {
Use();
fixed (void* pointer = &data[0]) {
glContext.BufferData(OpenGL.BufferTargetARB.ArrayBuffer, (uint) (sizeof(float) * data.Length), new IntPtr(pointer), dynamic ? OpenGL.BufferUsageARB.DynamicDraw : OpenGL.BufferUsageARB.StaticDraw);
}
}
public unsafe void BufferIndices(uint[] data, bool dynamic) {
Use();
fixed (void* pointer = &data[0]) {
glContext.BufferData(OpenGL.BufferTargetARB.ElementArrayBuffer, (uint) (sizeof(uint) * data.Length), new IntPtr(pointer), dynamic ? OpenGL.BufferUsageARB.DynamicDraw : OpenGL.BufferUsageARB.StaticDraw);
}
}
/// <summary>
/// Defines the vertex attributes in an OpenGL vertex array object.
/// Sends as floats.
/// </summary>
/// <param name="enableAttributes">Whether or not to automatically enable the attributes that are being defined. Defaults to true.</param>
/// <param name="definitions">The definitions for the vertex array object.</param>
public void defineVertexAttributes(bool enableAttributes = true, params VertexAttributeDefinition[] definitions) {
Use();
int offset = 0;
uint stride = 0;
foreach (VertexAttributeDefinition definition in definitions)
{
stride += (uint)definition.size * sizeof(float);
}
foreach (VertexAttributeDefinition definition in definitions)
{
glContext.VertexAttribPointer(definition.attributeIndex, definition.size, OpenGL.VertexAttribPointerType.Float, false, stride, new IntPtr(offset));
offset += definition.size * sizeof(float);
if (enableAttributes) glContext.EnableVertexAttribArray(definition.attributeIndex);
}
}
/// <summary>
/// Enaables the vertex array object's definitions at the given attribute indices.
/// </summary>
/// <param name="attributeIndices">The attribute indices to be enabled.</param>
public void EnableAttributes(params uint[] attributeIndices) {
Use();
foreach (uint attrib in attributeIndices)
{
glContext.EnableVertexAttribArray(attrib);
}
}
/// <summary>
/// Disables the vertex array object's definitions at the given attribute indices.
/// </summary>
/// <param name="attributeIndices">The attribute indices to be disabled.</param>
public void DisableAttributes(params uint[] attributeIndices) {
Use();
foreach (uint attrib in attributeIndices)
{
glContext.DisableVertexAttribArray(attrib);
}
}
protected virtual void Dispose(bool disposing)
{
if (this.disposed) return;
if (disposing) {
}
this.disposed = true;
glContext.DeleteVertexArrays(1, new uint[] {vertexArrayHandle});
glContext.DeleteBuffers(2, new uint[] {indexBufferHandle, vertexBufferHandle});
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
~VertexArrayBuffers() {
Dispose(false);
}
}
public struct VertexAttributeDefinition {
public uint attributeIndex;
public int size;
public VertexAttributeDefinition(uint attributeIndex, int size) {
this.attributeIndex = attributeIndex;
this.size = size;
}
}
}

View File

@ -1,27 +0,0 @@
using System.Text;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics;
namespace SlatedGameToolkit.Framework.Graphics.Shaders
{
public class GLFragmentShader : GLShader {
/// <summary>
/// Creates an OpenGL fragment shader.
/// </summary>
/// <param name="shader">A string representing the GLSL code to run.</param>
public GLFragmentShader(string shader) : base() {
Handle = createShader(GLEnum.GL_FRAGMENT_SHADER);
shaderSource(Handle, 1, new string[] {shader}, null);
compileShader(Handle);
uint logLength;
byte[] log = new byte[2048];
getShaderInfoLog(Handle, (uint)log.Length, out logLength, log);
if (logLength > 0) {
Dispose();
throw new OpenGLException(Encoding.UTF8.GetString(log));
}
OpenGLErrorException.CheckGLErrorStatus();
}
}
}

View File

@ -1,44 +0,0 @@
using System;
using System.Runtime.InteropServices;
using SDL2;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.Programs;
using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Graphics.Shaders
{
public abstract class GLShader : IDisposable {
private WindowContext context;
public virtual UIntPtr Handle { get; protected set; }
protected GLCreateShader createShader;
protected GLShaderSource shaderSource;
protected GLCompileShader compileShader;
protected GLGetShaderInfoLog getShaderInfoLog;
private GLDeleteShader deleteShader;
public GLShader() {
context = WindowContextsManager.CurrentWindowContext;
createShader = OpenGL.RetrieveGLDelegate<GLCreateShader>("glCreateShader");
shaderSource = OpenGL.RetrieveGLDelegate<GLShaderSource>("glShaderSource");
compileShader = OpenGL.RetrieveGLDelegate<GLCompileShader>("glCompileShader");
getShaderInfoLog = OpenGL.RetrieveGLDelegate<GLGetShaderInfoLog>("glGetShaderInfoLog");
deleteShader = OpenGL.RetrieveGLDelegate<GLDeleteShader>("glDeleteShader");
}
/// <summary>
/// Disposes of the shader at the handle.
/// </summary>
public virtual void Dispose()
{
deleteShader(Handle);
OpenGLErrorException.CheckGLErrorStatus();
}
~GLShader() {
Dispose();
}
}
}

View File

@ -1,140 +0,0 @@
using System;
using System.Runtime.InteropServices;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics;
namespace SlatedGameToolkit.Framework.Graphics.Shaders
{
public sealed class GLVertexArraySet : IDisposable {
private bool disposed;
public int Count { get; private set; }
private UIntPtr[] arrayBufferHandles;
private UIntPtr[] vertexArrayHandles;
private UIntPtr[] indexArrayHandles;
private GLBindBuffer bindBuffer;
private GLGenBuffers genBuffers;
private GLDeleteBuffers deleteBuffers;
private GLGenVertexArrays genVertexArrays;
private GLBindVertexArray bindVertexArray;
private GLDeleteVertexArrays deleteVertexArrays;
private GLVertexAttribPointer vertexAttribPointer;
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;
genBuffers = OpenGL.RetrieveGLDelegate<GLGenBuffers>("glGenBuffers");
deleteBuffers = OpenGL.RetrieveGLDelegate<GLDeleteBuffers>("glDeleteBuffers");
bindBuffer = OpenGL.RetrieveGLDelegate<GLBindBuffer>("glBindBuffer");
genVertexArrays = OpenGL.RetrieveGLDelegate<GLGenVertexArrays>("glGenVertexArrays");
bindVertexArray = OpenGL.RetrieveGLDelegate<GLBindVertexArray>("glBindVertexArray");
deleteVertexArrays = OpenGL.RetrieveGLDelegate<GLDeleteVertexArrays>("glDeleteVertexArrays");
vertexAttribPointer = OpenGL.RetrieveGLDelegate<GLVertexAttribPointer>("glVertexAttribPointer");
enableVertexAttribArray = OpenGL.RetrieveGLDelegate<GLEnableVertexAttribArray>("glEnableVertexAttribArray");
disableVertexAttribArray = OpenGL.RetrieveGLDelegate<GLDisableVertexAttribArray>("glDisableVertexAttribArray");
bufferData = OpenGL.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) {
bindVertexArray(vertexArrayHandles[index]);
OpenGLErrorException.CheckGLErrorStatus();
bindBuffer(GLEnum.GL_ELEMENT_ARRAY_BUFFER, indexArrayHandles[index]);
bindBuffer(GLEnum.GL_ARRAY_BUFFER, arrayBufferHandles[index]);
OpenGLErrorException.CheckGLErrorStatus();
}
public unsafe void BufferVertices(uint index, float[] data, bool dynamic) {
Use(index);
bufferData(GLEnum.GL_ARRAY_BUFFER, (uint) (sizeof(float) * data.Length), data, dynamic ? GLEnum.GL_DYNAMIC_DRAW : GLEnum.GL_STATIC_DRAW);
OpenGLErrorException.CheckGLErrorStatus();
}
public unsafe void BufferIndices(uint index, uint[] data, bool dynamic) {
Use(index);
bufferData(GLEnum.GL_ELEMENT_ARRAY_BUFFER, (uint) (sizeof(float) * data.Length), data, dynamic ? GLEnum.GL_DYNAMIC_DRAW : GLEnum.GL_STATIC_DRAW);
OpenGLErrorException.CheckGLErrorStatus();
}
/// <summary>
/// Defines the vertex attributes in an OpenGL vertex array object.
/// Sends as floats.
/// </summary>
/// <param name="bufferIndex">The buffer in this set to affect.</param>
/// <param name="enableAttributes">Whether or not to automatically enable the attributes that are being defined. Defaults to true.</param>
/// <param name="definitions">The definitions for the vertex array object.</param>
public void defineVertexAttributes(uint bufferIndex, bool enableAttributes = true, params VertexAttributeDefinition[] definitions) {
Use(bufferIndex);
foreach (VertexAttributeDefinition definition in definitions)
{
vertexAttribPointer(definition.attributeIndex, definition.size, GLEnum.GL_FLOAT, false, definition.stride, definition.offset);
OpenGLErrorException.CheckGLErrorStatus();
if (enableAttributes) enableVertexAttribArray(definition.attributeIndex);
}
}
/// <summary>
/// Enaables the vertex array object's definitions at the given attribute indices.
/// </summary>
/// <param name="bufferIndex">The buffer index in this set this should affect.</param>
/// <param name="attributeIndices">The attribute indices to be enabled.</param>
public void EnableAttributes(uint bufferIndex, params uint[] attributeIndices) {
Use(bufferIndex);
foreach (uint attrib in attributeIndices)
{
enableVertexAttribArray(attrib);
}
}
/// <summary>
/// Disables the vertex array object's definitions at the given attribute indices.
/// </summary>
/// <param name="bufferIndex">The buffer index in this set that should be affected.</param>
/// <param name="attributeIndices">The attribute indices to be disabled.</param>
public void DisableAttributes(uint bufferIndex, params uint[] attributeIndices) {
Use(bufferIndex);
foreach (uint attrib in attributeIndices)
{
disableVertexAttribArray(attrib);
}
}
public void Dispose()
{
if (this.disposed) return;
this.disposed = true;
deleteBuffers((uint)arrayBufferHandles.Length, arrayBufferHandles);
OpenGLErrorException.CheckGLErrorStatus();
deleteVertexArrays((uint)vertexArrayHandles.Length, vertexArrayHandles);
OpenGLErrorException.CheckGLErrorStatus();
GC.SuppressFinalize(this);
}
~GLVertexArraySet() {
Dispose();
}
}
public struct VertexAttributeDefinition {
public uint attributeIndex;
public int size;
public uint stride;
public uint offset;
public VertexAttributeDefinition(uint attributeIndex, int size, uint stride, uint offset) {
this.attributeIndex = attributeIndex;
this.size = size;
this.stride = stride;
this.offset = offset;
}
}
}

View File

@ -1,26 +0,0 @@
using System.Text;
using SlatedGameToolkit.Framework.Exceptions;
namespace SlatedGameToolkit.Framework.Graphics.Shaders
{
public class GLVertexShader : GLShader {
/// <summary>
/// Creates an OpenGL vertex shader.
/// </summary>
/// <param name="shader">A string representing the GLSL code.</param>
public GLVertexShader(string shader) : base() {
Handle = createShader(GLEnum.GL_VERTEX_SHADER);
shaderSource(Handle, 1, new string[] {shader}, null);
compileShader(Handle);
uint logLength;
byte[] log = new byte[2048];
getShaderInfoLog(Handle, (uint)log.Length, out logLength, log);
if (logLength > 0) {
Dispose();
throw new OpenGLException(Encoding.UTF8.GetString(log));
}
OpenGLErrorException.CheckGLErrorStatus();
}
}
}

View File

@ -1,21 +0,0 @@
using System;
using System.IO;
using System.Reflection;
namespace SlatedGameToolkit.Framework.Graphics.Shaders
{
public class NormalFragmentShader : GLShader
{
private GLFragmentShader shader;
public NormalFragmentShader() {
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SlatedGameToolkit.Framework.Resources.default.frag"))
{
using (StreamReader reader = new StreamReader(stream))
{
shader = new GLFragmentShader(reader.ReadToEnd());
}
}
this.Handle = shader.Handle;
}
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.IO;
using System.Reflection;
namespace SlatedGameToolkit.Framework.Graphics.Shaders {
public class NormalVertexShader : GLShader
{
private GLVertexShader shader;
public NormalVertexShader() {
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SlatedGameToolkit.Framework.Resources.default.vert"))
{
using (StreamReader reader = new StreamReader(stream)) {
shader = new GLVertexShader(reader.ReadToEnd());
}
}
Handle = shader.Handle;
}
}
}

View File

@ -1,63 +0,0 @@
using System;
namespace SlatedGameToolkit.Framework.Graphics.Shaders
{
public class VertexArray : IDisposable
{
private GLVertexArraySet glVertexArraySet;
private uint index;
public VertexArray(GLVertexArraySet gLVertexArraySet, uint index) {
this.glVertexArraySet = gLVertexArraySet;
this.index = index;
}
public VertexArray() {
this.glVertexArraySet = new GLVertexArraySet(1);
this.index = 0;
}
public void BufferVertices(float[] data, bool dynamic = true) {
glVertexArraySet.BufferVertices(index, data, dynamic);
}
public void BufferIndices(uint[] data, bool dynamic = true) {
glVertexArraySet.BufferIndices(index, data, dynamic);
}
/// <summary>
/// Defines the vertex attributes in an OpenGL vertex array object.
/// Sends as floats.
/// </summary>
/// <param name="enableAttributes">Whether or not to automatically enable the attributes that are being defined. Defaults to true.</param>
/// <param name="definitions">The definitions for the vertex array object.</param>
public void defineVertexAttributes(bool enableAttributes = true, params VertexAttributeDefinition[] definitions) {
this.glVertexArraySet.defineVertexAttributes(index, enableAttributes, definitions);
}
/// <summary>
/// Enaables the vertex array object's definitions at the given attribute indices.
/// </summary>
/// <param name="attributeIndices">The attribute indices to be enabled.</param>
public void EnableAttributes(params uint[] attributeIndices) {
glVertexArraySet.EnableAttributes(index, attributeIndices);
}
/// <summary>
/// Disables the vertex array object's definitions at the given attribute indices.
/// </summary>
/// <param name="attributeIndices">The attribute indices to be disabled.</param>
public void DisableAttributes(params uint[] attributeIndices) {
glVertexArraySet.DisableAttributes(index, attributeIndices);
}
public void Use() {
glVertexArraySet.Use(index);
}
public void Dispose()
{
this.glVertexArraySet.Dispose();
}
}
}

View File

@ -1,81 +0,0 @@
using System;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.Textures;
namespace SlatedGameToolkit.Framework.Graphics
{
public sealed class GLTexture2DSet : IDisposable
{
private bool disposed;
public int Count { get; private set; }
private GLGenTextures genTextures;
private GLTexParameteri texParameteri;
private GLTexParameterfv texParameterfv;
private GLDeleteTextures deleteTextures;
private GLTexImage2D texImage2D;
private GLBindTexture bindTexture;
private GLGenerateMipmap generateMipmap;
private readonly UIntPtr[] handle;
public GLTexture2DSet(TextureData[] textureDatas, bool linear = false, bool mipmap = false)
{
genTextures = OpenGL.RetrieveGLDelegate<GLGenTextures>("glGenTextures");
deleteTextures = OpenGL.RetrieveGLDelegate<GLDeleteTextures>("glDeleteTextures");
bindTexture = OpenGL.RetrieveGLDelegate<GLBindTexture>("glBindTexture");
texParameteri = OpenGL.RetrieveGLDelegate<GLTexParameteri>("glTexParameteri");
texParameterfv = OpenGL.RetrieveGLDelegate<GLTexParameterfv>("glTexParameterfv");
texImage2D = OpenGL.RetrieveGLDelegate<GLTexImage2D>("glTexImage2D");
generateMipmap = OpenGL.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]);
}
bindTexture(GLEnum.GL_TEXTURE_2D, UIntPtr.Zero);
OpenGLErrorException.CheckGLErrorStatus();
this.Count = textureDatas.Length;
}
private void Setup(uint index, TextureData textureData) {
Bind(index);
texImage2D(GLEnum.GL_TEXTURE_2D, 0, (int)GLEnum.GL_RGBA, textureData.width, textureData.height, 0, GLEnum.GL_RGBA, GLEnum.GL_UNSIGNED_BYTE, textureData.data);
OpenGLErrorException.CheckGLErrorStatus();
generateMipmap(GLEnum.GL_TEXTURE_2D);
OpenGLErrorException.CheckGLErrorStatus();
}
/// <summary>
/// Binds the given index's texture.
/// Sets the properties given the index of the OpenGL 2D texture.
/// </summary>
/// <param name="index">The index of the texture.</param>
/// <param name="linear">Whether or not to have linear filtering.</param>
/// <param name="mipmap">Whether or not to use MipMap</param>
public void SetProperties(uint index, GLEnum min, GLEnum mag) {
Bind(index);
texParameteri(GLEnum.GL_TEXTURE_2D, GLEnum.GL_TEXTURE_WRAP_S, (int)GLEnum.GL_CLAMP_TO_EDGE);
texParameteri(GLEnum.GL_TEXTURE_2D, GLEnum.GL_TEXTURE_WRAP_T, (int)GLEnum.GL_CLAMP_TO_EDGE);
texParameteri(GLEnum.GL_TEXTURE_2D, GLEnum.GL_TEXTURE_MIN_FILTER, (int) min);
texParameteri(GLEnum.GL_TEXTURE_2D, GLEnum.GL_TEXTURE_MAG_FILTER, (int) mag);
}
/// <summary>
/// Binds a GL texture to the active unit.
/// </summary>
/// <param name="index">The index of the texture in this set.</param>
public void Bind(uint index) {
bindTexture(GLEnum.GL_TEXTURE_2D, handle[index]);
OpenGLErrorException.CheckGLErrorStatus();
}
public void Dispose()
{
if (disposed) return;
this.disposed = true;
deleteTextures((uint)handle.Length, handle);
OpenGLErrorException.CheckGLErrorStatus();
GC.SuppressFinalize(this);
}
}
}

View File

@ -1,32 +1,54 @@
using SlatedGameToolkit.Framework.Exceptions; using System;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Window;
using SlatedGameToolkit.Framework.Loader; using SlatedGameToolkit.Framework.Loader;
namespace SlatedGameToolkit.Framework.Graphics.Textures namespace SlatedGameToolkit.Framework.Graphics.Textures
{ {
public class Texture : IAssetUseable public class Texture : IAssetUseable {
{ public readonly int width, height;
private readonly GLTexture2DSet glTexture2DSet; private bool disposed;
private readonly uint index; private GLContext glContext;
private uint handle;
public Texture(GLTexture2DSet set, uint index) { /// <summary>
this.glTexture2DSet = set; /// Creates an OpenGL Texture2D in the given GL Context.
this.index = index; /// </summary>
} /// <param name="textureData">The texture data to use to create the Texture2D.</param>
/// <param name="context">The openGL context to associate this with. If null, will use the currently active context. Defaults to null.</param>
public Texture(TextureData textureData, bool linear = true, bool mipmap = true) { public unsafe Texture(TextureData textureData, GLContext context = null) {
TextureData[] textureDatas = new TextureData[] {textureData}; this.glContext = context ?? WindowContextsManager.CurrentGL;
this.glTexture2DSet = new GLTexture2DSet(textureDatas, linear, mipmap); this.width = textureData.width;
OpenGLErrorException.CheckGLErrorStatus(); this.height = textureData.height;
this.index = 0; uint[] handles = new uint[1];
glContext.GenTextures(1, handles);
this.handle = handles[0];
Use();
glContext.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
glContext.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
glContext.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
glContext.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
fixed(void* p = &textureData.data[0]) {
glContext.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat.Rgba, (uint)textureData.width, (uint)textureData.height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, new IntPtr(p));
}
glContext.GenerateMipmap(OpenGL.TextureTarget.Texture2D);
} }
public void Use() { public void Use() {
this.glTexture2DSet.Bind(index); if (disposed) throw new ObjectDisposedException("Texture");
glContext.BindTexture(OpenGL.TextureTarget.Texture2D, handle);
} }
public void Dispose() public void Dispose()
{ {
this.glTexture2DSet.Dispose(); if (disposed) return;
disposed = true;
glContext.DeleteTextures(1, new uint[] {handle});
GC.SuppressFinalize(this);
}
~Texture() {
Dispose();
} }
} }
} }

View File

@ -4,8 +4,14 @@ namespace SlatedGameToolkit.Framework.Graphics.Textures
{ {
public class TextureData public class TextureData
{ {
public byte[] data; public readonly byte[] data;
public uint width; public readonly int width;
public uint height; public readonly int height;
public TextureData(int width, int height, byte[] data) {
this.data = data;
this.width = width;
this.height = height;
}
} }
} }

View File

@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
using SDL2; using SDL2;
using SlatedGameToolkit.Framework.Exceptions; using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics; using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
namespace SlatedGameToolkit.Framework.Graphics.Window namespace SlatedGameToolkit.Framework.Graphics.Window
{ {
@ -34,6 +35,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
/// </summary> /// </summary>
public sealed class WindowContext : IDisposable public sealed class WindowContext : IDisposable
{ {
public GLContext Context { get; private set; }
/// <summary> /// <summary>
/// The pointer referencing the SDL window. /// The pointer referencing the SDL window.
/// </summary> /// </summary>
@ -42,7 +44,6 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
/// <summary> /// <summary>
/// The pointer referencing the OpenGL context. /// The pointer referencing the OpenGL context.
/// </summary> /// </summary>
private readonly IntPtr glContextHandle;
public event WindowOperation focusGainedEvent, focusLostEvent; public event WindowOperation focusGainedEvent, focusLostEvent;
/// <summary> /// <summary>
@ -55,12 +56,6 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
/// </summary> /// </summary>
public event WindowRegionHit windowRegionHitEvent; public event WindowRegionHit windowRegionHitEvent;
internal readonly GLClearColour clearColour;
internal readonly GLClear clear;
internal readonly GLViewport viewport;
private readonly GLGetError getError;
/// <summary> /// <summary>
/// Whether or not to show this window. /// Whether or not to show this window.
/// </summary> /// </summary>
@ -258,7 +253,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
} }
/// <summary> /// <summary>
/// Instantiates a window handle. /// Instantiates a window with the given OpenGL context, or a new context.
/// </summary> /// </summary>
public WindowContext(string title, int x = -1, int y = -1, int width = 640, int height = 480, bool specialRegions = false, SDL.SDL_WindowFlags options = default(SDL.SDL_WindowFlags)) { public WindowContext(string title, int x = -1, int y = -1, int width = 640, int height = 480, bool specialRegions = false, SDL.SDL_WindowFlags options = default(SDL.SDL_WindowFlags)) {
GameEngine.Logger.Information(String.Format("Starting openGL window with title \"{0}\"", title)); GameEngine.Logger.Information(String.Format("Starting openGL window with title \"{0}\"", title));
@ -266,15 +261,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
if (windowHandle == null) { if (windowHandle == null) {
throw new FrameworkSDLException(); throw new FrameworkSDLException();
} }
glContextHandle = SDL.SDL_GL_CreateContext(windowHandle); this.Context = new GLContext(windowHandle);
if (glContextHandle == null) {
throw new FrameworkSDLException();
}
clear = OpenGL.RetrieveGLDelegate<GLClear>("glClear");
clearColour = OpenGL.RetrieveGLDelegate<GLClearColour>("glClearColor");
viewport = OpenGL.RetrieveGLDelegate<GLViewport>("glViewport");
getError = OpenGL.RetrieveGLDelegate<GLGetError>("glGetError");
if (specialRegions) { if (specialRegions) {
if (SDL.SDL_SetWindowHitTest(windowHandle, SpecialRegionHit, IntPtr.Zero) < 0) { if (SDL.SDL_SetWindowHitTest(windowHandle, SpecialRegionHit, IntPtr.Zero) < 0) {
@ -286,7 +273,9 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
MakeCurrent(); MakeCurrent();
Vector2 drawable = GetDrawableDimensions(); Vector2 drawable = GetDrawableDimensions();
viewport(0, 0, (int)drawable.X, (int)drawable.Y); this.Context.Viewport(0, 0, (int)drawable.X, (int)drawable.Y);
this.Context.Enable(EnableCap.Blend);
Context.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
} }
private SDL.SDL_HitTestResult SpecialRegionHit(IntPtr window, IntPtr hitPtr, IntPtr data) { private SDL.SDL_HitTestResult SpecialRegionHit(IntPtr window, IntPtr hitPtr, IntPtr data) {
@ -313,14 +302,6 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
focusGainedEvent?.Invoke(); focusGainedEvent?.Invoke();
} }
/// <summary>
/// Gets the current GL error code.
/// </summary>
/// <returns>The unsigned int representing the status of OpenGL.</returns>
public uint GetGLStatus() {
return getError();
}
/// <summary> /// <summary>
/// Gets the current drawable area of the window. /// Gets the current drawable area of the window.
/// </summary> /// </summary>
@ -337,7 +318,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
/// </summary> /// </summary>
public void MakeCurrent() { public void MakeCurrent() {
if (WindowContextsManager.CurrentWindowContext != this) { if (WindowContextsManager.CurrentWindowContext != this) {
SDL.SDL_GL_MakeCurrent(windowHandle, glContextHandle); SDL.SDL_GL_MakeCurrent(windowHandle, Context.Handle);
WindowContextsManager.current = this; WindowContextsManager.current = this;
} }
} }
@ -365,13 +346,21 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose(bool disposing) {
if (disposing)
{
}
WindowContextsManager.DeregisterWindow(this); WindowContextsManager.DeregisterWindow(this);
SDL.SDL_GL_DeleteContext(glContextHandle);
SDL.SDL_DestroyWindow(windowHandle); SDL.SDL_DestroyWindow(windowHandle);
Context.Dispose();
} }
~WindowContext() { ~WindowContext() {
Dispose(); Dispose(false);
} }
} }
} }

View File

@ -1,4 +1,7 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
namespace SlatedGameToolkit.Framework.Graphics.Window namespace SlatedGameToolkit.Framework.Graphics.Window
{ {
@ -16,6 +19,25 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
} }
private static Dictionary<uint, WindowContext> existingWindows = new Dictionary<uint, WindowContext>(); private static Dictionary<uint, WindowContext> existingWindows = new Dictionary<uint, WindowContext>();
/// <summary>
/// The currently loaded windows.
/// </summary>
/// <typeparam name="uint">The ID of the window.</typeparam>
/// <typeparam name="WindowContext">The window context.</typeparam>
/// <returns>A readonly dictionary of all the window contexts that were created.</returns>
public static ReadOnlyDictionary<uint, WindowContext> LoadedWindows { get; private set; } = new ReadOnlyDictionary<uint, WindowContext>(existingWindows);
/// <summary>
/// The OpenGL context of the active window.
/// Equivalent to retrieving the current window context, and then using the context from that instance.
/// </summary>
/// <value>The currently active window's OpenGL context.</value>
public static GLContext CurrentGL {
get {
return CurrentWindowContext.Context;
}
}
internal static void RegisterWindow(WindowContext windowHandle) { internal static void RegisterWindow(WindowContext windowHandle) {
GameEngine.Logger.Debug("Registering window: " + windowHandle.WindowID); GameEngine.Logger.Debug("Registering window: " + windowHandle.WindowID);
existingWindows.Add(windowHandle.WindowID, windowHandle); existingWindows.Add(windowHandle.WindowID, windowHandle);
@ -29,5 +51,16 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
public static WindowContext ContextFromWindowID(uint ID) { public static WindowContext ContextFromWindowID(uint ID) {
return existingWindows[ID]; return existingWindows[ID];
} }
/// <summary>
/// Disposes all the created window contexts.
/// This includes their OpenGL contexts.
/// </summary>
public static void DisposeAllWindowContexts() {
foreach (WindowContext context in LoadedWindows.Values)
{
context.Dispose();
}
}
} }
} }

View File

@ -1,25 +1,26 @@
using System.Collections.Generic; using System.Collections.Generic;
using SDL2;
namespace SlatedGameToolkit.Framework.Input.Devices namespace SlatedGameToolkit.Framework.Input.Devices
{ {
public delegate void keyboardUpdate(Key keys, bool pressed); public delegate void keyboardUpdate(SDL.SDL_Keycode keys, bool pressed);
public static class Keyboard { public static class Keyboard {
private static HashSet<Key> pressedKeys = new HashSet<Key>(); private static HashSet<SDL.SDL_Keycode> pressedKeys = new HashSet<SDL.SDL_Keycode>();
/// <summary> /// <summary>
/// Whenever a keyboard update occurs. /// Whenever a keyboard update occurs.
/// </summary> /// </summary>
public static event keyboardUpdate keyboardUpdateEvent; public static event keyboardUpdate keyboardUpdateEvent;
public static bool IsKeyPressed(Key key) { public static bool IsKeyPressed(SDL.SDL_Keycode key) {
return pressedKeys.Contains(key); return pressedKeys.Contains(key);
} }
internal static void OnKeyPressed(Key key) { internal static void OnKeyPressed(SDL.SDL_Keycode key) {
pressedKeys.Add(key); pressedKeys.Add(key);
keyboardUpdateEvent?.Invoke(key, true); keyboardUpdateEvent?.Invoke(key, true);
} }
internal static void OnKeyReleased(Key key) { internal static void OnKeyReleased(SDL.SDL_Keycode key) {
pressedKeys.Remove(key); pressedKeys.Remove(key);
keyboardUpdateEvent?.Invoke(key, false); keyboardUpdateEvent?.Invoke(key, false);
} }

View File

@ -1,262 +0,0 @@
using SDL2;
namespace SlatedGameToolkit.Framework.Input
{
public enum Key
{
K_RETURN = SDL.SDL_Keycode.SDLK_RETURN,
K_ESCAPE = SDL.SDL_Keycode.SDLK_ESCAPE, // '\033'
K_BACKSPACE = SDL.SDL_Keycode.SDLK_BACKSPACE,
K_TAB = SDL.SDL_Keycode.SDLK_TAB,
K_SPACE = SDL.SDL_Keycode.SDLK_SPACE,
K_EXCLAIM = SDL.SDL_Keycode.SDLK_EXCLAIM,
K_QUOTEDBL = SDL.SDL_Keycode.SDLK_QUOTEDBL,
K_HASH = SDL.SDL_Keycode.SDLK_HASH,
K_PERCENT = SDL.SDL_Keycode.SDLK_PERCENT,
K_DOLLAR = SDL.SDL_Keycode.SDLK_DOLLAR,
K_AMPERSAND = SDL.SDL_Keycode.SDLK_AMPERSAND,
K_QUOTE = SDL.SDL_Keycode.SDLK_QUOTE,
K_LEFTPAREN = SDL.SDL_Keycode.SDLK_KP_LEFTPAREN,
K_RIGHTPAREN = SDL.SDL_Keycode.SDLK_RIGHTPAREN,
K_ASTERISK = SDL.SDL_Keycode.SDLK_ASTERISK,
K_PLUS = SDL.SDL_Keycode.SDLK_PLUS,
K_COMMA = SDL.SDL_Keycode.SDLK_COMMA,
K_MINUS = SDL.SDL_Keycode.SDLK_MINUS,
K_PERIOD = SDL.SDL_Keycode.SDLK_PERIOD,
K_SLASH = SDL.SDL_Keycode.SDLK_SLASH,
K_0 = SDL.SDL_Keycode.SDLK_0,
K_1 = SDL.SDL_Keycode.SDLK_1,
K_2 = SDL.SDL_Keycode.SDLK_2,
K_3 = SDL.SDL_Keycode.SDLK_3,
K_4 = SDL.SDL_Keycode.SDLK_4,
K_5 = SDL.SDL_Keycode.SDLK_5,
K_6 = SDL.SDL_Keycode.SDLK_6,
K_7 = SDL.SDL_Keycode.SDLK_7,
K_8 = SDL.SDL_Keycode.SDLK_8,
K_9 = SDL.SDL_Keycode.SDLK_9,
K_COLON = SDL.SDL_Keycode.SDLK_COLON,
K_SEMICOLON = SDL.SDL_Keycode.SDLK_SEMICOLON,
K_LESS = SDL.SDL_Keycode.SDLK_LESS,
K_EQUALS = SDL.SDL_Keycode.SDLK_EQUALS,
K_GREATER = SDL.SDL_Keycode.SDLK_GREATER,
K_QUESTION = SDL.SDL_Keycode.SDLK_QUESTION,
K_AT = SDL.SDL_Keycode.SDLK_AT,
/*
Skip uppercase letters
*/
K_LEFTBRACKET = SDL.SDL_Keycode.SDLK_LEFTBRACKET,
K_BACKSLASH = SDL.SDL_Keycode.SDLK_BACKSLASH,
K_RIGHTBRACKET = SDL.SDL_Keycode.SDLK_RIGHTBRACKET,
K_CARET = SDL.SDL_Keycode.SDLK_CARET,
K_UNDERSCORE = SDL.SDL_Keycode.SDLK_UNDERSCORE,
K_BACKQUOTE = SDL.SDL_Keycode.SDLK_BACKQUOTE,
K_a = SDL.SDL_Keycode.SDLK_a,
K_b = SDL.SDL_Keycode.SDLK_b,
K_c = SDL.SDL_Keycode.SDLK_c,
K_d = SDL.SDL_Keycode.SDLK_d,
K_e = SDL.SDL_Keycode.SDLK_e,
K_f = SDL.SDL_Keycode.SDLK_f,
K_g = SDL.SDL_Keycode.SDLK_g,
K_h = SDL.SDL_Keycode.SDLK_h,
K_i = SDL.SDL_Keycode.SDLK_i,
K_j = SDL.SDL_Keycode.SDLK_j,
K_k = SDL.SDL_Keycode.SDLK_k,
K_l = SDL.SDL_Keycode.SDLK_l,
K_m = SDL.SDL_Keycode.SDLK_m,
K_n = SDL.SDL_Keycode.SDLK_n,
K_o = SDL.SDL_Keycode.SDLK_o,
K_p = SDL.SDL_Keycode.SDLK_p,
K_q = SDL.SDL_Keycode.SDLK_q,
K_r = SDL.SDL_Keycode.SDLK_r,
K_s = SDL.SDL_Keycode.SDLK_s,
K_t = SDL.SDL_Keycode.SDLK_t,
K_u = SDL.SDL_Keycode.SDLK_u,
K_v = SDL.SDL_Keycode.SDLK_v,
K_w = SDL.SDL_Keycode.SDLK_w,
K_x = SDL.SDL_Keycode.SDLK_x,
K_y = SDL.SDL_Keycode.SDLK_y,
K_z = SDL.SDL_Keycode.SDLK_z,
K_CAPSLOCK = SDL.SDL_Keycode.SDLK_CAPSLOCK,
K_F1 = SDL.SDL_Keycode.SDLK_F1,
K_F2 = SDL.SDL_Keycode.SDLK_F2,
K_F3 = SDL.SDL_Keycode.SDLK_F3,
K_F4 = SDL.SDL_Keycode.SDLK_F4,
K_F5 = SDL.SDL_Keycode.SDLK_F5,
K_F6 = SDL.SDL_Keycode.SDLK_F6,
K_F7 = SDL.SDL_Keycode.SDLK_F7,
K_F8 = SDL.SDL_Keycode.SDLK_F8,
K_F9 = SDL.SDL_Keycode.SDLK_F9,
K_F10 = SDL.SDL_Keycode.SDLK_F10,
K_F11 = SDL.SDL_Keycode.SDLK_F11,
K_F12 = SDL.SDL_Keycode.SDLK_F12,
K_PRINTSCREEN = SDL.SDL_Keycode.SDLK_PRINTSCREEN,
K_SCROLLLOCK = SDL.SDL_Keycode.SDLK_SCROLLLOCK,
K_PAUSE = SDL.SDL_Keycode.SDLK_PAUSE,
K_INSERT = SDL.SDL_Keycode.SDLK_INSERT,
K_HOME = SDL.SDL_Keycode.SDLK_HOME,
K_PAGEUP = SDL.SDL_Keycode.SDLK_PAGEUP,
K_DELETE = SDL.SDL_Keycode.SDLK_DELETE,
K_END = SDL.SDL_Keycode.SDLK_END,
K_PAGEDOWN = SDL.SDL_Keycode.SDLK_PAGEDOWN,
K_RIGHT = SDL.SDL_Keycode.SDLK_RIGHT,
K_LEFT = SDL.SDL_Keycode.SDLK_LEFT,
K_DOWN = SDL.SDL_Keycode.SDLK_DOWN,
K_UP = SDL.SDL_Keycode.SDLK_UP,
K_NUMLOCKCLEAR = SDL.SDL_Keycode.SDLK_NUMLOCKCLEAR,
K_KP_DIVIDE = SDL.SDL_Keycode.SDLK_KP_DIVIDE,
K_KP_MULTIPLY = SDL.SDL_Keycode.SDLK_KP_MULTIPLY,
K_KP_MINUS = SDL.SDL_Keycode.SDLK_MINUS,
K_KP_PLUS = SDL.SDL_Keycode.SDLK_KP_PLUS,
K_KP_ENTER = SDL.SDL_Keycode.SDLK_KP_ENTER,
K_KP_1 = SDL.SDL_Keycode.SDLK_KP_1,
K_KP_2 = SDL.SDL_Keycode.SDLK_KP_2,
K_KP_3 = SDL.SDL_Keycode.SDLK_KP_3,
K_KP_4 = SDL.SDL_Keycode.SDLK_KP_4,
K_KP_5 = SDL.SDL_Keycode.SDLK_KP_5,
K_KP_6 = SDL.SDL_Keycode.SDLK_KP_6,
K_KP_7 = SDL.SDL_Keycode.SDLK_KP_7,
K_KP_8 = SDL.SDL_Keycode.SDLK_KP_8,
K_KP_9 = SDL.SDL_Keycode.SDLK_KP_9,
K_KP_0 = SDL.SDL_Keycode.SDLK_KP_0,
K_KP_PERIOD = SDL.SDL_Keycode.SDLK_KP_0,
K_APPLICATION = SDL.SDL_Keycode.SDLK_APPLICATION,
K_POWER = SDL.SDL_Keycode.SDLK_POWER,
K_KP_EQUALS = SDL.SDL_Keycode.SDLK_EQUALS,
K_F13 = SDL.SDL_Keycode.SDLK_F13,
K_F14 = SDL.SDL_Keycode.SDLK_F14,
K_F15 = SDL.SDL_Keycode.SDLK_F15,
K_F16 = SDL.SDL_Keycode.SDLK_F16,
K_F17 = SDL.SDL_Keycode.SDLK_F17,
K_F18 = SDL.SDL_Keycode.SDLK_F18,
K_F19 = SDL.SDL_Keycode.SDLK_F19,
K_F20 = SDL.SDL_Keycode.SDLK_F20,
K_F21 = SDL.SDL_Keycode.SDLK_F21,
K_F22 = SDL.SDL_Keycode.SDLK_F22,
K_F23 = SDL.SDL_Keycode.SDLK_F23,
K_F24 = SDL.SDL_Keycode.SDLK_F24,
K_EXECUTE = SDL.SDL_Keycode.SDLK_EXECUTE,
K_HELP = SDL.SDL_Keycode.SDLK_HELP,
K_MENU = SDL.SDL_Keycode.SDLK_MENU,
K_SELECT = SDL.SDL_Keycode.SDLK_SELECT,
K_STOP = SDL.SDL_Keycode.SDLK_STOP,
K_AGAIN = SDL.SDL_Keycode.SDLK_AGAIN,
K_UNDO = SDL.SDL_Keycode.SDLK_UNDO,
K_CUT = SDL.SDL_Keycode.SDLK_CUT,
K_COPY = SDL.SDL_Keycode.SDLK_COPY,
K_PASTE = SDL.SDL_Keycode.SDLK_PASTE,
K_FIND = SDL.SDL_Keycode.SDLK_FIND,
K_MUTE = SDL.SDL_Keycode.SDLK_MUTE,
K_VOLUMEUP = SDL.SDL_Keycode.SDLK_VOLUMEUP,
K_VOLUMEDOWN = SDL.SDL_Keycode.SDLK_VOLUMEDOWN,
K_KP_COMMA = SDL.SDL_Keycode.SDLK_COMMA,
K_KP_EQUALSAS400 = SDL.SDL_Keycode.SDLK_KP_EQUALSAS400,
K_ALTERASE = SDL.SDL_Keycode.SDLK_ALTERASE,
K_SYSREQ = SDL.SDL_Keycode.SDLK_SYSREQ,
K_CANCEL = SDL.SDL_Keycode.SDLK_CANCEL,
K_CLEAR = SDL.SDL_Keycode.SDLK_CLEAR,
K_PRIOR = SDL.SDL_Keycode.SDLK_PRIOR,
K_RETURN2 = SDL.SDL_Keycode.SDLK_RETURN2,
K_SEPARATOR = SDL.SDL_Keycode.SDLK_SEPARATOR,
K_OUT = SDL.SDL_Keycode.SDLK_OUT,
K_OPER = SDL.SDL_Keycode.SDLK_OPER,
K_CLEARAGAIN = SDL.SDL_Keycode.SDLK_CLEARAGAIN,
K_CRSEL = SDL.SDL_Keycode.SDLK_CRSEL,
K_EXSEL = SDL.SDL_Keycode.SDLK_EXSEL,
K_KP_00 = SDL.SDL_Keycode.SDLK_KP_00,
K_KP_000 = SDL.SDL_Keycode.SDLK_KP_000,
K_THOUSANDSSEPARATOR = SDL.SDL_Keycode.SDLK_THOUSANDSSEPARATOR,
K_DECIMALSEPARATOR = SDL.SDL_Keycode.SDLK_DECIMALSEPARATOR,
K_CURRENCYUNIT = SDL.SDL_Keycode.SDLK_CURRENCYUNIT,
K_CURRENCYSUBUNIT = SDL.SDL_Keycode.SDLK_CURRENCYSUBUNIT,
K_KP_LEFTPAREN = SDL.SDL_Keycode.SDLK_LEFTPAREN,
K_KP_RIGHTPAREN = SDL.SDL_Keycode.SDLK_KP_RIGHTPAREN,
K_KP_LEFTBRACE = SDL.SDL_Keycode.SDLK_KP_LEFTBRACE,
K_KP_RIGHTBRACE = SDL.SDL_Keycode.SDLK_KP_RIGHTBRACE,
K_KP_TAB = SDL.SDL_Keycode.SDLK_KP_TAB,
K_KP_BACKSPACE = SDL.SDL_Keycode.SDLK_BACKSPACE,
K_KP_A = SDL.SDL_Keycode.SDLK_KP_A,
K_KP_B = SDL.SDL_Keycode.SDLK_KP_B,
K_KP_C = SDL.SDL_Keycode.SDLK_KP_C,
K_KP_D = SDL.SDL_Keycode.SDLK_KP_D,
K_KP_E = SDL.SDL_Keycode.SDLK_KP_E,
K_KP_F = SDL.SDL_Keycode.SDLK_KP_F,
K_KP_XOR = SDL.SDL_Keycode.SDLK_KP_XOR,
K_KP_POWER = SDL.SDL_Keycode.SDLK_KP_POWER,
K_KP_PERCENT = SDL.SDL_Keycode.SDLK_KP_PERCENT,
K_KP_LESS = SDL.SDL_Keycode.SDLK_KP_LESS,
K_KP_GREATER = SDL.SDL_Keycode.SDLK_KP_GREATER,
K_KP_AMPERSAND = SDL.SDL_Keycode.SDLK_KP_AMPERSAND,
K_KP_DBLAMPERSAND = SDL.SDL_Keycode.SDLK_KP_DBLAMPERSAND,
K_KP_VERTICALBAR = SDL.SDL_Keycode.SDLK_KP_VERTICALBAR,
K_KP_DBLVERTICALBAR = SDL.SDL_Keycode.SDLK_KP_DBLVERTICALBAR,
K_KP_COLON = SDL.SDL_Keycode.SDLK_KP_COLON,
K_KP_HASH = SDL.SDL_Keycode.SDLK_KP_HASH,
K_KP_SPACE = SDL.SDL_Keycode.SDLK_KP_SPACE,
K_KP_AT = SDL.SDL_Keycode.SDLK_KP_AT,
K_KP_EXCLAM = SDL.SDL_Keycode.SDLK_KP_EXCLAM,
K_KP_MEMSTORE = SDL.SDL_Keycode.SDLK_KP_MEMSTORE,
K_KP_MEMRECALL = SDL.SDL_Keycode.SDLK_KP_MEMRECALL,
K_KP_MEMCLEAR = SDL.SDL_Keycode.SDLK_KP_MEMCLEAR,
K_KP_MEMADD = SDL.SDL_Keycode.SDLK_KP_MEMADD,
K_KP_MEMSUBTRACT = SDL.SDL_Keycode.SDLK_KP_MEMSUBTRACT,
K_KP_MEMMULTIPLY = SDL.SDL_Keycode.SDLK_KP_MEMMULTIPLY,
K_KP_MEMDIVIDE = SDL.SDL_Keycode.SDLK_KP_MEMDIVIDE,
K_KP_PLUSMINUS = SDL.SDL_Keycode.SDLK_KP_PLUSMINUS,
K_KP_CLEAR = SDL.SDL_Keycode.SDLK_KP_CLEAR,
K_KP_CLEARENTRY = SDL.SDL_Keycode.SDLK_KP_CLEARENTRY,
K_KP_BINARY = SDL.SDL_Keycode.SDLK_KP_BINARY,
K_KP_OCTAL = SDL.SDL_Keycode.SDLK_KP_OCTAL,
K_KP_DECIMAL = SDL.SDL_Keycode.SDLK_KP_DECIMAL,
K_KP_HEXADECIMAL = SDL.SDL_Keycode.SDLK_KP_HEXADECIMAL,
K_LCTRL = SDL.SDL_Keycode.SDLK_LCTRL,
K_LSHIFT = SDL.SDL_Keycode.SDLK_LSHIFT,
K_LALT = SDL.SDL_Keycode.SDLK_LALT,
K_LGUI = SDL.SDL_Keycode.SDLK_LGUI,
K_RCTRL = SDL.SDL_Keycode.SDLK_RCTRL,
K_RSHIFT = SDL.SDL_Keycode.SDLK_RSHIFT,
K_RALT = SDL.SDL_Keycode.SDLK_RALT,
K_RGUI = SDL.SDL_Keycode.SDLK_RGUI,
K_MODE = SDL.SDL_Keycode.SDLK_MODE,
K_AUDIONEXT = SDL.SDL_Keycode.SDLK_AUDIONEXT,
K_AUDIOPREV = SDL.SDL_Keycode.SDLK_AUDIOPREV,
K_AUDIOSTOP = SDL.SDL_Keycode.SDLK_AUDIOSTOP,
K_AUDIOPLAY = SDL.SDL_Keycode.SDLK_AUDIOPLAY,
K_AUDIOMUTE = SDL.SDL_Keycode.SDLK_AUDIOMUTE,
K_MEDIASELECT = SDL.SDL_Keycode.SDLK_MEDIASELECT,
K_WWW = SDL.SDL_Keycode.SDLK_WWW,
K_MAIL = SDL.SDL_Keycode.SDLK_MAIL,
K_CALCULATOR = SDL.SDL_Keycode.SDLK_CALCULATOR,
K_COMPUTER = SDL.SDL_Keycode.SDLK_COMPUTER,
K_AC_SEARCH = SDL.SDL_Keycode.SDLK_AC_SEARCH,
K_AC_HOME = SDL.SDL_Keycode.SDLK_AC_HOME,
K_AC_BACK = SDL.SDL_Keycode.SDLK_AC_BACK,
K_AC_FORWARD = SDL.SDL_Keycode.SDLK_AC_FORWARD,
K_AC_STOP = SDL.SDL_Keycode.SDLK_AC_STOP,
K_AC_REFRESH = SDL.SDL_Keycode.SDLK_AC_REFRESH,
K_AC_BOOKMARKS = SDL.SDL_Keycode.SDLK_AC_BOOKMARKS,
K_BRIGHTNESSDOWN = SDL.SDL_Keycode.SDLK_BRIGHTNESSDOWN,
K_BRIGHTNESSUP = SDL.SDL_Keycode.SDLK_BRIGHTNESSUP,
K_DISPLAYSWITCH = SDL.SDL_Keycode.SDLK_DISPLAYSWITCH,
K_KBDILLUMTOGGLE = SDL.SDL_Keycode.SDLK_KBDILLUMTOGGLE,
K_KBDILLUMDOWN = SDL.SDL_Keycode.SDLK_KBDILLUMDOWN,
K_KBDILLUMUP = SDL.SDL_Keycode.SDLK_KBDILLUMUP,
K_EJECT = SDL.SDL_Keycode.SDLK_EJECT,
K_SLEEP = SDL.SDL_Keycode.SDLK_SLEEP,
K_APP1 = SDL.SDL_Keycode.SDLK_APP1,
K_APP2 = SDL.SDL_Keycode.SDLK_APP2,
K_AUDIOREWIND = SDL.SDL_Keycode.SDLK_AUDIOREWIND,
K_AUDIOFASTFORWARD = SDL.SDL_Keycode.SDLK_AUDIOFASTFORWARD
}
}

View File

@ -1,13 +1,31 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Threading; using System.Threading;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Window;
namespace SlatedGameToolkit.Framework.Loader { namespace SlatedGameToolkit.Framework.Loader {
public class AssetManager : IDisposable { /// <summary>
/// A delegate that should modify a given path.
/// </summary>
/// <param name="path">A path to modify.</param>
/// <returns>The modified path.</returns>
public delegate string ModifyPath(string path);
/// <summary>
/// A delegate that performs the loading of the specific asset.
/// </summary>
/// <param name="path">The path of the asset.</param>
/// <param name="glContext">The context to be used. May be null if called by user.</param>
/// <typeparam name="T">The type of the resulting asset.</typeparam>
/// <returns>A loaded, useable asset.</returns>
public delegate T LoadAsset<T>(string path, GLContext glContext) where T : IAssetUseable;
public class AssetManager {
private readonly object assetThreadLock = new object(); private readonly object assetThreadLock = new object();
private Thread thread; private Thread thread;
private ConcurrentQueue<ILoadable<IAssetUseable>> loadables; private ConcurrentQueue<(string, GLContext)> loadables;
private volatile bool load; private volatile bool load;
public bool Complete { public bool Complete {
get { get {
@ -15,36 +33,58 @@ namespace SlatedGameToolkit.Framework.Loader {
} }
} }
private ConcurrentDictionary<string, IAssetUseable> assets; private ConcurrentDictionary<string, IAssetUseable> assets;
public ConcurrentDictionary<Type, PathModifier> PathModifiers {get; private set; }
/// <summary>
/// A concurrent dictionary containing all the path modifier's in association with their extension.
/// This is what the manager uses to determine how to modify a filename or path dependent on it's extension.
/// </summary>
/// <value>A dictionary of file extension associated with respective paths.</value>
public ConcurrentDictionary<string, ModifyPath> PathModifiers { get; private set; }
/// <summary>
/// A dictionary containing associations between file extensions and their loaders.
/// All file extensions will be requested in lower cases, and therefore, the extension key in this dictionary should also be all lowercase.
/// </summary>
/// <value>The dictionary that associates the loaders to their file extensions.</value>
public ConcurrentDictionary<string, LoadAsset<IAssetUseable>> Loaders { get ; private set; }
public AssetManager() { public AssetManager() {
this.loadables = new ConcurrentQueue<ILoadable<IAssetUseable>>(); this.loadables = new ConcurrentQueue<(string, GLContext)>();
this.assets = new ConcurrentDictionary<string, IAssetUseable>(); this.assets = new ConcurrentDictionary<string, IAssetUseable>();
this.PathModifiers = new ConcurrentDictionary<Type, PathModifier>(); this.PathModifiers = new ConcurrentDictionary<string, ModifyPath>();
thread = new Thread(Process); this.Loaders = new ConcurrentDictionary<string, LoadAsset<IAssetUseable>>();
thread = new Thread(Run);
this.load = true; this.load = true;
thread.Name = "Asset-Loader"; thread.Name = "Asset-Loader";
thread.IsBackground = true; thread.IsBackground = true;
thread.Start(); thread.Start();
RegisterCommonLoaders();
}
private void RegisterCommonLoaders() {
Loaders["png"] = CommonLoaders.LoadTexture;
} }
/// <summary> /// <summary>
/// Queue's the loadable for batched loading. /// Queue's the loadable for batched loading.
/// The file name of the loadable is the one the loadable is saved under. /// The file name of the loadable is the one the loadable is saved under.
/// </summary> /// </summary>
/// <param name="loadable">The loadable.</param> /// <param name="name">path of file.</param>
public void QueueLoad(ILoadable<IAssetUseable> loadable) { public void QueueLoad(string name, GLContext glContext = null) {
loadables.Enqueue(loadable); if (glContext == null) glContext = WindowContextsManager.CurrentGL;
loadables.Enqueue((name, glContext));
} }
private void Process() { private void Run() {
lock (assetThreadLock) while (load) {
{ lock (assetThreadLock)
ILoadable<IAssetUseable> loadable; {
while (load) { ValueTuple<string, GLContext> loadable;
while (loadables.TryDequeue(out loadable)) { while (loadables.TryDequeue(out loadable)) {
Load(loadable); Load(loadable.Item1, loadable.Item2);
} }
Monitor.Pulse(loadable); if (load) Monitor.Wait(assetThreadLock);
} }
} }
} }
@ -52,10 +92,16 @@ namespace SlatedGameToolkit.Framework.Loader {
/// <summary> /// <summary>
/// Loads the loadable and stores it under the filename given to the loadable. /// Loads the loadable and stores it under the filename given to the loadable.
/// </summary> /// </summary>
/// <param name="loadable">The loadable to load.</param> /// <param name="name">The loadable to load.</param>
public void Load(ILoadable<IAssetUseable> loadable) { /// <param name="glContext">The OpenGL context to associate with the loaded asset if the loaded asset requires it. May be null, in which the currently active context will be associated with it.</param>
string name = loadable.FileName; public void Load(string name, GLContext glContext = null) {
assets[name] = loadable.Load(PathModifiers[loadable.GetType()]); if (glContext == null) glContext = WindowContextsManager.CurrentGL;
string ext = Path.GetExtension(name).ToLower();
if (PathModifiers.ContainsKey(ext)) {
name = PathModifiers[ext](name);
}
if (!Loaders.ContainsKey(ext)) throw new FrameworkUsageException(string.Format("Failed to find associated loader for file \"{0}\" with extension \"{1}\".", name, ext));
assets[name] = Loaders[ext](name, glContext);
} }
/// <summary> /// <summary>
@ -87,18 +133,5 @@ namespace SlatedGameToolkit.Framework.Loader {
Unload(name); Unload(name);
} }
} }
/// <summary>
/// Disposes of all the stored assets.
/// </summary>
public void Dispose()
{
load = false;
UnloadAll();
}
~AssetManager() {
Dispose();
}
} }
} }

View File

@ -0,0 +1,46 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using SDL2;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Loader;
namespace SlatedGameToolkit.Framework.Loader
{
public static class CommonLoaders
{
/// <summary>
/// Loads a texture using SDL2's image library.
/// Therefore, technically, this function should be able to laod any format SDL2 Image can load.
/// </summary>
/// <param name="path">The path of the texture to load.</param>
/// <param name="glContext">The OpenGL context the texture is to be associated with. </param>
/// <returns>An OpenGL Texture associated with the given context.</returns>
public static Texture LoadTexture(string path, GLContext glContext)
{
IntPtr ptr = SDL_image.IMG_Load(path);
if (ptr.Equals(IntPtr.Zero)) throw new FrameworkSDLException("Could not find texture file at path: " + path);
SDL.SDL_Surface surface = Marshal.PtrToStructure<SDL.SDL_Surface>(ptr);
SDL.SDL_PixelFormat pixelFormat = Marshal.PtrToStructure<SDL.SDL_PixelFormat>(surface.format);
if (pixelFormat.format != SDL.SDL_PIXELFORMAT_ABGR8888) {
GameEngine.Logger.Warning(string.Format("Texture \"{0}\" is of format {1}. Converting to ABGR8888. Consider saving files in such a data format for faster load times.", path, SDL.SDL_GetPixelFormatName(pixelFormat.format).Remove(0, 16)));
IntPtr convertedPtr = SDL.SDL_ConvertSurfaceFormat(ptr, SDL.SDL_PIXELFORMAT_ABGR8888, 0);
if (convertedPtr == null) throw new OptionalSDLException();
SDL.SDL_FreeSurface(ptr);
ptr = convertedPtr;
surface = Marshal.PtrToStructure<SDL.SDL_Surface>(ptr);
}
byte[] data = new byte[surface.pitch * surface.h];
Marshal.Copy(surface.pixels, data, 0, data.Length);
TextureData textureData = new TextureData(surface.w, surface.h, data);
Texture useable = new Texture(textureData, glContext);
SDL.SDL_FreeSurface(ptr);
return useable;
}
}
}

View File

@ -1,31 +0,0 @@
namespace SlatedGameToolkit.Framework.Loader
{
/// <summary>
/// The method should modify the path.
/// </summary>
/// <param name="path">The path to modify.</param>
/// <returns>The modified path.</returns>
public delegate string PathModifier(string path);
/// <summary>
/// A loader is to load an asset the game uses.
/// It is created whenever the asset needs to be loaded with a string representing the path to the file to actually load.
/// </summary>
public interface ILoadable <UseableT> where UseableT : IAssetUseable
{
/// <summary>
/// The name of the file to load.
/// This is what the asset manager stores the results under.
/// </summary>
/// <value>A string representing the name to load.</value>
string FileName { get; }
/// <summary>
/// Loads the asset.
/// </summary>
/// <param name="pathModifier">Modifies the path. May be null. Default is null.</param>
/// <typeparam name="Useable">The loadable type.</typeparam>
/// <returns>The loadable type.</returns>
UseableT Load(PathModifier pathModifier = null);
}
}

View File

@ -1,29 +0,0 @@
using System;
using System.Runtime.InteropServices;
using SDL2;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Loader;
namespace SlatedGameToolkit.Framework.Loader
{
public class TextureLoader : ILoadable<Texture>
{
public string FileName {get; private set; }
public TextureLoader(string path) {
this.FileName = path;
}
public Texture Load(PathModifier pathModifier = null)
{
IntPtr ptr = SDL_image.IMG_Load(pathModifier == null ? FileName : pathModifier(FileName));
if (ptr.Equals(IntPtr.Zero)) throw new FrameworkSDLException();
SDL.SDL_Surface surface = Marshal.PtrToStructure<SDL.SDL_Surface>(ptr);
TextureData textureData = new TextureData();
textureData.data = new byte[surface.pitch * surface.h];
Marshal.Copy(surface.pixels, textureData.data, 0, textureData.data.Length);
Texture useable = new Texture(textureData);
return useable;
}
}
}

View File

@ -1,4 +1,4 @@
#version 330 core #version 330
out vec4 outputColor; out vec4 outputColor;
in vec2 texCoord; in vec2 texCoord;

View File

@ -1,10 +1,12 @@
#version 330 core #version 330
in vec3 aPosition; in vec3 aPosition;
in vec4 aColor; in vec4 aColor;
in vec2 aTexCoord; in vec2 aTexCoord;
uniform mat4 models; uniform mat4 models;
uniform mat4 view; uniform mat4 view;
uniform mat4 projection; uniform mat4 projection;
out vec2 texCoord; out vec2 texCoord;
out vec4 color; out vec4 color;
@ -13,5 +15,5 @@ void main()
texCoord = aTexCoord; texCoord = aTexCoord;
color = aColor; color = aColor;
gl_Position = projection * view * models * vec4(aPosition, 1.0f); gl_Position = projection * view * models * vec4(aPosition, 1.0);
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -2,10 +2,11 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Threading; using System.Threading;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.Window; using SlatedGameToolkit.Framework.Graphics.Window;
using SlatedGameToolkit.Framework.StateSystem.States; using SlatedGameToolkit.Framework.StateSystem.States;
using SlatedGameToolkit.Framework.Utilities;
using SlatedGameToolkit.Framework.Graphics;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
namespace SlatedGameToolkit.Framework.StateSystem namespace SlatedGameToolkit.Framework.StateSystem
{ {
@ -48,10 +49,8 @@ namespace SlatedGameToolkit.Framework.StateSystem
internal void render(double delta) { internal void render(double delta) {
WindowContext windowContext = WindowContextsManager.CurrentWindowContext; WindowContext windowContext = WindowContextsManager.CurrentWindowContext;
windowContext.clearColour((float)backgroundColour.R / byte.MaxValue, (float)backgroundColour.G / byte.MaxValue, (float)backgroundColour.B / byte.MaxValue); windowContext.Context.ClearColor(backgroundColour.RedAsFloat(), backgroundColour.GreenAsFloat(), backgroundColour.BlueAsFloat(), 1f);
OpenGLErrorException.CheckGLErrorStatus(); windowContext.Context.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
windowContext.clear(GLEnum.GL_COLOR_BUFFER_BIT | GLEnum.GL_DEPTH_BUFFER_BIT);
OpenGLErrorException.CheckGLErrorStatus();
currentState.Render(delta); currentState.Render(delta);
windowContext.SwapBuffer(); windowContext.SwapBuffer();
} }

View File

@ -0,0 +1,20 @@
using System.Drawing;
namespace SlatedGameToolkit.Framework.Utilities
{
public static class ColorUtils
{
public static float RedAsFloat(this Color color) {
return (float) color.R / byte.MaxValue;
}
public static float GreenAsFloat(this Color color) {
return (float) color.G / byte.MaxValue;
}
public static float BlueAsFloat(this Color color) {
return (float) color.B / byte.MaxValue;
}
public static float AlphaAsFloat(this Color color) {
return (float) color.A / byte.MaxValue;
}
}
}

View File

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace SlatedGameToolkit.Framework.Utilities
{
public static class EmbeddedResourceUtils
{
public static string ReadEmbeddedResourceText(string name) {
string res;
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("SlatedGameToolkit.Framework.Resources.{0}", name)))
{
using (StreamReader reader = new StreamReader(stream)) {
res = reader.ReadToEnd();
}
}
return res;
}
public static byte[] ReadEmbeddedResourceData(string name) {
byte[] res;
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("SlatedGameToolkit.Framework.Resources.{0}", name)))
{
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
res = buffer;
}
return res;
}
}
}

View File

@ -0,0 +1,13 @@
using System.Numerics;
namespace SlatedGameToolkit.Framework.Utilities
{
public static class MatrixUtils
{
public static float[] ToColumnMajorArray(this Matrix4x4 mat) {
return new float[] {
mat.M11, mat.M12, mat.M13, mat.M14, mat.M21, mat.M22, mat.M23, mat.M24, mat.M31, mat.M32, mat.M33, mat.M34, mat.M41, mat.M42, mat.M43, mat.M44
};
}
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Numerics;
namespace SlatedGameToolkit.Framework.Utilities
{
public static class VectorUtils
{
public static Vector3 NormalizeSafe(this Vector3 value, Vector3 alternate) {
float l = value.Length();
if (l == 0) {
return alternate;
}
value /= l;
return value;
}
}
}

View File

@ -25,11 +25,11 @@ namespace SlatedGameToolkit.Tools.CommandSystem
string[] args = new string[splitMessage.Length - 1]; string[] args = new string[splitMessage.Length - 1];
Array.Copy(splitMessage, 1, args, 0, splitMessage.Length - 1); Array.Copy(splitMessage, 1, args, 0, splitMessage.Length - 1);
if (!invocable.Execute(interactable, args)) { if (!invocable.Execute(interactable, args)) {
interactable.Tell(string.Format("The command \"{0}\" was recognized, but arguments were incorrect. Please refer to Please type \"help {0}\" for more information.", invocation)); interactable.Tell(string.Format("The command \"{0}\" arguments were incorrect. Please refer to Please type \"help {0}\" for more information.", invocation));
} }
return; return;
} }
interactable.Tell(string.Format("The input \"{0}\" was not understood. Please type \"help\" for more information.", invocation)); interactable.Tell(string.Format("The command \"{0}\" was not understood. Please type \"help\" for more information.", invocation));
} }
} }
} }

View File

@ -21,7 +21,7 @@ namespace SlatedGameToolkit.Tools.Commands
if (invocable == null) interactable.Tell("Unable to find command {0}. Please type \"help\" for more a list of commands."); if (invocable == null) interactable.Tell("Unable to find command {0}. Please type \"help\" for more a list of commands.");
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.AppendJoin(", ", invocable.GetInvokers()); builder.AppendJoin(", ", invocable.GetInvokers());
interactable.Tell("Possible aliases: " + builder.ToString() + ": "); interactable.Tell("Possible aliases: " + builder.ToString());
interactable.Tell("Description: " + invocable.getDescription()); interactable.Tell("Description: " + invocable.getDescription());
interactable.Tell("Usage: " + invocable.getUsage(args.Length > 0 ? args[0] : null)); interactable.Tell("Usage: " + invocable.getUsage(args.Length > 0 ? args[0] : null));
} else { } else {

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -1,12 +1,13 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Numerics; using System.Numerics;
using SlatedGameToolkit.Framework.Exceptions; using SDL2;
using SlatedGameToolkit.Framework.Graphics.Programs;
using SlatedGameToolkit.Framework.Graphics.Render; using SlatedGameToolkit.Framework.Graphics.Render;
using SlatedGameToolkit.Framework.Graphics.Shaders; using SlatedGameToolkit.Framework.Graphics.Render.Programs;
using SlatedGameToolkit.Framework.Graphics.Textures; using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Graphics.Window; using SlatedGameToolkit.Framework.Graphics.Window;
using SlatedGameToolkit.Framework.Input;
using SlatedGameToolkit.Framework.Input.Devices;
using SlatedGameToolkit.Framework.Loader; using SlatedGameToolkit.Framework.Loader;
using SlatedGameToolkit.Framework.StateSystem; using SlatedGameToolkit.Framework.StateSystem;
using SlatedGameToolkit.Framework.StateSystem.States; using SlatedGameToolkit.Framework.StateSystem.States;
@ -16,9 +17,8 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
public class MainState : IState public class MainState : IState
{ {
private WindowContext window; private WindowContext window;
private GLShaderProgram program;
private Camera2D camera; private Camera2D camera;
private Renderer renderer; private MeshBatch renderer;
private Texture texture; private Texture texture;
private Sprite2D sprite; private Sprite2D sprite;
@ -36,10 +36,9 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
public void Deinitialize() public void Deinitialize()
{ {
window.Dispose();
program.Dispose();
texture.Dispose(); texture.Dispose();
renderer.Dispose(); renderer.Dispose();
window.Dispose();
} }
public string getName() public string getName()
@ -50,25 +49,35 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
public void Initialize(StateManager manager) public void Initialize(StateManager manager)
{ {
window = new WindowContext("SlatedGameToolkit Playground"); window = new WindowContext("SlatedGameToolkit Playground");
camera = new Camera2D(); camera = new Camera2D(2, 2);
camera.Width = window.WindowBoundaries.Width; renderer = new MeshBatch(camera);
camera.Height = window.WindowBoundaries.Height; texture = CommonLoaders.LoadTexture("Resources/Playground/yhdnbgnc.png", null);
camera.Position = new Vector2(camera.Width / 2, camera.Height / 2);
program = new GLShaderProgram(new NormalVertexShader(), new NormalFragmentShader());
renderer = new Renderer(camera, program);
texture = new TextureLoader("Resources/Playground/yhdnbgnc.png").Load();
sprite = new Sprite2D(texture, Color.White); sprite = new Sprite2D(texture, Color.White);
sprite.X = -0.5f;
sprite.Y = -0.5f;
} }
public void Render(double delta) public void Render(double delta)
{ {
OpenGLErrorException.CheckGLErrorStatus(); renderer.Begin(Matrix4x4.Identity);
renderer.Queue(sprite, Matrix4x4.Identity); renderer.Draw(sprite);
renderer.Render(); renderer.End();
} }
public void Update(double delta) public void Update(double delta)
{ {
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_DOWN)) {
camera.Position += new Vector2(0, (float)(-0.5f * delta));
}
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_UP)) {
camera.Position += new Vector2(0, (float)(0.5f * delta));
}
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_LEFT)) {
camera.Position += new Vector2((float)(-0.5f * delta), 0);
}
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_RIGHT)) {
camera.Position += new Vector2((float)(0.5f * delta), 0);
}
} }
} }
} }