History

Progress towards shadow maps.

Andrzej Kapolka committed 12 years ago

Commit 5cc5d9b1 parent 893eadc9 files · +188 −48Browse files

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

Unified · Split

interface/src/renderer/TextureCache.cpp+29−1
@@ -23,7 +23,8 @@ TextureCache::TextureCache() : · 22 unmodified lines
2323 _blueTextureID(0),
2424 _primaryFramebufferObject(NULL),
2525 _secondaryFramebufferObject(NULL),
26− _tertiaryFramebufferObject(NULL)
26+ _tertiaryFramebufferObject(NULL),
27+ _shadowFramebufferObject(NULL)
2728 {
2829 }
2930
@@ -179,6 +180,33 @@ QOpenGLFramebufferObject* TextureCache::getTertiaryFramebufferObject() { · 149 unmodified lines
179180 return _tertiaryFramebufferObject;
180181 }
181182
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+
182210 bool TextureCache::eventFilter(QObject* watched, QEvent* event) {
183211 if (event->type() == QEvent::Resize) {
184212 QSize size = static_cast<QResizeEvent*>(event)->size();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t