MXVK Vulkan Framework 0.24.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< MipLevellevels
std::vector< TextureLevelmipmaps
std::vector< mxvk::MXCOLORpixels
int width = 0

Detailed Description

Definition at line 104 of file main.cpp.

Member Function Documentation

◆ empty()

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

Definition at line 107 of file main.cpp.

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

◆ height()

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

Definition at line 115 of file main.cpp.

115 {
116 return empty() ? 0 : levels.front().height;
117 }

◆ sample() [1/3]

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

Definition at line 47 of file main.cpp.

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

◆ sample() [2/3]

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

Definition at line 47 of file main.cpp.

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

◆ 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 119 of file main.cpp.

119 {
120 level = std::clamp(level, 0.0f, static_cast<float>(levels.size() - 1));
121 const std::size_t first_level = static_cast<std::size_t>(std::floor(level));
122 const std::size_t second_level = std::min(first_level + 1, levels.size() - 1);
123 const float fraction = level - static_cast<float>(first_level);
124 const mxvk::MXCOLOR first_color = levels[first_level].sample_bilinear(u, v, repeat_horizontal);
125 if (first_level == second_level) {
126 return first_color;
127 }
128 return interpolate_color(first_color, levels[second_level].sample_bilinear(u, v, repeat_horizontal), fraction);
129 }
mxvk::MXCOLOR interpolate_color(mxvk::MXCOLOR first, mxvk::MXCOLOR second, float fraction)
Definition main.cpp:62
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 202 of file main.cpp.

202 {
203 const float clamped_lod = std::clamp(lod, 0.0f, static_cast<float>(mipmaps.size()));
204 const int first_level = static_cast<int>(std::floor(clamped_lod));
205 const int second_level = std::min(first_level + 1, static_cast<int>(mipmaps.size()));
206 const float blend = clamped_lod - static_cast<float>(first_level);
207 const mxvk::MXCOLOR first = sample_bilinear(first_level, u, v);
208 const mxvk::MXCOLOR second = sample_bilinear(second_level, u, v);
209 return blend_color(first, second, blend);
210 }
std::vector< TextureLevel > mipmaps
Definition main.cpp:200

◆ sample_nearest() [1/2]

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

Definition at line 59 of file main.cpp.

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

◆ sample_nearest() [2/2]

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

Definition at line 59 of file main.cpp.

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

◆ width()

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

Definition at line 111 of file main.cpp.

111 {
112 return empty() ? 0 : levels.front().width;
113 }

Member Data Documentation

◆ height

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

Definition at line 198 of file main.cpp.

◆ levels

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

Definition at line 105 of file main.cpp.

◆ mipmaps

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

Definition at line 200 of file main.cpp.

◆ pixels

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

Definition at line 199 of file main.cpp.

◆ width

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

Definition at line 197 of file main.cpp.


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