Neil Roberts 2008-04-25 13:37:36 +00:00
parent b70bf89ced
commit eff57a1cb0
40 changed files with 14675 additions and 1042 deletions

View File

@ -1,4 +1,4 @@
SUBDIRS = $(CLUTTER_COGL)
SUBDIRS = common $(CLUTTER_COGL)
EXTRA_DIST = cogl.h

25
TODO Normal file
View File

@ -0,0 +1,25 @@
============================
Cogl overhaul related tasks:
============================
MISC
- implemenent a 1 to 1 mapping of COGL_FEATURE flags
into CLUTTER_FEATURE flags before combining them
into final clutter flags value (clutter-feature.c)
TEXTURE
- cogl_texture_get_data, cogl_texture_set_region in GLES
- YUV texture format support (multitexturing + shader)
FBO
- add stencil, depth and other renderbuffers to fbos
- cogl_offscreen_new_multisample
- test cogl_offscreen_blit
- add "filter" argument to cogl_offscreen_blit

290
cogl.h
View File

@ -1,290 +0,0 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* COGL
* ====
*
* 'cogl' is a very simple abstraction layer which wraps GL and GLES.
*
*
* !!!! DO NOT USE THIS API YET OUTSIDE OF CLUTTER CORE !!!!
* THE API WILL FLUCTUATE WILDLY
*
* TODO:
* - Use ClutterReal for fixed/float params.
* - Add Perspective/viewport setup
* - Add Features..
*/
#ifndef __COGL_H__
#define __COGL_H__
#include <glib.h>
#include <clutter/clutter-color.h>
#include <clutter/clutter-feature.h>
#include <clutter/clutter-fixed.h>
#include <clutter/clutter-types.h>
#include "cogl-defines.h"
G_BEGIN_DECLS
#define CGL_ENABLE_BLEND (1<<1)
#define CGL_ENABLE_TEXTURE_2D (1<<2)
#define CGL_ENABLE_ALPHA_TEST (1<<3)
#define CGL_ENABLE_TEXTURE_RECT (1<<4)
typedef void (*CoglFuncPtr) (void);
CoglFuncPtr
cogl_get_proc_address (const gchar* name);
gboolean
cogl_check_extension (const gchar *name, const gchar *ext);
void
cogl_perspective (ClutterFixed fovy,
ClutterFixed aspect,
ClutterFixed zNear,
ClutterFixed zFar);
void
cogl_setup_viewport (guint width,
guint height,
ClutterFixed fovy,
ClutterFixed aspect,
ClutterFixed z_near,
ClutterFixed z_far);
void
cogl_paint_init (const ClutterColor *color);
void
cogl_push_matrix (void);
void
cogl_pop_matrix (void);
void
cogl_scale (ClutterFixed x, ClutterFixed z);
void
cogl_translatex (ClutterFixed x, ClutterFixed y, ClutterFixed z);
void
cogl_translate (gint x, gint y, gint z);
void
cogl_rotatex (ClutterFixed angle, gint x, gint y, gint z);
void
cogl_rotate (gint angle, gint x, gint y, gint z);
void
cogl_color (const ClutterColor *color);
void
cogl_clip_set (ClutterFixed x_offset,
ClutterFixed y_offset,
ClutterFixed width,
ClutterFixed height);
void
cogl_clip_unset (void);
void
cogl_enable (gulong flags);
void
cogl_enable_depth_test (gboolean setting);
gboolean
cogl_texture_can_size (COGLenum target,
COGLenum pixel_format,
COGLenum pixel_type,
int width,
int height);
void
cogl_texture_quad (gint x1,
gint x2,
gint y1,
gint y2,
ClutterFixed tx1,
ClutterFixed ty1,
ClutterFixed tx2,
ClutterFixed ty2);
void
cogl_textures_create (guint num, COGLuint *textures);
void
cogl_textures_destroy (guint num, const COGLuint *textures);
void
cogl_texture_bind (COGLenum target, COGLuint texture);
void
cogl_texture_set_alignment (COGLenum target,
guint alignment,
guint row_length);
void
cogl_texture_set_filters (COGLenum target,
COGLenum min_filter,
COGLenum max_filter);
void
cogl_texture_set_wrap (COGLenum target,
COGLenum wrap_s,
COGLenum wrap_t);
void
cogl_texture_image_2d (COGLenum target,
COGLint internal_format,
gint width,
gint height,
COGLenum format,
COGLenum type,
const guchar* pixels);
void
cogl_texture_sub_image_2d (COGLenum target,
gint xoff,
gint yoff,
gint width,
gint height,
COGLenum format,
COGLenum type,
const guchar* pixels);
void
cogl_rectangle (gint x, gint y, guint width, guint height);
void
cogl_trapezoid (gint y1,
gint x11,
gint x21,
gint y2,
gint x12,
gint x22);
void
cogl_alpha_func (COGLenum func,
ClutterFixed ref);
ClutterFeatureFlags
cogl_get_features ();
void
cogl_get_modelview_matrix (ClutterFixed m[16]);
void
cogl_get_projection_matrix (ClutterFixed m[16]);
void
cogl_get_viewport (ClutterFixed v[4]);
void
cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha);
void
cogl_fog_set (const ClutterColor *fog_color,
ClutterFixed density,
ClutterFixed z_near,
ClutterFixed z_far);
COGLhandle
cogl_create_shader (COGLenum shaderType);
void
cogl_shader_destroy (COGLhandle handle);
void
cogl_shader_source (COGLhandle shader,
const gchar *source);
void
cogl_shader_compile (COGLhandle shader_handle);
void
cogl_shader_get_info_log (COGLhandle handle,
guint size,
gchar *buffer);
void
cogl_shader_get_parameteriv (COGLhandle handle,
COGLenum pname,
COGLint *dest);
COGLhandle
cogl_create_program (void);
void
cogl_program_destroy (COGLhandle handle);
void
cogl_program_attach_shader (COGLhandle program_handle,
COGLhandle shader_handle);
/* 0 to use none */
void
cogl_program_link (COGLhandle program_handle);
void
cogl_program_use (COGLhandle program_handle);
COGLint
cogl_program_get_uniform_location (COGLhandle program_int,
const gchar *uniform_name);
void
cogl_program_uniform_1f (COGLint uniform_no,
gfloat value);
/* Offscreen - FBO support */
COGLuint
cogl_offscreen_create (COGLuint target_texture);
void
cogl_offscreen_destroy (COGLuint offscreen_handle);
void
cogl_offscreen_redirect_start (COGLuint offscreen_handle,
gint width,
gint height);
void
cogl_offscreen_redirect_end (COGLuint offscreen_handle,
gint width,
gint height);
G_END_DECLS
#endif /* __COGL_H__ */

874
cogl.h.in Normal file
View File

