31 #include "ascension/context.h" |
31 #include "ascension/context.h" |
32 #include "ascension/error.h" |
32 #include "ascension/error.h" |
33 #include "ascension/shader.h" |
33 #include "ascension/shader.h" |
34 |
34 |
35 #include <GL/glew.h> |
35 #include <GL/glew.h> |
|
36 #include <assert.h> |
36 |
37 |
37 typedef struct asc_rectangle_shader_s { |
38 typedef struct asc_rectangle_shader_s { |
38 AscShaderProgram program; |
39 AscShaderProgram program; |
39 GLint color; |
40 GLint color; |
40 GLint border_color; |
41 GLint border_color; |
49 |
50 |
50 static AscShaderProgram *asc_rectangle_shader_create(int flags) { |
51 static AscShaderProgram *asc_rectangle_shader_create(int flags) { |
51 AscShaderCodes codes; |
52 AscShaderCodes codes; |
52 // TODO: create a utility that rolls out those defines |
53 // TODO: create a utility that rolls out those defines |
53 const char * const defines[] = { |
54 const char * const defines[] = { |
54 NULL, |
55 "#define FILL\n", |
55 "#define FILL", |
56 "#define ROUNDED_CORNERS\n", |
56 "#define BORDER\n#define ROUNDED_CORNERS", |
57 "#define BORDER\n" |
57 "#define FILL\n#define ROUNDED_CORNERS", |
|
58 "#define BORDER", |
|
59 "#define BORDER\n#define FILL", |
|
60 "#define BORDER\n#define ROUNDED_CORNERS", |
|
61 "#define BORDER\n#define FILL\n#define ROUNDED_CORNERS", |
|
62 }; |
58 }; |
63 if (asc_shader_load_code_files((AscShaderCodeInfo){ |
59 if (asc_shader_load_code_files((AscShaderCodeInfo){ |
64 .files.vtx = "sprite_vtx.glsl", |
60 .files.vtx = "sprite_vtx.glsl", |
65 .files.frag = "rectangle_frag.glsl", |
61 .files.frag = "rectangle_frag.glsl", |
66 .defines.frag = defines[flags], |
62 .defines.frag_list = defines, |
|
63 .defines.frag_list_select = flags |
67 }, &codes)) { |
64 }, &codes)) { |
68 asc_error("Loading sprite shader failed."); |
65 asc_error("Loading sprite shader failed."); |
69 return NULL; |
66 return NULL; |
70 } |
67 } |
71 AscRectangleShader *shader = asc_shader_create(codes, sizeof(*shader)); |
68 AscRectangleShader *shader = asc_shader_create(codes, sizeof(*shader)); |
72 if (asc_has_error()) { |
69 if (asc_has_error()) { |
73 asc_shader_free_codes(codes); |
70 asc_shader_free_codes(codes); |
|
71 // TODO: must not return NULL or must add error handling on caller site |
74 return NULL; |
72 return NULL; |
75 } |
73 } |
76 shader->size = glGetUniformLocation(shader->program.gl_id, "size"); |
74 shader->size = glGetUniformLocation(shader->program.gl_id, "size"); |
77 if (asc_test_flag(flags, ASC_RECTANGLE_SHADER_FLAG_FILL)) { |
75 if (asc_test_flag(flags, ASC_RECTANGLE_SHADER_FLAG_FILL)) { |
78 shader->color = glGetUniformLocation(shader->program.gl_id, "color"); |
76 shader->color = glGetUniformLocation(shader->program.gl_id, "color"); |