mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Fixed rendering to multiple canvases, removed some redundant OpenGL calls when switching between canvases
This commit is contained in:
@@ -397,9 +397,6 @@ static void getStrategy()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int maxFBOColorAttachments = 0;
|
|
||||||
static int maxDrawBuffers = 0;
|
|
||||||
|
|
||||||
Canvas::Canvas(int width, int height, TextureType texture_type, int fsaa)
|
Canvas::Canvas(int width, int height, TextureType texture_type, int fsaa)
|
||||||
: fbo(0)
|
: fbo(0)
|
||||||
, resolve_fbo(0)
|
, resolve_fbo(0)
|
||||||
@@ -657,12 +654,19 @@ void Canvas::setupGrab()
|
|||||||
if (current == this)
|
if (current == this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// cleanup after previous fbo
|
// cleanup after previous Canvas
|
||||||
if (current != NULL)
|
if (current != nullptr)
|
||||||
current->stopGrab();
|
{
|
||||||
|
systemViewport = current->systemViewport;
|
||||||
|
current->stopGrab(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
systemViewport = gl.getViewport();
|
||||||
|
|
||||||
|
// indicate we are using this Canvas.
|
||||||
|
current = this;
|
||||||
|
|
||||||
// bind the framebuffer object.
|
// bind the framebuffer object.
|
||||||
systemViewport = gl.getViewport();
|
|
||||||
strategy->bindFBO(fbo);
|
strategy->bindFBO(fbo);
|
||||||
gl.setViewport(OpenGL::Viewport(0, 0, width, height));
|
gl.setViewport(OpenGL::Viewport(0, 0, width, height));
|
||||||
|
|
||||||
@@ -677,9 +681,6 @@ void Canvas::setupGrab()
|
|||||||
// Switch back to modelview matrix
|
// Switch back to modelview matrix
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
// indicate we are using this fbo
|
|
||||||
current = this;
|
|
||||||
|
|
||||||
if (fsaa_buffer != 0)
|
if (fsaa_buffer != 0)
|
||||||
fsaa_dirty = true;
|
fsaa_dirty = true;
|
||||||
}
|
}
|
||||||
@@ -695,7 +696,7 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
|
|||||||
if (!isMultiCanvasSupported())
|
if (!isMultiCanvasSupported())
|
||||||
throw love::Exception("Multi-canvas rendering is not supported on this system.");
|
throw love::Exception("Multi-canvas rendering is not supported on this system.");
|
||||||
|
|
||||||
if (canvases.size()+1 > size_t(maxDrawBuffers) || canvases.size()+1 > size_t(maxFBOColorAttachments))
|
if ((int) canvases.size() + 1 > gl.getMaxRenderTargets())
|
||||||
throw love::Exception("This system can't simultaniously render to %d canvases.", canvases.size()+1);
|
throw love::Exception("This system can't simultaniously render to %d canvases.", canvases.size()+1);
|
||||||
|
|
||||||
if (fsaa_samples != 0)
|
if (fsaa_samples != 0)
|
||||||
@@ -752,21 +753,23 @@ void Canvas::startGrab()
|
|||||||
attachedCanvases.clear();
|
attachedCanvases.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::stopGrab()
|
void Canvas::stopGrab(bool switchingToOtherCanvas)
|
||||||
{
|
{
|
||||||
// i am not grabbing. leave me alone
|
// i am not grabbing. leave me alone
|
||||||
if (current != this)
|
if (current != this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// bind default
|
|
||||||
strategy->bindFBO(0);
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
current = nullptr;
|
// bind default
|
||||||
|
if (!switchingToOtherCanvas)
|
||||||
gl.setViewport(systemViewport);
|
{
|
||||||
|
strategy->bindFBO(0);
|
||||||
|
current = nullptr;
|
||||||
|
gl.setViewport(systemViewport);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::clear(Color c)
|
void Canvas::clear(Color c)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public:
|
|||||||
**/
|
**/
|
||||||
void startGrab(const std::vector<Canvas *> &canvases);
|
void startGrab(const std::vector<Canvas *> &canvases);
|
||||||
void startGrab();
|
void startGrab();
|
||||||
void stopGrab();
|
void stopGrab(bool switchingToOtherCanvas = false);
|
||||||
|
|
||||||
void clear(Color c);
|
void clear(Color c);
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl
|
|||||||
if ((index == -1 && next >= size) || index < -1 || index >= size)
|
if ((index == -1 && next >= size) || index < -1 || index >= size)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
Vertex sprite[4];
|
||||||
|
|
||||||
// Needed for colors.
|
// Needed for colors.
|
||||||
memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4);
|
memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4);
|
||||||
|
|
||||||
@@ -131,6 +133,8 @@ int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy,
|
|||||||
if ((index == -1 && next >= size) || index < -1 || index >= next)
|
if ((index == -1 && next >= size) || index < -1 || index >= next)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
Vertex sprite[4];
|
||||||
|
|
||||||
// Needed for colors.
|
// Needed for colors.
|
||||||
memcpy(sprite, quad->getVertices(), sizeof(Vertex) * 4);
|
memcpy(sprite, quad->getVertices(), sizeof(Vertex) * 4);
|
||||||
|
|
||||||
|
|||||||
@@ -135,8 +135,6 @@ private:
|
|||||||
// The next free element.
|
// The next free element.
|
||||||
int next;
|
int next;
|
||||||
|
|
||||||
Vertex sprite[4];
|
|
||||||
|
|
||||||
// Current color. This color, if present, will be applied to the next
|
// Current color. This color, if present, will be applied to the next
|
||||||
// added sprite.
|
// added sprite.
|
||||||
Color *color;
|
Color *color;
|
||||||
|
|||||||
Reference in New Issue
Block a user