diff options
Diffstat (limited to 'src/adaptationlayers/mactexturemanager.cpp')
-rw-r--r-- | src/adaptationlayers/mactexturemanager.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/adaptationlayers/mactexturemanager.cpp b/src/adaptationlayers/mactexturemanager.cpp new file mode 100644 index 0000000..dec66c6 --- /dev/null +++ b/src/adaptationlayers/mactexturemanager.cpp @@ -0,0 +1,47 @@ +#include "mactexturemanager.h" + +/*! + Since we are using client storage which means asynchronous DMA + uploads, we need to keep the bits around for the duration + of the texture id. So we keep the image in along in the reference + */ +class QSGMacTextureReference : public TextureReference +{ +public: + QImage image; +}; + + +QSGMacTextureManager::QSGMacTextureManager() +{ +} + + +const TextureReference *QSGMacTextureManager::requestUploadedTexture(const QImage &image, UploadHints hints, QObject *listener, const char *slot) +{ + // Client storage will most likely fail when mipmapping is used.. + if (hints & TextureManager::GenerateMipmapUploadHint) + return TextureManager::requestUploadedTexture(image, hints, listener, slot); + + GLuint id; + glGenTextures(1, &id); + glBindTexture(GL_TEXTURE_2D, id); + + glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_SHARED_APPLE); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_BGRA, + GL_UNSIGNED_INT_8_8_8_8_REV, image.constBits()); + + glBindTexture(GL_TEXTURE_2D, 0); + + QSGMacTextureReference *texture = new QSGMacTextureReference; + texture->image = image; + texture->setTextureId(id); + texture->setTextureSize(image.size()); + texture->setStatus(TextureReference::Uploaded); + + return texture; +} |