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
|
#include "drape/texture.hpp"
#include "drape/glextensions_list.hpp"
#include "drape/glfunctions.hpp"
#include "drape/utils/gpu_mem_tracker.hpp"
#include "base/math.hpp"
namespace dp
{
Texture::ResourceInfo::ResourceInfo(m2::RectF const & texRect) : m_texRect(texRect) {}
m2::RectF const & Texture::ResourceInfo::GetTexRect() const { return m_texRect; }
Texture::Texture() {}
Texture::~Texture() { Destroy(); }
void Texture::Create(Params const & params)
{
if (AllocateTexture(params.m_allocator))
m_hwTexture->Create(params);
}
void Texture::Create(Params const & params, ref_ptr<void> data)
{
if (AllocateTexture(params.m_allocator))
m_hwTexture->Create(params, data);
}
void Texture::UploadData(uint32_t x, uint32_t y, uint32_t width, uint32_t height,
ref_ptr<void> data)
{
ASSERT(m_hwTexture != nullptr, ());
m_hwTexture->UploadData(x, y, width, height, data);
}
TextureFormat Texture::GetFormat() const
{
ASSERT(m_hwTexture != nullptr, ());
return m_hwTexture->GetFormat();
}
uint32_t Texture::GetWidth() const
{
ASSERT(m_hwTexture != nullptr, ());
return m_hwTexture->GetWidth();
}
uint32_t Texture::GetHeight() const
{
ASSERT(m_hwTexture != nullptr, ());
return m_hwTexture->GetHeight();
}
float Texture::GetS(uint32_t x) const
{
ASSERT(m_hwTexture != nullptr, ());
return m_hwTexture->GetS(x);
}
float Texture::GetT(uint32_t y) const
{
ASSERT(m_hwTexture != nullptr, ());
return m_hwTexture->GetT(y);
}
uint32_t Texture::GetID() const
{
ASSERT(m_hwTexture != nullptr, ());
return m_hwTexture->GetID();
}
void Texture::Bind() const
{
ASSERT(m_hwTexture != nullptr, ());
m_hwTexture->Bind();
}
void Texture::SetFilter(TextureFilter filter)
{
ASSERT(m_hwTexture != nullptr, ());
m_hwTexture->SetFilter(filter);
}
uint32_t Texture::GetMaxTextureSize()
{
return static_cast<uint32_t>(GLFunctions::glGetInteger(gl_const::GLMaxTextureSize));
}
void Texture::Destroy() { m_hwTexture.reset(); }
bool Texture::AllocateTexture(ref_ptr<HWTextureAllocator> allocator)
{
if (allocator != nullptr)
{
m_hwTexture = allocator->CreateTexture();
return true;
}
return false;
}
} // namespace dp
|