#include "cogl-util.h"
#include "cogl-bitmap.h"
#include "cogl-bitmap-private.h"
+#include "cogl-buffer-private.h"
#include "cogl-texture-private.h"
#include "cogl-texture-driver.h"
#include "cogl-texture-2d-sliced-private.h"
sub_width, sub_height);
}
+CoglHandle
+cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
+ guint width,
+ guint height,
+ CoglTextureFlags flags,
+ CoglPixelFormat format,
+ CoglPixelFormat internal_format,
+ guint rowstride,
+ const guint offset)
+{
+ CoglHandle texture;
+ CoglBitmap bitmap;
+ CoglBuffer *cogl_buffer;
+ CoglPixelBuffer *pixel_buffer;
+
+ g_return_val_if_fail (cogl_is_buffer (buffer), COGL_INVALID_HANDLE);
+
+ if (format == COGL_PIXEL_FORMAT_ANY)
+ return COGL_INVALID_HANDLE;
+
+ cogl_buffer = COGL_BUFFER (buffer);
+ pixel_buffer = COGL_PIXEL_BUFFER (buffer);
+
+ /* Rowstride from width if not given */
+ if (rowstride == 0)
+ rowstride = width * _cogl_get_format_bpp (format);
+
+ /* use the CoglBuffer height and width as last resort */
+ if (width == 0)
+ width = pixel_buffer->width;
+ if (height == 0)
+ height = pixel_buffer->height;
+ if (width == 0 || height == 0)
+ {
+ /* no width or height specified, neither at creation time (because the
+ * buffer was created by cogl_pixel_buffer_new()) nor when calling this
+ * function */
+ return COGL_INVALID_HANDLE;
+ }
+
+ /* Wrap the data into a bitmap */
+ bitmap.width = width;
+ bitmap.height = height;
+ bitmap.data = GUINT_TO_POINTER (offset);
+ bitmap.format = format;
+ bitmap.rowstride = rowstride;
+
+ _cogl_buffer_bind (cogl_buffer, GL_PIXEL_UNPACK_BUFFER);
+ texture = cogl_texture_new_from_bitmap (&bitmap, flags, internal_format);
+ _cogl_buffer_bind (NULL, GL_PIXEL_UNPACK_BUFFER);
+
+ return texture;
+}
+
guint
cogl_texture_get_width (CoglHandle handle)
{
gint sub_width,
gint sub_height);
+#if defined (COGL_ENABLE_EXPERIMENTAL_API)
+
+/**
+ * cogl_texture_new_from_buffer:
+ * @buffer: the #CoglHandle of a pixel buffer
+ * @width: width of texture in pixels or 0
+ * @height: height of texture in pixels or 0
+ * @flags: optional flags for the texture, or %COGL_TEXTURE_NONE
+ * @format: the #CoglPixelFormat the buffer is stored in in RAM
+ * @internal_format: the #CoglPixelFormat that will be used for storing
+ * the buffer on the GPU. If %COGL_PIXEL_FORMAT_ANY is given then a
+ * premultiplied format similar to the format of the source data will
+ * be used. The default blending equations of Cogl expect premultiplied
+ * color data; the main use of passing a non-premultiplied format here
+ * is if you have non-premultiplied source data and are going to adjust
+ * the blend mode (see cogl_material_set_blend()) or use the data for
+ * something other than straight blending
+ * @rowstride: the memory offset in bytes between the starts of
+ * scanlines in @data. If 0 is given the row stride will be deduced from
+ * @width and @format or the stride given by cogl_pixel_buffer_new_for_size()
+ * @offset: offset in bytes in @buffer from where the texture data starts
+ *
+ * Creates a new texture using the buffer specified by @handle. If the buffer
+ * has been created using cogl_pixel_buffer_new_for_size() it's possible to omit
+ * the height and width values already specified at creation time.
+ *
+ * Return value: a #CoglHandle to the new texture or %COGL_INVALID_HANDLE on
+ * failure
+ *
+ * Since: 1.2
+ * Stability: Unstable
+ */
+CoglHandle cogl_texture_new_from_buffer (CoglHandle buffer,
+ guint width,
+ guint height,
+ CoglTextureFlags flags,
+ CoglPixelFormat format,
+ CoglPixelFormat internal_format,
+ guint rowstride,
+ guint offset);
+
+/* the function above is experimental, the actual symbol is suffixed by _EXP so
+ * we can ensure ABI compatibility and leave the cogl_buffer namespace free for
+ * future use. A bunch of defines translates the symbols documented above into
+ * the real symbols */
+
+CoglHandle cogl_texture_new_from_buffer_EXP
+ (CoglHandle buffer,
+ guint width,
+ guint height,
+ CoglTextureFlags flags,
+ CoglPixelFormat format,
+ CoglPixelFormat internal_format,
+ guint rowstride,
+ guint offset);
+
+#define cogl_texture_new_from_buffer cogl_texture_new_from_buffer_EXP
+
+#endif
+
#ifndef COGL_DISABLE_DEPRECATED
/**