2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-01-02 11:13:29 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-19 12:28:29 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the QtOpenGL module of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** GNU General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtOpenGL/qgl.h>
|
|
|
|
#include <QtOpenGL/private/qgl_p.h>
|
2013-02-06 21:36:27 +00:00
|
|
|
#include <private/qopenglextensions_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/qatomic.h>
|
|
|
|
#include "qglbuffer.h"
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\class QGLBuffer
|
2012-11-27 14:09:17 +00:00
|
|
|
\inmodule QtOpenGL
|
2011-04-27 10:05:43 +00:00
|
|
|
\brief The QGLBuffer class provides functions for creating and managing GL buffer objects.
|
|
|
|
\since 4.7
|
2012-09-14 08:47:57 +00:00
|
|
|
\obsolete
|
2011-04-27 10:05:43 +00:00
|
|
|
\ingroup painting-3D
|
|
|
|
|
|
|
|
Buffer objects are created in the GL server so that the
|
|
|
|
client application can avoid uploading vertices, indices,
|
|
|
|
texture image data, etc every time they are needed.
|
|
|
|
|
|
|
|
QGLBuffer objects can be copied around as a reference to the
|
|
|
|
underlying GL buffer object:
|
|
|
|
|
|
|
|
\code
|
|
|
|
QGLBuffer buffer1(QGLBuffer::IndexBuffer);
|
|
|
|
buffer1.create();
|
|
|
|
|
|
|
|
QGLBuffer buffer2 = buffer1;
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
QGLBuffer performs a shallow copy when objects are copied in this
|
|
|
|
manner, but does not implement copy-on-write semantics. The original
|
|
|
|
object will be affected whenever the copy is modified.
|
2012-09-14 08:47:57 +00:00
|
|
|
|
|
|
|
\note This class has been deprecated in favor of QOpenGLBuffer.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\enum QGLBuffer::Type
|
|
|
|
This enum defines the type of GL buffer object to create with QGLBuffer.
|
|
|
|
|
|
|
|
\value VertexBuffer Vertex buffer object for use when specifying
|
|
|
|
vertex arrays.
|
|
|
|
\value IndexBuffer Index buffer object for use with \c{glDrawElements()}.
|
|
|
|
\value PixelPackBuffer Pixel pack buffer object for reading pixel
|
|
|
|
data from the GL server (for example, with \c{glReadPixels()}).
|
|
|
|
Not supported under OpenGL/ES.
|
|
|
|
\value PixelUnpackBuffer Pixel unpack buffer object for writing pixel
|
|
|
|
data to the GL server (for example, with \c{glTexImage2D()}).
|
|
|
|
Not supported under OpenGL/ES.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\enum QGLBuffer::UsagePattern
|
|
|
|
This enum defines the usage pattern of a QGLBuffer object.
|
|
|
|
|
|
|
|
\value StreamDraw The data will be set once and used a few times
|
|
|
|
for drawing operations. Under OpenGL/ES 1.1 this is identical
|
|
|
|
to StaticDraw.
|
|
|
|
\value StreamRead The data will be set once and used a few times
|
|
|
|
for reading data back from the GL server. Not supported
|
|
|
|
under OpenGL/ES.
|
|
|
|
\value StreamCopy The data will be set once and used a few times
|
|
|
|
for reading data back from the GL server for use in further
|
|
|
|
drawing operations. Not supported under OpenGL/ES.
|
|
|
|
\value StaticDraw The data will be set once and used many times
|
|
|
|
for drawing operations.
|
|
|
|
\value StaticRead The data will be set once and used many times
|
|
|
|
for reading data back from the GL server. Not supported
|
|
|
|
under OpenGL/ES.
|
|
|
|
\value StaticCopy The data will be set once and used many times
|
|
|
|
for reading data back from the GL server for use in further
|
|
|
|
drawing operations. Not supported under OpenGL/ES.
|
|
|
|
\value DynamicDraw The data will be modified repeatedly and used
|
|
|
|
many times for drawing operations.
|
|
|
|
\value DynamicRead The data will be modified repeatedly and used
|
|
|
|
many times for reading data back from the GL server.
|
|
|
|
Not supported under OpenGL/ES.
|
|
|
|
\value DynamicCopy The data will be modified repeatedly and used
|
|
|
|
many times for reading data back from the GL server for
|
|
|
|
use in further drawing operations. Not supported under OpenGL/ES.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\enum QGLBuffer::Access
|
|
|
|
This enum defines the access mode for QGLBuffer::map().
|
|
|
|
|
|
|
|
\value ReadOnly The buffer will be mapped for reading only.
|
|
|
|
\value WriteOnly The buffer will be mapped for writing only.
|
|
|
|
\value ReadWrite The buffer will be mapped for reading and writing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class QGLBufferPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QGLBufferPrivate(QGLBuffer::Type t)
|
|
|
|
: ref(1),
|
|
|
|
type(t),
|
|
|
|
guard(0),
|
|
|
|
usagePattern(QGLBuffer::StaticDraw),
|
2013-02-06 21:36:27 +00:00
|
|
|
actualUsagePattern(QGLBuffer::StaticDraw),
|
|
|
|
funcs(0)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QAtomicInt ref;
|
|
|
|
QGLBuffer::Type type;
|
2011-08-16 07:29:44 +00:00
|
|
|
QGLSharedResourceGuardBase *guard;
|
2011-04-27 10:05:43 +00:00
|
|
|
QGLBuffer::UsagePattern usagePattern;
|
|
|
|
QGLBuffer::UsagePattern actualUsagePattern;
|
2013-02-06 21:36:27 +00:00
|
|
|
QOpenGLExtensions *funcs;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Constructs a new buffer object of type QGLBuffer::VertexBuffer.
|
|
|
|
|
|
|
|
Note: this constructor just creates the QGLBuffer instance. The actual
|
|
|
|
buffer object in the GL server is not created until create() is called.
|
|
|
|
|
|
|
|
\sa create()
|
|
|
|
*/
|
|
|
|
QGLBuffer::QGLBuffer()
|
|
|
|
: d_ptr(new QGLBufferPrivate(QGLBuffer::VertexBuffer))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Constructs a new buffer object of \a type.
|
|
|
|
|
|
|
|
Note: this constructor just creates the QGLBuffer instance. The actual
|
|
|
|
buffer object in the GL server is not created until create() is called.
|
|
|
|
|
|
|
|
\sa create()
|
|
|
|
*/
|
|
|
|
QGLBuffer::QGLBuffer(QGLBuffer::Type type)
|
|
|
|
: d_ptr(new QGLBufferPrivate(type))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Constructs a shallow copy of \a other.
|
|
|
|
|
|
|
|
Note: QGLBuffer does not implement copy-on-write semantics,
|
|
|
|
so \a other will be affected whenever the copy is modified.
|
|
|
|
*/
|
|
|
|
QGLBuffer::QGLBuffer(const QGLBuffer &other)
|
|
|
|
: d_ptr(other.d_ptr)
|
|
|
|
{
|
|
|
|
d_ptr->ref.ref();
|
|
|
|
}
|
|
|
|
|
2011-08-16 07:29:44 +00:00
|
|
|
#define ctx QGLContext::currentContext();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Destroys this buffer object, including the storage being
|
|
|
|
used in the GL server.
|
|
|
|
*/
|
|
|
|
QGLBuffer::~QGLBuffer()
|
|
|
|
{
|
|
|
|
if (!d_ptr->ref.deref()) {
|
|
|
|
destroy();
|
|
|
|
delete d_ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Assigns a shallow copy of \a other to this object.
|
|
|
|
|
|
|
|
Note: QGLBuffer does not implement copy-on-write semantics,
|
|
|
|
so \a other will be affected whenever the copy is modified.
|
|
|
|
*/
|
|
|
|
QGLBuffer &QGLBuffer::operator=(const QGLBuffer &other)
|
|
|
|
{
|
|
|
|
if (d_ptr != other.d_ptr) {
|
|
|
|
other.d_ptr->ref.ref();
|
2012-11-17 03:39:14 +00:00
|
|
|
if (!d_ptr->ref.deref()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
destroy();
|
2012-11-17 03:39:14 +00:00
|
|
|
delete d_ptr;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
d_ptr = other.d_ptr;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the type of buffer represented by this object.
|
|
|
|
*/
|
|
|
|
QGLBuffer::Type QGLBuffer::type() const
|
|
|
|
{
|
|
|
|
Q_D(const QGLBuffer);
|
|
|
|
return d->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the usage pattern for this buffer object.
|
|
|
|
The default value is StaticDraw.
|
|
|
|
|
|
|
|
\sa setUsagePattern()
|
|
|
|
*/
|
|
|
|
QGLBuffer::UsagePattern QGLBuffer::usagePattern() const
|
|
|
|
{
|
|
|
|
Q_D(const QGLBuffer);
|
|
|
|
return d->usagePattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Sets the usage pattern for this buffer object to \a value.
|
|
|
|
This function must be called before allocate() or write().
|
|
|
|
|
|
|
|
\sa usagePattern(), allocate(), write()
|
|
|
|
*/
|
|
|
|
void QGLBuffer::setUsagePattern(QGLBuffer::UsagePattern value)
|
|
|
|
{
|
|
|
|
Q_D(QGLBuffer);
|
|
|
|
d->usagePattern = d->actualUsagePattern = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ctx
|
|
|
|
|
2011-08-16 07:29:44 +00:00
|
|
|
namespace {
|
|
|
|
void freeBufferFunc(QGLContext *ctx, GLuint id)
|
|
|
|
{
|
2013-02-06 21:36:27 +00:00
|
|
|
Q_ASSERT(ctx);
|
|
|
|
ctx->contextHandle()->functions()->glDeleteBuffers(1, &id);
|
2011-08-16 07:29:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
2013-10-02 14:51:05 +00:00
|
|
|
Creates the buffer object in the GL server. Returns \c true if
|
2011-04-27 10:05:43 +00:00
|
|
|
the object was created; false otherwise.
|
|
|
|
|
|
|
|
This function must be called with a current QGLContext.
|
|
|
|
The buffer will be bound to and can only be used in
|
|
|
|
that context (or any other context that is shared with it).
|
|
|
|
|
|
|
|
This function will return false if the GL implementation
|
|
|
|
does not support buffers, or there is no current QGLContext.
|
|
|
|
|
|
|
|
\sa isCreated(), allocate(), write(), destroy()
|
|
|
|
*/
|
|
|
|
bool QGLBuffer::create()
|
|
|
|
{
|
|
|
|
Q_D(QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
if (d->guard && d->guard->id())
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
2011-08-16 07:29:44 +00:00
|
|
|
QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext());
|
2011-04-27 10:05:43 +00:00
|
|
|
if (ctx) {
|
2013-02-06 21:36:27 +00:00
|
|
|
delete d->funcs;
|
|
|
|
d->funcs = new QOpenGLExtensions(ctx->contextHandle());
|
|
|
|
if (!d->funcs->hasOpenGLFeature(QOpenGLFunctions::Buffers))
|
2011-04-27 10:05:43 +00:00
|
|
|
return false;
|
2013-02-06 21:36:27 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
GLuint bufferId = 0;
|
2013-02-06 21:36:27 +00:00
|
|
|
d->funcs->glGenBuffers(1, &bufferId);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (bufferId) {
|
2011-08-16 07:29:44 +00:00
|
|
|
if (d->guard)
|
|
|
|
d->guard->free();
|
|
|
|
|
|
|
|
d->guard = createSharedResourceGuard(ctx, bufferId, freeBufferFunc);
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-16 07:29:44 +00:00
|
|
|
#define ctx QGLContext::currentContext()
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
/*!
|
2013-10-02 14:51:05 +00:00
|
|
|
Returns \c true if this buffer has been created; false otherwise.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa create(), destroy()
|
|
|
|
*/
|
|
|
|
bool QGLBuffer::isCreated() const
|
|
|
|
{
|
|
|
|
Q_D(const QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
return d->guard && d->guard->id();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Destroys this buffer object, including the storage being
|
|
|
|
used in the GL server. All references to the buffer will
|
|
|
|
become invalid.
|
|
|
|
*/
|
|
|
|
void QGLBuffer::destroy()
|
|
|
|
{
|
|
|
|
Q_D(QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
if (d->guard) {
|
|
|
|
d->guard->free();
|
|
|
|
d->guard = 0;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Reads the \a count bytes in this buffer starting at \a offset
|
2013-10-02 14:51:05 +00:00
|
|
|
into \a data. Returns \c true on success; false if reading from
|
2011-04-27 10:05:43 +00:00
|
|
|
the buffer is not supported. Buffer reading is not supported
|
|
|
|
under OpenGL/ES.
|
|
|
|
|
|
|
|
It is assumed that this buffer has been bound to the current context.
|
|
|
|
|
|
|
|
\sa write(), bind()
|
|
|
|
*/
|
|
|
|
bool QGLBuffer::read(int offset, void *data, int count)
|
|
|
|
{
|
|
|
|
#if !defined(QT_OPENGL_ES)
|
2014-02-28 16:03:57 +00:00
|
|
|
if (QOpenGLContext::openGLModuleType() != QOpenGLContext::GLES1) {
|
Dynamic GL switch on Windows
The patch introduces a new build configuration on Windows which
can be requested by passing -opengl dynamic to configure.
Platforms other than Windows (including WinRT) are not affected.
The existing Angle and desktop configurations are not affected.
These continue to function as before and Angle remains the default.
In the future, when all modules have added support for the dynamic
path, as described below, the default configuration could be changed
to be the dynamic one. This would allow providing a single set of
binaries in the official builds instead of the current two.
When requesting dynamic GL, Angle is built but QT_OPENGL_ES[_2] are
never defined. Instead, the code path that has traditionally been
desktop GL only becomes the dynamic path that has to do runtime
checks. Qt modules and applications are not linked to opengl32.dll or
libegl/glesv2.dll in this case. Instead, QtGui exports all necessary
egl/egl/gl functions which will, under the hood, forward all requests
to a dynamically loaded EGL/WGL/GL implementation.
Porting guide (better said, changes needed to prepare your code to
work with dynamic GL builds when the fallback to Angle is utilized):
1. In !QT_OPENGL_ES[_2] code branches use QOpenGLFunctions::isES() to
differentiate between desktop and ES where needed. Keep in mind that
it is the desktop GL header (plus qopenglext.h) that is included,
not the GLES one.
QtGui's proxy will handle some differences, for example calling
glClearDepth will route to glClearDepthf when needed. The built-in
eglGetProcAddress is able to retrieve pointers for standard GLES2
functions too so code resolving OpenGL 2 functions will function
in any case.
2. QT_CONFIG will contain "opengl" and "dynamicgl" in dynamic builds,
but never "angle" or "opengles2".
3. The preprocessor define QT_OPENGL_DYNAMIC is also available in
dynamic builds. The usage of this is strongly discouraged and should
not be needed anywhere except for QtGui and the platform plugin.
4. Code in need of the library handle can use
QOpenGLFunctions::platformGLHandle().
The decision on which library to load is currently based on a simple
test that creates a dummy window/context and tries to resolve an
OpenGL 2 function. If this fails, it goes for Angle. This seems to work
well on Win7 PCs for example that do not have proper graphics drivers
providing OpenGL installed but are D3D9 capable using the default drivers.
Setting QT_OPENGL to desktop or angle skips the test and forces
usage of the given GL. There are also two new application attributes
that could be used for the same purpose.
If Angle is requested but the libraries are not present, desktop is
tried. If desktop is requested, or if angle is requested but nothing
works, the EGL/WGL functions will still be callable but will return 0.
This conveniently means that eglInitialize() and such will report a failure.
Debug messages can be enabled by setting QT_OPENGLPROXY_DEBUG. This will
tell which implementation is chosen.
The textures example application is ported to OpenGL 2, the GL 1
code path is removed.
[ChangeLog][QtGui] Qt builds on Windows can now be configured for
dynamic loading of the OpenGL implementation. This can be requested
by passing -opengl dynamic to configure. In this mode no modules will
link to opengl32.dll or Angle's libegl/libglesv2. Instead, QtGui will
dynamically choose between desktop and Angle during the first GL/EGL/WGL
call. This allows deploying applications with a single set of Qt libraries
with the ability of transparently falling back to Angle in case the
opengl32.dll is not suitable, due to missing graphics drivers for example.
Task-number: QTBUG-36483
Change-Id: I716fdebbf60b355b7d9ef57d1e069eef366b4ab9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
2014-01-27 13:45:11 +00:00
|
|
|
Q_D(QGLBuffer);
|
|
|
|
if (!d->funcs->hasOpenGLFeature(QOpenGLFunctions::Buffers) || !d->guard->id())
|
|
|
|
return false;
|
|
|
|
while (glGetError() != GL_NO_ERROR) ; // Clear error state.
|
|
|
|
d->funcs->glGetBufferSubData(d->type, offset, count, data);
|
|
|
|
return glGetError() == GL_NO_ERROR;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
|
|
|
Q_UNUSED(offset);
|
|
|
|
Q_UNUSED(data);
|
|
|
|
Q_UNUSED(count);
|
|
|
|
#endif
|
Dynamic GL switch on Windows
The patch introduces a new build configuration on Windows which
can be requested by passing -opengl dynamic to configure.
Platforms other than Windows (including WinRT) are not affected.
The existing Angle and desktop configurations are not affected.
These continue to function as before and Angle remains the default.
In the future, when all modules have added support for the dynamic
path, as described below, the default configuration could be changed
to be the dynamic one. This would allow providing a single set of
binaries in the official builds instead of the current two.
When requesting dynamic GL, Angle is built but QT_OPENGL_ES[_2] are
never defined. Instead, the code path that has traditionally been
desktop GL only becomes the dynamic path that has to do runtime
checks. Qt modules and applications are not linked to opengl32.dll or
libegl/glesv2.dll in this case. Instead, QtGui exports all necessary
egl/egl/gl functions which will, under the hood, forward all requests
to a dynamically loaded EGL/WGL/GL implementation.
Porting guide (better said, changes needed to prepare your code to
work with dynamic GL builds when the fallback to Angle is utilized):
1. In !QT_OPENGL_ES[_2] code branches use QOpenGLFunctions::isES() to
differentiate between desktop and ES where needed. Keep in mind that
it is the desktop GL header (plus qopenglext.h) that is included,
not the GLES one.
QtGui's proxy will handle some differences, for example calling
glClearDepth will route to glClearDepthf when needed. The built-in
eglGetProcAddress is able to retrieve pointers for standard GLES2
functions too so code resolving OpenGL 2 functions will function
in any case.
2. QT_CONFIG will contain "opengl" and "dynamicgl" in dynamic builds,
but never "angle" or "opengles2".
3. The preprocessor define QT_OPENGL_DYNAMIC is also available in
dynamic builds. The usage of this is strongly discouraged and should
not be needed anywhere except for QtGui and the platform plugin.
4. Code in need of the library handle can use
QOpenGLFunctions::platformGLHandle().
The decision on which library to load is currently based on a simple
test that creates a dummy window/context and tries to resolve an
OpenGL 2 function. If this fails, it goes for Angle. This seems to work
well on Win7 PCs for example that do not have proper graphics drivers
providing OpenGL installed but are D3D9 capable using the default drivers.
Setting QT_OPENGL to desktop or angle skips the test and forces
usage of the given GL. There are also two new application attributes
that could be used for the same purpose.
If Angle is requested but the libraries are not present, desktop is
tried. If desktop is requested, or if angle is requested but nothing
works, the EGL/WGL functions will still be callable but will return 0.
This conveniently means that eglInitialize() and such will report a failure.
Debug messages can be enabled by setting QT_OPENGLPROXY_DEBUG. This will
tell which implementation is chosen.
The textures example application is ported to OpenGL 2, the GL 1
code path is removed.
[ChangeLog][QtGui] Qt builds on Windows can now be configured for
dynamic loading of the OpenGL implementation. This can be requested
by passing -opengl dynamic to configure. In this mode no modules will
link to opengl32.dll or Angle's libegl/libglesv2. Instead, QtGui will
dynamically choose between desktop and Angle during the first GL/EGL/WGL
call. This allows deploying applications with a single set of Qt libraries
with the ability of transparently falling back to Angle in case the
opengl32.dll is not suitable, due to missing graphics drivers for example.
Task-number: QTBUG-36483
Change-Id: I716fdebbf60b355b7d9ef57d1e069eef366b4ab9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
2014-01-27 13:45:11 +00:00
|
|
|
return false;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Replaces the \a count bytes of this buffer starting at \a offset
|
|
|
|
with the contents of \a data. Any other bytes in the buffer
|
|
|
|
will be left unmodified.
|
|
|
|
|
|
|
|
It is assumed that create() has been called on this buffer and that
|
|
|
|
it has been bound to the current context.
|
|
|
|
|
|
|
|
\sa create(), read(), allocate()
|
|
|
|
*/
|
|
|
|
void QGLBuffer::write(int offset, const void *data, int count)
|
|
|
|
{
|
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
if (!isCreated())
|
|
|
|
qWarning("QGLBuffer::allocate(): buffer not created");
|
|
|
|
#endif
|
|
|
|
Q_D(QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
if (d->guard && d->guard->id())
|
2013-02-06 21:36:27 +00:00
|
|
|
d->funcs->glBufferSubData(d->type, offset, count, data);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Allocates \a count bytes of space to the buffer, initialized to
|
|
|
|
the contents of \a data. Any previous contents will be removed.
|
|
|
|
|
|
|
|
It is assumed that create() has been called on this buffer and that
|
|
|
|
it has been bound to the current context.
|
|
|
|
|
|
|
|
\sa create(), read(), write()
|
|
|
|
*/
|
|
|
|
void QGLBuffer::allocate(const void *data, int count)
|
|
|
|
{
|
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
if (!isCreated())
|
|
|
|
qWarning("QGLBuffer::allocate(): buffer not created");
|
|
|
|
#endif
|
|
|
|
Q_D(QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
if (d->guard && d->guard->id())
|
2013-02-06 21:36:27 +00:00
|
|
|
d->funcs->glBufferData(d->type, count, data, d->actualUsagePattern);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void QGLBuffer::allocate(int count)
|
|
|
|
\overload
|
|
|
|
|
|
|
|
Allocates \a count bytes of space to the buffer. Any previous
|
|
|
|
contents will be removed.
|
|
|
|
|
|
|
|
It is assumed that create() has been called on this buffer and that
|
|
|
|
it has been bound to the current context.
|
|
|
|
|
|
|
|
\sa create(), write()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Binds the buffer associated with this object to the current
|
2013-10-02 14:51:05 +00:00
|
|
|
GL context. Returns \c false if binding was not possible, usually because
|
2011-04-27 10:05:43 +00:00
|
|
|
type() is not supported on this GL implementation.
|
|
|
|
|
|
|
|
The buffer must be bound to the same QGLContext current when create()
|
|
|
|
was called, or to another QGLContext that is sharing with it.
|
|
|
|
Otherwise, false will be returned from this function.
|
|
|
|
|
|
|
|
\sa release(), create()
|
|
|
|
*/
|
|
|
|
bool QGLBuffer::bind()
|
|
|
|
{
|
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
if (!isCreated())
|
|
|
|
qWarning("QGLBuffer::bind(): buffer not created");
|
|
|
|
#endif
|
|
|
|
Q_D(const QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
GLuint bufferId = d->guard ? d->guard->id() : 0;
|
2011-04-27 10:05:43 +00:00
|
|
|
if (bufferId) {
|
2011-08-22 08:49:28 +00:00
|
|
|
if (d->guard->group() != QOpenGLContextGroup::currentContextGroup()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
qWarning("QGLBuffer::bind: buffer is not valid in the current context");
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-06 21:36:27 +00:00
|
|
|
d->funcs->glBindBuffer(d->type, bufferId);
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Releases the buffer associated with this object from the
|
|
|
|
current GL context.
|
|
|
|
|
|
|
|
This function must be called with the same QGLContext current
|
|
|
|
as when bind() was called on the buffer.
|
|
|
|
|
|
|
|
\sa bind()
|
|
|
|
*/
|
|
|
|
void QGLBuffer::release()
|
|
|
|
{
|
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
if (!isCreated())
|
|
|
|
qWarning("QGLBuffer::release(): buffer not created");
|
|
|
|
#endif
|
|
|
|
Q_D(const QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
if (d->guard && d->guard->id())
|
2013-02-06 21:36:27 +00:00
|
|
|
d->funcs->glBindBuffer(d->type, 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef ctx
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Releases the buffer associated with \a type in the current
|
|
|
|
QGLContext.
|
|
|
|
|
|
|
|
This function is a direct call to \c{glBindBuffer(type, 0)}
|
|
|
|
for use when the caller does not know which QGLBuffer has
|
|
|
|
been bound to the context but wants to make sure that it
|
|
|
|
is released.
|
|
|
|
|
|
|
|
\code
|
|
|
|
QGLBuffer::release(QGLBuffer::VertexBuffer);
|
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
void QGLBuffer::release(QGLBuffer::Type type)
|
|
|
|
{
|
2013-02-06 21:36:27 +00:00
|
|
|
if (QOpenGLContext *ctx = QOpenGLContext::currentContext())
|
|
|
|
ctx->functions()->glBindBuffer(GLenum(type), 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2011-08-16 07:29:44 +00:00
|
|
|
#define ctx QGLContext::currentContext()
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the GL identifier associated with this buffer; zero if
|
|
|
|
the buffer has not been created.
|
|
|
|
|
|
|
|
\sa isCreated()
|
|
|
|
*/
|
|
|
|
GLuint QGLBuffer::bufferId() const
|
|
|
|
{
|
|
|
|
Q_D(const QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
return d->guard ? d->guard->id() : 0;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef GL_BUFFER_SIZE
|
|
|
|
#define GL_BUFFER_SIZE 0x8764
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the size of the data in this buffer, for reading operations.
|
|
|
|
Returns -1 if fetching the buffer size is not supported, or the
|
|
|
|
buffer has not been created.
|
|
|
|
|
|
|
|
It is assumed that this buffer has been bound to the current context.
|
|
|
|
|
|
|
|
\sa isCreated(), bind()
|
|
|
|
*/
|
|
|
|
int QGLBuffer::size() const
|
|
|
|
{
|
|
|
|
Q_D(const QGLBuffer);
|
2011-08-16 07:29:44 +00:00
|
|
|
if (!d->guard || !d->guard->id())
|
2011-04-27 10:05:43 +00:00
|
|
|
return -1;
|
|
|
|
GLint value = -1;
|
2013-02-06 21:36:27 +00:00
|
|
|
d->funcs->glGetBufferParameteriv(d->type, GL_BUFFER_SIZE, &value);
|
2011-04-27 10:05:43 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Maps the contents of this buffer into the application's memory
|
|
|
|
space and returns a pointer to it. Returns null if memory
|
|
|
|
mapping is not possible. The \a access parameter indicates the
|
|
|
|
type of access to be performed.
|
|
|
|
|
|
|
|
It is assumed that create() has been called on this buffer and that
|
|
|
|
it has been bound to the current context.
|
|
|
|
|
|
|
|
This function is only supported under OpenGL/ES if the
|
|
|
|
\c{GL_OES_mapbuffer} extension is present.
|
|
|
|
|
|
|
|
\sa unmap(), create(), bind()
|
|
|
|
*/
|
|
|
|
void *QGLBuffer::map(QGLBuffer::Access access)
|
|
|
|
{
|
|
|
|
Q_D(QGLBuffer);
|
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
if (!isCreated())
|
|
|
|
qWarning("QGLBuffer::map(): buffer not created");
|
|
|
|
#endif
|
2011-08-16 07:29:44 +00:00
|
|
|
if (!d->guard || !d->guard->id())
|
2011-04-27 10:05:43 +00:00
|
|
|
return 0;
|
2013-02-06 21:36:27 +00:00
|
|
|
return d->funcs->glMapBuffer(d->type, access);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Unmaps the buffer after it was mapped into the application's
|
2013-10-02 14:51:05 +00:00
|
|
|
memory space with a previous call to map(). Returns \c true if
|
2011-04-27 10:05:43 +00:00
|
|
|
the unmap succeeded; false otherwise.
|
|
|
|
|
|
|
|
It is assumed that this buffer has been bound to the current context,
|
|
|
|
and that it was previously mapped with map().
|
|
|
|
|
|
|
|
This function is only supported under OpenGL/ES if the
|
|
|
|
\c{GL_OES_mapbuffer} extension is present.
|
|
|
|
|
|
|
|
\sa map()
|
|
|
|
*/
|
|
|
|
bool QGLBuffer::unmap()
|
|
|
|
{
|
|
|
|
Q_D(QGLBuffer);
|
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
if (!isCreated())
|
|
|
|
qWarning("QGLBuffer::unmap(): buffer not created");
|
|
|
|
#endif
|
2011-08-16 07:29:44 +00:00
|
|
|
if (!d->guard || !d->guard->id())
|
2011-04-27 10:05:43 +00:00
|
|
|
return false;
|
2013-02-06 21:36:27 +00:00
|
|
|
return d->funcs->glUnmapBuffer(d->type) == GL_TRUE;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|