$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
texture.h File Reference

Image loading and GPU texture management. More...

#include "gl_common.h"
#include <stdint.h>
Include dependency graph for texture.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  { MAX_TEXTURE_DIMENSION = 8192 }
 

Functions

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...
 

Detailed Description

Image loading and GPU texture management.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MAX_TEXTURE_DIMENSION 

Function Documentation

◆ 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_idPointer to the PBO ID (generated if 0).
current_sizePointer to the currently tracking size (updated on realloc).
required_sizeThe minimum size needed.

◆ texture_generate_hdr_mipmap()

void texture_generate_hdr_mipmap ( GLuint  tex)

Generates mipmaps for an HDR texture.

Parameters
texThe 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
pathFile system path.
[out]widthWidth.
[out]heightHeight.
[out]channelsNumber of color channels.
Returns
Pointer to heap-allocated data. Buffer must be freed by caller.
Here is the call graph for this function:

◆ 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
pathFile 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_idID of the PBO to map.
size_bytesSize 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
widthTexture width.
heightTexture height.
old_texExisting texture ID to check for reuse (0 if none).
Returns
GLuint Pre-allocated texture ID, or 0 on failure.
Here is the call graph for this function:

◆ 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_idID of the PBO (must be bound).
ptrPointer to the mapped PBO memory (will be unmapped).
widthTexture width.
heightTexture height.
reuse_tex_idExisting texture ID to update/reuse.
Returns
GLuint The texture ID (new or reused).
Here is the call graph for this function: