diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-08-01 14:50:54 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-08-02 13:57:44 +0200 |
commit | 092074f9df073c9af075810602d61ac54a115d89 (patch) | |
tree | 594d520bf938a74ed03182c12cd683fce04e17f6 | |
parent | 804ddcfb17e532deb164459c25e20fbe0b286598 (diff) |
rhi: Add a note about size to newBuffer()
Also make sure the gl backend is consistent with the other three.
Change-Id: I2f6b783f5fa474c94ede460f5d7ac6fe8129a4f6
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 5 | ||||
-rw-r--r-- | src/gui/rhi/qrhigles2.cpp | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 7770cac870..7443c0a04f 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -4947,6 +4947,11 @@ QRhiShaderResourceBindings *QRhi::newShaderResourceBindings() backends. See \l{QRhiBuffer::UsageFlag}{UsageFlags} and \l{QRhi::NonDynamicUniformBuffers}{the feature flags}. + \note Backends may choose to allocate buffers bigger than \a size. This is + done transparently to applications, so there are no special restrictions on + the value of \a size. QRhiBuffer::size() will always report back the value + that was requested in \a size. + \sa QRhiResource::release() */ QRhiBuffer *QRhi::newBuffer(QRhiBuffer::Type type, diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index a4ab1cf2ec..379801efbd 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -2847,13 +2847,15 @@ bool QGles2Buffer::build() QRHI_RES_RHI(QRhiGles2); QRHI_PROF; + const int nonZeroSize = m_size <= 0 ? 256 : m_size; + if (m_usage.testFlag(QRhiBuffer::UniformBuffer)) { if (int(m_usage) != QRhiBuffer::UniformBuffer) { qWarning("Uniform buffer: multiple usages specified, this is not supported by the OpenGL backend"); return false; } - ubuf.resize(m_size); - QRHI_PROF_F(newBuffer(this, m_size, 0, 1)); + ubuf.resize(nonZeroSize); + QRHI_PROF_F(newBuffer(this, nonZeroSize, 0, 1)); return true; } @@ -2868,11 +2870,11 @@ bool QGles2Buffer::build() rhiD->f->glGenBuffers(1, &buffer); rhiD->f->glBindBuffer(targetForDataOps, buffer); - rhiD->f->glBufferData(targetForDataOps, m_size, nullptr, m_type == Dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); + rhiD->f->glBufferData(targetForDataOps, nonZeroSize, nullptr, m_type == Dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); usageState.access = AccessNone; - QRHI_PROF_F(newBuffer(this, m_size, 1, 0)); + QRHI_PROF_F(newBuffer(this, nonZeroSize, 1, 0)); rhiD->registerResource(this); return true; } |