rhi: gl: remove useless npot checks

Adjusting the size is not very useful on its own. Leave it to Qt Quick
or whoever provides the data to scale the source image data as they see
fit.

This is also more in line with other backends.

While we are at it, update the feature flag documentation. It applies
both to the repeat wrap mode and filtering modes other than nearest
and linear (i.e. mipmapping).

Change-Id: Ie28f1436b862335efeac042dc21e09189f46e626
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
This commit is contained in:
Laszlo Agocs 2019-08-07 12:52:08 +02:00
parent 98aeee5b5b
commit 0a36001a13
3 changed files with 12 additions and 49 deletions

View File

@ -505,8 +505,11 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
to issue a \l{QRhiCommandBuffer::drawIndexed()}{drawIndexed()} with a
non-aligned effective offset may lead to unspecified behavior.
\value NPOTTextureRepeat Indicates that the \l{QRhiSampler::Repeat}{Repeat}
mode is supported for textures with a non-power-of-two size.
\value NPOTTextureRepeat Indicates that the
\l{QRhiSampler::Repeat}{Repeat} wrap mode and mipmap filtering modes are
supported for textures with a non-power-of-two size. In practice this can
only be false with OpenGL ES 2.0 implementations without
\c{GL_OES_texture_npot}.
\value RedOrAlpha8IsRed Indicates that the
\l{QRhiTexture::RED_OR_ALPHA8}{RED_OR_ALPHA8} format maps to a one

View File

@ -424,8 +424,8 @@ bool QRhiGles2::create(QRhi::Flags flags)
caps.msaaRenderBuffer = f->hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)
&& f->hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit);
caps.npotTexture = f->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures);
caps.npotTextureRepeat = f->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat);
caps.npotTextureFull = f->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)
&& f->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat);
caps.gles = actualFormat.renderableType() == QSurfaceFormat::OpenGLES;
if (caps.gles)
@ -552,43 +552,6 @@ int QRhiGles2::effectiveSampleCount(int sampleCount) const
return s;
}
static inline bool isPowerOfTwo(int x)
{
// Assumption: x >= 1
return x == (x & -x);
}
QSize QRhiGles2::safeTextureSize(const QSize &pixelSize) const
{
QSize size = pixelSize.isEmpty() ? QSize(1, 1) : pixelSize;
if (!caps.npotTexture) {
if (!isPowerOfTwo(size.width())) {
qWarning("Texture width %d is not a power of two, adjusting",
size.width());
size.setWidth(qNextPowerOfTwo(size.width()));
}
if (!isPowerOfTwo(size.height())) {
qWarning("Texture height %d is not a power of two, adjusting",
size.height());
size.setHeight(qNextPowerOfTwo(size.height()));
}
}
if (size.width() > caps.maxTextureSize) {
qWarning("Texture width %d exceeds maximum width %d, adjusting",
size.width(), caps.maxTextureSize);
size.setWidth(caps.maxTextureSize);
}
if (size.height() > caps.maxTextureSize) {
qWarning("Texture height %d exceeds maximum height %d, adjusting",
size.height(), caps.maxTextureSize);
size.setHeight(caps.maxTextureSize);
}
return size;
}
QRhiSwapChain *QRhiGles2::createSwapChain()
{
return new QGles2SwapChain(this);
@ -730,7 +693,7 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
case QRhi::NonFourAlignedEffectiveIndexBufferOffset:
return true;
case QRhi::NPOTTextureRepeat:
return caps.npotTextureRepeat;
return caps.npotTextureFull;
case QRhi::RedOrAlpha8IsRed:
return caps.coreProfile;
case QRhi::ElementIndexUint:
@ -2942,7 +2905,7 @@ bool QGles2RenderBuffer::build()
rhiD->f->glGenRenderbuffers(1, &renderbuffer);
rhiD->f->glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
const QSize size = rhiD->safeTextureSize(m_pixelSize);
const QSize size = m_pixelSize.isEmpty() ? QSize(1, 1) : m_pixelSize;
switch (m_type) {
case QRhiRenderBuffer::DepthStencil:
@ -3039,7 +3002,7 @@ bool QGles2Texture::prepareBuild(QSize *adjustedSize)
if (!rhiD->ensureContext())
return false;
const QSize size = rhiD->safeTextureSize(m_pixelSize);
const QSize size = m_pixelSize.isEmpty() ? QSize(1, 1) : m_pixelSize;
const bool isCube = m_flags.testFlag(CubeMap);
const bool hasMipMaps = m_flags.testFlag(MipMapped);

View File

@ -693,7 +693,6 @@ public:
QGles2RenderTargetData *enqueueBindFramebuffer(QRhiRenderTarget *rt, QGles2CommandBuffer *cbD,
bool *wantsColorClear = nullptr, bool *wantsDsClear = nullptr);
int effectiveSampleCount(int sampleCount) const;
QSize safeTextureSize(const QSize &size) const;
bool compileShader(GLuint program, const QRhiShaderStage &shaderStage,
QShaderDescription *desc, int *glslVersionUsed);
bool linkProgram(GLuint program);
@ -717,8 +716,7 @@ public:
maxTextureSize(2048),
maxDrawBuffers(4),
msaaRenderBuffer(false),
npotTexture(true),
npotTextureRepeat(true),
npotTextureFull(true),
gles(false),
fixedIndexPrimitiveRestart(false),
bgraExternalFormat(false),
@ -747,8 +745,7 @@ public:
// Multisample fb and blit are supported (GLES 3.0 or OpenGL 3.x). Not
// the same as multisample textures!
uint msaaRenderBuffer : 1;
uint npotTexture : 1;
uint npotTextureRepeat : 1;
uint npotTextureFull : 1;
uint gles : 1;
uint fixedIndexPrimitiveRestart : 1;
uint bgraExternalFormat : 1;