140
140
: m_allocator(size)
141
141
, m_texture_id(0)
143
, m_filtering(QSGTexture::Linear)
144
143
, m_allocated(false)
146
m_internalFormat = GL_RGBA;
147
m_externalFormat = GL_BGRA;
150
if (QOpenGLContext::currentContext()->isOpenGLES()) {
148
153
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
149
154
QString *deviceName =
150
155
static_cast<QString *>(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("AndroidDeviceName"));
151
static bool wrongfullyReportsBgra8888Support = deviceName->compare(QStringLiteral("samsung SM-T211"), Qt::CaseInsensitive) == 0
152
|| deviceName->compare(QStringLiteral("samsung SM-T210"), Qt::CaseInsensitive) == 0
153
|| deviceName->compare(QStringLiteral("samsung SM-T215"), Qt::CaseInsensitive) == 0;
156
static bool wrongfullyReportsBgra8888Support = deviceName != 0
157
&& (deviceName->compare(QStringLiteral("samsung SM-T211"), Qt::CaseInsensitive) == 0
158
|| deviceName->compare(QStringLiteral("samsung SM-T210"), Qt::CaseInsensitive) == 0
159
|| deviceName->compare(QStringLiteral("samsung SM-T215"), Qt::CaseInsensitive) == 0);
155
161
static bool wrongfullyReportsBgra8888Support = false;
158
164
const char *ext = (const char *) glGetString(GL_EXTENSIONS);
159
165
if (!wrongfullyReportsBgra8888Support
165
171
} else if (strstr(ext, "GL_APPLE_texture_format_BGRA8888")) {
166
172
m_internalFormat = GL_RGBA;
167
173
m_externalFormat = GL_BGRA;
170
176
m_internalFormat = m_externalFormat = GL_RGBA;
173
m_internalFormat = GL_RGBA;
174
m_externalFormat = GL_BGRA;
177
183
m_use_bgra_fallback = qEnvironmentVariableIsSet("QSG_ATLAS_USE_BGRA_FALLBACK");
329
334
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
330
335
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
331
336
#if !defined(QT_OPENGL_ES_2)
332
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
337
if (!QOpenGLContext::currentContext()->isOpenGLES())
338
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
334
340
glTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, m_size.width(), m_size.height(), 0, m_externalFormat, GL_UNSIGNED_BYTE, 0);
361
367
glDeleteTextures(1, &m_texture_id);
362
368
m_texture_id = 0;
366
371
glBindTexture(GL_TEXTURE_2D, m_texture_id);
369
374
if (m_texture_id == 0)
372
377
// Upload all pending images..
373
378
for (int i=0; i<m_pending_uploads.size(); ++i) {
375
380
#ifndef QSG_NO_RENDER_TIMING
376
bool profileFrames = qsg_render_timing || QQmlProfilerService::enabled;
381
bool profileFrames = qsg_render_timing || QQuickProfiler::enabled;
377
382
if (profileFrames)
378
383
qsg_renderer_timer.start();
393
398
(int) (qsg_renderer_timer.elapsed()));
396
if (QQmlProfilerService::enabled) {
397
QQmlProfilerService::sceneGraphFrame(
398
QQmlProfilerService::SceneGraphTexturePrepare,
399
0, // bind (not relevant)
400
0, // convert (not relevant)
401
0, // swizzle (not relevant)
402
qsg_renderer_timer.nsecsElapsed(), // (upload all of the above)
403
0); // mipmap (not used ever...)
401
Q_QUICK_SG_PROFILE1(QQuickProfiler::SceneGraphTexturePrepare, (
402
0, // bind (not relevant)
403
0, // convert (not relevant)
404
0, // swizzle (not relevant)
405
qsg_renderer_timer.nsecsElapsed(), // (upload all of the above)
406
0)); // mipmap (not used ever...)
408
if (filtering != m_filtering) {
409
GLenum f = filtering == QSGTexture::Nearest ? GL_NEAREST : GL_LINEAR;
410
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, f);
411
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, f);
412
m_filtering = filtering;
410
GLenum f = filtering == QSGTexture::Nearest ? GL_NEAREST : GL_LINEAR;
411
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, f);
412
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, f);
415
414
m_pending_uploads.clear();
420
417
void Atlas::remove(Texture *t)
461
458
m_nonatlas_texture = new QSGPlainTexture();
462
459
m_nonatlas_texture->setImage(m_image);
463
460
m_nonatlas_texture->setFiltering(filtering());
461
m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());
465
463
return m_nonatlas_texture;