Skip to content

Commit

Permalink
rhi: gl: Switch GetBufferSubData emulation to MapBufferRange
Browse files Browse the repository at this point in the history
Use only APIs that are in GLES 3.0.

glMapBuffer() is an old OES extension, stop bothering with that.
Not the least because ANGLE claims supporting it and then fails the
map. (not that we care much about ANGLE, but, for instance, the qrhi
autotest is run with ANGLE configurations as well in the CI, so have
to still take care of it for the duration of Qt 5.x)

Change-Id: I29140402cedffe0430f920ee0c061673257c3aa1
Reviewed-by: Paul Olav Tvete <[email protected]>
  • Loading branch information
alpqr committed Oct 9, 2019
1 parent 9c46694 commit 3292411
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/gui/rhi/qrhi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,10 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
supports QRhiGraphicsPipeline::TriangleFan.
\value ReadBackNonUniformBuffer Indicates that
{QRhiResourceUpdateBatch::readBackBuffer()}{reading buffer contents} is
\l{QRhiResourceUpdateBatch::readBackBuffer()}{reading buffer contents} is
supported for QRhiBuffer instances with a usage different than
UniformBuffer. While this is supported in the majority of cases, it can be
unsupported, for example, on OpenGL ES 2.0 implementations without the
MapBuffer extension.
UniformBuffer. While this is supported in the majority of cases, it will be
unsupported with OpenGL ES older than 3.0.
*/

/*!
Expand Down
21 changes: 14 additions & 7 deletions src/gui/rhi/qrhigles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ QT_BEGIN_NAMESPACE
#define GL_POINT_SPRITE 0x8861
#endif

#ifndef GL_MAP_READ_BIT
#define GL_MAP_READ_BIT 0x0001
#endif

Q_DECLARE_LOGGING_CATEGORY(lcOpenGLProgramDiskCache)

/*!
Expand Down Expand Up @@ -492,7 +496,9 @@ bool QRhiGles2::create(QRhi::Flags flags)
else
caps.textureCompareMode = true;

caps.mapBuffer = f->hasOpenGLExtension(QOpenGLExtensions::MapBuffer);
// proper as in ES 3.0 (glMapBufferRange), not the old glMapBuffer
// extension(s) (which is not in ES 3.0...messy)
caps.properMapBuffer = f->hasOpenGLExtension(QOpenGLExtensions::MapBufferRange);

if (!caps.gles) {
f->glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
Expand Down Expand Up @@ -737,7 +743,7 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
case QRhi::TriangleFanTopology:
return true;
case QRhi::ReadBackNonUniformBuffer:
return !caps.gles || caps.mapBuffer;
return !caps.gles || caps.properMapBuffer;
default:
Q_UNREACHABLE();
return false;
Expand Down Expand Up @@ -2107,13 +2113,14 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
QRhiBufferReadbackResult *result = cmd.args.getBufferSubData.result;
f->glBindBuffer(cmd.args.getBufferSubData.target, cmd.args.getBufferSubData.buffer);
if (caps.gles) {
if (caps.mapBuffer) {
void *p = f->glMapBuffer(cmd.args.getBufferSubData.target, GL_READ_ONLY);
if (caps.properMapBuffer) {
void *p = f->glMapBufferRange(cmd.args.getBufferSubData.target,
cmd.args.getBufferSubData.offset,
cmd.args.getBufferSubData.size,
GL_MAP_READ_BIT);
if (p) {
result->data.resize(cmd.args.getBufferSubData.size);
memcpy(result->data.data(),
reinterpret_cast<char *>(p) + cmd.args.getBufferSubData.offset,
size_t(cmd.args.getBufferSubData.size));
memcpy(result->data.data(), p, size_t(cmd.args.getBufferSubData.size));
f->glUnmapBuffer(cmd.args.getBufferSubData.target);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/rhi/qrhigles2_p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ class QRhiGles2 : public QRhiImplementation
baseVertex(false),
compute(false),
textureCompareMode(false),
mapBuffer(false)
properMapBuffer(false)
{ }
int ctxMajor;
int ctxMinor;
Expand Down Expand Up @@ -784,7 +784,7 @@ class QRhiGles2 : public QRhiImplementation
uint baseVertex : 1;
uint compute : 1;
uint textureCompareMode : 1;
uint mapBuffer : 1;
uint properMapBuffer : 1;
} caps;
QGles2SwapChain *currentSwapChain = nullptr;
QVector<GLint> supportedCompressedFormats;
Expand Down

0 comments on commit 3292411

Please sign in to comment.