2021-11-30 21:29:18 -06:00
# ifndef TEXTURE_H
# define TEXTURE_H
2023-05-04 17:07:00 -05:00
# include "sokol/sokol_gfx.h"
2023-11-14 09:20:09 -06:00
# include "HandmadeMath.h"
2024-09-15 12:22:45 -05:00
# include "render.h"
2024-10-20 08:28:13 -05:00
# include "stb_rect_pack.h"
2024-10-05 08:43:51 -05:00
2024-09-15 12:22:45 -05:00
# include "sokol_app.h"
# include "sokol/util/sokol_imgui.h"
2022-02-06 10:14:57 -06:00
# define TEX_SPEC 0
# define TEX_NORM 1
# define TEX_HEIGHT 2
# define TEX_DIFF 3
2024-01-14 10:24:31 -06:00
# define FILTER_NEAREST SG_FILTER_NEAREST
# define FILTER_NONE SG_FILTER_NONE
# define FILTER_LINEAR SG_FILTER_LINEAR
2024-03-13 03:51:44 -05:00
extern struct rect ST_UNIT ;
2021-11-30 21:29:18 -06:00
2023-01-18 14:43:07 -06:00
/* Represents an actual texture on the GPU */
2024-03-13 03:51:44 -05:00
struct texture {
2024-09-15 12:22:45 -05:00
sg_image id ; /* ID reference for the GPU memory location of the texture */
2024-01-14 10:24:31 -06:00
int width ;
int height ;
2024-10-03 23:35:40 -05:00
HMM_Vec3 dimensions ;
2024-01-14 10:24:31 -06:00
unsigned char * data ;
2024-09-29 06:10:42 -05:00
int vram ;
2021-11-30 21:29:18 -06:00
} ;
2024-03-13 03:51:44 -05:00
typedef struct texture texture ;
2024-01-14 10:24:31 -06:00
typedef struct img_sampler {
int wrap_u ;
int wrap_v ;
int wrap_w ;
int min_filter ;
int mag_filter ;
int mip_filter ;
} img_sampler ;
2023-12-29 19:08:53 -06:00
2024-03-21 21:07:24 -05:00
texture * texture_from_file ( const char * path ) ;
2024-10-01 16:50:06 -05:00
texture * texture_fromdata ( void * raw , long size ) ;
texture * texture_empty ( int width , int height ) ; // Make an empty texture
texture * texture_dup ( texture * tex ) ; // return an identical texture
texture * texture_scale ( texture * tex , int width , int height ) ; // dup and scale the texture
2024-03-13 03:51:44 -05:00
void texture_free ( texture * tex ) ;
2024-10-01 16:50:06 -05:00
void texture_offload ( texture * tex ) ; // Remove the data from this texture
void texture_load_gpu ( texture * tex ) ; // Upload this data to the GPU if it isn't already there. Replace it if it is.
2022-12-24 13:18:06 -06:00
2024-10-01 16:50:06 -05:00
int texture_write_pixel ( texture * tex , int x , int y , struct rgba color ) ;
2024-10-01 17:57:05 -05:00
int texture_fill ( texture * tex , struct rgba color ) ;
int texture_fill_rect ( texture * tex , struct rect rect , struct rgba color ) ;
2024-10-01 16:50:06 -05:00
int texture_blit ( texture * dst , texture * src , struct rect dstrect , struct rect srcrect , int tile ) ; // copies src into dst, using their respective squares, scaling if necessary
int texture_flip ( texture * tex , int y ) ;
void texture_save ( texture * tex , const char * file ) ; // save the texture data to the given file
2024-01-02 07:55:22 -06:00
2021-11-30 21:29:18 -06:00
# endif