History

Removing access to the gl widget and display managers

Brad Davis committed 11 years ago

Commit 302aa9d1 parent 539063035 files · +401 −440Browse files

Showing the changes to libraries/render-utils/src/TextureCache.cpp (1 of 35 files). Show all

Unified · Split

libraries/render-utils/src/TextureCache.cpp+17−26
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <QResizeEvent>
2020 #include <QRunnable>
2121 #include <QThreadPool>
22+#include <QOpenGLContext>
2223
2324 #include <glm/glm.hpp>
2425 #include <glm/gtc/random.hpp>
@@ -32,8 +33,7 @@ TextureCache::TextureCache() : · 7 unmodified lines
3233 _permutationNormalTexture(0),
3334 _whiteTexture(0),
3435 _blueTexture(0),
35− _frameBufferSize(100, 100),
36− _associatedWidget(NULL)
36+ _frameBufferSize(100, 100)
3737 {
3838 const qint64 TEXTURE_DEFAULT_UNUSED_MAX_SIZE = DEFAULT_UNUSED_MAX_SIZE;
3939 setUnusedResourceCacheSize(TEXTURE_DEFAULT_UNUSED_MAX_SIZE);
@@ -290,22 +290,21 @@ GLuint TextureCache::getShadowDepthTextureID() { · 250 unmodified lines
290290 return gpu::GLBackend::getTextureID(_shadowTexture);
291291 }
292292
293−bool TextureCache::eventFilter(QObject* watched, QEvent* event) {
294− if (event->type() == QEvent::Resize) {
295− QSize size = static_cast<QResizeEvent*>(event)->size();
296− if (_frameBufferSize != size) {
297− _primaryFramebuffer.reset();
298− _primaryColorTexture.reset();
299− _primaryDepthTexture.reset();
300− _primaryNormalTexture.reset();
301− _primarySpecularTexture.reset();
302−
303− _secondaryFramebuffer.reset();
304−
305− _tertiaryFramebuffer.reset();
306− }
307− }
308− return false;
293+/// Returns a texture version of an image file
294+gpu::TexturePointer TextureCache::getImageTexture(const QString & path) {
295+ QImage image(path);
296+ gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB);
297+ gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB);
298+ if (image.hasAlphaChannel()) {
299+ formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA);
300+ formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, gpu::BGRA);
301+ }
302+ gpu::TexturePointer texture = gpu::TexturePointer(
303+ gpu::Texture::create2D(formatGPU, image.width(), image.height(),
304+ gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
305+ texture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
306+ texture->autoGenerateMips(-1);
307+ return texture;
309308 }
310309
311310 QSharedPointer<Resource> TextureCache::createResource(const QUrl& url,
@@ -315,14 +314,6 @@ QSharedPointer<Resource> TextureCache::createResource(const QUrl& url, · 3 unmodified lines
315314 &Resource::allReferencesCleared);
316315 }
317316
318−void TextureCache::associateWithWidget(QGLWidget* widget) {
319− if (_associatedWidget) {
320− _associatedWidget->removeEventFilter(this);
321− }
322− _associatedWidget = widget;
323− _associatedWidget->installEventFilter(this);
324−}
325−
326317 Texture::Texture() {
327318 }
328319