LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_textures.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2024
3  * All rights reserved
4  */
5 
6 #ifndef LG_TEXTURES_H
7 #define LG_TEXTURES_H
8 
9 #define LG_TEX_PATH_MAX_LEN (512 - 1)
10 
11 #define LG_FIRST_NODE_ID 500001
12 #define LG_INVALID_TEXTURE_ID 500002
13 
14 #define LG_TEX_TYPE_UNKNOWN (-1)
15 
16 #define LG_MAX_TEX_UNITS 256
17 
18 #define LG_CUBEMAP_FACES_NUM 6
19 
20 typedef struct __attribute__((packed)) {
21  uint8_t sig[8]; /* {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a} */
22  uint8_t padding1[8];
23  uint32_t width; /* Big-endian */
24  uint32_t height; /* Big-endian */
25 } PNG_Header;
26 
27 /* TODO: specify if mipmaps were generated ? */
28 typedef enum {
29  LG_TC_UNCOMPRESSED, /* Never with mipmaps */
30  LG_TC_DXT1,
31  LG_TC_DXT3,
32  LG_TC_ASTC, /* TODO: specify block size ? */
33  LG_TC_ETC1,
34  LG_TC_UNKNOWN
35 } lg_tc_format;
36 
37 /*
38  * Actually a texture node in textures doubly-linked list
39  */
40 typedef struct LG_Texture LG_Texture;
41 
42 struct LG_Texture {
43  GLuint id; /* Texture 'handle', set to LG_INVALID_TEXTURE_ID if not valid */
44  GLenum unit; /* GL_TEXTURE0 -> GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1 */
45  int type; /* GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP (so far ...) */
46  int w;
47  int h;
48  int tc_format; /* lg_tc_format enum */
49  char path[LG_TEX_PATH_MAX_LEN + 1];
50  LG_Texture *prev;
51  LG_Texture *next;
52 };
53 
55 
56 LG_Texture *lg_texture_new_from_data(lg_tc_format, int, const char *, void *, void **, size_t, int, int, int);
57 
58 LG_Texture *lg_texture_new_from_file(int, const char *);
59 
60 SDL_Surface *lg_sdl_surf_from_file(const char *, int, int);
61 
62 void *lg_compressed_texdata_from_file(const char *, lg_tc_format *, size_t *, int *, int *, int *);
63 
64 zboolean lg_test_file_extension(const char *, const char*);
65 
66 int lg_get_png_dims(const char *, int *, int *);
67 /*
68  * === Doubly-linked list ops ===
69  */
71 
73 
75 
77 
79 
81 
82 void lg_texture_info(const LG_Texture *);
83 
84 void lg_texture_info_all();
85 
86 void lg_texture_list_all();
87 /*
88  * Other stuff
89  */
90 zboolean lg_read_pixels_from_screen(void *, Rec2Di);
91 
92 zboolean lg_write_pixels_to_screen(void *, const Rec2Di *);
93 
94 void lg_texture_unbind();
95 
96 void lg_tex_units_info();
97 
98 unsigned int lg_get_active_tex();
99 
100 void lg_active_tex_info();
101 
102 void lg_free_sdl_surf(SDL_Surface *);
103 
104 int lg_surf_depth(SDL_Surface *);
105 
107 
108 #endif /* LG_TEXTURES_H */
lg_get_active_tex
unsigned int lg_get_active_tex()
Definition: lg_textures.c:1065
lg_info_out_read_framebuffer
void lg_info_out_read_framebuffer()
Definition: lg_textures.c:1108
lg_compressed_texdata_from_file
void * lg_compressed_texdata_from_file(const char *path, lg_tc_format *tc_format, size_t *size, int *w, int *h, int *n_mipmaps)
Definition: lg_textures.c:571
lg_texture_new_from_data
LG_Texture * lg_texture_new_from_data(lg_tc_format tc_format, int tex_type, const char *path, void *data, void **cubemap_data, size_t size, int w, int h, int n_mipmaps)
Definition: lg_textures.c:127
lg_texture_count_nodes
int lg_texture_count_nodes()
Definition: lg_textures.c:869
lg_tex_units_info
void lg_tex_units_info()
Definition: lg_textures.c:1050
lg_texture_info_all
void lg_texture_info_all()
Definition: lg_textures.c:913
lg_texture_find_by_id
LG_Texture * lg_texture_find_by_id(GLuint id)
Definition: lg_textures.c:851
lg_surf_depth
int lg_surf_depth(SDL_Surface *surf)
Definition: lg_textures.c:1100
lg_texture_new_from_file
LG_Texture * lg_texture_new_from_file(int tex_type, const char *path)
Definition: lg_textures.c:299
lg_read_pixels_from_screen
zboolean lg_read_pixels_from_screen(void *pixels, Rec2Di r)
Definition: lg_textures.c:951
lg_test_file_extension
zboolean lg_test_file_extension(const char *path, const char *ext)
Definition: lg_textures.c:594
lg_texture_info
void lg_texture_info(const LG_Texture *tex)
Definition: lg_textures.c:904
lg_texture_unbind
void lg_texture_unbind(LG_Texture *tex)
Definition: lg_textures.c:1037
lg_sdl_surf_from_file
SDL_Surface * lg_sdl_surf_from_file(const char *path, int scale_x, int scale_y)
Definition: lg_textures.c:467
lg_write_pixels_to_screen
zboolean lg_write_pixels_to_screen(void *pixels, const Rec2Di *dest)
Definition: lg_textures.c:979
lg_active_tex_info
void lg_active_tex_info()
Definition: lg_textures.c:1077
lg_texture_remove_all
void lg_texture_remove_all()
Definition: lg_textures.c:799
LG_Texture
Definition: lg_textures.h:42
lg_texture_last
LG_Texture * lg_texture_last(LG_Texture *node)
Definition: lg_textures.c:834
PNG_Header
Definition: lg_textures.h:20
lg_init_textures_module
void lg_init_textures_module()
Definition: lg_textures.c:88
lg_texture_list_all
void lg_texture_list_all()
Definition: lg_textures.c:928
lg_free_sdl_surf
void lg_free_sdl_surf(SDL_Surface *surf)
Definition: lg_textures.c:1087
lg_texture_first
LG_Texture * lg_texture_first(LG_Texture *node)
Definition: lg_textures.c:817
lg_get_png_dims
int lg_get_png_dims(const char *path, int *w, int *h)
Definition: lg_textures.c:608
lg_texture_remove
void lg_texture_remove(LG_Texture *node)
Definition: lg_textures.c:768
Rec2Di
Definition: lg_gr_func.h:47