2011-07-13 10:47:10 -04:00
|
|
|
/*
|
|
|
|
* texture rectangle
|
|
|
|
*
|
|
|
|
* A small utility function to help create a rectangle texture
|
|
|
|
*
|
|
|
|
* Authored By Neil Roberts <neil@linux.intel.com>
|
|
|
|
*
|
2012-03-23 14:51:25 -04:00
|
|
|
* Copyright (C) 2011, 2012 Intel Corporation
|
2011-07-13 10:47:10 -04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2012-03-23 14:51:25 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include "meta-texture-rectangle.h"
|
2011-07-13 10:47:10 -04:00
|
|
|
|
2012-03-23 14:51:25 -04:00
|
|
|
CoglTexture *
|
2011-07-13 10:47:10 -04:00
|
|
|
meta_texture_rectangle_new (unsigned int width,
|
|
|
|
unsigned int height,
|
|
|
|
CoglPixelFormat format,
|
2012-03-23 14:51:25 -04:00
|
|
|
CoglPixelFormat internal_format,
|
2011-07-13 10:47:10 -04:00
|
|
|
unsigned int rowstride,
|
2012-03-23 14:51:25 -04:00
|
|
|
const guint8 *data,
|
|
|
|
GError **error)
|
2011-07-13 10:47:10 -04:00
|
|
|
{
|
2012-03-23 14:51:25 -04:00
|
|
|
ClutterBackend *backend =
|
|
|
|
clutter_get_default_backend ();
|
|
|
|
CoglContext *context =
|
|
|
|
clutter_backend_get_cogl_context (backend);
|
|
|
|
CoglTextureRectangle *tex_rect;
|
|
|
|
|
|
|
|
tex_rect = cogl_texture_rectangle_new_with_size (context,
|
|
|
|
width, height,
|
|
|
|
internal_format,
|
|
|
|
error);
|
|
|
|
if (tex_rect == NULL)
|
|
|
|
return NULL;
|
2011-07-13 10:47:10 -04:00
|
|
|
|
|
|
|
if (data)
|
2012-03-23 14:51:25 -04:00
|
|
|
cogl_texture_set_region (COGL_TEXTURE (tex_rect),
|
|
|
|
0, 0, /* src_x/y */
|
|
|
|
0, 0, /* dst_x/y */
|
|
|
|
width, height, /* dst_width/height */
|
|
|
|
width, height, /* width/height */
|
2011-07-13 10:47:10 -04:00
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
data);
|
|
|
|
|
2012-03-23 14:51:25 -04:00
|
|
|
return COGL_TEXTURE (tex_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
texture_rectangle_check_cb (CoglTexture *sub_texture,
|
|
|
|
const float *sub_texture_coords,
|
|
|
|
const float *meta_coords,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
gboolean *result = user_data;
|
|
|
|
|
|
|
|
if (cogl_is_texture_rectangle (sub_texture))
|
|
|
|
*result = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determines if the given texture is using a rectangle texture as its
|
|
|
|
* primitive texture type. Eventually this function could be replaced
|
|
|
|
* with cogl_texture_get_type if Cogl makes that public.
|
|
|
|
*
|
|
|
|
* http://git.gnome.org/browse/cogl/commit/?h=8012eee31
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
meta_texture_rectangle_check (CoglTexture *texture)
|
|
|
|
{
|
|
|
|
gboolean result = FALSE;
|
|
|
|
|
|
|
|
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (texture),
|
|
|
|
0.0f, 0.0f, /* tx_1 / ty_1 */
|
|
|
|
1.0f, 1.0f, /* tx_2 / ty_2 */
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
texture_rectangle_check_cb,
|
|
|
|
&result);
|
2011-07-13 10:47:10 -04:00
|
|
|
|
2012-03-23 14:51:25 -04:00
|
|
|
return result;
|
2011-07-13 10:47:10 -04:00
|
|
|
}
|