2007-03-27 Matthew Allum <mallum@openedhand.com>

* clutter/clutter-feature.c:
        Rejig ifdef's a little. Make drm vblanking Linux only.

        * clutter/clutter-stage.c:
        * clutter/clutter-stage.h:
        Add a perspective boxed type.

        * clutter/glx/clutter-stage-glx.c:
        Add some FIXMEs

        * clutter/Makefile.am:
        * clutter/cogl/Makefile.am:
        * clutter/cogl/cogl.h:
        * clutter/cogl/gl/Makefile.am:
        * clutter/cogl/gl/cogl.c:
        * configure.ac:
        Very initial work on 'cogl' GL/GLES abstraction/utility code.
This commit is contained in:
Matthew Allum 2007-03-26 23:18:39 +00:00
parent f595460932
commit 464f24fdc0
11 changed files with 327 additions and 37 deletions

View File

@ -1,3 +1,23 @@
2007-03-27 Matthew Allum <mallum@openedhand.com>
* clutter/clutter-feature.c:
Rejig ifdef's a little. Make drm vblanking Linux only.
* clutter/clutter-stage.c:
* clutter/clutter-stage.h:
Add a perspective boxed type.
* clutter/glx/clutter-stage-glx.c:
Add some FIXMEs
* clutter/Makefile.am:
* clutter/cogl/Makefile.am:
* clutter/cogl/cogl.h:
* clutter/cogl/gl/Makefile.am:
* clutter/cogl/gl/cogl.c:
* configure.ac:
Very initial work on 'cogl' GL/GLES abstraction/utility code.
2007-03-26 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-behaviour-scale.[ch]: Add API for getting

View File

@ -1,8 +1,8 @@
NULL =
SUBDIRS = pango $(clutterbackend)
SUBDIRS = cogl pango $(clutterbackend)
DIST_SUBDIRS = pango glx egl
DIST_SUBDIRS = pango glx egl cogl
target = $(clutterbackend)
@ -15,6 +15,7 @@ GLIB_MKENUMS=`pkg-config --variable=glib_mkenums glib-2.0`
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/clutter/pango \
-I$(top_srcdir)/cogl \
-DPREFIX=\""$(prefix)"\" \
-DLIBDIR=\""$(libdir)"\" \
-DDATADIR=\""$(datadir)"\" \
@ -149,25 +150,22 @@ source_h_priv = \
$(NULL)
libclutter_glx_0_3_la_LIBADD = $(CLUTTER_LIBS) pango/libpangoclutter.la glx/libclutter-glx.la
libclutter_glx_0_3_la_SOURCES = $(source_c) $(source_h) $(source_h_priv)
libclutter_glx_0_3_la_LDFLAGS = $(LDADD)
libclutter_@CLUTTER_FLAVOUR@_@CLUTTER_API_VERSION@_la_LIBADD = \
$(CLUTTER_LIBS) pango/libpangoclutter.la \
@CLUTTER_FLAVOUR@/libclutter-@CLUTTER_FLAVOUR@.la \
cogl/gl/libclutter-cogl.la
#libclutter_egl_0_3_la_LIBADD = \
# $(CLUTTER_LIBS) \
# pango/libpangoclutter.la \
# egl/libclutter-egl.la
#libclutter_egl_0_3_la_LDADD = $(LDADD)
#libclutter_egl_0_3_la_SOURCES = \
# $(source_c) \
# $(source_h) \
# $(source_h_priv)
libclutter_@CLUTTER_FLAVOUR@_@CLUTTER_API_VERSION@_la_SOURCES = \
$(source_c) $(source_h) $(source_h_priv)
libclutter_@CLUTTER_FLAVOUR@_@CLUTTER_API_VERSION@_la_LDFLAGS = $(LDADD)
lib_LTLIBRARIES = $(clutterbackendlib)
EXTRA_LTLIBRARIES = libclutter-glx-0.3.la
EXTRA_LTLIBRARIES = libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_API_VERSION@.la
clutterdir = $(includedir)/clutter-@CLUTTER_API_VERSION@/clutter
clutter_HEADERS = \
$(source_h) \
clutter-enum-types.h \

View File

