cogl-texture: Add a new constructor to turn CoglBuffers into textures

The only goal of using COGL buffers is to use them to create
textures. cogl_texture_new_from_buffer() is the new symbol to create
textures out of buffers.
This commit is contained in:
Damien Lespiau 2010-01-22 15:07:27 +00:00
parent abbb668163
commit b7f049495b
3 changed files with 118 additions and 0 deletions

View File

@ -35,6 +35,7 @@
#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"
@ -452,6 +453,60 @@ cogl_texture_new_from_sub_texture (CoglHandle full_texture,
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)
{

View File

@ -344,6 +344,66 @@ CoglHandle cogl_texture_new_from_sub_texture
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
/**

View File

@ -494,4 +494,7 @@ cogl_pixel_buffer_new
cogl_pixel_buffer_new_for_size
cogl_is_pixel_buffer
<SUBSECTION>
cogl_texture_new_from_buffer
</SECTION>