@ -0,0 +1,874 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* COGL
* ====
*
* 'cogl' is a very simple abstraction layer which wraps GL and GLES.
*
*
* !!!! DO NOT USE THIS API YET OUTSIDE OF CLUTTER CORE !!!!
* THE API WILL FLUCTUATE WILDLY
*
* TODO:
* - Use ClutterReal for fixed/float params.
* - Add Perspective/viewport setup
* - Add Features..
*/
#ifndef __COGL_H__
#define __COGL_H__
#include <glib.h>
#include <clutter/clutter-color.h>
#include <clutter/clutter-feature.h>
#include <clutter/clutter-fixed.h>
#include <clutter/clutter-types.h>
#include <cogl/cogl-defines-@CLUTTER_COGL@.h>
G_BEGIN_DECLS
/* Enum declarations */
#define COGL_PIXEL_FORMAT_24 2
#define COGL_PIXEL_FORMAT_32 3
#define COGL_A_BIT (1 << 4)
#define COGL_BGR_BIT (1 << 5)
#define COGL_AFIRST_BIT (1 << 6)
#define COGL_PREMULT_BIT (1 << 7)
#define COGL_UNORDERED_MASK 0x0F
#define COGL_UNPREMULT_MASK 0x7F
/**
* CoglPixelFormat:
* @COGL_PIXEL_FORMAT_ANY:
* @COGL_PIXEL_FORMAT_A_8:
* @COGL_PIXEL_FORMAT_RGB_888:
* @COGL_PIXEL_FORMAT_BGR_888:
* @COGL_PIXEL_FORMAT_RGBA_8888:
* @COGL_PIXEL_FORMAT_BGRA_8888:
* @COGL_PIXEL_FORMAT_ARGB_8888:
* @COGL_PIXEL_FORMAT_ABGR_8888:
* @COGL_PIXEL_FORMAT_RGBA_8888_PRE:
* @COGL_PIXEL_FORMAT_BGRA_8888_PRE:
* @COGL_PIXEL_FORMAT_ARGB_8888_PRE:
* @COGL_PIXEL_FORMAT_ABGR_8888_PRE:
* @COGL_PIXEL_FORMAT_RGB_565:
* @COGL_PIXEL_FORMAT_RGBA_4444:
* @COGL_PIXEL_FORMAT_RGBA_5551:
* @COGL_PIXEL_FORMAT_RGBA_4444_PRE:
* @COGL_PIXEL_FORMAT_RGBA_5551_PRE:
* @COGL_PIXEL_FORMAT_YUV:
* @COGL_PIXEL_FORMAT_G_8:
*
* Pixel formats used by COGL.
*/
typedef enum
{
COGL_PIXEL_FORMAT_ANY = 0,
COGL_PIXEL_FORMAT_A_8 = 1 | COGL_A_BIT,
COGL_PIXEL_FORMAT_RGB_888 = COGL_PIXEL_FORMAT_24,
COGL_PIXEL_FORMAT_BGR_888 = (COGL_PIXEL_FORMAT_24 | COGL_BGR_BIT),
COGL_PIXEL_FORMAT_RGBA_8888 = COGL_PIXEL_FORMAT_32 | COGL_A_BIT,
COGL_PIXEL_FORMAT_BGRA_8888 = (COGL_PIXEL_FORMAT_32 | COGL_A_BIT | COGL_BGR_BIT),
COGL_PIXEL_FORMAT_ARGB_8888 = (COGL_PIXEL_FORMAT_32 | COGL_A_BIT | COGL_AFIRST_BIT),
COGL_PIXEL_FORMAT_ABGR_8888 = (COGL_PIXEL_FORMAT_32 | COGL_A_BIT | COGL_BGR_BIT | COGL_AFIRST_BIT),
COGL_PIXEL_FORMAT_RGBA_8888_PRE = (COGL_PIXEL_FORMAT_32 | COGL_A_BIT | COGL_PREMULT_BIT),
COGL_PIXEL_FORMAT_BGRA_8888_PRE = (COGL_PIXEL_FORMAT_32 | COGL_A_BIT | COGL_PREMULT_BIT | COGL_BGR_BIT),
COGL_PIXEL_FORMAT_ARGB_8888_PRE = (COGL_PIXEL_FORMAT_32 | COGL_A_BIT | COGL_PREMULT_BIT | COGL_AFIRST_BIT),
COGL_PIXEL_FORMAT_ABGR_8888_PRE = (COGL_PIXEL_FORMAT_32 | COGL_A_BIT | COGL_PREMULT_BIT | COGL_BGR_BIT | COGL_AFIRST_BIT),
COGL_PIXEL_FORMAT_RGB_565 = 4,
COGL_PIXEL_FORMAT_RGBA_4444 = 5 | COGL_A_BIT,
COGL_PIXEL_FORMAT_RGBA_5551 = 6 | COGL_A_BIT,
COGL_PIXEL_FORMAT_RGBA_4444_PRE = (COGL_PIXEL_FORMAT_RGBA_4444 | COGL_A_BIT | COGL_PREMULT_BIT),
COGL_PIXEL_FORMAT_RGBA_5551_PRE = (COGL_PIXEL_FORMAT_RGBA_5551 | COGL_A_BIT | COGL_PREMULT_BIT),
COGL_PIXEL_FORMAT_YUV = 7,
COGL_PIXEL_FORMAT_G_8 = 8
} CoglPixelFormat;
/**
* CoglFeatureFlags:
* @COGL_FEATURE_TEXTURE_RECTANGLE:
* @COGL_FEATURE_TEXTURE_NPOT:
* @COGL_FEATURE_TEXTURE_YUV:
* @COGL_FEATURE_TEXTURE_READ_PIXELS:
* @COGL_FEATURE_SHADERS_GLSL:
* @COGL_FEATURE_OFFSCREEN:
* @COGL_FEATURE_OFFSCREEN_MULTISAMPLE:
* @COGL_FEATURE_OFFSCREEN_BLIT:
* @COGL_FEATURE_FOUR_CLIP_PLANES:
* @COGL_FEATURE_STENCIL_BUFFER:
*
* Flags for the supported features.
*/
typedef enum
{
COGL_FEATURE_TEXTURE_RECTANGLE = (1 << 1),
COGL_FEATURE_TEXTURE_NPOT = (1 << 2),
COGL_FEATURE_TEXTURE_YUV = (1 << 3),
COGL_FEATURE_TEXTURE_READ_PIXELS = (1 << 4),
COGL_FEATURE_SHADERS_GLSL = (1 << 5),
COGL_FEATURE_OFFSCREEN = (1 << 6),
COGL_FEATURE_OFFSCREEN_MULTISAMPLE = (1 << 7),
COGL_FEATURE_OFFSCREEN_BLIT = (1 << 8),
COGL_FEATURE_FOUR_CLIP_PLANES = (1 << 9),
COGL_FEATURE_STENCIL_BUFFER = (1 << 10)
} CoglFeatureFlags;
/**
* CoglBufferTarget:
* @COGL_WINDOW_BUFFER:
* @COGL_MASK_BUFFER:
* @COGL_OFFSCREEN_BUFFER:
*
* FIXME
*/
typedef enum
{
COGL_WINDOW_BUFFER = (1 << 1),
COGL_MASK_BUFFER = (1 << 2),
COGL_OFFSCREEN_BUFFER = (1 << 3)
} CoglBufferTarget;
/**
* CoglTextureVertex:
* @x: Model x-coordinate
* @y: Model y-coordinate
* @z: Model z-coordinate
* @tx: Texture x-coordinate
* @ty: Texture y-coordinate
* @color: The color to use at this vertex. This is ignored if
* @use_color is %FALSE when calling cogl_texture_polygon().
*
* Used to specify vertex information when calling cogl_texture_polygon().
*/
struct _CoglTextureVertex
{
ClutterFixed x, y, z;
ClutterFixed tx, ty;
ClutterColor color;
};
typedef struct _CoglTextureVertex CoglTextureVertex;
/* Context manipulation */
gboolean
cogl_create_context (void);
void
cogl_destroy_context (void);
/* Misc */
#define COGL_INVALID_HANDLE NULL
typedef gpointer CoglHandle;
typedef void (* CoglFuncPtr) (void);
/**
* cogl_get_features:
*
* Returns all of the features supported by COGL.
*
* Return value: A logical OR of all the supported COGL features.
*
* Since: 0.8
*/
ClutterFeatureFlags
cogl_get_features (void);
/**
* cogl_features_available:
* @features: A bitmask of features to check for
*
* Checks whether the given COGL features are available. Multiple
* features can be checked for by or-ing them together with the '|'
* operator. %TRUE is only returned if all of the requested features
* are available.
*
* Return value: %TRUE if the features are available, %FALSE otherwise.
*/
gboolean
cogl_features_available (CoglFeatureFlags features);
/**
* cogl_get_proc_address:
* @name: the name of the function.
*
* Gets a pointer to a given GL or GL ES extension function. This acts
* as a wrapper around glXGetProcAddress() or whatever is the
* appropriate function for the current backend.
*
* Return value: a pointer to the requested function or %NULL if the
* function is not available.
*/
CoglFuncPtr
cogl_get_proc_address (const gchar* name);
gboolean
cogl_check_extension (const gchar *name,
const gchar *ext);
/**
* cogl_get_bitmasks:
* @red: Return location for the number of red bits or %NULL
* @green: Return location for the number of green bits or %NULL
* @blue: Return location for the number of blue bits or %NULL
* @alpha: Return location for the number of alpha bits or %NULL
*
* Gets the number of bitplanes used for each of the color components
* in the color buffer. Pass %NULL for any of the arguments if the
* value is not required.
*/
void
cogl_get_bitmasks (gint *red,
gint *green,
gint *blue,
gint *alpha);
void
cogl_perspective (ClutterFixed fovy,
ClutterFixed aspect,
ClutterFixed zNear,
ClutterFixed zFar);
/**
* cogl_setup_viewport:
* @width: Width of the viewport
* @height: Height of the viewport
* @fovy: Field of view angle in degrees
* @aspect: Aspect ratio to determine the field of view along the x-axis
* @z_near: Nearest visible point along the z-axis
* @z_far: Furthest visible point along the z-axis
*
* Replaces the current viewport and projection matrix with the given
* values. The viewport is placed at the top left corner of the window
* with the given width and height. The projection matrix is replaced
* with one that has a viewing angle of @fovy along the y-axis and a
* view scaled according to @aspect along the x-axis. The view is
* clipped according to @z_near and @z_far on the z-axis.
*/
void
cogl_setup_viewport (guint width,
guint height,
ClutterFixed fovy,
ClutterFixed aspect,
ClutterFixed z_near,
ClutterFixed z_far);
/**
* cogl_push_matrix:
*
* Store the current model-view matrix on the matrix stack. The matrix
* can later be restored with cogl_pop_matrix().
*/
void
cogl_push_matrix (void);
/**
* cogl_pop_matrix:
*
* Restore the current model-view matrix from the matrix stack.
*/
void
cogl_pop_matrix (void);
/**
* cogl_scale:
* @x: Amount to scale along the x-axis
* @y: Amount to scale along the y-axis
*
* Multiplies the current model-view matrix by one that scales the x
* and y axes by the given values.
*/
void
cogl_scale (ClutterFixed x, ClutterFixed y);
/**
* cogl_translatex:
* @x: Distance to translate along the x-axis
* @y: Distance to translate along the y-axis
* @z: Distance to translate along the z-axis
*
* Multiplies the current model-view matrix by one that translates the
* model along all three axes according to the given values.
*/
void
cogl_translatex (ClutterFixed x, ClutterFixed y, ClutterFixed z);
/**
* cogl_translate:
* @x: Distance to translate along the x-axis
* @y: Distance to translate along the y-axis
* @z: Distance to translate along the z-axis
*
* Integer version of cogl_translatex(). Multiplies the current
* model-view matrix by one that translates the model along all three
* axes according to the given values.
*/
void
cogl_translate (gint x, gint y, gint z);
/**
* cogl_rotatex:
* @angle: Angle in degrees to rotate.
* @x: X-component of vertex to rotate around.
* @y: Y-component of vertex to rotate around.
* @z: Z-component of vertex to rotate around.
*
* Multiplies the current model-view matrix by one that rotates the
* model around the vertex specified by @x, @y and @z. The rotation
* follows the right-hand thumb rule so for example rotating by 10
* degrees about the vertex (0, 0, 1) causes a small counter-clockwise
* rotation.
*/
void
cogl_rotatex (ClutterFixed angle, gint x, gint y, gint z);
/**
* cogl_rotate:
* @angle: Angle in degrees to rotate.
* @x: X-component of vertex to rotate around.
* @y: Y-component of vertex to rotate around.
* @z: Z-component of vertex to rotate around.
*
* Integer version of cogl_rotatex(). Multiplies the current
* model-view matrix by one that rotates the model around the vertex
* specified by @x, @y and @z.
*/
void
cogl_rotate (gint angle, gint x, gint y, gint z);
/**
* cogl_get_modelview_matrix:
* @m: pointer to a 4x4 array of #ClutterFixed<!-- -->s to receive the matrix
*
* Stores the current model-view matrix in @m. The matrix is in
* column-major order.
*/
void
cogl_get_modelview_matrix (ClutterFixed m[16]);
/**
* cogl_get_projection_matrix:
* @m: pointer to a 4x4 array of #ClutterFixed<!-- -->s to receive the matrix
*
* Stores the current projection matrix in @m. The matrix is in
* column-major order.
*/
void
cogl_get_projection_matrix (ClutterFixed m[16]);
/**
* cogl_get_viewport:
* @v: pointer to a 4 element array of #ClutterFixed<!-- -->s to
* receive the viewport dimensions.
*
* Stores the current viewport in @v. @v[0] and @v[1] get the x and y
* position of the viewport and @v[2] and @v[3] get the width and
* height.
*/
void
cogl_get_viewport (ClutterFixed v[4]);
/**
* cogl_clip_set:
* @x_offset: left edge of the clip rectangle
* @y_offset: top edge of the clip rectangle
* @width: width of the clip rectangle
* @height: height of the clip rectangle
*
* Specifies a rectangular clipping area for all subsequent drawing
* operations. Any drawing commands that extend outside the rectangle
* will be clipped so that only the portion inside the rectangle will
* be displayed. The rectangle dimensions are transformed by the
* current model-view matrix.
*/
void
cogl_clip_set (ClutterFixed x_offset,
ClutterFixed y_offset,
ClutterFixed width,
ClutterFixed height);
/**
* cogl_clip_unset:
*
* Removes the current clipping rectangle so that all drawing
* operations extend to full size of the viewport again.
*/
void
cogl_clip_unset (void);
/**
* cogl_enable_depth_test:
* @setting: %TRUE to enable depth testing or %FALSE to disable.
*
* Sets whether depth testing is enabled. If it is disabled then the
* order that actors are layered on the screen depends solely on the
* order specified using clutter_actor_raise() and
* clutter_actor_lower(), otherwise it will also take into account the
* actor's depth. Depth testing is disabled by default.
*/
void
cogl_enable_depth_test (gboolean setting);
void
cogl_alpha_func (COGLenum func,
ClutterFixed ref);
/**
* cogl_fog_set:
* @fog_color: The color of the fog
* @density: Ignored
* @z_near: Position along z-axis where no fogging should be applied
* @z_far: Position along z-axes where full fogging should be applied
*
* Enables fogging. Fogging causes vertices that are further away from
* the eye to be rendered with a different color. The color is
* linearly interpolated so that vertices at @z_near are drawn fully
* with their original color and vertices at @z_far are drawn fully
* with @fog_color. Fogging will remain enabled until the next call to
* cogl_paint_init().
*/
void
cogl_fog_set (const ClutterColor *fog_color,
ClutterFixed density,
ClutterFixed z_near,
ClutterFixed z_far);
/**
* cogl_paint_init:
* @color: Background color to clear to
*
* Clears the color buffer to @color. The depth buffer and stencil
* buffers are also cleared and fogging and lighting are disabled.
*/
void
cogl_paint_init (const ClutterColor *color);
/* Textures api */
CoglHandle
cogl_texture_new_with_size (guint width,
guint height,
gint max_waste,
CoglPixelFormat internal_format);
CoglHandle
cogl_texture_new_from_file (const gchar *filename,
gint max_waste,
CoglPixelFormat internal_format,
GError **error);
CoglHandle
cogl_texture_new_from_data (guint width,
guint height,
gint max_waste,
CoglPixelFormat format,
CoglPixelFormat internal_format,
guint rowstride,
const guchar *data);
CoglHandle
cogl_texture_new_from_foreign (GLuint gl_handle,
GLenum gl_target,
GLuint width,
GLuint height,
GLuint x_pot_waste,
GLuint y_pot_waste,
CoglPixelFormat format);
/**
* cogl_is_texture:
* @handle: A CoglHandle
*
* Gets whether the given handle references an existing texture object.
*
* Return value: %TRUE if the handle references a texture,
* %FALSE otherwise
*/
gboolean
cogl_is_texture (CoglHandle handle);
guint
cogl_texture_get_width (CoglHandle handle);
guint
cogl_texture_get_height (CoglHandle handle);
CoglPixelFormat
cogl_texture_get_format (CoglHandle handle);
guint
cogl_texture_get_rowstride (CoglHandle handle);
gint
cogl_texture_get_max_waste (CoglHandle handle);
COGLenum
cogl_texture_get_min_filter (CoglHandle handle);
COGLenum
cogl_texture_get_mag_filter (CoglHandle handle);
gboolean
cogl_texture_is_sliced (CoglHandle handle);
gboolean
cogl_texture_get_gl_texture (CoglHandle handle,
GLuint *out_gl_handle,
GLenum *out_gl_target);
gint
cogl_texture_get_data (CoglHandle handle,
CoglPixelFormat format,
guint rowstride,
guchar *data);
void
cogl_texture_set_filters (CoglHandle handle,
COGLenum min_filter,
COGLenum mag_filter);
gboolean
cogl_texture_set_region (CoglHandle handle,
gint src_x,
gint src_y,
gint dst_x,
gint dst_y,
guint dst_width,
guint dst_height,
gint width,
gint height,
CoglPixelFormat format,
guint rowstride,
const guchar *data);
CoglHandle
cogl_texture_ref (CoglHandle handle);
void
cogl_texture_unref (CoglHandle handle);
void
cogl_texture_rectangle (CoglHandle handle,
ClutterFixed x1,
ClutterFixed y1,
ClutterFixed x2,
ClutterFixed y2,
ClutterFixed tx1,
ClutterFixed ty1,
ClutterFixed tx2,
ClutterFixed ty2);
/**
* cogl_texture_polygon:
* @handle: A CoglHandle for a texture
* @n_vertices: The length of the vertices array
* @vertices: An array of #CoglTextureVertex structs
* @use_color: %TRUE if the color member of #CoglTextureVertex should be used
*
* Draws a polygon from a texture with the given model and texture
* coordinates. This can be used to draw arbitrary shapes textured
* with a COGL texture. If @use_color is %TRUE then the current COGL
* color will be changed for each vertex using the value specified in
* the color member of #CoglTextureVertex. This can be used for
* example to make the texture fade out by setting the alpha value of
* the color.
*
* All of the texture coordinates must be in the range [0,1] and
* repeating the texture is not supported.
*
* Because of the way this function is implemented it will currently
* only work if either the texture is not sliced or the backend is not
* OpenGL ES and the minifying and magnifying functions are both set
* to CGL_NEAREST.
*/
void
cogl_texture_polygon (CoglHandle handle,
guint n_vertices,
CoglTextureVertex *vertices,
gboolean use_color);
/* Primitives API */
void
cogl_color (const ClutterColor *color);
void
cogl_fast_fill_rectangle (gint x,
gint y,
guint width,
guint height);
void
cogl_fast_fill_rectanglex (ClutterFixed x,
ClutterFixed y,
ClutterFixed width,
ClutterFixed height);
void
cogl_fast_fill_trapezoid (gint y1,
gint x11,
gint x21,
gint y2,
gint x12,
gint x22);
void
cogl_fast_fill_trapezoidx (ClutterFixed y1,
ClutterFixed x11,
ClutterFixed x21,
ClutterFixed y2,
ClutterFixed x12,
ClutterFixed x22);
void
cogl_fill ();
void
cogl_stroke ();
void
cogl_path_move_to (ClutterFixed x,
ClutterFixed y);
void
cogl_path_move_to_rel (ClutterFixed x,
ClutterFixed y);
void
cogl_path_line_to (ClutterFixed x,
ClutterFixed y);
void
cogl_path_line_to_rel (ClutterFixed x,
ClutterFixed y);
void
cogl_path_h_line_to (ClutterFixed x);
void
cogl_path_v_line_to (ClutterFixed y);
void
cogl_path_h_line_to_rel (ClutterFixed x);
void
cogl_path_v_line_to_rel (ClutterFixed y);
void
cogl_path_arc (ClutterFixed center_x,
ClutterFixed center_y,
ClutterFixed radius_x,
ClutterFixed radius_y,
ClutterAngle angle_1,
ClutterAngle angle_2,
ClutterAngle angle_step);
void
cogl_path_arc_rel (ClutterFixed center_x,
ClutterFixed center_y,
ClutterFixed radius_x,
ClutterFixed radius_y,
ClutterAngle angle_1,
ClutterAngle angle_2,
ClutterAngle angle_step);
void
cogl_path_bezier2_to (ClutterFixed x1,
ClutterFixed y1,
ClutterFixed x2,
ClutterFixed y2);
void
cogl_path_bezier2_to_rel (ClutterFixed x1,
ClutterFixed y1,
ClutterFixed x2,
ClutterFixed y2);
void
cogl_path_bezier3_to (ClutterFixed x1,
ClutterFixed y1,
ClutterFixed x2,
ClutterFixed y2,
ClutterFixed x3,
ClutterFixed y3);
void
cogl_path_bezier3_to_rel (ClutterFixed x1,
ClutterFixed y1,
ClutterFixed x2,
ClutterFixed y2,
ClutterFixed x3,
ClutterFixed y3);
void
cogl_path_close ();
void
cogl_line (ClutterFixed x1,
ClutterFixed y1,
ClutterFixed x2,
ClutterFixed y2);
void
cogl_polyline (ClutterFixed *coords,
gint num_points);
void
cogl_polygon (ClutterFixed *coords,
gint num_points);
void
cogl_rectangle (ClutterFixed x,
ClutterFixed y,
ClutterFixed width,
ClutterFixed height);
void
cogl_arc (ClutterFixed center_x,
ClutterFixed center_y,
ClutterFixed radius_x,
ClutterFixed radius_y,
ClutterAngle angle_1,
ClutterAngle angle_2,
ClutterAngle angle_step);
void
cogl_ellipse (ClutterFixed center_x,
ClutterFixed center_y,
ClutterFixed radius_x,
ClutterFixed radius_y,
ClutterAngle angle_step);
void
cogl_round_rectangle (ClutterFixed x,
ClutterFixed y,
ClutterFixed width,
ClutterFixed height,
ClutterFixed radius,
ClutterAngle arc_step);
COGLhandle
cogl_create_shader (COGLenum shaderType);
void
cogl_shader_destroy (COGLhandle handle);
void
cogl_shader_source (COGLhandle shader,
const gchar *source);
void
cogl_shader_compile (COGLhandle shader_handle);
void
cogl_shader_get_info_log (COGLhandle handle,
guint size,
gchar *buffer);
void
cogl_shader_get_parameteriv (COGLhandle handle,
COGLenum pname,
COGLint *dest);
COGLhandle
cogl_create_program (void);
void
cogl_program_destroy (COGLhandle handle);
void
cogl_program_attach_shader (COGLhandle program_handle,
COGLhandle shader_handle);
/* 0 to use none */
void
cogl_program_link (COGLhandle program_handle);
void
cogl_program_use (COGLhandle program_handle);
COGLint
cogl_program_get_uniform_location (COGLhandle program_int,
const gchar *uniform_name);
void
cogl_program_uniform_1f (COGLint uniform_no,
gfloat value);
/* Offscreen api */
CoglHandle
cogl_offscreen_new_to_texture (CoglHandle texhandle);
CoglHandle
cogl_offscreen_new_multisample ();
CoglHandle
cogl_offscreen_ref (CoglHandle handle);
void
cogl_offscreen_unref (CoglHandle handle);
void
cogl_offscreen_blit (CoglHandle src_buffer,
CoglHandle dst_buffer);
void
cogl_offscreen_blit_region (CoglHandle src_buffer,
CoglHandle dst_buffer,
int src_x,
int src_y,
int src_w,
int src_h,
int dst_x,
int dst_y,
int dst_w,
int dst_h);
void
cogl_draw_buffer (CoglBufferTarget target, CoglHandle offscreen);
G_END_DECLS
#endif /* __COGL_H__ */

23
common/Makefile.am Normal file
View File

@ -0,0 +1,23 @@
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/clutter \
-I$(top_srcdir)/clutter/cogl \
-I$(top_srcdir)/clutter/cogl/$(CLUTTER_COGL) \
-I$(top_builddir)/clutter \
-I$(top_builddir)/clutter/cogl \
$(CLUTTER_CFLAGS) \
$(CLUTTER_DEBUG_CFLAGS) \
$(GCC_FLAGS)
LDADD = $(CLUTTER_LIBS)
noinst_LTLIBRARIES = libclutter-cogl-common.la
EXTRA_DIST = stb_image.c
libclutter_cogl_common_la_SOURCES = \
cogl-util.h \
cogl-bitmap.h \
cogl-util.c \
cogl-bitmap.c \
cogl-bitmap-fallback.c \
cogl-bitmap-pixbuf.c

View File