@ -55,16 +55,16 @@
#endif
typedef void (*FuncPtr) (void);
typedef int (*GLXGetVideoSyncProc) (unsigned int *count);
typedef int (*GLXWaitVideoSyncProc) (int divisor,
int remainder,
unsigned int *count);
typedef int (*GetVideoSyncProc) (unsigned int *count);
typedef int (*WaitVideoSyncProc) (int divisor,
int remainder,
unsigned int *count);
typedef FuncPtr (*GLXGetProcAddressProc) (const guint8 *procName);
typedef struct ClutterFeatureFuncs
{
GLXGetVideoSyncProc get_video_sync;
GLXWaitVideoSyncProc wait_video_sync;
GetVideoSyncProc get_video_sync;
WaitVideoSyncProc wait_video_sync;
} ClutterFeatureFuncs;
@ -89,7 +89,8 @@ typedef struct ClutterFeatures
static ClutterFeatures* __features = NULL;
G_LOCK_DEFINE_STATIC (__features);
/* #ifdef linux */
#ifdef __linux__
#define DRM_VBLANK_RELATIVE 0x1;
struct drm_wait_vblank_request {
@ -129,7 +130,7 @@ static int drm_wait_vblank(int fd, drm_wait_vblank_t *vbl)
return rc;
}
/* #endif */
#endif
/* Note must be called after context created */
@ -137,6 +138,7 @@ static gboolean
check_gl_extension (const gchar *name,
const gchar *ext)
{
/* FIXME: move to cogl */
gchar *end;
gint name_len, n;
@ -159,6 +161,7 @@ check_gl_extension (const gchar *name,
return FALSE;
}
/* FIXME: move to cogl */
static FuncPtr
get_proc_address (const gchar *name)
{
@ -237,7 +240,7 @@ check_vblank_env (const char *name)
static void
clutter_feature_init (void)
{
const gchar *gl_extensions, *glx_extensions;
const gchar *gl_extensions, *glx_extensions = NULL;
CLUTTER_NOTE (MISC, "checking features");
@ -259,16 +262,18 @@ clutter_feature_init (void)
return;
#ifdef HAVE_CLUTTER_GLX
glx_extensions
= glXQueryExtensionsString (clutter_glx_get_default_display (),
clutter_glx_get_default_screen ());
#endif
gl_extensions = (const gchar*) glGetString (GL_EXTENSIONS);
glx_extensions = glXQueryExtensionsString (clutter_glx_get_default_display (),
clutter_glx_get_default_screen ());
if (check_gl_extension ("GL_ARB_texture_rectangle", gl_extensions) ||
check_gl_extension ("GL_EXT_texture_rectangle", gl_extensions))
{
__features->flags |= CLUTTER_FEATURE_TEXTURE_RECTANGLE;
}
#endif
/* vblank */
@ -285,10 +290,10 @@ clutter_feature_init (void)
check_gl_extension ("GLX_SGI_video_sync", glx_extensions))
{
__features->funcs.get_video_sync =
(GLXGetVideoSyncProc) get_proc_address ("glXGetVideoSyncSGI");
(GetVideoSyncProc) get_proc_address ("glXGetVideoSyncSGI");
__features->funcs.wait_video_sync =
(GLXWaitVideoSyncProc) get_proc_address ("glXWaitVideoSyncSGI");
(WaitVideoSyncProc) get_proc_address ("glXWaitVideoSyncSGI");
if ((__features->funcs.get_video_sync != NULL) &&
(__features->funcs.wait_video_sync != NULL))
@ -300,7 +305,7 @@ clutter_feature_init (void)
}
}
#endif
#ifdef __linux__
if (!(__features->flags & CLUTTER_FEATURE_SYNC_TO_VBLANK))
{
__features->dri_fd = open("/dev/dri/card0", O_RDWR);
@ -312,7 +317,7 @@ clutter_feature_init (void)
__features->flags |= CLUTTER_FEATURE_SYNC_TO_VBLANK;
}
}
#endif
if (!(__features->flags & CLUTTER_FEATURE_SYNC_TO_VBLANK))
{
CLUTTER_NOTE (MISC,
@ -388,6 +393,7 @@ clutter_feature_wait_for_vblank (void)
switch (__features->vblank_type)
{
case CLUTTER_VBLANK_GLX:
#ifdef HAVE_CLUTTER_GLX
{
unsigned int retraceCount;
__features->funcs.get_video_sync (&retraceCount);
@ -395,8 +401,10 @@ clutter_feature_wait_for_vblank (void)
(retraceCount + 1) % 2,
&retraceCount);
}
#endif
break;
case CLUTTER_VBLANK_DRI:
#ifdef __linux__
{
drm_wait_vblank_t blank;
blank.request.type = DRM_VBLANK_RELATIVE;
@ -404,6 +412,7 @@ clutter_feature_wait_for_vblank (void)
blank.request.signal = 0;
drm_wait_vblank (__features->dri_fd, &blank);
}
#endif
break;
case CLUTTER_VBLANK_NONE:
default:

View File

@ -767,3 +767,58 @@ clutter_stage_get_actor_at_pos (ClutterStage *stage,
return found;
}
/*** Perspective boxed type ******/
/**
* clutter_perspective_copy:
* @perspective: a #ClutterPerspective
*
* Makes a copy of the perspective structure. The result must be
* freed using clutter_perspective_free().
*
* Return value: an allocated copy of @perspective.
*
* Since: 0.2
*/
ClutterPerspective *
clutter_perspective_copy (const ClutterPerspective *perspective)
{
ClutterPerspective *result;
g_return_val_if_fail (perspective != NULL, NULL);
result = g_slice_new (ClutterPerspective);
*result = *perspective;
return result;
}
/**
* clutter_perspective_free:
* @perspective: a #ClutterPerspective
*
* Frees a perspective structure created with clutter_perspective_copy().
*
* Since: 0.2
*/
void
clutter_perspective_free (ClutterPerspective *perspective)
{
g_return_if_fail (perspective != NULL);
g_slice_free (ClutterPerspective, perspective);
}
GType
clutter_perspective_get_type (void)
{
static GType our_type = 0;
if (!our_type)
our_type = g_boxed_type_register_static
("ClutterPerspective",
(GBoxedCopyFunc) clutter_perspective_copy,
(GBoxedFreeFunc) clutter_perspective_free);
return our_type;
}

View File

@ -120,6 +120,22 @@ struct _ClutterStageClass
void (*_clutter_stage6) (void);
};
#define CLUTTER_TYPE_PERSPECTIVE (clutter_perspective_get_type ())
typedef struct _ClutterPerspective ClutterPerspective;
struct _ClutterPerspective
{
ClutterFixed fovy;
ClutterFixed aspect;
ClutterFixed zNear;
ClutterFixed zFar;
};
ClutterPerspective *clutter_perspective_copy (const ClutterPerspective *perspective);
void clutter_perspective_free (ClutterPerspective *perspective);
GType clutter_stage_get_type (void) G_GNUC_CONST;
ClutterActor *clutter_stage_get_default (void);

3
clutter/cogl/Makefile.am Normal file
View File

@ -0,0 +1,3 @@
SUBDIRS=gl
EXTRA_DIST=cogl.h

59
clutter/cogl/cogl.h Normal file
View File

@ -0,0 +1,59 @@
/*
* 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.
*/
#include <clutter/clutter.h>
typedef void (*CoglFuncPtr) (void);
CoglFuncPtr
cogl_get_proc_address (const gchar* name);
gboolean
cogl_check_extension (const gchar *name, const gchar *ext);
void
cogl_paint_init (ClutterColor *color);
void
cogl_push_matrix (void);
void
cogl_pop_matrix (void);
void
cogl_scaled (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);

View File

@ -0,0 +1,17 @@
libclutterincludedir = $(includedir)/clutter-@CLUTTER_API_VERSION@/clutter
libclutterinclude_HEADERS = $(top_srcdir)/clutter/cogl/cogl.h
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/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 \
cogl.c

102
clutter/cogl/gl/cogl.c Normal file
View File

@ -0,0 +1,102 @@
/*
* 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.
*/
#include "cogl.h"
#include <GL/gl.h>
CoglFuncPtr
cogl_get_proc_address (const gchar* name)
{
return NULL;
}
gboolean
cogl_check_extension (const gchar *name, const gchar *ext)
{
return FALSE;
}
void
cogl_paint_init (ClutterColor *color)
{
glClearColor (((float) color->red / 0xff * 1.0),
((float) color->green / 0xff * 1.0),
((float) color->blue / 0xff * 1.0),
0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDisable (GL_LIGHTING);
glDisable (GL_DEPTH_TEST);
}
/* FIXME: inline most of these */
void
cogl_push_matrix (void)
{
glPushMatrix();
}
void
cogl_pop_matrix (void)
{
glPopMatrix();
}
void
cogl_scaled (ClutterFixed x, ClutterFixed y)
{
glScaled (CLUTTER_FIXED_TO_DOUBLE (x),
CLUTTER_FIXED_TO_DOUBLE (y),
1.0);
}
void
cogl_translatex (ClutterFixed x, ClutterFixed y, ClutterFixed z)
{
glTranslated (CLUTTER_FIXED_TO_DOUBLE (x),
CLUTTER_FIXED_TO_DOUBLE (y),
CLUTTER_FIXED_TO_DOUBLE (z));
}
void
cogl_translate (gint x, gint y, gint z)
{
glTranslatef ((float)x, (float)y, (float)z);
}
void
cogl_rotatex (ClutterFixed angle, gint x, gint y, gint z)
{
glRotated (CLUTTER_FIXED_TO_DOUBLE (angle),
CLUTTER_FIXED_TO_DOUBLE (x),
CLUTTER_FIXED_TO_DOUBLE (y),
CLUTTER_FIXED_TO_DOUBLE (z));
}
void
cogl_rotate (gint angle, gint x, gint y, gint z)
{
glRotatef ((float)angle, (float)x, (float)y, (float)z);
}

View File

@ -287,10 +287,10 @@ static void
clutter_stage_glx_paint (ClutterActor *self)
{
ClutterStageGlx *stage_glx = CLUTTER_STAGE_GLX (self);
ClutterStage *stage = CLUTTER_STAGE (self);
ClutterColor stage_color;
static GTimer *timer = NULL;
static guint timer_n_frames = 0;
ClutterStage *stage = CLUTTER_STAGE (self);
ClutterColor stage_color;
static GTimer *timer = NULL;
static guint timer_n_frames = 0;
CLUTTER_NOTE (PAINT, " Redraw enter");
@ -302,6 +302,7 @@ clutter_stage_glx_paint (ClutterActor *self)
clutter_stage_get_color (stage, &stage_color);
/* FIXME: move below into cogl_paint_start() ? */
glClearColor (((float) stage_color.red / 0xff * 1.0),
((float) stage_color.green / 0xff * 1.0),
((float) stage_color.blue / 0xff * 1.0),
@ -310,9 +311,14 @@ clutter_stage_glx_paint (ClutterActor *self)
glDisable (GL_LIGHTING);
glDisable (GL_DEPTH_TEST);
if (CLUTTER_ACTOR_CLASS (clutter_stage_glx_parent_class)->paint)
/* FIXME Check is redundant */
if (G_LIKELY(CLUTTER_ACTOR_CLASS (clutter_stage_glx_parent_class)->paint))
/* Basically call up to ClutterGroup paint here */
CLUTTER_ACTOR_CLASS (clutter_stage_glx_parent_class)->paint (self);
/* Why this paint is done in backend as likely GL windowing system
* specific calls, like swapping buffers.
*/
if (stage_glx->xwin)
{
clutter_feature_wait_for_vblank ();

View File

@ -115,10 +115,12 @@ AC_SUBST([clutterbackend])
case $clutterbackend in
glx)
CLUTTER_FLAVOUR="glx"
CLUTTER_GOGL="gl"
AC_DEFINE([HAVE_CLUTTER_GLX], 1, [Have the GLX backend])
;;
egl)
CLUTTER_FLAVOUR="egl"
CLUTTER_GOGL="gles"
AC_DEFINE([HAVE_CLUTTER_EGL], 1, [Have the EGL backend])
;;
*) AC_MSG_ERROR([Invalid backend for Clutter: use glx or egl])
@ -126,6 +128,7 @@ case $clutterbackend in
esac
AC_SUBST(CLUTTER_FLAVOUR)
AC_SUBST(CLUTTER_COGL)
clutterbackendlib=libclutter-$clutterbackend-$CLUTTER_MAJORMINOR.la
AC_SUBST([clutterbackendlib])
@ -196,6 +199,8 @@ AC_CONFIG_FILES([
clutter/clutter-version.h
clutter/glx/Makefile
clutter/egl/Makefile
clutter/cogl/Makefile
clutter/cogl/gl/Makefile
examples/Makefile
doc/Makefile
doc/reference/Makefile