$darkmode
#include "texture.h"#include "gl_common.h"#include "io.h"#include "log.h"#include "profiler.h"#include "utils.h"#include <math.h>#include <stb_image.h>#include <stddef.h>#include <stdio.h>Enumerations | |
| enum | { MAX_TEXTURE_FILE_SIZE = 64 * 1024 * 1024 } |
Functions | |
| float * | texture_load_pixels (const char *path, int *width, int *height, int *channels) |
| Decodes an HDR image into RAM without uploading to GPU. More... | |
| void | texture_ensure_pbo (GLuint *pbo_id, GLsizeiptr *current_size, GLsizeiptr required_size) |
| Ensures a PBO is allocated with sufficient size. More... | |
| void * | texture_map_pbo (GLuint pbo_id, size_t size_bytes) |
| Maps a PBO for writing. More... | |
| static bool | texture_matches_hdr (int width, int height) |
| Check if an existing texture matches the expected HDR format. More... | |
| GLuint | texture_preallocate_hdr (int width, int height, GLuint old_tex) |
| Pre-allocates VRAM for an HDR texture (glTexStorage2D only). More... | |
| static GLuint | texture_reuse_or_create_hdr (int width, int height, GLuint reuse_tex_id, bool *is_reused, int *levels_out) |
| static bool | texture_allocate_storage_hdr (int width, int height, int levels) |
| GLuint | texture_upload_hdr_from_pbo (GLuint pbo_id, void *ptr, int width, int height, GLuint reuse_tex_id) |
| Finalizes HDR upload from a PBO (Unmap -> Upload -> Mipmaps). More... | |
| void | texture_generate_hdr_mipmap (GLuint tex) |
| Generates mipmaps for an HDR texture. More... | |
| GLuint | texture_load_rgba_png (const char *path) |
| Loads a PNG image from disk and creates an OpenGL RGBA texture. More... | |
Variables | |
| static const uint32_t | TRACY_COLOR_TEXTURE_UPLOAD = 0xAAAA55 |
| static const uint32_t | TRACY_COLOR_TEXTURE_STORAGE = 0xAA55AA |
| static const uint32_t | TRACY_COLOR_MIPMAP_GEN = 0x55AAAA |
| static const uint32_t | TRACY_COLOR_TEXTURE_UPLOAD_FULL = 0xFF8800 |
|
static |
| void texture_ensure_pbo | ( | GLuint * | pbo_id, |
| GLsizeiptr * | current_size, | ||
| GLsizeiptr | required_size | ||
| ) |
Ensures a PBO is allocated with sufficient size.
Checks if internal *current_size is >= required_size. If not, reallocates (orphans) the buffer using glBufferData.
| pbo_id | Pointer to the PBO ID (generated if 0). |
| current_size | Pointer to the currently tracking size (updated on realloc). |
| required_size | The minimum size needed. |
| void texture_generate_hdr_mipmap | ( | GLuint | tex | ) |
Generates mipmaps for an HDR texture.
| tex | The OpenGL ID of the texture. |
| float* texture_load_pixels | ( | const char * | path, |
| int * | width, | ||
| int * | height, | ||
| int * | channels | ||
| ) |
Decodes an HDR image into RAM without uploading to GPU.
Useful for asynchronous loading or CPU-side processing.
| path | File system path. | |
| [out] | width | Width. |
| [out] | height | Height. |
| [out] | channels | Number of color channels. |
| GLuint texture_load_rgba_png | ( | const char * | path | ) |
Loads a PNG image from disk and creates an OpenGL RGBA texture.
| path | File system path to the PNG image. |
| void* texture_map_pbo | ( | GLuint | pbo_id, |
| size_t | size_bytes | ||
| ) |
Maps a PBO for writing.
| pbo_id | ID of the PBO to map. |
| size_bytes | Size to map (should match creation size). |
|
static |
Check if an existing texture matches the expected HDR format.
Queries GL state for the texture's level-0 dimensions and internal format. The texture must already be bound to GL_TEXTURE_2D before calling.
| GLuint texture_preallocate_hdr | ( | int | width, |
| int | height, | ||
| GLuint | old_tex | ||
| ) |
Pre-allocates VRAM for an HDR texture (glTexStorage2D only).
Call this early (e.g. when async loader requests a PBO) to spread the cost of texture allocation across frames. If old_tex already matches the requested dimensions, it is returned as-is (zero-cost reuse).
| width | Texture width. |
| height | Texture height. |
| old_tex | Existing texture ID to check for reuse (0 if none). |
|
static |
| GLuint texture_upload_hdr_from_pbo | ( | GLuint | pbo_id, |
| void * | ptr, | ||
| int | width, | ||
| int | height, | ||
| GLuint | reuse_tex_id | ||
| ) |
Finalizes HDR upload from a PBO (Unmap -> Upload -> Mipmaps).
| pbo_id | ID of the PBO (must be bound). |
| ptr | Pointer to the mapped PBO memory (will be unmapped). |
| width | Texture width. |
| height | Texture height. |
| reuse_tex_id | Existing texture ID to update/reuse. |
|
static |
|
static |
|
static |
|
static |