diff --git a/src/api.h b/src/api.h index f987adfb..8ced41e8 100644 --- a/src/api.h +++ b/src/api.h @@ -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); diff --git a/src/api/graphics.c b/src/api/graphics.c index 1b095b35..886fc2f6 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -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++; } diff --git a/src/api/types/canvas.c b/src/api/types/canvas.c index aa60e121..24763771 100644 --- a/src/api/types/canvas.c +++ b/src/api/types/canvas.c @@ -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; diff --git a/src/api/types/material.c b/src/api/types/material.c index 6a39e6f6..6605320d 100644 --- a/src/api/types/material.c +++ b/src/api/types/material.c @@ -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; } diff --git a/src/graphics/opengl.c b/src/graphics/opengl.c index b318b277..90f31bb7 100644 --- a/src/graphics/opengl.c +++ b/src/graphics/opengl.c @@ -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]);