@ -0,0 +1,369 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-bitmap.h"
#include <string.h>
/* TO rgba */
inline static void
_cogl_g_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[0];
dst[1] = src[0];
dst[2] = src[0];
dst[3] = 255;
}
inline static void
_cogl_rgb_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = 255;
}
inline static void
_cogl_bgr_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = 255;
}
inline static void
_cogl_bgra_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
}
inline static void
_cogl_argb_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[1];
dst[1] = src[2];
dst[2] = src[3];
dst[3] = src[0];
}
inline static void
_cogl_abgr_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[3];
dst[1] = src[2];
dst[2] = src[1];
dst[3] = src[0];
}
inline static void
_cogl_rgba_to_rgba (const guchar *src, guchar *dst)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = src[3];
}
/* FROM rgba */
inline static void
_cogl_rgba_to_g (const guchar *src, guchar *dst)
{
dst[0] = (src[0] + src[1] + src[2]) / 3;
}
inline static void
_cogl_rgba_to_rgb (const guchar *src, guchar *dst)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
inline static void
_cogl_rgba_to_bgr (const guchar *src, guchar *dst)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
}
inline static void
_cogl_rgba_to_bgra (const guchar *src, guchar *dst)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
}
inline static void
_cogl_rgba_to_argb (const guchar *src, guchar *dst)
{
dst[0] = src[3];
dst[1] = src[0];
dst[2] = src[1];
dst[3] = src[2];
}
inline static void
_cogl_rgba_to_abgr (const guchar *src, guchar *dst)
{
dst[0] = src[3];
dst[1] = src[2];
dst[2] = src[1];
dst[3] = src[0];
}
/* (Un)Premultiplication */
inline static void
_cogl_unpremult_alpha_0 (const guchar *src, guchar *dst)
{
dst[0] = 0;
dst[1] = 0;
dst[2] = 0;
dst[3] = 0;
}
inline static void
_cogl_unpremult_alpha_last (const guchar *src, guchar *dst)
{
guchar alpha = src[3];
dst[0] = (((src[0] >> 16) & 0xff) * 255 ) / alpha;
dst[1] = (((src[1] >> 8) & 0xff) * 255 ) / alpha;
dst[2] = (((src[2] >> 0) & 0xff) * 255 ) / alpha;
dst[3] = alpha;
}
inline static void
_cogl_unpremult_alpha_first (const guchar *src, guchar *dst)
{
guchar alpha = src[0];
dst[0] = alpha;
dst[1] = (((src[1] >> 16) & 0xff) * 255 ) / alpha;
dst[2] = (((src[2] >> 8) & 0xff) * 255 ) / alpha;
dst[3] = (((src[3] >> 0) & 0xff) * 255 ) / alpha;
}
gboolean
_cogl_bitmap_fallback_can_convert (CoglPixelFormat src, CoglPixelFormat dst)
{
if (src == dst)
return FALSE;
switch (src & COGL_UNORDERED_MASK)
{
case COGL_PIXEL_FORMAT_G_8:
case COGL_PIXEL_FORMAT_24:
case COGL_PIXEL_FORMAT_32:
if ((dst & COGL_UNORDERED_MASK) != COGL_PIXEL_FORMAT_24 &&
(dst & COGL_UNORDERED_MASK) != COGL_PIXEL_FORMAT_32 &&
(dst & COGL_UNORDERED_MASK) != COGL_PIXEL_FORMAT_G_8)
return FALSE;
break;
default:
return FALSE;
}
return TRUE;
}
gboolean
_cogl_bitmap_fallback_can_unpremult (CoglPixelFormat format)
{
return ((format & COGL_UNORDERED_MASK) == COGL_PIXEL_FORMAT_32);
}
gboolean
_cogl_bitmap_fallback_convert (const CoglBitmap *bmp,
CoglBitmap *dst_bmp,
CoglPixelFormat dst_format)
{
guchar *src;
guchar *dst;
gint src_bpp;
gint dst_bpp;
gint x,y;
guchar temp_rgba[4] = {0,0,0,0};
/* Make sure conversion supported */
if (!_cogl_bitmap_fallback_can_convert (bmp->format, dst_format))
return FALSE;
src_bpp = _cogl_get_format_bpp (bmp->format);
dst_bpp = _cogl_get_format_bpp (dst_format);
/* Initialize destination bitmap */
*dst_bmp = *bmp;
dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
(dst_format & COGL_UNPREMULT_MASK));
/* Allocate a new buffer to hold converted data */
dst_bmp->data = g_malloc (sizeof(guchar)
* dst_bmp->height
* dst_bmp->rowstride);
/* FIXME: Optimize */
for (y = 0; y < bmp->height; y++)
{
src = (guchar*)bmp->data + y * bmp->rowstride;
dst = (guchar*)dst_bmp->data + y * dst_bmp->rowstride;
for (x = 0; x < bmp->width; x++)
{
/* FIXME: Would be nice to at least remove this inner
* branching, but not sure it can be done without
* rewriting of the whole loop */
switch (bmp->format & COGL_UNPREMULT_MASK)
{
case COGL_PIXEL_FORMAT_G_8:
_cogl_g_to_rgba (src, temp_rgba); break;
case COGL_PIXEL_FORMAT_RGB_888:
_cogl_rgb_to_rgba (src, temp_rgba); break;
case COGL_PIXEL_FORMAT_BGR_888:
_cogl_bgr_to_rgba (src, temp_rgba); break;
case COGL_PIXEL_FORMAT_RGBA_8888:
_cogl_rgba_to_rgba (src, temp_rgba); break;
case COGL_PIXEL_FORMAT_BGRA_8888:
_cogl_bgra_to_rgba (src, temp_rgba); break;
case COGL_PIXEL_FORMAT_ARGB_8888:
_cogl_argb_to_rgba (src, temp_rgba); break;
case COGL_PIXEL_FORMAT_ABGR_8888:
_cogl_abgr_to_rgba (src, temp_rgba); break;
default:
break;
}
switch (dst_format & COGL_UNPREMULT_MASK)
{
case COGL_PIXEL_FORMAT_G_8:
_cogl_rgba_to_g (temp_rgba, dst); break;
case COGL_PIXEL_FORMAT_RGB_888:
_cogl_rgba_to_rgb (temp_rgba, dst); break;
case COGL_PIXEL_FORMAT_BGR_888:
_cogl_rgba_to_bgr (temp_rgba, dst); break;
case COGL_PIXEL_FORMAT_RGBA_8888:
_cogl_rgba_to_rgba (temp_rgba, dst); break;
case COGL_PIXEL_FORMAT_BGRA_8888:
_cogl_rgba_to_bgra (temp_rgba, dst); break;
case COGL_PIXEL_FORMAT_ARGB_8888:
_cogl_rgba_to_argb (temp_rgba, dst); break;
case COGL_PIXEL_FORMAT_ABGR_8888:
_cogl_rgba_to_abgr (temp_rgba, dst); break;
default:
break;
}
src += src_bpp;
dst += dst_bpp;
}
}
return TRUE;
}
gboolean
_cogl_bitmap_fallback_unpremult (const CoglBitmap *bmp,
CoglBitmap *dst_bmp)
{
guchar *src;
guchar *dst;
gint bpp;
gint x,y;
/* Make sure format supported for un-premultiplication */
if (!_cogl_bitmap_fallback_can_unpremult (bmp->format))
return FALSE;
bpp = _cogl_get_format_bpp (bmp->format);
/* Initialize destination bitmap */
*dst_bmp = *bmp;
dst_bmp->format = (bmp->format & COGL_UNPREMULT_MASK);
/* Allocate a new buffer to hold converted data */
dst_bmp->data = g_malloc (sizeof(guchar)
* dst_bmp->height
* dst_bmp->rowstride);
/* FIXME: Optimize */
for (y = 0; y < bmp->height; y++)
{
src = (guchar*)bmp->data + y * bmp->rowstride;
dst = (guchar*)dst_bmp->data + y * dst_bmp->rowstride;
for (x = 0; x < bmp->width; x++)
{
/* FIXME: Would be nice to at least remove this inner
* branching, but not sure it can be done without
* rewriting of the whole loop */
if (bmp->format & COGL_AFIRST_BIT)
{
if (src[0] == 0)
_cogl_unpremult_alpha_0 (src, dst);
else
_cogl_unpremult_alpha_first (src, dst);
}
else
{
if (src[3] == 0)
_cogl_unpremult_alpha_0 (src, dst);
else
_cogl_unpremult_alpha_last (src, dst);
}
src += bpp;
dst += bpp;
}
}
return TRUE;
}
gboolean
_cogl_bitmap_fallback_from_file (CoglBitmap *bmp,
const gchar *filename)
{
/* FIXME: use jpeglib, libpng, etc. manually maybe */
return FALSE;
}

197
common/cogl-bitmap-pixbuf.c Normal file
View File

@ -0,0 +1,197 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-bitmap.h"
#include <string.h>
#ifdef USE_GDKPIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
gboolean
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst)
{
return FALSE;
}
gboolean
_cogl_bitmap_can_unpremult (CoglPixelFormat format)
{
return FALSE;
}
gboolean
_cogl_bitmap_convert (const CoglBitmap *bmp,
CoglBitmap *dst_bmp,
CoglPixelFormat dst_format)
{
return FALSE;
}
gboolean
_cogl_bitmap_unpremult (const CoglBitmap *bmp,
CoglBitmap *dst_bmp)
{
return FALSE;
}
#ifdef USE_GDKPIXBUF
gboolean
_cogl_bitmap_from_file (CoglBitmap *bmp,
const gchar *filename,
GError **error)
{
GdkPixbuf *pixbuf;
gboolean has_alpha;
GdkColorspace color_space;
CoglPixelFormat pixel_format;
gint width;
gint height;
gint rowstride;
gint bits_per_sample;
gint n_channels;
gint last_row_size;
guchar *pixels;
guchar *out_data;
guchar *out;
gint r;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (bmp == NULL) return FALSE;
/* Load from file using GdkPixbuf */
pixbuf = gdk_pixbuf_new_from_file (filename, error);
if (pixbuf == NULL) return FALSE;
/* Get pixbuf properties */
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
color_space = gdk_pixbuf_get_colorspace (pixbuf);
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
/* The docs say this is the right way */
last_row_size = width * ((n_channels * bits_per_sample + 7) / 8);
/* According to current docs this should be true and so
* the translation to cogl pixel format below valid */
g_assert (bits_per_sample == 8);
if (has_alpha)
g_assert (n_channels == 4);
else
g_assert (n_channels == 3);
/* Translate to cogl pixel format */
switch (color_space)
{
case GDK_COLORSPACE_RGB:
/* The only format supported by GdkPixbuf so far */
pixel_format = has_alpha ?
COGL_PIXEL_FORMAT_RGBA_8888 :
COGL_PIXEL_FORMAT_RGB_888;
break;
default:
/* Ouch, spec changed! */
g_object_unref (pixbuf);
return FALSE;
}
/* FIXME: Any way to destroy pixbuf but retain pixel data? */
pixels = gdk_pixbuf_get_pixels (pixbuf);
out_data = (guchar*) g_malloc ((height - 1) * rowstride + last_row_size);
out = out_data;
/* Copy up to last row */
for (r = 0; r < height-1; ++r)
{
memcpy (out, pixels, rowstride);
pixels += rowstride;
out += rowstride;
}
/* Copy last row */
memcpy (out, pixels, last_row_size);
/* Destroy GdkPixbuf object */
g_object_unref (pixbuf);
/* Store bitmap info */
bmp->data = out_data;
bmp->format = pixel_format;
bmp->width = width;
bmp->height = height;
bmp->rowstride = rowstride;
return TRUE;
}
#else
#include "stb_image.c"
gboolean
_cogl_bitmap_from_file (CoglBitmap *bmp,
const gchar *filename,
GError **error)
{
gint stb_pixel_format;
gint width;
gint height;
guchar *pixels;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (bmp == NULL) return FALSE;
/* Load from file using stb */
pixels = stbi_load (filename, &width, &height, &stb_pixel_format, STBI_rgb_alpha);
if (pixels == NULL) return FALSE;
/* Store bitmap info */
bmp->data = pixels;
bmp->format = COGL_PIXEL_FORMAT_RGBA_8888;
bmp->width = width;
bmp->height = height;
bmp->rowstride = width * 4;
g_print ("we successfully used stb_image to load %s\n", filename);
return TRUE;
}
#endif

150
common/cogl-bitmap.c Normal file
View File

@ -0,0 +1,150 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-bitmap.h"
#include <string.h>
gint
_cogl_get_format_bpp (CoglPixelFormat format)
{
gint bpp_lut[] = {
0, /* invalid */
1, /* A_8 */
3, /* 888 */
4, /* 8888 */
2, /* 565 */
2, /* 4444 */
2, /* 5551 */
2, /* YUV */
1 /* G_8 */
};
return bpp_lut [format & COGL_UNORDERED_MASK];
}
gboolean
_cogl_bitmap_convert_and_premult (const CoglBitmap *bmp,
CoglBitmap *dst_bmp,
CoglPixelFormat dst_format)
{
CoglBitmap tmp_bmp = *bmp;
CoglBitmap new_bmp = *bmp;
gboolean new_bmp_owner = FALSE;
/* Is base format different (not considering premult status)? */
if ((bmp->format & COGL_UNPREMULT_MASK) !=
(dst_format & COGL_UNPREMULT_MASK))
{
/* Try converting using imaging library */
if (!_cogl_bitmap_convert (&new_bmp, &tmp_bmp, dst_format))
{
/* ... or try fallback */
if (!_cogl_bitmap_fallback_convert (&new_bmp, &tmp_bmp, dst_format))
return FALSE;
}
/* Update bitmap with new data */
new_bmp = tmp_bmp;
new_bmp_owner = TRUE;
}
/* Do we need to unpremultiply */
if ((bmp->format & COGL_PREMULT_BIT) == 0 &&
(dst_format & COGL_PREMULT_BIT) > 0)
{
/* Try unpremultiplying using imaging library */
if (!_cogl_bitmap_unpremult (&new_bmp, &tmp_bmp))
{
/* ... or try fallback */
if (!_cogl_bitmap_fallback_unpremult (&new_bmp, &tmp_bmp))
{
if (new_bmp_owner)
g_free (new_bmp.data);
return FALSE;
}
}
/* Update bitmap with new data */
if (new_bmp_owner)
g_free (new_bmp.data);
new_bmp = tmp_bmp;
new_bmp_owner = TRUE;
}
/* Do we need to premultiply */
if ((bmp->format & COGL_PREMULT_BIT) > 0 &&
(dst_format & COGL_PREMULT_BIT) == 0)
{
/* FIXME: implement premultiplication */
if (new_bmp_owner)
g_free (new_bmp.data);
return FALSE;
}
/* Output new bitmap info */
*dst_bmp = new_bmp;
return TRUE;
}
void
_cogl_bitmap_copy_subregion (CoglBitmap *src,
CoglBitmap *dst,
gint src_x,
gint src_y,
gint dst_x,
gint dst_y,
gint width,
gint height)
{
guchar *srcdata;
guchar *dstdata;
gint bpp;
gint line;
/* Intended only for fast copies when format is equal! */
g_assert (src->format == dst->format);
bpp = _cogl_get_format_bpp (src->format);
srcdata = src->data + src_y * src->rowstride + src_x * bpp;
dstdata = dst->data + dst_y * dst->rowstride + dst_x * bpp;
for (line=0; line<height; ++line)
{
memcpy (dstdata, srcdata, width * bpp);
srcdata += src->rowstride;
dstdata += dst->rowstride;
}
}

95
common/cogl-bitmap.h Normal file
View File

@ -0,0 +1,95 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_BITMAP_H
#define __COGL_BITMAP_H
#include <glib.h>
typedef struct _CoglBitmap CoglBitmap;
struct _CoglBitmap
{
guchar *data;
CoglPixelFormat format;
gint width;
gint height;
gint rowstride;
};
gboolean
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
gboolean
_cogl_bitmap_fallback_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
gboolean
_cogl_bitmap_can_unpremult (CoglPixelFormat format);
gboolean
_cogl_bitmap_fallback_can_unpremult (CoglPixelFormat format);
gboolean
_cogl_bitmap_convert (const CoglBitmap *bmp,
CoglBitmap *dst_bmp,
CoglPixelFormat dst_format);
gboolean
_cogl_bitmap_fallback_convert (const CoglBitmap *bmp,
CoglBitmap *dst_bmp,
CoglPixelFormat dst_format);
gboolean
_cogl_bitmap_unpremult (const CoglBitmap *bmp,
CoglBitmap *dst_bmp);
gboolean
_cogl_bitmap_fallback_unpremult (const CoglBitmap *bmp,
CoglBitmap *dst_bmp);
gboolean
_cogl_bitmap_from_file (CoglBitmap *bmp,
const gchar *filename,
GError **error);
gboolean
_cogl_bitmap_fallback_from_file (CoglBitmap *bmp,
const gchar *filename);
gboolean
_cogl_bitmap_convert_and_premult (const CoglBitmap *bmp,
CoglBitmap *dst_bmp,
CoglPixelFormat dst_format);
void
_cogl_bitmap_copy_subregion (CoglBitmap *src,
CoglBitmap *dst,
gint src_x,
gint src_y,
gint dst_x,
gint dst_y,
gint width,
gint height);
#endif /* __COGL_BITMAP_H */

51
common/cogl-util.c Normal file
View File

@ -0,0 +1,51 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-util.h"
/**
* cogl_util_next_p2:
* @a: Value to get the next power
*
* Calculates the next power greater than @a.
*
* Return value: The next power after @a.
*/
int
cogl_util_next_p2 (int a)
{
int rval=1;
while(rval < a)
rval <<= 1;
return rval;
}

32
common/cogl-util.h Normal file
View File

@ -0,0 +1,32 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_UTIL_H
#define __COGL_UTIL_H
int
cogl_util_next_p2 (int a);
#endif /* __COGL_UTIL_H */

