From 171c27ab8035758c5ff05f61ea84d2bb60cdd7ef Mon Sep 17 00:00:00 2001 From: Harrison Date: Thu, 20 Feb 2020 04:17:39 -0500 Subject: [PATCH] New batching structure base files. --- .../Render/{TextureBatch.cs => Batch.cs} | 7 ++-- RecrownedGTK/Graphics/Texture.cs | 33 +++-------------- RecrownedGTK/Graphics/TextureData.cs | 35 +++++++++++++++++++ 3 files changed, 44 insertions(+), 31 deletions(-) rename RecrownedGTK/Graphics/Render/{TextureBatch.cs => Batch.cs} (81%) create mode 100644 RecrownedGTK/Graphics/TextureData.cs diff --git a/RecrownedGTK/Graphics/Render/TextureBatch.cs b/RecrownedGTK/Graphics/Render/Batch.cs similarity index 81% rename from RecrownedGTK/Graphics/Render/TextureBatch.cs rename to RecrownedGTK/Graphics/Render/Batch.cs index caaab18..1d2a17b 100644 --- a/RecrownedGTK/Graphics/Render/TextureBatch.cs +++ b/RecrownedGTK/Graphics/Render/Batch.cs @@ -1,14 +1,15 @@ using System; namespace RecrownedGTK.Graphics.Render { - public class TextureBatch { + public class Batch { private bool begun; - public TextureBatch() { - //TODO Finish batch. + public Batch() { + //TODO: Finish this class. } public void Begin() { if (begun) throw new InvalidOperationException("This batch has already been started."); begun = true; } + public void End() { if (!begun) throw new InvalidOperationException("The batch has not begun."); begun = false; diff --git a/RecrownedGTK/Graphics/Texture.cs b/RecrownedGTK/Graphics/Texture.cs index 9f7c08c..561f30e 100644 --- a/RecrownedGTK/Graphics/Texture.cs +++ b/RecrownedGTK/Graphics/Texture.cs @@ -1,34 +1,11 @@ -using System.Drawing; -using System.IO; - namespace RecrownedGTK.Graphics { - public class Texture : IRectangleDrawable { - //TODO Complete a basic texture capable of being rendered by a batch. - byte[] textureData; - public byte[] ColorData { - get { - return textureData; - } - } + public class Texture : IDrawable { public Texture() { + } - - public Texture(byte[] textureData) { - this.textureData = textureData; - } - - public Texture(string path) { - LoadFromPNG(path); - } - - public void LoadFromPNG(string path) { - using (FileStream file = new FileStream(path, FileMode.Open)) { - using (Bitmap bitmap = new Bitmap(file)) { - ImageConverter converter = new ImageConverter(); - textureData = (byte[]) converter.ConvertTo(bitmap, typeof(byte[])); - } - } - + public void Draw(out float[] vertices, out float[] indices, out TextureData textureData) { + throw new System.NotImplementedException(); + //TODO: Implement this. } } } \ No newline at end of file diff --git a/RecrownedGTK/Graphics/TextureData.cs b/RecrownedGTK/Graphics/TextureData.cs new file mode 100644 index 0000000..5a349ed --- /dev/null +++ b/RecrownedGTK/Graphics/TextureData.cs @@ -0,0 +1,35 @@ +using System.Drawing; +using System.IO; +using OpenTK.Graphics.OpenGL; +namespace RecrownedGTK.Graphics { + public class TextureData { + int handle; + byte[] textureData; + public byte[] ColorData { + get { + return textureData; + } + } + + public TextureData(string path) { + LoadFromPNG(path); + } + public TextureData() { + //TODO: Finish this class. + } + public TextureData(byte[] textureData, int width, int height, int mipmap = 0) { + this.textureData = textureData; + GL.TexImage2D(TextureTarget.Texture2D, mipmap, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, textureData); + } + + public void LoadFromPNG(string path) { + using (FileStream file = new FileStream(path, FileMode.Open)) { + using (Bitmap bitmap = new Bitmap(file)) { + ImageConverter converter = new ImageConverter(); + textureData = (byte[]) converter.ConvertTo(bitmap, typeof(byte[])); + } + } + + } + } +} \ No newline at end of file