mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
graphics: clean up some shared backbuffer settings code.
This commit is contained in:
@@ -201,12 +201,7 @@ Graphics::DisplayState::DisplayState()
|
||||
|
||||
Graphics::Graphics(const char *name)
|
||||
: Module(M_GRAPHICS, name)
|
||||
, width(0)
|
||||
, height(0)
|
||||
, pixelWidth(0)
|
||||
, pixelHeight(0)
|
||||
, backbufferHasStencil(false)
|
||||
, backbufferHasDepth(false)
|
||||
, backbufferSettings()
|
||||
, created(false)
|
||||
, active(true)
|
||||
, batchedDrawState()
|
||||
@@ -736,7 +731,7 @@ void Graphics::validateStencilState(const StencilState &s) const
|
||||
const auto &rts = states.back().renderTargets;
|
||||
love::graphics::Texture *dstexture = rts.depthStencil.texture.get();
|
||||
|
||||
if (!isRenderTargetActive() && !backbufferHasStencil)
|
||||
if (!isRenderTargetActive() && !backbufferSettings.stencil)
|
||||
throw love::Exception("The window must have stenciling enabled to draw to the main screen's stencil buffer.");
|
||||
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.");
|
||||
@@ -750,7 +745,7 @@ void Graphics::validateDepthState(bool depthwrite) const
|
||||
const auto &rts = states.back().renderTargets;
|
||||
love::graphics::Texture *dstexture = rts.depthStencil.texture.get();
|
||||
|
||||
if (!isRenderTargetActive() && !backbufferHasDepth)
|
||||
if (!isRenderTargetActive() && !backbufferSettings.depth)
|
||||
throw love::Exception("The window must have depth enabled to draw to the main screen's depth buffer.");
|
||||
else if (isRenderTargetActive() && (rts.temporaryRTFlags & TEMPORARY_RT_DEPTH) == 0 && (dstexture == nullptr || !isPixelFormatDepth(dstexture->getPixelFormat())))
|
||||
throw love::Exception("Drawing to the depth buffer with a Canvas active requires either depth=true or a custom depth-type Canvas to be used, in setCanvas.");
|
||||
@@ -759,22 +754,22 @@ void Graphics::validateDepthState(bool depthwrite) const
|
||||
|
||||
int Graphics::getWidth() const
|
||||
{
|
||||
return width;
|
||||
return backbufferSettings.width;
|
||||
}
|
||||
|
||||
int Graphics::getHeight() const
|
||||
{
|
||||
return height;
|
||||
return backbufferSettings.height;
|
||||
}
|
||||
|
||||
int Graphics::getPixelWidth() const
|
||||
{
|
||||
return pixelWidth;
|
||||
return backbufferSettings.pixelWidth;
|
||||
}
|
||||
|
||||
int Graphics::getPixelHeight() const
|
||||
{
|
||||
return pixelHeight;
|
||||
return backbufferSettings.pixelHeight;
|
||||
}
|
||||
|
||||
double Graphics::getCurrentDPIScale() const
|
||||
@@ -791,6 +786,11 @@ double Graphics::getScreenDPIScale() const
|
||||
return (double) getPixelHeight() / (double) getHeight();
|
||||
}
|
||||
|
||||
int Graphics::getRequestedBackbufferMSAA() const
|
||||
{
|
||||
return backbufferSettings.msaa;
|
||||
}
|
||||
|
||||
bool Graphics::isCreated() const
|
||||
{
|
||||
return created;
|
||||
@@ -813,7 +813,12 @@ void Graphics::reset()
|
||||
|
||||
void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixelheight)
|
||||
{
|
||||
backbufferChanged(width, height, pixelwidth, pixelheight, backbufferHasStencil, backbufferHasDepth, getRequestedBackbufferMSAA());
|
||||
BackbufferSettings s = backbufferSettings;
|
||||
s.width = width;
|
||||
s.height = height;
|
||||
s.pixelWidth = pixelwidth;
|
||||
s.pixelHeight = pixelheight;
|
||||
backbufferChanged(s);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1235,7 +1240,7 @@ void Graphics::setRenderTarget()
|
||||
const RenderTargetsStrongRef prevRTs = state.renderTargets;
|
||||
|
||||
flushBatchedDraws();
|
||||
setRenderTargetsInternal(RenderTargets(), pixelWidth, pixelHeight, isGammaCorrect());
|
||||
setRenderTargetsInternal(RenderTargets(), backbufferSettings.pixelWidth, backbufferSettings.pixelHeight, isGammaCorrect());
|
||||
|
||||
state.renderTargets = RenderTargetsStrongRef();
|
||||
renderTargetSwitchCount++;
|
||||
|
||||
@@ -448,6 +448,30 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct BackbufferSettings
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int pixelWidth = 0;
|
||||
int pixelHeight = 0;
|
||||
bool stencil = false;
|
||||
bool depth = false;
|
||||
int msaa = 0;
|
||||
|
||||
bool operator == (const BackbufferSettings &other) const
|
||||
{
|
||||
return width == other.width && height == other.height
|
||||
&& pixelWidth == other.pixelWidth && pixelHeight == other.pixelHeight
|
||||
&& stencil == other.stencil && depth == other.depth
|
||||
&& msaa == other.msaa;
|
||||
}
|
||||
|
||||
bool operator != (const BackbufferSettings &other) const
|
||||
{
|
||||
return !(operator == (other));
|
||||
}
|
||||
};
|
||||
|
||||
Graphics(const char *name);
|
||||
virtual ~Graphics();
|
||||
|
||||
@@ -505,13 +529,13 @@ public:
|
||||
/**
|
||||
* Called when the backbuffer changes.
|
||||
**/
|
||||
virtual void backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa) = 0;
|
||||
virtual void backbufferChanged(const BackbufferSettings &settings) = 0;
|
||||
void backbufferChanged(int width, int height, int pixelwidth, int pixelheight);
|
||||
|
||||
/**
|
||||
* Sets the current graphics display viewport and initializes the renderer.
|
||||
**/
|
||||
virtual bool setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa) = 0;
|
||||
virtual bool setMode(void *context, const BackbufferSettings &settings) = 0;
|
||||
|
||||
/**
|
||||
* Un-sets the current graphics display mode (uninitializing objects if
|
||||
@@ -546,7 +570,7 @@ public:
|
||||
double getCurrentDPIScale() const;
|
||||
double getScreenDPIScale() const;
|
||||
|
||||
virtual int getRequestedBackbufferMSAA() const = 0;
|
||||
int getRequestedBackbufferMSAA() const;
|
||||
virtual int getBackbufferMSAA() const = 0;
|
||||
|
||||
Buffer *getQuadIndexBuffer() const { return quadIndexBuffer; }
|
||||
@@ -1051,13 +1075,7 @@ protected:
|
||||
|
||||
void updateDeviceProjection(const Matrix4 &projection);
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int pixelWidth;
|
||||
int pixelHeight;
|
||||
|
||||
bool backbufferHasStencil;
|
||||
bool backbufferHasDepth;
|
||||
BackbufferSettings backbufferSettings;
|
||||
|
||||
bool created;
|
||||
bool active;
|
||||
|
||||
@@ -64,8 +64,8 @@ public:
|
||||
love::graphics::Texture *newTextureView(love::graphics::Texture *base, const Texture::ViewSettings &viewsettings) override;
|
||||
love::graphics::Buffer *newBuffer(const Buffer::Settings &settings, const std::vector<Buffer::DataDeclaration> &format, const void *data, size_t size, size_t arraylength) override;
|
||||
|
||||
void backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa) override;
|
||||
bool setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa) override;
|
||||
void backbufferChanged(const BackbufferSettings &settings) override;
|
||||
bool setMode(void *context, const BackbufferSettings &settings) override;
|
||||
void unSetMode() override;
|
||||
|
||||
void setActive(bool active) override;
|
||||
@@ -84,7 +84,6 @@ public:
|
||||
|
||||
void present(void *screenshotCallbackData) override;
|
||||
|
||||
int getRequestedBackbufferMSAA() const override;
|
||||
int getBackbufferMSAA() const override;
|
||||
|
||||
void setColor(Colorf c) override;
|
||||
@@ -231,7 +230,6 @@ private:
|
||||
|
||||
StrongRef<love::graphics::Texture> backbufferMSAA;
|
||||
StrongRef<love::graphics::Texture> backbufferDepthStencil;
|
||||
int requestedBackbufferMSAA;
|
||||
|
||||
AttachmentStoreActions attachmentStoreActions;
|
||||
|
||||
|
||||
@@ -278,7 +278,6 @@ Graphics::Graphics()
|
||||
, lastCullMode(CULL_MAX_ENUM)
|
||||
, lastRenderPipelineKey()
|
||||
, shaderSwitches(0)
|
||||
, requestedBackbufferMSAA(0)
|
||||
, attachmentStoreActions()
|
||||
, renderBindings()
|
||||
, uniformBufferOffset(0)
|
||||
@@ -486,22 +485,15 @@ love::graphics::GraphicsReadback *Graphics::newReadbackInternal(ReadbackMethod m
|
||||
return new GraphicsReadback(this, method, texture, slice, mipmap, rect, dest, destx, desty);
|
||||
}
|
||||
|
||||
void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
|
||||
void Graphics::backbufferChanged(const BackbufferSettings &settings)
|
||||
{
|
||||
bool sizechanged = width != this->width || height != this->height
|
||||
|| pixelwidth != this->pixelWidth || pixelheight != this->pixelHeight;
|
||||
bool sizechanged = settings.width != backbufferSettings.width || settings.height != backbufferSettings.height
|
||||
|| settings.pixelWidth != backbufferSettings.pixelWidth || settings.pixelHeight != backbufferSettings.pixelHeight;
|
||||
|
||||
bool dschanged = backbufferstencil != this->backbufferHasStencil || backbufferdepth != this->backbufferHasDepth;
|
||||
bool msaachanged = msaa != this->requestedBackbufferMSAA;
|
||||
bool dschanged = settings.stencil != backbufferSettings.stencil || settings.depth != backbufferSettings.depth;
|
||||
bool msaachanged = settings.msaa != backbufferSettings.msaa;
|
||||
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->pixelWidth = pixelwidth;
|
||||
this->pixelHeight = pixelheight;
|
||||
|
||||
this->backbufferHasStencil = backbufferstencil;
|
||||
this->backbufferHasDepth = backbufferdepth;
|
||||
this->requestedBackbufferMSAA = msaa;
|
||||
backbufferSettings = settings;
|
||||
|
||||
if (!isRenderTargetActive())
|
||||
{
|
||||
@@ -509,44 +501,42 @@ void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixe
|
||||
resetProjection();
|
||||
}
|
||||
|
||||
Texture::Settings settings;
|
||||
settings.width = width;
|
||||
settings.height = height;
|
||||
settings.dpiScale = (float)pixelheight / (float)height;
|
||||
settings.msaa = getRequestedBackbufferMSAA();
|
||||
settings.renderTarget = true;
|
||||
settings.readable.set(false);
|
||||
Texture::Settings ts;
|
||||
ts.width = settings.width;
|
||||
ts.height = settings.height;
|
||||
ts.dpiScale = (float)settings.pixelHeight / (float)settings.height;
|
||||
ts.msaa = getRequestedBackbufferMSAA();
|
||||
ts.renderTarget = true;
|
||||
ts.readable.set(false);
|
||||
|
||||
if (sizechanged || msaachanged)
|
||||
{
|
||||
backbufferMSAA.set(nullptr);
|
||||
if (settings.msaa > 1)
|
||||
if (ts.msaa > 1)
|
||||
{
|
||||
settings.format = isGammaCorrect() ? PIXELFORMAT_BGRA8_sRGB : PIXELFORMAT_BGRA8_UNORM;
|
||||
backbufferMSAA.set(newTexture(settings), Acquire::NORETAIN);
|
||||
ts.format = isGammaCorrect() ? PIXELFORMAT_BGRA8_sRGB : PIXELFORMAT_BGRA8_UNORM;
|
||||
backbufferMSAA.set(newTexture(ts), Acquire::NORETAIN);
|
||||
}
|
||||
}
|
||||
|
||||
if (sizechanged || msaachanged || dschanged)
|
||||
{
|
||||
backbufferDepthStencil.set(nullptr);
|
||||
if (backbufferstencil || backbufferdepth)
|
||||
if (settings.stencil || settings.depth)
|
||||
{
|
||||
if (backbufferstencil && backbufferdepth)
|
||||
settings.format = PIXELFORMAT_DEPTH24_UNORM_STENCIL8;
|
||||
else if (backbufferstencil)
|
||||
settings.format = PIXELFORMAT_STENCIL8;
|
||||
else if (backbufferdepth)
|
||||
settings.format = PIXELFORMAT_DEPTH24_UNORM;
|
||||
backbufferDepthStencil.set(newTexture(settings), Acquire::NORETAIN);
|
||||
if (settings.stencil && settings.depth)
|
||||
ts.format = PIXELFORMAT_DEPTH24_UNORM_STENCIL8;
|
||||
else if (settings.stencil)
|
||||
ts.format = PIXELFORMAT_STENCIL8;
|
||||
else if (settings.depth)
|
||||
ts.format = PIXELFORMAT_DEPTH24_UNORM;
|
||||
backbufferDepthStencil.set(newTexture(ts), Acquire::NORETAIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
|
||||
bool Graphics::setMode(void *context, const BackbufferSettings &settings)
|
||||
{ @autoreleasepool {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->metalLayer = (__bridge CAMetalLayer *) context;
|
||||
|
||||
metalLayer.device = device;
|
||||
@@ -560,7 +550,7 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int
|
||||
metalLayer.magnificationFilter = kCAFilterNearest;
|
||||
#endif
|
||||
|
||||
backbufferChanged(width, height, pixelwidth, pixelheight, backbufferstencil, backbufferdepth, msaa);
|
||||
backbufferChanged(settings);
|
||||
|
||||
created = true;
|
||||
|
||||
@@ -1786,11 +1776,6 @@ void Graphics::present(void *screenshotCallbackData)
|
||||
processCompletedCommandBuffers();
|
||||
}}
|
||||
|
||||
int Graphics::getRequestedBackbufferMSAA() const
|
||||
{
|
||||
return requestedBackbufferMSAA;
|
||||
}
|
||||
|
||||
int Graphics::getBackbufferMSAA() const
|
||||
{
|
||||
return backbufferMSAA.get() ? backbufferMSAA->getMSAA() : 0;
|
||||
|
||||
@@ -110,7 +110,6 @@ Graphics::Graphics()
|
||||
, windowHasStencil(false)
|
||||
, mainVAO(0)
|
||||
, internalBackbufferFBO(0)
|
||||
, requestedBackbufferMSAA(0)
|
||||
, bufferMapMemory(nullptr)
|
||||
, bufferMapMemorySize(2 * 1024 * 1024)
|
||||
, pixelFormatUsage()
|
||||
@@ -188,27 +187,15 @@ love::graphics::GraphicsReadback *Graphics::newReadbackInternal(ReadbackMethod m
|
||||
return new GraphicsReadback(this, method, texture, slice, mipmap, rect, dest, destx, desty);
|
||||
}
|
||||
|
||||
void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
|
||||
void Graphics::backbufferChanged(const BackbufferSettings &settings)
|
||||
{
|
||||
bool changed = width != this->width || height != this->height
|
||||
|| pixelwidth != this->pixelWidth || pixelheight != this->pixelHeight;
|
||||
|
||||
changed |= backbufferstencil != this->backbufferHasStencil || backbufferdepth != this->backbufferHasDepth;
|
||||
changed |= msaa != this->requestedBackbufferMSAA;
|
||||
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->pixelWidth = pixelwidth;
|
||||
this->pixelHeight = pixelheight;
|
||||
|
||||
this->backbufferHasStencil = backbufferstencil;
|
||||
this->backbufferHasDepth = backbufferdepth;
|
||||
this->requestedBackbufferMSAA = msaa;
|
||||
bool changed = settings != backbufferSettings;
|
||||
backbufferSettings = settings;
|
||||
|
||||
if (!isRenderTargetActive())
|
||||
{
|
||||
// Set the viewport to top-left corner.
|
||||
gl.setViewport({0, 0, pixelwidth, pixelheight});
|
||||
gl.setViewport({0, 0, settings.pixelWidth, settings.pixelHeight});
|
||||
|
||||
// Re-apply the scissor if it was active, since the rectangle passed to
|
||||
// glScissor is affected by the viewport dimensions.
|
||||
@@ -222,7 +209,7 @@ void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixe
|
||||
return;
|
||||
|
||||
bool useinternalbackbuffer = false;
|
||||
if (msaa > 1)
|
||||
if (settings.msaa > 1)
|
||||
useinternalbackbuffer = true;
|
||||
|
||||
GLuint prevFBO = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
|
||||
@@ -230,27 +217,27 @@ void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixe
|
||||
|
||||
if (useinternalbackbuffer)
|
||||
{
|
||||
Texture::Settings settings;
|
||||
settings.width = width;
|
||||
settings.height = height;
|
||||
settings.dpiScale = (float)pixelheight / (float)height;
|
||||
settings.msaa = msaa;
|
||||
settings.renderTarget = true;
|
||||
settings.readable.set(false);
|
||||
Texture::Settings ts;
|
||||
ts.width = settings.width;
|
||||
ts.height = settings.height;
|
||||
ts.dpiScale = (float)settings.pixelHeight / (float)settings.height;
|
||||
ts.msaa = settings.msaa;
|
||||
ts.renderTarget = true;
|
||||
ts.readable.set(false);
|
||||
|
||||
settings.format = isGammaCorrect() ? PIXELFORMAT_RGBA8_sRGB : PIXELFORMAT_RGBA8_UNORM;
|
||||
internalBackbuffer.set(newTexture(settings), Acquire::NORETAIN);
|
||||
ts.format = isGammaCorrect() ? PIXELFORMAT_RGBA8_sRGB : PIXELFORMAT_RGBA8_UNORM;
|
||||
internalBackbuffer.set(newTexture(ts), Acquire::NORETAIN);
|
||||
|
||||
internalBackbufferDepthStencil.set(nullptr);
|
||||
if (backbufferstencil || backbufferdepth)
|
||||
if (settings.stencil || settings.depth)
|
||||
{
|
||||
if (backbufferstencil && backbufferdepth)
|
||||
settings.format = PIXELFORMAT_DEPTH24_UNORM_STENCIL8;
|
||||
else if (backbufferstencil)
|
||||
settings.format = PIXELFORMAT_STENCIL8;
|
||||
else if (backbufferdepth)
|
||||
settings.format = PIXELFORMAT_DEPTH24_UNORM;
|
||||
internalBackbufferDepthStencil.set(newTexture(settings), Acquire::NORETAIN);
|
||||
if (settings.stencil && settings.depth)
|
||||
ts.format = PIXELFORMAT_DEPTH24_UNORM_STENCIL8;
|
||||
else if (settings.stencil)
|
||||
ts.format = PIXELFORMAT_STENCIL8;
|
||||
else if (settings.depth)
|
||||
ts.format = PIXELFORMAT_DEPTH24_UNORM;
|
||||
internalBackbufferDepthStencil.set(newTexture(ts), Acquire::NORETAIN);
|
||||
}
|
||||
|
||||
RenderTargets rts;
|
||||
@@ -293,7 +280,7 @@ GLuint Graphics::getSystemBackbufferFBO() const
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Graphics::setMode(void */*context*/, int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
|
||||
bool Graphics::setMode(void */*context*/, const BackbufferSettings &settings)
|
||||
{
|
||||
// Okay, setup OpenGL.
|
||||
gl.initContext();
|
||||
@@ -350,7 +337,7 @@ bool Graphics::setMode(void */*context*/, int width, int height, int pixelwidth,
|
||||
|
||||
setDebug(isDebugEnabled());
|
||||
|
||||
backbufferChanged(width, height, pixelwidth, pixelheight, backbufferstencil, backbufferdepth, msaa);
|
||||
backbufferChanged(settings);
|
||||
|
||||
if (batchedDrawState.vb[0] == nullptr)
|
||||
{
|
||||
@@ -1314,11 +1301,6 @@ void Graphics::present(void *screenshotCallbackData)
|
||||
updateTemporaryResources();
|
||||
}
|
||||
|
||||
int Graphics::getRequestedBackbufferMSAA() const
|
||||
{
|
||||
return requestedBackbufferMSAA;
|
||||
}
|
||||
|
||||
int Graphics::getBackbufferMSAA() const
|
||||
{
|
||||
return internalBackbuffer.get() ? internalBackbuffer->getMSAA() : 0;
|
||||
|
||||
@@ -60,8 +60,8 @@ public:
|
||||
love::graphics::Texture *newTextureView(love::graphics::Texture *base, const Texture::ViewSettings &viewsettings) override;
|
||||
love::graphics::Buffer *newBuffer(const Buffer::Settings &settings, const std::vector<Buffer::DataDeclaration> &format, const void *data, size_t size, size_t arraylength) override;
|
||||
|
||||
void backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa) override;
|
||||
bool setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa) override;
|
||||
void backbufferChanged(const BackbufferSettings &settings) override;
|
||||
bool setMode(void *context, const BackbufferSettings &settings) override;
|
||||
void unSetMode() override;
|
||||
|
||||
void setActive(bool active) override;
|
||||
@@ -80,7 +80,6 @@ public:
|
||||
|
||||
void present(void *screenshotCallbackData) override;
|
||||
|
||||
int getRequestedBackbufferMSAA() const override;
|
||||
int getBackbufferMSAA() const override;
|
||||
|
||||
void setColor(Colorf c) override;
|
||||
@@ -166,7 +165,6 @@ private:
|
||||
StrongRef<love::graphics::Texture> internalBackbuffer;
|
||||
StrongRef<love::graphics::Texture> internalBackbufferDepthStencil;
|
||||
GLuint internalBackbufferFBO;
|
||||
int requestedBackbufferMSAA;
|
||||
|
||||
char *bufferMapMemory;
|
||||
size_t bufferMapMemorySize;
|
||||
|
||||
@@ -265,7 +265,7 @@ void Graphics::clear(const std::vector<OptionalColorD> &colors, OptionalInt sten
|
||||
|
||||
if (stencil.hasValue)
|
||||
{
|
||||
if ((!rtactive && backbufferHasStencil)
|
||||
if ((!rtactive && backbufferSettings.stencil)
|
||||
|| (dstexture && isPixelFormatStencil(dstexture->getPixelFormat())) || (rts.temporaryRTFlags & TEMPORARY_RT_STENCIL) != 0)
|
||||
{
|
||||
depthStencilAttachment.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
@@ -274,7 +274,7 @@ void Graphics::clear(const std::vector<OptionalColorD> &colors, OptionalInt sten
|
||||
}
|
||||
if (depth.hasValue)
|
||||
{
|
||||
if ((!rtactive && backbufferHasDepth)
|
||||
if ((!rtactive && backbufferSettings.depth)
|
||||
|| (dstexture && isPixelFormatDepth(dstexture->getPixelFormat())) || (rts.temporaryRTFlags & TEMPORARY_RT_DEPTH) != 0)
|
||||
{
|
||||
depthStencilAttachment.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
@@ -617,26 +617,18 @@ void Graphics::present(void *screenshotCallbackdata)
|
||||
beginFrame();
|
||||
}
|
||||
|
||||
void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
|
||||
void Graphics::backbufferChanged(const BackbufferSettings &settings)
|
||||
{
|
||||
if (swapChain != VK_NULL_HANDLE && (pixelwidth != this->pixelWidth || pixelheight != this->pixelHeight || width != this->width || height != this->height
|
||||
|| backbufferstencil != this->backbufferHasStencil || backbufferdepth != this->backbufferHasDepth || msaa != requestedMsaa))
|
||||
if (swapChain != VK_NULL_HANDLE && settings != backbufferSettings)
|
||||
requestSwapchainRecreation();
|
||||
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->pixelWidth = pixelwidth;
|
||||
this->pixelHeight = pixelheight;
|
||||
|
||||
this->backbufferHasStencil = backbufferstencil;
|
||||
this->backbufferHasDepth = backbufferdepth;
|
||||
this->requestedMsaa = msaa;
|
||||
backbufferSettings = settings;
|
||||
|
||||
if (!isRenderTargetActive())
|
||||
resetProjection();
|
||||
|
||||
if (swapChain != VK_NULL_HANDLE)
|
||||
msaaSamples = getMsaaCount(requestedMsaa);
|
||||
msaaSamples = getMsaaCount(settings.msaa);
|
||||
|
||||
// Don't wait until the next frame starts to recreate the swapchain - doing so
|
||||
// will cause a 1 frame delay in the backbuffer size on resize, and it can cause
|
||||
@@ -650,10 +642,10 @@ void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixe
|
||||
}
|
||||
}
|
||||
|
||||
bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
|
||||
bool Graphics::setMode(void *context, const BackbufferSettings &settings)
|
||||
{
|
||||
// Must be called before the swapchain is created.
|
||||
backbufferChanged(width, height, pixelwidth, pixelheight, backbufferstencil, backbufferdepth, msaa);
|
||||
backbufferChanged(settings);
|
||||
|
||||
cleanUpFunctions.clear();
|
||||
cleanUpFunctions.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
@@ -674,7 +666,7 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int
|
||||
initCapabilities();
|
||||
}
|
||||
|
||||
msaaSamples = getMsaaCount(requestedMsaa);
|
||||
msaaSamples = getMsaaCount(settings.msaa);
|
||||
|
||||
createSwapChain();
|
||||
createImageViews();
|
||||
@@ -830,11 +822,6 @@ void Graphics::setActive(bool enable)
|
||||
active = enable;
|
||||
}
|
||||
|
||||
int Graphics::getRequestedBackbufferMSAA() const
|
||||
{
|
||||
return requestedMsaa;
|
||||
}
|
||||
|
||||
int Graphics::getBackbufferMSAA() const
|
||||
{
|
||||
return static_cast<int>(msaaSamples);
|
||||
@@ -2076,8 +2063,8 @@ void Graphics::createSwapChain()
|
||||
// because newTexture needs an active command buffer to do its initial
|
||||
// layout transitions.
|
||||
swapChainImages.clear();
|
||||
extent.width = std::max(1, pixelWidth);
|
||||
extent.height = std::max(1, pixelHeight);
|
||||
extent.width = std::max(1, backbufferSettings.pixelWidth);
|
||||
extent.height = std::max(1, backbufferSettings.pixelHeight);
|
||||
|
||||
if (isGammaCorrect())
|
||||
surfaceFormat.format = VK_FORMAT_R8G8B8A8_SRGB;
|
||||
@@ -2190,8 +2177,8 @@ VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabiliti
|
||||
else
|
||||
{
|
||||
VkExtent2D actualExtent = {
|
||||
static_cast<uint32_t>(pixelWidth),
|
||||
static_cast<uint32_t>(pixelHeight)
|
||||
static_cast<uint32_t>(backbufferSettings.pixelWidth),
|
||||
static_cast<uint32_t>(backbufferSettings.pixelHeight)
|
||||
};
|
||||
|
||||
actualExtent.width = clampuint32_t(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
||||
@@ -2696,7 +2683,7 @@ void Graphics::setDefaultRenderPass()
|
||||
|
||||
RenderPassConfiguration renderPassConfiguration{};
|
||||
|
||||
VkFormat dsformat = backbufferHasDepth || backbufferHasStencil ? depthStencilFormat : VK_FORMAT_UNDEFINED;
|
||||
VkFormat dsformat = backbufferSettings.depth || backbufferSettings.stencil ? depthStencilFormat : VK_FORMAT_UNDEFINED;
|
||||
renderPassConfiguration.staticData.depthStencilAttachment = { dsformat, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_LOAD_OP_LOAD, msaaSamples };
|
||||
if (msaaSamples & VK_SAMPLE_COUNT_1_BIT)
|
||||
renderPassConfiguration.staticData.resolve = false;
|
||||
@@ -2741,13 +2728,13 @@ void Graphics::setDefaultRenderPass()
|
||||
renderPassState.clearColors[0].color = Texture::getClearColor(nullptr, renderPassState.mainWindowClearColorValue.value);
|
||||
}
|
||||
|
||||
if (renderPassState.mainWindowClearDepthValue.hasValue && backbufferHasDepth)
|
||||
if (renderPassState.mainWindowClearDepthValue.hasValue && backbufferSettings.depth)
|
||||
{
|
||||
renderPassState.renderPassConfiguration.staticData.depthStencilAttachment.depthLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
renderPassState.clearColors[1].depthStencil.depth = static_cast<float>(renderPassState.mainWindowClearDepthValue.value);
|
||||
}
|
||||
|
||||
if (renderPassState.mainWindowClearStencilValue.hasValue && backbufferHasStencil)
|
||||
if (renderPassState.mainWindowClearStencilValue.hasValue && backbufferSettings.stencil)
|
||||
{
|
||||
renderPassState.renderPassConfiguration.staticData.depthStencilAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
renderPassState.clearColors[1].depthStencil.stencil = static_cast<uint32_t>(renderPassState.mainWindowClearStencilValue.value);
|
||||
@@ -3304,7 +3291,7 @@ VkFormat Graphics::findDepthFormat()
|
||||
|
||||
void Graphics::createDepthResources()
|
||||
{
|
||||
if (!backbufferHasDepth && !backbufferHasStencil)
|
||||
if (!backbufferSettings.depth && !backbufferSettings.stencil)
|
||||
{
|
||||
depthImage = VK_NULL_HANDLE;
|
||||
depthImageView = VK_NULL_HANDLE;
|
||||
@@ -3343,9 +3330,9 @@ void Graphics::createDepthResources()
|
||||
imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
imageViewInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
if (backbufferHasDepth)
|
||||
if (backbufferSettings.depth)
|
||||
imageViewInfo.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
if (backbufferHasStencil)
|
||||
if (backbufferSettings.stencil)
|
||||
imageViewInfo.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
imageViewInfo.subresourceRange.baseMipLevel = 0;
|
||||
imageViewInfo.subresourceRange.levelCount = 1;
|
||||
|
||||
@@ -240,11 +240,10 @@ public:
|
||||
void clear(const std::vector<OptionalColorD> &colors, OptionalInt stencil, OptionalDouble depth) override;
|
||||
void discard(const std::vector<bool>& colorbuffers, bool depthstencil) override;
|
||||
void present(void *screenshotCallbackdata) override;
|
||||
void backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa) override;
|
||||
bool setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa) override;
|
||||
void backbufferChanged(const BackbufferSettings &settings) override;
|
||||
bool setMode(void *context, const BackbufferSettings &settings) override;
|
||||
void unSetMode() override;
|
||||
void setActive(bool active) override;
|
||||
int getRequestedBackbufferMSAA() const override;
|
||||
int getBackbufferMSAA() const override;
|
||||
void setColor(Colorf c) override;
|
||||
void setScissor(const Rect &rect) override;
|
||||
@@ -364,7 +363,6 @@ private:
|
||||
VkInstance instance = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
uint32_t deviceApiVersion = VK_API_VERSION_1_0;
|
||||
int requestedMsaa = 0;
|
||||
VkDevice device = VK_NULL_HANDLE;
|
||||
OptionalInstanceExtensions optionalInstanceExtensions;
|
||||
OptionalDeviceExtensions optionalDeviceExtensions;
|
||||
|
||||
@@ -658,6 +658,15 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
|
||||
double scaledw, scaledh;
|
||||
fromPixels((double) pixelWidth, (double) pixelHeight, scaledw, scaledh);
|
||||
|
||||
graphics::Graphics::BackbufferSettings backbufferSettings;
|
||||
backbufferSettings.width = (int)scaledw;
|
||||
backbufferSettings.height = (int)scaledh;
|
||||
backbufferSettings.pixelWidth = pixelWidth;
|
||||
backbufferSettings.pixelHeight = pixelHeight;
|
||||
backbufferSettings.stencil = f.stencil;
|
||||
backbufferSettings.depth = f.depth;
|
||||
backbufferSettings.msaa = f.msaa;
|
||||
|
||||
if (needsetmode)
|
||||
{
|
||||
void *context = nullptr;
|
||||
@@ -669,11 +678,11 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
|
||||
#endif
|
||||
|
||||
// TODO: try/catch
|
||||
graphics->setMode(context, (int) scaledw, (int) scaledh, pixelWidth, pixelHeight, f.stencil, f.depth, f.msaa);
|
||||
graphics->setMode(context, backbufferSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics->backbufferChanged((int) scaledw, (int) scaledh, pixelWidth, pixelHeight, f.stencil, f.depth, f.msaa);
|
||||
graphics->backbufferChanged(backbufferSettings);
|
||||
}
|
||||
|
||||
this->settings.msaa = graphics->getBackbufferMSAA();
|
||||
|
||||
Reference in New Issue
Block a user