-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdebug_drawable.cpp
117 lines (101 loc) · 3.68 KB
/
debug_drawable.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
115
116
117
// Copyright (C) 2020-2024 Sami Väisänen
// Copyright (C) 2020-2024 Ensisoft http://www.ensisoft.com
//
// This program 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, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
#include "base/format.h"
#include "graphics/debug_drawable.h"
#include "graphics/shader_source.h"
#include "graphics/program.h"
#include "graphics/geometry.h"
namespace gfx
{
void DebugDrawableBase::ApplyDynamicState(const Environment& env, ProgramState& program, RasterState& state) const
{
mDrawable->ApplyDynamicState(env, program, state);
}
ShaderSource DebugDrawableBase::GetShader(const Environment& env, const Device& device) const
{
return mDrawable->GetShader(env, device);
}
std::string DebugDrawableBase::GetShaderId(const Environment& env) const
{
return mDrawable->GetShaderId(env);
}
std::string DebugDrawableBase::GetShaderName(const Environment& env) const
{
return mDrawable->GetShaderName(env);
}
std::string DebugDrawableBase::GetGeometryId(const Environment& env) const
{
const auto normals = mFlags.test(Flags::Normals);
const auto tangents = mFlags.test(Flags::Tangents);
const auto bitangents = mFlags.test(Flags::Bitangents);
std::string id;
id += mDrawable->GetGeometryId(env);
id += base::ToString(mFeature);
id += normals ? "Normals" : "";
id += tangents ? "Tangents" : "";
id += bitangents ? "Bitangents" : "";
return id;
}
bool DebugDrawableBase::Construct(const Environment& env, Geometry::CreateArgs& create) const
{
if (mDrawable->GetDrawPrimitive() != DrawPrimitive::Triangles)
{
return mDrawable->Construct(env, create);
}
Geometry::CreateArgs temp;
if (!mDrawable->Construct(env, temp))
return false;
if (!temp.buffer.HasData())
return false;
if (mFeature == Feature::Wireframe)
{
GeometryBuffer wireframe;
CreateWireframe(temp.buffer, wireframe);
create.buffer = std::move(wireframe);
create.content_name = "Wireframe/" + temp.content_name;
create.content_hash = temp.content_hash;
}
else if (mFeature == Feature::NormalMesh)
{
const auto normals = mFlags.test(Flags::Normals);
const auto tangents = mFlags.test(Flags::Tangents);
const auto bitangents = mFlags.test(Flags::Bitangents);
unsigned flags = 0;
if (normals) flags |= NormalMeshFlags::Normals;
if (tangents) flags |= NormalMeshFlags::Tangents;
if (bitangents) flags |= NormalMeshFlags::Bitangents;
GeometryBuffer buffer;
if (!CreateNormalMesh(temp.buffer, buffer, flags))
return false;
create.buffer = std::move(buffer);
create.content_name = base::FormatString("%1%2%3Mesh/%4",
normals ? "Normal" : "",
tangents ? "Tangent" : "",
bitangents ? "Bitangent" : "",
temp.content_name);
create.content_hash = temp.content_hash;
}
return true;
}
Drawable::Usage DebugDrawableBase::GetGeometryUsage() const
{
return mDrawable->GetGeometryUsage();
}
size_t DebugDrawableBase::GetGeometryHash() const
{
return mDrawable->GetGeometryHash();
}
} // namespace