mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
Add gpu.loadImage
This commit is contained in:
parent
e5e2d58f62
commit
0068509357
1 changed files with 44 additions and 1 deletions
|
@ -2,8 +2,10 @@
|
||||||
using Capy64.Runtime.Objects;
|
using Capy64.Runtime.Objects;
|
||||||
using KeraLua;
|
using KeraLua;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Capy64.Runtime.Libraries;
|
namespace Capy64.Runtime.Libraries;
|
||||||
|
|
||||||
|
@ -112,6 +114,11 @@ public class GPU : IPlugin
|
||||||
name = "drawBuffer",
|
name = "drawBuffer",
|
||||||
function = L_DrawBuffer,
|
function = L_DrawBuffer,
|
||||||
},
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
name = "loadImage",
|
||||||
|
function = L_LoadImage,
|
||||||
|
},
|
||||||
new(), // NULL
|
new(), // NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -424,7 +431,6 @@ public class GPU : IPlugin
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// WIP
|
|
||||||
private static int L_DrawBuffer(IntPtr state)
|
private static int L_DrawBuffer(IntPtr state)
|
||||||
{
|
{
|
||||||
var L = Lua.FromIntPtr(state);
|
var L = Lua.FromIntPtr(state);
|
||||||
|
@ -468,4 +474,41 @@ public class GPU : IPlugin
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int L_LoadImage(IntPtr state)
|
||||||
|
{
|
||||||
|
var L = Lua.FromIntPtr(state);
|
||||||
|
|
||||||
|
var path = L.CheckString(1);
|
||||||
|
|
||||||
|
path = FileSystem.Resolve(path);
|
||||||
|
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
L.Error("file not found");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D texture;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
texture = Texture2D.FromFile(Capy64.Instance.Drawing.Canvas.GraphicsDevice, path);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
L.Error(e.Message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = new uint[texture.Width * texture.Height];
|
||||||
|
texture.GetData(data);
|
||||||
|
|
||||||
|
GPUBuffer.Push(L, data);
|
||||||
|
L.PushInteger(texture.Width);
|
||||||
|
L.PushInteger(texture.Height);
|
||||||
|
|
||||||
|
texture.Dispose();
|
||||||
|
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue