From 354f83c1cbbf7a26c751073cabf3a668a608a495 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 19 Jul 2015 22:39:02 -0300 Subject: [PATCH] Added support for MSAA on the window on iOS. Requires updated dependencies to compile on iOS, which can be downloaded at https://dl.dropboxusercontent.com/u/4214717/love-ios-libraries-0.10.zip --- src/modules/graphics/opengl/Graphics.cpp | 32 ++++++++++- .../graphics/opengl/wrap_SpriteBatch.cpp | 56 ++++++------------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index dd0d48311..bea92a732 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -494,11 +494,13 @@ void Graphics::discard(const std::vector &colorbuffers, bool stencil) } else { - int activecanvascount = (int) states.back().canvases.size(); + int rendertargetcount = 1; + if (Canvas::current) + rendertargetcount = (int) states.back().canvases.size(); for (int i = 0; i < (int) colorbuffers.size(); i++) { - if (colorbuffers[i] && i < activecanvascount) + if (colorbuffers[i] && i < rendertargetcount) attachments.push_back(GL_COLOR_ATTACHMENT0 + i); } @@ -1308,8 +1310,34 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool throw love::Exception("Out of memory."); } +#ifdef LOVE_IOS + SDL_SysWMinfo info = {}; + SDL_VERSION(&info.version); + SDL_GetWindowWMInfo(SDL_GL_GetCurrentWindow(), &info); + + if (info.info.uikit.resolveFramebuffer != 0) + { + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, info.info.uikit.resolveFramebuffer); + + // We need to do an explicit MSAA resolve on iOS, because it uses GLES + // FBOs rather than a system framebuffer. + if (GLAD_ES_VERSION_3_0) + glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); + else if (GLAD_APPLE_framebuffer_multisample) + glResolveMultisampleFramebufferAPPLE(); + + glBindFramebuffer(GL_READ_FRAMEBUFFER, info.info.uikit.resolveFramebuffer); + } +#endif + glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); +#ifdef LOVE_IOS + // Restore the previous binding for the main framebuffer. + if (info.info.uikit.resolveFramebuffer != 0) + glBindFramebuffer(GL_FRAMEBUFFER, gl.getDefaultFBO()); +#endif + if (!copyAlpha) { // Replace alpha values with full opacity. diff --git a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp index 08ff147f1..c550fd6f7 100644 --- a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp +++ b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp @@ -39,19 +39,17 @@ SpriteBatch *luax_checkspritebatch(lua_State *L, int idx) return luax_checktype(L, idx, GRAPHICS_SPRITE_BATCH_ID); } -int w_SpriteBatch_add(lua_State *L) +static inline int w_SpriteBatch_add_or_set(lua_State *L, SpriteBatch *t, int startidx, int index) { - SpriteBatch *t = luax_checkspritebatch(L, 1); Quad *quad = nullptr; - int startidx = 2; - if (luax_istype(L, 2, GRAPHICS_QUAD_ID)) + if (luax_istype(L, startidx, GRAPHICS_QUAD_ID)) { - quad = luax_totype(L, 2, GRAPHICS_QUAD_ID); - startidx = 3; + quad = luax_totype(L, startidx, GRAPHICS_QUAD_ID); + startidx++; } - else if (lua_isnil(L, 2) && !lua_isnoneornil(L, 3)) - return luax_typerror(L, 2, "Quad"); + else if (lua_isnil(L, startidx) && !lua_isnoneornil(L, startidx + 1)) + return luax_typerror(L, startidx, "Quad"); float x = (float) luaL_optnumber(L, startidx + 0, 0.0); float y = (float) luaL_optnumber(L, startidx + 1, 0.0); @@ -63,15 +61,23 @@ int w_SpriteBatch_add(lua_State *L) float kx = (float) luaL_optnumber(L, startidx + 7, 0.0); float ky = (float) luaL_optnumber(L, startidx + 8, 0.0); - int index = 0; luax_catchexcept(L, [&]() { if (quad) - index = t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky); + index = t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky, index); else - index = t->add(x, y, a, sx, sy, ox, oy, kx, ky); + index = t->add(x, y, a, sx, sy, ox, oy, kx, ky, index); }); + return index; +} + +int w_SpriteBatch_add(lua_State *L) +{ + SpriteBatch *t = luax_checkspritebatch(L, 1); + + int index = w_SpriteBatch_add_or_set(L, t, 2, -1); lua_pushinteger(L, index + 1); + return 1; } @@ -80,33 +86,7 @@ int w_SpriteBatch_set(lua_State *L) SpriteBatch *t = luax_checkspritebatch(L, 1); int index = (int) luaL_checknumber(L, 2) - 1; - Quad *quad = nullptr; - int startidx = 3; - - if (luax_istype(L, 3, GRAPHICS_QUAD_ID)) - { - quad = luax_totype(L, 3, GRAPHICS_QUAD_ID); - startidx = 4; - } - else if (lua_isnil(L, 3) && !lua_isnoneornil(L, 4)) - return luax_typerror(L, 3, "Quad"); - - float x = (float) luaL_optnumber(L, startidx + 0, 0.0); - float y = (float) luaL_optnumber(L, startidx + 1, 0.0); - float a = (float) luaL_optnumber(L, startidx + 2, 0.0); - float sx = (float) luaL_optnumber(L, startidx + 3, 1.0); - float sy = (float) luaL_optnumber(L, startidx + 4, sx); - float ox = (float) luaL_optnumber(L, startidx + 5, 0.0); - float oy = (float) luaL_optnumber(L, startidx + 6, 0.0); - float kx = (float) luaL_optnumber(L, startidx + 7, 0.0); - float ky = (float) luaL_optnumber(L, startidx + 8, 0.0); - - luax_catchexcept(L, [&]() { - if (quad) - t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky, index); - else - t->add(x, y, a, sx, sy, ox, oy, kx, ky, index); - }); + w_SpriteBatch_add_or_set(L, t, 3, index); return 0; }