Skip to content

Commit

Permalink
Fixed up some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareantics committed Jan 10, 2024
1 parent f6bda83 commit e194da4
Show file tree
Hide file tree
Showing 36 changed files with 533 additions and 298 deletions.
3 changes: 2 additions & 1 deletion FinalEngine.Audio/ISound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace FinalEngine.Audio;

using System;
using FinalEngine.Resources;

public interface ISound : IResource
public interface ISound : IResource, IDisposable
{
bool IsLooping { get; set; }

Expand Down
34 changes: 33 additions & 1 deletion FinalEngine.Examples.Sponza/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using FinalEngine.Rendering.OpenGL.Invocation;
using FinalEngine.Rendering.Primitives;
using FinalEngine.Rendering.Renderers;
using FinalEngine.Rendering.Textures;
using FinalEngine.Resources;
using FinalEngine.Runtime;
using FinalEngine.Runtime.Invocation;
Expand Down Expand Up @@ -123,7 +124,14 @@ private static void Main()
3
];

var mesh = new Mesh(renderDevice.Factory, vertices, indices, true);
var mesh = new Mesh<MeshVertex>(
renderDevice.Factory,
vertices,
indices,
MeshVertex.InputElements,
MeshVertex.SizeInBytes,
MeshVertex.CalculateNormals,
MeshVertex.CalculateTangents);

