4 def __init__(self, name, vs_path, fs_path, attributes, uniforms, subroutines):
12 def header_chunks(self):
14 yield " GLuint program;\n"
16 yield f
" GLuint {attribute};\n"
18 yield f
" GLuint {uniform};\n"
19 for subroutine, routines
in self.
subroutines.items():
21 yield " GLuint uniform;\n"
23 yield f
" GLuint {r};\n"
24 yield f
" }} {subroutine};\n"
25 yield f
" }} {self.name};\n"
27 def source_chunks(self):
28 yield f
" shaders.{self.name}.program = gl_program_vert_frag(\"{self.vs_path}\", \"{self.fs_path}\");\n"
30 yield f
" shaders.{self.name}.{attribute} = glGetAttribLocation(shaders.{self.name}.program, \"{attribute}\");\n"
32 yield f
" shaders.{self.name}.{uniform} = glGetUniformLocation(shaders.{self.name}.program, \"{uniform}\");\n"
34 yield " if (gl_has( OPENGL_SUBROUTINES )) {\n"
35 for subroutine, routines
in self.
subroutines.items():
36 yield f
" shaders.{self.name}.{subroutine}.uniform = glGetSubroutineUniformLocation( shaders.{self.name}.program, GL_FRAGMENT_SHADER, \"{subroutine}\" );\n"
38 yield f
" shaders.{self.name}.{subroutine}.{r} = glGetSubroutineIndex( shaders.{self.name}.program, GL_FRAGMENT_SHADER, \"{r}\" );\n"
43 def __init__(self, name, fs_path):
44 super().__init__( name=name, vs_path=
"project_pos.vert", fs_path=fs_path, attributes=[
"vertex"], uniforms=[
"projection",
"color",
"dimensions",
"dt",
"paramf",
"parami",
"paramv"], subroutines={} )
45 global num_simpleshaders
46 num_simpleshaders += 1
47 def header_chunks(self):
48 yield f
" SimpleShader {self.name};\n"
49 def source_chunks(self):
50 yield f
" shaders_loadSimple( \"{self.name}\", &shaders.{self.name}, \"{self.fs_path}\" );"
55 vs_path =
"project.vert",
56 fs_path =
"solid.frag",
57 attributes = [
"vertex"],
58 uniforms = [
"projection",
"color"],
63 vs_path =
"project_pos.vert",
64 fs_path =
"trail.frag",
65 attributes = [
"vertex"],
66 uniforms = [
"projection",
"c1",
"c2",
"t1",
"t2",
"dt",
"pos1",
"pos2",
"r",
"nebu_col" ],
81 vs_path =
"smooth.vert",
82 fs_path =
"smooth.frag",
83 attributes = [
"vertex",
"vertex_color"],
84 uniforms = [
"projection"],
89 vs_path =
"texture.vert",
90 fs_path =
"texture.frag",
91 attributes = [
"vertex"],
92 uniforms = [
"projection",
"color",
"tex_mat",
"sampler"],
96 name =
"texture_interpolate",
97 vs_path =
"texture.vert",
98 fs_path =
"texture_interpolate.frag",
99 attributes = [
"vertex"],
100 uniforms = [
"projection",
"color",
"tex_mat",
"sampler1",
"sampler2",
"inter"],
104 name =
"stealthoverlay",
105 vs_path =
"texture.vert",
106 fs_path =
"stealthoverlay.frag",
107 attributes = [
"vertex"],
108 uniforms = [
"projection",
"color",
"tex_mat"],
113 vs_path =
"nebula.vert",
114 fs_path =
"nebula_overlay.frag",
115 attributes = [
"vertex"],
116 uniforms = [
"projection",
"hue",
"nonuniformity",
"horizon",
"eddy_scale",
"time"],
120 name =
"nebula_background",
121 vs_path =
"nebula.vert",
122 fs_path =
"nebula_background.frag",
123 attributes = [
"vertex"],
124 uniforms = [
"projection",
"hue",
"nonuniformity",
"eddy_scale",
"time",
"volatility"],
128 name =
"nebula_puff",
129 vs_path =
"project_pos.vert",
130 fs_path =
"nebula_puff.frag",
131 attributes = [
"vertex"],
132 uniforms = [
"projection",
"nebu_col",
"time",
"r" ],
137 vs_path =
"system_map.vert",
138 fs_path =
"nebula_map.frag",
139 attributes = [
"vertex"],
140 uniforms = [
"projection",
"hue",
"time",
"globalpos",
"alpha",
"volatility"],
145 vs_path =
"smooth.vert",
146 fs_path =
"points.frag",
147 attributes = [
"vertex",
"vertex_color"],
148 uniforms = [
"projection"],
153 vs_path =
"stars.vert",
154 fs_path =
"stars.frag",
155 attributes = [
"vertex",
"brightness"],
156 uniforms = [
"projection",
"star_xy",
"dims",
"xy",
"use_lines",
"dim"],
161 vs_path =
"lines.vert",
162 fs_path =
"lines.frag",
163 attributes = [
"vertex"],
164 uniforms = [
"projection",
"colour"],
169 vs_path =
"font.vert",
170 fs_path =
"font.frag",
171 attributes = [
"vertex",
"tex_coord"],
172 uniforms = [
"projection",
"m",
"color",
"outline_color"],
177 vs_path =
"project_pos.vert",
178 fs_path =
"beam.frag",
179 attributes = [
"vertex"],
180 uniforms = [
"projection",
"color",
"dt",
"r",
"dimensions" ],
195 vs_path =
"project_pos.vert",
196 fs_path =
"jump.frag",
197 attributes = [
"vertex"],
198 uniforms = [
"projection",
"progress",
"direction",
"dimensions",
"brightness"],
211 vs_path =
"material.vert",
212 fs_path =
"material.frag",
213 attributes = [
"vertex",
"vertex_normal",
"vertex_tex"],
214 uniforms = [
"projection",
"model",
"map_Kd",
"map_Ks",
"map_Ke",
"map_Bump",
"Ns",
"Ka",
"Kd",
"Ks",
"Ke",
"Ni",
"d",
"bm"],
219 vs_path =
"postprocess.vert",
220 fs_path =
"colorblind.frag",
221 attributes = [
"VertexPosition"],
222 uniforms = [
"ClipSpaceFromLocal",
"MainTex"],
227 vs_path =
"postprocess.vert",
228 fs_path =
"shake.frag",
229 attributes = [
"VertexPosition"],
230 uniforms = [
"ClipSpaceFromLocal",
"MainTex",
"shake_pos",
"shake_vel",
"shake_force"],
235 vs_path =
"postprocess.vert",
236 fs_path =
"damage.frag",
237 attributes = [
"VertexPosition"],
238 uniforms = [
"ClipSpaceFromLocal",
"MainTex",
"damage_strength",
"love_ScreenSize"],
242 name =
"gamma_correction",
243 vs_path =
"postprocess.vert",
244 fs_path =
"gamma_correction.frag",
245 attributes = [
"VertexPosition"],
246 uniforms = [
"ClipSpaceFromLocal",
"MainTex",
"gamma"],
251 fs_path =
"status.frag",
254 name =
"factiondisk",
255 fs_path =
"factiondisk.frag",
258 name =
"stealthaura",
259 fs_path =
"stealthaura.frag",
262 name =
"spobmarker_empty",
263 fs_path =
"spobmarker_empty.frag",
266 name =
"spobmarker_earth",
267 fs_path =
"spobmarker_earth.frag",
270 name =
"spobmarker_rhombus",
271 fs_path =
"spobmarker_rhombus.frag",
274 name =
"spobmarker_triangle",
275 fs_path =
"spobmarker_triangle.frag",
278 name =
"spobmarker_wormhole",
279 fs_path =
"spobmarker_wormhole.frag",
283 fs_path =
"jumpmarker.frag",
286 name =
"pilotmarker",
287 fs_path =
"pilotmarker.frag",
290 name =
"playermarker",
291 fs_path =
"playermarker.frag",
294 name =
"blinkmarker",
295 fs_path =
"blinkmarker.frag",
299 fs_path =
"sysmarker.frag",
303 fs_path =
"notemarker.frag",
306 name =
"asteroidmarker",
307 fs_path =
"asteroidmarker.frag",
311 fs_path =
"targetship.frag",
315 fs_path =
"targetspob.frag",
319 fs_path =
"jumplane.frag",
322 name =
"jumplanegoto",
323 fs_path =
"jumplanegoto.frag",
327 fs_path =
"safelane.frag",
331 fs_path =
"iflockon.frag",
335 fs_path =
"gear.frag",
339 fs_path =
"selectspob.frag",
342 name =
"selectposition",
343 fs_path =
"selectposition.frag",
347 fs_path =
"sdfsolid.frag",
351 fs_path =
"circle.frag",
355 fs_path =
"crosshairs.frag",
359 fs_path =
"astaura.frag",
363 fs_path =
"hilight.frag",
366 name =
"hilight_circle",
367 fs_path =
"hilight_circle.frag",
370 name =
"stealthmarker",
371 fs_path =
"stealthmarker.frag",
375 fs_path =
"healthbar.frag",
380 yield f
"/* FILE GENERATED BY {__file__} */"
382def generate_h_file():
383 yield from header_chunks()
390#define NUM_SIMPLE_SHADERS {num_simpleshaders}
392typedef struct SimpleShader_ {{
405typedef struct Shaders_ {{
408 for shader
in SHADERS:
409 yield from shader.header_chunks()
411 yield f
""" SimpleShader *simple_shaders[ NUM_SIMPLE_SHADERS ];
414extern Shaders shaders;
416void shaders_load (void);
417void shaders_unload (void);
418const SimpleShader *shaders_getSimple( const char *name );
421def generate_c_file():
422 yield from header_chunks()
426#include "shaders.gen.h"
427#include "opengl_shader.h"
431static int nsimpleshaders = 0;
433static int shaders_cmp( const void *p1, const void *p2 )
435 const SimpleShader **s1 = (const SimpleShader**) p1;
436 const SimpleShader **s2 = (const SimpleShader**) p2;
437 return strcmp( (*s1)->name, (*s2)->name );
440static int shaders_loadSimple( const char *name, SimpleShader *shd, const char *fs_path )
443 shd->program = gl_program_vert_frag(
"project_pos.vert", fs_path );
444 shd->vertex = glGetAttribLocation( shd->program,
"vertex" );
445 shd->projection = glGetUniformLocation( shd->program,
"projection" );
446 shd->color = glGetUniformLocation( shd->program,
"color" );
447 shd->dimensions = glGetUniformLocation( shd->program,
"dimensions" );
448 shd->dt = glGetUniformLocation( shd->program,
"dt" );
449 shd->paramf = glGetUniformLocation( shd->program,
"paramf" );
450 shd->parami = glGetUniformLocation( shd->program,
"parami" );
451 shd->paramv = glGetUniformLocation( shd->program,
"paramv" );
454 shaders.simple_shaders[ nsimpleshaders++ ] = shd;
459const SimpleShader *shaders_getSimple( const char *name )
461 const SimpleShader shd = { .name=name };
462 const SimpleShader *shdptr = &shd;
463 const SimpleShader **found = bsearch( &shdptr, shaders.simple_shaders, nsimpleshaders, sizeof(SimpleShader*), shaders_cmp );
469void shaders_load (void) {
471 for i, shader
in enumerate(SHADERS):
472 yield from shader.source_chunks()
473 if i != len(SHADERS) - 1:
476 qsort( shaders.simple_shaders, nsimpleshaders, sizeof(SimpleShader*), shaders_cmp );
479void shaders_unload (void) {
481 for shader
in SHADERS:
482 yield f
" glDeleteProgram(shaders.{shader.name}.program);\n"
484 yield """ memset(&shaders, 0, sizeof(shaders));
488with open("shaders.gen.h", "w") as shaders_gen_h:
489 shaders_gen_h.writelines(generate_h_file())
491with open(
"shaders.gen.c",
"w")
as shaders_gen_c:
492 shaders_gen_c.writelines(generate_c_file())