3772
common/stb_image.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,93 @@
## Process this file with automake to produce Makefile.in
# We require automake 1.6 at least.
AUTOMAKE_OPTIONS = 1.6
# This is a blank Makefile.am for using gtk-doc.
# Copy this to your project's API docs directory and modify the variables to
# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples
# of using the various options.
# The name of the module, e.g. 'glib'.
DOC_MODULE=cogl
# The top-level SGML file. You can change this if you want to.
DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
# The directory containing the source code. Relative to $(srcdir).
# gtk-doc will search all .c & .h files beneath here for inline comments
# documenting the functions and macros.
# e.g. DOC_SOURCE_DIR=../../../gtk
DOC_SOURCE_DIR=../../../clutter/cogl
# Extra options to pass to gtkdoc-scangobj. Not normally needed.
SCANGOBJ_OPTIONS=
# Extra options to supply to gtkdoc-scan.
# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED"
SCAN_OPTIONS=--deprecated-guards="CLUTTER_DISABLE_DEPRECATED"
# Extra options to supply to gtkdoc-mkdb.
# e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml
MKDB_OPTIONS=--sgml-mode --output-format=xml
# Extra options to supply to gtkdoc-mktmpl
# e.g. MKTMPL_OPTIONS=--only-section-tmpl
MKTMPL_OPTIONS=
# Extra options to supply to gtkdoc-fixref. Not normally needed.
# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html
FIXXREF_OPTIONS=\
--extra-dir=$(GLIB_PREFIX)/share/gtk-doc/html/glib \
--extra-dir=$(GDPIXBUF_PREFIX)/share/gtk-doc/html/gdk-pixbuf \
--extra-dir=$(top_srcdir)/doc/reference/clutter/html
# Used for dependencies. The docs will be rebuilt if any of these change.
# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h
# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c
HFILE_GLOB=\
$(top_srcdir)/clutter/cogl/*.h \
$(top_srcdir)/clutter/cogl/common/*.h
CFILE_GLOB=\
$(top_srcdir)/clutter/cogl/common/*.c
# Header files to ignore when scanning.
# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h
IGNORE_HFILES=\
cogl-bitmap.h \
cogl-context.h \
cogl-defines.h \
cogl-internal.h \
cogl-primitives.h \
cogl-texture.h
EXTRA_HFILES=
# Images to copy into HTML directory.
# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
HTML_IMAGES=
# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE).
# e.g. content_files=running.sgml building.sgml changes-2.0.sgml
content_files=
# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded
# These files must be listed here *and* in content_files
# e.g. expand_content_files=running.sgml
expand_content_files=
# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
# Only needed if you are using gtkdoc-scangobj to dynamically query widget
# signals and properties.
# e.g. INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS)
# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib)
INCLUDES=-I$(top_srcdir) -I$(top_srcdir)/clutter $(CLUTTER_CFLAGS)
GTKDOC_LIBS=$(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la $(CLUTTER_LIBS)
# This includes the standard gtk-doc make rules, copied by gtkdocize.
include $(top_srcdir)/gtk-doc.make
# Other files to distribute
# e.g. EXTRA_DIST += version.xml.in
EXTRA_DIST =

View File

@ -0,0 +1,57 @@
<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
<bookinfo>
<title>COGL Reference Manual</title>
<releaseinfo>
</releaseinfo>
<copyright>
<year>2008</year>
<holder>OpenedHand LTD</holder>
</copyright>
<legalnotice>
<para>
Permission is granted to copy, distribute and/or modify this
document under the terms of the <citetitle>GNU Free
Documentation License</citetitle>, Version 1.1 or any later
version published by the Free Software Foundation with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. You may obtain a copy of the <citetitle>GNU Free
Documentation License</citetitle> from the Free Software
Foundation by visiting <ulink type="http"
url="http://www.fsf.org">their Web site</ulink> or by writing
to:
<address>
The Free Software Foundation, Inc.,
<street>59 Temple Place</street> - Suite 330,
<city>Boston</city>, <state>MA</state> <postcode>02111-1307</postcode>
,
<country>USA</country>
</address>
</para>
</legalnotice>
</bookinfo>
<chapter>
<title>COGL - GL Abstraction API</title>
<section id="cogl-intro">
<title>About COGL</title>
<para>
FIXME
</para>
</section>
<xi:include href="xml/cogl.xml"/>
<xi:include href="xml/cogl-primitives.xml"/>
<xi:include href="xml/cogl-util.xml"/>
<xi:include href="xml/cogl-texture.xml"/>
<xi:include href="xml/cogl-shaders.xml"/>
<xi:include href="xml/cogl-offscreen.xml"/>
</chapter>
</book>

View File

@ -0,0 +1,148 @@
<SECTION>
<FILE>cogl</FILE>
<TITLE>General API</TITLE>
COGL_PIXEL_FORMAT_24
COGL_PIXEL_FORMAT_32
COGL_A_BIT
COGL_BGR_BIT
COGL_AFIRST_BIT
COGL_PREMULT_BIT
COGL_UNORDERED_MASK
COGL_UNPREMULT_MASK
CoglPixelFormat
CoglBufferTarget
<SUBSECTION>
cogl_perspective
cogl_setup_viewport
cogl_get_modelview_matrix
cogl_get_projection_matrix
cogl_get_viewport
<SUBSECTION>
cogl_push_matrix
cogl_pop_matrix
cogl_scale
cogl_translatex
cogl_translate
cogl_rotatex
cogl_rotate
<SUBSECTION>
cogl_clip_set
cogl_clip_unset
<SUBSECTION>
cogl_enable_depth_test
cogl_alpha_func
cogl_fog_set
</SECTION>
<SECTION>
<FILE>cogl-util</FILE>
<TITLE>Utility API</TITLE>
cogl_create_context
cogl_destroy_context
COGL_INVALID_HANDLE
CoglHandle
CoglFuncPtr
<SUBSECTION>
CoglFeatureFlags
cogl_get_features
cogl_features_available
<SUBSECTION>
cogl_get_proc_address
cogl_check_extension
cogl_get_bitmasks
cogl_paint_init
<SUBSECTION>
cogl_util_next_p2
</SECTION>
<SECTION>
<FILE>cogl-primitives</FILE>
<TITLE>Primitives</TITLE>
cogl_color
cogl_fast_fill_rectangle
cogl_fast_fill_rectanglex
cogl_fast_fill_trapezoid
cogl_fast_fill_trapezoidx
cogl_fill
cogl_stroke
cogl_path_move_to
cogl_path_move_to_rel
cogl_path_line_to
cogl_path_line_to_rel
cogl_path_h_line_to
cogl_path_v_line_to
cogl_path_h_line_to_rel
cogl_path_v_line_to_rel
cogl_path_arc
cogl_path_arc_rel
cogl_path_bezier2_to
cogl_path_bezier2_to_rel
cogl_path_bezier3_to
cogl_path_bezier3_to_rel
cogl_path_close
cogl_line
cogl_polyline
cogl_polygon
cogl_rectangle
cogl_arc
cogl_ellipse
cogl_round_rectangle
</SECTION>
<SECTION>
<FILE>cogl-texture</FILE>
<TITLE>Textures</TITLE>
CoglTextureVertex
cogl_texture_new_with_size
cogl_texture_new_from_file
cogl_texture_new_from_data
cogl_texture_new_from_foreign
cogl_is_texture
cogl_texture_get_width
cogl_texture_get_height
cogl_texture_get_format
cogl_texture_get_rowstride
cogl_texture_get_max_waste
cogl_texture_get_min_filter
cogl_texture_get_mag_filter
cogl_texture_is_sliced
cogl_texture_get_gl_texture
cogl_texture_get_data
cogl_texture_set_filters
cogl_texture_set_region
cogl_texture_ref
cogl_texture_unref
cogl_texture_rectangle
cogl_texture_polygon
</SECTION>
<SECTION>
<FILE>cogl-shaders</FILE>
<TITLE>Shaders and Programmable Pipeline</TITLE>
cogl_create_shader
cogl_shader_destroy
cogl_shader_source
cogl_shader_compile
cogl_shader_get_info_log
cogl_shader_get_parameteriv
<SUBSECTION>
cogl_create_program
cogl_program_destroy
cogl_program_attach_shader
cogl_program_link
cogl_program_use
cogl_program_get_uniform_location
cogl_program_uniform_1f
</SECTION>
<SECTION>
<FILE>cogl-offscreen</FILE>
<TITLE>Offscreen Buffers</TITLE>
cogl_offscreen_new_to_texture
cogl_offscreen_new_multisample
cogl_offscreen_ref
cogl_offscreen_unref
cogl_offscreen_blit
cogl_offscreen_blit_region
cogl_draw_buffer
</SECTION>

View File

@ -1,19 +1,36 @@
libclutterincludedir = $(includedir)/clutter-@CLUTTER_API_VERSION@/clutter
libclutterinclude_HEADERS = $(top_srcdir)/clutter/cogl/cogl.h \
$(top_srcdir)/clutter/cogl/gl/cogl-defines.h
libclutterincludedir = $(includedir)/clutter-@CLUTTER_API_VERSION@/cogl
libclutterinclude_HEADERS = $(top_builddir)/clutter/cogl/cogl.h \
$(top_builddir)/clutter/cogl/cogl-defines-gl.h
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir) \
-I$(top_srcdir)/clutter \
-I$(top_srcdir)/clutter/cogl \
$(CLUTTER_CFLAGS) \
$(CLUTTER_DEBUG_CFLAGS) \
-I$(top_srcdir)/clutter/cogl/common \
-I$(top_srcdir)/clutter/cogl/$(CLUTTER_COGL) \
-I$(top_builddir)/clutter \
-I$(top_builddir)/clutter/cogl \
$(CLUTTER_CFLAGS) \
$(CLUTTER_DEBUG_CFLAGS) \
$(GCC_FLAGS)
LDADD = $(CLUTTER_LIBS)
noinst_LTLIBRARIES = libclutter-cogl.la
libclutter_cogl_la_SOURCES = \
$(top_srcdir)/clutter/cogl/cogl.h \
$(top_srcdir)/clutter/cogl/gl/cogl-defines.h \
cogl.c
libclutter_cogl_la_SOURCES = \
$(top_builddir)/clutter/cogl/cogl.h \
$(top_builddir)/clutter/cogl/gl/cogl-defines.h \
cogl-defines.h \
cogl-internal.h \
cogl-primitives.h \
cogl-texture.h \
cogl-fbo.h \
cogl-context.h \
cogl.c \
cogl-primitives.c \
cogl-texture.c \
cogl-fbo.c \
cogl-context.c
libclutter_cogl_la_LIBADD = $(top_builddir)/clutter/cogl/common/libclutter-cogl-common.la

114
gl/cogl-context.c Normal file
View File

@ -0,0 +1,114 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-util.h"
#include "cogl-context.h"
#include <string.h>
static CoglContext *_context = NULL;
gboolean
cogl_create_context ()
{
if (_context != NULL)
return FALSE;
/* Allocate context memory */
_context = (CoglContext*) g_malloc (sizeof (CoglContext));
/* Init default values */
_context->feature_flags = 0;
_context->features_cached = FALSE;
_context->enable_flags = 0;
_context->color_alpha = 255;
_context->path_nodes = NULL;
_context->path_nodes_cap = 0;
_context->path_nodes_size = 0;
_context->texture_handles = NULL;
_context->fbo_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER;
_context->pf_glGenRenderbuffersEXT = NULL;
_context->pf_glBindRenderbufferEXT = NULL;
_context->pf_glRenderbufferStorageEXT = NULL;
_context->pf_glGenFramebuffersEXT = NULL;
_context->pf_glBindFramebufferEXT = NULL;
_context->pf_glFramebufferTexture2DEXT = NULL;
_context->pf_glFramebufferRenderbufferEXT = NULL;
_context->pf_glCheckFramebufferStatusEXT = NULL;
_context->pf_glDeleteFramebuffersEXT = NULL;
_context->pf_glBlitFramebufferEXT = NULL;
_context->pf_glRenderbufferStorageMultisampleEXT = NULL;
_context->pf_glCreateProgramObjectARB = NULL;
_context->pf_glCreateShaderObjectARB = NULL;
_context->pf_glShaderSourceARB = NULL;
_context->pf_glCompileShaderARB = NULL;
_context->pf_glAttachObjectARB = NULL;
_context->pf_glLinkProgramARB = NULL;
_context->pf_glUseProgramObjectARB = NULL;
_context->pf_glGetUniformLocationARB = NULL;
_context->pf_glDeleteObjectARB = NULL;
_context->pf_glGetInfoLogARB = NULL;
_context->pf_glGetObjectParameterivARB = NULL;
_context->pf_glUniform1fARB = NULL;
/* Init OpenGL state */
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColorMask (TRUE, TRUE, TRUE, FALSE);
cogl_enable (0);
return TRUE;
}
void
cogl_destroy_context ()
{
if (_context == NULL)
return;
g_free (_context);
}
CoglContext *
_cogl_context_get_default ()
{
/* Create if doesn't exist yet */
if (_context == NULL)
cogl_create_context ();
return _context;
}

95
gl/cogl-context.h Normal file
View File

@ -0,0 +1,95 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_CONTEXT_H
#define __COGL_CONTEXT_H
#include "cogl-primitives.h"
typedef struct
{
/* Features cache */
CoglFeatureFlags feature_flags;
gboolean features_cached;
/* Enable cache */
gulong enable_flags;
guint8 color_alpha;
/* Primitives */
CoglFixedVec2 path_start;
CoglFixedVec2 path_pen;
CoglFloatVec2 *path_nodes;
guint path_nodes_cap;
guint path_nodes_size;
CoglFixedVec2 path_nodes_min;
CoglFixedVec2 path_nodes_max;
/* Textures */
GArray *texture_handles;
/* Framebuffer objects */
GArray *fbo_handles;
CoglBufferTarget draw_buffer;
/* Relying on glext.h to define these */
PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT;
PFNGLBINDRENDERBUFFEREXTPROC pf_glBindRenderbufferEXT;
PFNGLRENDERBUFFERSTORAGEEXTPROC pf_glRenderbufferStorageEXT;
PFNGLGENFRAMEBUFFERSEXTPROC pf_glGenFramebuffersEXT;
PFNGLBINDFRAMEBUFFEREXTPROC pf_glBindFramebufferEXT;
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC pf_glFramebufferTexture2DEXT;
PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC pf_glFramebufferRenderbufferEXT;
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC pf_glCheckFramebufferStatusEXT;
PFNGLDELETEFRAMEBUFFERSEXTPROC pf_glDeleteFramebuffersEXT;
PFNGLBLITFRAMEBUFFEREXTPROC pf_glBlitFramebufferEXT;
PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC pf_glRenderbufferStorageMultisampleEXT;
PFNGLCREATEPROGRAMOBJECTARBPROC pf_glCreateProgramObjectARB;
PFNGLCREATESHADEROBJECTARBPROC pf_glCreateShaderObjectARB;
PFNGLSHADERSOURCEARBPROC pf_glShaderSourceARB;
PFNGLCOMPILESHADERARBPROC pf_glCompileShaderARB;
PFNGLATTACHOBJECTARBPROC pf_glAttachObjectARB;
PFNGLLINKPROGRAMARBPROC pf_glLinkProgramARB;
PFNGLUSEPROGRAMOBJECTARBPROC pf_glUseProgramObjectARB;
PFNGLGETUNIFORMLOCATIONARBPROC pf_glGetUniformLocationARB;
PFNGLDELETEOBJECTARBPROC pf_glDeleteObjectARB;
PFNGLGETINFOLOGARBPROC pf_glGetInfoLogARB;
PFNGLGETOBJECTPARAMETERIVARBPROC pf_glGetObjectParameterivARB;
PFNGLUNIFORM1FARBPROC pf_glUniform1fARB;
} CoglContext;
CoglContext *
_cogl_context_get_default ();
/* Obtains the context and returns retval if NULL */
#define _COGL_GET_CONTEXT(ctxvar, retval) \
CoglContext *ctxvar = _cogl_context_get_default (); \
if (ctxvar == NULL) return retval;
#define NO_RETVAL
#endif /* __COGL_CONTEXT_H */

390
gl/cogl-fbo.c Normal file
View File

