src/sprite.c

changeset 163
3628cc3c0483
parent 162
d3598c834f9b
equal deleted inserted replaced
162:d3598c834f9b 163:3628cc3c0483
50 .defines.frag = rect ? "#define USE_RECT" : NULL, 50 .defines.frag = rect ? "#define USE_RECT" : NULL,
51 }, &codes)) { 51 }, &codes)) {
52 asc_error("Loading sprite shader failed."); 52 asc_error("Loading sprite shader failed.");
53 return NULL; 53 return NULL;
54 } 54 }
55 // TODO: find better way to deal with inheritance (&shader->program just looks bad)
55 AscSpriteShader *shader = asc_shader_create(codes, sizeof(*shader)); 56 AscSpriteShader *shader = asc_shader_create(codes, sizeof(*shader));
56 if (shader == NULL) { 57 if (asc_shader_invalid(&shader->program)) {
57 asc_shader_free_codes(codes); 58 asc_shader_free_codes(codes);
58 return NULL; 59 return (AscShaderProgram*) shader;
59 } 60 }
60 shader->tex = glGetUniformLocation(shader->program.gl_id, "tex"); 61 shader->tex = glGetUniformLocation(shader->program.gl_id, "tex");
61 asc_shader_free_codes(codes); 62 asc_shader_free_codes(codes);
62 63
63 asc_error_catch_all_gl(); 64 asc_error_catch_all_gl();
97 // TODO: scene should know which shader we are going to activate s.t. it can pre-sort nodes 98 // TODO: scene should know which shader we are going to activate s.t. it can pre-sort nodes
98 const AscSpriteShader *shader = 99 const AscSpriteShader *shader =
99 sprite->texture->target == GL_TEXTURE_RECTANGLE 100 sprite->texture->target == GL_TEXTURE_RECTANGLE
100 ? asc_shader_lookup_or_create(ASC_SHADER_SPRITE_RECT, asc_sprite_shader_create, 1) 101 ? asc_shader_lookup_or_create(ASC_SHADER_SPRITE_RECT, asc_sprite_shader_create, 1)
101 : asc_shader_lookup_or_create(ASC_SHADER_SPRITE_UV, asc_sprite_shader_create, 0); 102 : asc_shader_lookup_or_create(ASC_SHADER_SPRITE_UV, asc_sprite_shader_create, 0);
102 if (shader == NULL) return; 103 // TODO: how to remove the following cast?
104 if (asc_shader_invalid((AscShaderProgram*)shader)) return;
103 asc_shader_use(&shader->program, camera); 105 asc_shader_use(&shader->program, camera);
104 106
105 // Upload model matrix 107 // Upload model matrix
106 glUniformMatrix4fv(shader->program.model, 1, 108 glUniformMatrix4fv(shader->program.model, 1,
107 GL_FALSE, node->world_transform); 109 GL_FALSE, node->world_transform);

mercurial