Showing the changes to libraries/render-utils/src/TextureCache.cpp (1 of 35 files). Show all
Unified · Split
| @@ -19,6 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | #include <QResizeEvent> |
| 20 | 20 | #include <QRunnable> |
| 21 | 21 | #include <QThreadPool> |
| 22 | +#include <QOpenGLContext> | |
| 22 | 23 | |
| 23 | 24 | #include <glm/glm.hpp> |
| 24 | 25 | #include <glm/gtc/random.hpp> |
| @@ -32,8 +33,7 @@ TextureCache::TextureCache() : · 7 unmodified lines | ||
| 32 | 33 | _permutationNormalTexture(0), |
| 33 | 34 | _whiteTexture(0), |
| 34 | 35 | _blueTexture(0), |
| 35 | − _frameBufferSize(100, 100), | |
| 36 | − _associatedWidget(NULL) | |
| 36 | + _frameBufferSize(100, 100) | |
| 37 | 37 | { |
| 38 | 38 | const qint64 TEXTURE_DEFAULT_UNUSED_MAX_SIZE = DEFAULT_UNUSED_MAX_SIZE; |
| 39 | 39 | setUnusedResourceCacheSize(TEXTURE_DEFAULT_UNUSED_MAX_SIZE); |
| @@ -290,22 +290,21 @@ GLuint TextureCache::getShadowDepthTextureID() { · 250 unmodified lines | ||
| 290 | 290 | return gpu::GLBackend::getTextureID(_shadowTexture); |
| 291 | 291 | } |
| 292 | 292 | |
| 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; | |
| 309 | 308 | } |
| 310 | 309 | |
| 311 | 310 | QSharedPointer<Resource> TextureCache::createResource(const QUrl& url, |
| @@ -315,14 +314,6 @@ QSharedPointer<Resource> TextureCache::createResource(const QUrl& url, · 3 unmodified lines | ||
| 315 | 314 | &Resource::allReferencesCleared); |
| 316 | 315 | } |
| 317 | 316 | |
| 318 | −void TextureCache::associateWithWidget(QGLWidget* widget) { | |
| 319 | − if (_associatedWidget) { | |
| 320 | − _associatedWidget->removeEventFilter(this); | |
| 321 | − } | |
| 322 | − _associatedWidget = widget; | |
| 323 | − _associatedWidget->installEventFilter(this); | |
| 324 | −} | |
| 325 | − | |
| 326 | 317 | Texture::Texture() { |
| 327 | 318 | } |
| 328 | 319 | |