mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
Add gpu.drawBuffer
This commit is contained in:
parent
50461558e4
commit
8eddd69616
1 changed files with 38 additions and 9 deletions
|
@ -107,6 +107,11 @@ public class GPU : IPlugin
|
||||||
name = "newBuffer",
|
name = "newBuffer",
|
||||||
function = L_NewBuffer,
|
function = L_NewBuffer,
|
||||||
},
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
name = "drawBuffer",
|
||||||
|
function = L_DrawBuffer,
|
||||||
|
},
|
||||||
new(), // NULL
|
new(), // NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -420,23 +425,47 @@ public class GPU : IPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
// WIP
|
// WIP
|
||||||
private static int L_CopyBuffer(IntPtr state)
|
private static int L_DrawBuffer(IntPtr state)
|
||||||
{
|
{
|
||||||
var L = Lua.FromIntPtr(state);
|
var L = Lua.FromIntPtr(state);
|
||||||
|
|
||||||
var x = L.CheckInteger(1);
|
var from = L.CheckObject<uint[]>(1, GPUBuffer.ObjectType, false);
|
||||||
var y = L.CheckInteger(2);
|
|
||||||
|
|
||||||
var from = L.CheckObject<uint[]>(3, GPUBuffer.ObjectType, false);
|
|
||||||
if (from is null)
|
if (from is null)
|
||||||
{
|
{
|
||||||
L.ArgumentError(3, GPUBuffer.ObjectType + " expected, got " + L.TypeName(L.Type(3)));
|
L.ArgumentError(1, GPUBuffer.ObjectType + " expected, got " + L.TypeName(L.Type(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
var origin = new uint[_game.Width * _game.Height];
|
var x = (int)L.CheckInteger(2) - 1;
|
||||||
_game.Drawing.Canvas.GetData(origin);
|
var y = (int)L.CheckInteger(3) - 1;
|
||||||
|
var w = (int)L.CheckInteger(4);
|
||||||
|
var h = (int)L.CheckInteger(5);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_game.Drawing.Canvas.SetData(0, new Rectangle
|
||||||
|
{
|
||||||
|
X = x,
|
||||||
|
Y = y,
|
||||||
|
Width = w,
|
||||||
|
Height = h,
|
||||||
|
}, from, 0, from.Length);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (w * h != from.Length)
|
||||||
|
{
|
||||||
|
L.Error("buffer size does not match width and height");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(x < 0 || y < 0 || x + w >= _game.Drawing.Canvas.Width || y + h >= _game.Drawing.Canvas.Height)
|
||||||
|
{
|
||||||
|
L.Error("position out of bounds");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
L.Error(e.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue