2017-12-10 20:40:37 +00:00
|
|
|
#include "api.h"
|
2017-12-07 07:50:52 +00:00
|
|
|
#include "graphics/canvas.h"
|
2018-08-24 21:47:35 +00:00
|
|
|
#include "graphics/graphics.h"
|
2017-12-07 07:50:52 +00:00
|
|
|
|
2018-08-22 04:08:40 +00:00
|
|
|
static int luax_checkattachment(lua_State* L, int index, Attachment* attachment) {
|
|
|
|
attachment->texture = luax_checktype(L, index++, Texture);
|
|
|
|
attachment->slice = lua_type(L, index) == LUA_TNUMBER ? lua_tointeger(L, index++) - 1 : 0;
|
|
|
|
attachment->level = lua_type(L, index) == LUA_TNUMBER ? lua_tointeger(L, index++) - 1 : 0;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
int l_lovrCanvasGetTexture(lua_State* L) {
|
2018-08-24 01:28:37 +00:00
|
|
|
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
|
|
|
int count;
|
|
|
|
const Attachment* attachments = lovrCanvasGetAttachments(canvas, &count);
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
luax_pushobject(L, attachments[i].texture);
|
|
|
|
}
|
|
|
|
return count;
|
2018-08-22 04:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int l_lovrCanvasSetTexture(lua_State* L) {
|
|
|
|
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
2018-08-24 01:28:37 +00:00
|
|
|
Attachment attachments[MAX_CANVAS_ATTACHMENTS];
|
|
|
|
int count;
|
2018-08-22 04:08:40 +00:00
|
|
|
int index = 2;
|
2018-08-24 01:28:37 +00:00
|
|
|
int top = lua_gettop(L);
|
|
|
|
for (count = 0; count < MAX_CANVAS_ATTACHMENTS && index <= top; count++) {
|
|
|
|
index = luax_checkattachment(L, index, attachments + count);
|
2018-08-22 04:08:40 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 01:28:37 +00:00
|
|
|
lovrCanvasSetAttachments(canvas, attachments, count);
|
2018-08-22 04:08:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-24 21:47:35 +00:00
|
|
|
int l_lovrCanvasRenderTo(lua_State* L) {
|
|
|
|
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
|
|
|
luaL_checktype(L, 2, LUA_TFUNCTION);
|
|
|
|
int argumentCount = lua_gettop(L) - 2;
|
|
|
|
Canvas* old = lovrGraphicsGetCanvas();
|
|
|
|
lovrGraphicsSetCanvas(canvas);
|
|
|
|
lua_call(L, argumentCount, 0);
|
|
|
|
lovrGraphicsSetCanvas(old);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-07 07:50:52 +00:00
|
|
|
const luaL_Reg lovrCanvas[] = {
|
2018-08-22 04:08:40 +00:00
|
|
|
{ "getTexture", l_lovrCanvasGetTexture },
|
|
|
|
{ "setTexture", l_lovrCanvasSetTexture },
|
2018-08-24 21:47:35 +00:00
|
|
|
{ "renderTo", l_lovrCanvasRenderTo },
|
2017-12-07 07:50:52 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|