History

Beginnings of ambient occlusion. Looks like an architectural drawing.

Andrzej Kapolka committed 13 years ago

Commit 3ddab481 parent cceeb1c9 files · +160 −19Browse files

Showing the changes to interface/src/renderer/TextureCache.cpp (1 of 9 files). Show all

Unified · Split

interface/src/renderer/TextureCache.cpp+25−2
@@ -5,6 +5,9 @@ · 4 unmodified lines
55 // Created by Andrzej Kapolka on 8/6/13.
66 // Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
77
8+// include this before QGLWidget, which includes an earlier version of OpenGL
9+#include "InterfaceConfig.h"
10+
811 #include <QGLWidget>
912 #include <QOpenGLFramebufferObject>
1013
@@ -23,6 +26,7 @@ TextureCache::~TextureCache() { · 12 unmodified lines
2326 }
2427 if (_primaryFramebufferObject != NULL) {
2528 delete _primaryFramebufferObject;
29+ glDeleteTextures(1, &_primaryDepthTextureID);
2630 }
2731 if (_secondaryFramebufferObject != NULL) {
2832 delete _secondaryFramebufferObject;
@@ -60,13 +64,31 @@ GLuint TextureCache::getPermutationNormalTextureID() { · 31 unmodified lines
6064
6165 QOpenGLFramebufferObject* TextureCache::getPrimaryFramebufferObject() {
6266 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);
6569 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();
6682 }
6783 return _primaryFramebufferObject;
6884 }
6985
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+
7092 QOpenGLFramebufferObject* TextureCache::getSecondaryFramebufferObject() {
7193 if (_secondaryFramebufferObject == NULL) {
7294 _secondaryFramebufferObject = new QOpenGLFramebufferObject(Application::getInstance()->getGLWidget()->size());
@@ -89,6 +111,7 @@ bool TextureCache::eventFilter(QObject* watched, QEvent* event) { · 16 unmodified lines
89111 if (_primaryFramebufferObject != NULL && _primaryFramebufferObject->size() != size) {
90112 delete _primaryFramebufferObject;
91113 _primaryFramebufferObject = NULL;
114+ glDeleteTextures(1, &_primaryDepthTextureID);
92115 }
93116 if (_secondaryFramebufferObject != NULL && _secondaryFramebufferObject->size() != size) {
94117 delete _secondaryFramebufferObject;