-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHTMLDrawableElement.cpp
More file actions
118 lines (91 loc) · 4.07 KB
/
HTMLDrawableElement.cpp
File metadata and controls
118 lines (91 loc) · 4.07 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
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
118
//
// Created by Monika on 02.10.2024.
//
#include <Graphics/Render/HTML/HTMLDrawableElement.h>
namespace SR_GRAPH_NS {
/*HTMLDrawableElement::~HTMLDrawableElement() {
SetShader(nullptr);
SetTexture(nullptr);
auto&& uboManager = SR_GRAPH_NS::Memory::UBOManager::Instance();
auto&& descriptorManager = SR_GRAPH_NS::DescriptorManager::Instance();
if (m_virtualUBO != SR_ID_INVALID && !uboManager.FreeUBO(&m_virtualUBO)) {
SR_ERROR("HTMLDrawableElement::~HTMLDrawableElement() : failed to free virtual uniform buffer object!");
}
if (m_virtualDescriptor != SR_ID_INVALID) {
descriptorManager.FreeDescriptorSet(&m_virtualDescriptor);
}
}
void HTMLDrawableElement::SetShader(SR_GTYPES_NS::Shader::Ptr pShader) {
m_dirtyMaterial |= m_pShader != pShader;
m_pShader = pShader;
}
void HTMLDrawableElement::SetTexture(SR_GTYPES_NS::Texture::Ptr pTexture) {
if (m_pTexture == pTexture) {
return;
}
if (m_pTexture) {
m_pTexture->RemoveUsePoint();
}
if ((m_pTexture = pTexture)) {
pTexture->AddUsePoint();
}
m_dirtyMaterial = true;
}
HTMLRendererUpdateResult HTMLDrawableElement::Update(const HTMLRendererUpdateContext& context) {
HTMLRendererUpdateResult result;
if (m_virtualUBO == SR_ID_INVALID) SR_UNLIKELY_ATTRIBUTE {
SRHalt("HTMLDrawableElement::Update() : virtual UBO is invalid!");
return result;
}
m_pipeline->SetCurrentShader(m_pShader);
auto&& uboManager = SR_GRAPH_NS::Memory::UBOManager::Instance();
if (uboManager.BindNoDublicateUBO(m_virtualUBO) != Memory::UBOManager::BindResult::Success) SR_UNLIKELY_ATTRIBUTE {
return result;
}
auto&& pNode = m_pPage->GetNodeById(m_nodeId);
auto&& style = pNode->GetStyle();
SR_MATH_NS::FVector2 position = context.offset;
position.x = position.x + context.size.x;
position.y = -position.y - context.size.y;
position = SR_MATH_NS::FVector2(-1, 1) + (position / context.resolution);
m_pShader->SetVec2("position"_atom_hash, position);
m_pShader->SetVec2("size"_atom_hash, context.size / context.resolution);
if (style.backgroundColor.colorType == SR_UTILS_NS::Web::CSSColor::ColorType::RGBA) {
m_pShader->SetVec4("backgroundColor"_atom_hash, style.backgroundColor.color.ToFColor());
//m_pShader->SetVec4("backgroundColor"_atom_hash, SR_MATH_NS::FColor::Cyan());
}
SR_MAYBE_UNUSED_VAR m_pShader->Flush();
return result;
}
const SR_UTILS_NS::Web::CSSStyle& HTMLDrawableElement::GetStyle() const {
return m_pPage->GetNodeById(m_nodeId)->GetStyle();
}
void HTMLDrawableElement::Draw() {
SR_TRACY_ZONE;
auto&& uboManager = SR_GRAPH_NS::Memory::UBOManager::Instance();
auto&& descriptorManager = SR_GRAPH_NS::DescriptorManager::Instance();
if (m_dirtyMaterial) SR_UNLIKELY_ATTRIBUTE {
m_virtualUBO = uboManager.AllocateUBO(m_virtualUBO);
if (m_virtualUBO == SR_ID_INVALID) SR_UNLIKELY_ATTRIBUTE {
return;
}
m_virtualDescriptor = descriptorManager.AllocateDescriptorSet(m_virtualDescriptor);
}
uboManager.BindUBO(m_virtualUBO);
const auto result = descriptorManager.Bind(m_virtualDescriptor);
if (m_pipeline->GetCurrentBuildIteration() == 0) {
if (result == DescriptorManager::BindResult::Duplicated || m_dirtyMaterial) SR_UNLIKELY_ATTRIBUTE {
if (m_pTexture) {
m_pShader->SetSampler2D("image"_atom, m_pTexture);
}
m_pShader->FlushSamplers();
descriptorManager.Flush();
}
m_pipeline->GetCurrentShader()->FlushConstants();
}
if (result != DescriptorManager::BindResult::Failed) SR_UNLIKELY_ATTRIBUTE {
m_pipeline->Draw(4);
}
m_dirtyMaterial = false;
}*/
}