-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOmniShadowMap.cpp
More file actions
63 lines (45 loc) · 1.97 KB
/
Copy pathOmniShadowMap.cpp
File metadata and controls
63 lines (45 loc) · 1.97 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
57
58
59
60
61
62
63
#include "OmniShadowMap.h"
OmniShadowMap::OmniShadowMap() : ShadowMap()
{
}
bool OmniShadowMap::Init(GLuint width, GLuint height)
{
shadowWidth = width; shadowHeight = height;
glGenFramebuffers(1, &FBO);
glGenTextures(1, &shadowMap);
glBindTexture(GL_TEXTURE_CUBE_MAP, shadowMap);
//go through and set up each parts of the cubemap
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); //the positive x side is the side of our cube on the far left
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GL_LINEAR means when you zoom in to the image, if you zoom in or zoom out of the image, it will try and blend the pixels together
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //GL_TEXTURE_WRAP_S specifies how to handle the image when it's around the border. S refers to the x-axis
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(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); //we are setting these two values to none since we don't wan't to draw or read any sort of color
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); //check for errors
if (status != GL_FRAMEBUFFER_COMPLETE)
{ //If the frame buffer failed
printf("Framebuffer Error: %i\n", status);
return false;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0); //unbind the framebuffer
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()
{
}