/** * @name teleaf_canvas_context_2d_rebind * @brief if the given context is active, rebind it * @param ctx - (context_2d *) context to rebind * @retval NONE */ void tealeaf_canvas_context_2d_rebind(context_2d *ctx) { if (canvas.active_ctx == ctx) { canvas.active_ctx = NULL; tealeaf_canvas_context_2d_bind(ctx); } }
/** * @name context_2d_bind * @brief bind's the given context to gl and enables / disables scissors * @param ctx - (context_2d *) context to bind * @retval NONE */ void context_2d_bind(context_2d *ctx) { if (tealeaf_canvas_context_2d_bind(ctx)) { if (IS_SCISSOR_ENABLED(ctx)) { enable_scissor(ctx); } else { disable_scissor(ctx); } } }
/** Saves the given context_2d's buffer to a file of the given filetype @param ctx the given context2d @param file_name filename to save the buffer to @return void **/ char *context_2d_save_buffer_to_base64(context_2d *ctx, const char *image_type) { //bind offscreen buffer to gl frame buffer tealeaf_canvas_context_2d_bind(ctx); unsigned char *buffer = (unsigned char*)context_2d_read_pixels(ctx); //opengGL gives this as RGBA, Need to switch to //BGRA which will be interpreted as ARGB in Java //becuase of the endianess difference between Java/C // int i; // for(i = 0; i < ctx->width * ctx->height * 4; i+=4) { // char r = buffer[i]; // buffer[i] = buffer[i + 2]; // buffer[i + 2] = r; // } char *buf = (char*)write_image_to_base64(image_type, buffer, ctx->width, ctx->height, 4); tealeaf_canvas_context_2d_bind(context_2d_get_onscreen()); free(buffer); return buf; }
/** * @name tealeaf_canvas_init * @brief initilizes the tealeaf canvas object * @param framebuffer_name - (int) gl id of the onscreen framebuffer * @retval NONE */ void tealeaf_canvas_init(int framebuffer_name) { LOG("{canvas} Initializing Canvas"); int width = config_get_screen_width(); int height = config_get_screen_height(); GLuint offscreen_buffer_name; GLTRACE(glGenFramebuffers(1, &offscreen_buffer_name)); canvas.offscreen_framebuffer = offscreen_buffer_name; canvas.view_framebuffer = framebuffer_name; canvas.onscreen_ctx = context_2d_init(&canvas, "onscreen", -1, true); canvas.onscreen_ctx->width = width; canvas.onscreen_ctx->height = height; canvas.active_ctx = 0; // TODO: should_resize is not respected on iOS tealeaf_canvas_context_2d_bind(canvas.onscreen_ctx); }