Refactor ResourceLoader, use only Texture2d in Renderer.
This commit is contained in:
@@ -2,7 +2,6 @@ using System.Drawing;
|
||||
using System.Numerics;
|
||||
|
||||
using Silk.NET.GLFW;
|
||||
using Silk.NET.Maths;
|
||||
using Silk.NET.OpenGL;
|
||||
|
||||
namespace DaggerFramework.Rendering
|
||||
@@ -71,11 +70,6 @@ namespace DaggerFramework.Rendering
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int LoadTexture(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SetTargetFps(int fps)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace DaggerFramework.Rendering
|
||||
|
||||
public override void CreateWindow(string title, Vector2 size)
|
||||
{
|
||||
Raylib.SetTraceLogLevel(TraceLogLevel.LOG_NONE);
|
||||
// Raylib.SetTraceLogLevel(TraceLogLevel.LOG_NONE);
|
||||
_windowSize = size;
|
||||
Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, title);
|
||||
}
|
||||
@@ -77,41 +77,30 @@ namespace DaggerFramework.Rendering
|
||||
|
||||
public override int LoadTexture(Texture2d texture)
|
||||
{
|
||||
Image image;
|
||||
Texture2D rayTexture;
|
||||
string ext = "png";
|
||||
byte[] extBytes = Encoding.ASCII.GetBytes(ext);
|
||||
Image image = new Image();
|
||||
|
||||
// TODO: This can cause memory leaks.
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* textureData = texture.Data)
|
||||
fixed (void* dataPtr = texture.Buffer)
|
||||
{
|
||||
fixed (byte* bExt = extBytes)
|
||||
{
|
||||
sbyte* sbExt = (sbyte*)*bExt;
|
||||
image = Raylib.LoadImageFromMemory(sbExt, textureData, texture.Data.Length);
|
||||
}
|
||||
image.data = dataPtr;
|
||||
}
|
||||
}
|
||||
|
||||
image.width = texture.Width;
|
||||
image.height = texture.Height;
|
||||
image.mipmaps = 1;
|
||||
image.format = PixelFormat.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
|
||||
Texture2D rayTexture;
|
||||
|
||||
rayTexture = Raylib.LoadTextureFromImage(image);
|
||||
Raylib.UnloadImage(image);
|
||||
|
||||
_texturePool.Add(rayTexture);
|
||||
|
||||
return _texturePool.Count - 1;
|
||||
}
|
||||
|
||||
public override int LoadTexture(string path)
|
||||
{
|
||||
Image image = Raylib.LoadImage(path);
|
||||
var rayTexture = Raylib.LoadTextureFromImage(image);
|
||||
Raylib.UnloadImage(image);
|
||||
|
||||
_texturePool.Add(rayTexture);
|
||||
return _texturePool.Count - 1;
|
||||
}
|
||||
|
||||
public override void DrawTexture(int id, System.Drawing.Color tint)
|
||||
{
|
||||
Raylib.DrawTextureV(_texturePool[id], _position, SystemColorToRaylibColor(tint));
|
||||
|
||||
@@ -22,12 +22,6 @@ namespace DaggerFramework.Rendering
|
||||
public abstract void ClearBackground(Color color);
|
||||
public abstract double GetFrameTime();
|
||||
public abstract int LoadTexture(Texture2d texture);
|
||||
/// <summary>
|
||||
/// Temporary workaround for Raylib's LoadImageFromMemory.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public abstract int LoadTexture(string path);
|
||||
public abstract void SetTransform(Vector2 position, float rotation = 0.0f);
|
||||
public abstract void SetTransform(Matrix4x4 transform);
|
||||
public abstract void DrawCircle(float radius, Color color);
|
||||
|
||||
Reference in New Issue
Block a user