Showing the changes to interface/src/renderer/TextureCache.cpp (1 of 9 files). Show all
Unified · Split
| @@ -23,7 +23,8 @@ TextureCache::TextureCache() : · 22 unmodified lines | |||
| 23 | _blueTextureID(0), | 23 | _blueTextureID(0), |
| 24 | _primaryFramebufferObject(NULL), | 24 | _primaryFramebufferObject(NULL), |
| 25 | _secondaryFramebufferObject(NULL), | 25 | _secondaryFramebufferObject(NULL), |
| 26 | _tertiaryFramebufferObject(NULL) | 26 | _tertiaryFramebufferObject(NULL), |
| 27 | _shadowFramebufferObject(NULL) | ||
| 27 | { | 28 | { |
| 28 | } | 29 | } |
| 29 | 30 | ||
| @@ -179,6 +180,33 @@ QOpenGLFramebufferObject* TextureCache::getTertiaryFramebufferObject() { · 149 unmodified lines | |||
| 179 | return _tertiaryFramebufferObject; | 180 | return _tertiaryFramebufferObject; |
| 180 | } | 181 | } |
| 181 | 182 | ||
| 183 | QOpenGLFramebufferObject* TextureCache::getShadowFramebufferObject() { | ||
| 184 | if (_shadowFramebufferObject == NULL) { | ||
| 185 | const int SHADOW_MAP_SIZE = 1024; | ||
| 186 | _shadowFramebufferObject = new QOpenGLFramebufferObject(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, | ||
| 187 | QOpenGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RGB); | ||
| 188 | |||
| 189 | glGenTextures(1, &_shadowDepthTextureID); | ||
| 190 | glBindTexture(GL_TEXTURE_2D, _shadowDepthTextureID); | ||
| 191 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, | ||
| 192 | 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); | ||
| 193 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||
| 194 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
| 195 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 196 | |||
| 197 | _shadowFramebufferObject->bind(); | ||
| 198 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _shadowDepthTextureID, 0); | ||
| 199 | _shadowFramebufferObject->release(); | ||
| 200 | } | ||
| 201 | return _shadowFramebufferObject; | ||
| 202 | } | ||
| 203 | |||
| 204 | GLuint TextureCache::getShadowDepthTextureID() { | ||
| 205 | // ensure that the shadow framebuffer object is initialized before returning the depth texture id | ||
| 206 | getShadowFramebufferObject(); | ||
| 207 | return _shadowDepthTextureID; | ||
| 208 | } | ||
| 209 | |||
| 182 | bool TextureCache::eventFilter(QObject* watched, QEvent* event) { | 210 | bool TextureCache::eventFilter(QObject* watched, QEvent* event) { |
| 183 | if (event->type() == QEvent::Resize) { | 211 | if (event->type() == QEvent::Resize) { |
| 184 | QSize size = static_cast<QResizeEvent*>(event)->size(); | 212 | QSize size = static_cast<QResizeEvent*>(event)->size(); |