Image loading and GPU texture management.
More...
#include "gl_common.h"
#include <stdint.h>
Go to the source code of this file.
|
| 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...
|
| |
| GLuint | texture_preallocate_hdr (int width, int height, GLuint old_tex) |
| | Pre-allocates VRAM for an HDR texture (glTexStorage2D only). More...
|
| |
| 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...
|
| |
| float * | texture_load_pixels (const char *path, int *width, int *height, int *channels) |
| | Decodes an HDR image into RAM without uploading to GPU. More...
|
| |
| GLuint | texture_load_rgba_png (const char *path) |
| | Loads a PNG image from disk and creates an OpenGL RGBA texture. More...
|
| |
Image loading and GPU texture management.
◆ anonymous enum
| Enumerator |
|---|
| MAX_TEXTURE_DIMENSION | |
◆ texture_ensure_pbo()
| 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.
- Parameters
-
| 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. |
◆ texture_generate_hdr_mipmap()
| void texture_generate_hdr_mipmap |
( |
GLuint |
tex | ) |
|
Generates mipmaps for an HDR texture.
- Parameters
-
| tex | The OpenGL ID of the texture. |
◆ texture_load_pixels()
| 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.
- Parameters
-
| path | File system path. |
| [out] | width | Width. |
| [out] | height | Height. |
| [out] | channels | Number of color channels. |
- Returns
- Pointer to heap-allocated data. Buffer must be freed by caller.
◆ texture_load_rgba_png()
| GLuint texture_load_rgba_png |
( |
const char * |
path | ) |
|
Loads a PNG image from disk and creates an OpenGL RGBA texture.
- Parameters
-
| path | File system path to the PNG image. |
- Returns
- GLuint The OpenGL texture ID, or 0 on failure.
◆ texture_map_pbo()
| void* texture_map_pbo |
( |
GLuint |
pbo_id, |
|
|
size_t |
size_bytes |
|
) |
| |
Maps a PBO for writing.
- Parameters
-
| pbo_id | ID of the PBO to map. |
| size_bytes | Size to map (should match creation size). |
- Returns
- Pointer to mapped memory, or NULL on failure.
◆ texture_preallocate_hdr()
| 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).
- Parameters
-
| width | Texture width. |
| height | Texture height. |
| old_tex | Existing texture ID to check for reuse (0 if none). |
- Returns
- GLuint Pre-allocated texture ID, or 0 on failure.
◆ texture_upload_hdr_from_pbo()
| 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).
- Parameters
-
| 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. |
- Returns
- GLuint The texture ID (new or reused).