diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 0da3e05f13..a24bdde04f 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -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 diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 92aaf9d4b0..0d7f8224af 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -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); diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h index 259d16ca5e..462ce8032c 100644 --- a/src/gui/rhi/qrhigles2_p_p.h +++ b/src/gui/rhi/qrhigles2_p_p.h @@ -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;