mirror of https://github.com/bjornbytes/lovr.git
Canvas getters;
This commit is contained in:
parent
3c78eae42b
commit
4215ea2e24
|
@ -21,6 +21,29 @@ static int luax_checkattachment(lua_State* L, int index, Attachment* attachment)
|
|||
return index;
|
||||
}
|
||||
|
||||
int l_lovrCanvasNewTextureData(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
int index = luaL_optinteger(L, 2, 1) - 1;
|
||||
int count;
|
||||
lovrCanvasGetAttachments(canvas, &count);
|
||||
lovrAssert(index >= 0 && index < count, "Can not create a TextureData from Texture #%d of Canvas (it only has %d textures)", index, count);
|
||||
TextureData* textureData = lovrCanvasNewTextureData(canvas, index);
|
||||
luax_pushobject(L, textureData);
|
||||
lovrRelease(textureData);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int l_lovrCanvasGetTexture(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
int count;
|
||||
|
@ -46,33 +69,56 @@ int l_lovrCanvasSetTexture(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrCanvasNewTextureData(lua_State* L) {
|
||||
int l_lovrCanvasGetWidth(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
int index = luaL_optinteger(L, 2, 1) - 1;
|
||||
int count;
|
||||
lovrCanvasGetAttachments(canvas, &count);
|
||||
lovrAssert(index >= 0 && index < count, "Can not create a TextureData from Texture #%d of Canvas (it only has %d textures)", index, count);
|
||||
TextureData* textureData = lovrCanvasNewTextureData(canvas, index);
|
||||
luax_pushobject(L, textureData);
|
||||
lovrRelease(textureData);
|
||||
lua_pushinteger(L, lovrCanvasGetWidth(canvas));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrCanvasRenderTo(lua_State* L) {
|
||||
int l_lovrCanvasGetHeight(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;
|
||||
lua_pushinteger(L, lovrCanvasGetHeight(canvas));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrCanvasGetDimensions(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
lua_pushinteger(L, lovrCanvasGetWidth(canvas));
|
||||
lua_pushinteger(L, lovrCanvasGetHeight(canvas));
|
||||
return 2;
|
||||
}
|
||||
|
||||
int l_lovrCanvasGetDepthFormat(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
DepthFormat format = lovrCanvasGetDepthFormat(canvas);
|
||||
lua_pushstring(L, DepthFormats[format]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrCanvasGetMSAA(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
int msaa = lovrCanvasGetMSAA(canvas);
|
||||
lua_pushinteger(L, msaa);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrCanvasIsStereo(lua_State* L) {
|
||||
Canvas* canvas = luax_checktype(L, 1, Canvas);
|
||||
bool stereo = lovrCanvasIsStereo(canvas);
|
||||
lua_pushboolean(L, stereo);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg lovrCanvas[] = {
|
||||
{ "getTexture", l_lovrCanvasGetTexture },
|
||||
{ "setTexture", l_lovrCanvasSetTexture },
|
||||
{ "newTextureData", l_lovrCanvasNewTextureData },
|
||||
{ "renderTo", l_lovrCanvasRenderTo },
|
||||
{ "getTexture", l_lovrCanvasGetTexture },
|
||||
{ "setTexture", l_lovrCanvasSetTexture },
|
||||
{ "getWidth", l_lovrCanvasGetWidth },
|
||||
{ "getHeight", l_lovrCanvasGetHeight },
|
||||
{ "getDimensions", l_lovrCanvasGetDimensions },
|
||||
{ "getDepthFormat", l_lovrCanvasGetDepthFormat },
|
||||
{ "getMSAA", l_lovrCanvasGetMSAA },
|
||||
{ "isStereo", l_lovrCanvasIsStereo },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -34,6 +34,8 @@ void lovrCanvasBind(Canvas* canvas);
|
|||
void lovrCanvasResolve(Canvas* canvas);
|
||||
void lovrCanvasBlit(Canvas* canvas);
|
||||
bool lovrCanvasIsStereo(Canvas* canvas);
|
||||
uint32_t lovrCanvasGetWidth(Canvas* canvas);
|
||||
uint32_t lovrCanvasGetHeight(Canvas* canvas);
|
||||
int lovrCanvasGetWidth(Canvas* canvas);
|
||||
int lovrCanvasGetHeight(Canvas* canvas);
|
||||
int lovrCanvasGetMSAA(Canvas* canvas);
|
||||
DepthFormat lovrCanvasGetDepthFormat(Canvas* canvas);
|
||||
TextureData* lovrCanvasNewTextureData(Canvas* canvas, int index);
|
||||
|
|
|
@ -1327,8 +1327,8 @@ void lovrCanvasSetAttachments(Canvas* canvas, Attachment* attachments, int count
|
|||
Texture* texture = attachments[i].texture;
|
||||
int width = lovrTextureGetWidth(texture, attachments[i].level);
|
||||
int height = lovrTextureGetHeight(texture, attachments[i].level);
|
||||
lovrAssert(width == canvas->width, "Texture width of %d does not match Canvas width", width);
|
||||
lovrAssert(height == canvas->height, "Texture height of %d does not match Canvas height", height);
|
||||
lovrAssert(!canvas->depthBuffer || width == canvas->width, "Texture width of %d does not match Canvas width", width);
|
||||
lovrAssert(!canvas->depthBuffer || height == canvas->height, "Texture height of %d does not match Canvas height", height);
|
||||
lovrAssert(texture->msaa == canvas->flags.msaa, "Texture MSAA does not match Canvas MSAA");
|
||||
lovrRetain(texture);
|
||||
}
|
||||
|
@ -1447,14 +1447,22 @@ bool lovrCanvasIsStereo(Canvas* canvas) {
|
|||
return canvas->flags.stereo;
|
||||
}
|
||||
|
||||
uint32_t lovrCanvasGetWidth(Canvas* canvas) {
|
||||
int lovrCanvasGetWidth(Canvas* canvas) {
|
||||
return canvas->width;
|
||||
}
|
||||
|
||||
uint32_t lovrCanvasGetHeight(Canvas* canvas) {
|
||||
int lovrCanvasGetHeight(Canvas* canvas) {
|
||||
return canvas->height;
|
||||
}
|
||||
|
||||
int lovrCanvasGetMSAA(Canvas* canvas) {
|
||||
return canvas->flags.msaa;
|
||||
}
|
||||
|
||||
DepthFormat lovrCanvasGetDepthFormat(Canvas* canvas) {
|
||||
return canvas->flags.depth;
|
||||
}
|
||||
|
||||
TextureData* lovrCanvasNewTextureData(Canvas* canvas, int index) {
|
||||
lovrCanvasBind(canvas);
|
||||
|
||||
|
|
Loading…
Reference in New Issue