-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshadowbuffer.cpp
More file actions
58 lines (43 loc) · 1.19 KB
/
shadowbuffer.cpp
File metadata and controls
58 lines (43 loc) · 1.19 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
#include "stdafx.h"
#include "shadowbuffer.h"
#include "drawable.h"
ShadowBuffer::ShadowBuffer()
{
m_FBO = ~0u;
}
ShadowBuffer::~ShadowBuffer(){}
bool ShadowBuffer::initialise(bool mainShadowBuffer)
{
if (!m_shader.load("Shaders/shadow.vert", "Shaders/shadow.frag"))
return false;
if (!m_texture.create(1024, 1024, Enum::GPU, Enum::DEPTH_COMPONENT,
{ { GL_TEXTURE_MIN_FILTER, GL_NEAREST }, { GL_TEXTURE_MAG_FILTER, GL_NEAREST } }, Enum::FLOAT, Enum::DEPTH32))
return false;
glGenFramebuffers(1, &m_FBO);
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
m_texture.bindForGPU();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_TEXTURE_2D, m_texture.id(), 0);
unsigned status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
{
Error(std::string("Could not create gbuffer. Error status ") + toString(status));
return false;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (mainShadowBuffer)
setAsGlobalShadowBuffer();
return true;
}
void ShadowBuffer::bind()
{
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
m_shader.set();
}
void ShadowBuffer::setAsGlobalShadowBuffer()
{
Drawable::s_shadowShader = &m_shader;
}
void ShadowBuffer::shutdown()
{
}