Path Tracing
Loading...
Searching...
No Matches
texture.cpp File Reference
#include "texture.hpp"
#include "stb_image.h"
#include "stb_image_resize2.h"
#include <algorithm>
#include <functional>
Include dependency graph for texture.cpp:

Macros

#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_RESIZE_IMPLEMENTATION

Functions

bool loadEnvMap (const string &path, Renderer &r)
 Loads an HDRI map and uploads it as a GPU texture.
bool packTextureArray (const vector< CPUMaterial > &cpu_materials, vector< GPUMaterial > &gpu_materials, GLuint &out_array, GLenum internal_format, const char *label, std::function< const CPUTextureSlot &(const CPUMaterial &)> get_slot, std::function< void(GPUMaterial &, int)> write_index)
 Packs one texture slot (albedo or normal) across all materials into a single GL_TEXTURE_2D_ARRAY, writing the resolved layer index back to the corresponding GPUMaterial field.
bool uploadTexture (const vector< CPUMaterial > &cpu_materials, vector< GPUMaterial > &gpu_materials, Renderer &r)
 Builds the material texture array from the loaded materials. Uploads every material texture into a GPU texture array, and patches each GPUMaterial::tex_index to point at its layer.

Macro Definition Documentation

◆ STB_IMAGE_IMPLEMENTATION

#define STB_IMAGE_IMPLEMENTATION

◆ STB_IMAGE_RESIZE_IMPLEMENTATION

#define STB_IMAGE_RESIZE_IMPLEMENTATION

Function Documentation

◆ loadEnvMap()

bool loadEnvMap ( const std::string & path,
Renderer & r )

Loads an HDRI map and uploads it as a GPU texture.

Parameters
pathPath to the HDRI file (.hdr, .exr)
rRenderer to pass env map
Returns
true if the image was loaded

◆ packTextureArray()

bool packTextureArray ( const vector< CPUMaterial > & cpu_materials,
vector< GPUMaterial > & gpu_materials,
GLuint & out_array,
GLenum internal_format,
const char * label,
std::function< const CPUTextureSlot &(const CPUMaterial &)> get_slot,
std::function< void(GPUMaterial &, int)> write_index )

Packs one texture slot (albedo or normal) across all materials into a single GL_TEXTURE_2D_ARRAY, writing the resolved layer index back to the corresponding GPUMaterial field.

Note
Previous uploadTexture()
Parameters
get_slotSelects which CPUTextureSlot to read (albedo or normal)
write_indexWrites the resolved layer (or -1) into the right GPUMaterial field
internal_formatGL_SRGB8_ALPHA8 for color data (albedo); GL_RGBA8 for vector-encoded data (normals)
labelShort name used only in log output (ex. "albedo", "normal")

◆ uploadTexture()

bool uploadTexture ( const vector< CPUMaterial > & cpu_materials,
vector< GPUMaterial > & gpu_materials,
Renderer & r )

Builds the material texture array from the loaded materials. Uploads every material texture into a GPU texture array, and patches each GPUMaterial::tex_index to point at its layer.

Todo
Bad handling textures that are not squared (like 128x2048, or 64x512), but forces to be. It's hip to be square
Parameters
cpu_materialsCPU-sided material data, with texture sources
gpu_materialsIn-out GPU material
rendererRenderer to pass the resulting array
Returns
true on success
See also
CPUMaterial, GPUMaterials