mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Fixed Canvases on iOS, added support for Canvas MSAA on OpenGL ES 3.
--HG-- branch : minor
This commit is contained in:
@@ -520,7 +520,7 @@ bool Canvas::createMSAAFBO(GLenum internalformat)
|
||||
// Create our FBO without a texture.
|
||||
status = strategy->createFBO(fbo, 0);
|
||||
|
||||
GLuint previous = 0;
|
||||
GLuint previous = gl.getDefaultFBO();
|
||||
if (current != this)
|
||||
{
|
||||
if (current != nullptr)
|
||||
@@ -567,11 +567,8 @@ bool Canvas::loadVolatile()
|
||||
return false;
|
||||
}
|
||||
|
||||
int max_samples = 0;
|
||||
if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object || GLAD_EXT_framebuffer_multisample)
|
||||
glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
|
||||
|
||||
requested_samples = std::max(std::min(requested_samples, max_samples), 0);
|
||||
requested_samples = std::min(requested_samples, gl.getMaxRenderbufferSamples());
|
||||
requested_samples = std::max(requested_samples, 0);
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
gl.bindTexture(texture);
|
||||
@@ -596,14 +593,8 @@ bool Canvas::loadVolatile()
|
||||
while (glGetError() != GL_NO_ERROR)
|
||||
/* Clear the error buffer. */;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
iformat,
|
||||
width, height,
|
||||
0,
|
||||
externalformat,
|
||||
textype,
|
||||
nullptr);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, iformat, width, height, 0,
|
||||
externalformat, textype, nullptr);
|
||||
|
||||
if (glGetError() != GL_NO_ERROR)
|
||||
{
|
||||
@@ -890,7 +881,7 @@ void Canvas::clear(Color c)
|
||||
if (strategy == &strategyNone)
|
||||
return;
|
||||
|
||||
GLuint previous = 0;
|
||||
GLuint previous = gl.getDefaultFBO();
|
||||
|
||||
if (current != this)
|
||||
{
|
||||
@@ -1024,12 +1015,12 @@ bool Canvas::resolveMSAA()
|
||||
if (!msaa_dirty)
|
||||
return true;
|
||||
|
||||
GLuint previous = 0;
|
||||
GLuint previous = gl.getDefaultFBO();
|
||||
if (current != nullptr)
|
||||
previous = current->fbo;
|
||||
|
||||
// Do the MSAA resolve by blitting the MSAA renderbuffer to the texture.
|
||||
if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object)
|
||||
if (GLAD_ES_VERSION_3_0 || GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object)
|
||||
{
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo);
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef LOVE_IOS
|
||||
#include <SDL_system.h>
|
||||
#endif
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
@@ -454,6 +458,12 @@ void Graphics::present()
|
||||
glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments);
|
||||
}
|
||||
|
||||
#ifdef LOVE_IOS
|
||||
// Hack: SDL's color renderbuffer needs to be bound when swapBuffers is called.
|
||||
GLuint rbo = SDL_iPhoneGetViewRenderbuffer(SDL_GL_GetCurrentWindow());
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||
#endif
|
||||
|
||||
currentWindow->swapBuffers();
|
||||
|
||||
// Restore the currently active canvas, if there is one.
|
||||
@@ -1286,13 +1296,7 @@ double Graphics::getSystemLimit(SystemLimit limittype) const
|
||||
limit = (double) gl.getMaxRenderTargets();
|
||||
break;
|
||||
case Graphics::LIMIT_CANVAS_MSAA:
|
||||
if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object
|
||||
|| GLAD_EXT_framebuffer_multisample)
|
||||
{
|
||||
GLint intlimit = 0;
|
||||
glGetIntegerv(GL_MAX_SAMPLES, &intlimit);
|
||||
limit = (double) intlimit;
|
||||
}
|
||||
limit = (double) gl.getMaxRenderbufferSamples();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
// For SDL_GL_GetProcAddress.
|
||||
#include <SDL_video.h>
|
||||
|
||||
#ifdef LOVE_IOS
|
||||
#include <SDL_system.h>
|
||||
#endif
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
@@ -49,6 +53,7 @@ OpenGL::OpenGL()
|
||||
, maxAnisotropy(1.0f)
|
||||
, maxTextureSize(0)
|
||||
, maxRenderTargets(0)
|
||||
, maxRenderbufferSamples(0)
|
||||
, vendor(VENDOR_UNKNOWN)
|
||||
, state()
|
||||
{
|
||||
@@ -124,8 +129,6 @@ void OpenGL::setupContext()
|
||||
|
||||
glActiveTexture(curgltextureunit);
|
||||
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, (GLint *) &state.defaultFBO);
|
||||
|
||||
BlendState blend = {GL_ONE, GL_ONE, GL_ZERO, GL_ZERO, GL_FUNC_ADD};
|
||||
setBlendState(blend);
|
||||
|
||||
@@ -215,6 +218,11 @@ void OpenGL::initMaxValues()
|
||||
}
|
||||
|
||||
maxRenderTargets = std::min(maxattachments, maxdrawbuffers);
|
||||
|
||||
if (GLAD_ES_VERSION_3_0 || GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object || GLAD_EXT_framebuffer_multisample)
|
||||
glGetIntegerv(GL_MAX_SAMPLES, &maxRenderbufferSamples);
|
||||
else
|
||||
maxRenderbufferSamples = 0;
|
||||
}
|
||||
|
||||
void OpenGL::initMatrices()
|
||||
@@ -423,7 +431,12 @@ float OpenGL::getPointSize() const
|
||||
|
||||
GLuint OpenGL::getDefaultFBO() const
|
||||
{
|
||||
return state.defaultFBO;
|
||||
#ifdef LOVE_IOS
|
||||
// Hack: iOS uses a custom FBO.
|
||||
return SDL_iPhoneGetViewFramebuffer(SDL_GL_GetCurrentWindow());
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
GLuint OpenGL::getDefaultTexture() const
|
||||
@@ -560,6 +573,11 @@ int OpenGL::getMaxRenderTargets() const
|
||||
return maxRenderTargets;
|
||||
}
|
||||
|
||||
int OpenGL::getMaxRenderbufferSamples() const
|
||||
{
|
||||
return maxRenderbufferSamples;
|
||||
}
|
||||
|
||||
void OpenGL::updateTextureMemorySize(size_t oldsize, size_t newsize)
|
||||
{
|
||||
int64 memsize = (int64) stats.textureMemory + ((int64 )newsize - (int64) oldsize);
|
||||
|
||||
@@ -310,6 +310,11 @@ public:
|
||||
**/
|
||||
int getMaxRenderTargets() const;
|
||||
|
||||
/**
|
||||
* Returns the maximum supported number of MSAA samples for renderbuffers.
|
||||
**/
|
||||
int getMaxRenderbufferSamples() const;
|
||||
|
||||
void updateTextureMemorySize(size_t oldsize, size_t newsize);
|
||||
|
||||
/**
|
||||
@@ -335,6 +340,7 @@ private:
|
||||
float maxAnisotropy;
|
||||
int maxTextureSize;
|
||||
int maxRenderTargets;
|
||||
int maxRenderbufferSamples;
|
||||
|
||||
Vendor vendor;
|
||||
|
||||
@@ -357,7 +363,6 @@ private:
|
||||
|
||||
float pointSize;
|
||||
|
||||
GLuint defaultFBO;
|
||||
GLuint defaultTexture;
|
||||
|
||||
BlendState blend;
|
||||
|
||||
Reference in New Issue
Block a user