@ -0,0 +1,390 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-util.h"
#include "cogl-texture.h"
#include "cogl-fbo.h"
#include "cogl-context.h"
/* Expecting EXT functions not to be defined - redirect to pointers in context */
#define glGenRenderbuffersEXT ctx->pf_glGenRenderbuffersEXT
#define glBindRenderbufferEXT ctx->pf_glBindRenderbufferEXT
#define glRenderbufferStorageEXT ctx->pf_glRenderbufferStorageEXT
#define glGenFramebuffersEXT ctx->pf_glGenFramebuffersEXT
#define glBindFramebufferEXT ctx->pf_glBindFramebufferEXT
#define glFramebufferTexture2DEXT ctx->pf_glFramebufferTexture2DEXT
#define glFramebufferRenderbufferEXT ctx->pf_glFramebufferRenderbufferEXT
#define glCheckFramebufferStatusEXT ctx->pf_glCheckFramebufferStatusEXT
#define glDeleteFramebuffersEXT ctx->pf_glDeleteFramebuffersEXT
#define glBlitFramebufferEXT ctx->pf_glBlitFramebufferEXT
#define glRenderbufferStorageMultisampleEXT ctx->pf_glRenderbufferStorageMultisampleEXT
static gint
_cogl_fbo_handle_find (CoglHandle handle)
{
_COGL_GET_CONTEXT (ctx, -1);
gint i;
if (ctx->fbo_handles == NULL)
return -1;
for (i=0; i < ctx->fbo_handles->len; ++i)
if (g_array_index (ctx->fbo_handles, CoglHandle, i) == handle)
return i;
return -1;
}
static CoglHandle
_cogl_fbo_handle_new (CoglFbo *fbo)
{
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
CoglHandle handle = (CoglHandle)fbo;
if (ctx->fbo_handles == NULL)
ctx->fbo_handles = g_array_new (FALSE, FALSE, sizeof (CoglHandle));
g_array_append_val (ctx->fbo_handles, handle);
return handle;
}
static void
_cogl_fbo_handle_release (CoglHandle handle)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
gint i;
if ( (i = _cogl_fbo_handle_find (handle)) == -1)
return;
g_array_remove_index_fast (ctx->fbo_handles, i);
}
static CoglFbo*
_cogl_fbo_pointer_from_handle (CoglHandle handle)
{
return (CoglFbo*) handle;
}
gboolean
cogl_is_offscreen_buffer (CoglHandle handle)
{
if (handle == COGL_INVALID_HANDLE)
return FALSE;
return _cogl_fbo_handle_find (handle) >= 0;
}
CoglHandle
cogl_offscreen_new_to_texture (CoglHandle texhandle)
{
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
if (!cogl_features_available (COGL_FEATURE_OFFSCREEN))
return COGL_INVALID_HANDLE;
CoglTexture *tex;
CoglFbo *fbo;
CoglTexSliceSpan *x_span;
CoglTexSliceSpan *y_span;
GLuint tex_gl_handle;
GLuint fbo_gl_handle;
GLenum status;
/* Make texhandle is a valid texture object */
if (!cogl_is_texture (texhandle))
return COGL_INVALID_HANDLE;
tex = _cogl_texture_pointer_from_handle (texhandle);
/* The texture must not be sliced */
if (tex->slice_gl_handles == NULL)
return COGL_INVALID_HANDLE;
if (tex->slice_gl_handles->len != 1)
return COGL_INVALID_HANDLE;
/* Pick the single texture slice width, height and GL id */
x_span = &g_array_index (tex->slice_x_spans, CoglTexSliceSpan, 0);
y_span = &g_array_index (tex->slice_y_spans, CoglTexSliceSpan, 0);
tex_gl_handle = g_array_index (tex->slice_gl_handles, GLuint, 0);
/* Generate framebuffer */
glGenFramebuffersEXT (1, &fbo_gl_handle);
GE( glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo_gl_handle) );
GE( glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
tex->gl_target, tex_gl_handle, 0) );
/* Make sure it's complete */
status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
{
GE( glDeleteFramebuffersEXT (1, &fbo_gl_handle) );
GE( glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0) );
return COGL_INVALID_HANDLE;
}
GE( glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0) );
/* Allocate and init a CoglFbo object (store non-wasted size
for subsequent blits and viewport setup) */
fbo = (CoglFbo*) g_malloc (sizeof (CoglFbo));
fbo->ref_count = 1;
fbo->width = x_span->size - x_span->waste;
fbo->height = y_span->size - y_span->waste;
fbo->gl_handle = fbo_gl_handle;
return _cogl_fbo_handle_new (fbo);
}
CoglHandle
cogl_offscreen_new_multisample ()
{
if (!cogl_features_available (COGL_FEATURE_OFFSCREEN_MULTISAMPLE))
return COGL_INVALID_HANDLE;
return COGL_INVALID_HANDLE;
}
CoglHandle
cogl_offscreen_ref (CoglHandle handle)
{
CoglFbo *fbo;
if (!cogl_is_offscreen_buffer (handle))
return COGL_INVALID_HANDLE;
fbo = _cogl_fbo_pointer_from_handle (handle);
fbo->ref_count++;
return handle;
}
void
cogl_offscreen_unref (CoglHandle handle)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
CoglFbo *fbo;
/* Make sure this is a valid fbo handle */
if (!cogl_is_offscreen_buffer (handle))
return;
fbo = _cogl_fbo_pointer_from_handle (handle);
if (--fbo->ref_count < 1)
{
/* Release handle and destroy object */
GE( glDeleteFramebuffersEXT (1, &fbo->gl_handle) );
_cogl_fbo_handle_release (handle);
g_free (fbo);
}
}
void
cogl_offscreen_blit_region (CoglHandle src_buffer,
CoglHandle dst_buffer,
int src_x,
int src_y,
int src_w,
int src_h,
int dst_x,
int dst_y,
int dst_w,
int dst_h)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (!cogl_features_available (COGL_FEATURE_OFFSCREEN_BLIT))
return;
CoglFbo *src_fbo;
CoglFbo *dst_fbo;
/* Make sure these are valid fbo handles */
if (!cogl_is_offscreen_buffer (src_buffer))
return;
if (!cogl_is_offscreen_buffer (dst_buffer))
return;
src_fbo = _cogl_fbo_pointer_from_handle (src_buffer);
dst_fbo = _cogl_fbo_pointer_from_handle (dst_buffer);
/* Copy (and scale) a region from one to another framebuffer */
GE( glBindFramebufferEXT (GL_READ_FRAMEBUFFER_EXT, src_fbo->gl_handle) );
GE( glBindFramebufferEXT (GL_DRAW_FRAMEBUFFER_EXT, dst_fbo->gl_handle) );
GE( glBlitFramebufferEXT (src_x, src_y, src_x + src_w, src_y + src_h,
dst_x, dst_y, dst_x + dst_w, dst_y + dst_h,
GL_COLOR_BUFFER_BIT, GL_LINEAR) );
}
void
cogl_offscreen_blit (CoglHandle src_buffer,
CoglHandle dst_buffer)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (!cogl_features_available (COGL_FEATURE_OFFSCREEN_BLIT))
return;
CoglFbo *src_fbo;
CoglFbo *dst_fbo;
/* Make sure these are valid fbo handles */
if (!cogl_is_offscreen_buffer (src_buffer))
return;
if (!cogl_is_offscreen_buffer (dst_buffer))
return;
src_fbo = _cogl_fbo_pointer_from_handle (src_buffer);
dst_fbo = _cogl_fbo_pointer_from_handle (dst_buffer);
/* Copy (and scale) whole image from one to another framebuffer */
GE( glBindFramebufferEXT (GL_READ_FRAMEBUFFER_EXT, src_fbo->gl_handle) );
GE( glBindFramebufferEXT (GL_DRAW_FRAMEBUFFER_EXT, dst_fbo->gl_handle) );
GE( glBlitFramebufferEXT (0, 0, src_fbo->width, src_fbo->height,
0, 0, dst_fbo->width, dst_fbo->height,
GL_COLOR_BUFFER_BIT, GL_LINEAR) );
}
void
cogl_draw_buffer (CoglBufferTarget target, CoglHandle offscreen)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
CoglFbo *fbo = NULL;
if (target == COGL_OFFSCREEN_BUFFER)
{
/* Make sure it is a valid fbo handle */
if (!cogl_is_offscreen_buffer (offscreen))
return;
fbo = _cogl_fbo_pointer_from_handle (offscreen);
/* Check current draw buffer target */
if (ctx->draw_buffer != COGL_OFFSCREEN_BUFFER)
{
/* Push the viewport and matrix setup if redirecting
from a non-screen buffer */
GE( glPushAttrib (GL_VIEWPORT_BIT) );
GE( glMatrixMode (GL_PROJECTION) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
}
else
{
/* Override viewport and matrix setup if redirecting
from another offscreen buffer */
GE( glMatrixMode (GL_PROJECTION) );
GE( glLoadIdentity () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glLoadIdentity () );
}
/* Setup new viewport and matrices */
GE( glViewport (0, 0, fbo->width, fbo->height) );
GE( glTranslatef (-1.0f, -1.0f, 0.0f) );
GE( glScalef (2.0f / fbo->width, 2.0f / fbo->height, 1.0f) );
/* Bind offscreen framebuffer object */
GE( glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo->gl_handle) );
GE( glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) );
/* Some implementation require a clear before drawing
to an fbo. Luckily it is affected by scissor test. */
/* FIXME: test where exactly this is needed end whether
a glClear with 0 argument is enough */
GE( glPushAttrib (GL_SCISSOR_BIT) );
GE( glScissor (0,0,0,0) );
GE( glEnable (GL_SCISSOR_TEST) );
GE( glClear (GL_COLOR_BUFFER_BIT) );
GE( glPopAttrib () );
}
else if ((target & COGL_WINDOW_BUFFER) ||
(target & COGL_MASK_BUFFER))
{
/* Check current draw buffer target */
if (ctx->draw_buffer == COGL_OFFSCREEN_BUFFER)
{
/* Pop viewport and matrices if redirecting back
from an offscreen buffer */
GE( glPopAttrib () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glPopMatrix () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPopMatrix () );
}
/* Bind window framebuffer object */
GE( glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0) );
if (target == COGL_WINDOW_BUFFER)
{
/* Draw to RGB channels */
GE( glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE) );
}
else if (target == COGL_MASK_BUFFER)
{
/* Draw only to ALPHA channel */
GE( glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE) );
}
else
{
/* Draw to all channels */
GE( glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) );
}
}
/* Store new target */
ctx->draw_buffer = target;
}

38
gl/cogl-fbo.h Normal file
View File

@ -0,0 +1,38 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_FBO_H
#define __COGL_FBO_H
typedef struct
{
guint ref_count;
int width;
int height;
GLuint gl_handle;
} CoglFbo;
#endif /* __COGL_FBO_H */

61
gl/cogl-internal.h Normal file
View File

@ -0,0 +1,61 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_INTERNAL_H
#define __COGL_INTERNAL_H
#define COGL_DEBUG 0
#if COGL_DEBUG
#define GE(x...) G_STMT_START { \
GLenum err; \
(x); \
while ((err = glGetError()) != GL_NO_ERROR) { \
fprintf(stderr, "glError: %s caught at %s:%u\n", \
(char *)error_string(err), \
__FILE__, __LINE__); \
} \
} G_STMT_END
#else
#define GE(x) (x);
#endif
#define COGL_ENABLE_BLEND (1<<1)
#define COGL_ENABLE_TEXTURE_2D (1<<2)
#define COGL_ENABLE_ALPHA_TEST (1<<3)
#define COGL_ENABLE_TEXTURE_RECT (1<<4)
#define COGL_ENABLE_VERTEX_ARRAY (1<<5)
#define COGL_ENABLE_TEXCOORD_ARRAY (1<<6)
gint
_cogl_get_format_bpp (CoglPixelFormat format);
void
cogl_enable (gulong flags);
gulong
cogl_get_enable ();
#endif /* __COGL_INTERNAL_H */

1092
gl/cogl-primitives.c Normal file

File diff suppressed because it is too large Load Diff

61
gl/cogl-primitives.h Normal file
View File

@ -0,0 +1,61 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_PRIMITIVES_H
#define __COGL_PRIMITIVES_H
typedef struct _CoglFixedVec2 CoglFixedVec2;
typedef struct _CoglFloatVec2 CoglFloatVec2;
typedef struct _CoglBezQuad CoglBezQuad;
typedef struct _CoglBezCubic CoglBezCubic;
struct _CoglFixedVec2
{
ClutterFixed x;
ClutterFixed y;
};
struct _CoglFloatVec2
{
GLfloat x;
GLfloat y;
};
struct _CoglBezQuad
{
CoglFixedVec2 p1;
CoglFixedVec2 p2;
CoglFixedVec2 p3;
};
struct _CoglBezCubic
{
CoglFixedVec2 p1;
CoglFixedVec2 p2;
CoglFixedVec2 p3;
CoglFixedVec2 p4;
};
#endif /* __COGL_PRIMITIVES_H */

2303
gl/cogl-texture.c Normal file

File diff suppressed because it is too large Load Diff

64
gl/cogl-texture.h Normal file
View File

@ -0,0 +1,64 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_TEXTURE_H
#define __COGL_TEXTURE_H
#include "cogl-bitmap.h"
typedef struct _CoglTexture CoglTexture;
typedef struct _CoglTexSliceSpan CoglTexSliceSpan;
typedef struct _CoglSpanIter CoglSpanIter;
struct _CoglTexSliceSpan
{
gint start;
gint size;
gint waste;
};
struct _CoglTexture
{
guint ref_count;
CoglBitmap bitmap;
gboolean bitmap_owner;
GLenum gl_target;
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
GArray *slice_x_spans;
GArray *slice_y_spans;
GArray *slice_gl_handles;
gint max_waste;
COGLenum min_filter;
COGLenum mag_filter;
gboolean is_foreign;
GLint wrap_mode;
};
CoglTexture*
_cogl_texture_pointer_from_handle (CoglHandle handle);
#endif /* __COGL_TEXTURE_H */

794
gl/cogl.c
View File

