summaryrefslogtreecommitdiffstats
path: root/src/adaptationlayers/adaptationlayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/adaptationlayers/adaptationlayer.cpp')
-rw-r--r--src/adaptationlayers/adaptationlayer.cpp172
1 files changed, 107 insertions, 65 deletions
diff --git a/src/adaptationlayers/adaptationlayer.cpp b/src/adaptationlayers/adaptationlayer.cpp
index fe31289..196891e 100644
--- a/src/adaptationlayers/adaptationlayer.cpp
+++ b/src/adaptationlayers/adaptationlayer.cpp
@@ -43,68 +43,110 @@
#include <qdatetime.h>
-/*!
- Constructs a new texture reference with status set to Null
- */
-TextureReference::TextureReference()
- : m_status(Null)
- , m_texture_id(0)
- , m_sub_rect(0, 0, 1, 1)
- , m_has_alpha(false)
- , m_owns_texture(false)
- , m_mipmap(false)
-{
-}
-
-TextureReference::~TextureReference()
-{
- if (m_owns_texture) {
- glDeleteTextures(1, (GLuint *) &m_texture_id);
- }
-}
-
-void TextureReference::setStatus(Status s)
-{
- m_status = s;
-
- Q_ASSERT(s != Uploaded || (m_texture_id > 0 && !m_texture_size.isEmpty()));
-
- emit statusChanged(s);
-}
-
-/*!
- Performs a synchronous upload of \a image using the specified \a hints.
-
- The upload is done using the QGLContext::bindTexture().
- */
-const TextureReference *TextureManager::requestUploadedTexture(const QImage &image, UploadHints hints, QObject *listener, const char *slot)
-{
- QTime time;
- time.start();
-
- QGLContext *context = const_cast<QGLContext *>(QGLContext::currentContext());
-
- QGLContext::BindOptions options = QGLContext::PremultipliedAlphaBindOption;
- if (hints & GenerateMipmapUploadHint)
- options |= QGLContext::MipmapBindOption;
-
- int id = context->bindTexture(image,
- GL_TEXTURE_2D,
- image.hasAlphaChannel() ? GL_RGBA : GL_RGB,
- options);
-
- printf("Texture uploaded in: %d\n", time.elapsed());
-
- TextureReference *ref = new TextureReference();
-
- if (listener && slot)
- QObject::connect(ref, SIGNAL(statusChanged(int)), listener, slot);
-
- ref->setTextureId(id);
- ref->setOwnsTexture(true);
- ref->setAlphaChannel(image.hasAlphaChannel());
- ref->setTextureSize(image.size());
- ref->setStatus(TextureReference::Uploaded);
-
- return ref;
-}
+///*!
+// Constructs a new texture reference with status set to Null
+// */
+//TextureReference::TextureReference()
+// : m_status(Null)
+// , m_texture_id(0)
+// , m_sub_rect(0, 0, 1, 1)
+// , m_has_alpha(false)
+// , m_mipmap(false)
+//{
+//}
+
+//TextureReference::~TextureReference()
+//{
+// if (m_owns_texture) {
+// glDeleteTextures(1, (GLuint *) &m_texture_id);
+// }
+//}
+
+//void TextureReference::setStatus(Status s)
+//{
+// m_status = s;
+
+// Q_ASSERT(s != Uploaded || (m_texture_id > 0 && !m_texture_size.isEmpty()));
+
+// emit statusChanged(s);
+//}
+
+//struct QSGTextureCacheKey {
+// quint64 cacheKey;
+// uint hints;
+//};
+
+//struct QSGTextureCacheEntry {
+// int ref;
+// GLuint id;
+//};
+
+//class QSGCachedTextureReference : public TextureReference
+//{
+//public:
+// ~QSGCachedTextureReference();
+
+// QSGTextureCacheEntry *entry;
+// TextureManagerPrivate *d;
+//};
+
+
+//uint qHash(const QSGTextureCacheKey &key)
+//{
+// return (key.cacheKey >> 32) ^ uint(key.cacheKey) ^ uint(key.hints);
+//}
+
+//class TextureManagerPrivate
+//{
+//public:
+// QHash<QSGTextureCacheKey, QSGTextureCacheEntry *> cache;
+//};
+
+//QSGCachedTextureReference::~QSGCachedTextureReference()
+//{
+// if (!--entry->ref) {
+// d->cache.remove(d->cache.key(entry));
+// glDeleteTextures(1, &entry->id);
+// delete entry;
+// }
+//}
+
+//const QSGTextureRef &TextureManager::requestUploadedTexture(const QImage &image,
+// UploadHints hints,
+// QObject *listener,
+// const char *slot)
+//{
+
+// QSGTextureCacheKey key = { image.cacheKey(), uint(hints) };
+// QSGTextureCacheEntry *entry = d->cache.value(key);
+
+// QSGCachedTextureReference *texture = new QSGCachedTextureReference();
+// QObject::connect(texture, SIGNAL(statusChanged(int)), listener, slot);
+// texture->setTextureSize(image.size());
+// texture->setAlphaChannel(image.hasAlphaChannel());
+// texture->setMipmaps(hints & GenerateMipmapUploadHint);
+
+// if (!entry) {
+// entry = new QSGTextureCacheEntry;
+// entry->id = uploadTexture(image, hints);
+// entry->ref = 1;
+// } else {
+// ++entry->ref;
+// // ### gunnar: this currently does not support the usecase where
+// // the same image is uploaded both as async and as sync...
+// texture->setStatus(TextureReference::Uploaded);
+// }
+
+// texture->setTextureId(entry->id);
+// texture->entry = entry;
+// return texture;
+//}
+
+///*!
+// Performs a synchronous upload of \a image using the specified \a hints.
+
+// The upload is done using the QGLContext::bindTexture().
+// */
+//GLuint TextureManager::uploadTexture(const QImage &image, UploadHints hints)
+//{
+//}