CoglTexture2D * cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp, CoglPixelFormat internal_format, CoglError **error) { CoglContext *ctx; _COGL_RETURN_VAL_IF_FAIL (bmp != NULL, NULL); ctx = _cogl_bitmap_get_context (bmp); internal_format = _cogl_texture_determine_internal_format (cogl_bitmap_get_format (bmp), internal_format); if (!_cogl_texture_2d_can_create (ctx, cogl_bitmap_get_width (bmp), cogl_bitmap_get_height (bmp), internal_format)) { _cogl_set_error (error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE, "Failed to create texture 2d due to size/format" " constraints"); return NULL; } return ctx->driver_vtable->texture_2d_new_from_bitmap (bmp, internal_format, error); }
CoglHandle _cogl_texture_2d_new_from_bitmap (CoglHandle bmp_handle, CoglTextureFlags flags, CoglPixelFormat internal_format) { CoglTexture2D *tex_2d; CoglBitmap *bmp = (CoglBitmap *)bmp_handle; CoglBitmap dst_bmp; gboolean dst_bmp_owner; GLenum gl_intformat; GLenum gl_format; GLenum gl_type; g_return_val_if_fail (bmp_handle != COGL_INVALID_HANDLE, COGL_INVALID_HANDLE); internal_format = _cogl_texture_determine_internal_format (bmp->format, internal_format); if (!_cogl_texture_2d_can_create (bmp->width, bmp->height, internal_format)) return COGL_INVALID_HANDLE; if (!_cogl_texture_prepare_for_upload (bmp, internal_format, &internal_format, &dst_bmp, &dst_bmp_owner, &gl_intformat, &gl_format, &gl_type)) return COGL_INVALID_HANDLE; tex_2d = _cogl_texture_2d_create_base (bmp->width, bmp->height, flags, internal_format); _cogl_texture_driver_gen (GL_TEXTURE_2D, 1, &tex_2d->gl_texture); _cogl_texture_driver_upload_to_gl (GL_TEXTURE_2D, tex_2d->gl_texture, &dst_bmp, gl_intformat, gl_format, gl_type); tex_2d->gl_format = gl_intformat; if (dst_bmp_owner) g_free (dst_bmp.data); return _cogl_texture_2d_handle_new (tex_2d); }