static void make_reorder_chain () { basic_block prev = NULL; int nbb_m1 = n_basic_blocks - 1; basic_block next; /* Loop until we've placed every block. */ do { int i; next = NULL; /* Find the next unplaced block. */ /* ??? Get rid of this loop, and track which blocks are not yet placed more directly, so as to avoid the O(N^2) worst case. Perhaps keep a doubly-linked list of all to-be-placed blocks; remove from the list as we place. The head of that list is what we're looking for here. */ for (i = 0; i <= nbb_m1 && !next; ++i) { basic_block bb = BASIC_BLOCK (i); if (! RBI (bb)->visited) next = bb; } if (next) prev = make_reorder_chain_1 (next, prev); } while (next); RBI (prev)->next = NULL; }
static int free_mesh(struct rbi* rbi, struct render_mesh* mesh) { if(!mesh) return -1; if(mesh->vertex_array) RBI(rbi, vertex_array_ref_put(mesh->vertex_array)); if(mesh->vertex_buffer) RBI(rbi, buffer_ref_put(mesh->vertex_buffer)); if(mesh->index_buffer) RBI(rbi, buffer_ref_put(mesh->index_buffer)); free(mesh); return 0; }
static int free_shader (struct rbi* rbi, struct rb_context* ctxt, struct render_shader* shader) { if(!ctxt || !shader) return -1; if(shader->view_uniform) RBI(rbi, uniform_ref_put(shader->view_uniform)); if(shader->proj_uniform) RBI(rbi, uniform_ref_put(shader->proj_uniform)); if(shader->program) RBI(rbi, program_ref_put(shader->program)); if(shader->vertex_shader) RBI(rbi, shader_ref_put(shader->vertex_shader)); if(shader->fragment_shader) RBI(rbi, shader_ref_put(shader->fragment_shader)); free(shader); return 0; }
int main(int argc, char** argv) { /* Check command arguments */ if(argc != 3) { printf("usage: %s RB_DRIVER FONT\n", argv[0]); return -1; } const char* driver_name = argv[1]; const char* font_name = argv[2]; FILE* file = fopen(driver_name, "r"); if(!file) { fprintf(stderr, "Invalid driver %s\n", driver_name); return -1; } fclose(file); file = fopen(font_name, "r"); if(!file) { fprintf(stderr, "Invalid font name %s\n", font_name); return -1; } fclose(file); /* Spawn a drawable windows */ struct wm_device* device = NULL; struct wm_window* window = NULL; const struct wm_window_desc win_desc = { .width = 640, .height = 480, .fullscreen = false }; WM(create_device(NULL, &device)); WM(create_window(device, &win_desc, &window)); /* Create a render backend */ struct rbi rbi; struct rb_context* rb_ctxt = NULL; CHECK(rbi_init(driver_name, &rbi), 0); RBI(&rbi, create_context(NULL, &rb_ctxt)); /* Load font resource */ struct font_system* font_sys = NULL; struct font_rsrc* font_rsrc = NULL; bool is_font_scalable = false; int line_space = 0; FONT(system_create(NULL, &font_sys)); FONT(rsrc_create(font_sys, font_name, &font_rsrc)); FONT(rsrc_get_line_space(font_rsrc, &line_space)); FONT(rsrc_is_scalable(font_rsrc, &is_font_scalable)); if(is_font_scalable) { FONT(rsrc_set_size(font_rsrc, 24, 24)); } /* Build x charset description */ int glyph_min_width = INT_MAX; const wchar_t* charset = L"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" L" &~\"#'{([-|`_\\^@)]=}+$%*,?;.:/!<>"; const size_t charset_len = wcslen(charset); size_t i = 0; struct lp_font_glyph_desc lp_font_glyph_desc_list[512]; unsigned char* glyph_bitmap_list[512]; ASSERT(charset_len <= 512); for(i = 0; i < charset_len; ++i) { struct font_glyph_desc font_glyph_desc; struct font_glyph* font_glyph = NULL; int width = 0; int height = 0; int Bpp = 0; FONT(rsrc_get_glyph(font_rsrc, charset[i], &font_glyph)); FONT(glyph_get_desc(font_glyph, &font_glyph_desc)); glyph_min_width = MIN(font_glyph_desc.width, glyph_min_width); lp_font_glyph_desc_list[i].width = font_glyph_desc.width; lp_font_glyph_desc_list[i].character = font_glyph_desc.character; lp_font_glyph_desc_list[i].bitmap_left = font_glyph_desc.bbox.x_min; lp_font_glyph_desc_list[i].bitmap_top = font_glyph_desc.bbox.y_min; FONT(glyph_get_bitmap(font_glyph, true, &width, &height, &Bpp, NULL)); if(width && height ) { glyph_bitmap_list[i] = MEM_CALLOC (&mem_default_allocator, (size_t)(width*height), (size_t)Bpp); NCHECK(glyph_bitmap_list[i], NULL); FONT(glyph_get_bitmap (font_glyph, true, &width, &height, &Bpp, glyph_bitmap_list[i])); } lp_font_glyph_desc_list[i].bitmap.width = width; lp_font_glyph_desc_list[i].bitmap.height = height; lp_font_glyph_desc_list[i].bitmap.bytes_per_pixel = Bpp; lp_font_glyph_desc_list[i].bitmap.buffer = glyph_bitmap_list[i]; FONT(glyph_ref_put(font_glyph)); } /* Create the lp system and font */ struct lp* lp = NULL; struct lp_font* lp_font = NULL; LP(create(&rbi, rb_ctxt, NULL, &lp)); LP(font_create(lp, &lp_font)); LP(font_set_data (lp_font, line_space, (int)charset_len, lp_font_glyph_desc_list)); /* Create the printer */ struct lp_printer* lp_printer = NULL; LP(printer_create(lp, &lp_printer)); LP(printer_set_font(lp_printer, lp_font)); LP(printer_set_viewport(lp_printer, 0, 0, win_desc.width, win_desc.height)); enum wm_state esc = WM_STATE_UNKNOWN; do { int cur[2] = { 0, 0 }; RBI(&rbi, clear (rb_ctxt, RB_CLEAR_COLOR_BIT, (float[]){0.05f, 0.05f, 0.05f}, 0.f, 0)); LP(printer_print_wstring (lp_printer, 50, 70, L">$ ", (float[]){0.f, 1.f, 0.f}, cur+0, cur+1)); LP(printer_print_wstring (lp_printer, cur[0], cur[1], L"Hello", (float[]){1.f, 1.f, 1.f}, cur+0, cur+1));