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}::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::MXCOLORpixels
int width = 0

Detailed Description

Definition at line 79 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 84 of file main.cpp.

84 {
85 u = repeat_horizontal ? u - std::floor(u) : std::clamp(u, 0.0f, 1.0f);
86 v = std::clamp(v, 0.0f, 1.0f);
87 const float texture_x = u * static_cast<float>(repeat_horizontal ? width : width - 1);
88 const float texture_y = v * static_cast<float>(height - 1);
89 const int first_x = static_cast<int>(std::floor(texture_x));
90 const int first_y = static_cast<int>(std::floor(texture_y));
91 const int second_x = repeat_horizontal ? (first_x + 1) % width : std::min(first_x + 1, width - 1);
92 const int second_y = std::min(first_y + 1, height - 1);
93 const float x_fraction = texture_x - static_cast<float>(first_x);
94 const float y_fraction = texture_y - static_cast<float>(first_y);
95 const auto texel = [this](int x, int y) {
96 return pixels[static_cast<std::size_t>(y) * static_cast<std::size_t>(width) + static_cast<std::size_t>(x)];
97 };
98 const mxvk::MXCOLOR top = interpolate_color(texel(first_x, first_y), texel(second_x, first_y), x_fraction);
99 const mxvk::MXCOLOR bottom = interpolate_color(texel(first_x, second_y), texel(second_x, second_y), x_fraction);
100 return interpolate_color(top, bottom, y_fraction);
101 }
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
std::vector< mxvk::MXCOLOR > pixels
Definition main.cpp:82

Member Data Documentation

◆ height

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

Definition at line 81 of file main.cpp.

◆ pixels

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

Definition at line 82 of file main.cpp.

◆ width

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

Definition at line 80 of file main.cpp.


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