-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOmniShadowMap.cpp
More file actions
executable file
·56 lines (42 loc) · 1.45 KB
/
OmniShadowMap.cpp
File metadata and controls
executable file
·56 lines (42 loc) · 1.45 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
53
54
55
56
#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)
{
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, shadowWidth, shadowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
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: %i\n", Status);
return false;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
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()
{
}