@ -39,23 +39,12 @@
typedef CoglFuncPtr (*GLXGetProcAddressProc) (const guint8 *procName);
#endif
static gulong __enable_flags = 0;
#include "cogl-internal.h"
#include "cogl-util.h"
#include "cogl-context.h"
/* FBO Procs */
typedef void (*GenFramebuffers) (GLsizei n, GLuint *ids);
typedef void (*BindFramebuffer) (GLenum target, GLuint framebuffer);
typedef void (*FramebufferTexture2D) (GLenum target, GLenum attachment,
GLenum textarget, GLuint texture,
GLint level);
typedef GLenum (*CheckFramebufferStatus)(GLenum target);
typedef void (*DeleteFramebuffers) (GLsizei n, const GLuint *framebuffers);
static GenFramebuffers _gen_framebuffers = NULL;
static BindFramebuffer _bind_framebuffer = NULL;
static FramebufferTexture2D _framebuffer_texture_2d = NULL;
static CheckFramebufferStatus _check_framebuffer_status = NULL;
static DeleteFramebuffers _delete_framebuffers = NULL;
/* GL error to string conversion */
#if COGL_DEBUG
struct token_string
{
@ -89,19 +78,21 @@ error_string(GLenum errorCode)
}
#endif
#if COGL_DEBUG
#define GE(x...) G_STMT_START { \
GLenum err; \
(x); \
while ((err = glGetError()) != GL_NO_ERROR) { \
fprintf(stderr, "glError: %s caught at %s:%u\n", \
(char *)error_string(err), \
__FILE__, __LINE__); \
} \
} G_STMT_END
#else
#define GE(x) (x);
#endif
/* Expecting ARB functions not to be defined */
#define glCreateProgramObjectARB ctx->pf_glCreateProgramObjectARB
#define glCreateShaderObjectARB ctx->pf_glCreateShaderObjectARB
#define glShaderSourceARB ctx->pf_glShaderSourceARB
#define glCompileShaderARB ctx->pf_glCompileShaderARB
#define glAttachObjectARB ctx->pf_glAttachObjectARB
#define glLinkProgramARB ctx->pf_glLinkProgramARB
#define glUseProgramObjectARB ctx->pf_glUseProgramObjectARB
#define glGetUniformLocationARB ctx->pf_glGetUniformLocationARB
#define glDeleteObjectARB ctx->pf_glDeleteObjectARB
#define glGetInfoLogARB ctx->pf_glGetInfoLogARB
#define glGetObjectParameterivARB ctx->pf_glGetObjectParameterivARB
#define glUniform1fARB ctx->pf_glUniform1fARB
CoglFuncPtr
cogl_get_proc_address (const gchar* name)
@ -217,9 +208,6 @@ cogl_paint_init (const ClutterColor *color)
* glDepthFunc (GL_LEQUAL);
* glAlphaFunc (GL_GREATER, 0.1);
*/
cogl_enable (CGL_ENABLE_BLEND);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
/* FIXME: inline most of these */
@ -272,59 +260,155 @@ cogl_rotate (gint angle, gint x, gint y, gint z)
glRotatef ((float)angle, (float)x, (float)y, (float)z);
}
static inline gboolean
cogl_toggle_flag (CoglContext *ctx,
gulong new_flags,
gulong flag,
GLenum gl_flag)
{
/* Toggles and caches a single enable flag on or off
* by comparing to current state
*/
if (new_flags & flag)
{
if (!(ctx->enable_flags & flag))
{
GE( glEnable (gl_flag) );
ctx->enable_flags |= flag;
return TRUE;
}
}
else if (ctx->enable_flags & flag)
{
GE( glDisable (gl_flag) );
ctx->enable_flags &= ~flag;
}
return FALSE;
}
static inline gboolean
cogl_toggle_client_flag (CoglContext *ctx,
gulong new_flags,
gulong flag,
GLenum gl_flag)
{
/* Toggles and caches a single client-side enable flag
* on or off by comparing to current state
*/
if (new_flags & flag)
{
if (!(ctx->enable_flags & flag))
{
GE( glEnableClientState (gl_flag) );
ctx->enable_flags |= flag;
return TRUE;
}
}
else if (ctx->enable_flags & flag)
{
GE( glDisableClientState (gl_flag) );
ctx->enable_flags &= ~flag;
}
return FALSE;
}
void
cogl_enable (gulong flags)
{
/* This function essentially caches glEnable state() in the
* hope of lessening number GL traffic.
*/
if (flags & CGL_ENABLE_BLEND)
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (cogl_toggle_flag (ctx, flags,
COGL_ENABLE_BLEND,
GL_BLEND))
{
if (!(__enable_flags & CGL_ENABLE_BLEND))
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
cogl_toggle_flag (ctx, flags,
COGL_ENABLE_TEXTURE_2D,
GL_TEXTURE_2D);
cogl_toggle_client_flag (ctx, flags,
COGL_ENABLE_VERTEX_ARRAY,
GL_VERTEX_ARRAY);
cogl_toggle_client_flag (ctx, flags,
COGL_ENABLE_TEXCOORD_ARRAY,
GL_TEXTURE_COORD_ARRAY);
#ifdef GL_TEXTURE_RECTANGLE_ARB
cogl_toggle_flag (ctx, flags,
COGL_ENABLE_TEXTURE_RECT,
GL_TEXTURE_RECTANGLE_ARB);
#endif
}
gulong
cogl_get_enable ()
{
_COGL_GET_CONTEXT (ctx, 0);
return ctx->enable_flags;
}
/*
void
cogl_enable (gulong flags)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (flags & COGL_ENABLE_BLEND)
{
if (!(ctx->enable_flags & COGL_ENABLE_BLEND))
{
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
__enable_flags |= CGL_ENABLE_BLEND;
ctx->enable_flags |= COGL_ENABLE_BLEND;
}
}
else if (__enable_flags & CGL_ENABLE_BLEND)
else if (ctx->enable_flags & COGL_ENABLE_BLEND)
{
glDisable (GL_BLEND);
__enable_flags &= ~CGL_ENABLE_BLEND;
ctx->enable_flags &= ~COGL_ENABLE_BLEND;
}
if (flags & CGL_ENABLE_TEXTURE_2D)
if (flags & COGL_ENABLE_TEXTURE_2D)
{
if (!(__enable_flags & CGL_ENABLE_TEXTURE_2D))
if (!(ctx->enable_flags & COGL_ENABLE_TEXTURE_2D))
{
glEnable (GL_TEXTURE_2D);
__enable_flags |= CGL_ENABLE_TEXTURE_2D;
ctx->enable_flags |= COGL_ENABLE_TEXTURE_2D;
}
}
else if (__enable_flags & CGL_ENABLE_TEXTURE_2D)
else if (ctx->enable_flags & COGL_ENABLE_TEXTURE_2D)
{
glDisable (GL_TEXTURE_2D);
__enable_flags &= ~CGL_ENABLE_TEXTURE_2D;
ctx->enable_flags &= ~COGL_ENABLE_TEXTURE_2D;
}
#ifdef GL_TEXTURE_RECTANGLE_ARB
if (flags & CGL_ENABLE_TEXTURE_RECT)
if (flags & COGL_ENABLE_TEXTURE_RECT)
{
if (!(__enable_flags & CGL_ENABLE_TEXTURE_RECT))
if (!(ctx->enable_flags & COGL_ENABLE_TEXTURE_RECT))
{
glEnable (GL_TEXTURE_RECTANGLE_ARB);
__enable_flags |= CGL_ENABLE_TEXTURE_RECT;
ctx->enable_flags |= COGL_ENABLE_TEXTURE_RECT;
}
}
else if (__enable_flags & CGL_ENABLE_TEXTURE_RECT)
else if (ctx->enable_flags & COGL_ENABLE_TEXTURE_RECT)
{
glDisable (GL_TEXTURE_RECTANGLE_ARB);
__enable_flags &= ~CGL_ENABLE_TEXTURE_RECT;
ctx->enable_flags &= ~COGL_ENABLE_TEXTURE_RECT;
}
#endif
}
*/
void
cogl_enable_depth_test (gboolean setting)
{
@ -345,7 +429,15 @@ cogl_enable_depth_test (gboolean setting)
void
cogl_color (const ClutterColor *color)
{
glColor4ub (color->red, color->green, color->blue, color->alpha);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glColor4ub (color->red,
color->green,
color->blue,
color->alpha);
/* Store alpha for proper blending enables */
ctx->color_alpha = color->alpha;
}
void
@ -354,197 +446,63 @@ cogl_clip_set (ClutterFixed x_offset,
ClutterFixed width,
ClutterFixed height)
{
GE( glEnable (GL_STENCIL_TEST) );
if (cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES))
{
GLdouble eqn_left[4] = { 1.0, 0, 0,
-CLUTTER_FIXED_TO_FLOAT (x_offset) };
GLdouble eqn_right[4] = { -1.0, 0, 0,
CLUTTER_FIXED_TO_FLOAT (x_offset + width) };
GLdouble eqn_top[4] = { 0, 1.0, 0, -CLUTTER_FIXED_TO_FLOAT (y_offset) };
GLdouble eqn_bottom[4] = { 0, -1.0, 0, CLUTTER_FIXED_TO_FLOAT
(y_offset + height) };
GE( glClearStencil (0.0f) );
GE( glClear (GL_STENCIL_BUFFER_BIT) );
GE( glClipPlane (GL_CLIP_PLANE0, eqn_left) );
GE( glClipPlane (GL_CLIP_PLANE1, eqn_right) );
GE( glClipPlane (GL_CLIP_PLANE2, eqn_top) );
GE( glClipPlane (GL_CLIP_PLANE3, eqn_bottom) );
GE( glEnable (GL_CLIP_PLANE0) );
GE( glEnable (GL_CLIP_PLANE1) );
GE( glEnable (GL_CLIP_PLANE2) );
GE( glEnable (GL_CLIP_PLANE3) );
}
else if (cogl_features_available (COGL_FEATURE_STENCIL_BUFFER))
{
GE( glEnable (GL_STENCIL_TEST) );
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
GE( glClearStencil (0.0f) );
GE( glClear (GL_STENCIL_BUFFER_BIT) );
GE( glColor3f (1.0f, 1.0f, 1.0f) );
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
GE( glRectf (CLUTTER_FIXED_TO_FLOAT (x_offset),
CLUTTER_FIXED_TO_FLOAT (y_offset),
CLUTTER_FIXED_TO_FLOAT (x_offset + width),
CLUTTER_FIXED_TO_FLOAT (y_offset + height)) );
GE( glColor3f (1.0f, 1.0f, 1.0f) );
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
GE( glRectf (CLUTTER_FIXED_TO_FLOAT (x_offset),
CLUTTER_FIXED_TO_FLOAT (y_offset),
CLUTTER_FIXED_TO_FLOAT (x_offset + width),
CLUTTER_FIXED_TO_FLOAT (y_offset + height)) );
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
}
}
void
cogl_clip_unset (void)
{
GE( glDisable (GL_STENCIL_TEST) );
}
gboolean
cogl_texture_can_size (COGLenum target,
COGLenum pixel_format,
COGLenum pixel_type,
int width,
int height)
{
#ifdef GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB
if (target == CGL_TEXTURE_RECTANGLE_ARB)
if (cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES))
{
GLint max_size = 0;
GE( glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &max_size) );
return (max_size && width <= max_size && height <= max_size);
GE( glDisable (GL_CLIP_PLANE3) );
GE( glDisable (GL_CLIP_PLANE2) );
GE( glDisable (GL_CLIP_PLANE1) );
GE( glDisable (GL_CLIP_PLANE0) );
}
else /* Assumes CGL_TEXTURE_2D */
#endif
else if (cogl_features_available (COGL_FEATURE_STENCIL_BUFFER))
{
GLint new_width = 0;
GE( glTexImage2D (GL_PROXY_TEXTURE_2D, 0, GL_RGBA,
width, height, 0 /* border */,
pixel_format, pixel_type, NULL) );
GE( glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0,
GL_TEXTURE_WIDTH, &new_width) );
return new_width != 0;
GE( glDisable (GL_STENCIL_TEST) );
}
}
void
cogl_texture_quad (gint x1,
gint x2,
gint y1,
gint y2,
ClutterFixed tx1,
ClutterFixed ty1,
ClutterFixed tx2,
ClutterFixed ty2)
{
gdouble txf1, tyf1, txf2, tyf2;
txf1 = CLUTTER_FIXED_TO_DOUBLE (tx1);
tyf1 = CLUTTER_FIXED_TO_DOUBLE (ty1);
txf2 = CLUTTER_FIXED_TO_DOUBLE (tx2);
tyf2 = CLUTTER_FIXED_TO_DOUBLE (ty2);
glBegin (GL_QUADS);
glTexCoord2f (txf2, tyf2); glVertex2i (x2, y2);
glTexCoord2f (txf1, tyf2); glVertex2i (x1, y2);
glTexCoord2f (txf1, tyf1); glVertex2i (x1, y1);
glTexCoord2f (txf2, tyf1); glVertex2i (x2, y1);
glEnd ();
}
void
cogl_textures_create (guint num, COGLuint *textures)
{
GE( glGenTextures (num, textures) );
}
void
cogl_textures_destroy (guint num, const COGLuint *textures)
{
GE( glDeleteTextures (num, textures) );
}
void
cogl_texture_bind (COGLenum target, COGLuint texture)
{
GE( glBindTexture (target, texture) );
}
void
cogl_texture_set_alignment (COGLenum target,
guint alignment,
guint row_length)
{
GE( glPixelStorei (GL_UNPACK_ROW_LENGTH, row_length) );
GE( glPixelStorei (GL_UNPACK_ALIGNMENT, alignment) );
}
void
cogl_texture_set_filters (COGLenum target,
COGLenum min_filter,
COGLenum max_filter)
{
GE( glTexParameteri(target, GL_TEXTURE_MAG_FILTER, max_filter) );
GE( glTexParameteri(target, GL_TEXTURE_MIN_FILTER, min_filter) );
}
void
cogl_texture_set_wrap (COGLenum target,
COGLenum wrap_s,
COGLenum wrap_t)
{
GE( glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap_s) );
GE( glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap_s) );
}
void
cogl_texture_image_2d (COGLenum target,
COGLint internal_format,
gint width,
gint height,
COGLenum format,
COGLenum type,
const guchar* pixels)
{
GE( glTexImage2D (target,
0, /* No mipmap support as yet */
internal_format,
width,
height,
0, /* 0 pixel border */
format,
type,
pixels) );
}
void
cogl_texture_sub_image_2d (COGLenum target,
gint xoff,
gint yoff,
gint width,
gint height,
COGLenum format,
COGLenum type,
const guchar* pixels)
{
GE( glTexSubImage2D (target,
0,
xoff,
yoff,
width,
height,
format,
type,
pixels));
}
void
cogl_rectangle (gint x, gint y, guint width, guint height)
{
GE( glRecti (x, y, x + width, y + height) );
}
/* FIXME: Should use ClutterReal or Fixed */
void
cogl_trapezoid (gint y1,
gint x11,
gint x21,
gint y2,
gint x12,
gint x22)
{
GE( glBegin (GL_QUADS) );
GE( glVertex2i (x11, y1) );
GE( glVertex2i (x21, y1) );
GE( glVertex2i (x22, y2) );
GE( glVertex2i (x12, y2) );
GE( glEnd () );
}
void
cogl_alpha_func (COGLenum func,
ClutterFixed ref)
@ -649,13 +607,17 @@ cogl_setup_viewport (guint width,
GE( glTranslatef (0.0f, -1.0 * height, 0.0f) );
}
ClutterFeatureFlags
cogl_get_features ()
static void
_cogl_features_init ()
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
ClutterFeatureFlags flags = 0;
const gchar *gl_extensions;
int max_clip_planes = 0;
int stencil_bits = 0;
flags = CLUTTER_FEATURE_TEXTURE_READ_PIXELS;
flags = COGL_FEATURE_TEXTURE_READ_PIXELS;
gl_extensions = (const gchar*) glGetString (GL_EXTENSIONS);
@ -663,53 +625,194 @@ cogl_get_features ()
if (cogl_check_extension ("GL_ARB_texture_rectangle", gl_extensions) ||
cogl_check_extension ("GL_EXT_texture_rectangle", gl_extensions))
{
flags |= CLUTTER_FEATURE_TEXTURE_RECTANGLE;
flags |= COGL_FEATURE_TEXTURE_RECTANGLE;
}
#endif
if (cogl_check_extension ("GL_ARB_texture_non_power_of_two", gl_extensions))
{
flags |= COGL_FEATURE_TEXTURE_NPOT;
}
#ifdef GL_YCBCR_MESA
if (cogl_check_extension ("GL_MESA_ycbcr_texture", gl_extensions))
{
flags |= CLUTTER_FEATURE_TEXTURE_YUV;
flags |= COGL_FEATURE_TEXTURE_YUV;
}
#endif
if (cogl_check_extension ("GL_ARB_vertex_shader", gl_extensions) &&
if (cogl_check_extension ("GL_ARB_shader_objects", gl_extensions) &&
cogl_check_extension ("GL_ARB_vertex_shader", gl_extensions) &&
cogl_check_extension ("GL_ARB_fragment_shader", gl_extensions))
{
flags |= CLUTTER_FEATURE_SHADERS_GLSL;
ctx->pf_glCreateProgramObjectARB =
(PFNGLCREATEPROGRAMOBJECTARBPROC)
cogl_get_proc_address ("glCreateProgramObjectARB");
ctx->pf_glCreateShaderObjectARB =
(PFNGLCREATESHADEROBJECTARBPROC)
cogl_get_proc_address ("glCreateShaderObjectARB");
ctx->pf_glShaderSourceARB =
(PFNGLSHADERSOURCEARBPROC)
cogl_get_proc_address ("glShaderSourceARB");
ctx->pf_glCompileShaderARB =
(PFNGLCOMPILESHADERARBPROC)
cogl_get_proc_address ("glCompileShaderARB");
ctx->pf_glAttachObjectARB =
(PFNGLATTACHOBJECTARBPROC)
cogl_get_proc_address ("glAttachObjectARB");
ctx->pf_glLinkProgramARB =
(PFNGLLINKPROGRAMARBPROC)
cogl_get_proc_address ("glLinkProgramARB");
ctx->pf_glUseProgramObjectARB =
(PFNGLUSEPROGRAMOBJECTARBPROC)
cogl_get_proc_address ("glUseProgramObjectARB");
ctx->pf_glGetUniformLocationARB =
(PFNGLGETUNIFORMLOCATIONARBPROC)
cogl_get_proc_address ("glGetUniformLocationARB");
ctx->pf_glDeleteObjectARB =
(PFNGLDELETEOBJECTARBPROC)
cogl_get_proc_address ("glDeleteObjectARB");
ctx->pf_glGetInfoLogARB =
(PFNGLGETINFOLOGARBPROC)
cogl_get_proc_address ("glGetInfoLogARB");
ctx->pf_glGetObjectParameterivARB =
(PFNGLGETOBJECTPARAMETERIVARBPROC)
cogl_get_proc_address ("glGetObjectParameterivARB");
ctx->pf_glUniform1fARB =
(PFNGLUNIFORM1FARBPROC)
cogl_get_proc_address ("glUniform1fARB");
if (ctx->pf_glCreateProgramObjectARB &&
ctx->pf_glCreateShaderObjectARB &&
ctx->pf_glShaderSourceARB &&
ctx->pf_glCompileShaderARB &&
ctx->pf_glAttachObjectARB &&
ctx->pf_glLinkProgramARB &&
ctx->pf_glUseProgramObjectARB &&
ctx->pf_glGetUniformLocationARB &&
ctx->pf_glDeleteObjectARB &&
ctx->pf_glGetInfoLogARB &&
ctx->pf_glGetObjectParameterivARB &&
ctx->pf_glUniform1fARB)
flags |= COGL_FEATURE_SHADERS_GLSL;
}
if (cogl_check_extension ("GL_EXT_framebuffer_object", gl_extensions) ||
cogl_check_extension ("GL_ARB_framebuffer_object", gl_extensions))
{
_gen_framebuffers =
(GenFramebuffers) cogl_get_proc_address ("glGenFramebuffersEXT");
ctx->pf_glGenRenderbuffersEXT =
(PFNGLGENRENDERBUFFERSEXTPROC)
cogl_get_proc_address ("glGenRenderbuffersEXT");
_bind_framebuffer =
(BindFramebuffer) cogl_get_proc_address ("glBindFramebufferEXT");
ctx->pf_glBindRenderbufferEXT =
(PFNGLBINDRENDERBUFFEREXTPROC)
cogl_get_proc_address ("glBindRenderbufferEXT");
_framebuffer_texture_2d =
(FramebufferTexture2D)
cogl_get_proc_address ("glFramebufferTexture2DEXT");
ctx->pf_glRenderbufferStorageEXT =
(PFNGLRENDERBUFFERSTORAGEEXTPROC)
cogl_get_proc_address ("glRenderbufferStorageEXT");
_check_framebuffer_status =
(CheckFramebufferStatus)
cogl_get_proc_address ("glCheckFramebufferStatusEXT");
ctx->pf_glGenFramebuffersEXT =
(PFNGLGENFRAMEBUFFERSEXTPROC)
cogl_get_proc_address ("glGenFramebuffersEXT");
_delete_framebuffers =
(DeleteFramebuffers)
cogl_get_proc_address ("glDeleteFramebuffersEXT");
ctx->pf_glBindFramebufferEXT =
(PFNGLBINDFRAMEBUFFEREXTPROC)
cogl_get_proc_address ("glBindFramebufferEXT");
if (_gen_framebuffers
&& _bind_framebuffer
&& _framebuffer_texture_2d
&& _check_framebuffer_status
&& _delete_framebuffers)
flags |= CLUTTER_FEATURE_OFFSCREEN;
ctx->pf_glFramebufferTexture2DEXT =
(PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)
cogl_get_proc_address ("glFramebufferTexture2DEXT");
ctx->pf_glFramebufferRenderbufferEXT =
(PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)
cogl_get_proc_address ("glFramebufferRenderbufferEXT");
ctx->pf_glCheckFramebufferStatusEXT =
(PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)
cogl_get_proc_address ("glCheckFramebufferStatusEXT");
ctx->pf_glDeleteFramebuffersEXT =
(PFNGLDELETEFRAMEBUFFERSEXTPROC)
cogl_get_proc_address ("glDeleteFramebuffersEXT");
if (ctx->pf_glGenRenderbuffersEXT &&
ctx->pf_glBindRenderbufferEXT &&
ctx->pf_glRenderbufferStorageEXT &&
ctx->pf_glGenFramebuffersEXT &&
ctx->pf_glBindFramebufferEXT &&
ctx->pf_glFramebufferTexture2DEXT &&
ctx->pf_glFramebufferRenderbufferEXT &&
ctx->pf_glCheckFramebufferStatusEXT &&
ctx->pf_glDeleteFramebuffersEXT)
flags |= COGL_FEATURE_OFFSCREEN;
}
return flags;
if (cogl_check_extension ("GL_EXT_framebuffer_blit", gl_extensions))
{
ctx->pf_glBlitFramebufferEXT =
(PFNGLBLITFRAMEBUFFEREXTPROC)
cogl_get_proc_address ("glBlitFramebufferEXT");
if (ctx->pf_glBlitFramebufferEXT)
flags |= COGL_FEATURE_OFFSCREEN_BLIT;
}
if (cogl_check_extension ("GL_EXT_framebuffer_multisample", gl_extensions))
{
ctx->pf_glRenderbufferStorageMultisampleEXT =
(PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC)
cogl_get_proc_address ("glRenderbufferStorageMultisampleEXT");
if (ctx->pf_glRenderbufferStorageMultisampleEXT)
flags |= COGL_FEATURE_OFFSCREEN_MULTISAMPLE;
}
GE( glGetIntegerv (GL_STENCIL_BITS, &stencil_bits) );
if (stencil_bits > 0)
flags |= COGL_FEATURE_STENCIL_BUFFER;
GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
if (max_clip_planes >= 4)
flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
/* Cache features */
ctx->feature_flags = flags;
ctx->features_cached = TRUE;
}
ClutterFeatureFlags
cogl_get_features ()
{
_COGL_GET_CONTEXT (ctx, 0);
if (!ctx->features_cached)
_cogl_features_init ();
return ctx->feature_flags;
}
gboolean
cogl_features_available (CoglFeatureFlags features)
{
_COGL_GET_CONTEXT (ctx, 0);
if (!ctx->features_cached)
_cogl_features_init ();
return (ctx->feature_flags & features) == features;
}
void
@ -835,217 +938,79 @@ cogl_fog_set (const ClutterColor *fog_color,
glFogf (GL_FOG_END, CLUTTER_FIXED_TO_FLOAT (stop));
}
/* FBOs - offscreen */
COGLuint
cogl_offscreen_create (COGLuint target_texture)
{
#ifdef GL_FRAMEBUFFER_EXT
COGLuint handle;
GLenum status;
if (_gen_framebuffers == NULL
|| _bind_framebuffer == NULL
|| _framebuffer_texture_2d == NULL
|| _check_framebuffer_status == NULL)
{
/* tmp warning - need error reporting */
g_warning("Missing GL_FRAMEBUFFER_EXT API\n");
return 0;
}
_gen_framebuffers (1, &handle);
_bind_framebuffer (GL_FRAMEBUFFER_EXT, handle);
_framebuffer_texture_2d (GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_RECTANGLE_ARB,
target_texture,
0);
status = _check_framebuffer_status (GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
{
_delete_framebuffers (1, &handle);
return 0;
}
_bind_framebuffer (GL_FRAMEBUFFER_EXT, 0);
return handle;
#else
/* tmp warning - need error reporting */
g_warning("No GL_FRAMEBUFFER_EXT\n");
return 0;
#endif
}
void
cogl_offscreen_destroy (COGLuint offscreen_handle)
{
if (_delete_framebuffers)
_delete_framebuffers (1, &offscreen_handle);
}
void
cogl_offscreen_redirect_start (COGLuint offscreen_handle,
gint width,
gint height)
{
/* FIXME: silly we need to pass width / height to init viewport */
#ifdef GL_FRAMEBUFFER_EXT
if (_bind_framebuffer == NULL)
return;
_bind_framebuffer (GL_FRAMEBUFFER_EXT, offscreen_handle);
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity ();
glMatrixMode (GL_MODELVIEW);
glPushMatrix();
glLoadIdentity ();
glTranslatef (-1.0f, -1.0f, 0.0f);
glScalef (2.0f / (float)width, 2.0f / (float)height, 1.0f);
/* Clear the scene, appears needed on some backends - OSX */
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
#endif
}
void
cogl_offscreen_redirect_end (COGLuint offscreen_handle,
gint width,
gint height)
{
/* FIXME: silly we need to pass width / height to reset to */
if (_bind_framebuffer == NULL)
return;
#ifdef GL_FRAMEBUFFER_EXT
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glPopMatrix();
glMatrixMode (GL_MODELVIEW);
glPopMatrix();
_bind_framebuffer (GL_FRAMEBUFFER_EXT, 0);
#endif
}
/* Shader Magic follows */
#ifdef __GNUC__
#define PROC(rettype, retval, procname, args...) \
static rettype (*proc) (args) = NULL; \
if (proc == NULL) \
{ \
proc = (void*)cogl_get_proc_address (#procname);\
if (!proc)\
{\
g_warning ("failed to lookup proc: %s", #procname);\
return retval;\
}\
}
#else
#define PROC(rettype, retval, procname, ...) \
static rettype (*proc) (__VA_ARGS__) = NULL; \
if (proc == NULL) \
{ \
proc = (void*)cogl_get_proc_address (#procname);\
if (!proc)\
{\
g_warning ("failed to lookup proc: %s", #procname);\
return retval;\
}\
}
#endif
COGLhandle
cogl_create_program (void)
{
PROC (GLhandleARB, 0, glCreateProgramObjectARB, void);
return proc ();
_COGL_GET_CONTEXT (ctx, 0);
return glCreateProgramObjectARB ();
}
COGLhandle
cogl_create_shader (COGLenum shaderType)
{
PROC (GLhandleARB, 0, glCreateShaderObjectARB, GLenum);
return proc (shaderType);
_COGL_GET_CONTEXT (ctx, 0);
return glCreateShaderObjectARB (shaderType);
}
void
cogl_shader_source (COGLhandle shader,
const gchar *source)
{
PROC (GLvoid,, glShaderSourceARB, GLhandleARB, GLsizei, const GLcharARB **, const GLint *)
proc (shader, 1, &source, NULL);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glShaderSourceARB (shader, 1, &source, NULL);
}
void
cogl_shader_compile (COGLhandle shader_handle)
{
PROC (GLvoid,, glCompileShaderARB, GLhandleARB);
proc (shader_handle);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glCompileShaderARB (shader_handle);
}
void
cogl_program_attach_shader (COGLhandle program_handle,
COGLhandle shader_handle)
{
PROC (GLvoid,, glAttachObjectARB, GLhandleARB, GLhandleARB);
proc (program_handle, shader_handle);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glAttachObjectARB (program_handle, shader_handle);
}
void
cogl_program_link (COGLhandle program_handle)
{
PROC (GLvoid,, glLinkProgramARB, GLhandleARB);
proc (program_handle);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glLinkProgramARB (program_handle);
}
void
cogl_program_use (COGLhandle program_handle)
{
PROC (GLvoid,, glUseProgramObjectARB, GLhandleARB);
proc (program_handle);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glUseProgramObjectARB (program_handle);
}
COGLint
cogl_program_get_uniform_location (COGLhandle program_handle,
const gchar *uniform_name)
{
PROC (GLint,0, glGetUniformLocationARB, GLhandleARB, const GLcharARB *)
return proc (program_handle, uniform_name);
_COGL_GET_CONTEXT (ctx, 0);
return glGetUniformLocationARB (program_handle, uniform_name);
}
void
cogl_program_destroy (COGLhandle handle)
{
PROC (GLvoid,, glDeleteObjectARB, GLhandleARB);
proc (handle);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glDeleteObjectARB (handle);
}
void
cogl_shader_destroy (COGLhandle handle)
{
PROC (GLvoid,, glDeleteObjectARB, GLhandleARB);
proc (handle);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glDeleteObjectARB (handle);
}
void
@ -1054,8 +1019,8 @@ cogl_shader_get_info_log (COGLhandle handle,
gchar *buffer)
{
COGLint len;
PROC (GLvoid,, glGetInfoLogARB, GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
proc (handle, size-1, &len, buffer);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glGetInfoLogARB (handle, size-1, &len, buffer);
buffer[len]='\0';
}
@ -1064,15 +1029,14 @@ cogl_shader_get_parameteriv (COGLhandle handle,
COGLenum pname,
COGLint *dest)
{
PROC (GLvoid,, glGetObjectParameterivARB, GLhandleARB, GLenum, GLint*)
proc (handle, pname, dest);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glGetObjectParameterivARB (handle, pname, dest);
}
void
cogl_program_uniform_1f (COGLint uniform_no,
gfloat value)
{
PROC (GLvoid,, glUniform1fARB, GLint, GLfloat);
proc (uniform_no, value);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glUniform1fARB (uniform_no, value);
}

View File

@ -1,19 +1,36 @@
libclutterincludedir = $(includedir)/clutter-@CLUTTER_API_VERSION@/clutter
libclutterinclude_HEADERS = $(top_srcdir)/clutter/cogl/cogl.h \
$(top_srcdir)/clutter/cogl/gles/cogl-defines.h
libclutterincludedir = $(includedir)/clutter-@CLUTTER_API_VERSION@/cogl
libclutterinclude_HEADERS = $(top_builddir)/clutter/cogl/cogl.h \
$(top_builddir)/clutter/cogl/cogl-defines-gles.h
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir) \
-I$(top_srcdir)/clutter \
-I$(top_srcdir)/clutter/cogl \
$(CLUTTER_CFLAGS) \
$(CLUTTER_DEBUG_CFLAGS) \
-I$(top_srcdir)/clutter/cogl/common \
-I$(top_srcdir)/clutter/cogl/$(CLUTTER_COGL) \
-I$(top_builddir)/clutter \
-I$(top_builddir)/clutter/cogl \
$(CLUTTER_CFLAGS) \
$(CLUTTER_DEBUG_CFLAGS) \
$(GCC_FLAGS)
LDADD = $(CLUTTER_LIBS)
noinst_LTLIBRARIES = libclutter-cogl.la
libclutter_cogl_la_SOURCES = \
$(top_srcdir)/clutter/cogl/cogl.h \
$(top_srcdir)/clutter/cogl/gl/cogl-defines.h \
cogl.c
libclutter_cogl_la_SOURCES = \
$(top_builddir)/clutter/cogl/cogl.h \
$(top_builddir)/clutter/cogl/gles/cogl-defines.h \
cogl-defines.h \
cogl-internal.h \
cogl-primitives.h \
cogl-texture.h \
cogl-fbo.h \
cogl-context.h \
cogl.c \
cogl-primitives.c \
cogl-texture.c \
cogl-fbo.c \
cogl-context.c
libclutter_cogl_la_LIBADD = $(top_builddir)/clutter/cogl/common/libclutter-cogl-common.la

96
gles/cogl-context.c Normal file
View File

@ -0,0 +1,96 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include <GLES/gl.h>
#include <string.h>
#include "cogl-internal.h"
#include "cogl-util.h"
#include "cogl-context.h"
static CoglContext *_context = NULL;
gboolean
cogl_create_context ()
{
if (_context != NULL)
return FALSE;
/* Allocate context memory */
_context = (CoglContext*) g_malloc (sizeof (CoglContext));
/* Init default values */
_context->feature_flags = 0;
_context->features_cached = FALSE;
_context->enable_flags = 0;
_context->color_alpha = 255;
_context->path_nodes = NULL;
_context->path_nodes_cap = 0;
_context->path_nodes_size = 0;
_context->texture_handles = NULL;
_context->texture_vertices_size = 0;
_context->texture_vertices = NULL;
_context->fbo_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER;
/* Init OpenGL state */
glTexEnvx (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColorMask (TRUE, TRUE, TRUE, FALSE);
cogl_enable (0);
return TRUE;
}
void
cogl_destroy_context ()
{
if (_context == NULL)
return;
if (_context->texture_vertices)
g_free (_context->texture_vertices);
g_free (_context);
}
CoglContext *
_cogl_context_get_default ()
{
/* Create if doesn't exists yet */
if (_context == NULL)
cogl_create_context ();
return _context;
}

78
gles/cogl-context.h Normal file
View File

@ -0,0 +1,78 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_CONTEXT_H
#define __COGL_CONTEXT_H
#include "cogl-primitives.h"
typedef struct
{
GLfixed v[3];
GLfixed t[2];
GLfixed c[4];
} CoglTextureGLVertex;
typedef struct
{
/* Features cache */
CoglFeatureFlags feature_flags;
gboolean features_cached;
/* Enable cache */
gulong enable_flags;
guint8 color_alpha;
/* Primitives */
CoglFixedVec2 path_start;
CoglFixedVec2 path_pen;
CoglFixedVec2 *path_nodes;
guint path_nodes_cap;
guint path_nodes_size;
CoglFixedVec2 path_nodes_min;
CoglFixedVec2 path_nodes_max;
/* Textures */
GArray *texture_handles;
CoglTextureGLVertex *texture_vertices;
gulong texture_vertices_size;
/* Framebuffer objects */
GArray *fbo_handles;
CoglBufferTarget draw_buffer;
} CoglContext;
CoglContext *
_cogl_context_get_default ();
/* Obtains the context and returns retval if NULL */
#define _COGL_GET_CONTEXT(ctxvar, retval) \
CoglContext *ctxvar = _cogl_context_get_default (); \
if (ctxvar == NULL) return retval;
#define NO_RETVAL
#endif /* __COGL_CONTEXT_H */

View File

@ -444,18 +444,6 @@ typedef GLuint COGLhandle;
/* extras */
#define CGL_TEXTURE_2D GL_TEXTURE_2D
#define CGL_ARGB GL_ARGB
/* FIXME: There is no BGR support in GLES - so with below BGR textures are
* borked. Will likely need a feature flag and some coversion..
*/
#define CGL_BGR GL_RGB
#define CGL_BGRA GL_RGBA
/* Its unlikely we support this */
#define CGL_TEXTURE_RECTANGLE_ARB 0
/* YUV textures also unsupported */
#define CGL_YCBCR_MESA 0
#define CGL_UNSIGNED_SHORT_8_8_REV_MESA 0

188
gles/cogl-fbo.c Normal file
View File

@ -0,0 +1,188 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-util.h"
#include "cogl-texture.h"
#include "cogl-fbo.h"
#include "cogl-context.h"
/* Expecting EXT functions not to be defined - redirect to pointers in context */
#define glGenRenderbuffersEXT ctx->pf_glGenRenderbuffersEXT
#define glBindRenderbufferEXT ctx->pf_glBindRenderbufferEXT
#define glRenderbufferStorageEXT ctx->pf_glRenderbufferStorageEXT
#define glGenFramebuffersEXT ctx->pf_glGenFramebuffersEXT
#define glBindFramebufferEXT ctx->pf_glBindFramebufferEXT
#define glFramebufferTexture2DEXT ctx->pf_glFramebufferTexture2DEXT
#define glFramebufferRenderbufferEXT ctx->pf_glFramebufferRenderbufferEXT
#define glCheckFramebufferStatusEXT ctx->pf_glCheckFramebufferStatusEXT
#define glDeleteFramebuffersEXT ctx->pf_glDeleteFramebuffersEXT
#define glBlitFramebufferEXT ctx->pf_glBlitFramebufferEXT
#define glRenderbufferStorageMultisampleEXT ctx->pf_glRenderbufferStorageMultisampleEXT
static gint
_cogl_fbo_handle_find (CoglHandle handle)
{
_COGL_GET_CONTEXT (ctx, -1);
gint i;
if (ctx->fbo_handles == NULL)
return -1;
for (i=0; i < ctx->fbo_handles->len; ++i)
if (g_array_index (ctx->fbo_handles, CoglHandle, i) == handle)
return i;
return -1;
}
/*
static CoglHandle
_cogl_fbo_handle_new (CoglFbo *fbo)
{
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
CoglHandle handle = (CoglHandle)fbo;
if (ctx->fbo_handles == NULL)
ctx->fbo_handles = g_array_new (FALSE, FALSE, sizeof (CoglHandle));
g_array_append_val (ctx->fbo_handles, handle);
return handle;
}
static void
_cogl_fbo_handle_release (CoglHandle handle)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
gint i;
if ( (i = _cogl_fbo_handle_find (handle)) == -1)
return;
g_array_remove_index_fast (ctx->fbo_handles, i);
}
static CoglFbo*
_cogl_fbo_pointer_from_handle (CoglHandle handle)
{
return (CoglFbo*) handle;
}*/
gboolean
cogl_is_offscreen_buffer (CoglHandle handle)
{
if (handle == COGL_INVALID_HANDLE)
return FALSE;
return _cogl_fbo_handle_find (handle) >= 0;
}
CoglHandle
cogl_offscreen_new_to_texture (CoglHandle texhandle)
{
return COGL_INVALID_HANDLE;
}
CoglHandle
cogl_offscreen_new_multisample ()
{
return COGL_INVALID_HANDLE;
}
CoglHandle
cogl_offscreen_ref (CoglHandle handle)
{
return COGL_INVALID_HANDLE;
}
void
cogl_offscreen_unref (CoglHandle handle)
{
}
void
cogl_offscreen_blit_region (CoglHandle src_buffer,
CoglHandle dst_buffer,
int src_x,
int src_y,
int src_w,
int src_h,
int dst_x,
int dst_y,
int dst_w,
int dst_h)
{
}
void
cogl_offscreen_blit (CoglHandle src_buffer,
CoglHandle dst_buffer)
{
}
void
cogl_draw_buffer (CoglBufferTarget target, CoglHandle offscreen)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
switch (target)
{
case COGL_OFFSCREEN_BUFFER:
/* Not supported */
return;
case COGL_WINDOW_BUFFER:
/* Draw to RGB channels */
GE( glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE) );
break;
case COGL_MASK_BUFFER:
/* Draw only to ALPHA channel */
GE( glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE) );
break;
case COGL_WINDOW_BUFFER & COGL_MASK_BUFFER:
/* Draw to all channels */
GE( glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) );
break;
}
/* Store new target */
ctx->draw_buffer = target;
}

38
gles/cogl-fbo.h Normal file
View File

@ -0,0 +1,38 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_FBO_H
#define __COGL_FBO_H
typedef struct
{
guint ref_count;
int width;
int height;
GLuint gl_handle;
} CoglFbo;
#endif /* __COGL_FBO_H */

63
gles/cogl-internal.h Normal file
View File

@ -0,0 +1,63 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_INTERNAL_H
#define __COGL_INTERNAL_H
#define COGL_DEBUG 0
#if COGL_DEBUG
#define GE(x...) { \
GLenum err; \
(x); \
fprintf(stderr, "%s\n", #x); \
while ((err = glGetError()) != GL_NO_ERROR) { \
fprintf(stderr, "glError: %s caught at %s:%u\n", \
(char *)error_string(err), \
__FILE__, __LINE__); \
} \
}
#else
#define GE(x) (x);
#endif
#define COGL_ENABLE_BLEND (1<<1)
#define COGL_ENABLE_TEXTURE_2D (1<<2)
#define COGL_ENABLE_ALPHA_TEST (1<<3)
#define COGL_ENABLE_TEXTURE_RECT (1<<4)
#define COGL_ENABLE_VERTEX_ARRAY (1<<5)
#define COGL_ENABLE_TEXCOORD_ARRAY (1<<6)
#define COGL_ENABLE_COLOR_ARRAY (1<<7)
gint
_cogl_get_format_bpp (CoglPixelFormat format);
void
cogl_enable (gulong flags);
gulong
cogl_get_enable ();
#endif /* __COGL_INTERNAL_H */

1112
gles/cogl-primitives.c Normal file

File diff suppressed because it is too large Load Diff

54
gles/cogl-primitives.h Normal file
View File

@ -0,0 +1,54 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_PRIMITIVES_H
#define __COGL_PRIMITIVES_H
typedef struct _CoglFixedVec2 CoglFixedVec2;
typedef struct _CoglBezQuad CoglBezQuad;
typedef struct _CoglBezCubic CoglBezCubic;
struct _CoglFixedVec2
{
ClutterFixed x;
ClutterFixed y;
};
struct _CoglBezQuad
{
CoglFixedVec2 p1;
CoglFixedVec2 p2;
CoglFixedVec2 p3;
};
struct _CoglBezCubic
{
CoglFixedVec2 p1;
CoglFixedVec2 p2;
CoglFixedVec2 p3;
CoglFixedVec2 p4;
};
#endif /* __COGL_PRIMITIVES_H */

2185
gles/cogl-texture.c Normal file

File diff suppressed because it is too large Load Diff

63
gles/cogl-texture.h Normal file
View File

@ -0,0 +1,63 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_TEXTURE_H
#define __COGL_TEXTURE_H
#include "cogl-bitmap.h"
typedef struct _CoglTexture CoglTexture;
typedef struct _CoglTexSliceSpan CoglTexSliceSpan;
typedef struct _CoglSpanIter CoglSpanIter;
struct _CoglTexSliceSpan
{
gint start;
gint size;
gint waste;
};
struct _CoglTexture
{
guint ref_count;
CoglBitmap bitmap;
gboolean bitmap_owner;
GLenum gl_target;
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
GArray *slice_x_spans;
GArray *slice_y_spans;
GArray *slice_gl_handles;
gint max_waste;
COGLenum min_filter;
COGLenum mag_filter;
gboolean is_foreign;
};
CoglTexture*
_cogl_texture_pointer_from_handle (CoglHandle handle);
#endif /* __COGL_TEXTURE_H */

51
gles/cogl-util.c Normal file
View File

@ -0,0 +1,51 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-util.h"
/**
* cogl_util_next_p2:
* @a: Value to get the next power
*
* Calculates the next power greater than @a.
*
* Return value: The next power after @a.
*/
int
cogl_util_next_p2 (int a)
{
int rval=1;
while(rval < a)
rval <<= 1;
return rval;
}

32
gles/cogl-util.h Normal file
View File

@ -0,0 +1,32 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_UTIL_H
#define __COGL_UTIL_H
int
cogl_util_next_p2 (int a);
#endif /* __COGL_UTIL_H */

View File

@ -32,16 +32,12 @@
#include <GLES/gl.h>
#include <string.h>
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define PIXEL_TYPE GL_UNSIGNED_BYTE
#else
#define PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
#endif
#include "cogl-internal.h"
#include "cogl-util.h"
#include "cogl-context.h"
static gulong __enable_flags = 0;
#define COGL_DEBUG 0
/* GL error to string conversion */
#if COGL_DEBUG
struct token_string
{
@ -75,20 +71,6 @@ error_string(GLenum errorCode)
}
#endif
#if COGL_DEBUG
#define GE(x...) { \
GLenum err; \
(x); \
fprintf(stderr, "%s\n", #x); \
while ((err = glGetError()) != GL_NO_ERROR) { \
fprintf(stderr, "glError: %s caught at %s:%u\n", \
(char *)error_string(err), \
__FILE__, __LINE__); \
} \
}
#else
#define GE(x) (x);
#endif
CoglFuncPtr
cogl_get_proc_address (const gchar* name)
@ -117,9 +99,6 @@ cogl_paint_init (const ClutterColor *color)
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDisable (GL_LIGHTING);
glDisable (GL_FOG);
cogl_enable (CGL_ENABLE_BLEND);
glTexEnvx (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
/* FIXME: inline most of these */
@ -173,53 +152,98 @@ cogl_rotate (gint angle, gint x, gint y, gint z)
CLUTTER_INT_TO_FIXED(z)) );
}
static inline gboolean
cogl_toggle_flag (CoglContext *ctx,
gulong new_flags,
gulong flag,
GLenum gl_flag)
{
/* Toggles and caches a single enable flag on or off
* by comparing to current state
*/
if (new_flags & flag)
{
if (!(ctx->enable_flags & flag))
{
GE( glEnable (gl_flag) );
ctx->enable_flags |= flag;
return TRUE;
}
}
else if (ctx->enable_flags & flag)
{
GE( glDisable (gl_flag) );
ctx->enable_flags &= ~flag;
}
return FALSE;
}
static inline gboolean
cogl_toggle_client_flag (CoglContext *ctx,
gulong new_flags,
gulong flag,
GLenum gl_flag)
{
/* Toggles and caches a single client-side enable flag
* on or off by comparing to current state
*/
if (new_flags & flag)
{
if (!(ctx->enable_flags & flag))
{
GE( glEnableClientState (gl_flag) );
ctx->enable_flags |= flag;
return TRUE;
}
}
else if (ctx->enable_flags & flag)
{
GE( glDisableClientState (gl_flag) );
ctx->enable_flags &= ~flag;
}
return FALSE;
}
void
cogl_enable (gulong flags)
{
/* This function essentially caches glEnable state() in the
* hope of lessening number GL traffic.
*/
if (flags & CGL_ENABLE_BLEND)
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (cogl_toggle_flag (ctx, flags,
COGL_ENABLE_BLEND,
GL_BLEND))
{
if (!(__enable_flags & CGL_ENABLE_BLEND))
{
GE( glEnable (GL_BLEND) );
GE( glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) );
}
__enable_flags |= CGL_ENABLE_BLEND;
}
else if (__enable_flags & CGL_ENABLE_BLEND)
{
GE( glDisable (GL_BLEND) );
__enable_flags &= ~CGL_ENABLE_BLEND;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
if (flags & CGL_ENABLE_TEXTURE_2D)
{
if (!(__enable_flags & CGL_ENABLE_TEXTURE_2D))
GE( glEnable (GL_TEXTURE_2D) );
__enable_flags |= CGL_ENABLE_TEXTURE_2D;
}
else if (__enable_flags & CGL_ENABLE_TEXTURE_2D)
{
GE( glDisable (GL_TEXTURE_2D) );
__enable_flags &= ~CGL_ENABLE_TEXTURE_2D;
}
cogl_toggle_flag (ctx, flags,
COGL_ENABLE_TEXTURE_2D,
GL_TEXTURE_2D);
#if 0
if (flags & CGL_ENABLE_TEXTURE_RECT)
{
if (!(__enable_flags & CGL_ENABLE_TEXTURE_RECT))
glEnable (GL_TEXTURE_RECTANGLE_);
cogl_toggle_client_flag (ctx, flags,
COGL_ENABLE_VERTEX_ARRAY,
GL_VERTEX_ARRAY);
__enable_flags |= CGL_ENABLE_TEXTURE_RECT;
}
else if (__enable_flags & CGL_ENABLE_TEXTURE_RECT)
{
glDisable (GL_TEXTURE_RECTANGLE_);
__enable_flags &= ~CGL_ENABLE_TEXTURE_RECT;
}
#endif
cogl_toggle_client_flag (ctx, flags,
COGL_ENABLE_TEXCOORD_ARRAY,
GL_TEXTURE_COORD_ARRAY);
cogl_toggle_client_flag (ctx, flags,
COGL_ENABLE_COLOR_ARRAY,
GL_COLOR_ARRAY);
}
gulong
cogl_get_enable ()
{
_COGL_GET_CONTEXT (ctx, 0);
return ctx->enable_flags;
}
void
@ -242,6 +266,8 @@ cogl_enable_depth_test (gboolean setting)
void
cogl_color (const ClutterColor *color)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
#if 0 /*HAVE_GLES_COLOR4UB*/
/* NOTE: seems SDK_OGLES-1.1_LINUX_PCEMULATION_2.02.22.0756 has this call
@ -267,25 +293,9 @@ cogl_color (const ClutterColor *color)
(color->blue << 16) / 0xff,
(color->alpha << 16) / 0xff));
#endif
}
static inline void
cogl_rectangle_internal (ClutterFixed x,
ClutterFixed y,
ClutterFixed width,
ClutterFixed height)
{
GLfixed rect_verts[8] = {
x, y,
x + width, y,
x, y + height,
x + width, y + height
};
GE( glEnableClientState (GL_VERTEX_ARRAY) );
GE( glVertexPointer (2, GL_FIXED, 0, rect_verts) );
GE( glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) );
GE( glDisableClientState (GL_VERTEX_ARRAY) );
/* Store alpha for proper blending enables */
ctx->color_alpha = color->alpha;
}
void
@ -294,199 +304,57 @@ cogl_clip_set (ClutterFixed x_offset,
ClutterFixed width,
ClutterFixed height)
{
GE( glEnable (GL_STENCIL_TEST) );
if (cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES))
{
GLfixed eqn_left[4] = { CFX_ONE, 0, 0, -x_offset };
GLfixed eqn_right[4] = { -CFX_ONE, 0, 0, x_offset + width };
GLfixed eqn_top[4] = { 0, CFX_ONE, 0, -y_offset };
GLfixed eqn_bottom[4] = { 0, -CFX_ONE, 0, y_offset + height };
GE( glClearStencil (0) );
GE( glClear (GL_STENCIL_BUFFER_BIT) );
GE( glClipPlanex (GL_CLIP_PLANE0, eqn_left) );
GE( glClipPlanex (GL_CLIP_PLANE1, eqn_right) );
GE( glClipPlanex (GL_CLIP_PLANE2, eqn_top) );
GE( glClipPlanex (GL_CLIP_PLANE3, eqn_bottom) );
GE( glEnable (GL_CLIP_PLANE0) );
GE( glEnable (GL_CLIP_PLANE1) );
GE( glEnable (GL_CLIP_PLANE2) );
GE( glEnable (GL_CLIP_PLANE3) );
}
else if (cogl_features_available (COGL_FEATURE_STENCIL_BUFFER))
{
GE( glEnable (GL_STENCIL_TEST) );
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
GE( glClearStencil (0) );
GE( glClear (GL_STENCIL_BUFFER_BIT) );
GE( glColor4x (CFX_ONE, CFX_ONE, CFX_ONE, CFX_ONE ) );
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
cogl_rectangle_internal (x_offset, y_offset, width, height);
GE( glColor4x (CFX_ONE, CFX_ONE, CFX_ONE, CFX_ONE ) );
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
cogl_fast_fill_rectanglex (x_offset, y_offset, width, height);
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
}
}
void
cogl_clip_unset (void)
{
GE( glDisable (GL_STENCIL_TEST) );
if (cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES))
{
GE( glDisable (GL_CLIP_PLANE3) );
GE( glDisable (GL_CLIP_PLANE2) );
GE( glDisable (GL_CLIP_PLANE1) );
GE( glDisable (GL_CLIP_PLANE0) );
}
else if (cogl_features_available (COGL_FEATURE_STENCIL_BUFFER))
{
GE( glDisable (GL_STENCIL_TEST) );
}
}
gboolean
cogl_texture_can_size (COGLenum target,
COGLenum pixel_format,
COGLenum pixel_type,
int width,
int height)
{
/* FIXME: How we get this is likely GLES implementation dependant. */
return TRUE;
}
void
cogl_texture_quad (gint x1,
gint x2,
gint y1,
gint y2,
ClutterFixed tx1,
ClutterFixed ty1,
ClutterFixed tx2,
ClutterFixed ty2)
{
#define FIX CLUTTER_INT_TO_FIXED
GLfixed quadVerts[] = {
FIX(x1), FIX(y1), 0,
FIX(x2), FIX(y1), 0,
FIX(x2), FIX(y2), 0,
FIX(x2), FIX(y2), 0,
FIX(x1), FIX(y2), 0,
FIX(x1), FIX(y1), 0
};
GLfixed quadTex[] = {
tx1, ty1,
tx2, ty1,
tx2, ty2,
tx2, ty2,
tx1, ty2,
tx1, ty1
};
#undef FIX
GE( glEnableClientState(GL_VERTEX_ARRAY) );
GE( glEnableClientState(GL_TEXTURE_COORD_ARRAY) );
GE( glVertexPointer(3, GL_FIXED, 0, quadVerts) );
GE( glTexCoordPointer(2, GL_FIXED, 0, quadTex) );
GE( glDrawArrays(GL_TRIANGLES, 0, 6) );
GE( glDisableClientState(GL_TEXTURE_COORD_ARRAY) );
GE( glDisableClientState(GL_VERTEX_ARRAY) );
/* Note also see glDrawTexxOES for potential optimisation */
}
void
cogl_textures_create (guint num, COGLuint *textures)
{
GE( glGenTextures (num, textures) );
}
void
cogl_textures_destroy (guint num, const COGLuint *textures)
{
GE( glDeleteTextures (num, textures) );
}
void
cogl_texture_bind (COGLenum target, COGLuint texture)
{
GE( glBindTexture (target, texture) );
}
void
cogl_texture_set_alignment (COGLenum target,
guint alignment,
guint row_length)
{
/* GE( glPixelStorei (GL_UNPACK_ROW_LENGTH, row_length) ); */
GE( glPixelStorei (GL_UNPACK_ALIGNMENT, alignment) );
}
void
cogl_texture_set_filters (COGLenum target,
COGLenum min_filter,
COGLenum max_filter)
{
GE( glTexParameteri(target, GL_TEXTURE_MAG_FILTER, max_filter) );
GE( glTexParameteri(target, GL_TEXTURE_MIN_FILTER, min_filter) );
}
void
cogl_texture_set_wrap (COGLenum target,
COGLenum wrap_s,
COGLenum wrap_t)
{
GE( glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap_s) );
GE( glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap_s) );
}
void
cogl_texture_image_2d (COGLenum target,
COGLint internal_format,
gint width,
gint height,
COGLenum format,
COGLenum type,
const guchar* pixels)
{
GE( glTexImage2D (target,
0,
format, /* HACK: For gles we set the internal_format equal
* to the pixel format. This is for RGB data (i.e
* jpgs) which seem to need a matching internal
* format rather than RGBA (which is used by GL)
*.
* This fix isn't ideal..
*/
width,
height,
0,
format,
type,
pixels) );
}
void
cogl_texture_sub_image_2d (COGLenum target,
gint xoff,
gint yoff,
gint width,
gint height,
COGLenum format,
COGLenum type,
const guchar* pixels)
{
GE( glTexSubImage2D (target,
0,
xoff,
yoff,
width,
height,
format,
type,
pixels));
}
void
cogl_rectangle (gint x,
gint y,
guint width,
guint height)
{
cogl_rectangle_internal (CLUTTER_INT_TO_FIXED (x),
CLUTTER_INT_TO_FIXED (y),
CLUTTER_INT_TO_FIXED (width),
CLUTTER_INT_TO_FIXED (height));
}
/* FIXME: Should use ClutterReal or Fixed */
void
cogl_trapezoid (gint y1,
gint x11,
gint x21,
gint y2,
gint x12,
gint x22)
{
/* FIXME */
}
void
cogl_alpha_func (COGLenum func,
ClutterFixed ref)
@ -591,11 +459,49 @@ cogl_setup_viewport (guint w,
GE( glTranslatex (0, -CFX_ONE * height, 0) );
}
static void
_cogl_features_init ()
{
ClutterFeatureFlags flags = 0;
int stencil_bits = 0;
int max_clip_planes = 0;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
flags = COGL_FEATURE_TEXTURE_READ_PIXELS;
GE( glGetIntegerv (GL_STENCIL_BITS, &stencil_bits) );
if (stencil_bits > 0)
flags |= COGL_FEATURE_STENCIL_BUFFER;
GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
if (max_clip_planes >= 4)
flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
ctx->feature_flags = flags;
ctx->features_cached = TRUE;
}
ClutterFeatureFlags
cogl_get_features ()
{
/* Suck */
return 0;
_COGL_GET_CONTEXT (ctx, 0);
if (!ctx->features_cached)
_cogl_features_init ();
return ctx->feature_flags;
}
gboolean
cogl_features_available (CoglFeatureFlags features)
{
_COGL_GET_CONTEXT (ctx, 0);
if (!ctx->features_cached)
_cogl_features_init ();
return (ctx->feature_flags & features) == features;
}
void
@ -654,39 +560,6 @@ cogl_fog_set (const ClutterColor *fog_color,
glFogx (GL_FOG_END, (GLfixed) z_far);
}
/* Offscreen - TODO: possible support from FBO's/PBuffers
* See;
* http://www.khronos.org/message_boards/viewtopic.php?t=589
* http://www.gamedev.net/community/forums/topic.asp?topic_id=369739
*
* Likely requires EGL 1.3 for eglBindTexImage
*/
COGLuint
cogl_offscreen_create (COGLuint target_texture)
{
return 0;
}
void
cogl_offscreen_destroy (COGLuint offscreen_handle)
{
}
void
cogl_offscreen_redirect_start (COGLuint offscreen_handle,
gint width,
gint height)
{
}
void
cogl_offscreen_redirect_end (COGLuint offscreen_handle,
gint width,
gint height)
{
}
/* Shaders, no support on regular OpenGL 1.1 */
COGLhandle