MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
example Namespace Reference

Namespaces

namespace  anonymous_namespace{example.cpp}
namespace  anonymous_namespace{matrix.cpp}
namespace  anonymous_namespace{planet.cpp}

Classes

class  BinaryMatrixWindow
class  ConsoleDemoWindow
class  DarkWindow
class  ExampleWindow
class  FireWindow
class  FireworksWindow
class  FractalWindow
class  GlitchCubeWindow
class  MasterPieceWindow
class  Math3DCubeWindow
class  Math3DModelLoaderWindow
class  Math3DPongWindow
class  Math3DPyramidWindow
class  Math3DTextureArrayWindow
class  Math3DTextureWindow
class  Math3DWindow
class  MatrixRainBackdrop
class  MatrixWindow
class  ModelWindow
class  MoonWindow
class  OpenCVModelWindow
class  PlanetWindow
class  PointSpriteWindow
class  PostprocessWindow
struct  PyramidPlacement
class  SnowEffect3D
struct  SnowFlake
class  StarfieldWindow
struct  StarParticle
class  StarshipWindow
class  StaticWindow
class  StencilWindow
struct  SurfaceDeleter
class  TicTacToeWindow
class  WaterWindow

Typedefs

using Clock = std::chrono::steady_clock

Functions

std::string joinPath (const std::string &base, const std::string &file)
SDL_Surface * loadColorKeyedPNG (const std::string &path, std::uint8_t threshold=12, std::uint8_t softness=48)
std::string resolveShaderEntry (const std::string &shader_path, const std::string &entry)
std::string trimLine (const std::string &text)

Typedef Documentation

◆ Clock

using example::Clock = std::chrono::steady_clock

Definition at line 27 of file planet.cpp.

Function Documentation

◆ joinPath()

std::string example::joinPath ( const std::string & base,
const std::string & file )
nodiscard

Definition at line 51 of file shaders.cpp.

51 {
52 const std::filesystem::path file_path(file);
53 if (base.empty() || file_path.is_absolute()) {
54 return file_path.string();
55 }
56 return (std::filesystem::path(base) / file_path).string();
57 }

◆ loadColorKeyedPNG()

SDL_Surface * example::loadColorKeyedPNG ( const std::string & path,
std::uint8_t threshold = 12,
std::uint8_t softness = 48 )

Definition at line 45 of file moon.cpp.

45 {
46 SDL_Surface *loaded_surface = mxvk::LoadPNG(path.c_str());
47 if (loaded_surface == nullptr) {
48 throw mxvk::Exception("Failed to load PNG: " + path);
49 }
50
51 SDL_Surface *surface = SDL_ConvertSurface(loaded_surface, SDL_PIXELFORMAT_RGBA32);
52 SDL_DestroySurface(loaded_surface);
53 if (surface == nullptr) {
54 throw mxvk::Exception("Failed to convert PNG to RGBA: " + path);
55 }
56
57 const SDL_PixelFormatDetails *format_details = SDL_GetPixelFormatDetails(surface->format);
58 if (format_details == nullptr) {
59 SDL_DestroySurface(surface);
60 throw mxvk::Exception("Failed to query pixel format details for: " + path);
61 }
62
63 if (!SDL_LockSurface(surface)) {
64 SDL_DestroySurface(surface);
65 throw mxvk::Exception("Failed to lock PNG surface: " + path);
66 }
67
68 auto *pixels = static_cast<std::uint32_t *>(surface->pixels);
69 const int pixel_count = surface->w * surface->h;
70 for (int i = 0; i < pixel_count; ++i) {
71 std::uint8_t r = 0;
72 std::uint8_t g = 0;
73 std::uint8_t b = 0;
74 std::uint8_t a = 0;
75 SDL_GetRGBA(pixels[i], format_details, nullptr, &r, &g, &b, &a);
76
77 const int brightness = std::max({static_cast<int>(r), static_cast<int>(g), static_cast<int>(b)});
78 if (brightness <= threshold) {
79 a = 0;
80 } else if (brightness < static_cast<int>(threshold) + static_cast<int>(softness)) {
81 const float fade = static_cast<float>(brightness - threshold) / static_cast<float>(std::max<int>(1, softness));
82 a = static_cast<std::uint8_t>(std::clamp(static_cast<int>(std::lround(static_cast<float>(a) * fade)), 0, 255));
83 }
84
85 pixels[i] = SDL_MapRGBA(format_details, nullptr, r, g, b, a);
86 }
87
88 SDL_UnlockSurface(surface);
89 return surface;
90 }
SDL_Surface * LoadPNG(const char *file)
Load a PNG file into an SDL_Surface.
Definition mxvk_png.cpp:103

◆ resolveShaderEntry()

std::string example::resolveShaderEntry ( const std::string & shader_path,
const std::string & entry )
nodiscard

Definition at line 59 of file shaders.cpp.

59 {
60 const std::filesystem::path entry_path(entry);
61 if (entry_path.extension() == ".spv") {
62 return joinPath(shader_path, entry);
63 }
64
65 std::filesystem::path spv_entry = entry_path.parent_path() / "spv" / entry_path.stem();
66 spv_entry.replace_extension(".spv");
67 const std::filesystem::path spv_path = std::filesystem::path(shader_path) / spv_entry;
68 if (std::filesystem::exists(spv_path)) {
69 return spv_path.string();
70 }
71
72 std::filesystem::path sibling_entry = entry_path;
73 sibling_entry.replace_extension(".spv");
74 const std::filesystem::path sibling_spv_path = std::filesystem::path(shader_path) / sibling_entry;
75 if (std::filesystem::exists(sibling_spv_path)) {
76 return sibling_spv_path.string();
77 }
78
79 return joinPath(shader_path, entry);
80 }
std::string joinPath(const std::string &base, const std::string &file)
Definition shaders.cpp:51

◆ trimLine()

std::string example::trimLine ( const std::string & text)
nodiscard

Definition at line 37 of file shaders.cpp.

37 {
38 auto begin = text.begin();
39 while (begin != text.end() && std::isspace(static_cast<unsigned char>(*begin)) != 0) {
40 ++begin;
41 }
42
43 auto end = text.end();
44 while (end != begin && std::isspace(static_cast<unsigned char>(*(end - 1))) != 0) {
45 --end;
46 }
47
48 return std::string(begin, end);
49 }