Commit add7e8e8 authored by Laszlo Agocs's avatar Laszlo Agocs

gl: Add support for sRGB in default fb at least

...so that setting QRhiSwapChain::sRGB behaves identically between
all 4 backends.
parent f2d394d4
......@@ -483,6 +483,8 @@ int main(int argc, char **argv)
fmt.setSamples(sampleCount);
if (scFlags.testFlag(QRhiSwapChain::NoVSync))
fmt.setSwapInterval(0);
if (scFlags.testFlag(QRhiSwapChain::sRGB))
fmt.setColorSpace(QSurfaceFormat::sRGBColorSpace);
QSurfaceFormat::setDefaultFormat(fmt);
// Vulkan setup.
......
......@@ -1887,7 +1887,7 @@ QRhiRenderBuffer::QRhiRenderBuffer(QRhiImplementation *rhi, Type type_, const QS
QRhiResourceUpdateBatch::generateMips(). Multisample textures cannot have
mipmaps.
\value sRGB Use an sRGB format
\value sRGB Use an sRGB format.
\value UsedAsTransferSource The texture is used as the source of a texture
copy or readback, meaning the texture is given as the source in
......@@ -2955,7 +2955,12 @@ QRhiGraphicsPipeline::QRhiGraphicsPipeline(QRhiImplementation *rhi)
\value SurfaceHasNonPreMulAlpha Indicates the target surface has
transparencyt with non-premultiplied alpha.
\value sRGB Requests to pick an sRGB format.
\value sRGB Requests to pick an sRGB format for the swapchain and/or its
render target views, where applicable. Note that this implies that sRGB
framebuffer update and blending will get enabled for all content targeting
this swapchain, and opting out is not possible. For OpenGL, set
\l{QSurfaceFormat::sRGBColorSpace}{sRGBColorSpace} on the QSurfaceFormat of
the QWindow in addition.
\value UsedAsTransferSource Indicates the the swapchain will be used as the
source of a readback in QRhiResourceUpdateBatch::readBackTexture().
......
......@@ -177,6 +177,14 @@ QT_BEGIN_NAMESPACE
#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69
#endif
#ifndef GL_FRAMEBUFFER_SRGB
#define GL_FRAMEBUFFER_SRGB 0x8DB9
#endif
#ifndef GL_FRAMEBUFFER_SRGB_CAPABLE
#define GL_FRAMEBUFFER_SRGB_CAPABLE 0x8DBA
#endif
static QSurfaceFormat qrhigles2_effectiveFormat()
{
QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
......@@ -329,6 +337,14 @@ bool QRhiGles2::create(QRhi::Flags flags)
caps.r8Format = f->hasOpenGLFeature(QOpenGLFunctions::TextureRGFormats);
caps.r16Format = f->hasOpenGLExtension(QOpenGLExtensions::Sized16Formats);
caps.srgbCapableDefaultFramebuffer = false;
if (ctx->hasExtension(QByteArrayLiteral("GL_ARB_framebuffer_sRGB"))) {
GLint srgbCapable = 0;
f->glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE, &srgbCapable);
if (srgbCapable)
caps.srgbCapableDefaultFramebuffer = true;
}
nativeHandlesStruct.context = ctx;
if (rsh) {
......@@ -1474,6 +1490,12 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
f->glBindFramebuffer(GL_FRAMEBUFFER, cmd.args.bindFramebuffer.fbo);
else
f->glBindFramebuffer(GL_FRAMEBUFFER, ctx->defaultFramebufferObject());
if (caps.srgbCapableDefaultFramebuffer) {
if (cmd.args.bindFramebuffer.srgb)
f->glEnable(GL_FRAMEBUFFER_SRGB);
else
f->glDisable(GL_FRAMEBUFFER_SRGB);
}
break;
case QGles2CommandBuffer::Command::Clear:
f->glDisable(GL_SCISSOR_TEST);
......@@ -1812,6 +1834,7 @@ void QRhiGles2::beginPass(QRhiCommandBuffer *cb,
Q_UNREACHABLE();
break;
}
fbCmd.args.bindFramebuffer.srgb = rtD->srgbUpdateAndBlend;
cbD->commands.append(fbCmd);
cbD->currentTarget = rt;
......@@ -2656,6 +2679,7 @@ bool QGles2SwapChain::buildOrResize()
rt.d.pixelSize = pixelSize;
rt.d.dpr = m_window->devicePixelRatio();
rt.d.attCount = m_depthStencil ? 2 : 1;
rt.d.srgbUpdateAndBlend = m_flags.testFlag(QRhiSwapChain::sRGB);
frameCount = 0;
......
......@@ -137,6 +137,7 @@ struct QGles2RenderTargetData
QSize pixelSize;
float dpr = 1;
int attCount = 0;
bool srgbUpdateAndBlend = false;
};
struct QGles2ReferenceRenderTarget : public QRhiRenderTarget
......@@ -313,6 +314,7 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
} clear;
struct {
GLuint fbo;
bool srgb;
} bindFramebuffer;
struct {
GLenum target;
......@@ -559,7 +561,8 @@ public:
bgraExternalFormat(false),
bgraInternalFormat(false),
r8Format(false),
r16Format(false)
r16Format(false),
srgbCapableDefaultFramebuffer(false)
{ }
int maxTextureSize;
// Multisample fb and blit are supported (GLES 3.0 or OpenGL 3.x). Not
......@@ -572,6 +575,7 @@ public:
uint bgraInternalFormat : 1;
uint r8Format : 1;
uint r16Format : 1;
uint srgbCapableDefaultFramebuffer : 1;
} caps;
bool inFrame = false;
bool inPass = false;
......
gl: srgb textures/rt
vk: image in wrong layout when beginFrame-endFrame without a pass in it
reduce viewport/scissor/other state changes in a pass (?)
anisotropic
res.sh.: example to show read/write same texture?
event/fence for res.sh.?
advanced blend modes
gl: tex formats (texture, readback)
gl: srgb? (glEnable and co.)
should istexformatsupported should check srgb combinations
vk: image in wrong layout when beginFrame-endFrame without a pass in it
cbuffer alignment rules - some things fail to translate (to hlsl e.g. with structs), which is fine but how to mitigate
what does image copy do for compressed formats?
reduce viewport/scissor/other state changes in a pass
vk: test FrameOpDeviceLost somehow
d3d device loss?
more what-if-resource-rebuilt cases
anisotropic
gl: more ubuf types
more QImage->tex formats
if tex adjust its size (e.g. npot on gl), should QImage get scaled automatically?
......@@ -43,6 +41,9 @@ dxc for d3d as an alternative to fxc?
hlsl -> dxc -> spirv -> spirv-cross hmmm...
+++ done
gl: tex formats (texture)
gl: srgb? (glEnable and co.)
more what-if-resource-rebuilt cases
res.sh.: mtl
res.sh.: gl
res.sh.: exercise it in multiwindow_threaded too
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment