Showing the changes to interface/src/renderer/TextureCache.cpp (1 of 9 files). Show all
Unified · Split
| @@ -5,6 +5,9 @@ · 4 unmodified lines | ||
| 5 | 5 | // Created by Andrzej Kapolka on 8/6/13. |
| 6 | 6 | // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. |
| 7 | 7 | |
| 8 | +// include this before QGLWidget, which includes an earlier version of OpenGL | |
| 9 | +#include "InterfaceConfig.h" | |
| 10 | + | |
| 8 | 11 | #include <QGLWidget> |
| 9 | 12 | #include <QOpenGLFramebufferObject> |
| 10 | 13 | |
| @@ -23,6 +26,7 @@ TextureCache::~TextureCache() { · 12 unmodified lines | ||
| 23 | 26 | } |
| 24 | 27 | if (_primaryFramebufferObject != NULL) { |
| 25 | 28 | delete _primaryFramebufferObject; |
| 29 | + glDeleteTextures(1, &_primaryDepthTextureID); | |
| 26 | 30 | } |
| 27 | 31 | if (_secondaryFramebufferObject != NULL) { |
| 28 | 32 | delete _secondaryFramebufferObject; |
| @@ -60,13 +64,31 @@ GLuint TextureCache::getPermutationNormalTextureID() { · 31 unmodified lines | ||
| 60 | 64 | |
| 61 | 65 | QOpenGLFramebufferObject* TextureCache::getPrimaryFramebufferObject() { |
| 62 | 66 | if (_primaryFramebufferObject == NULL) { |
| 63 | − _primaryFramebufferObject = new QOpenGLFramebufferObject(Application::getInstance()->getGLWidget()->size(), | |
| 64 | − QOpenGLFramebufferObject::Depth); | |
| 67 | + QSize size = Application::getInstance()->getGLWidget()->size(); | |
| 68 | + _primaryFramebufferObject = new QOpenGLFramebufferObject(size); | |
| 65 | 69 | Application::getInstance()->getGLWidget()->installEventFilter(this); |
| 70 | + | |
| 71 | + glGenTextures(1, &_primaryDepthTextureID); | |
| 72 | + glBindTexture(GL_TEXTURE_2D, _primaryDepthTextureID); | |
| 73 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size.width(), size.height(), | |
| 74 | + 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); | |
| 75 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 76 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 77 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 78 | + | |
| 79 | + _primaryFramebufferObject->bind(); | |
| 80 | + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _primaryDepthTextureID, 0); | |
| 81 | + _primaryFramebufferObject->release(); | |
| 66 | 82 | } |
| 67 | 83 | return _primaryFramebufferObject; |
| 68 | 84 | } |
| 69 | 85 | |
| 86 | +GLuint TextureCache::getPrimaryDepthTextureID() { | |
| 87 | + // ensure that the primary framebuffer object is initialized before returning the depth texture id | |
| 88 | + getPrimaryFramebufferObject(); | |
| 89 | + return _primaryDepthTextureID; | |
| 90 | +} | |
| 91 | + | |
| 70 | 92 | QOpenGLFramebufferObject* TextureCache::getSecondaryFramebufferObject() { |
| 71 | 93 | if (_secondaryFramebufferObject == NULL) { |
| 72 | 94 | _secondaryFramebufferObject = new QOpenGLFramebufferObject(Application::getInstance()->getGLWidget()->size()); |
| @@ -89,6 +111,7 @@ bool TextureCache::eventFilter(QObject* watched, QEvent* event) { · 16 unmodified lines | ||
| 89 | 111 | if (_primaryFramebufferObject != NULL && _primaryFramebufferObject->size() != size) { |
| 90 | 112 | delete _primaryFramebufferObject; |
| 91 | 113 | _primaryFramebufferObject = NULL; |
| 114 | + glDeleteTextures(1, &_primaryDepthTextureID); | |
| 92 | 115 | } |
| 93 | 116 | if (_secondaryFramebufferObject != NULL && _secondaryFramebufferObject->size() != size) { |
| 94 | 117 | delete _secondaryFramebufferObject; |