Canvas mipmaps flag;

This commit is contained in:
bjorn 2018-08-29 13:34:54 -07:00
parent 06fa846680
commit 74fec01e60
3 changed files with 16 additions and 1 deletions

View File

@ -944,7 +944,7 @@ int l_lovrGraphicsNewShaderBlock(lua_State* L) {
int l_lovrGraphicsNewCanvas(lua_State* L) {
int width = luaL_checkinteger(L, 1);
int height = luaL_checkinteger(L, 2);
CanvasFlags flags = { .depth = DEPTH_D16, .stereo = true, .msaa = 0 };
CanvasFlags flags = { .depth = DEPTH_D16, .stereo = true, .msaa = 0, .mipmaps = true };
if (lua_istable(L, 3)) {
lua_getfield(L, 3, "depth");
@ -962,6 +962,10 @@ int l_lovrGraphicsNewCanvas(lua_State* L) {
lua_getfield(L, 3, "msaa");
flags.msaa = lua_isnil(L, -1) ? flags.msaa : luaL_checkinteger(L, -1);
lua_pop(L, 1);
lua_getfield(L, 3, "mipmaps");
flags.mipmaps = lua_isnil(L, -1) ? flags.mipmaps : lua_toboolean(L, -1);
lua_pop(L, 1);
}
Canvas* canvas = lovrCanvasCreate(width, height, flags);

View File

@ -21,6 +21,7 @@ typedef struct {
DepthFormat depth;
bool stereo;
int msaa;
bool mipmaps;
} CanvasFlags;
typedef struct Canvas Canvas;

View File

@ -1421,6 +1421,16 @@ void lovrCanvasResolve(Canvas* canvas) {
glReadBuffer(0);
glDrawBuffers(canvas->count, buffers);
}
if (canvas->flags.mipmaps) {
for (int i = 0; i < canvas->count; i++) {
Texture* texture = canvas->attachments[i].texture;
if (texture->mipmapCount > 1) {
lovrGpuBindTexture(texture, 0);
glGenerateMipmap(texture->target);
}
}
}
}
void lovrCanvasBlit(Canvas* canvas) {