Rename internal uses of canvas to texture/render target

This commit is contained in:
Alex Szpakowski
2020-02-08 20:40:10 -04:00
parent 12c90b3dca
commit 453322678c
12 changed files with 101 additions and 101 deletions
+3 -3
View File
@@ -161,11 +161,11 @@ void Event::exceptionIfInRenderPass(const char *name)
{ {
// Some core OS graphics functionality (e.g. swap buffers on some platforms) // Some core OS graphics functionality (e.g. swap buffers on some platforms)
// happens inside SDL_PumpEvents - which is called by SDL_PollEvent and // happens inside SDL_PumpEvents - which is called by SDL_PollEvent and
// friends. It's probably a bad idea to call those functions while a Canvas // friends. It's probably a bad idea to call those functions while a RT
// is active. // is active.
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS); auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr && gfx->isCanvasActive()) if (gfx != nullptr && gfx->isRenderTargetActive())
throw love::Exception("%s cannot be called while a Canvas is active in love.graphics.", name); throw love::Exception("%s cannot be called while a render target is active in love.graphics.", name);
} }
Message *Event::convert(const SDL_Event &e) Message *Event::convert(const SDL_Event &e)
+41 -41
View File
@@ -397,7 +397,7 @@ void Graphics::restoreState(const DisplayState &s)
setFont(s.font.get()); setFont(s.font.get());
setShader(s.shader.get()); setShader(s.shader.get());
setCanvas(s.renderTargets); setRenderTargets(s.renderTargets);
setColorMask(s.colorMask); setColorMask(s.colorMask);
setWireframe(s.wireframe); setWireframe(s.wireframe);
@@ -450,27 +450,27 @@ void Graphics::restoreStateChecked(const DisplayState &s)
const auto &sRTs = s.renderTargets; const auto &sRTs = s.renderTargets;
const auto &curRTs = cur.renderTargets; const auto &curRTs = cur.renderTargets;
bool canvaseschanged = sRTs.colors.size() != curRTs.colors.size(); bool rtschanged = sRTs.colors.size() != curRTs.colors.size();
if (!canvaseschanged) if (!rtschanged)
{ {
for (size_t i = 0; i < sRTs.colors.size() && i < curRTs.colors.size(); i++) for (size_t i = 0; i < sRTs.colors.size() && i < curRTs.colors.size(); i++)
{ {
if (sRTs.colors[i] != curRTs.colors[i]) if (sRTs.colors[i] != curRTs.colors[i])
{ {
canvaseschanged = true; rtschanged = true;
break; break;
} }
} }
if (!canvaseschanged && sRTs.depthStencil != curRTs.depthStencil) if (!rtschanged && sRTs.depthStencil != curRTs.depthStencil)
canvaseschanged = true; rtschanged = true;
if (sRTs.temporaryRTFlags != curRTs.temporaryRTFlags) if (sRTs.temporaryRTFlags != curRTs.temporaryRTFlags)
canvaseschanged = true; rtschanged = true;
} }
if (canvaseschanged) if (rtschanged)
setCanvas(s.renderTargets); setRenderTargets(s.renderTargets);
if (s.colorMask != cur.colorMask) if (s.colorMask != cur.colorMask)
setColorMask(s.colorMask); setColorMask(s.colorMask);
@@ -543,19 +543,19 @@ love::graphics::Shader *Graphics::getShader() const
return states.back().shader.get(); return states.back().shader.get();
} }
void Graphics::setCanvas(RenderTarget rt, uint32 temporaryRTFlags) void Graphics::setRenderTarget(RenderTarget rt, uint32 temporaryRTFlags)
{ {
if (rt.texture == nullptr) if (rt.texture == nullptr)
return setCanvas(); return setRenderTarget();
RenderTargets rts; RenderTargets rts;
rts.colors.push_back(rt); rts.colors.push_back(rt);
rts.temporaryRTFlags = temporaryRTFlags; rts.temporaryRTFlags = temporaryRTFlags;
setCanvas(rts); setRenderTargets(rts);
} }
void Graphics::setCanvas(const RenderTargetsStrongRef &rts) void Graphics::setRenderTargets(const RenderTargetsStrongRef &rts)
{ {
RenderTargets targets; RenderTargets targets;
targets.colors.reserve(rts.colors.size()); targets.colors.reserve(rts.colors.size());
@@ -566,27 +566,27 @@ void Graphics::setCanvas(const RenderTargetsStrongRef &rts)
targets.depthStencil = RenderTarget(rts.depthStencil.texture, rts.depthStencil.slice, rts.depthStencil.mipmap); targets.depthStencil = RenderTarget(rts.depthStencil.texture, rts.depthStencil.slice, rts.depthStencil.mipmap);
targets.temporaryRTFlags = rts.temporaryRTFlags; targets.temporaryRTFlags = rts.temporaryRTFlags;
return setCanvas(targets); return setRenderTargets(targets);
} }
void Graphics::setCanvas(const RenderTargets &rts) void Graphics::setRenderTargets(const RenderTargets &rts)
{ {
DisplayState &state = states.back(); DisplayState &state = states.back();
int ncanvases = (int) rts.colors.size(); int rtcount = (int) rts.colors.size();
RenderTarget firsttarget = rts.getFirstTarget(); RenderTarget firsttarget = rts.getFirstTarget();
Texture *firsttex = firsttarget.texture; Texture *firsttex = firsttarget.texture;
if (firsttex == nullptr) if (firsttex == nullptr)
return setCanvas(); return setRenderTarget();
const auto &prevRTs = state.renderTargets; const auto &prevRTs = state.renderTargets;
if (ncanvases == (int) prevRTs.colors.size()) if (rtcount == (int) prevRTs.colors.size())
{ {
bool modified = false; bool modified = false;
for (int i = 0; i < ncanvases; i++) for (int i = 0; i < rtcount; i++)
{ {
if (rts.colors[i] != prevRTs.colors[i]) if (rts.colors[i] != prevRTs.colors[i])
{ {
@@ -605,8 +605,8 @@ void Graphics::setCanvas(const RenderTargets &rts)
return; return;
} }
if (ncanvases > capabilities.limits[LIMIT_MULTI_CANVAS]) if (rtcount > capabilities.limits[LIMIT_MULTI_CANVAS])
throw love::Exception("This system can't simultaneously render to %d canvases.", ncanvases); throw love::Exception("This system can't simultaneously render to %d textures.", rtcount);
bool multiformatsupported = capabilities.features[FEATURE_MULTI_CANVAS_FORMATS]; bool multiformatsupported = capabilities.features[FEATURE_MULTI_CANVAS_FORMATS];
@@ -615,10 +615,10 @@ void Graphics::setCanvas(const RenderTargets &rts)
firstcolorformat = rts.colors[0].texture->getPixelFormat(); firstcolorformat = rts.colors[0].texture->getPixelFormat();
if (!firsttex->isRenderTarget()) if (!firsttex->isRenderTarget())
throw love::Exception("Texture must be created as a render target to be used in setCanvas."); throw love::Exception("Texture must be created as a render target to be used in setRenderTargets.");
if (isPixelFormatDepthStencil(firstcolorformat)) if (isPixelFormatDepthStencil(firstcolorformat))
throw love::Exception("Depth/stencil format Canvases must be used with the 'depthstencil' field of the table passed into setCanvas."); throw love::Exception("Depth/stencil format textures must be used with the 'depthstencil' field of the table passed into setRenderTargets.");
if (firsttarget.mipmap < 0 || firsttarget.mipmap >= firsttex->getMipmapCount()) if (firsttarget.mipmap < 0 || firsttarget.mipmap >= firsttex->getMipmapCount())
throw love::Exception("Invalid mipmap level %d.", firsttarget.mipmap + 1); throw love::Exception("Invalid mipmap level %d.", firsttarget.mipmap + 1);
@@ -626,12 +626,12 @@ void Graphics::setCanvas(const RenderTargets &rts)
if (!firsttex->isValidSlice(firsttarget.slice)) if (!firsttex->isValidSlice(firsttarget.slice))
throw love::Exception("Invalid slice index: %d.", firsttarget.slice + 1); throw love::Exception("Invalid slice index: %d.", firsttarget.slice + 1);
bool hasSRGBcanvas = firstcolorformat == PIXELFORMAT_sRGBA8_UNORM; bool hasSRGBtexture = firstcolorformat == PIXELFORMAT_sRGBA8_UNORM;
int pixelw = firsttex->getPixelWidth(firsttarget.mipmap); int pixelw = firsttex->getPixelWidth(firsttarget.mipmap);
int pixelh = firsttex->getPixelHeight(firsttarget.mipmap); int pixelh = firsttex->getPixelHeight(firsttarget.mipmap);
int reqmsaa = firsttex->getRequestedMSAA(); int reqmsaa = firsttex->getRequestedMSAA();
for (int i = 1; i < ncanvases; i++) for (int i = 1; i < rtcount; i++)
{ {
Texture *c = rts.colors[i].texture; Texture *c = rts.colors[i].texture;
PixelFormat format = c->getPixelFormat(); PixelFormat format = c->getPixelFormat();
@@ -639,7 +639,7 @@ void Graphics::setCanvas(const RenderTargets &rts)
int slice = rts.colors[i].slice; int slice = rts.colors[i].slice;
if (!c->isRenderTarget()) if (!c->isRenderTarget())
throw love::Exception("Texture must be created as a render target to be used in setCanvas."); throw love::Exception("Texture must be created as a render target to be used in setRenderTargets.");
if (mip < 0 || mip >= c->getMipmapCount()) if (mip < 0 || mip >= c->getMipmapCount())
throw love::Exception("Invalid mipmap level %d.", mip + 1); throw love::Exception("Invalid mipmap level %d.", mip + 1);
@@ -648,19 +648,19 @@ void Graphics::setCanvas(const RenderTargets &rts)
throw love::Exception("Invalid slice index: %d.", slice + 1); throw love::Exception("Invalid slice index: %d.", slice + 1);
if (c->getPixelWidth(mip) != pixelw || c->getPixelHeight(mip) != pixelh) if (c->getPixelWidth(mip) != pixelw || c->getPixelHeight(mip) != pixelh)
throw love::Exception("All canvases must have the same pixel dimensions."); throw love::Exception("All textures must have the same pixel dimensions.");
if (!multiformatsupported && format != firstcolorformat) if (!multiformatsupported && format != firstcolorformat)
throw love::Exception("This system doesn't support multi-canvas rendering with different canvas formats."); throw love::Exception("This system doesn't support multi-render-target rendering with different texture formats.");
if (c->getRequestedMSAA() != reqmsaa) if (c->getRequestedMSAA() != reqmsaa)
throw love::Exception("All Canvases must have the same MSAA value."); throw love::Exception("All textures must have the same MSAA value.");
if (isPixelFormatDepthStencil(format)) if (isPixelFormatDepthStencil(format))
throw love::Exception("Depth/stencil format Canvases must be used with the 'depthstencil' field of the table passed into setCanvas."); throw love::Exception("Depth/stencil format textures must be used with the 'depthstencil' field of the table passed into setRenderTargets.");
if (format == PIXELFORMAT_sRGBA8_UNORM) if (format == PIXELFORMAT_sRGBA8_UNORM)
hasSRGBcanvas = true; hasSRGBtexture = true;
} }
if (rts.depthStencil.texture != nullptr) if (rts.depthStencil.texture != nullptr)
@@ -670,10 +670,10 @@ void Graphics::setCanvas(const RenderTargets &rts)
int slice = rts.depthStencil.slice; int slice = rts.depthStencil.slice;
if (!c->isRenderTarget()) if (!c->isRenderTarget())
throw love::Exception("Texture must be created as a render target to be used in setCanvas."); throw love::Exception("Texture must be created as a render target to be used in setRenderTargets.");
if (!isPixelFormatDepthStencil(c->getPixelFormat())) if (!isPixelFormatDepthStencil(c->getPixelFormat()))
throw love::Exception("Only depth/stencil format Texture can be used with the 'depthstencil' field of the table passed into setCanvas."); throw love::Exception("Only depth/stencil format textures can be used with the 'depthstencil' field of the table passed into setRenderTargets.");
if (c->getPixelWidth(mip) != pixelw || c->getPixelHeight(mip) != pixelh) if (c->getPixelWidth(mip) != pixelw || c->getPixelHeight(mip) != pixelh)
throw love::Exception("All Textures must have the same pixel dimensions."); throw love::Exception("All Textures must have the same pixel dimensions.");
@@ -708,17 +708,17 @@ void Graphics::setCanvas(const RenderTargets &rts)
else if (wantsstencil) else if (wantsstencil)
dsformat = PIXELFORMAT_STENCIL8; dsformat = PIXELFORMAT_STENCIL8;
// We want setCanvasInternal to have a pointer to the temporary RT, but // We want setRenderTargetsInternal to have a pointer to the temporary RT,
// we don't want to directly store it in the main graphics state. // but we don't want to directly store it in the main graphics state.
RenderTargets realRTs = rts; RenderTargets realRTs = rts;
realRTs.depthStencil.texture = getTemporaryTexture(dsformat, pixelw, pixelh, reqmsaa); realRTs.depthStencil.texture = getTemporaryTexture(dsformat, pixelw, pixelh, reqmsaa);
realRTs.depthStencil.slice = 0; realRTs.depthStencil.slice = 0;
setCanvasInternal(realRTs, w, h, pixelw, pixelh, hasSRGBcanvas); setRenderTargetsInternal(realRTs, w, h, pixelw, pixelh, hasSRGBtexture);
} }
else else
setCanvasInternal(rts, w, h, pixelw, pixelh, hasSRGBcanvas); setRenderTargetsInternal(rts, w, h, pixelw, pixelh, hasSRGBtexture);
RenderTargetsStrongRef refs; RenderTargetsStrongRef refs;
refs.colors.reserve(rts.colors.size()); refs.colors.reserve(rts.colors.size());
@@ -734,7 +734,7 @@ void Graphics::setCanvas(const RenderTargets &rts)
renderTargetSwitchCount++; renderTargetSwitchCount++;
} }
void Graphics::setCanvas() void Graphics::setRenderTarget()
{ {
DisplayState &state = states.back(); DisplayState &state = states.back();
@@ -742,13 +742,13 @@ void Graphics::setCanvas()
return; return;
flushStreamDraws(); flushStreamDraws();
setCanvasInternal(RenderTargets(), width, height, pixelWidth, pixelHeight, isGammaCorrect()); setRenderTargetsInternal(RenderTargets(), width, height, pixelWidth, pixelHeight, isGammaCorrect());
state.renderTargets = RenderTargetsStrongRef(); state.renderTargets = RenderTargetsStrongRef();
renderTargetSwitchCount++; renderTargetSwitchCount++;
} }
Graphics::RenderTargets Graphics::getCanvas() const Graphics::RenderTargets Graphics::getRenderTargets() const
{ {
const auto &curRTs = states.back().renderTargets; const auto &curRTs = states.back().renderTargets;
@@ -764,7 +764,7 @@ Graphics::RenderTargets Graphics::getCanvas() const
return rts; return rts;
} }
bool Graphics::isCanvasActive() const bool Graphics::isRenderTargetActive() const
{ {
const auto &rts = states.back().renderTargets; const auto &rts = states.back().renderTargets;
return !rts.colors.empty() || rts.depthStencil.texture != nullptr; return !rts.colors.empty() || rts.depthStencil.texture != nullptr;
+7 -7
View File
@@ -538,13 +538,13 @@ public:
Shader *getShader() const; Shader *getShader() const;
void setCanvas(RenderTarget rt, uint32 temporaryRTFlags); void setRenderTarget(RenderTarget rt, uint32 temporaryRTFlags);
void setCanvas(const RenderTargets &rts); void setRenderTargets(const RenderTargets &rts);
void setCanvas(const RenderTargetsStrongRef &rts); void setRenderTargets(const RenderTargetsStrongRef &rts);
void setCanvas(); void setRenderTarget();
RenderTargets getCanvas() const; RenderTargets getRenderTargets() const;
bool isCanvasActive() const; bool isRenderTargetActive() const;
bool isRenderTargetActive(Texture *texture) const; bool isRenderTargetActive(Texture *texture) const;
bool isRenderTargetActive(Texture *texture, int slice) const; bool isRenderTargetActive(Texture *texture, int slice) const;
@@ -949,7 +949,7 @@ protected:
virtual Shader *newShaderInternal(ShaderStage *vertex, ShaderStage *pixel) = 0; virtual Shader *newShaderInternal(ShaderStage *vertex, ShaderStage *pixel) = 0;
virtual StreamBuffer *newStreamBuffer(BufferType type, size_t size) = 0; virtual StreamBuffer *newStreamBuffer(BufferType type, size_t size) = 0;
virtual void setCanvasInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBcanvas) = 0; virtual void setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBtexture) = 0;
virtual void initCapabilities() = 0; virtual void initCapabilities() = 0;
virtual void getAPIStats(int &shaderswitches) const = 0; virtual void getAPIStats(int &shaderswitches) const = 0;
+25 -25
View File
@@ -157,7 +157,7 @@ void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelh
this->pixelWidth = pixelwidth; this->pixelWidth = pixelwidth;
this->pixelHeight = pixelheight; this->pixelHeight = pixelheight;
if (!isCanvasActive()) if (!isRenderTargetActive())
{ {
// Set the viewport to top-left corner. // Set the viewport to top-left corner.
gl.setViewport({0, 0, pixelwidth, pixelheight}); gl.setViewport({0, 0, pixelwidth, pixelheight});
@@ -499,11 +499,11 @@ void Graphics::setDebug(bool enable)
::printf("OpenGL debug output enabled (LOVE_GRAPHICS_DEBUG=1)\n"); ::printf("OpenGL debug output enabled (LOVE_GRAPHICS_DEBUG=1)\n");
} }
void Graphics::setCanvasInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBcanvas) void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBtexture)
{ {
const DisplayState &state = states.back(); const DisplayState &state = states.back();
OpenGL::TempDebugGroup debuggroup("setCanvas"); OpenGL::TempDebugGroup debuggroup("setRenderTargets");
flushStreamDraws(); flushStreamDraws();
endPass(); endPass();
@@ -515,8 +515,8 @@ void Graphics::setCanvasInternal(const RenderTargets &rts, int w, int h, int pix
{ {
gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, gl.getDefaultFBO()); gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, gl.getDefaultFBO());
// The projection matrix is flipped compared to rendering to a canvas, due // The projection matrix is flipped compared to rendering to a texture,
// to OpenGL considering (0,0) bottom-left instead of top-left. // due to OpenGL considering (0,0) bottom-left instead of top-left.
projectionMatrix = Matrix4::ortho(0.0, (float) w, (float) h, 0.0, -10.0f, 10.0f); projectionMatrix = Matrix4::ortho(0.0, (float) w, (float) h, 0.0, -10.0f, 10.0f);
} }
else else
@@ -525,7 +525,7 @@ void Graphics::setCanvasInternal(const RenderTargets &rts, int w, int h, int pix
projectionMatrix = Matrix4::ortho(0.0, (float) w, 0.0, (float) h, -10.0f, 10.0f); projectionMatrix = Matrix4::ortho(0.0, (float) w, 0.0, (float) h, -10.0f, 10.0f);
// Flip front face winding when rendering to a canvas, since our // Flip front face winding when rendering to a texture, since our
// projection matrix is flipped. // projection matrix is flipped.
vertexwinding = vertexwinding == vertex::WINDING_CW ? vertex::WINDING_CCW : vertex::WINDING_CW; vertexwinding = vertexwinding == vertex::WINDING_CW ? vertex::WINDING_CCW : vertex::WINDING_CW;
} }
@@ -539,11 +539,11 @@ void Graphics::setCanvasInternal(const RenderTargets &rts, int w, int h, int pix
if (state.scissor) if (state.scissor)
setScissor(state.scissorRect); setScissor(state.scissorRect);
// Make sure the correct sRGB setting is used when drawing to the canvases. // Make sure the correct sRGB setting is used when drawing to the textures.
if (GLAD_VERSION_1_0 || GLAD_EXT_sRGB_write_control) if (GLAD_VERSION_1_0 || GLAD_EXT_sRGB_write_control)
{ {
if (hasSRGBcanvas != gl.isStateEnabled(OpenGL::ENABLE_FRAMEBUFFER_SRGB)) if (hasSRGBtexture != gl.isStateEnabled(OpenGL::ENABLE_FRAMEBUFFER_SRGB))
gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, hasSRGBcanvas); gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, hasSRGBtexture);
} }
} }
@@ -669,10 +669,10 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors, OptionalInt sten
if (colors.size() == 0 && !stencil.hasValue && !depth.hasValue) if (colors.size() == 0 && !stencil.hasValue && !depth.hasValue)
return; return;
int ncolorcanvases = (int) states.back().renderTargets.colors.size(); int ncolorRTs = (int) states.back().renderTargets.colors.size();
int ncolors = (int) colors.size(); int ncolors = (int) colors.size();
if (ncolors <= 1 && ncolorcanvases <= 1) if (ncolors <= 1 && ncolorRTs <= 1)
{ {
clear(ncolors > 0 ? colors[0] : OptionalColorf(), stencil, depth); clear(ncolors > 0 ? colors[0] : OptionalColorf(), stencil, depth);
return; return;
@@ -681,7 +681,7 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors, OptionalInt sten
flushStreamDraws(); flushStreamDraws();
bool drawbuffersmodified = false; bool drawbuffersmodified = false;
ncolors = std::min(ncolors, ncolorcanvases); ncolors = std::min(ncolors, ncolorRTs);
for (int i = 0; i < ncolors; i++) for (int i = 0; i < ncolors; i++)
{ {
@@ -712,10 +712,10 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors, OptionalInt sten
{ {
GLenum bufs[MAX_COLOR_RENDER_TARGETS]; GLenum bufs[MAX_COLOR_RENDER_TARGETS];
for (int i = 0; i < ncolorcanvases; i++) for (int i = 0; i < ncolorRTs; i++)
bufs[i] = GL_COLOR_ATTACHMENT0 + i; bufs[i] = GL_COLOR_ATTACHMENT0 + i;
glDrawBuffers(ncolorcanvases, bufs); glDrawBuffers(ncolorRTs, bufs);
} }
GLbitfield flags = 0; GLbitfield flags = 0;
@@ -773,7 +773,7 @@ void Graphics::discard(OpenGL::FramebufferTarget target, const std::vector<bool>
attachments.reserve(colorbuffers.size()); attachments.reserve(colorbuffers.size());
// glDiscardFramebuffer uses different attachment enums for the default FBO. // glDiscardFramebuffer uses different attachment enums for the default FBO.
if (!isCanvasActive() && gl.getDefaultFBO() == 0) if (!isRenderTargetActive() && gl.getDefaultFBO() == 0)
{ {
if (colorbuffers.size() > 0 && colorbuffers[0]) if (colorbuffers.size() > 0 && colorbuffers[0])
attachments.push_back(GL_COLOR); attachments.push_back(GL_COLOR);
@@ -859,7 +859,7 @@ void Graphics::bindCachedFBO(const RenderTargets &targets)
int ncolortargets = 0; int ncolortargets = 0;
GLenum drawbuffers[MAX_COLOR_RENDER_TARGETS]; GLenum drawbuffers[MAX_COLOR_RENDER_TARGETS];
auto attachCanvas = [&](const RenderTarget &rt) auto attachRT = [&](const RenderTarget &rt)
{ {
bool renderbuffer = msaa > 1 || !rt.texture->isReadable(); bool renderbuffer = msaa > 1 || !rt.texture->isReadable();
bool srgb = false; bool srgb = false;
@@ -894,10 +894,10 @@ void Graphics::bindCachedFBO(const RenderTargets &targets)
}; };
for (const auto &rt : targets.colors) for (const auto &rt : targets.colors)
attachCanvas(rt); attachRT(rt);
if (hasDS) if (hasDS)
attachCanvas(targets.depthStencil); attachRT(targets.depthStencil);
if (ncolortargets > 1) if (ncolortargets > 1)
glDrawBuffers(ncolortargets, drawbuffers); glDrawBuffers(ncolortargets, drawbuffers);
@@ -930,8 +930,8 @@ void Graphics::present(void *screenshotCallbackData)
if (!isActive()) if (!isActive())
return; return;
if (isCanvasActive()) if (isRenderTargetActive())
throw love::Exception("present cannot be called while a Canvas is active."); throw love::Exception("present cannot be called while a render target is active.");
deprecations.draw(this); deprecations.draw(this);
@@ -1084,7 +1084,7 @@ void Graphics::setScissor(const Rect &rect)
glrect.h = (int) (rect.h * dpiscale); glrect.h = (int) (rect.h * dpiscale);
// OpenGL's reversed y-coordinate is compensated for in OpenGL::setScissor. // OpenGL's reversed y-coordinate is compensated for in OpenGL::setScissor.
gl.setScissor(glrect, isCanvasActive()); gl.setScissor(glrect, isRenderTargetActive());
state.scissor = true; state.scissor = true;
state.scissorRect = rect; state.scissorRect = rect;
@@ -1106,10 +1106,10 @@ void Graphics::drawToStencilBuffer(StencilAction action, int value)
const auto &rts = states.back().renderTargets; const auto &rts = states.back().renderTargets;
love::graphics::Texture *dstexture = rts.depthStencil.texture.get(); love::graphics::Texture *dstexture = rts.depthStencil.texture.get();
if (!isCanvasActive() && !windowHasStencil) if (!isRenderTargetActive() && !windowHasStencil)
throw love::Exception("The window must have stenciling enabled to draw to the main screen's stencil buffer."); throw love::Exception("The window must have stenciling enabled to draw to the main screen's stencil buffer.");
else if (isCanvasActive() && (rts.temporaryRTFlags & TEMPORARY_RT_STENCIL) == 0 && (dstexture == nullptr || !isPixelFormatStencil(dstexture->getPixelFormat()))) else if (isRenderTargetActive() && (rts.temporaryRTFlags & TEMPORARY_RT_STENCIL) == 0 && (dstexture == nullptr || !isPixelFormatStencil(dstexture->getPixelFormat())))
throw love::Exception("Drawing to the stencil buffer with a Canvas active requires either stencil=true or a custom stencil-type Canvas to be used, in setCanvas."); throw love::Exception("Drawing to the stencil buffer with a render target active requires either stencil=true or a custom stencil-type texture to be used, in setRenderTarget.");
flushStreamDraws(); flushStreamDraws();
@@ -1237,7 +1237,7 @@ void Graphics::setFrontFaceWinding(vertex::Winding winding)
state.winding = winding; state.winding = winding;
if (isCanvasActive()) if (isRenderTargetActive())
winding = winding == vertex::WINDING_CW ? vertex::WINDING_CCW : vertex::WINDING_CW; winding = winding == vertex::WINDING_CW ? vertex::WINDING_CCW : vertex::WINDING_CW;
glFrontFace(winding == vertex::WINDING_CW ? GL_CW : GL_CCW); glFrontFace(winding == vertex::WINDING_CW ? GL_CW : GL_CCW);
+1 -1
View File
@@ -135,7 +135,7 @@ private:
love::graphics::ShaderStage *newShaderStageInternal(ShaderStage::StageType stage, const std::string &cachekey, const std::string &source, bool gles) override; love::graphics::ShaderStage *newShaderStageInternal(ShaderStage::StageType stage, const std::string &cachekey, const std::string &source, bool gles) override;
love::graphics::Shader *newShaderInternal(love::graphics::ShaderStage *vertex, love::graphics::ShaderStage *pixel) override; love::graphics::Shader *newShaderInternal(love::graphics::ShaderStage *vertex, love::graphics::ShaderStage *pixel) override;
love::graphics::StreamBuffer *newStreamBuffer(BufferType type, size_t size) override; love::graphics::StreamBuffer *newStreamBuffer(BufferType type, size_t size) override;
void setCanvasInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBcanvas) override; void setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBtexture) override;
void initCapabilities() override; void initCapabilities() override;
void getAPIStats(int &shaderswitches) const override; void getAPIStats(int &shaderswitches) const override;
+4 -4
View File
@@ -804,13 +804,13 @@ Rect OpenGL::getViewport() const
return state.viewport; return state.viewport;
} }
void OpenGL::setScissor(const Rect &v, bool canvasActive) void OpenGL::setScissor(const Rect &v, bool rtActive)
{ {
if (canvasActive) if (rtActive)
glScissor(v.x, v.y, v.w, v.h); glScissor(v.x, v.y, v.w, v.h);
else else
{ {
// With no Canvas active, we need to compensate for glScissor starting // With no RT active, we need to compensate for glScissor starting
// from the lower left of the viewport instead of the top left. // from the lower left of the viewport instead of the top left.
glScissor(v.x, state.viewport.h - (v.y + v.h), v.w, v.h); glScissor(v.x, state.viewport.h - (v.y + v.h), v.w, v.h);
} }
@@ -1996,7 +1996,7 @@ const char *OpenGL::framebufferStatusString(GLenum status)
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
return "Error in graphics driver (incomplete read buffer)"; return "Error in graphics driver (incomplete read buffer)";
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
return "Canvas with the specified MSAA count cannot be rendered to on this system."; return "Texture with the specified MSAA count cannot be rendered to on this system.";
case GL_FRAMEBUFFER_UNSUPPORTED: case GL_FRAMEBUFFER_UNSUPPORTED:
return "Renderable textures are unsupported"; return "Renderable textures are unsupported";
default: default:
+1 -1
View File
@@ -261,7 +261,7 @@ public:
* Sets the scissor box to the specified rectangle. * Sets the scissor box to the specified rectangle.
* The y-coordinate starts at the top and is flipped internally. * The y-coordinate starts at the top and is flipped internally.
**/ **/
void setScissor(const Rect &v, bool canvasActive); void setScissor(const Rect &v, bool rtActive);
/** /**
* Sets the global point size. * Sets the global point size.
+2 -2
View File
@@ -734,8 +734,8 @@ void Shader::updateBuiltinUniforms(love::graphics::Graphics *gfx, int viewportW,
// The shader does pixcoord.y = gl_FragCoord.y * params.z + params.w. // The shader does pixcoord.y = gl_FragCoord.y * params.z + params.w.
// This lets us flip pixcoord.y when needed, to be consistent (drawing // This lets us flip pixcoord.y when needed, to be consistent (drawing
// with no Canvas active makes the pixel coordinates y-flipped.) // with no RT active makes the pixel coordinates y-flipped.)
if (gfx->isCanvasActive()) if (gfx->isRenderTargetActive())
{ {
// No flipping: pixcoord.y = gl_FragCoord.y * 1.0 + 0.0. // No flipping: pixcoord.y = gl_FragCoord.y * 1.0 + 0.0.
data.screenSizeParams.z = 1.0f; data.screenSizeParams.z = 1.0f;
+1 -1
View File
@@ -402,7 +402,7 @@ void Texture::unloadVolatile()
if (isRenderTarget() && (fbo != 0 || renderbuffer != 0 || texture != 0)) if (isRenderTarget() && (fbo != 0 || renderbuffer != 0 || texture != 0))
{ {
// This is a bit ugly, but we need some way to destroy the cached FBO // This is a bit ugly, but we need some way to destroy the cached FBO
// when this Canvas' texture is destroyed. // when this texture's texture is destroyed.
auto gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS); auto gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr) if (gfx != nullptr)
gfx->cleanupRenderTexture(this); gfx->cleanupRenderTexture(this);
+7 -7
View File
@@ -169,7 +169,7 @@ int w_discard(lua_State *L)
else else
{ {
bool discardcolor = luax_optboolean(L, 1, true); bool discardcolor = luax_optboolean(L, 1, true);
size_t numbuffers = std::max((size_t) 1, instance()->getCanvas().colors.size()); size_t numbuffers = std::max((size_t) 1, instance()->getRenderTargets().colors.size());
colorbuffers = std::vector<bool>(numbuffers, discardcolor); colorbuffers = std::vector<bool>(numbuffers, discardcolor);
} }
@@ -271,7 +271,7 @@ int w_setCanvas(lua_State *L)
// called with none -> reset to default buffer // called with none -> reset to default buffer
if (lua_isnoneornil(L, 1)) if (lua_isnoneornil(L, 1))
{ {
instance()->setCanvas(); instance()->setRenderTarget();
return 0; return 0;
} }
@@ -295,7 +295,7 @@ int w_setCanvas(lua_State *L)
targets.colors.emplace_back(luax_checktexture(L, -1), 0); targets.colors.emplace_back(luax_checktexture(L, -1), 0);
if (targets.colors.back().texture->getTextureType() != TEXTURE_2D) if (targets.colors.back().texture->getTextureType() != TEXTURE_2D)
return luaL_error(L, "Non-2D canvases must use the table-of-tables variant of setCanvas."); return luaL_error(L, "Non-2D textures must use the table-of-tables variant of setRenderTargets.");
} }
lua_pop(L, 1); lua_pop(L, 1);
@@ -341,7 +341,7 @@ int w_setCanvas(lua_State *L)
} }
if (i > 1 && type != TEXTURE_2D) if (i > 1 && type != TEXTURE_2D)
return luaL_error(L, "This variant of setCanvas only supports 2D texture types."); return luaL_error(L, "This variant of setRenderTargets only supports 2D texture types.");
targets.colors.push_back(target); targets.colors.push_back(target);
} }
@@ -349,9 +349,9 @@ int w_setCanvas(lua_State *L)
luax_catchexcept(L, [&]() { luax_catchexcept(L, [&]() {
if (targets.getFirstTarget().texture != nullptr) if (targets.getFirstTarget().texture != nullptr)
instance()->setCanvas(targets); instance()->setRenderTargets(targets);
else else
instance()->setCanvas(); instance()->setRenderTarget();
}); });
return 0; return 0;
@@ -383,7 +383,7 @@ static void pushRenderTarget(lua_State *L, const Graphics::RenderTarget &rt)
int w_getCanvas(lua_State *L) int w_getCanvas(lua_State *L)
{ {
Graphics::RenderTargets targets = instance()->getCanvas(); Graphics::RenderTargets targets = instance()->getRenderTargets();
int ntargets = (int) targets.colors.size(); int ntargets = (int) targets.colors.size();
if (ntargets == 0) if (ntargets == 0)
+3 -3
View File
@@ -418,7 +418,7 @@ int w_Texture_renderTo(lua_State *L)
if (graphics) if (graphics)
{ {
// Save the current render targets so we can restore them when we're done. // Save the current render targets so we can restore them when we're done.
Graphics::RenderTargets oldtargets = graphics->getCanvas(); Graphics::RenderTargets oldtargets = graphics->getRenderTargets();
for (auto c : oldtargets.colors) for (auto c : oldtargets.colors)
c.texture->retain(); c.texture->retain();
@@ -427,7 +427,7 @@ int w_Texture_renderTo(lua_State *L)
oldtargets.depthStencil.texture->retain(); oldtargets.depthStencil.texture->retain();
luax_catchexcept(L, luax_catchexcept(L,
[&]() { graphics->setCanvas(rt, 0); }, [&]() { graphics->setRenderTarget(rt, 0); },
[&](bool err) [&](bool err)
{ {
if (err) if (err)
@@ -441,7 +441,7 @@ int w_Texture_renderTo(lua_State *L)
lua_settop(L, 2); // make sure the function is on top of the stack lua_settop(L, 2); // make sure the function is on top of the stack
int status = lua_pcall(L, 0, 0, 0); int status = lua_pcall(L, 0, 0, 0);
graphics->setCanvas(oldtargets); graphics->setRenderTargets(oldtargets);
for (auto c : oldtargets.colors) for (auto c : oldtargets.colors)
c.texture->release(); c.texture->release();
+6 -6
View File
@@ -432,8 +432,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
if (!graphics.get()) if (!graphics.get())
graphics.set(Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS)); graphics.set(Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS));
if (graphics.get() && graphics->isCanvasActive()) if (graphics.get() && graphics->isRenderTargetActive())
throw love::Exception("love.window.setMode cannot be called while a Canvas is active in love.graphics."); throw love::Exception("love.window.setMode cannot be called while a render target is active in love.graphics.");
WindowSettings f; WindowSettings f;
@@ -664,8 +664,8 @@ void Window::close(bool allowExceptions)
{ {
if (graphics.get()) if (graphics.get())
{ {
if (allowExceptions && graphics->isCanvasActive()) if (allowExceptions && graphics->isRenderTargetActive())
throw love::Exception("love.window.close cannot be called while a Canvas is active in love.graphics."); throw love::Exception("love.window.close cannot be called while a render target is active in love.graphics.");
graphics->unSetMode(); graphics->unSetMode();
} }
@@ -694,8 +694,8 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
if (!window) if (!window)
return false; return false;
if (graphics.get() && graphics->isCanvasActive()) if (graphics.get() && graphics->isRenderTargetActive())
throw love::Exception("love.window.setFullscreen cannot be called while a Canvas is active in love.graphics."); throw love::Exception("love.window.setFullscreen cannot be called while a render target is active in love.graphics.");
WindowSettings newsettings = settings; WindowSettings newsettings = settings;
newsettings.fullscreen = fullscreen; newsettings.fullscreen = fullscreen;