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