forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture.cpp
More file actions
77 lines (66 loc) · 1.79 KB
/
Copy pathTexture.cpp
File metadata and controls
77 lines (66 loc) · 1.79 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
#include "pch.h"
#include "Texture.h"
#include "VulkanRenderer.h"
#include "VulkanTextureBuffer.h"
#include <cstring>
namespace sh::render
{
Texture::Texture(TextureFormat format, uint32_t width, uint32_t height) :
renderer(nullptr),
format(format), width(width), height(height),
bDirty(false)
{
pixels.resize(width * height * 4);
}
Texture::Texture(Texture&& other) noexcept :
renderer(other.renderer),
format(other.format), width(other.width), height(other.height),
pixels(std::move(other.pixels)), buffer(std::move(other.buffer)),
bDirty(other.bDirty)
{
}
Texture::~Texture()
{
}
void Texture::SetPixelData(void* data)
{
std::memcpy(pixels.data(), data, pixels.size());
if (renderer)
Build(*renderer);
}
auto Texture::GetPixelData() const -> const std::vector<Byte>&
{
return pixels;
}
void Texture::Build(Renderer& renderer)
{
this->renderer = &renderer;
if (renderer.apiType == RenderAPI::Vulkan)
{
buffer[core::ThreadType::Game] = std::make_unique<vk::VulkanTextureBuffer>();
buffer[core::ThreadType::Game]->Create(static_cast<const vk::VulkanRenderer&>(renderer), pixels.data(), width, height, format);
buffer[core::ThreadType::Render] = std::make_unique<vk::VulkanTextureBuffer>();
buffer[core::ThreadType::Render]->Create(static_cast<const vk::VulkanRenderer&>(renderer), pixels.data(), width, height, format);
}
SetDirty();
}
auto Texture::GetBuffer(core::ThreadType thr) const -> ITextureBuffer*
{
return buffer[thr].get();
}
void Texture::SetDirty()
{
if (bDirty)
return;
bDirty = true;
if (renderer != nullptr)
renderer->GetThreadSyncManager().PushSyncable(*this);
else
bDirty = false;
}
void Texture::Sync()
{
std::swap(buffer[core::ThreadType::Render], buffer[core::ThreadType::Game]);
bDirty = false;
}
}