diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00000000..b4f62baf
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "CorgEC"]
+ path = CorgEC
+ url = https://github.com/PowerfulBacon/CorgEC
diff --git a/CorgEC b/CorgEC
new file mode 160000
index 00000000..0bd28adb
--- /dev/null
+++ b/CorgEC
@@ -0,0 +1 @@
+Subproject commit 0bd28adbda007ff1999d3338f7f89caa3416e57f
diff --git a/CorgEng.Core/CorgEng.Core.csproj b/CorgEng.Core/CorgEng.Core.csproj
index 2dfc246a..59d654fa 100644
--- a/CorgEng.Core/CorgEng.Core.csproj
+++ b/CorgEng.Core/CorgEng.Core.csproj
@@ -5,6 +5,16 @@
false
AnyCPU;ARM32;ARM64
True
+ 2.0.0
+
CorgEng Core
+ PowerfulBacon
+ README.md
+ https://github.com/PowerfulBacon/CorgEng
+ git
+ game-engine
+ Copyright owned by PowerfulBacon. See EULA
+ LICENSE
+ True
bin\x64\Debug\
@@ -49,6 +59,16 @@
Always
+
+
+ True
+ \
+
+
+ True
+ \
+
+
diff --git a/CorgEng.Core/CorgEng.Core.sln b/CorgEng.Core/CorgEng.Core.sln
index cbf8b97e..d5fd894b 100644
--- a/CorgEng.Core/CorgEng.Core.sln
+++ b/CorgEng.Core/CorgEng.Core.sln
@@ -75,7 +75,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorgEng.Lighting", "..\Corg
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorgEng.EntityQuery", "..\CorgEng.EntityQuery\CorgEng.EntityQuery.csproj", "{CD4E414F-536D-454B-8423-9631952EF705}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorgEng.Functional", "..\CorgEng.Functional\CorgEng.Functional.csproj", "{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ECCore", "..\CorgEC\ECCore\ECCore.csproj", "{CD1C4D5D-1534-4126-8F86-E52B87A50BA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -215,8 +215,8 @@ Global
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM32.ActiveCfg = Debug|ARM32
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM32.Build.0 = Debug|ARM32
- {14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM64.ActiveCfg = Debug|ARM64
- {14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM64.Build.0 = Debug|ARM64
+ {14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM64.ActiveCfg = Debug|Any CPU
+ {14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM64.Build.0 = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|x64.ActiveCfg = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|x64.Build.0 = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|x86.ActiveCfg = Debug|Any CPU
@@ -415,8 +415,8 @@ Global
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM32.ActiveCfg = Debug|ARM32
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM32.Build.0 = Debug|ARM32
- {EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM64.ActiveCfg = Debug|ARM64
- {EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM64.Build.0 = Debug|ARM64
+ {EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM64.ActiveCfg = Debug|Any CPU
+ {EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM64.Build.0 = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|x64.ActiveCfg = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|x64.Build.0 = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|x86.ActiveCfg = Debug|Any CPU
@@ -651,26 +651,26 @@ Global
{CD4E414F-536D-454B-8423-9631952EF705}.Release|x64.Build.0 = Release|Any CPU
{CD4E414F-536D-454B-8423-9631952EF705}.Release|x86.ActiveCfg = Release|Any CPU
{CD4E414F-536D-454B-8423-9631952EF705}.Release|x86.Build.0 = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|ARM32.ActiveCfg = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|ARM32.Build.0 = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|ARM64.ActiveCfg = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|ARM64.Build.0 = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|x64.ActiveCfg = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|x64.Build.0 = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|x86.ActiveCfg = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|x86.Build.0 = Debug|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|Any CPU.Build.0 = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|ARM32.ActiveCfg = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|ARM32.Build.0 = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|ARM64.ActiveCfg = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|ARM64.Build.0 = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|x64.ActiveCfg = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|x64.Build.0 = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|x86.ActiveCfg = Release|Any CPU
- {0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|x86.Build.0 = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|ARM32.ActiveCfg = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|ARM32.Build.0 = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|ARM64.ActiveCfg = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|ARM64.Build.0 = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|x64.Build.0 = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Debug|x86.Build.0 = Debug|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|ARM32.ActiveCfg = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|ARM32.Build.0 = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|ARM64.ActiveCfg = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|ARM64.Build.0 = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|x64.ActiveCfg = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|x64.Build.0 = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|x86.ActiveCfg = Release|Any CPU
+ {CD1C4D5D-1534-4126-8F86-E52B87A50BA7}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/CorgEng.Core/CorgEngMain.cs b/CorgEng.Core/CorgEngMain.cs
index b0ab5967..e00ac94c 100644
--- a/CorgEng.Core/CorgEngMain.cs
+++ b/CorgEng.Core/CorgEngMain.cs
@@ -6,7 +6,11 @@
using CorgEng.Core.Rendering.Exceptions;
using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Logging;
+using CorgEng.GenericInterfaces.Networking.Networking.Client;
+using CorgEng.GenericInterfaces.Networking.Networking.Server;
using CorgEng.GenericInterfaces.Rendering;
+using CorgEng.GenericInterfaces.Rendering.Renderers;
+using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
using GLFW;
using System;
using System.Collections.Concurrent;
@@ -14,6 +18,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
+using System.Runtime.CompilerServices;
using System.Runtime.Loader;
using System.Threading;
using System.Threading.Tasks;
@@ -24,6 +29,12 @@ namespace CorgEng.Core
public static class CorgEngMain
{
+ ///
+ /// Get a dependency for a default sprite renderer
+ ///
+ [UsingDependency]
+ private static ISpriteRendererFactory SpriteRendererFactory = null!;
+
///
/// The internal render master.
/// Handles transfering iamges generated by the RenderCore to
@@ -32,9 +43,22 @@ public static class CorgEngMain
private static RenderMaster InternalRenderMaster { get; set; }
///
- /// The main render core currently in use by the renderer
+ /// The render cores that are currently being used by the renderer.
+ /// If none is provided then a renderer provided one will be given which just draws things on its plane and performs
+ /// no other special effects.
///
- public static RenderCore MainRenderCore { get; private set; }
+ private static ConcurrentDictionary renderCores { get; } = new ConcurrentDictionary();
+
+ ///
+ /// Render planes that are staged to start rendering
+ ///
+ private static volatile SortedList stagedRenderPlanes = new SortedList();
+
+ ///
+ /// A sorted list containing the planes that are currently drawing directly to the screen.
+ /// Planes are drawn in order of layer when they aren't drawn to another surface first.
+ ///
+ private static SortedList renderingPlanes = new SortedList();
///
/// The window associated with the CorgEng application
@@ -57,6 +81,12 @@ public static class CorgEngMain
[UsingDependency]
private static ILogger Logger;
+ ///
+ /// The thing that we use to create the world
+ ///
+ [UsingDependency]
+ private static IWorldFactory WorldFactory;
+
///
/// Time of the last frame
///
@@ -81,17 +111,17 @@ public static class CorgEngMain
public static event Action OnReadyEvents = null;
- private static IWorld primaryWorld = null;
+ private static IWorld _primaryWorld = null;
///
/// The main world to use for the game for when one isn't accessible
///
- public static IWorld PrimaryWorld
+ public static IWorld World
{
- get => primaryWorld;
+ get => _primaryWorld;
set {
- primaryWorld = value;
- WorldInit(primaryWorld);
+ _primaryWorld = value;
+ WorldInit(_primaryWorld);
}
}
///
@@ -108,13 +138,14 @@ public static IWorld PrimaryWorld
/// Initializes the CorgEng game engine.
/// Will call initialization on all CorgEng modules.
///
- public static void Initialize(bool disableRendering = false)
+ public static void Initialize(string filePath, bool disableRendering = false, bool awaitOnError = true)
{
+ LoadConfig(filePath, awaitOnError);
try
{
// Reset the world list
WorldList.Clear();
- //Load priority modules (Logging)
+ // Load priority modules (Logging)
PriorityModuleInit();
Logger?.WriteLine("Starting CorgEng Application", LogType.DEBUG);
if (disableRendering)
@@ -123,20 +154,33 @@ public static void Initialize(bool disableRendering = false)
ModuleInit();
return;
}
- //Enable rendering functionality
+ // Enable rendering functionality
IsRendering = true;
- //Create a new window
+ // Create a new window
GameWindow = new CorgEngWindow();
GameWindow.Open();
Logger?.WriteLine("Successfully created primary window", LogType.DEBUG);
- //Create the internal render master
+ // Create the internal render master
InternalRenderMaster = new RenderMaster();
InternalRenderMaster.Initialize();
Logger?.WriteLine("Successfully initialized render master", LogType.DEBUG);
- //Bind the render master size to the game window size
- GameWindow.OnWindowResized += InternalRenderMaster.SetWindowRenderSize;
- //Load non-priority modules
+ // Bind the render master size to the game window
+ GameWindow.OnWindowResized += InternalRenderMaster.SetWindowRenderSize;
+ GameWindow.OnWindowResized += activeSizeDelegate;
+ // Load non-priority modules
ModuleInit();
+ // Create the world
+ if (World == null)
+ {
+ if (WorldFactory != null)
+ {
+ World = WorldFactory.CreateWorld();
+ }
+ else
+ {
+ Logger?.WriteLine($"The world module is not loaded, meaning that no base game was created.", LogType.WARNING);
+ }
+ }
}
catch (System.Exception e)
{
@@ -173,6 +217,22 @@ public static void TransferToRenderingThread()
while (!GameWindow.ShouldClose())
{
lastFrameTime = Glfw.Time;
+ // Move the staged rendering planes into the active queue
+ if (stagedRenderPlanes.Count > 0)
+ {
+ lock (stagedRenderPlanes)
+ {
+ foreach (var stagedPlane in stagedRenderPlanes)
+ {
+ renderingPlanes.TryAdd(stagedPlane.Key, stagedPlane.Value);
+ if (!stagedPlane.Value.Initialized)
+ {
+ stagedPlane.Value.Initialize();
+ }
+ }
+ stagedRenderPlanes.Clear();
+ }
+ }
//Trigger any render thread code
if (!queuedActions.IsEmpty)
{
@@ -197,13 +257,17 @@ public static void TransferToRenderingThread()
Glfw.PollEvents();
//Handle key events
GameWindow.Update();
- //Check to ensure we have a render core
- if (MainRenderCore == null)
- throw new NullRenderCoreException("The main CorgEng render core is not set! Use CorgEng.SetRenderCore(RenderCore) to set the primary render core.");
- //Process the main render core
- MainRenderCore.DoRender();
- //Pass the output image from the render core to the internal renderer
- InternalRenderMaster.RenderImageToScreen(MainRenderCore);
+ // Refresh the screen
+ RenderMaster.RefreshScreen();
+ // Perform rendering of the render planes that are not diverted to another source
+ foreach (var renderPlane in renderingPlanes.Values)
+ {
+ // Process the actual render
+ renderPlane.Render(MainCamera);
+ //Pass the output image from the render core to the internal renderer
+ InternalRenderMaster.RenderImageToScreen(renderPlane);
+ }
+ // Update the delta time
DeltaTime = Glfw.Time - lastFrameTime;
#if PERFORMANCE
total += DeltaTime;
@@ -224,19 +288,47 @@ public static void SetMainCamera(ICamera camera)
MainCamera = camera;
}
- private static CorgEngWindow.WindowResizeDelegate activeSizeDelegate;
+ ///
+ /// Resize all of the contained render cores when the screen size changes
+ ///
+ private static CorgEngWindow.WindowResizeDelegate activeSizeDelegate = (width, height) => {
+ foreach (IRenderer renderCore in renderCores.Values)
+ {
+ renderCore.Resize(width, height);
+ }
+ };
///
/// Sets the CorgEng program's render core.
///
- public static void SetRenderCore(RenderCore newRenderCore)
+ public static void SetPlaneRenderCore(int renderCorePlane, IRenderer newRenderCore)
{
- MainRenderCore = newRenderCore;
- MainRenderCore.Initialize();
- GameWindow.OnWindowResized -= activeSizeDelegate;
- activeSizeDelegate = MainRenderCore.Resize;
- GameWindow.OnWindowResized += activeSizeDelegate;
+ newRenderCore.Initialize();
+ renderCores.AddOrUpdate(renderCorePlane, newRenderCore, (plane, oldCore) => {
+ oldCore.Dispose();
+ return newRenderCore;
+ });
}
+ ///
+ /// Get the render core with the provided plane number.
+ /// If no render core has been set for this plane, one will be created.
+ ///
+ ///
+ ///
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static IRenderer GetRendererForPlane(int renderCorePlane)
+ {
+ return renderCores.GetOrAdd(renderCorePlane, plane => {
+ // Fetch a default render core implementation
+ var spriteRenderer = SpriteRendererFactory.CreateSpriteRenderer(_primaryWorld, plane);
+ lock (stagedRenderPlanes)
+ {
+ stagedRenderPlanes.Add(plane, spriteRenderer);
+ }
+ return spriteRenderer;
+ });
+ }
///
/// Shuts down and cleans up all resources used by CorgEng
@@ -264,14 +356,14 @@ public static void Shutdown()
/// TODO: Whitelist/blacklist types and add sandboxing
///
///
- public static void LoadConfig(string filePath, bool embeddedResource = true, bool awaitOnError = true)
+ private static void LoadConfig(string filePath, bool awaitOnError = true)
{
try
{
string resourceName;
Stream resourceStream;
//Locate the config resources file
- if (embeddedResource)
+ if (!File.Exists(filePath))
{
resourceName = Assembly.GetEntryAssembly().GetManifestResourceNames().Single(str => str.EndsWith(filePath));
resourceStream = Assembly.GetEntryAssembly().GetManifestResourceStream(resourceName);
@@ -313,6 +405,9 @@ public static void LoadConfig(string filePath, bool embeddedResource = true, boo
}
LoadedAssemblyModules = loadedAssemblies;
break;
+ case "WindowName":
+ WindowName = childElement.Value;
+ break;
default:
Console.Error.WriteLine($"[CorgEng Config Error]: Error parsing config, unknown config attribute {childElement.Name}.");
break;
@@ -490,7 +585,6 @@ public static void ExecuteIn(Action action, double executeTime)
}
}
double timeToFire = Time + executeTime * 0.001;
- Logger.WriteLine($"Action queued to fire at {timeToFire}", LogType.WARNING);
// 0 or negative execution time
if (timeToFire <= Time)
{
@@ -543,16 +637,14 @@ internal static void CheckQueuedExecutions()
public static void Cleanup()
{
MainCamera = null;
- primaryWorld = null;
+ _primaryWorld = null;
foreach (IWorld world in WorldList)
{
world.Cleanup();
}
WorldList.Clear();
queuedActions.Clear();
- MainRenderCore = null;
Logger.WriteLine("Full cleanup of CorgEng application completed.", LogType.DEBUG);
}
-
}
}
diff --git a/CorgEng.Core/Rendering/RenderCore.cs b/CorgEng.Core/Rendering/RenderCore.cs
deleted file mode 100644
index 43b1687d..00000000
--- a/CorgEng.Core/Rendering/RenderCore.cs
+++ /dev/null
@@ -1,383 +0,0 @@
-using CorgEng.Core.Dependencies;
-using CorgEng.GenericInterfaces.Core;
-using CorgEng.GenericInterfaces.EntityComponentSystem;
-using CorgEng.GenericInterfaces.Logging;
-using CorgEng.GenericInterfaces.Rendering.Shaders;
-using CorgEng.GenericInterfaces.UtilityTypes;
-using System;
-using System.Collections.Generic;
-using static OpenGL.Gl;
-
-namespace CorgEng.Core.Rendering
-{
- public abstract class RenderCore : WorldObject, IRenderCore
- {
-
- [UsingDependency]
- private static ILogger Logger;
-
- //Fetch shader loading from some dependency somewhere
- [UsingDependency]
- private static IShaderFactory ShaderFactory;
-
- [UsingDependency]
- protected static IColourFactory ColourFactory;
-
- private static float[] quadVertices = {
- 1, 1, 0,
- 1, -1, 0,
- -1, 1, 0,
- -1, 1, 0,
- 1, -1, 0,
- -1, -1, 0
- };
-
- private static bool initialized = false;
-
- //The vertex array and buffer objects
- private static uint vertexArray;
- private static uint vertexBuffer;
-
- private static IShaderSet shaderSet;
-
- private static IShaderSet depthShaderSet;
-
- private static int textureUniformLocation;
-
- private static int depthUniformLocation;
-
- private static int depthIncrementUniformLocation;
-
- //Create a program for rendering
- private static uint programUint;
-
- ///
- /// The uint of the frame buffer
- ///
- public uint FrameBufferUint { get; }
-
- ///
- /// The uint of the render buffer
- ///
- public uint RenderBufferUint { get; }
-
- ///
- /// The uint of our render texture
- ///
- public uint RenderTextureUint { get; }
-
- ///
- /// The ID of the depth texture generated by rendering this render core.
- ///
- public uint DepthTextureUint { get; }
-
- public virtual int Width { get; internal set; } = 1920;
-
- public virtual int Height { get; internal set; } = 1080;
-
- private static IColour _currentBackColour;
- private static DepthModes _currentDepthMode = DepthModes.KEEP_DEPTH;
- private static RenderModes _currentBlendMode = RenderModes.DEFAULT;
-
- ///
- /// The render mode to use when drawing this render core to the framebuffer.
- ///
- public virtual RenderModes DrawMode { get; } = RenderModes.DEFAULT;
-
- ///
- /// The render mode to use when rendering elements on to the render core.
- ///
- public virtual RenderModes BlendMode { get; } = RenderModes.DEFAULT;
-
- ///
- /// Should we keep depth?
- /// Ignoring depth causes the render core to overlay on whatever it is being drawn on.
- ///
- public virtual DepthModes DepthMode { get; } = DepthModes.KEEP_DEPTH;
-
- ///
- /// The scaling mode of this render core.
- ///
- public virtual ScalingModes ScalingMode { get; } = ScalingModes.NEAREST_NEIGHBOUR;
-
- ///
- /// If this is set to true, the render core will be allowed to be resized through the Resize() function.
- ///
- public virtual bool CanResize { get; } = true;
-
- ///
- /// The path of the shaders to use.
- /// Only accessed during initialisation.
- ///
- public virtual string ShaderPath => "CoreShader";
-
- public virtual IColour BackColour { get; } = ColourFactory.GetColour(0, 0, 0, 0);
-
- ///
- /// How much depth should we add to this render core?
- ///
- public virtual float DepthAdd { get; } = 0;
-
- [UsingDependency]
- private static IWorldFactory WorldFactory;
-
- public unsafe RenderCore(IWorld world) : base(world)
- {
- if (!CorgEngMain.IsRendering)
- return;
- //Generate a render buff
- RenderBufferUint = glGenRenderbuffer();
- glBindRenderbuffer(RenderBufferUint);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, Width, Height);
- //Generate a frame buffer
- FrameBufferUint = glGenFramebuffer();
- glBindFramebuffer(GL_FRAMEBUFFER, FrameBufferUint);
- //Create a render texture
- glActiveTexture(GL_TEXTURE0);
- RenderTextureUint = glGenTexture();
- //Bind the created texture so we can modify it
- glBindTexture(GL_TEXTURE_2D, RenderTextureUint);
- //Load the texture scale
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- //Set the texture parameters
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- //Bind the framebuffer to the texture
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, RenderTextureUint, 0);
- //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
- //Bind the render depth buffer to the framebuffer
- //glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RenderBufferUint);
- //Bind the framebuffer to the texture
- //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, RenderTextureUint, 0);
- //=========================
- // Setup the depth texture
- //=========================
- glActiveTexture(GL_TEXTURE1);
- DepthTextureUint = glGenTexture();
- glBindTexture(GL_TEXTURE_2D, DepthTextureUint);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RenderBufferUint);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, DepthTextureUint, 0);
- //Check for issues
- if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
- {
- //TODO: Introduce a rendering mode that bypasses framebuffers and just draws directly to the screen.
- //Slightly broken is better than nothing.
- Logger.WriteLine("WARNING: FRAMEBUFFER ERROR. Your GPU may not support this application!", LogType.ERROR);
- }
- //Log creation
- Logger?.WriteLine($"Created RenderCore, rendering to framebuffer {FrameBufferUint} outputting texture to {RenderTextureUint}", LogType.DEBUG);
- }
-
- public unsafe static void SetupRendering()
- {
- //Create stuff we need for screen rendering (static)
- if (!initialized)
- {
- Logger?.WriteLine("Initialized RenderCore static requirements.", LogType.LOG);
- //Mark initialized to be true.
- initialized = true;
- //create and link a program
- programUint = glCreateProgram();
- //Start using the program: All operations will affect this program
- glUseProgram(programUint);
- //Generate a vertex array and bind it
- vertexArray = glGenVertexArray();
- glBindVertexArray(vertexArray);
- //Create and bind the vertex buffer
- vertexBuffer = glGenBuffer();
- glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
-
- //Put data into the buffer
- fixed (float* vertexPointer = &quadVertices[0])
- {
- glBufferData(GL_ARRAY_BUFFER, sizeof(float) * quadVertices.Length, vertexPointer, GL_STATIC_DRAW);
- }
- //Create the shaders
- shaderSet = ShaderFactory.CreateShaderSet("CoreShader");
- //Get the uniform location of the shaders
- shaderSet.AttachShaders(programUint);
- glLinkProgram(programUint);
- //Fetch uniform locations
- textureUniformLocation = glGetUniformLocation(programUint, "renderTexture");
- depthUniformLocation = glGetUniformLocation(programUint, "depthTexture");
- depthIncrementUniformLocation = glGetUniformLocation(programUint, "depthIncrement");
- }
- }
-
- private static Dictionary loadedShaders = new Dictionary();
-
- private IShaderSet GetShader(string name)
- {
- if (!loadedShaders.ContainsKey(name))
- {
- IShaderSet createdShader = ShaderFactory.CreateShaderSet(name);
- loadedShaders.Add(name, createdShader);
- }
- return loadedShaders[name];
- }
-
- public void PreRender()
- {
- //Bind our framebuffer to render to
- glBindFramebuffer(GL_FRAMEBUFFER, FrameBufferUint);
- //Clear the backbuffer
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- //Set the viewport
- glViewport(0, 0, Width, Height);
- }
-
- ///
- /// Do rendering
- ///
- public void DoRender(Action? preRenderAction = null)
- {
- RenderModes prev = SwitchBlendMode(BlendMode);
- DepthModes prevDepth = SwitchDepthMode(DepthMode);
- IColour prevColour = SwitchBackColour(BackColour);
- PreRender();
- preRenderAction?.Invoke();
- PerformRender();
- SwitchBlendMode(prev);
- SwitchDepthMode(prevDepth);
- SwitchBackColour(prevColour);
- }
-
- protected static RenderModes SwitchBlendMode(RenderModes newMode)
- {
- if (newMode == _currentBlendMode)
- return newMode;
- RenderModes prevMode = _currentBlendMode;
- _currentBlendMode = newMode;
- switch (_currentBlendMode)
- {
- case RenderModes.DEFAULT:
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- break;
- case RenderModes.MULTIPLY:
- glBlendFunc(GL_DST_COLOR, GL_ZERO);
- break;
- case RenderModes.ADDITIVE:
- glBlendFunc(GL_ONE, GL_ONE);
- break;
- }
- return prevMode;
- }
-
- protected static DepthModes SwitchDepthMode(DepthModes newMode)
- {
- if (newMode == _currentDepthMode)
- return newMode;
- DepthModes prevMode = _currentDepthMode;
- _currentDepthMode = newMode;
- switch (_currentDepthMode)
- {
- case DepthModes.KEEP_DEPTH:
- glDepthFunc(GL_LEQUAL);
- break;
- case DepthModes.IGNORE_DEPTH:
- glDepthFunc(GL_ALWAYS);
- break;
- }
- return prevMode;
- }
-
- protected static IColour SwitchBackColour(IColour newColour)
- {
- if (newColour == null || newColour.Equals(_currentBackColour))
- return newColour;
- IColour prevCol = _currentBackColour;
- _currentBackColour = newColour;
- glClearColor(newColour.Red, newColour.Green, newColour.Blue, newColour.Alpha);
- return prevCol;
- }
-
- ///
- /// Called when the render core is initialized
- ///
- public abstract void Initialize();
-
- ///
- /// Perform rendering
- ///
- public abstract void PerformRender();
-
- public unsafe void Resize(int width, int height)
- {
- //Set the new width
- Width = width;
- Height = height;
- //Log
- Logger?.WriteLine($"Render core resized to {Width}x{Height}", LogType.DEBUG);
- if (!CorgEngMain.IsRendering || !CanResize)
- return;
- //Update the tex image
- //Bind the created texture so we can modify it
- glBindTexture(GL_TEXTURE_2D, RenderTextureUint);
- //Load the texture scale
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- //Set the texture parameters
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScalingMode == ScalingModes.NEAREST_NEIGHBOUR ? GL_NEAREST : GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ScalingMode == ScalingModes.NEAREST_NEIGHBOUR ? GL_NEAREST : GL_LINEAR);
- // Bind the depth texture
- glBindTexture(GL_TEXTURE_2D, DepthTextureUint);
- //Load the texture scale
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
- //Set the texture parameters
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScalingMode == ScalingModes.NEAREST_NEIGHBOUR ? GL_NEAREST : GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ScalingMode == ScalingModes.NEAREST_NEIGHBOUR ? GL_NEAREST : GL_LINEAR);
- }
-
- public unsafe void DrawToBuffer(uint buffer, int drawX, int drawY, int bufferWidth, int bufferHeight)
- {
- //Reset the framebuffer (We want to draw to the screen, not a frame buffer)
- glBindFramebuffer(GL_FRAMEBUFFER, buffer);
- //glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RenderBufferUint);
- //Draw to full screen
- glViewport(drawX, drawY, bufferWidth, bufferHeight);
-
- //Setup blending
- RenderModes prevRender = SwitchBlendMode(DrawMode);
- DepthModes prevBlend = SwitchDepthMode(DepthMode);
- IColour prevColour = SwitchBackColour(BackColour);
-
- //Set the using program to our program uint
- glUseProgram(programUint);
- //Bind uniform variables
- glUniform1i(textureUniformLocation, 0);
- glUniform1i(depthUniformLocation, 1);
- glUniform1f(depthIncrementUniformLocation, DepthAdd);
- //Bind the vertex buffer
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
- glVertexAttribPointer(
- 0, //Attribute - Where the layout location is in the vertex shader
- 3, //Size of the triangles (3 sides)
- GL_FLOAT, //Type (Floats)
- false, //Normalized (nope)
- 0, //Stride (0)
- NULL //Array buffer offset (null)
- );
- //Set the vertex attrib divisor
- glVertexAttribDivisor(0, 0);
- //Bind the texture
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, RenderTextureUint);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, DepthTextureUint);
- //glBindRenderbuffer(RenderBufferUint);
- //glBindTexture(GL_RENDERBUFFER, RenderBufferUint);
- //Draw
- glDrawArrays(GL_TRIANGLES, 0, 6);
- //Disable the vertex attrib array
- glDisableVertexAttribArray(0);
-
- SwitchBlendMode(prevRender);
- SwitchDepthMode(prevBlend);
- SwitchBackColour(prevColour);
- }
-
- }
-}
diff --git a/CorgEng.Core/Rendering/RenderMaster.cs b/CorgEng.Core/Rendering/RenderMaster.cs
index e7c94b39..e92b1dae 100644
--- a/CorgEng.Core/Rendering/RenderMaster.cs
+++ b/CorgEng.Core/Rendering/RenderMaster.cs
@@ -1,4 +1,5 @@
using CorgEng.Core.Dependencies;
+using CorgEng.GenericInterfaces.Rendering.Renderers;
using CorgEng.GenericInterfaces.Rendering.Shaders;
using System;
using static OpenGL.Gl;
@@ -19,8 +20,6 @@ public void Initialize()
{
//Setup the global GL flags
SetGlobalGlFlags();
- //Initialize render core
- RenderCore.SetupRendering();
}
private void SetGlobalGlFlags()
@@ -48,15 +47,19 @@ private void SetGlobalGlFlags()
}
+ public static void RefreshScreen()
+ {
+ //Reset the framebuffer (We want to draw to the screen, not a frame buffer)
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ //Clear the screen and reset it to the background colour
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ }
+
///
/// Renders an image outputted by a render core to the screen.
///
- public unsafe void RenderImageToScreen(RenderCore renderCore)
+ public unsafe void RenderImageToScreen(IRenderer renderCore)
{
- //Reset the framebuffer (We want to draw to the screen, not a frame buffer)
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- //Clear the screen and reset it to the background colour
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Draw the render core to the screen
renderCore.DrawToBuffer(0, 0, 0, Width, Height);
}
diff --git a/CorgEng.EntityComponentSystem/Systems/EntitySystemManager.cs b/CorgEng.EntityComponentSystem/Systems/EntitySystemManager.cs
index e191e46a..499bd061 100644
--- a/CorgEng.EntityComponentSystem/Systems/EntitySystemManager.cs
+++ b/CorgEng.EntityComponentSystem/Systems/EntitySystemManager.cs
@@ -50,7 +50,7 @@ internal class EntitySystemManager : IEntitySystemManager
///
internal Dictionary> RegisteredSystemSignalHandlers { get; } = new Dictionary>();
- private EntitySystemThreadManager entitySystemThreadManager = new EntitySystemThreadManager(4);
+ private EntitySystemThreadManager entitySystemThreadManager = new EntitySystemThreadManager(1);
private IWorld world;
diff --git a/CorgEng.EntityComponentSystem/Systems/EntitySystemThreadManager.cs b/CorgEng.EntityComponentSystem/Systems/EntitySystemThreadManager.cs
index 99ccdc1c..30b56f8b 100644
--- a/CorgEng.EntityComponentSystem/Systems/EntitySystemThreadManager.cs
+++ b/CorgEng.EntityComponentSystem/Systems/EntitySystemThreadManager.cs
@@ -91,7 +91,6 @@ public void EnqueueSystemForProcessing(EntitySystem system)
public void FireSystemIn(EntitySystem system, double fireTime)
{
CorgEngMain.ExecuteIn(() => {
- Logger.WriteLine($"Attempting to queue system {system} for processing fire at {CorgEngMain.Time}", LogType.TEMP);
system.QueueProcessing();
}, fireTime);
}
diff --git a/CorgEng.Example.Server/CorgEngConfig.xml b/CorgEng.Example.Server/CorgEngConfig.xml
index 0ae947d7..2e2c8b3b 100644
--- a/CorgEng.Example.Server/CorgEngConfig.xml
+++ b/CorgEng.Example.Server/CorgEngConfig.xml
@@ -1,4 +1,5 @@
+
CorgEng.ContentLoading
@@ -18,4 +19,7 @@
CorgEng.UserInterface
CorgEng.World
+
+ CorgEngApplication Server
+
diff --git a/CorgEng.Example.Server/Program.cs b/CorgEng.Example.Server/Program.cs
index 76d6b079..41be113d 100644
--- a/CorgEng.Example.Server/Program.cs
+++ b/CorgEng.Example.Server/Program.cs
@@ -14,7 +14,6 @@
using CorgEng.Example.Shared.Components.FollowMouseComponent;
using CorgEng.Example.Shared.Components.Gravity;
using CorgEng.Example.Shared.Components.SandFactory;
-using CorgEng.Example.Shared.RenderCores;
using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Logging;
using CorgEng.GenericInterfaces.Networking.Config;
@@ -58,35 +57,21 @@ class Program
[UsingDependency]
private static INetworkConfig NetworkConfig;
- [UsingDependency]
- private static IWorldFactory WorldFactory;
-
- public static IWorld ServerWorld;
-
static void Main(string[] args)
{
- //Load the application config
- CorgEngMain.LoadConfig("CorgEngConfig.xml");
- CorgEngMain.WindowName = "CorgEngApplication Server";
//Initialize CorgEng in headless mode
#if !DEBUG_RENDERING
- CorgEngMain.Initialize(true);
+ CorgEngMain.Initialize("CorgEngConfig.xml", true);
#else
- CorgEngMain.Initialize();
-
- // Create the program world
- ServerWorld = WorldFactory.CreateWorld();
- CorgEngMain.PrimaryWorld = ServerWorld;
+ CorgEngMain.Initialize("CorgEngConfig.xml");
//Start networking server
- ServerWorld.ServerInstance.StartHosting(5000);
+ CorgEngMain.World.ServerInstance.StartHosting(5000);
//Debug
NetworkConfig.ProcessClientSystems = true;
- ExampleRenderCore erc = new ExampleRenderCore(ServerWorld);
- CorgEngMain.SetRenderCore(erc);
- ServerWorld.EntityManager.CreateEmptyEntity(entity => {
+ CorgEngMain.World.EntityManager.CreateEmptyEntity(entity => {
IIsometricCamera camera = IsometricCameraFactory.CreateCamera();
camera.Width = 30;
camera.Height = 30;
@@ -98,7 +83,7 @@ static void Main(string[] args)
});
// Create a lighting debugger
- ServerWorld.EntityManager.CreateEmptyEntity(entity => {
+ CorgEngMain.World.EntityManager.CreateEmptyEntity(entity => {
entity.AddComponent(new TransformComponent());
entity.AddComponent(new FollowCursorComponent());
entity.AddComponent(new SpriteRenderComponent());
@@ -164,7 +149,7 @@ private static void BuildWorld()
{
for (int yv = Math.Min(start_y, end_y); yv <= Math.Max(start_y, end_y); yv++)
{
- ServerWorld.EntityManager.CreateEmptyEntity(testingEntity => {
+ CorgEngMain.World.EntityManager.CreateEmptyEntity(testingEntity => {
//Add components
testingEntity.AddComponent(new NetworkTransformComponent());
testingEntity.AddComponent(new SpriteRenderComponent());
@@ -181,7 +166,7 @@ private static void BuildWorld()
});
//Create a testing entity
- ServerWorld.EntityManager.CreateEmptyEntity(testingEntity => {
+ CorgEngMain.World.EntityManager.CreateEmptyEntity(testingEntity => {
//Add components
testingEntity.AddComponent(new NetworkTransformComponent());
testingEntity.AddComponent(new SpriteRenderComponent());
@@ -195,13 +180,13 @@ private static void BuildWorld()
private static void SetPlayerPrototype()
{
- ServerWorld.EntityManager.CreateEmptyEntity(playerPrototype => {
+ CorgEngMain.World.EntityManager.CreateEmptyEntity(playerPrototype => {
playerPrototype.AddComponent(new ClientComponent());
playerPrototype.AddComponent(new NetworkTransformComponent());
playerPrototype.AddComponent(new SpriteRenderComponent() { Sprite = IconFactory.CreateIcon("human.ghost", 5, Constants.RenderingConstants.DEFAULT_RENDERER_PLANE), SpriteRendererIdentifier = 1 });
playerPrototype.AddComponent(new PlayerMovementComponent());
IPrototype prototype = PrototypeManager.GetPrototype(playerPrototype);
- ServerWorld.ServerInstance.SetClientPrototype(prototype);
+ CorgEngMain.World.ServerInstance.SetClientPrototype(prototype);
new DeleteEntityEvent().Raise(playerPrototype);
});
}
diff --git a/CorgEng.Example.Shared/RenderCores/ExampleRenderCore.cs b/CorgEng.Example.Shared/RenderCores/ExampleRenderCore.cs
deleted file mode 100644
index 3a92d1db..00000000
--- a/CorgEng.Example.Shared/RenderCores/ExampleRenderCore.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-using CorgEng.Core;
-using CorgEng.Core.Dependencies;
-using CorgEng.Core.Rendering;
-using CorgEng.EntityComponentSystem.Entities;
-using CorgEng.GenericInterfaces.EntityComponentSystem;
-using CorgEng.GenericInterfaces.Font.Fonts;
-using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
-using CorgEng.GenericInterfaces.Rendering.RenderObjects.SpriteRendering;
-using CorgEng.GenericInterfaces.Rendering.Text;
-using CorgEng.GenericInterfaces.Rendering.Textures;
-using CorgEng.GenericInterfaces.UserInterface.Components;
-using CorgEng.GenericInterfaces.UserInterface.Generators;
-using CorgEng.Lighting.RenderCores;
-using CorgEng.Rendering.DepthParallax;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CorgEng.Example.Shared.RenderCores
-{
- public class ExampleRenderCore : RenderCore
- {
-
- private Entity renderableEntity;
-
- [UsingDependency]
- public static ISpriteRendererFactory SpriteRendererFactory;
-
- public ISpriteRenderer spriteRenderer;
-
- [UsingDependency]
- public static ISpriteRenderObjectFactory spriteRenderObjectFactory;
-
- [UsingDependency]
- public static ITextureFactory textureFactory;
-
- [UsingDependency]
- public static IFontFactory FontFactory;
-
- [UsingDependency]
- public static ITextObjectFactory TextObjectFactory;
-
- private LightingRenderCore lightingRenderCore;
-
- private ParallaxLayerRenderCore parallaxLayerRenderCore;
-
- public ExampleRenderCore(IWorld world) : base(world)
- {
- }
-
- public override void Initialize()
- {
- spriteRenderer = SpriteRendererFactory.CreateSpriteRenderer(1);
- spriteRenderer?.Initialize();
-
- IFont font = FontFactory.GetFont("CourierCode");
- ITextObject textObject = TextObjectFactory.CreateTextObject(spriteRenderer, font, "CorgEng.Font");
- textObject.StartRendering();
-
- parallaxLayerRenderCore = new ParallaxLayerRenderCore(world, 1, 30);
- parallaxLayerRenderCore?.Initialize();
-
- lightingRenderCore = new LightingRenderCore(world);
- lightingRenderCore.Initialize();
- }
-
- public override void PerformRender()
- {
- spriteRenderer?.Render(CorgEngMain.MainCamera);
- parallaxLayerRenderCore.DoRender();
- parallaxLayerRenderCore.DrawToBuffer(FrameBufferUint, 0, 0, Width, Height);
- //lightingRenderCore.DoRender();
- //lightingRenderCore.DrawToBuffer(FrameBufferUint, 0, 0, Width, Height);
- }
- }
-}
diff --git a/CorgEng.Example/Program.cs b/CorgEng.Example/Program.cs
index 42b4e6fe..2ba4a149 100644
--- a/CorgEng.Example/Program.cs
+++ b/CorgEng.Example/Program.cs
@@ -1,7 +1,6 @@
using CorgEng.Core;
using CorgEng.Core.Dependencies;
using CorgEng.Example.Modules.CameraScroll;
-using CorgEng.Example.Shared.RenderCores;
using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Networking.Networking.Client;
using CorgEng.GenericInterfaces.Rendering.Cameras.Isometric;
@@ -21,42 +20,18 @@ class Program
static void Main(string[] args)
{
- //Load the application config
- CorgEngMain.LoadConfig("CorgEngConfig.xml");
//Initialize CorgEng
//This creates the window and loads all
//modules that are dependencies
- CorgEngMain.Initialize();
-
- // Create the world
- IWorld world = WorldFactory.CreateWorld();
- CorgEngMain.PrimaryWorld = world;
-
- //Set the render core
-
- // Prevent failures
- //Thread.Sleep(5000);
+ CorgEngMain.Initialize("CorgEngConfig.xml");
//Camera an isometric camera
IIsometricCamera camera = isometricCameraFactory.CreateCamera();
CameraScrollSystem.IsometricCamera = camera;
- ExampleRenderCore erc = new ExampleRenderCore(world);
- CorgEngMain.SetRenderCore(erc);
-
//Connect to our server
- world.ClientInstance.AttemptConnection("127.0.0.1", 5000);
+ CorgEngMain.World.ClientInstance.AttemptConnection("127.0.0.1", 5000);
- //Create the entity to hold and move the camera
- /*Entity mainCameraEntity = new Entity();
- mainCameraEntity.AddComponent(new TransformComponent());
- mainCameraEntity.AddComponent(new PlayerMovementComponent());
- mainCameraEntity.AddComponent(new CameraComponent(camera));
- mainCameraEntity.AddComponent(new SpriteRenderComponent());*/
- /*
- new SetSpriteEvent("human.ghost").Raise(mainCameraEntity);
- new SetSpriteRendererEvent(erc.spriteRenderer).Raise(mainCameraEntity);
- */
//Set the main camera
CorgEngMain.SetMainCamera(camera);
//Transfer control of the main thread to the CorgEng
diff --git a/CorgEng.Functional/CorgEng.Functional.csproj b/CorgEng.Functional/CorgEng.Functional.csproj
deleted file mode 100644
index 132c02c5..00000000
--- a/CorgEng.Functional/CorgEng.Functional.csproj
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
- net6.0
- enable
- enable
-
-
-
diff --git a/CorgEng.Functional/Monads/Result.cs b/CorgEng.Functional/Monads/Result.cs
deleted file mode 100644
index 8af271b8..00000000
--- a/CorgEng.Functional/Monads/Result.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CorgEng.Functional.Monads
-{
- public class Result
- {
-
- public virtual bool HasValue { get; } = true;
-
- private T value;
-
- public Result(T value)
- {
- this.value = value;
- }
-
- public Result Fail(Action failureAction)
- {
- if (HasValue)
- return this;
- failureAction();
- return this;
- }
-
- public Result Then(Action successAction)
- {
- if (!HasValue)
- return this;
- successAction(value);
- return this;
- }
-
- }
-
- public class Failure : Result
- {
-
- public Failure() : base(default)
- { }
-
- public override bool HasValue => false;
- }
-}
diff --git a/CorgEng.GenericInterfaces/Core/IRenderCore.cs b/CorgEng.GenericInterfaces/Core/IRenderCore.cs
deleted file mode 100644
index 51020625..00000000
--- a/CorgEng.GenericInterfaces/Core/IRenderCore.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CorgEng.GenericInterfaces.Core
-{
- public interface IRenderCore
- {
-
- int Width { get; }
-
- int Height { get; }
-
- ///
- /// The uint of the frame buffer
- ///
- uint FrameBufferUint { get; }
-
- ///
- /// The uint of our render texture
- ///
- uint RenderTextureUint { get; }
-
- ///
- /// Initialize the render core, run one time at the start.
- ///
- void Initialize();
-
- ///
- /// Render this render core to its render texture.
- ///
- /// The depth texture of the thing that we are drawing on top of
- ///
- void DoRender(Action? preRenderAction = null);
-
- ///
- /// Draws the rendered frame buffer to the screen (Framebuffer 0)
- ///
- void DrawToBuffer(uint buffer, int drawX, int drawY, int bufferWidth, int bufferHeight);
-
- ///
- /// Resize the render core to the specified size.
- ///
- /// The width in pixels of the new render core.
- /// The height in pixels of the new render core.
- void Resize(int width, int height);
-
- }
-}
diff --git a/CorgEng.GenericInterfaces/Rendering/Icons/IIcon.cs b/CorgEng.GenericInterfaces/Rendering/Icons/IIcon.cs
index 08d28746..6a5cc182 100644
--- a/CorgEng.GenericInterfaces/Rendering/Icons/IIcon.cs
+++ b/CorgEng.GenericInterfaces/Rendering/Icons/IIcon.cs
@@ -47,7 +47,7 @@ public interface IIcon : ICustomSerialisationBehaviour
///
/// The plane that this icon should be renderer on.
///
- uint Plane { get; set; }
+ int Plane { get; set; }
///
/// The renderer being used to render this icon.
diff --git a/CorgEng.GenericInterfaces/Rendering/Icons/IIconFactory.cs b/CorgEng.GenericInterfaces/Rendering/Icons/IIconFactory.cs
index 7e558f02..0b28d845 100644
--- a/CorgEng.GenericInterfaces/Rendering/Icons/IIconFactory.cs
+++ b/CorgEng.GenericInterfaces/Rendering/Icons/IIconFactory.cs
@@ -10,7 +10,7 @@ namespace CorgEng.GenericInterfaces.Rendering.Icons
public interface IIconFactory
{
- IIcon CreateIcon(string name, float layer, uint plane);
+ IIcon CreateIcon(string name, float layer, int plane);
}
}
diff --git a/CorgEng.GenericInterfaces/Rendering/Renderers/IRenderer.cs b/CorgEng.GenericInterfaces/Rendering/Renderers/IRenderer.cs
index 6d1384f4..96f0f9c8 100644
--- a/CorgEng.GenericInterfaces/Rendering/Renderers/IRenderer.cs
+++ b/CorgEng.GenericInterfaces/Rendering/Renderers/IRenderer.cs
@@ -6,14 +6,61 @@
namespace CorgEng.GenericInterfaces.Rendering.Renderers
{
- public interface IRenderer
+ public interface IRenderer : IDisposable
{
- uint NetworkIdentifier { get; }
+ ///
+ /// The width in pixels of the renderer
+ ///
+ int Width { get; }
- void Initialize();
+ ///
+ /// The height in pixels of the renderer
+ ///
+ int Height { get; }
+ ///
+ /// The uint of the frame buffer
+ ///
+ uint FrameBufferUint { get; }
+
+ ///
+ /// The uint of our render texture
+ ///
+ uint RenderTextureUint { get; }
+
+ ///
+ /// The plane of the renderer
+ ///
+ int Plane { get; }
+
+ ///
+ /// Has this renderer been initialised?
+ ///
+ bool Initialized { get; }
+
+ ///
+ /// Initialise the renderer
+ ///
+ void Initialize();
+
+ ///
+ /// Render the context of the renderer
+ ///
+ ///
void Render(ICamera camera);
- }
+ ///
+ /// Draws the rendered frame buffer to the screen (Framebuffer 0)
+ ///
+ void DrawToBuffer(uint buffer, int drawX, int drawY, int bufferWidth, int bufferHeight);
+
+ ///
+ /// Resize the render core to the specified size.
+ ///
+ /// The width in pixels of the new render core.
+ /// The height in pixels of the new render core.
+ void Resize(int width, int height);
+
+ }
}
diff --git a/CorgEng.GenericInterfaces/Rendering/Renderers/ParallaxRenderer/IParallaxRendererFactory.cs b/CorgEng.GenericInterfaces/Rendering/Renderers/ParallaxRenderer/IParallaxRendererFactory.cs
index d009bda9..2c04eef7 100644
--- a/CorgEng.GenericInterfaces/Rendering/Renderers/ParallaxRenderer/IParallaxRendererFactory.cs
+++ b/CorgEng.GenericInterfaces/Rendering/Renderers/ParallaxRenderer/IParallaxRendererFactory.cs
@@ -1,4 +1,5 @@
-using System;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -14,7 +15,7 @@ public interface IParallaxRendererFactory
///
///
///
- IParallaxRenderer CreateParallaxRenderer(uint networkedIdentifier);
+ IParallaxRenderer CreateParallaxRenderer(IWorld world, int plane);
}
}
diff --git a/CorgEng.GenericInterfaces/Rendering/Renderers/SpriteRendering/ISpriteRendererFactory.cs b/CorgEng.GenericInterfaces/Rendering/Renderers/SpriteRendering/ISpriteRendererFactory.cs
index 8caca72a..0621c1cc 100644
--- a/CorgEng.GenericInterfaces/Rendering/Renderers/SpriteRendering/ISpriteRendererFactory.cs
+++ b/CorgEng.GenericInterfaces/Rendering/Renderers/SpriteRendering/ISpriteRendererFactory.cs
@@ -1,4 +1,5 @@
-using System;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -9,7 +10,7 @@ namespace CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering
public interface ISpriteRendererFactory
{
- ISpriteRenderer CreateSpriteRenderer(uint networkedIdentifier);
+ ISpriteRenderer CreateSpriteRenderer(IWorld world, int plane);
}
}
diff --git a/CorgEng.InputHandling/InputHandler.cs b/CorgEng.InputHandling/InputHandler.cs
index 352c7e7a..25ae50cb 100644
--- a/CorgEng.InputHandling/InputHandler.cs
+++ b/CorgEng.InputHandling/InputHandler.cs
@@ -76,7 +76,7 @@ private void HandleScroll(IntPtr window, double x, double y)
{
//Synchronous to prevent subsystem overloading, will not render the
//next frame until this is handled.
- new MouseScrollEvent(y).RaiseGlobally(CorgEngMain.PrimaryWorld, synchronous: true);
+ new MouseScrollEvent(y).RaiseGlobally(CorgEngMain.World, synchronous: true);
//Trigger the new actions
foreach (string actionName in boundScrollActions)
{
@@ -96,7 +96,7 @@ private void HandleCursorMove(IntPtr window, double x, double y)
{
//Synchronous to prevent subsystem overloading, will not render the
//next frame until this is handled.
- new MouseMoveEvent(x / CorgEngMain.GameWindow.Width, y / CorgEngMain.GameWindow.Height).RaiseGlobally(CorgEngMain.PrimaryWorld, synchronous: true);
+ new MouseMoveEvent(x / CorgEngMain.GameWindow.Width, y / CorgEngMain.GameWindow.Height).RaiseGlobally(CorgEngMain.World, synchronous: true);
//Trigger the new actions
foreach (string actionName in boundMouseMoveActions)
{
@@ -134,7 +134,7 @@ private void HandleMousePress(IntPtr window, MouseButton button, InputState stat
{
return;
}
- mousePressEvent.RaiseGlobally(CorgEngMain.PrimaryWorld);
+ mousePressEvent.RaiseGlobally(CorgEngMain.World);
mouseDownAt = CorgEngMain.Time;
//Trigger the action
if (!boundMouseActions.TryGetValue(button, out action))
@@ -153,7 +153,7 @@ private void HandleMousePress(IntPtr window, MouseButton button, InputState stat
MouseReleaseEvent mouseReleaseEvent = new MouseReleaseEvent(x / width, y / height, button, modifiers);
mouseReleaseEvent.HeldTime = CorgEngMain.Time - mouseDownAt;
//Raise synchronously, so we can determine if the event was handled
- mouseReleaseEvent.RaiseGlobally(CorgEngMain.PrimaryWorld, true);
+ mouseReleaseEvent.RaiseGlobally(CorgEngMain.World, true);
//Handle world clicks
if (!mouseReleaseEvent.Handled && mouseReleaseEvent.MouseButton == MouseButton.Left)
{
@@ -192,7 +192,7 @@ private void HandleKeyboardPress(IntPtr window, Keys key, int scanCode, InputSta
{
case InputState.Press:
KeyPressEvent keyPressEvent = new KeyPressEvent(key, mods);
- keyPressEvent.RaiseGlobally(CorgEngMain.PrimaryWorld);
+ keyPressEvent.RaiseGlobally(CorgEngMain.World);
lock (heldKeysDownAt)
{
heldKeysDownAt.Add(key, CorgEngMain.Time);
@@ -214,7 +214,7 @@ private void HandleKeyboardPress(IntPtr window, Keys key, int scanCode, InputSta
try
{
KeyReleaseEvent keyReleaseEvent = new KeyReleaseEvent(key, mods);
- keyReleaseEvent.RaiseGlobally(CorgEngMain.PrimaryWorld);
+ keyReleaseEvent.RaiseGlobally(CorgEngMain.World);
//Trigger the action
if (!boundKeyActions.TryGetValue(key, out action))
return;
diff --git a/CorgEng.Lighting/RenderCores/LightingRenderCore.cs b/CorgEng.Lighting/RenderCores/LightingRenderCore.cs
deleted file mode 100644
index 7f609cc2..00000000
--- a/CorgEng.Lighting/RenderCores/LightingRenderCore.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using CorgEng.Core;
-using CorgEng.Core.Dependencies;
-using CorgEng.Core.Rendering;
-using CorgEng.GenericInterfaces.EntityComponentSystem;
-using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
-using CorgEng.GenericInterfaces.UtilityTypes;
-using static OpenGL.Gl;
-
-namespace CorgEng.Lighting.RenderCores
-{
- public class LightingRenderCore : RenderCore
- {
-
- public const int LIGHTING_PLANE = 10;
-
- [UsingDependency]
- private static ISpriteRendererFactory SpriteRendererFactory = default!;
-
- public override RenderModes DrawMode => RenderModes.MULTIPLY;
-
- public override RenderModes BlendMode => RenderModes.ADDITIVE;
-
- public override DepthModes DepthMode => DepthModes.IGNORE_DEPTH;
-
- public ISpriteRenderer lightRenderer = null!;
-
- public LightingRenderCore(IWorld world) : base(world)
- {
- }
-
- public override IColour BackColour => ColourFactory.GetColour(0.4f, 0.4f, 0.4f, 1);
-
- public override void Initialize()
- {
- lightRenderer = SpriteRendererFactory.CreateSpriteRenderer(LIGHTING_PLANE);
- lightRenderer.Initialize();
- }
-
- public override void PerformRender()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- lightRenderer.Render(CorgEngMain.MainCamera);
- }
-
- }
-}
diff --git a/CorgEng.Lighting/RenderCores/LightingRenderer.cs b/CorgEng.Lighting/RenderCores/LightingRenderer.cs
new file mode 100644
index 00000000..e004e16d
--- /dev/null
+++ b/CorgEng.Lighting/RenderCores/LightingRenderer.cs
@@ -0,0 +1,32 @@
+using CorgEng.Core;
+using CorgEng.Core.Dependencies;
+using CorgEng.Core.Rendering;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
+using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
+using CorgEng.GenericInterfaces.UtilityTypes;
+using CorgEng.Rendering.SpriteRendering;
+using static OpenGL.Gl;
+
+namespace CorgEng.Lighting.RenderCores
+{
+ public class LightingRenderer : SpriteRenderer
+ {
+
+ public static int LIGHTING_PLANE = 10;
+
+ public override RenderModes DrawMode => RenderModes.MULTIPLY;
+
+ public override RenderModes BlendMode => RenderModes.ADDITIVE;
+
+ public override DepthModes DepthMode => DepthModes.IGNORE_DEPTH;
+
+ public ISpriteRenderer lightRenderer = null!;
+
+ public override IColour BackColour => ColourFactory.GetColour(0.4f, 0.4f, 0.4f, 1);
+
+ public LightingRenderer(IWorld world) : base(world)
+ {
+ }
+
+ }
+}
diff --git a/CorgEng.Lighting/Systems/LightingSystem.cs b/CorgEng.Lighting/Systems/LightingSystem.cs
index aeb5b166..bf03530f 100644
--- a/CorgEng.Lighting/Systems/LightingSystem.cs
+++ b/CorgEng.Lighting/Systems/LightingSystem.cs
@@ -31,7 +31,7 @@ public override void SystemSetup(IWorld world)
//When the lighting object initialises, set it to start rendering on the specified system
RegisterLocalEvent((entity, lightingComponent, signal) => {
//Create an overlay lighting icon.
- IIcon createdIcon = IconFactory.CreateIcon("light_mask", 100, LightingRenderCore.LIGHTING_PLANE);
+ IIcon createdIcon = IconFactory.CreateIcon("light_mask", 100, LightingRenderer.LIGHTING_PLANE);
createdIcon.Transform = new Matrix(new float[,]
{
{ lightingComponent.Radius, 0, 0 },
diff --git a/CorgEng.Logging/Logging/ConsoleLogger.cs b/CorgEng.Logging/Logging/ConsoleLogger.cs
index 49b654d8..0a86160f 100644
--- a/CorgEng.Logging/Logging/ConsoleLogger.cs
+++ b/CorgEng.Logging/Logging/ConsoleLogger.cs
@@ -1,4 +1,5 @@
-using CorgEng.Core.Modules;
+using CorgEng.Core;
+using CorgEng.Core.Modules;
using CorgEng.DependencyInjection.Dependencies;
using CorgEng.GenericInterfaces.Logging;
using System;
@@ -47,7 +48,7 @@ public void WriteLine(object message, LogType logType)
ExceptionCount++;
DateTime logTime = DateTime.Now;
- string logText = $"[{Thread.CurrentThread.Name ?? $"T{Thread.CurrentThread.ManagedThreadId}"}][{logType}][{logTime}]";
+ string logText = $"[{Thread.CurrentThread.Name ?? $"T{Thread.CurrentThread.ManagedThreadId}"}][{logType}][{logTime}/{CorgEngMain.Time:F3}]";
lock (consoleLock)
{
//Ignore this log
diff --git a/CorgEng.Networking/Networking/Client/NetworkClient.cs b/CorgEng.Networking/Networking/Client/NetworkClient.cs
index 4888a860..e46e3731 100644
--- a/CorgEng.Networking/Networking/Client/NetworkClient.cs
+++ b/CorgEng.Networking/Networking/Client/NetworkClient.cs
@@ -310,7 +310,7 @@ protected override void HandleMessage(IPEndPoint sender, PacketHeaders header, b
Logger.WriteMetric("networked_global_event", raisedEvent.GetType().ToString());
//Deserialize the event
raisedEvent.Deserialise(reader);
- raisedEvent.RaiseGlobally(CorgEngMain.PrimaryWorld, false);
+ raisedEvent.RaiseGlobally(CorgEngMain.World, false);
}
}
return;
@@ -341,7 +341,7 @@ protected override void HandleMessage(IPEndPoint sender, PacketHeaders header, b
double viewOffsetHeight = reader.ReadDouble();
//Update our view
//Send a signal
- new ModifyIsometricView(viewX + viewOffsetX, viewY + viewOffsetY, viewZ, viewOffsetWidth, viewOffsetHeight).RaiseGlobally(CorgEngMain.PrimaryWorld);
+ new ModifyIsometricView(viewX + viewOffsetX, viewY + viewOffsetY, viewZ, viewOffsetWidth, viewOffsetHeight).RaiseGlobally(CorgEngMain.World);
}
}
return;
diff --git a/CorgEng.Pathfinding/CorgEng.Pathfinding.csproj b/CorgEng.Pathfinding/CorgEng.Pathfinding.csproj
index 757ddd99..a01854a0 100644
--- a/CorgEng.Pathfinding/CorgEng.Pathfinding.csproj
+++ b/CorgEng.Pathfinding/CorgEng.Pathfinding.csproj
@@ -8,6 +8,7 @@
+
diff --git a/CorgEng.Rendering/ComponentSystem/DepthParallax/DepthSpriteRenderComponent.cs b/CorgEng.Rendering/ComponentSystem/DepthParallax/DepthSpriteRenderComponent.cs
index 535d24ce..825b0783 100644
--- a/CorgEng.Rendering/ComponentSystem/DepthParallax/DepthSpriteRenderComponent.cs
+++ b/CorgEng.Rendering/ComponentSystem/DepthParallax/DepthSpriteRenderComponent.cs
@@ -23,7 +23,7 @@ public override ISpriteRenderer SpriteRenderer
{
if (!ParallaxLayerRenderCore.parallaxRenderCores.ContainsKey((int)SpriteRendererIdentifier))
return null;
- _spriteRenderer = ParallaxLayerRenderCore.parallaxRenderCores[(int)SpriteRendererIdentifier][(int)Sprite.Layer-1].renderer;
+ _spriteRenderer = ParallaxLayerRenderCore.parallaxRenderCores[(int)SpriteRendererIdentifier][(int)Sprite.Layer-1];
cachedSpriteRendererIdentifier = SpriteRendererIdentifier;
}
return _spriteRenderer;
diff --git a/CorgEng.Rendering/ComponentSystem/SpriteRendering/SetSpriteRendererEvent.cs b/CorgEng.Rendering/ComponentSystem/SpriteRendering/SetSpriteRendererEvent.cs
index 53839f6a..210c43d9 100644
--- a/CorgEng.Rendering/ComponentSystem/SpriteRendering/SetSpriteRendererEvent.cs
+++ b/CorgEng.Rendering/ComponentSystem/SpriteRendering/SetSpriteRendererEvent.cs
@@ -21,21 +21,21 @@ public class SetSpriteRendererEvent : INetworkedEvent
[UsingDependency]
private static IAutoSerialiser AutoSerialiser;
- public uint Target { get; set; }
+ public int Target { get; set; }
- public SetSpriteRendererEvent(uint target)
+ public SetSpriteRendererEvent(int target)
{
Target = target;
}
public SetSpriteRendererEvent(ISpriteRenderer target)
{
- Target = target.NetworkIdentifier;
+ Target = target.Plane;
}
public void Deserialise(BinaryReader reader)
{
- Target = reader.ReadUInt32();
+ Target = reader.ReadInt32();
}
public void Serialise(BinaryWriter writer)
@@ -45,7 +45,7 @@ public void Serialise(BinaryWriter writer)
public int SerialisedLength()
{
- return sizeof(uint);
+ return sizeof(int);
}
}
}
diff --git a/CorgEng.Rendering/ComponentSystem/SpriteRendering/SpriteRenderComponent.cs b/CorgEng.Rendering/ComponentSystem/SpriteRendering/SpriteRenderComponent.cs
index dff5d587..26c5c78e 100644
--- a/CorgEng.Rendering/ComponentSystem/SpriteRendering/SpriteRenderComponent.cs
+++ b/CorgEng.Rendering/ComponentSystem/SpriteRendering/SpriteRenderComponent.cs
@@ -1,4 +1,5 @@
-using CorgEng.EntityComponentSystem.Components;
+using CorgEng.Core;
+using CorgEng.EntityComponentSystem.Components;
using CorgEng.GenericInterfaces.ContentLoading;
using CorgEng.GenericInterfaces.Networking.Attributes;
using CorgEng.GenericInterfaces.Rendering.Icons;
@@ -49,7 +50,7 @@ public class SpriteRenderComponent : Component, IInstantiatable
/// The identifier of the sprite renderer to use
///
[NetworkSerialized]
- public uint SpriteRendererIdentifier { get; set; }
+ public int SpriteRendererIdentifier { get; set; }
///
/// Is the sprite currently being rendered
@@ -58,7 +59,7 @@ public class SpriteRenderComponent : Component, IInstantiatable
internal bool WantsToRender { get; set; } = true;
- protected uint cachedSpriteRendererIdentifier = 0;
+ protected int cachedSpriteRendererIdentifier = 0;
protected ISpriteRenderer _spriteRenderer;
@@ -70,7 +71,7 @@ public virtual ISpriteRenderer SpriteRenderer
return null;
if (_spriteRenderer == null || cachedSpriteRendererIdentifier != SpriteRendererIdentifier)
{
- _spriteRenderer = RendererLookup.GetRendererByIdentifier(SpriteRendererIdentifier);
+ _spriteRenderer = (ISpriteRenderer)CorgEngMain.GetRendererForPlane(SpriteRendererIdentifier);
cachedSpriteRendererIdentifier = SpriteRendererIdentifier;
}
return _spriteRenderer;
diff --git a/CorgEng.Rendering/DepthParallax/ParallaxLayerRenderCore.cs b/CorgEng.Rendering/DepthParallax/ParallaxLayerRenderCore.cs
index 176e82bc..b9c92eef 100644
--- a/CorgEng.Rendering/DepthParallax/ParallaxLayerRenderCore.cs
+++ b/CorgEng.Rendering/DepthParallax/ParallaxLayerRenderCore.cs
@@ -2,6 +2,7 @@
using CorgEng.Core.Dependencies;
using CorgEng.Core.Rendering;
using CorgEng.GenericInterfaces.EntityComponentSystem;
+using CorgEng.GenericInterfaces.Rendering;
using CorgEng.GenericInterfaces.Rendering.Renderers;
using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
using CorgEng.Rendering.SpriteRendering;
@@ -14,7 +15,7 @@
namespace CorgEng.Rendering.DepthParallax
{
- public class ParallaxLayerRenderCore : RenderCore
+ public class ParallaxLayerRenderCore : SpriteRenderer
{
[UsingDependency]
@@ -30,11 +31,6 @@ public class ParallaxLayerRenderCore : RenderCore
///
private ParallaxLayerRenderCore? next;
- ///
- /// The renderer
- ///
- internal ISpriteRenderer renderer;
-
///
/// Parallax render cores that are active in the world
///
@@ -56,22 +52,18 @@ public ParallaxLayerRenderCore(IWorld world, int identifier, int layer) : base(w
public override void Initialize()
{
- renderer = SpriteRendererFactory.CreateSpriteRenderer(0);
- renderer.Initialize();
+ base.Initialize();
next?.Initialize();
}
- public override void PerformRender()
+ public override void Render(ICamera camera)
{
- // Render our current layer then pass that on to the next render core to draw
- renderer.Render(CorgEngMain.MainCamera);
+ base.Render(camera);
// Now render the layer below us
if (next != null)
{
- next.DoRender(() => {
- DrawToBuffer(next.FrameBufferUint, 0, 0, Width, Height);
- });
- // Render the layer below us onto our layer
+ // TODO: Make the next layer not draw to the screen too
+ next.Render(camera);
next.DrawToBuffer(FrameBufferUint, 1, 1, Width, Height);
}
}
diff --git a/CorgEng.Rendering/Icons/Icon.cs b/CorgEng.Rendering/Icons/Icon.cs
index 9529ea89..5862177a 100644
--- a/CorgEng.Rendering/Icons/Icon.cs
+++ b/CorgEng.Rendering/Icons/Icon.cs
@@ -1,4 +1,5 @@
-using CorgEng.Core.Dependencies;
+using CorgEng.Core;
+using CorgEng.Core.Dependencies;
using CorgEng.GenericInterfaces.Rendering.Icons;
using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
using CorgEng.GenericInterfaces.Rendering.Textures;
@@ -65,8 +66,8 @@ public float Layer
/// The renderer that should be used in order to render this icon.
/// Will trigger ValueChanged when updated.
///
- private uint plane;
- public uint Plane
+ private int plane;
+ public int Plane
{
get => plane;
set
@@ -85,7 +86,7 @@ public ISpriteRenderer Renderer
get
{
if (_cachedRenderer == null)
- _cachedRenderer = RendererLookup.GetRendererByIdentifier(Plane);
+ _cachedRenderer = (ISpriteRenderer)CorgEngMain.GetRendererForPlane(Plane);
return _cachedRenderer;
}
}
@@ -104,7 +105,7 @@ public IMatrix Transform
}
}
- public Icon(string iconName, float layer, uint plane)
+ public Icon(string iconName, float layer, int plane)
{
IconName = iconName;
Layer = layer;
@@ -119,7 +120,7 @@ public void DeserialiseFrom(BinaryReader binaryReader)
{
IconName = AutoSerialiser.Deserialize(typeof(string), binaryReader) as string;
Layer = (float)AutoSerialiser.Deserialize(typeof(float), binaryReader);
- Plane = (uint)AutoSerialiser.Deserialize(typeof(uint), binaryReader);
+ Plane = (int)AutoSerialiser.Deserialize(typeof(int), binaryReader);
DirectionalState = (DirectionalState)AutoSerialiser.Deserialize(typeof(int), binaryReader);
Colour = (IVector)AutoSerialiser.Deserialize(typeof(Vector), binaryReader);
}
@@ -128,7 +129,7 @@ public int GetSerialisationLength()
{
return AutoSerialiser.SerialisationLength(typeof(string), IconName)
+ AutoSerialiser.SerialisationLength(typeof(float), Layer)
- + AutoSerialiser.SerialisationLength(typeof(uint), Plane)
+ + AutoSerialiser.SerialisationLength(typeof(int), Plane)
+ AutoSerialiser.SerialisationLength(typeof(int), (int)DirectionalState)
+ AutoSerialiser.SerialisationLength(typeof(Vector), Colour);
}
@@ -137,7 +138,7 @@ public void SerialiseInto(BinaryWriter binaryWriter)
{
AutoSerialiser.SerializeInto(typeof(string), IconName, binaryWriter);
AutoSerialiser.SerializeInto(typeof(float), Layer, binaryWriter);
- AutoSerialiser.SerializeInto(typeof(uint), Plane, binaryWriter);
+ AutoSerialiser.SerializeInto(typeof(int), Plane, binaryWriter);
AutoSerialiser.SerializeInto(typeof(int), (int)DirectionalState, binaryWriter);
AutoSerialiser.SerializeInto(typeof(Vector), Colour, binaryWriter);
}
diff --git a/CorgEng.Rendering/Icons/IconFactory.cs b/CorgEng.Rendering/Icons/IconFactory.cs
index 291e7b80..525ef043 100644
--- a/CorgEng.Rendering/Icons/IconFactory.cs
+++ b/CorgEng.Rendering/Icons/IconFactory.cs
@@ -13,7 +13,7 @@ namespace CorgEng.Rendering.Icons
internal class IconFactory : IIconFactory
{
- public IIcon CreateIcon(string name, float layer, uint plane)
+ public IIcon CreateIcon(string name, float layer, int plane)
{
return new Icon(name, layer, plane);
}
diff --git a/CorgEng.Rendering/InstancedRenderer.cs b/CorgEng.Rendering/InstancedRenderer.cs
index c0558792..f5a2d91e 100644
--- a/CorgEng.Rendering/InstancedRenderer.cs
+++ b/CorgEng.Rendering/InstancedRenderer.cs
@@ -1,12 +1,14 @@
using CorgEng.Constants;
using CorgEng.Core;
using CorgEng.Core.Dependencies;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Logging;
using CorgEng.GenericInterfaces.Rendering;
using CorgEng.GenericInterfaces.Rendering.Renderers;
using CorgEng.GenericInterfaces.Rendering.RenderObjects;
using CorgEng.GenericInterfaces.Rendering.Shaders;
using CorgEng.GenericInterfaces.Rendering.SharedRenderAttributes;
+using CorgEng.GenericInterfaces.UtilityTypes;
using CorgEng.GenericInterfaces.UtilityTypes.Batches;
using System;
using System.Collections.Generic;
@@ -18,14 +20,25 @@
namespace CorgEng.Rendering
{
- internal static class InstancedRendererDependencyHolder
+ public abstract class InstancedRendererDependencyHolder : WorldObject
{
[UsingDependency]
internal static ILogger Logger;
- }
- public abstract class InstancedRenderer : IRenderer
- where TSharedRenderAttributes : ISharedRenderAttributes
+ //Fetch shader loading from some dependency somewhere
+ [UsingDependency]
+ protected static IShaderFactory ShaderFactory;
+
+ [UsingDependency]
+ protected static IColourFactory ColourFactory;
+
+ protected InstancedRendererDependencyHolder(IWorld world) : base(world)
+ {
+ }
+ }
+
+ public abstract partial class InstancedRenderer : PlaneRenderer, IRenderer
+ where TSharedRenderAttributes : ISharedRenderAttributes
where TBatch : IBatch, new()
{
@@ -44,24 +57,18 @@ public abstract class InstancedRenderer : IRend
//The location of buffers that we are using
protected uint[] storedBufferLocations;
- //Used to identifier the networker
- public uint NetworkIdentifier { get; }
+ public int Plane { get; private set; }
- public InstancedRenderer(uint networkIdentifier)
- {
- //Set the network identifier
- NetworkIdentifier = networkIdentifier;
- //Do the renderer lookup
- if (networkIdentifier != RenderingConstants.NETWORK_RENDERING_ID_LOCAL)
- {
- InstancedRendererDependencyHolder.Logger.WriteLine($"Added renderer on plane ID {networkIdentifier}", LogType.DEBUG);
- RendererLookup.AddRenderer(this);
- }
- }
+ public bool Initialized { get; set; } = false;
- public void Initialize()
+ public override void Initialize()
{
- CreateShaders();
+ base.Initialize();
+ if (Initialized)
+ throw new Exception($"Render core {GetType()} is initialised already.");
+ Initialized = true;
+ // Create the shaders
+ CreateShaders();
//Create a program for the renderer
programUint = glCreateProgram();
//Setup the program:
@@ -77,7 +84,7 @@ public void Initialize()
protected abstract void CreateShaders();
- public void Render(ICamera camera)
+ public override void Render(ICamera camera)
{
if (ShaderSet == null)
throw new Exception("Attempting to use a renderer before it has been initialised. Please call Initialize() first.");
@@ -154,11 +161,15 @@ public void Render(ICamera camera)
private int viewMatrixUniformLocation;
private int projectionMatrixUniformLocation;
- ///
- /// Bind the texture if your batches use textures
- ///
- ///
- protected virtual void BindBatchTexture(TSharedRenderAttributes batchAttributes)
+ protected InstancedRenderer(IWorld world) : base(world)
+ {
+ }
+
+ ///
+ /// Bind the texture if your batches use textures
+ ///
+ ///
+ protected virtual void BindBatchTexture(TSharedRenderAttributes batchAttributes)
{ }
///
@@ -270,6 +281,5 @@ protected unsafe void BindAttribArray(uint index, uint buffer, int size)
NULL //Array buffer offset (null)
);
}
-
- }
+ }
}
diff --git a/CorgEng.Rendering/PlaneRenderer.cs b/CorgEng.Rendering/PlaneRenderer.cs
new file mode 100644
index 00000000..7b7e2294
--- /dev/null
+++ b/CorgEng.Rendering/PlaneRenderer.cs
@@ -0,0 +1,384 @@
+using CorgEng.Core;
+using CorgEng.Core.Dependencies;
+using CorgEng.Core.Rendering;
+using CorgEng.GenericInterfaces.Core;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
+using CorgEng.GenericInterfaces.Logging;
+using CorgEng.GenericInterfaces.Rendering;
+using CorgEng.GenericInterfaces.Rendering.Renderers;
+using CorgEng.GenericInterfaces.Rendering.Shaders;
+using CorgEng.GenericInterfaces.Rendering.SharedRenderAttributes;
+using CorgEng.GenericInterfaces.UtilityTypes;
+using CorgEng.GenericInterfaces.UtilityTypes.Batches;
+using System;
+using System.Collections.Generic;
+using static OpenGL.Gl;
+
+namespace CorgEng.Rendering
+{
+ public abstract partial class PlaneRenderer : InstancedRendererDependencyHolder, IDisposable
+ {
+
+ private static float[] quadVertices = {
+ 1, 1, 0,
+ 1, -1, 0,
+ -1, 1, 0,
+ -1, 1, 0,
+ 1, -1, 0,
+ -1, -1, 0
+ };
+
+ private static bool initialized = false;
+
+ //The vertex array and buffer objects
+ private static uint vertexArray;
+ private static uint vertexBuffer;
+
+ private static IShaderSet shaderSet;
+
+ private static IShaderSet depthShaderSet;
+
+ private static int textureUniformLocation;
+
+ private static int depthUniformLocation;
+
+ private static int depthIncrementUniformLocation;
+
+ //Create a program for rendering
+ private static uint planeDrawingProgramUint;
+
+ ///
+ /// The uint of the frame buffer
+ ///
+ public uint FrameBufferUint { get; private set; }
+
+ ///
+ /// The uint of the render buffer
+ ///
+ public uint RenderBufferUint { get; private set; }
+
+ ///
+ /// The uint of our render texture
+ ///
+ public uint RenderTextureUint { get; private set; }
+
+ ///
+ /// The ID of the depth texture generated by rendering this render core.
+ ///
+ public uint DepthTextureUint { get; private set; }
+
+ public int Width { get; internal set; } = 1920;
+
+ public int Height { get; internal set; } = 1080;
+
+ private static IColour _currentBackColour;
+ private static DepthModes _currentDepthMode = DepthModes.KEEP_DEPTH;
+ private static RenderModes _currentBlendMode = RenderModes.DEFAULT;
+
+ ///
+ /// The render mode to use when drawing this render core to the framebuffer.
+ ///
+ public virtual RenderModes DrawMode { get; } = RenderModes.DEFAULT;
+
+ ///
+ /// The render mode to use when rendering elements on to the render core.
+ ///
+ public virtual RenderModes BlendMode { get; } = RenderModes.DEFAULT;
+
+ ///
+ /// Should we keep depth?
+ /// Ignoring depth causes the render core to overlay on whatever it is being drawn on.
+ ///
+ public virtual DepthModes DepthMode { get; } = DepthModes.KEEP_DEPTH;
+
+ ///
+ /// The scaling mode of this render core.
+ ///
+ public virtual ScalingModes ScalingMode { get; } = ScalingModes.NEAREST_NEIGHBOUR;
+
+ ///
+ /// If this is set to true, the render core will be allowed to be resized through the Resize() function.
+ ///
+ public virtual bool CanResize { get; } = true;
+
+ ///
+ /// The path of the shaders to use.
+ /// Only accessed during initialisation.
+ ///
+ public virtual string ShaderPath => "CoreShader";
+
+ ///
+ /// The back colour of the plane. By default, fully transparent black.
+ ///
+ public virtual IColour BackColour { get; } = ColourFactory.GetColour(0, 0, 0, 0);
+
+ ///
+ /// How much depth should we add to this render core?
+ ///
+ public virtual float DepthAdd { get; } = 0;
+
+ public unsafe virtual void Initialize()
+ {
+ if (!CorgEngMain.IsRendering)
+ return;
+ //Generate a render buff
+ RenderBufferUint = glGenRenderbuffer();
+ glBindRenderbuffer(RenderBufferUint);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, Width, Height);
+ //Generate a frame buffer
+ FrameBufferUint = glGenFramebuffer();
+ glBindFramebuffer(GL_FRAMEBUFFER, FrameBufferUint);
+ //Create a render texture
+ glActiveTexture(GL_TEXTURE0);
+ RenderTextureUint = glGenTexture();
+ //Bind the created texture so we can modify it
+ glBindTexture(GL_TEXTURE_2D, RenderTextureUint);
+ //Load the texture scale
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ //Set the texture parameters
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ //Bind the framebuffer to the texture
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, RenderTextureUint, 0);
+
+ //=========================
+ // Setup the depth texture
+ //=========================
+ glActiveTexture(GL_TEXTURE1);
+ DepthTextureUint = glGenTexture();
+ glBindTexture(GL_TEXTURE_2D, DepthTextureUint);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RenderBufferUint);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, DepthTextureUint, 0);
+
+ //Check for issues
+ if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+ {
+ //TODO: Introduce a rendering mode that bypasses framebuffers and just draws directly to the screen.
+ //Slightly broken is better than nothing.
+ Logger.WriteLine("WARNING: FRAMEBUFFER ERROR. Your GPU may not support this application!", LogType.ERROR);
+ }
+ //Log creation
+ Logger?.WriteLine($"Created RenderCore, rendering to framebuffer {FrameBufferUint} outputting texture to {RenderTextureUint}", LogType.DEBUG);
+ // Prepare for rendering if we need
+ SetupRendering();
+ }
+
+ public unsafe static void SetupRendering()
+ {
+ //Create stuff we need for screen rendering (static)
+ if (!initialized)
+ {
+ Logger?.WriteLine("Initialized RenderCore static requirements.", LogType.LOG);
+ //Mark initialized to be true.
+ initialized = true;
+ //create and link a program
+ planeDrawingProgramUint = glCreateProgram();
+ //Start using the program: All operations will affect this program
+ glUseProgram(planeDrawingProgramUint);
+ //Generate a vertex array and bind it
+ vertexArray = glGenVertexArray();
+ glBindVertexArray(vertexArray);
+ //Create and bind the vertex buffer
+ vertexBuffer = glGenBuffer();
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
+
+ //Put data into the buffer
+ fixed (float* vertexPointer = &quadVertices[0])
+ {
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float) * quadVertices.Length, vertexPointer, GL_STATIC_DRAW);
+ }
+ //Create the shaders
+ shaderSet = ShaderFactory.CreateShaderSet("CoreShader");
+ //Get the uniform location of the shaders
+ shaderSet.AttachShaders(planeDrawingProgramUint);
+ glLinkProgram(planeDrawingProgramUint);
+ //Fetch uniform locations
+ textureUniformLocation = glGetUniformLocation(planeDrawingProgramUint, "renderTexture");
+ depthUniformLocation = glGetUniformLocation(planeDrawingProgramUint, "depthTexture");
+ depthIncrementUniformLocation = glGetUniformLocation(planeDrawingProgramUint, "depthIncrement");
+ }
+ }
+
+ private static Dictionary loadedShaders = new Dictionary();
+
+ protected PlaneRenderer(IWorld world) : base(world)
+ {
+ }
+
+ private IShaderSet GetShader(string name)
+ {
+ if (!loadedShaders.ContainsKey(name))
+ {
+ IShaderSet createdShader = ShaderFactory.CreateShaderSet(name);
+ loadedShaders.Add(name, createdShader);
+ }
+ return loadedShaders[name];
+ }
+
+ ///
+ /// Do rendering
+ ///
+ public void DoRender(ICamera camera)
+ {
+ RenderModes prev = SwitchBlendMode(BlendMode);
+ DepthModes prevDepth = SwitchDepthMode(DepthMode);
+ IColour prevColour = SwitchBackColour(BackColour);
+ PreRender();
+ Render(camera);
+ SwitchBlendMode(prev);
+ SwitchDepthMode(prevDepth);
+ SwitchBackColour(prevColour);
+ }
+
+ public void PreRender()
+ {
+ //Bind our framebuffer to render to
+ glBindFramebuffer(GL_FRAMEBUFFER, FrameBufferUint);
+ //Clear the backbuffer
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ //Set the viewport
+ glViewport(0, 0, Width, Height);
+ }
+
+ ///
+ /// Render whatever we need to render to the plane.
+ ///
+ ///
+ public abstract void Render(ICamera camera);
+
+ protected static RenderModes SwitchBlendMode(RenderModes newMode)
+ {
+ if (newMode == _currentBlendMode)
+ return newMode;
+ RenderModes prevMode = _currentBlendMode;
+ _currentBlendMode = newMode;
+ switch (_currentBlendMode)
+ {
+ case RenderModes.DEFAULT:
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ break;
+ case RenderModes.MULTIPLY:
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
+ break;
+ case RenderModes.ADDITIVE:
+ glBlendFunc(GL_ONE, GL_ONE);
+ break;
+ }
+ return prevMode;
+ }
+
+ protected static DepthModes SwitchDepthMode(DepthModes newMode)
+ {
+ if (newMode == _currentDepthMode)
+ return newMode;
+ DepthModes prevMode = _currentDepthMode;
+ _currentDepthMode = newMode;
+ switch (_currentDepthMode)
+ {
+ case DepthModes.KEEP_DEPTH:
+ glDepthFunc(GL_LEQUAL);
+ break;
+ case DepthModes.IGNORE_DEPTH:
+ glDepthFunc(GL_ALWAYS);
+ break;
+ }
+ return prevMode;
+ }
+
+ protected static IColour SwitchBackColour(IColour newColour)
+ {
+ if (newColour == null || newColour.Equals(_currentBackColour))
+ return newColour;
+ IColour prevCol = _currentBackColour;
+ _currentBackColour = newColour;
+ glClearColor(newColour.Red, newColour.Green, newColour.Blue, newColour.Alpha);
+ return prevCol;
+ }
+
+ public unsafe void Resize(int width, int height)
+ {
+ //Set the new width
+ Width = width;
+ Height = height;
+ //Log
+ Logger?.WriteLine($"Render core resized to {Width}x{Height}", LogType.DEBUG);
+ if (!CorgEngMain.IsRendering || !CanResize)
+ return;
+ //Update the tex image
+ //Bind the created texture so we can modify it
+ glBindTexture(GL_TEXTURE_2D, RenderTextureUint);
+ //Load the texture scale
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ //Set the texture parameters
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScalingMode == ScalingModes.NEAREST_NEIGHBOUR ? GL_NEAREST : GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ScalingMode == ScalingModes.NEAREST_NEIGHBOUR ? GL_NEAREST : GL_LINEAR);
+ // Bind the depth texture
+ glBindTexture(GL_TEXTURE_2D, DepthTextureUint);
+ //Load the texture scale
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
+ //Set the texture parameters
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScalingMode == ScalingModes.NEAREST_NEIGHBOUR ? GL_NEAREST : GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ScalingMode == ScalingModes.NEAREST_NEIGHBOUR ? GL_NEAREST : GL_LINEAR);
+ }
+
+ public unsafe void DrawToBuffer(uint buffer, int drawX, int drawY, int bufferWidth, int bufferHeight)
+ {
+ //Reset the framebuffer (We want to draw to the screen, not a frame buffer)
+ glBindFramebuffer(GL_FRAMEBUFFER, buffer);
+ //Draw to full screen
+ glViewport(drawX, drawY, bufferWidth, bufferHeight);
+
+ //Setup blending
+ RenderModes prevRender = SwitchBlendMode(DrawMode);
+ DepthModes prevBlend = SwitchDepthMode(DepthMode);
+ IColour prevColour = SwitchBackColour(BackColour);
+
+ //Set the using program to our program uint
+ glUseProgram(planeDrawingProgramUint);
+ //Bind uniform variables
+ glUniform1i(textureUniformLocation, 0);
+ glUniform1i(depthUniformLocation, 1);
+ glUniform1f(depthIncrementUniformLocation, DepthAdd);
+ //Bind the vertex buffer
+ glEnableVertexAttribArray(0);
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
+ glVertexAttribPointer(
+ 0, //Attribute - Where the layout location is in the vertex shader
+ 3, //Size of the triangles (3 sides)
+ GL_FLOAT, //Type (Floats)
+ false, //Normalized (nope)
+ 0, //Stride (0)
+ NULL //Array buffer offset (null)
+ );
+ //Set the vertex attrib divisor
+ glVertexAttribDivisor(0, 0);
+ //Bind the texture
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, RenderTextureUint);
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, DepthTextureUint);
+ //Draw
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+ //Disable the vertex attrib array
+ glDisableVertexAttribArray(0);
+
+ SwitchBlendMode(prevRender);
+ SwitchDepthMode(prevBlend);
+ SwitchBackColour(prevColour);
+ }
+
+ ///
+ /// Dispose the render core and cleanup any resources
+ ///
+ public void Dispose()
+ {
+ glDeleteRenderbuffer(RenderBufferUint);
+ glDeleteFramebuffer(FrameBufferUint);
+ glDeleteTexture(RenderTextureUint);
+ }
+
+ }
+}
diff --git a/CorgEng.Rendering/RendererLookup.cs b/CorgEng.Rendering/RendererLookup.cs
deleted file mode 100644
index bd24f5f9..00000000
--- a/CorgEng.Rendering/RendererLookup.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using CorgEng.GenericInterfaces.Rendering.SharedRenderAttributes;
-using CorgEng.GenericInterfaces.UtilityTypes.Batches;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CorgEng.Rendering
-{
- public static class RendererLookup
- {
-
- ///
- /// The renderer lookup table
- ///
- private static IDictionary rendererLookup = new Dictionary();
-
- internal static void AddRenderer(InstancedRenderer renderer)
- where T : ISharedRenderAttributes
- where R : IBatch, new()
- {
- rendererLookup.Add(renderer.NetworkIdentifier, renderer);
- }
-
- public static T GetRendererByIdentifier(uint identifier)
- {
- return (T)rendererLookup[identifier];
- }
-
- }
-}
diff --git a/CorgEng.Rendering/SpriteRendering/Parallax/ParallaxRenderer.cs b/CorgEng.Rendering/SpriteRendering/Parallax/ParallaxRenderer.cs
index ee934066..b7a1d738 100644
--- a/CorgEng.Rendering/SpriteRendering/Parallax/ParallaxRenderer.cs
+++ b/CorgEng.Rendering/SpriteRendering/Parallax/ParallaxRenderer.cs
@@ -1,4 +1,5 @@
-using CorgEng.GenericInterfaces.Rendering.Renderers.ParallaxRenderer;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
+using CorgEng.GenericInterfaces.Rendering.Renderers.ParallaxRenderer;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,10 +10,10 @@ namespace CorgEng.Rendering.SpriteRendering.Parallax
{
internal class ParallaxRenderer : SpriteRenderer, IParallaxRenderer
{
- internal ParallaxRenderer(uint networkedId) : base(networkedId)
- { }
+ public ParallaxRenderer(IWorld world) : base(world)
+ { }
- protected override void CreateShaders()
+ protected override void CreateShaders()
{
_shaderSet = ShaderFactory.CreateShaderSet("ParallaxShader");
}
diff --git a/CorgEng.Rendering/SpriteRendering/Parallax/ParallaxRendererFactory.cs b/CorgEng.Rendering/SpriteRendering/Parallax/ParallaxRendererFactory.cs
index a27919e9..4d3c9699 100644
--- a/CorgEng.Rendering/SpriteRendering/Parallax/ParallaxRendererFactory.cs
+++ b/CorgEng.Rendering/SpriteRendering/Parallax/ParallaxRendererFactory.cs
@@ -1,4 +1,5 @@
using CorgEng.DependencyInjection.Dependencies;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Rendering.Renderers.ParallaxRenderer;
using System;
using System.Collections.Generic;
@@ -11,9 +12,9 @@ namespace CorgEng.Rendering.SpriteRendering.Parallax
[Dependency]
internal class ParallaxRendererFactory : IParallaxRendererFactory
{
- public IParallaxRenderer CreateParallaxRenderer(uint networkedIdentifier)
+ public IParallaxRenderer CreateParallaxRenderer(IWorld world, int plane)
{
- return new ParallaxRenderer(networkedIdentifier);
+ return new ParallaxRenderer(world);
}
}
}
diff --git a/CorgEng.Rendering/SpriteRendering/SpriteBatch.cs b/CorgEng.Rendering/SpriteRendering/SpriteBatch.cs
index 2360ea15..0ee69b1e 100644
--- a/CorgEng.Rendering/SpriteRendering/SpriteBatch.cs
+++ b/CorgEng.Rendering/SpriteRendering/SpriteBatch.cs
@@ -10,7 +10,7 @@
namespace CorgEng.Rendering.SpriteRendering
{
- internal sealed class SpriteBatch : Batch
+ public sealed class SpriteBatch : Batch
{
public override int[] BatchVectorSizes { get; } = new int[] { 3, 3, 4, 1, 4 };
diff --git a/CorgEng.Rendering/SpriteRendering/SpriteRenderer.cs b/CorgEng.Rendering/SpriteRendering/SpriteRenderer.cs
index 1e6a3ff7..d8b935ec 100644
--- a/CorgEng.Rendering/SpriteRendering/SpriteRenderer.cs
+++ b/CorgEng.Rendering/SpriteRendering/SpriteRenderer.cs
@@ -1,5 +1,6 @@
using CorgEng.Core.Dependencies;
using CorgEng.DependencyInjection.Dependencies;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Rendering;
using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
using CorgEng.GenericInterfaces.Rendering.RenderObjects.SpriteRendering;
@@ -20,19 +21,18 @@
namespace CorgEng.Rendering.SpriteRendering
{
- internal class SpriteRenderer : InstancedRenderer, ISpriteRenderer
+ public class SpriteRenderer : InstancedRenderer, ISpriteRenderer
{
- [UsingDependency]
- protected static IShaderFactory ShaderFactory;
-
protected IShaderSet _shaderSet;
protected override IShaderSet ShaderSet => _shaderSet;
- internal SpriteRenderer(uint networkedId) : base(networkedId) { }
+ public SpriteRenderer(IWorld world) : base(world)
+ {
+ }
- protected override void CreateShaders()
+ protected override void CreateShaders()
{
_shaderSet = ShaderFactory.CreateShaderSet("SpriteShader");
}
@@ -71,9 +71,9 @@ public void StopRendering(ISpriteRenderObject spriteRenderObject)
spriteRenderObject.SetBelongingBatchElement(null);
}
- private int textureSamplerUniformLocation;
+ private int textureSamplerUniformLocation;
- protected override void LoadUniformVariableLocations()
+ protected override void LoadUniformVariableLocations()
{
base.LoadUniformVariableLocations();
textureSamplerUniformLocation = glGetUniformLocation(programUint, "renderTexture");
diff --git a/CorgEng.Rendering/SpriteRendering/SpriteRendererFactory.cs b/CorgEng.Rendering/SpriteRendering/SpriteRendererFactory.cs
index d0ad7ccf..6a86d7e7 100644
--- a/CorgEng.Rendering/SpriteRendering/SpriteRendererFactory.cs
+++ b/CorgEng.Rendering/SpriteRendering/SpriteRendererFactory.cs
@@ -1,4 +1,5 @@
using CorgEng.DependencyInjection.Dependencies;
+using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
using System;
using System.Collections.Generic;
@@ -12,10 +13,11 @@ namespace CorgEng.Rendering.SpriteRendering
public class SpriteRendererFactory : ISpriteRendererFactory
{
- public ISpriteRenderer CreateSpriteRenderer(uint networkedIdentifier)
+ public ISpriteRenderer CreateSpriteRenderer(IWorld world, int plane)
{
- return new SpriteRenderer(networkedIdentifier);
- }
+ var spriteRenderer = new SpriteRenderer(world);
+ return spriteRenderer;
+ }
}
}
diff --git a/CorgEng.Tests/EntityComponentSystem/ProcessingSystemTest.cs b/CorgEng.Tests/EntityComponentSystem/ProcessingSystemTest.cs
index fe4cc63e..a59e75ec 100644
--- a/CorgEng.Tests/EntityComponentSystem/ProcessingSystemTest.cs
+++ b/CorgEng.Tests/EntityComponentSystem/ProcessingSystemTest.cs
@@ -58,7 +58,7 @@ public override void SystemSetup(IWorld world)
public void TestProcessingSystems()
{
IWorld world = WorldFactory.CreateWorld();
- CorgEngMain.PrimaryWorld = world;
+ CorgEngMain.World = world;
//Create an entity to process
IEntity testEntity = world.EntityManager.CreateEmptyEntity(null);
TestComponent testComponent = new TestComponent();
diff --git a/CorgEng.Tests/Stubs/IRenderCoreStubFactory.cs b/CorgEng.Tests/Stubs/IRenderCoreStubFactory.cs
deleted file mode 100644
index 53024684..00000000
--- a/CorgEng.Tests/Stubs/IRenderCoreStubFactory.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using CorgEng.GenericInterfaces.Core;
-using CorgEng.GenericInterfaces.UserInterface.Rendering;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CorgEng.Tests.Stubs
-{
- /*internal class IRenderCoreStubFactory : IUserInterfaceRenderCoreFactory
- {
- public IRenderCore Create()
- {
- return new RenderCoreStub();
- }
- }*/
-}
diff --git a/CorgEng.Tests/Stubs/RenderCoreStub.cs b/CorgEng.Tests/Stubs/RenderCoreStub.cs
deleted file mode 100644
index 72f55bc5..00000000
--- a/CorgEng.Tests/Stubs/RenderCoreStub.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using CorgEng.GenericInterfaces.Core;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CorgEng.Tests.Stubs
-{
- internal class RenderCoreStub : IRenderCore
- {
- public uint FrameBufferUint => 0;
-
- public uint RenderTextureUint => 0;
-
- public int Width => 0;
-
- public int Height => 0;
-
- public void DoRender(Action preRenderAction = null)
- {
- return;
- }
-
- public void DrawToBuffer()
- {
- return;
- }
-
- public void DrawToBuffer(uint buffer, int drawX, int drawY, int bufferWidth, int bufferHeight)
- {
- return;
- }
-
- public void Initialize()
- {
- return;
- }
-
- public void Resize(int width, int height)
- {
- return;
- }
- }
-}
diff --git a/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceBox.cs b/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceBox.cs
index 0390e42d..4de222e7 100644
--- a/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceBox.cs
+++ b/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceBox.cs
@@ -2,6 +2,7 @@
using CorgEng.Core.Dependencies;
using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Logging;
+using CorgEng.GenericInterfaces.Rendering;
using CorgEng.GenericInterfaces.UserInterface.Anchors;
using CorgEng.GenericInterfaces.UserInterface.Components;
using CorgEng.GenericInterfaces.UtilityTypes;
@@ -66,11 +67,11 @@ public override void Initialize()
userInterfaceBoxRenderer.StartRendering(boxRenderObject);
}
- public override void PerformRender()
- {
- if (!CorgEngMain.IsRendering)
- return;
- userInterfaceBoxRenderer.Render(Width, Height);
- }
- }
+ public override void Render(ICamera camera)
+ {
+ if (!CorgEngMain.IsRendering)
+ return;
+ userInterfaceBoxRenderer.Render(Width, Height);
+ }
+ }
}
diff --git a/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceComponent.cs b/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceComponent.cs
index e26212af..22105ca5 100644
--- a/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceComponent.cs
+++ b/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceComponent.cs
@@ -5,10 +5,12 @@
using CorgEng.GenericInterfaces.Core;
using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Logging;
+using CorgEng.GenericInterfaces.Rendering;
using CorgEng.GenericInterfaces.UserInterface.Anchors;
using CorgEng.GenericInterfaces.UserInterface.Components;
using CorgEng.GenericInterfaces.UserInterface.Rendering;
using CorgEng.GenericInterfaces.UserInterface.Rendering.Renderer;
+using CorgEng.Rendering;
using CorgEng.UserInterface.Hooks;
using CorgEng.UserInterface.Rendering;
using System;
@@ -20,7 +22,7 @@
namespace CorgEng.UserInterface.Components
{
- internal class UserInterfaceComponent : RenderCore, IUserInterfaceComponent
+ internal class UserInterfaceComponent : PlaneRenderer, IUserInterfaceComponent
{
private static int IdCounter = 0;
@@ -249,20 +251,20 @@ private void ParseArguments(IDictionary arguments)
// Component Rendering Interfaces
//====================================
- private static void Render(UserInterfaceComponent userInterfaceComponent, uint buffer, bool drawOnTop = false)
+ private static void Render(ICamera camera, UserInterfaceComponent userInterfaceComponent, uint buffer, bool drawOnTop = false)
{
//Not initalized yet
if (!userInterfaceComponent.initialized)
return;
//Resize if necessary
- if (userInterfaceComponent.Fullscreen && userInterfaceComponent.Parent == null && (userInterfaceComponent.PixelWidth != CorgEngMain.MainRenderCore.Width || userInterfaceComponent.PixelHeight != CorgEngMain.MainRenderCore.Height))
+ if (userInterfaceComponent.Fullscreen && userInterfaceComponent.Parent == null && (userInterfaceComponent.PixelWidth != CorgEngMain.GameWindow.Width || userInterfaceComponent.PixelHeight != CorgEngMain.GameWindow.Height))
{
- userInterfaceComponent.SetWidth(CorgEngMain.MainRenderCore.Width, CorgEngMain.MainRenderCore.Height);
+ userInterfaceComponent.SetWidth(CorgEngMain.GameWindow.Width, CorgEngMain.GameWindow.Height);
}
//Switch to the correct render core and draw it to the framebuffer
if (userInterfaceComponent.RenderInclude)
{
- userInterfaceComponent.DoRender();
+ userInterfaceComponent.DoRender(camera);
}
else
{
@@ -275,7 +277,7 @@ private static void Render(UserInterfaceComponent userInterfaceComponent, uint b
foreach (IUserInterfaceComponent childComponent in userInterfaceComponent.GetChildren())
{
//Render the child component to our buffer
- Render(childComponent as UserInterfaceComponent, userInterfaceComponent.FrameBufferUint);
+ Render(camera, childComponent as UserInterfaceComponent, userInterfaceComponent.FrameBufferUint);
}
}
if (drawOnTop)
@@ -299,7 +301,7 @@ public void DrawToFramebuffer(uint frameBuffer)
{
try
{
- Render(this, frameBuffer, drawOnTop: true);
+ Render(CorgEngMain.MainCamera, this, frameBuffer, drawOnTop: true);
}
catch (Exception e)
{
@@ -532,8 +534,9 @@ public void SetWidth(double width, double height)
}
}
- public override void Initialize()
+ public override void Initialize()
{
+ base.Initialize();
if (initialiseCallbackFunction != null)
{
UserInterfaceModule.KeyMethods[initialiseCallbackFunction].Invoke(null, new object[] { this });
@@ -542,9 +545,6 @@ public override void Initialize()
initialized = true;
}
- public override void PerformRender()
- { }
-
public virtual IUserInterfaceComponent Screencast(int relativeX, int relativeY)
{
//If outside bounds, return nothing
@@ -596,5 +596,10 @@ public object GetData(string dataName)
{
return dataStore[dataName];
}
- }
+
+ public override void Render(ICamera camera)
+ {
+ throw new NotImplementedException();
+ }
+ }
}
diff --git a/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceIcon.cs b/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceIcon.cs
index 35cd6c3e..2e18aa2d 100644
--- a/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceIcon.cs
+++ b/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceIcon.cs
@@ -3,6 +3,7 @@
using CorgEng.Core.Dependencies;
using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Logging;
+using CorgEng.GenericInterfaces.Rendering;
using CorgEng.GenericInterfaces.Rendering.Icons;
using CorgEng.GenericInterfaces.Rendering.Textures;
using CorgEng.GenericInterfaces.UserInterface.Anchors;
@@ -72,8 +73,8 @@ public override void Initialize()
userInterfaceIconRenderer.StartRendering(userInterfaceIconRenderObject);
}
- public override void PerformRender()
- {
+ public override void Render(ICamera camera)
+ {
if (!CorgEngMain.IsRendering)
return;
userInterfaceIconRenderer.Render(Width, Height);
diff --git a/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceText.cs b/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceText.cs
index dfc4ee7a..b37c3968 100644
--- a/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceText.cs
+++ b/CorgEng.UserInterface/UserInterfaceComponents/UserInterfaceText.cs
@@ -2,6 +2,7 @@
using CorgEng.Core.Dependencies;
using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Font.Fonts;
+using CorgEng.GenericInterfaces.Rendering;
using CorgEng.GenericInterfaces.Rendering.Cameras.Isometric;
using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
using CorgEng.GenericInterfaces.Rendering.Text;
@@ -60,7 +61,7 @@ private void Setup(IDictionary arguments)
//Create the camera
IsometricCamera = IsometricCameraFactory.CreateCamera();
//Create the renderer (Local, since UI)
- spriteRenderer = SpriteRendererFactory.CreateSpriteRenderer(Constants.RenderingConstants.NETWORK_RENDERING_ID_LOCAL);
+ spriteRenderer = SpriteRendererFactory.CreateSpriteRenderer(world, Constants.RenderingConstants.NETWORK_RENDERING_ID_LOCAL);
spriteRenderer.Initialize();
//Get the font to use
string typeface;
@@ -79,8 +80,8 @@ private void Setup(IDictionary arguments)
});
}
- public override void PerformRender()
- {
+ public override void Render(ICamera camera)
+ {
if (!ready)
return;
IsometricCamera.X = 0.8f;
diff --git a/DmiIconConversionUtility/DmiIconConversionUtility.csproj b/DmiIconConversionUtility/DmiIconConversionUtility.csproj
index 5be6542c..40cdfed4 100644
--- a/DmiIconConversionUtility/DmiIconConversionUtility.csproj
+++ b/DmiIconConversionUtility/DmiIconConversionUtility.csproj
@@ -53,6 +53,6 @@
all
-
+
\ No newline at end of file