-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOmniShadowMap.cpp
More file actions
52 lines (38 loc) · 1.57 KB
/
OmniShadowMap.cpp
File metadata and controls
52 lines (38 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "OmniShadowMap.h"
OmniShadowMap::OmniShadowMap() : ShadowMap() {}
bool OmniShadowMap::init(unsigned int width, unsigned int height) {
shadowWidth = width;
shadowHeight = height;
glGenFramebuffers(1, &FBO);
glGenTextures(1, &shadowMap);
glBindTexture(GL_TEXTURE_CUBE_MAP, shadowMap);
for (size_t i = 0; i < 6; i++) {
// GL_TEXTURE_CUBE_MAP_POSITIVE_.. X, Y, Z are right after each other so this works
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, shadowWidth, shadowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
}
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowMap, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (Status != GL_FRAMEBUFFER_COMPLETE)
{
printf("Framebuffer error: %s\n", Status);
return false;
}
return true;
}
void OmniShadowMap::write() {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FBO);
}
void OmniShadowMap::read(GLenum texUnit) {
glActiveTexture(texUnit);
glBindTexture(GL_TEXTURE_CUBE_MAP, shadowMap);
}
OmniShadowMap::~OmniShadowMap() {
}