Enable QOpenGLTexture for OpenGL ES 2

Change-Id: I3ec2b7af303070c92e86c0f5ca729eb1a1731682
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
Jorgen Lind 2013-11-05 12:25:29 +01:00 committed by The Qt Project
parent f3f25b1469
commit d7d7786026
7 changed files with 179 additions and 25 deletions

View File

@ -56,9 +56,7 @@
#include <private/qopenglextensions_p.h> #include <private/qopenglextensions_p.h>
#include <private/qopenglversionfunctionsfactory_p.h> #include <private/qopenglversionfunctionsfactory_p.h>
#if !defined(QT_OPENGL_ES_2)
#include <private/qopengltexturehelper_p.h> #include <private/qopengltexturehelper_p.h>
#endif
#include <QDebug> #include <QDebug>
@ -527,10 +525,8 @@ void QOpenGLContext::destroy()
d->versionFunctions.clear(); d->versionFunctions.clear();
qDeleteAll(d->versionFunctionsBackend); qDeleteAll(d->versionFunctionsBackend);
d->versionFunctionsBackend.clear(); d->versionFunctionsBackend.clear();
#if !defined(QT_OPENGL_ES_2)
delete d->textureFunctions; delete d->textureFunctions;
d->textureFunctions = 0; d->textureFunctions = 0;
#endif
} }
/*! /*!
@ -984,7 +980,6 @@ void QOpenGLContext::removeFunctionsBackend(const QOpenGLVersionStatus &v)
d->versionFunctionsBackend.remove(v); d->versionFunctionsBackend.remove(v);
} }
#if !defined(QT_OPENGL_ES_2)
/*! /*!
\internal \internal
*/ */
@ -1002,7 +997,6 @@ void QOpenGLContext::setTextureFunctions(QOpenGLTextureHelper* textureFuncs)
Q_D(QOpenGLContext); Q_D(QOpenGLContext);
d->textureFunctions = textureFuncs; d->textureFunctions = textureFuncs;
} }
#endif
/*! /*!
\class QOpenGLContextGroup \class QOpenGLContextGroup

View File

@ -221,10 +221,8 @@ private:
QOpenGLVersionFunctionsBackend *backend); QOpenGLVersionFunctionsBackend *backend);
void removeFunctionsBackend(const QOpenGLVersionStatus &v); void removeFunctionsBackend(const QOpenGLVersionStatus &v);
#if !defined(QT_OPENGL_ES_2)
QOpenGLTextureHelper* textureFunctions() const; QOpenGLTextureHelper* textureFunctions() const;
void setTextureFunctions(QOpenGLTextureHelper* textureFuncs); void setTextureFunctions(QOpenGLTextureHelper* textureFuncs);
#endif
void destroy(); void destroy();
}; };

View File

@ -53,6 +53,17 @@ contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles2) {
opengl/qopenglvertexarrayobject.cpp \ opengl/qopenglvertexarrayobject.cpp \
opengl/qopengldebug.cpp opengl/qopengldebug.cpp
!wince* {
HEADERS += opengl/qopengltexture.h \
opengl/qopengltexture_p.h \
opengl/qopengltexturehelper_p.h \
opengl/qopenglpixeltransferoptions.h
SOURCES += opengl/qopengltexture.cpp \
opengl/qopengltexturehelper.cpp \
opengl/qopenglpixeltransferoptions.cpp
}
!contains(QT_CONFIG, opengles2) { !contains(QT_CONFIG, opengles2) {
HEADERS += opengl/qopenglfunctions_1_0.h \ HEADERS += opengl/qopenglfunctions_1_0.h \
opengl/qopenglfunctions_1_1.h \ opengl/qopenglfunctions_1_1.h \
@ -77,11 +88,7 @@ contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles2) {
opengl/qopenglfunctions_4_2_compatibility.h \ opengl/qopenglfunctions_4_2_compatibility.h \
opengl/qopenglfunctions_4_3_compatibility.h \ opengl/qopenglfunctions_4_3_compatibility.h \
opengl/qopenglqueryhelper_p.h \ opengl/qopenglqueryhelper_p.h \
opengl/qopengltimerquery.h \ opengl/qopengltimerquery.h
opengl/qopengltexture.h \
opengl/qopengltexture_p.h \
opengl/qopengltexturehelper_p.h \
opengl/qopenglpixeltransferoptions.h
SOURCES += opengl/qopenglfunctions_1_0.cpp \ SOURCES += opengl/qopenglfunctions_1_0.cpp \
opengl/qopenglfunctions_1_1.cpp \ opengl/qopenglfunctions_1_1.cpp \
@ -105,10 +112,7 @@ contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles2) {
opengl/qopenglfunctions_4_1_compatibility.cpp \ opengl/qopenglfunctions_4_1_compatibility.cpp \
opengl/qopenglfunctions_4_2_compatibility.cpp \ opengl/qopenglfunctions_4_2_compatibility.cpp \
opengl/qopenglfunctions_4_3_compatibility.cpp \ opengl/qopenglfunctions_4_3_compatibility.cpp \
opengl/qopengltimerquery.cpp \ opengl/qopengltimerquery.cpp
opengl/qopengltexture.cpp \
opengl/qopengltexturehelper.cpp \
opengl/qopenglpixeltransferoptions.cpp
} }
contains(QT_CONFIG, opengles2) { contains(QT_CONFIG, opengles2) {

View File

@ -50,6 +50,11 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
//this is to work around GL_TEXTURE_WRAP_R_OES which also has 0x8072 as value
#if !defined(GL_TEXTURE_WRAP_R)
#define GL_TEXTURE_WRAP_R 0x8072
#endif
QOpenGLTexturePrivate::QOpenGLTexturePrivate(QOpenGLTexture::Target textureTarget, QOpenGLTexturePrivate::QOpenGLTexturePrivate(QOpenGLTexture::Target textureTarget,
QOpenGLTexture *qq) QOpenGLTexture *qq)
: q_ptr(qq), : q_ptr(qq),
@ -1255,6 +1260,13 @@ QOpenGLTexture *QOpenGLTexturePrivate::createTextureView(QOpenGLTexture::Target
\value SRGB_Alpha_DXT3 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT \value SRGB_Alpha_DXT3 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
\value SRGB_Alpha_DXT5 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT \value SRGB_Alpha_DXT5 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
\value SRGB_BP_UNorm Equivalent to GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB \value SRGB_BP_UNorm Equivalent to GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
\value DepthFormat Equivalent to GL_DEPTH_COMPONENT (OpenGL ES 2 only and when OES_depth_texture is present)
\value AlphaFormat Equivalent to GL_ALPHA (OpenGL ES 2 only)
\value RGBFormat Equivalent to GL_RGB (OpenGL ES 2 only)
\value RGBAFormat Equivalent to GL_RGBA (OpenGL ES 2 only)
\value LuminanceFormat Equivalent to GL_LUMINANCE (OpenGL ES 2 only)
\value LuminanceAlphaFormat Equivalent to GL_LUMINANCE_ALPHA (OpenGL ES 2 only)
*/ */
/*! /*!
@ -1289,6 +1301,10 @@ QOpenGLTexture *QOpenGLTexturePrivate::createTextureView(QOpenGLTexture::Target
\value BGRA_Integer Equivalent to GL_BGRA_INTEGER \value BGRA_Integer Equivalent to GL_BGRA_INTEGER
\value Depth Equivalent to GL_DEPTH_COMPONENT \value Depth Equivalent to GL_DEPTH_COMPONENT
\value DepthStencil Equivalent to GL_DEPTH_STENCIL \value DepthStencil Equivalent to GL_DEPTH_STENCIL
\value Alpha Equivalent to GL_ALPHA (OpenGL ES 2 only)
\value Luminance Equivalent to GL_LUMINANCE (OpenGL ES 2 only)
\value LuminanceAlpha Equivalent to GL_LUMINANCE_ALPHA (OpenGL ES 2 only)
*/ */
/*! /*!
@ -1303,6 +1319,7 @@ QOpenGLTexture *QOpenGLTexturePrivate::createTextureView(QOpenGLTexture::Target
\value Int32 Equivalent to GL_INT \value Int32 Equivalent to GL_INT
\value UInt32 Equivalent to GL_UNSIGNED_INT \value UInt32 Equivalent to GL_UNSIGNED_INT
\value Float16 Equivalent to GL_HALF_FLOAT \value Float16 Equivalent to GL_HALF_FLOAT
\value Float16OES Equivalent to GL_HALF_FLOAT_OES
\value Float32 Equivalent to GL_FLOAT \value Float32 Equivalent to GL_FLOAT
\value UInt32_RGB9_E5 Equivalent to GL_UNSIGNED_INT_5_9_9_9_REV \value UInt32_RGB9_E5 Equivalent to GL_UNSIGNED_INT_5_9_9_9_REV
\value UInt32_RG11B10F Equivalent to GL_UNSIGNED_INT_10F_11F_11F_REV \value UInt32_RG11B10F Equivalent to GL_UNSIGNED_INT_10F_11F_11F_REV
@ -1752,6 +1769,12 @@ void QOpenGLTexture::setFormat(TextureFormat format)
case D32: case D32:
case D32F: case D32F:
case D32FS8X24: case D32FS8X24:
case DepthFormat:
case AlphaFormat:
case RGBFormat:
case RGBAFormat:
case LuminanceFormat:
case LuminanceAlphaFormat:
d->formatClass = FormatClass_Unique; d->formatClass = FormatClass_Unique;
break; break;
} }
@ -2242,6 +2265,7 @@ bool QOpenGLTexture::hasFeature(Feature feature)
bool supported = false; bool supported = false;
switch (feature) { switch (feature) {
#if !defined(QT_OPENGL_ES_2)
case ImmutableMultisampleStorage: case ImmutableMultisampleStorage:
case TextureBuffer: case TextureBuffer:
case StencilTexturing: case StencilTexturing:
@ -2289,16 +2313,38 @@ bool QOpenGLTexture::hasFeature(Feature feature)
break; break;
} }
#else
case Texture3D:
supported = ctx->hasExtension(QByteArrayLiteral("GL_OES_texture_3D"));
break;
case AnisotropicFiltering:
supported = ctx->hasExtension(QByteArrayLiteral("GL_EXT_texture_filter_anisotropic"));
break;
case NPOTTextures:
case NPOTTextureRepeat:
supported = f.version() >= qMakePair(3,0);
if (!supported) {
supported = ctx->hasExtension(QByteArrayLiteral("GL_OES_texture_npot"));
if (!supported)
supported = ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_non_power_of_two"));
}
default:
break;
}
#endif
return supported; return supported;
} }
/*! /*!
Sets the base mipmap level used for all texture lookups with this texture to \a baseLevel. Sets the base mipmap level used for all texture lookups with this texture to \a baseLevel.
\note This function has no effect on Qt built for OpenGL ES 2.
\sa mipBaseLevel(), setMipMaxLevel(), setMipLevelRange() \sa mipBaseLevel(), setMipMaxLevel(), setMipLevelRange()
*/ */
void QOpenGLTexture::setMipBaseLevel(int baseLevel) void QOpenGLTexture::setMipBaseLevel(int baseLevel)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
@ -2306,6 +2352,10 @@ void QOpenGLTexture::setMipBaseLevel(int baseLevel)
Q_ASSERT(baseLevel <= d->maxLevel); Q_ASSERT(baseLevel <= d->maxLevel);
d->baseLevel = baseLevel; d->baseLevel = baseLevel;
d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_TEXTURE_BASE_LEVEL, baseLevel); d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_TEXTURE_BASE_LEVEL, baseLevel);
#else
Q_UNUSED(baseLevel);
qWarning("QOpenGLTexture: Mipmap base level is not supported");
#endif
} }
/*! /*!
@ -2323,10 +2373,12 @@ int QOpenGLTexture::mipBaseLevel() const
/*! /*!
Sets the maximum mipmap level used for all texture lookups with this texture to \a maxLevel. Sets the maximum mipmap level used for all texture lookups with this texture to \a maxLevel.
\note This function has no effect on Qt built for OpenGL ES 2.
\sa mipMaxLevel(), setMipBaseLevel(), setMipLevelRange() \sa mipMaxLevel(), setMipBaseLevel(), setMipLevelRange()
*/ */
void QOpenGLTexture::setMipMaxLevel(int maxLevel) void QOpenGLTexture::setMipMaxLevel(int maxLevel)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
@ -2334,6 +2386,10 @@ void QOpenGLTexture::setMipMaxLevel(int maxLevel)
Q_ASSERT(d->baseLevel <= maxLevel); Q_ASSERT(d->baseLevel <= maxLevel);
d->maxLevel = maxLevel; d->maxLevel = maxLevel;
d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_TEXTURE_MAX_LEVEL, maxLevel); d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_TEXTURE_MAX_LEVEL, maxLevel);
#else
Q_UNUSED(maxLevel);
qWarning("QOpenGLTexture: Mipmap max level is not supported");
#endif
} }
/*! /*!
@ -2351,10 +2407,12 @@ int QOpenGLTexture::mipMaxLevel() const
Sets the range of mipmap levels that can be used for texture lookups with this texture Sets the range of mipmap levels that can be used for texture lookups with this texture
to range from \a baseLevel to \a maxLevel. to range from \a baseLevel to \a maxLevel.
\note This function has no effect on Qt built for OpenGL ES 2.
\sa setMipBaseLevel(), setMipMaxLevel(), mipLevelRange() \sa setMipBaseLevel(), setMipMaxLevel(), mipLevelRange()
*/ */
void QOpenGLTexture::setMipLevelRange(int baseLevel, int maxLevel) void QOpenGLTexture::setMipLevelRange(int baseLevel, int maxLevel)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
@ -2362,6 +2420,11 @@ void QOpenGLTexture::setMipLevelRange(int baseLevel, int maxLevel)
Q_ASSERT(baseLevel <= maxLevel); Q_ASSERT(baseLevel <= maxLevel);
d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_TEXTURE_BASE_LEVEL, baseLevel); d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_TEXTURE_BASE_LEVEL, baseLevel);
d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_TEXTURE_MAX_LEVEL, maxLevel); d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_TEXTURE_MAX_LEVEL, maxLevel);
#else
Q_UNUSED(baseLevel);
Q_UNUSED(maxLevel);
qWarning("QOpenGLTexture: Mipmap level range is not supported");
#endif
} }
/*! /*!
@ -2451,11 +2514,12 @@ void QOpenGLTexture::generateMipMaps(int baseLevel, bool resetBaseLevel)
This function maps \a component to the output \a value. This function maps \a component to the output \a value.
\note This function has no effect on Mac and Qt built for OpenGL ES 2.
\sa swizzleMask() \sa swizzleMask()
*/ */
void QOpenGLTexture::setSwizzleMask(SwizzleComponent component, SwizzleValue value) void QOpenGLTexture::setSwizzleMask(SwizzleComponent component, SwizzleValue value)
{ {
#if !defined(Q_OS_MAC) #if !defined(Q_OS_MAC) && !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2467,9 +2531,9 @@ void QOpenGLTexture::setSwizzleMask(SwizzleComponent component, SwizzleValue val
d->swizzleMask[component - SwizzleRed] = value; d->swizzleMask[component - SwizzleRed] = value;
d->texFuncs->glTextureParameteri(d->textureId, d->target, component, value); d->texFuncs->glTextureParameteri(d->textureId, d->target, component, value);
#else #else
qWarning("Texture swizzling is not supported");
Q_UNUSED(component); Q_UNUSED(component);
Q_UNUSED(value); Q_UNUSED(value);
qWarning("QOpenGLTexture: Texture swizzling is not supported");
#endif #endif
} }
@ -2479,7 +2543,7 @@ void QOpenGLTexture::setSwizzleMask(SwizzleComponent component, SwizzleValue val
void QOpenGLTexture::setSwizzleMask(SwizzleValue r, SwizzleValue g, void QOpenGLTexture::setSwizzleMask(SwizzleValue r, SwizzleValue g,
SwizzleValue b, SwizzleValue a) SwizzleValue b, SwizzleValue a)
{ {
#if !defined(Q_OS_MAC) #if !defined(Q_OS_MAC) && !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2495,11 +2559,11 @@ void QOpenGLTexture::setSwizzleMask(SwizzleValue r, SwizzleValue g,
d->swizzleMask[3] = a; d->swizzleMask[3] = a;
d->texFuncs->glTextureParameteriv(d->textureId, d->target, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); d->texFuncs->glTextureParameteriv(d->textureId, d->target, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
#else #else
qWarning("Texture swizzling is not supported");
Q_UNUSED(r); Q_UNUSED(r);
Q_UNUSED(g); Q_UNUSED(g);
Q_UNUSED(b); Q_UNUSED(b);
Q_UNUSED(a); Q_UNUSED(a);
qWarning("QOpenGLTexture: Texture swizzling is not supported");
#endif #endif
} }
@ -2520,11 +2584,12 @@ QOpenGLTexture::SwizzleValue QOpenGLTexture::swizzleMask(SwizzleComponent compon
shader will access the depth component as a single float, as normal. But when shader will access the depth component as a single float, as normal. But when
the parameter is set to StencilMode?, the shader will access the stencil component. the parameter is set to StencilMode?, the shader will access the stencil component.
\note This function has no effect on Mac and Qt built for OpenGL ES 2.
\sa depthStencilMode() \sa depthStencilMode()
*/ */
void QOpenGLTexture::setDepthStencilMode(QOpenGLTexture::DepthStencilMode mode) void QOpenGLTexture::setDepthStencilMode(QOpenGLTexture::DepthStencilMode mode)
{ {
#if !defined(Q_OS_MAC) #if !defined(Q_OS_MAC) && !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2537,7 +2602,7 @@ void QOpenGLTexture::setDepthStencilMode(QOpenGLTexture::DepthStencilMode mode)
d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_DEPTH_STENCIL_TEXTURE_MODE, mode); d->texFuncs->glTextureParameteri(d->textureId, d->target, GL_DEPTH_STENCIL_TEXTURE_MODE, mode);
#else #else
Q_UNUSED(mode); Q_UNUSED(mode);
qWarning("DepthStencil Mode is not supported"); qWarning("QOpenGLTexture: DepthStencil Mode is not supported");
#endif #endif
} }
@ -2706,10 +2771,12 @@ QOpenGLTexture::WrapMode QOpenGLTexture::wrapMode(QOpenGLTexture::CoordinateDire
/*! /*!
Sets the border color of the texture to \a color. Sets the border color of the texture to \a color.
\note This function has no effect on Mac and Qt built for OpenGL ES 2.
\sa borderColor() \sa borderColor()
*/ */
void QOpenGLTexture::setBorderColor(QColor color) void QOpenGLTexture::setBorderColor(QColor color)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2723,6 +2790,10 @@ void QOpenGLTexture::setBorderColor(QColor color)
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
d->borderColor.append(QVariant(values[i])); d->borderColor.append(QVariant(values[i]));
d->texFuncs->glTextureParameterfv(d->textureId, d->target, GL_TEXTURE_BORDER_COLOR, values); d->texFuncs->glTextureParameterfv(d->textureId, d->target, GL_TEXTURE_BORDER_COLOR, values);
#else
Q_UNUSED(color);
qWarning("QOpenGLTexture: Border color is not supported");
#endif
} }
/*! /*!
@ -2730,6 +2801,7 @@ void QOpenGLTexture::setBorderColor(QColor color)
*/ */
void QOpenGLTexture::setBorderColor(float r, float g, float b, float a) void QOpenGLTexture::setBorderColor(float r, float g, float b, float a)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2743,6 +2815,13 @@ void QOpenGLTexture::setBorderColor(float r, float g, float b, float a)
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
d->borderColor.append(QVariant(values[i])); d->borderColor.append(QVariant(values[i]));
d->texFuncs->glTextureParameterfv(d->textureId, d->target, GL_TEXTURE_BORDER_COLOR, values); d->texFuncs->glTextureParameterfv(d->textureId, d->target, GL_TEXTURE_BORDER_COLOR, values);
#else
Q_UNUSED(r);
Q_UNUSED(g);
Q_UNUSED(b);
Q_UNUSED(a);
qWarning("QOpenGLTexture: Border color is not supported");
#endif
} }
/*! /*!
@ -2750,6 +2829,7 @@ void QOpenGLTexture::setBorderColor(float r, float g, float b, float a)
*/ */
void QOpenGLTexture::setBorderColor(int r, int g, int b, int a) void QOpenGLTexture::setBorderColor(int r, int g, int b, int a)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2763,6 +2843,13 @@ void QOpenGLTexture::setBorderColor(int r, int g, int b, int a)
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
d->borderColor.append(QVariant(values[i])); d->borderColor.append(QVariant(values[i]));
d->texFuncs->glTextureParameteriv(d->textureId, d->target, GL_TEXTURE_BORDER_COLOR, values); d->texFuncs->glTextureParameteriv(d->textureId, d->target, GL_TEXTURE_BORDER_COLOR, values);
#else
Q_UNUSED(r);
Q_UNUSED(g);
Q_UNUSED(b);
Q_UNUSED(a);
qWarning("QOpenGLTexture: Border color is not supported");
#endif
// TODO Handle case of using glTextureParameterIiv() based on format // TODO Handle case of using glTextureParameterIiv() based on format
} }
@ -2772,6 +2859,7 @@ void QOpenGLTexture::setBorderColor(int r, int g, int b, int a)
*/ */
void QOpenGLTexture::setBorderColor(uint r, uint g, uint b, uint a) void QOpenGLTexture::setBorderColor(uint r, uint g, uint b, uint a)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2785,6 +2873,13 @@ void QOpenGLTexture::setBorderColor(uint r, uint g, uint b, uint a)
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
d->borderColor.append(QVariant(values[i])); d->borderColor.append(QVariant(values[i]));
d->texFuncs->glTextureParameteriv(d->textureId, d->target, GL_TEXTURE_BORDER_COLOR, values); d->texFuncs->glTextureParameteriv(d->textureId, d->target, GL_TEXTURE_BORDER_COLOR, values);
#else
Q_UNUSED(r);
Q_UNUSED(g);
Q_UNUSED(b);
Q_UNUSED(a);
qWarning("QOpenGLTexture: Border color is not supported");
#endif
// TODO Handle case of using glTextureParameterIuiv() based on format // TODO Handle case of using glTextureParameterIuiv() based on format
} }
@ -2862,10 +2957,12 @@ void QOpenGLTexture::borderColor(unsigned int *border) const
Sets the minimum level of detail to \a value. This limits the selection of highest Sets the minimum level of detail to \a value. This limits the selection of highest
resolution mipmap (lowest mipmap level). The default value is -1000. resolution mipmap (lowest mipmap level). The default value is -1000.
\note This function has no effect on Qt built for OpenGL ES 2.
\sa minimumLevelOfDetail(), setMaximumLevelOfDetail(), setLevelOfDetailRange() \sa minimumLevelOfDetail(), setMaximumLevelOfDetail(), setLevelOfDetailRange()
*/ */
void QOpenGLTexture::setMinimumLevelOfDetail(float value) void QOpenGLTexture::setMinimumLevelOfDetail(float value)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2873,6 +2970,10 @@ void QOpenGLTexture::setMinimumLevelOfDetail(float value)
Q_ASSERT(value < d->maxLevelOfDetail); Q_ASSERT(value < d->maxLevelOfDetail);
d->minLevelOfDetail = value; d->minLevelOfDetail = value;
d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_MIN_LOD, value); d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_MIN_LOD, value);
#else
Q_UNUSED(value);
qWarning("QOpenGLTexture: Detail level is not supported");
#endif
} }
/*! /*!
@ -2890,10 +2991,12 @@ float QOpenGLTexture::minimumLevelOfDetail() const
Sets the maximum level of detail to \a value. This limits the selection of lowest Sets the maximum level of detail to \a value. This limits the selection of lowest
resolution mipmap (highest mipmap level). The default value is 1000. resolution mipmap (highest mipmap level). The default value is 1000.
\note This function has no effect on Qt built for OpenGL ES 2.
\sa maximumLevelOfDetail(), setMinimumLevelOfDetail(), setLevelOfDetailRange() \sa maximumLevelOfDetail(), setMinimumLevelOfDetail(), setLevelOfDetailRange()
*/ */
void QOpenGLTexture::setMaximumLevelOfDetail(float value) void QOpenGLTexture::setMaximumLevelOfDetail(float value)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2901,6 +3004,10 @@ void QOpenGLTexture::setMaximumLevelOfDetail(float value)
Q_ASSERT(value > d->minLevelOfDetail); Q_ASSERT(value > d->minLevelOfDetail);
d->maxLevelOfDetail = value; d->maxLevelOfDetail = value;
d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_MAX_LOD, value); d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_MAX_LOD, value);
#else
Q_UNUSED(value);
qWarning("QOpenGLTexture: Detail level is not supported");
#endif
} }
/*! /*!
@ -2917,10 +3024,12 @@ float QOpenGLTexture::maximumLevelOfDetail() const
/*! /*!
Sets the minimum and maximum level of detail parameters. Sets the minimum and maximum level of detail parameters.
\note This function has no effect on Qt built for OpenGL ES 2.
\sa levelOfDetailRange(), setMinimumLevelOfDetail(), setMaximumLevelOfDetail() \sa levelOfDetailRange(), setMinimumLevelOfDetail(), setMaximumLevelOfDetail()
*/ */
void QOpenGLTexture::setLevelOfDetailRange(float min, float max) void QOpenGLTexture::setLevelOfDetailRange(float min, float max)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
@ -2930,6 +3039,11 @@ void QOpenGLTexture::setLevelOfDetailRange(float min, float max)
d->maxLevelOfDetail = max; d->maxLevelOfDetail = max;
d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_MIN_LOD, min); d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_MIN_LOD, min);
d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_MAX_LOD, max); d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_MAX_LOD, max);
#else
Q_UNUSED(min);
Q_UNUSED(max);
qWarning("QOpenGLTexture: Detail level is not supported");
#endif
} }
/*! /*!
@ -2946,16 +3060,22 @@ QPair<float, float> QOpenGLTexture::levelOfDetailRange() const
/*! /*!
Sets the level of detail bias parameter. Sets the level of detail bias parameter.
\note This function has no effect on Qt built for OpenGL ES 2.
\sa levelofDetailBias() \sa levelofDetailBias()
*/ */
void QOpenGLTexture::setLevelofDetailBias(float bias) void QOpenGLTexture::setLevelofDetailBias(float bias)
{ {
#if !defined(QT_OPENGL_ES_2)
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
d->create(); d->create();
Q_ASSERT(d->texFuncs); Q_ASSERT(d->texFuncs);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->levelOfDetailBias = bias; d->levelOfDetailBias = bias;
d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_LOD_BIAS, bias); d->texFuncs->glTextureParameterf(d->textureId, d->target, GL_TEXTURE_LOD_BIAS, bias);
#else
Q_UNUSED(bias);
qWarning("QOpenGLTexture: Detail level is not supported");
#endif
} }
/*! /*!

View File

@ -222,7 +222,16 @@ public:
SRGB_Alpha_DXT1 = 0x8C4D, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT SRGB_Alpha_DXT1 = 0x8C4D, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
SRGB_Alpha_DXT3 = 0x8C4E, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT SRGB_Alpha_DXT3 = 0x8C4E, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
SRGB_Alpha_DXT5 = 0x8C4F, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT SRGB_Alpha_DXT5 = 0x8C4F, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
SRGB_BP_UNorm = 0x8E8D // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB SRGB_BP_UNorm = 0x8E8D, // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
// ES 2 formats
DepthFormat = 0x1902, // GL_DEPTH_COMPONENT
AlphaFormat = 0x1906, // GL_ALPHA
RGBFormat = 0x1907, // GL_RGB
RGBAFormat = 0x1908, // GL_RGBA
LuminanceFormat = 0x1909, // GL_LUMINANCE
LuminanceAlphaFormat = 0x190A
}; };
// This is not used externally yet but is reserved to allow checking of // This is not used externally yet but is reserved to allow checking of
@ -296,7 +305,10 @@ public:
RGBA_Integer = 0x8D99, // GL_RGBA_INTEGER RGBA_Integer = 0x8D99, // GL_RGBA_INTEGER
BGRA_Integer = 0x8D9B, // GL_BGRA_INTEGER BGRA_Integer = 0x8D9B, // GL_BGRA_INTEGER
Depth = 0x1902, // GL_DEPTH_COMPONENT Depth = 0x1902, // GL_DEPTH_COMPONENT
DepthStencil = 0x84F9 // GL_DEPTH_STENCIL DepthStencil = 0x84F9, // GL_DEPTH_STENCIL
Alpha = 0x1906, // GL_ALPHA
Luminance = 0x1909, // GL_LUMINANCE
LuminanceAlpha = 0x190A // GL_LUMINANCE_ALPHA
}; };
enum PixelType { enum PixelType {
@ -308,6 +320,7 @@ public:
Int32 = 0x1404, // GL_INT Int32 = 0x1404, // GL_INT
UInt32 = 0x1405, // GL_UNSIGNED_INT UInt32 = 0x1405, // GL_UNSIGNED_INT
Float16 = 0x140B, // GL_HALF_FLOAT Float16 = 0x140B, // GL_HALF_FLOAT
Float16OES = 0x8D61, // GL_HALF_FLOAT_OES
Float32 = 0x1406, // GL_FLOAT Float32 = 0x1406, // GL_FLOAT
UInt32_RGB9_E5 = 0x8C3E, // GL_UNSIGNED_INT_5_9_9_9_REV UInt32_RGB9_E5 = 0x8C3E, // GL_UNSIGNED_INT_5_9_9_9_REV
UInt32_RG11B10F = 0x8C3B, // GL_UNSIGNED_INT_10F_11F_11F_REV UInt32_RG11B10F = 0x8C3B, // GL_UNSIGNED_INT_10F_11F_11F_REV

View File

@ -48,6 +48,7 @@ QT_BEGIN_NAMESPACE
QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context) QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context)
{ {
// Resolve EXT_direct_state_access entry points if present // Resolve EXT_direct_state_access entry points if present
#if !defined(QT_OPENGL_ES_2)
if (context->hasExtension(QByteArrayLiteral("GL_EXT_direct_state_access"))) { if (context->hasExtension(QByteArrayLiteral("GL_EXT_direct_state_access"))) {
TextureParameteriEXT = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLenum , GLint )>(context->getProcAddress(QByteArrayLiteral("glTextureParameteriEXT"))); TextureParameteriEXT = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLenum , GLint )>(context->getProcAddress(QByteArrayLiteral("glTextureParameteriEXT")));
TextureParameterivEXT = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLenum , const GLint *)>(context->getProcAddress(QByteArrayLiteral("glTextureParameterivEXT"))); TextureParameterivEXT = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLenum , const GLint *)>(context->getProcAddress(QByteArrayLiteral("glTextureParameterivEXT")));
@ -96,6 +97,7 @@ QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context)
CompressedTextureImage2D = &QOpenGLTextureHelper::dsa_CompressedTextureImage2D; CompressedTextureImage2D = &QOpenGLTextureHelper::dsa_CompressedTextureImage2D;
CompressedTextureImage3D = &QOpenGLTextureHelper::dsa_CompressedTextureImage3D; CompressedTextureImage3D = &QOpenGLTextureHelper::dsa_CompressedTextureImage3D;
} else { } else {
#endif
// Use our own DSA emulation // Use our own DSA emulation
TextureParameteri = &QOpenGLTextureHelper::qt_TextureParameteri; TextureParameteri = &QOpenGLTextureHelper::qt_TextureParameteri;
TextureParameteriv = &QOpenGLTextureHelper::qt_TextureParameteriv; TextureParameteriv = &QOpenGLTextureHelper::qt_TextureParameteriv;
@ -117,9 +119,21 @@ QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context)
CompressedTextureImage1D = &QOpenGLTextureHelper::qt_CompressedTextureImage1D; CompressedTextureImage1D = &QOpenGLTextureHelper::qt_CompressedTextureImage1D;
CompressedTextureImage2D = &QOpenGLTextureHelper::qt_CompressedTextureImage2D; CompressedTextureImage2D = &QOpenGLTextureHelper::qt_CompressedTextureImage2D;
CompressedTextureImage3D = &QOpenGLTextureHelper::qt_CompressedTextureImage3D; CompressedTextureImage3D = &QOpenGLTextureHelper::qt_CompressedTextureImage3D;
#if defined(QT_OPENGL_ES_2)
if (context->hasExtension(QByteArrayLiteral("GL_OES_texture_3D"))) {
TexImage3D = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*)>(context->getProcAddress(QByteArrayLiteral("glTexImage3DOES")));
TexSubImage3D = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid*)>(context->getProcAddress(QByteArrayLiteral("glTexSubImage3DOES")));
CompressedTexImage3D = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*)>(context->getProcAddress(QByteArrayLiteral("glCompressedTexImage3DOES")));
CompressedTexSubImage3D = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*)>(context->getProcAddress(QByteArrayLiteral("glCompressedTexSubImage3DOES")));
}
#endif
#if !defined(QT_OPENGL_ES_2)
} }
#endif
// Some DSA functions are part of NV_texture_multisample instead // Some DSA functions are part of NV_texture_multisample instead
#if !defined(QT_OPENGL_ES_2)
if (context->hasExtension(QByteArrayLiteral("GL_NV_texture_multisample"))) { if (context->hasExtension(QByteArrayLiteral("GL_NV_texture_multisample"))) {
TextureImage3DMultisampleNV = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLsizei , GLint , GLsizei , GLsizei , GLsizei , GLboolean )>(context->getProcAddress(QByteArrayLiteral("glTextureImage3DMultisampleNV"))); TextureImage3DMultisampleNV = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLsizei , GLint , GLsizei , GLsizei , GLsizei , GLboolean )>(context->getProcAddress(QByteArrayLiteral("glTextureImage3DMultisampleNV")));
TextureImage2DMultisampleNV = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLsizei , GLint , GLsizei , GLsizei , GLboolean )>(context->getProcAddress(QByteArrayLiteral("glTextureImage2DMultisampleNV"))); TextureImage2DMultisampleNV = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLsizei , GLint , GLsizei , GLsizei , GLboolean )>(context->getProcAddress(QByteArrayLiteral("glTextureImage2DMultisampleNV")));
@ -127,9 +141,12 @@ QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context)
TextureImage3DMultisample = &QOpenGLTextureHelper::dsa_TextureImage3DMultisample; TextureImage3DMultisample = &QOpenGLTextureHelper::dsa_TextureImage3DMultisample;
TextureImage2DMultisample = &QOpenGLTextureHelper::dsa_TextureImage2DMultisample; TextureImage2DMultisample = &QOpenGLTextureHelper::dsa_TextureImage2DMultisample;
} else { } else {
#endif
TextureImage3DMultisample = &QOpenGLTextureHelper::qt_TextureImage3DMultisample; TextureImage3DMultisample = &QOpenGLTextureHelper::qt_TextureImage3DMultisample;
TextureImage2DMultisample = &QOpenGLTextureHelper::qt_TextureImage2DMultisample; TextureImage2DMultisample = &QOpenGLTextureHelper::qt_TextureImage2DMultisample;
#if !defined(QT_OPENGL_ES_2)
} }
#endif
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
HMODULE handle = GetModuleHandleA("opengl32.dll"); HMODULE handle = GetModuleHandleA("opengl32.dll");

View File

@ -256,6 +256,7 @@ public:
} }
private: private:
#if !defined(QT_OPENGL_ES_2)
// DSA wrapper (so we can use pointer to member function as switch) // DSA wrapper (so we can use pointer to member function as switch)
inline void dsa_TextureParameteri(GLuint texture, GLenum target, GLenum pname, GLint param) inline void dsa_TextureParameteri(GLuint texture, GLenum target, GLenum pname, GLint param)
{ {
@ -403,6 +404,7 @@ private:
{ {
CompressedTextureImage3DEXT(texture, target, level, internalFormat, width, height, depth, border, imageSize, bits); CompressedTextureImage3DEXT(texture, target, level, internalFormat, width, height, depth, border, imageSize, bits);
} }
#endif
// DSA-like API // DSA-like API
@ -899,6 +901,7 @@ public:
int val = 0; int val = 0;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &val); glGetIntegerv(GL_UNPACK_ALIGNMENT, &val);
options.setAlignment(val); options.setAlignment(val);
#if !defined(QT_OPENGL_ES_2)
glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &val); glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &val);
options.setSkipImages(val); options.setSkipImages(val);
glGetIntegerv(GL_UNPACK_SKIP_ROWS, &val); glGetIntegerv(GL_UNPACK_SKIP_ROWS, &val);
@ -914,12 +917,14 @@ public:
options.setLeastSignificantByteFirst(b); options.setLeastSignificantByteFirst(b);
glGetBooleanv(GL_UNPACK_SWAP_BYTES, &b); glGetBooleanv(GL_UNPACK_SWAP_BYTES, &b);
options.setSwapBytesEnabled(b); options.setSwapBytesEnabled(b);
#endif
return options; return options;
} }
inline void setPixelUploadOptions(const QOpenGLPixelTransferOptions &options) inline void setPixelUploadOptions(const QOpenGLPixelTransferOptions &options)
{ {
glPixelStorei(GL_UNPACK_ALIGNMENT, options.alignment()); glPixelStorei(GL_UNPACK_ALIGNMENT, options.alignment());
#if !defined(QT_OPENGL_ES_2)
glPixelStorei(GL_UNPACK_SKIP_IMAGES, options.skipImages()); glPixelStorei(GL_UNPACK_SKIP_IMAGES, options.skipImages());
glPixelStorei(GL_UNPACK_SKIP_ROWS, options.skipRows()); glPixelStorei(GL_UNPACK_SKIP_ROWS, options.skipRows());
glPixelStorei(GL_UNPACK_SKIP_PIXELS, options.skipPixels()); glPixelStorei(GL_UNPACK_SKIP_PIXELS, options.skipPixels());
@ -927,6 +932,7 @@ public:
glPixelStorei(GL_UNPACK_ROW_LENGTH, options.rowLength()); glPixelStorei(GL_UNPACK_ROW_LENGTH, options.rowLength());
glPixelStorei(GL_UNPACK_LSB_FIRST, options.isLeastSignificantBitFirst()); glPixelStorei(GL_UNPACK_LSB_FIRST, options.isLeastSignificantBitFirst());
glPixelStorei(GL_UNPACK_SWAP_BYTES, options.isSwapBytesEnabled()); glPixelStorei(GL_UNPACK_SWAP_BYTES, options.isSwapBytesEnabled());
#endif
} }
private: private:
@ -982,6 +988,7 @@ private:
CompressedTextureImage2DMemberFunc CompressedTextureImage2D; CompressedTextureImage2DMemberFunc CompressedTextureImage2D;
CompressedTextureImage3DMemberFunc CompressedTextureImage3D; CompressedTextureImage3DMemberFunc CompressedTextureImage3D;
#if !defined(QT_OPENGL_ES_2)
// Raw function pointers for core and DSA functions // Raw function pointers for core and DSA functions
// EXT_direct_state_access used when DSA is available // EXT_direct_state_access used when DSA is available
@ -1012,6 +1019,7 @@ private:
// Plus some missing ones that are in the NV_texture_multisample extension instead // Plus some missing ones that are in the NV_texture_multisample extension instead
void (QOPENGLF_APIENTRYP TextureImage3DMultisampleNV)(GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); void (QOPENGLF_APIENTRYP TextureImage3DMultisampleNV)(GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
void (QOPENGLF_APIENTRYP TextureImage2DMultisampleNV)(GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); void (QOPENGLF_APIENTRYP TextureImage2DMultisampleNV)(GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
#endif
// OpenGL 1.0 // OpenGL 1.0
void (QOPENGLF_APIENTRYP GetIntegerv)(GLenum pname, GLint *params); void (QOPENGLF_APIENTRYP GetIntegerv)(GLenum pname, GLint *params);