LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_shader_progs.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  */
5 
6 #ifndef LG_SHADER_PROGS_H
7 #define LG_SHADER_PROGS_H
8 
9 #define LG_INVALID_SHADER_PROG_ID 500000
10 
11 typedef struct {
12  unsigned int id;
14 
15 /* Uniform locations */
16 typedef struct {
17  int world_m;
18  int view_m;
19  int proj_m;
20  int view_proj_m;
21  int model_view_m; /* Or world_view_m */
22  int model_view_proj_m; /* Or world_view_proj_m or MVP_matrix */
23  int texcoords;
24  int light_type;
25  int light_pos;
26  int light_dir;
27  int light_color;
28  int luminosity_k;
30 
31 /* Vertex Attrib Pointer params */
32 typedef struct {
33  int32_t index;
34  const char *attrib_name;
35  uint32_t num_components; /* 1 to 4 */
36  int32_t type; /* One of GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FIXED, GL_FLOAT */
37  zboolean do_normalize;
38  size_t stride; /* Byte offset between consecutive generic vertex attributes */
39  void *first_component_offset; /* For instance: offsetof(Vertex_uv_n, u) */
41 
42 #define VAP_END {-1, NULL, 0, 0, 0, 0, NULL}
43 
44 #define CHECK_GL_E lg_check_gl_errors(lg_log_time(), __FILE__ , __LINE__, __func__)
45 
46 #define CHECK_GL_E_2 {if (lg_check_gl_errors(lg_log_time(), __FILE__, __LINE__, __func__) != LG_OK) exit(-1);}
47 
48 #define STH_WRONG_HERE \
49  { \
50  static int i = 0; \
51  if (i == 0) { \
52  INFO_OUT("VARO TÄSSÄ\n%s [%s: %d] %s(): jotain pitää korjata\n", UTF8_RW_ROUNDED_ARROW, __FILE__, __LINE__, __func__) \
53  i++; \
54  } \
55  }
56 
57 LG_ShaderProg LG_ShaderProg_create(const char **, const char **, LG_VAP_params *);
58 
60 
61 void LG_ShaderProg_use(LG_ShaderProg *, zboolean);
62 
63 int LG_ShaderProg_get_attrib_loc(LG_ShaderProg *, const char *);
64 
65 int LG_ShaderProg_get_uniform_loc(LG_ShaderProg *, const char *);
66 
67 uint32_t lg_load_shader(int, const char **);
68 
69 int lg_check_gl_errors(long long, const char *, int, const char *);
70 
71 void lg_shader_info_log(uint32_t);
72 
73 #endif /* LG_SHADER_PROGS_H */
LG_VAP_params
Definition: lg_shader_progs.h:32
lg_check_gl_errors
int lg_check_gl_errors(long long log_time, const char *file, int line, const char *func)
Definition: lg_shader_progs.c:286
LG_ShaderProg
Definition: lg_shader_progs.h:11
LG_ShaderULocs
Definition: lg_shader_progs.h:16
LG_ShaderProg_get_attrib_loc
int LG_ShaderProg_get_attrib_loc(LG_ShaderProg *shader_prog, const char *attrib_name)
Definition: lg_shader_progs.c:209
LG_ShaderProg_get_uniform_loc
int LG_ShaderProg_get_uniform_loc(LG_ShaderProg *shader_prog, const char *uniform_name)
Definition: lg_shader_progs.c:237
lg_shader_info_log
void lg_shader_info_log(uint32_t shader)
Definition: lg_shader_progs.c:320
LG_ShaderProg_create
LG_ShaderProg LG_ShaderProg_create(const char **vertex_shader_code, const char **fragment_shader_code, LG_VAP_params *params)
Definition: lg_shader_progs.c:63
LG_ShaderProg_use
void LG_ShaderProg_use(LG_ShaderProg *shader_prog, zboolean gl_checking)
Definition: lg_shader_progs.c:182
lg_load_shader
uint32_t lg_load_shader(int type, const char **shader_code)
Definition: lg_shader_progs.c:256
LG_ShaderProg_delete
void LG_ShaderProg_delete(LG_ShaderProg *shader_prog)
Definition: lg_shader_progs.c:167