Commit 72450e45 authored by Laszlo Agocs's avatar Laszlo Agocs

Add isYUpInNDC()

Complements isYUpInFramebuffer().
parent 064fc28a
......@@ -3900,7 +3900,8 @@ QSize QRhi::sizeForMipLevel(int mipLevel, const QSize &baseLevelSize) const
}
/*!
\return \c true if the underlying graphics API has Y up in the framebuffer.
\return \c true if the underlying graphics API has the Y axis pointing up
in framebuffers and images.
In practice this is \c true for OpenGL only.
*/
......@@ -3910,12 +3911,27 @@ bool QRhi::isYUpInFramebuffer() const
}
/*!
\return a matrix that can be used allow applications keep using
OpenGL-targeted vertex data and projection matrices (for example, the ones
generated by QMatrix4x4::perspective()) regardless of the backed. Once
\c{this_matrix * mvp} is used instead of just \c mvp, vertex data with Y up
and viewports with depth range 0 - 1 can be used without considering what
backend and so graphics API is going to be used at run time.
\return \c true if the underlying graphics API has the Y axis pointing up
in its normalized device coordinate system.
In practice this is \c false for Vulkan only.
\note clipSpaceCorrMatrix() includes the corresponding adjustment (to make
Y point up) in its returned matrix.
*/
bool QRhi::isYUpInNDC() const
{
return d->isYUpInNDC();
}
/*!
\return a matrix that can be used to allow applications keep using
OpenGL-targeted vertex data and perspective projection matrices (such as,
the ones generated by QMatrix4x4::perspective()), regardless of the
backend. Once \c{this_matrix * mvp} is used instead of just \c mvp, vertex
data with Y up and viewports with depth range 0 - 1 can be used without
considering what backend and so graphics API is going to be used at run
time.
See
\l{https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/}{this
......
......@@ -1283,6 +1283,7 @@ public:
QSize sizeForMipLevel(int mipLevel, const QSize &baseLevelSize) const;
bool isYUpInFramebuffer() const;
bool isYUpInNDC() const;
QMatrix4x4 clipSpaceCorrMatrix() const;
......
......@@ -131,6 +131,7 @@ public:
virtual QVector<int> supportedSampleCounts() const = 0;
virtual int ubufAlignment() const = 0;
virtual bool isYUpInFramebuffer() const = 0;
virtual bool isYUpInNDC() const = 0;
virtual QMatrix4x4 clipSpaceCorrMatrix() const = 0;
virtual bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const = 0;
virtual bool isFeatureSupported(QRhi::Feature feature) const = 0;
......
......@@ -344,6 +344,11 @@ bool QRhiD3D11::isYUpInFramebuffer() const
return false;
}
bool QRhiD3D11::isYUpInNDC() const
{
return true;
}
QMatrix4x4 QRhiD3D11::clipSpaceCorrMatrix() const
{
// Like with Vulkan, but Y is already good.
......
......@@ -520,6 +520,7 @@ public:
QVector<int> supportedSampleCounts() const override;
int ubufAlignment() const override;
bool isYUpInFramebuffer() const override;
bool isYUpInNDC() const override;
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
......
......@@ -414,6 +414,11 @@ bool QRhiGles2::isYUpInFramebuffer() const
return true;
}
bool QRhiGles2::isYUpInNDC() const
{
return true;
}
QMatrix4x4 QRhiGles2::clipSpaceCorrMatrix() const
{
return QMatrix4x4(); // identity
......
......@@ -514,6 +514,7 @@ public:
QVector<int> supportedSampleCounts() const override;
int ubufAlignment() const override;
bool isYUpInFramebuffer() const override;
bool isYUpInNDC() const override;
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
......
......@@ -455,6 +455,11 @@ bool QRhiMetal::isYUpInFramebuffer() const
return false;
}
bool QRhiMetal::isYUpInNDC() const
{
return true;
}
QMatrix4x4 QRhiMetal::clipSpaceCorrMatrix() const
{
// depth range 0..1
......
......@@ -346,6 +346,7 @@ public:
QVector<int> supportedSampleCounts() const override;
int ubufAlignment() const override;
bool isYUpInFramebuffer() const override;
bool isYUpInNDC() const override;
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
......
......@@ -110,6 +110,11 @@ bool QRhiNull::isYUpInFramebuffer() const
return true;
}
bool QRhiNull::isYUpInNDC() const
{
return true;
}
QMatrix4x4 QRhiNull::clipSpaceCorrMatrix() const
{
return QMatrix4x4(); // identity
......
......@@ -233,6 +233,7 @@ public:
QVector<int> supportedSampleCounts() const override;
int ubufAlignment() const override;
bool isYUpInFramebuffer() const override;
bool isYUpInNDC() const override;
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
......
......@@ -2963,9 +2963,14 @@ bool QRhiVulkan::isYUpInFramebuffer() const
return false;
}
bool QRhiVulkan::isYUpInNDC() const
{
return false;
}
QMatrix4x4 QRhiVulkan::clipSpaceCorrMatrix() const
{
// See e.g. https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/
// See https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/
static QMatrix4x4 m;
if (m.isIdentity()) {
......
......@@ -418,6 +418,7 @@ public:
QVector<int> supportedSampleCounts() const override;
int ubufAlignment() const override;
bool isYUpInFramebuffer() const override;
bool isYUpInNDC() const override;
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
......
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