#pragma once #include "pxl8_math.h" #include "pxl8_types.h" #ifdef __cplusplus extern "C" { #endif #define PXL8_MESH_MAX_VERTICES 65536 #define PXL8_MESH_MAX_INDICES 65536 typedef enum pxl8_blend_mode { PXL8_BLEND_OPAQUE = 0, PXL8_BLEND_ALPHA_TEST, PXL8_BLEND_ALPHA, PXL8_BLEND_ADDITIVE, } pxl8_blend_mode; typedef struct pxl8_material { u32 texture_id; u8 alpha; u8 blend_mode; bool dither; bool double_sided; bool dynamic_lighting; bool per_pixel; bool vertex_color_passthrough; f32 emissive_intensity; } pxl8_material; typedef struct pxl8_vertex { pxl8_vec3 position; pxl8_vec3 normal; f32 u, v; u8 color; u8 light; u8 _pad[2]; } pxl8_vertex; typedef struct pxl8_mesh { pxl8_vertex* vertices; u16* indices; u32 vertex_count; u32 index_count; u32 vertex_capacity; u32 index_capacity; } pxl8_mesh; pxl8_mesh* pxl8_mesh_create(u32 vertex_capacity, u32 index_capacity); void pxl8_mesh_destroy(pxl8_mesh* mesh); void pxl8_mesh_clear(pxl8_mesh* mesh); u16 pxl8_mesh_push_vertex(pxl8_mesh* mesh, pxl8_vertex v); void pxl8_mesh_push_triangle(pxl8_mesh* mesh, u16 i0, u16 i1, u16 i2); void pxl8_mesh_push_quad(pxl8_mesh* mesh, u16 i0, u16 i1, u16 i2, u16 i3); void pxl8_mesh_push_box(pxl8_mesh* mesh, pxl8_vec3 center, pxl8_vec3 half_extents, u8 color); void pxl8_mesh_push_box_uv(pxl8_mesh* mesh, pxl8_vec3 center, pxl8_vec3 half_extents, u8 color, f32 u_scale, f32 v_scale); static inline u32 pxl8_mesh_triangle_count(const pxl8_mesh* mesh) { return mesh->index_count / 3; } static inline pxl8_material pxl8_material_create(u32 texture_id) { return (pxl8_material){ .texture_id = texture_id, .alpha = 255, .blend_mode = PXL8_BLEND_OPAQUE, .dither = true, .double_sided = false, .dynamic_lighting = false, .per_pixel = false, .vertex_color_passthrough = false, .emissive_intensity = 0.0f, }; } static inline pxl8_material pxl8_material_with_alpha(pxl8_material m, u8 alpha) { m.alpha = alpha; if (alpha < 255 && m.blend_mode == PXL8_BLEND_OPAQUE) { m.blend_mode = PXL8_BLEND_ALPHA; } return m; } static inline pxl8_material pxl8_material_with_blend(pxl8_material m, pxl8_blend_mode mode) { m.blend_mode = mode; return m; } static inline pxl8_material pxl8_material_with_double_sided(pxl8_material m) { m.double_sided = true; return m; } static inline pxl8_material pxl8_material_with_emissive(pxl8_material m, f32 intensity) { m.emissive_intensity = intensity; return m; } static inline pxl8_material pxl8_material_with_lighting(pxl8_material m) { m.dynamic_lighting = true; return m; } static inline pxl8_material pxl8_material_with_no_dither(pxl8_material m) { m.dither = false; return m; } static inline pxl8_material pxl8_material_with_passthrough(pxl8_material m) { m.vertex_color_passthrough = true; return m; } static inline pxl8_material pxl8_material_with_per_pixel(pxl8_material m) { m.per_pixel = true; return m; } #ifdef __cplusplus } #endif