var material = new Material()
{
Expand All @@ -139,6 +147,30 @@ private static void Main()
var skyboxRenderer = new SkyboxRenderer(renderDevice);
var renderingEngine = new RenderingEngine(renderDevice, geometryRenderer, lightRenderer, skyboxRenderer);

var right = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\Skybox\\default_right.png");
var left = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\Skybox\\default_left.png");
var top = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\Skybox\\default_top.png");
var bottom = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\Skybox\\default_bottom.png");
var front = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\Skybox\\default_front.png");
var back = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\Skybox\\default_back.png");

var cubeTexture = renderDevice.Factory.CreateCubeTexture(new TextureCubeDescription()
{
Width = right.Description.Width,
Height = right.Description.Height,
WrapR = TextureWrapMode.Clamp,
WrapS = TextureWrapMode.Clamp,
WrapT = TextureWrapMode.Clamp,
},
right,
left,
top,
bottom,
back,
front);

renderingEngine.SetSkybox(cubeTexture);

var controller = new ImGuiController(window.ClientSize.Width, window.ClientSize.Height);

var light = new Light()
Expand Down
1 change: 0 additions & 1 deletion FinalEngine.Rendering.OpenGL/Buffers/OpenGLFrameBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace FinalEngine.Rendering.OpenGL.Buffers;
using FinalEngine.Rendering.OpenGL.Invocation;
using FinalEngine.Rendering.OpenGL.Textures;
using OpenTK.Graphics.OpenGL4;
using PixelFormat = Rendering.Textures.PixelFormat;

public class OpenGLFrameBuffer : IFrameBuffer, IOpenGLFrameBuffer
{
Expand Down
35 changes: 17 additions & 18 deletions FinalEngine.Rendering.OpenGL/Invocation/IOpenGLInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ public interface IOpenGLInvoker

void CompileShader(int shader);

void CopyImageSubData(
int srcName,
ImageTarget srcTarget,
int srcLevel,
int srcX,
int srcY,
int srcZ,
int dstName,
ImageTarget dstTarget,
int dstLevel,
int dstX,
int dstY,
int dstZ,
int srcWidth,
int srcHeight,
int srcDepth);

int CreateBuffer();

int CreateFramebuffer();
Expand Down Expand Up @@ -94,8 +111,6 @@ public interface IOpenGLInvoker

int GenVertexArray();

void GetActiveUniform(int program, int index, int bufSize, out int length, out int size, out ActiveUniformType type, out string name);

void GetInteger(GetIndexedPName target, int index, int[] data);

int GetInteger(GetPName pname);
Expand Down Expand Up @@ -148,22 +163,6 @@ void NamedBufferSubData<T3>(int buffer, IntPtr offset, int size, T3[] data)

void TextureSubImage2D(int texture, int level, int xoffset, int yoffset, int width, int height, PixelFormat format, PixelType type, IntPtr pixels);

void CopyImageSubData(int srcName,
ImageTarget srcTarget,
int srcLevel,
int srcX,
int srcY,
int srcZ,
int dstName,
ImageTarget dstTarget,
int dstLevel,
int dstX,
int dstY,
int dstZ,
int srcWidth,
int srcHeight,
int srcDepth);

void Uniform1(int location, int x);

void Uniform1(int location, float v0);
Expand Down
19 changes: 5 additions & 14 deletions FinalEngine.Rendering.OpenGL/Invocation/OpenGLInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,6 @@ public int GenVertexArray()
return GL.GenVertexArray();
}

public void GetActiveUniform(int program, int index, int bufSize, out int length, out int size,
out ActiveUniformType type, out string name)
{
GL.GetActiveUniform(program, index, bufSize, out length, out size, out type, out name);
}

public void GetInteger(GetIndexedPName target, int index, int[] data)
{
GL.GetInteger(target, index, data);
Expand Down Expand Up @@ -358,14 +352,13 @@ public void TextureStorage2D(int texture, int levels, SizedInternalFormat intern
GL.TextureStorage2D(texture, levels, internalFormat, width, height);
}

public void TextureSubImage2D(int texture, int level, int xoffset, int yoffset, int width, int height,
PixelFormat format, PixelType type, IntPtr pixels)
public void TextureSubImage2D(int texture, int level, int xoffset, int yoffset, int width, int height, PixelFormat format, PixelType type, IntPtr pixels)
{
GL.TextureSubImage2D(texture, level, xoffset, yoffset, width, height, format, type, pixels);
}


public void CopyImageSubData(int srcName,
public void CopyImageSubData(
int srcName,
ImageTarget srcTarget,
int srcLevel,
int srcX,
Expand All @@ -381,8 +374,7 @@ public void CopyImageSubData(int srcName,
int srcHeight,
int srcDepth)
{
GL.CopyImageSubData(srcName, srcTarget, srcLevel, srcX, srcY, srcZ, dstName, dstTarget, dstLevel, dstX, dstY,
dstZ, srcWidth, srcHeight, srcDepth);
GL.CopyImageSubData(srcName, srcTarget, srcLevel, srcX, srcY, srcZ, dstName, dstTarget, dstLevel, dstX, dstY, dstZ, srcWidth, srcHeight, srcDepth);
}

public void Uniform1(int location, int x)
Expand Down Expand Up @@ -435,8 +427,7 @@ public void VertexAttribBinding(int attribindex, int bindingindex)
GL.VertexAttribBinding(attribindex, bindingindex);
}

public void VertexAttribFormat(int attribindex, int size, VertexAttribType type, bool normalized,
int relativeoffset)
public void VertexAttribFormat(int attribindex, int size, VertexAttribType type, bool normalized, int relativeoffset)
{
GL.VertexAttribFormat(attribindex, size, type, normalized, relativeoffset);
}
Expand Down
32 changes: 25 additions & 7 deletions FinalEngine.Rendering.OpenGL/OpenGLGPUResourceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace FinalEngine.Rendering.OpenGL;
using FinalEngine.Rendering.Textures;
using FinalEngine.Utilities;
using OpenTK.Graphics.OpenGL4;
using static System.Runtime.InteropServices.JavaScript.JSType;
using PixelFormat = FinalEngine.Rendering.Textures.PixelFormat;

public class OpenGLGPUResourceFactory : IGPUResourceFactory
Expand All @@ -32,6 +31,31 @@ public OpenGLGPUResourceFactory(IOpenGLInvoker invoker, IEnumMapper mapper)
this.mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
}

public ITextureCube CreateCubeTexture(
TextureCubeDescription description,
ITexture2D right,
ITexture2D left,
ITexture2D top,
ITexture2D bottom,
ITexture2D back,
ITexture2D front,
SizedFormat internalFormat = SizedFormat.Rgba8)
{
ArgumentNullException.ThrowIfNull(right, nameof(right));
ArgumentNullException.ThrowIfNull(left, nameof(left));
ArgumentNullException.ThrowIfNull(left, nameof(top));
ArgumentNullException.ThrowIfNull(left, nameof(bottom));
ArgumentNullException.ThrowIfNull(left, nameof(back));
ArgumentNullException.ThrowIfNull(left, nameof(front));

var cubeFaces = new List<ITexture2D>()
{
right, left, top, bottom, front, back,
};

return new OpenGLTextureCube(this.invoker, this.mapper, description, internalFormat, cubeFaces.Cast<IOpenGLTexture>().ToArray().AsReadOnly());
}

public IFrameBuffer CreateFrameBuffer(IReadOnlyCollection<ITexture2D>? colorTargets, ITexture2D? depthTarget = null)
{
if (depthTarget is not null and not IOpenGLTexture)
Expand Down Expand Up @@ -83,12 +107,6 @@ public ITexture2D CreateTexture2D<T>(
return result;
}

public ICubeTexture CreateCubeTexture(CubeTextureDescription description, ITexture2D right, ITexture2D left, ITexture2D top,
ITexture2D bottom, ITexture2D back, ITexture2D front, SizedFormat internalFormat = SizedFormat.Rgba8)
{
var cubeFaces = new List<ITexture2D>(){right,left,top,bottom,front,back};
return new OpenglCubeTexture(this.invoker, this.mapper, description, internalFormat, cubeFaces.Cast<IOpenGLTexture>().ToArray());
}
public IVertexBuffer CreateVertexBuffer<T>(BufferUsageType type, IReadOnlyCollection<T> data, int sizeInBytes, int stride)
where T : struct
{
Expand Down
2 changes: 1 addition & 1 deletion FinalEngine.Rendering.OpenGL/OpenGLRenderDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public OpenGLRenderDevice(IOpenGLInvoker invoker)
{ SizedFormat.Rg8, SizedInternalFormat.Rg8 },
{ SizedFormat.Rgb8, All.Rgb8 },
{ SizedFormat.Rgba8, SizedInternalFormat.Rgba8 },
{ SizedFormat.Depth, SizedInternalFormat.DepthComponent32f },
{ SizedFormat.Depth, SizedInternalFormat.DepthComponent16 },
{ SizedFormat.Srgba, SizedInternalFormat.Srgb8Alpha8 },
{ BufferUsageType.Static, BufferUsageHint.StaticDraw },
{ BufferUsageType.Dynamic, BufferUsageHint.DynamicDraw },
Expand Down
14 changes: 12 additions & 2 deletions FinalEngine.Rendering.OpenGL/Textures/IOpenGLTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ namespace FinalEngine.Rendering.OpenGL.Textures;

public interface IOpenGLTexture : ITexture
{
// TODO : delete?
int RenderId { get; }
void Attach(FramebufferAttachment type, int framebuffer);

void Bind(int unit);

void CopyImageSubData(
int srcLevel,
int srcX,
int srcY,
int srcZ,
int dstName,
ImageTarget dstTarget,
int dstLevel,
int dstX,
int dstY,
int dstZ);
}
38 changes: 30 additions & 8 deletions FinalEngine.Rendering.OpenGL/Textures/OpenGLTexture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ public OpenGLTexture2D(

protected bool IsDisposed { get; private set; }

public int RenderId
{
get
{
return this.rendererID;
}
}

public void Attach(FramebufferAttachment type, int framebuffer)
{
ObjectDisposedException.ThrowIf(this.IsDisposed, this);
Expand All @@ -101,6 +93,36 @@ public void Bind(int unit)
this.invoker.BindTextureUnit(unit, this.rendererID);
}

public void CopyImageSubData(
int srcLevel,
int srcX,
int srcY,
int srcZ,
int dstName,
ImageTarget dstTarget,
int dstLevel,
int dstX,
int dstY,
int dstZ)
{
this.invoker.CopyImageSubData(
this.rendererID,
ImageTarget.Texture2D,
srcLevel,
srcX,
srcY,
srcZ,
dstName,
dstTarget,
dstLevel,
dstX,
dstY,
dstZ,
this.Description.Width,
this.Description.Height,
1);
}

public void Dispose()
{
this.Dispose(true);
Expand Down
Loading

0 comments on commit e194da4

Please sign in to comment.