Allow Canvases to be used as Textures sometimes;

This commit is contained in:
bjorn 2018-08-29 03:42:22 -07:00
parent 36ec69e244
commit 6b87a71261
5 changed files with 16 additions and 5 deletions

View File

@ -121,3 +121,4 @@ int luax_pushvariant(lua_State* L, Variant* variant);
int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* dest, const char* debug);
void luax_checkuniformtype(lua_State* L, int index, UniformType* baseType, int* components);
int luax_optmipmap(lua_State* L, int index, Texture* texture);
Texture* luax_checktexture(lua_State* L, int index);

View File

@ -829,7 +829,7 @@ int l_lovrGraphicsSphere(lua_State* L) {
}
int l_lovrGraphicsSkybox(lua_State* L) {
Texture* texture = luax_checktype(L, 1, Texture);
Texture* texture = luax_checktexture(L, 1);
float angle = luaL_optnumber(L, 2, 0);
float ax = luaL_optnumber(L, 3, 0);
float ay = luaL_optnumber(L, 4, 1);
@ -864,7 +864,7 @@ int l_lovrGraphicsStencil(lua_State* L) {
}
int l_lovrGraphicsFill(lua_State* L) {
Texture* texture = lua_isnoneornil(L, 1) ? NULL : luax_checktype(L, 1, Texture);
Texture* texture = lua_isnoneornil(L, 1) ? NULL : luax_checktexture(L, 1);
lovrGraphicsFill(texture);
return 0;
}
@ -1005,7 +1005,7 @@ int l_lovrGraphicsNewMaterial(lua_State* L) {
lovrRelease(textureData);
lovrRelease(texture);
} else if (lua_isuserdata(L, index)) {
Texture* texture = luax_checktype(L, index, Texture);
Texture* texture = luax_checktexture(L, index);
lovrMaterialSetTexture(material, TEXTURE_DIFFUSE, texture);
index++;
}

View File

@ -2,6 +2,16 @@
#include "graphics/canvas.h"
#include "graphics/graphics.h"
Texture* luax_checktexture(lua_State* L, int index) {
Canvas* canvas = luax_totype(L, index, Canvas);
if (canvas) {
const Attachment* attachment = lovrCanvasGetAttachments(canvas, NULL);
return attachment->texture;
} else {
return luax_checktype(L, index, Texture);
}
}
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;

View File

@ -57,7 +57,7 @@ int l_lovrMaterialSetTexture(lua_State* L) {
textureType = luaL_checkoption(L, index, NULL, MaterialTextures);
index++;
}
Texture* texture = lua_isnoneornil(L, index) ? NULL : luax_checktype(L, index, Texture);
Texture* texture = lua_isnoneornil(L, index) ? NULL : luax_checktexture(L, index);
lovrMaterialSetTexture(material, textureType, texture);
return 0;
}

View File

@ -538,7 +538,7 @@ static void lovrGpuUseProgram(uint32_t program) {
static void lovrGpuSetViewports(float viewports[][4], int viewportCount, int index) {
#ifdef GL_ARB_viewport_array
if (state.supportsSinglepass) {
glViewportArrayv(0, viewportCount, viewports);
glViewportArrayv(0, viewportCount, &viewports[0][0]);
} else {
#endif
glViewport(viewports[index][0], viewports[index][1], viewports[index][2], viewports[index][3]);