Nullable fixes, use Texture2d resource for rendering directly.

This commit is contained in:
2024-01-21 17:34:49 +01:00
parent cfbf46860d
commit 5f4e32e2e0
10 changed files with 105 additions and 74 deletions

View File

@@ -117,35 +117,14 @@ namespace DaggerFramework.Rendering
_rotation = rotation;
}
public override int LoadTexture(Texture2d texture)
public override void DrawTexture(Texture2d texture, Color tint)
{
Image image = new Image();
unsafe
if (texture.Handle == -1)
{
fixed (void* dataPtr = texture.Buffer)
{
image.data = dataPtr;
}
LoadTexture(texture);
}
image.width = texture.Width;
image.height = texture.Height;
image.mipmaps = 1;
image.format = PixelFormat.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
Texture2D rayTexture;
rayTexture = Raylib.LoadTextureFromImage(image);
_texturePool.Add(rayTexture);
return _texturePool.Count - 1;
}
public override void DrawTexture(int id, Color tint)
{
Raylib.DrawTextureV(_texturePool[id], _position, DaggerColorToRaylibColor(tint));
Raylib.DrawTextureV(_texturePool[texture.Handle], _position, DaggerColorToRaylibColor(tint));
}
public override void DrawRectangle(Vector2 size, Color color)
@@ -206,12 +185,12 @@ namespace DaggerFramework.Rendering
public override void DrawText(Font font, string text, Color color)
{
if (font.FontHandle == -1)
if (font.Handle == -1)
{
LoadFont(font);
}
var rayFont = _fontPool[font.FontHandle];
var rayFont = _fontPool[font.Handle];
Raylib.DrawTextPro(rayFont, text, _position, Vector2.Zero, _rotation, font.Size, 0.0f, DaggerColorToRaylibColor(color));
}
@@ -255,7 +234,33 @@ namespace DaggerFramework.Rendering
_fontPool.Add(fontRay);
font.FontHandle = _fontPool.Count - 1;
font.Handle = _fontPool.Count - 1;
}
private void LoadTexture(Texture2d texture)
{
Image image = new();
unsafe
{
fixed (void* dataPtr = texture.Buffer)
{
image.data = dataPtr;
}
}
image.width = texture.Width;
image.height = texture.Height;
image.mipmaps = texture.Mipmaps;
image.format = (PixelFormat)texture.Format;
Texture2D rayTexture;
rayTexture = Raylib.LoadTextureFromImage(image);
_texturePool.Add(rayTexture);
texture.Handle = _texturePool.Count - 1;
}

View File

@@ -79,13 +79,6 @@ namespace DaggerFramework.Rendering
/// <param name="color">Background color.</param>
public abstract void ClearBackground(Color color);
/// <summary>
/// Loads the texture onto the GPU for later use in DrawTexture or other Texture related methods.
/// </summary>
/// <param name="texture">Texture to load.</param>
/// <returns>A texture handler on the GPU.</returns>
public abstract int LoadTexture(Texture2d texture);
/// <summary>
/// Sets transforms for the next draw operation.
/// </summary>
@@ -131,9 +124,9 @@ namespace DaggerFramework.Rendering
/// <summary>
/// Draws the texture.
/// </summary>
/// <param name="id">Texture handle.</param>
/// <param name="id">Texture to draw.</param>
/// <param name="tint">Texture tint.</param>
public abstract void DrawTexture(int id, Color tint);
public abstract void DrawTexture(Texture2d texture, Color tint);
}
public enum Msaa

View File

@@ -83,7 +83,7 @@ namespace DaggerFramework.Rendering
}
/// <inheritdoc />
public override void DrawTexture(int id, Color tint)
public override void DrawTexture(Texture2d texture, Color tint)
{
throw new NotImplementedException();
}
@@ -94,12 +94,6 @@ namespace DaggerFramework.Rendering
return 0.0;
}
/// <inheritdoc />
public override int LoadTexture(Texture2d texture)
{
throw new NotImplementedException();
}
/// <inheritdoc />
protected override void SetTargetFps(int fps)
{
@@ -196,7 +190,6 @@ namespace DaggerFramework.Rendering
throw new NotImplementedException();
}
private GL _gl;
private Glfw _glfw;
private unsafe WindowHandle* _windowHandle;