-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutline.cpp
114 lines (97 loc) · 3.37 KB
/
Outline.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "Outline.h"
#include "Shader.h"
#include "Object.h"
#include "MeshImporter.h"
#include "ShaderManager.h"
#include "Quad.h"
Outline::Outline(int width, int height)
{
cout << "Create an outline constructor" << endl;
vector<string> outline_shader_paths = { "assets/shaders/Outline.vert", "assets/shaders/Outline.frag" };
ShaderManager::createShader("Outline", outline_shader_paths);
vector<string> mask_shader_paths = { "assets/shaders/Mask.vert", "assets/shaders/Mask.frag" };
ShaderManager::createShader("Mask", mask_shader_paths);
for (int i = 0; i < 4; ++i)
{
m_outline_buffers.push_back(make_unique<FrameBuffer>());
m_outline_buffers.at(i)->createBuffers(width, height);
}
vector<string> debug_shader = { "assets/shaders/Debug.vert", "assets/shaders/Debug.frag" };
ShaderManager::createShader("Debug", debug_shader);
cout << "Outline finish loading" << endl;
cout << endl;
}
Outline::~Outline()
{}
void Outline::setupBuffers(Object& go, const glm::mat4& V, float width, float height)
{
float aspect = width / height;
glm::mat4 P = glm::perspective(glm::radians(45.0f), aspect, 0.1f, 100.0f);
glViewport(0, 0, m_outline_buffers[0]->getWidth(), m_outline_buffers[0]->getHeight());
shared_ptr<Shader> shader = ShaderManager::getShader("Mask");
m_outline_buffers.at(0)->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader->load();
go.drawMesh(P, V, *shader);
m_outline_buffers.at(0)->unbind();
shader = ShaderManager::getShader("Debug");
m_outline_buffers.at(1)->bind();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader->load();
glActiveTexture(GL_TEXTURE0);
m_outline_buffers.at(0)->bindFrameTexture();
Quad::getQuad()->draw();
m_outline_buffers.at(1)->unbind();
shader = ShaderManager::getShader("Outline");
m_outline_buffers.at(2)->bind();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader->load();
glActiveTexture(GL_TEXTURE0);
m_outline_buffers.at(1)->bindFrameTexture();
shader->setInt("outline_map", 0);
shader->setFloat("width", 1400.0f);
shader->setFloat("height", 800.0f);
shader->setInt("pass", 0);
shader->setFloat("jump", 1.0f);
Quad::getQuad()->draw();
m_outline_buffers.at(2)->unbind();
m_outline_buffers.at(3)->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader->load();
glActiveTexture(GL_TEXTURE0);
m_outline_buffers.at(2)->bindFrameTexture();
shader->setInt("outline_map", 0);
shader->setFloat("width", 1400.0f);
shader->setFloat("height", 800.0f);
shader->setInt("pass", 0);
shader->setFloat("jump", 2.0f);
Quad::getQuad()->draw();
m_outline_buffers.at(3)->unbind();
}
void Outline::draw(Object& go)
{
glDisable(GL_DEPTH_TEST);
shared_ptr<Shader> shader = ShaderManager::getShader("Outline");
shader->load();
glActiveTexture(GL_TEXTURE0);
m_outline_buffers.back()->bindFrameTexture();
shader->setInt("outline_map", 0);
glActiveTexture(GL_TEXTURE0 + 1);
m_outline_buffers.at(0)->bindFrameTexture();
shader->setInt("mask_map", 1);
shader->setInt("pass", 2);
Quad::getQuad()->draw();
glEnable(GL_DEPTH_TEST);
}
void Outline::clearOutlineFrame()
{
shared_ptr<Shader> shader = ShaderManager::getShader("Outline");
m_outline_buffers.back()->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader->load();
shader->setInt("pass", 3);
Quad::getQuad()->draw();
m_outline_buffers.back()->unbind();
}