![]() |
Blamite Game Engine - blam!
00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
|
#include "components/rendering/rendering.h"#include <bx/allocator.h>#include "api/v1/types/tags/classes/bitmap.h"#include "components/diagnostics/logger/logger.h"#include "components/rendering/bgfx/texture_storage.h"
Include dependency graph for bitmaps.cpp:Classes | |
| struct | bgfx_texture_info_data |
| Data structure used to group together information about a texture. More... | |
Functions | |
| bgfx::TextureFormat::Enum | determine_gpu_pixel_format (bitmap::format_enum tag_format) |
| Converts a bitmap pixel format enum value to the equivalent bgfx pixel format. More... | |
| bgfx_texture_info_data * | create_default_color_texture (uint32_t color) |
| uint32_t | compute_sampler_flags_from_bitmap (bitmap *bitmap_tag) |
| Determines sampler flags from a bitmap tag. More... | |
| float | srgb_to_linear (float srgb_value) |
| Converts a single sRGB-encoded color channel value to linear space. More... | |
| float | linear_to_srgb (float linear_value) |
| Converts a single linear-space color channel value to sRGB encoding. More... | |
| void | downsample_mip_2x2 (const uint8_t *source, int source_width, int source_height, uint8_t *destination, int destination_width, int destination_height, bool treat_as_srgb) |
| Generates the next mip level for an RGBA8 texture by averaging 2x2 pixel blocks. More... | |
| int | compute_mip_count (int width, int height) |
| Computes the number of mip levels for a 2D texture of the given dimensions. More... | |
| int | compute_mip_chain_size_rgba8 (int base_width, int base_height) |
| Computes the total byte count required to hold a complete mip chain for an RGBA8 texture of the given base dimensions. More... | |
| const bgfx::Memory * | build_mip_chain_rgba8 (const void *base_pixel_data, int base_width, int base_height, bool treat_as_srgb) |
| Builds the complete mip chain for an RGBA8 texture and packages it as a bgfx::Memory pointer ready to pass to bgfx::createTexture2D. More... | |
Variables | |
| bgfx::TextureHandle | default_texture = BGFX_INVALID_HANDLE |
| bgfx::TextureHandle | fallback_white = BGFX_INVALID_HANDLE |
| bgfx::TextureHandle | fallback_normal = BGFX_INVALID_HANDLE |
| bgfx::TextureHandle | fallback_metal_rough = BGFX_INVALID_HANDLE |
| bgfx::TextureHandle | fallback_gray_50 = BGFX_INVALID_HANDLE |
| std::unordered_map< std::string, bgfx_texture_info_data * > | bgfx_texture_map = std::unordered_map<std::string, bgfx_texture_info_data*>() |
| Map containing information on all loaded textures. More... | |
| const bgfx::Memory* build_mip_chain_rgba8 | ( | const void * | base_pixel_data, |
| int | base_width, | ||
| int | base_height, | ||
| bool | treat_as_srgb | ||
| ) |
Builds the complete mip chain for an RGBA8 texture and packages it as a bgfx::Memory pointer ready to pass to bgfx::createTexture2D.
Allocates a single bgfx-managed buffer sized for the entire chain, copies the provided base data into the mip 0 region, then iteratively downsamples each subsequent mip from the previous one using a 2x2 box filter. The output is packed in the layout bgfx expects (mip 0 first, followed by each subsequent mip contiguously).
| base_pixel_data | - Pointer to the source mip 0 data (RGBA8, tightly packed). |
| base_width | - Width of the base texture in pixels. |
| base_height | - Height of the base texture in pixels. |
| treat_as_srgb | - Whether downsampling should be gamma-correct for color textures. |
Here is the call graph for this function:
Here is the caller graph for this function:| int compute_mip_chain_size_rgba8 | ( | int | base_width, |
| int | base_height | ||
| ) |
Computes the total byte count required to hold a complete mip chain for an RGBA8 texture of the given base dimensions.
The mip chain follows the standard "halve each dimension, minimum 1" rule and terminates when both dimensions reach 1. Each mip's contribution is its width * height * 4 bytes.
| base_width | - Width of mip 0 in pixels. |
| base_height | - Height of mip 0 in pixels. |
Here is the caller graph for this function:| int compute_mip_count | ( | int | width, |
| int | height | ||
| ) |
Computes the number of mip levels for a 2D texture of the given dimensions.
The mip count is determined by the largest dimension, halved repeatedly until it reaches 1. The base level (mip 0) is always counted, so this returns at least 1.
| width | - Width of the base texture in pixels. |
| height | - Height of the base texture in pixels. |
Determines sampler flags from a bitmap tag.
This will determine the sampler flags for this bitmap based on the filtering modes for this bitmap tag.
| bitmap_tag | - The bitmap tag to determine sampler flags for. |
0 if the tag was nullptr.
Here is the caller graph for this function:| bgfx_texture_info_data* create_default_color_texture | ( | uint32_t | color | ) |
Here is the caller graph for this function:| bgfx::TextureFormat::Enum determine_gpu_pixel_format | ( | bitmap::format_enum | tag_format | ) |
Converts a bitmap pixel format enum value to the equivalent bgfx pixel format.
| tag_format | - The bitmap pixel format value to convert. |
bgfx::TextureFormat::Unknown is returned.
Here is the caller graph for this function:| void downsample_mip_2x2 | ( | const uint8_t * | source, |
| int | source_width, | ||
| int | source_height, | ||
| uint8_t * | destination, | ||
| int | destination_width, | ||
| int | destination_height, | ||
| bool | treat_as_srgb | ||
| ) |
Generates the next mip level for an RGBA8 texture by averaging 2x2 pixel blocks.
When sRGB correctness is requested, the color channels (RGB) are converted to linear space before averaging and converted back to sRGB afterward. This avoids the brightness-shift artifact that occurs when sRGB-encoded values are averaged directly. Alpha is always averaged in raw bytes since it isn't gamma encoded. Source data is sampled with edge-clamp behavior so non-power-of-two dimensions are handled correctly.
| source | - Pointer to the source mip's pixel buffer (RGBA8, tightly packed). |
| source_width | - Width in pixels of the source buffer. |
| source_height | - Height in pixels of the source buffer. |
| destination | - Pointer to the destination buffer to write the new mip into. |
| destination_width | - Width in pixels of the destination buffer. |
| destination_height | - Height in pixels of the destination buffer. |
| treat_as_srgb | - If true, RGB channels go through gamma-correct averaging. |
Here is the call graph for this function:
Here is the caller graph for this function:| float linear_to_srgb | ( | float | linear_value | ) |
Converts a single linear-space color channel value to sRGB encoding.
The inverse of srgb_to_linear. Used after averaging color values in linear space to produce a result that's correctly gamma-encoded for storage in an sRGB texture.
| linear_value | - The linear-space value, normalized to the [0, 1] range. |
Here is the caller graph for this function:| float srgb_to_linear | ( | float | srgb_value | ) |
Converts a single sRGB-encoded color channel value to linear space.
Uses the proper piecewise transform from the sRGB specification rather than the gamma-2.2 approximation. The piecewise version handles values near black more accurately - the gamma curve goes flat in that region and a pure power function would produce slightly wrong results.
| srgb_value | - The sRGB-encoded value, normalized to the [0, 1] range. |
Here is the caller graph for this function:| std::unordered_map<std::string, bgfx_texture_info_data*> bgfx_texture_map = std::unordered_map<std::string, bgfx_texture_info_data*>() |
Map containing information on all loaded textures.
Each key contains the tag path of the texture's bitmap tag, and each value stores the texture information structure.
| bgfx::TextureHandle default_texture = BGFX_INVALID_HANDLE |
| bgfx::TextureHandle fallback_gray_50 = BGFX_INVALID_HANDLE |
| bgfx::TextureHandle fallback_metal_rough = BGFX_INVALID_HANDLE |
| bgfx::TextureHandle fallback_normal = BGFX_INVALID_HANDLE |
| bgfx::TextureHandle fallback_white = BGFX_INVALID_HANDLE |