Files
SimpleRayTracing/header/Rendering/Texture.h
Misaki fb1ff5cac6 Update rendering, material handling, and shading logic
Changed README.md to update rendering settings and build instructions.
Changed BSDF.h to add functions for normal unpacking and tangent transformation.
Changed RayIntersection.h to include tangent vector in hit_result_t.
Changed Common.h to include vec2.h for 2D vector handling.
Changed String.h to add string_copy function and improve is_absolute_path.
Changed GeometryUtilities.h to enhance quad creation with tangent calculations.
Changed Mesh.h to include tangents in the vertex structure.
Changed Triangle.h to add tangents in the vertex structure for better normal mapping.
Changed Light.h to include tangents in the light shading context.
Changed SkyLight.h to introduce a new structure for sky lights.
Changed Material.h to include tangents in the shading context.
Changed SimpleLit.h to add normal and tangent textures for detailed shading.
Changed Texture.h to introduce a new structure for texture assets.
Changed BSDF.c to add functions for unpacking normals and transforming tangents.
Changed PathTracing.c to include tangents in the shading context.
Changed RayIntersection.c to calculate normals and tangents in ray-triangle intersections.
Changed Mesh.c to improve material texture loading and handle tangents.
Changed Material.c to enhance material collection initialization and resizing.
Changed SimpleLit.c to incorporate normal mapping with normal textures.
Changed Texture.c to improve management of texture assets and resources.
2025-04-29 17:58:10 +09:00

80 lines
1.6 KiB
C

#ifndef TEXTURE_H
#define TEXTURE_H
#include "cglm/struct/vec4.h"
#include <stdint.h>
#include <stdbool.h>
#define INVALID_TEXTURE_ID UINT16_MAX
typedef enum
{
REPEAT,
CLAMP,
} wrap_mode_t;
typedef enum
{
NEAREST,
LINEAR,
} filter_mode_t;
typedef struct
{
uint32_t width;
uint32_t height;
wrap_mode_t wrap_mode;
filter_mode_t filter_mode;
uint8_t channel_count;
uint8_t* data;
} texture_t;
typedef struct
{
char* full_name;
texture_t texture;
} texture_asset_t;
typedef struct
{
uint16_t count;
uint16_t size;
texture_asset_t* buffer;
} texture_collection_t;
typedef struct
{
uint16_t id;
} texture_entity_t;
bool texture_collection_init(uint16_t size, texture_collection_t* textures);
void texture_collection_resize(texture_collection_t* textures, uint16_t size);
void texture_collection_free(texture_collection_t* textures);
texture_entity_t texture_load(const char* filename, bool srgb, texture_collection_t* textures);
vec4s texture_sample(const texture_t* texture, float u, float v);
void texture_free(texture_t* texture);
inline texture_entity_t invalid_texture_entity()
{
return (texture_entity_t){.id = INVALID_TEXTURE_ID};
}
inline bool is_texture_entity_valid(texture_entity_t entity)
{
return entity.id != INVALID_TEXTURE_ID;
}
inline texture_t* get_texture(const texture_collection_t* textures, texture_entity_t entity)
{
if (entity.id >= textures->count || !is_texture_entity_valid(entity))
{
return NULL;
}
return &textures->buffer[entity.id].texture;
}
#endif // TEXTURE_H