28 #include "ascension/shader.h" |
28 #include "ascension/shader.h" |
29 #include "ascension/files.h" |
29 #include "ascension/files.h" |
30 #include "ascension/error.h" |
30 #include "ascension/error.h" |
31 |
31 |
32 #include <GL/glew.h> |
32 #include <GL/glew.h> |
|
33 #include <string.h> |
33 |
34 |
34 AscShaderProgram ASC_SHADER_FONT; |
35 AscShaderFont ASC_SHADER_FONT; |
35 |
36 |
36 |
37 |
37 AscShader asc_shader_compile(unsigned int type, |
38 AscShader asc_shader_compile(unsigned int type, |
38 char const *code, |
39 char const *code, |
39 int length) { |
40 int length) { |
91 glGetProgramiv(id, GL_LINK_STATUS, &success); |
92 glGetProgramiv(id, GL_LINK_STATUS, &success); |
92 glDetachShader(id, vertex.id); |
93 glDetachShader(id, vertex.id); |
93 glDetachShader(id, fragment.id); |
94 glDetachShader(id, fragment.id); |
94 if (success) { |
95 if (success) { |
95 asc_dprintf("Shader Program %u linked (vtf: %u, frag: %u)", id, vertex.id, fragment.id); |
96 asc_dprintf("Shader Program %u linked (vtf: %u, frag: %u)", id, vertex.id, fragment.id); |
96 return (AscShaderProgram) {id}; |
97 AscShaderProgram prog; |
|
98 prog.id = id; |
|
99 prog.model = glGetUniformLocation(id, "model"); |
|
100 prog.view = glGetUniformLocation(id, "view"); |
|
101 prog.projection = glGetUniformLocation(id, "projection"); |
|
102 return prog; |
97 } else { |
103 } else { |
98 char *log = malloc(1024); |
104 char *log = malloc(1024); |
99 glGetProgramInfoLog(id, 1024, NULL, log); |
105 glGetProgramInfoLog(id, 1024, NULL, log); |
100 glDeleteShader(id); |
106 glDeleteShader(id); |
101 asc_error(log); |
107 asc_error(log); |
129 asc_shader_destroy(font_frag); |
135 asc_shader_destroy(font_frag); |
130 return prog; |
136 return prog; |
131 } |
137 } |
132 |
138 |
133 void asc_shader_initialize_predefined(void) { |
139 void asc_shader_initialize_predefined(void) { |
134 ASC_SHADER_FONT = asc_shader_compile_link_discard("shader/font_vtx.glsl", "shader/font_frag.glsl"); |
140 ASC_SHADER_FONT.base = asc_shader_compile_link_discard("shader/font_vtx.glsl", "shader/font_frag.glsl"); |
|
141 ASC_SHADER_FONT.surface = glGetUniformLocation(ASC_SHADER_FONT.base.id, "surface"); |
135 } |
142 } |
136 |
143 |
137 void asc_shader_destroy_predefined(void) { |
144 void asc_shader_destroy_predefined(void) { |
138 asc_shader_program_destroy(ASC_SHADER_FONT); |
145 asc_shader_program_destroy(ASC_SHADER_FONT.base); |
139 } |
146 } |