MXVK Vulkan Framework 0.35.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
anonymous_namespace{main.cpp}::Texture Struct Reference

Public Member Functions

bool empty () const
int height () const
mxvk::MXCOLOR sample (float u, float v) const
mxvk::MXCOLOR sample (float u, float v) const
mxvk::MXCOLOR sample (float u, float v, float level, bool repeat_horizontal) const
mxvk::MXCOLOR sample_filtered (float u, float v, float lod) const
mxvk::MXCOLOR sample_nearest (float u, float v) const
mxvk::MXCOLOR sample_nearest (float u, float v) const
int width () const

Public Attributes

int height = 0
std::vector< MipLevel > levels
std::vector< TextureLevel > mipmaps
std::vector< mxvk::MXCOLOR > pixels
int width = 0

Detailed Description

Definition at line 85 of file main.cpp.

Member Function Documentation

◆ empty()

bool anonymous_namespace{main.cpp}::Texture::empty ( ) const
inlinenodiscard

Definition at line 88 of file main.cpp.

88{ return levels.empty() || levels.front().width <= 0 || levels.front().height <= 0 || levels.front().pixels.empty(); }
std::vector< MipLevel > levels
Definition main.cpp:86

◆ height()

int anonymous_namespace{main.cpp}::Texture::height ( ) const
inlinenodiscard

Definition at line 92 of file main.cpp.

92{ return empty() ? 0 : levels.front().height; }

◆ sample() [1/3]

mxvk::MXCOLOR anonymous_namespace{main.cpp}::Texture::sample ( float u,
float v ) const
inlinenodiscard

Definition at line 45 of file main.cpp.

45 {
46 if (width <= 0 || height <= 0 || pixels.empty()) {
47 return mxvk::MXVK_RGB(255, 255, 255);
48 }
49
50 u = std::clamp(u, 0.0f, 1.0f);
51 v = std::clamp(v, 0.0f, 1.0f);
52 const int x = std::clamp(static_cast<int>(u * static_cast<float>(width - 1) + 0.5f), 0, width - 1);
53 const int y = std::clamp(static_cast<int>(v * static_cast<float>(height - 1) + 0.5f), 0, height - 1);
54 return pixels[static_cast<std::size_t>(y * width + x)];
55 }
constexpr MXCOLOR MXVK_RGB(int r, int g, int b)
Build an opaque ARGB color from red, green, and blue components.
Definition mxvk_math.h:49
std::vector< mxvk::MXCOLOR > pixels
Definition main.cpp:191

◆ sample() [2/3]

mxvk::MXCOLOR anonymous_namespace{main.cpp}::Texture::sample ( float u,
float v ) const
inlinenodiscard

Definition at line 45 of file main.cpp.

45 {
46 if (width <= 0 || height <= 0 || pixels.empty()) {
47 return mxvk::MXVK_RGB(255, 255, 255);
48 }
49
50 u = std::clamp(u, 0.0f, 1.0f);
51 v = std::clamp(v, 0.0f, 1.0f);
52 const int x = std::clamp(static_cast<int>(u * static_cast<float>(width - 1) + 0.5f), 0, width - 1);
53 const int y = std::clamp(static_cast<int>(v * static_cast<float>(height - 1) + 0.5f), 0, height - 1);
54 return pixels[static_cast<std::size_t>(y * width + x)];
55 }

◆ sample() [3/3]

mxvk::MXCOLOR anonymous_namespace{main.cpp}::Texture::sample ( float u,
float v,
float level,
bool repeat_horizontal ) const
inlinenodiscard

Definition at line 94 of file main.cpp.

94 {
95 level = std::clamp(level, 0.0f, static_cast<float>(levels.size() - 1));
96 const std::size_t first_level = static_cast<std::size_t>(std::floor(level));
97 const std::size_t second_level = std::min(first_level + 1, levels.size() - 1);
98 const float fraction = level - static_cast<float>(first_level);
99 const mxvk::MXCOLOR first_color = levels[first_level].sample_bilinear(u, v, repeat_horizontal);
100 if (first_level == second_level) {
101 return first_color;
102 }
103 return interpolate_color(first_color, levels[second_level].sample_bilinear(u, v, repeat_horizontal), fraction);
104 }
mxvk::MXCOLOR interpolate_color(mxvk::MXCOLOR first, mxvk::MXCOLOR second, float fraction)
Definition main.cpp:55
std::uint32_t MXCOLOR
Packed 32-bit color in ARGB byte order.
Definition mxvk_math.h:40

◆ sample_filtered()

mxvk::MXCOLOR anonymous_namespace{main.cpp}::Texture::sample_filtered ( float u,
float v,
float lod ) const
inlinenodiscard

Definition at line 194 of file main.cpp.

194 {
195 const float clamped_lod = std::clamp(lod, 0.0f, static_cast<float>(mipmaps.size()));
196 const int first_level = static_cast<int>(std::floor(clamped_lod));
197 const int second_level = std::min(first_level + 1, static_cast<int>(mipmaps.size()));
198 const float blend = clamped_lod - static_cast<float>(first_level);
199 const mxvk::MXCOLOR first = sample_bilinear(first_level, u, v);
200 const mxvk::MXCOLOR second = sample_bilinear(second_level, u, v);
201 return blend_color(first, second, blend);
202 }
std::vector< TextureLevel > mipmaps
Definition main.cpp:192

◆ sample_nearest() [1/2]

mxvk::MXCOLOR anonymous_namespace{main.cpp}::Texture::sample_nearest ( float u,
float v ) const
inlinenodiscard

Definition at line 57 of file main.cpp.

57 {
58 u = std::clamp(u, 0.0f, 1.0f);
59 v = std::clamp(v, 0.0f, 1.0f);
60 const int x = static_cast<int>(u * static_cast<float>(width - 1) + 0.5f);
61 const int y = static_cast<int>(v * static_cast<float>(height - 1) + 0.5f);
62 return pixels[static_cast<std::size_t>(y * width + x)];
63 }

◆ sample_nearest() [2/2]

mxvk::MXCOLOR anonymous_namespace{main.cpp}::Texture::sample_nearest ( float u,
float v ) const
inlinenodiscard

Definition at line 57 of file main.cpp.

57 {
58 u = std::clamp(u, 0.0f, 1.0f);
59 v = std::clamp(v, 0.0f, 1.0f);
60 const int x = static_cast<int>(u * static_cast<float>(width - 1) + 0.5f);
61 const int y = static_cast<int>(v * static_cast<float>(height - 1) + 0.5f);
62 return pixels[static_cast<std::size_t>(y * width + x)];
63 }

◆ width()

int anonymous_namespace{main.cpp}::Texture::width ( ) const
inlinenodiscard

Definition at line 90 of file main.cpp.

90{ return empty() ? 0 : levels.front().width; }

Member Data Documentation

◆ height

int anonymous_namespace{main.cpp}::Texture::height = 0

Definition at line 190 of file main.cpp.

◆ levels

std::vector<MipLevel> anonymous_namespace{main.cpp}::Texture::levels

Definition at line 86 of file main.cpp.

◆ mipmaps

std::vector<TextureLevel> anonymous_namespace{main.cpp}::Texture::mipmaps

Definition at line 192 of file main.cpp.

◆ pixels

std::vector< mxvk::MXCOLOR > anonymous_namespace{main.cpp}::Texture::pixels

Definition at line 191 of file main.cpp.

◆ width

int anonymous_namespace{main.cpp}::Texture::width = 0

Definition at line 189 of file main.cpp.


The documentation for this struct was generated from the following files: