/
adddynamicshadow.cpp
71 lines (61 loc) · 2.23 KB
/
adddynamicshadow.cpp
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
64
65
66
67
68
69
70
71
// Copyright 2012-2013 The Ephenation Authors
//
// This file is part of Ephenation.
//
// Ephenation is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// Ephenation is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Ephenation. If not, see <http://www.gnu.org/licenses/>.
//
#include <glbinding/gl/functions33.h>
#include <stdio.h>
#include <stdlib.h>
#include <glm/glm.hpp>
#include "../primitives.h"
#include "adddynamicshadow.h"
#include "../ui/Error.h"
#include "../Options.h"
#include "../uniformbuffer.h"
#include "../shadowconfig.h"
#include "../shapes/quad.h"
#include "../contrib/glsw.h"
using namespace gl33;
/// Using GLSW to define shader
static const GLchar *vertexShaderSource[] = {
"dynamicshadow.Vertex"
};
/// Using GLSW to define shader
static const GLchar *fragmentShaderSource[] = {
"common.UniformBuffer",
"common.DoubleResolutionFunction",
"common.SunDirection",
"dynamicshadow.Fragment"
};
AddDynamicShadow::AddDynamicShadow() {
fShadowMapMatrixIdx = -1;
}
void AddDynamicShadow::Init(void) {
const GLsizei vertexShaderLines = sizeof(vertexShaderSource) / sizeof(GLchar*);
const GLsizei fragmentShaderLines = sizeof(fragmentShaderSource) / sizeof(GLchar*);
ShaderBase::Initglsw("AddDynamicShadow", vertexShaderLines, vertexShaderSource, fragmentShaderLines, fragmentShaderSource);
}
void AddDynamicShadow::GetLocations(void) {
fShadowMapMatrixIdx = this->GetUniformLocation("shadowmat");
// The followig uniforms only need to be initialized once
glUniform1i(this->GetUniformLocation("shadowmapTex"), 4); // The shadow map has to use GL_TEXTURE4
glUniform1i(this->GetUniformLocation("normalTex"), 2);
glUniform1i(this->GetUniformLocation("posTex"), 1);
}
void AddDynamicShadow::Draw(const glm::mat4 &mat) {
glUseProgram(this->Program());
glUniformMatrix4fv(fShadowMapMatrixIdx, 1, GL_FALSE, &mat[0][0]);
gQuad.Draw();
glUseProgram(0);
}