static void material_generate_programs(material* m) { for(int i = 0; i < m->num_entries; i++) { material_entry* me = m->entries[i]; me->program = shader_program_new(); bool attached = false; for(int j = 0; j < me->num_items; j++) { if (me->types[j] == mat_item_shader) { asset_hndl ah = me->items[j].as_asset; shader_program_attach_shader(me->program, asset_hndl_ptr(&ah)); attached = true; } } if (attached) { shader_program_link(me->program); } } SDL_GL_CheckError(); }
shader_program* prog_load_file(char* filename) { shader_program* sp = shader_program_new(); SDL_RWops* file = SDL_RWFromFile(filename, "r"); if(file == NULL) { error("Could not load file %s", filename); } char line[1024]; while(SDL_RWreadline(file, line, 1024)) { char type[256]; char path[1024]; if (sscanf(line, "%256s : %1024s", type, path) == 2) { if(!asset_loaded(path)) { load_file(path); } shader* s = asset_get(path); shader_program_attach_shader(sp, s); } } SDL_RWclose(file); shader_program_link(sp); shader_program_print_log(sp); int error = 0; glGetProgramiv(*sp, GL_LINK_STATUS, &error); if (error == GL_FALSE) { error("Linking Error on Shader Program %s.", filename); } return sp; }