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}::MipLevel Struct Reference

Public Member Functions

mxvk::MXCOLOR sample_bilinear (float u, float v, bool repeat_horizontal) const

Public Attributes

int height = 0
std::vector< mxvk::MXCOLOR > pixels
int width = 0

Detailed Description

Definition at line 62 of file main.cpp.

Member Function Documentation

◆ sample_bilinear()

mxvk::MXCOLOR anonymous_namespace{main.cpp}::MipLevel::sample_bilinear ( float u,
float v,
bool repeat_horizontal ) const
inlinenodiscard

Definition at line 67 of file main.cpp.

67 {
68 u = repeat_horizontal ? u - std::floor(u) : std::clamp(u, 0.0f, 1.0f);
69 v = std::clamp(v, 0.0f, 1.0f);
70 const float texture_x = u * static_cast<float>(repeat_horizontal ? width : width - 1);
71 const float texture_y = v * static_cast<float>(height - 1);
72 const int first_x = static_cast<int>(std::floor(texture_x));
73 const int first_y = static_cast<int>(std::floor(texture_y));
74 const int second_x = repeat_horizontal ? (first_x + 1) % width : std::min(first_x + 1, width - 1);
75 const int second_y = std::min(first_y + 1, height - 1);
76 const float x_fraction = texture_x - static_cast<float>(first_x);
77 const float y_fraction = texture_y - static_cast<float>(first_y);
78 const auto texel = [this](int x, int y) { return pixels[static_cast<std::size_t>(y) * static_cast<std::size_t>(width) + static_cast<std::size_t>(x)]; };
79 const mxvk::MXCOLOR top = interpolate_color(texel(first_x, first_y), texel(second_x, first_y), x_fraction);
80 const mxvk::MXCOLOR bottom = interpolate_color(texel(first_x, second_y), texel(second_x, second_y), x_fraction);
81 return interpolate_color(top, bottom, y_fraction);
82 }
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
std::vector< mxvk::MXCOLOR > pixels
Definition main.cpp:65

Member Data Documentation

◆ height

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

Definition at line 64 of file main.cpp.

◆ pixels

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

Definition at line 65 of file main.cpp.

◆ width

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

Definition at line 63 of file main.cpp.


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