2007-10-12 08:17:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-05-02 20:05:29 +00:00
|
|
|
#include "config.h"
|
2007-10-12 08:17:00 +00:00
|
|
|
#endif
|
2007-05-02 20:05:29 +00:00
|
|
|
|
|
|
|
#include "clutter-backend-sdl.h"
|
|
|
|
#include "clutter-stage-sdl.h"
|
|
|
|
#include "../clutter-private.h"
|
|
|
|
#include "../clutter-main.h"
|
|
|
|
#include "../clutter-debug.h"
|
|
|
|
|
|
|
|
static ClutterBackendSDL *backend_singleton = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (ClutterBackendSDL, clutter_backend_sdl, CLUTTER_TYPE_BACKEND);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_backend_sdl_pre_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_backend_sdl_post_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
2008-04-25 12:17:01 +00:00
|
|
|
int err;
|
2007-05-02 20:05:29 +00:00
|
|
|
|
2008-04-25 12:17:01 +00:00
|
|
|
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
|
2007-05-02 20:05:29 +00:00
|
|
|
{
|
|
|
|
g_set_error (error, CLUTTER_INIT_ERROR,
|
|
|
|
CLUTTER_INIT_ERROR_BACKEND,
|
|
|
|
"Unable to Initialize SDL");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(WIN32)
|
2008-04-25 12:17:01 +00:00
|
|
|
err = SDL_GL_LoadLibrary ("opengl32.dll");
|
2007-05-02 20:05:29 +00:00
|
|
|
#elif defined(__linux__) || defined(__FreeBSD__)
|
2008-04-25 12:17:01 +00:00
|
|
|
err = SDL_GL_LoadLibrary ("libGL.so");
|
2007-05-02 20:05:29 +00:00
|
|
|
#else
|
|
|
|
#error Your platform is not supported
|
|
|
|
err = 1;
|
|
|
|
#endif
|
2008-04-25 12:17:01 +00:00
|
|
|
|
2007-05-02 20:05:29 +00:00
|
|
|
if (err != 0)
|
|
|
|
{
|
|
|
|
g_set_error (error, CLUTTER_INIT_ERROR,
|
|
|
|
CLUTTER_INIT_ERROR_BACKEND,
|
2009-03-09 10:59:52 +00:00
|
|
|
"%s", SDL_GetError ());
|
2007-05-02 20:05:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-04-25 12:17:01 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "SDL successfully initialized");
|
|
|
|
|
2007-05-02 20:05:29 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-04-25 12:17:01 +00:00
|
|
|
static void
|
|
|
|
clutter_backend_sdl_ensure_context (ClutterBackend *backend,
|
|
|
|
ClutterStage *stage)
|
|
|
|
{
|
|
|
|
/* no context to ensure */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_sdl_redraw (ClutterBackend *backend,
|
|
|
|
ClutterStage *stage)
|
|
|
|
{
|
|
|
|
clutter_actor_paint (CLUTTER_ACTOR (stage));
|
2009-06-29 16:10:34 +00:00
|
|
|
cogl_flush ();
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 17:46:42 +00:00
|
|
|
|
2008-04-25 12:17:01 +00:00
|
|
|
SDL_GL_SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
static ClutterActor *
|
|
|
|
clutter_backend_sdl_create_stage (ClutterBackend *backend,
|
|
|
|
ClutterStage *wrapper,
|
|
|
|
GError **error)
|
2007-05-02 20:05:29 +00:00
|
|
|
{
|
|
|
|
ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (backend);
|
2008-04-25 12:17:01 +00:00
|
|
|
ClutterStageSDL *stage_sdl;
|
|
|
|
ClutterActor *stage;
|
2007-05-02 20:05:29 +00:00
|
|
|
|
2008-04-25 12:17:01 +00:00
|
|
|
if (backend_sdl->stage)
|
2007-05-02 20:05:29 +00:00
|
|
|
{
|
2008-04-25 12:17:01 +00:00
|
|
|
g_warning ("The SDL backend does not support multiple stages");
|
|
|
|
return CLUTTER_ACTOR (backend_sdl->stage);
|
|
|
|
}
|
2007-05-02 20:05:29 +00:00
|
|
|
|
2008-04-25 12:17:01 +00:00
|
|
|
stage = g_object_new (CLUTTER_TYPE_STAGE_SDL, NULL);
|
2007-05-02 20:05:29 +00:00
|
|
|
|
2008-04-25 12:17:01 +00:00
|
|
|
/* copy backend data into the stage */
|
|
|
|
stage_sdl = CLUTTER_STAGE_SDL (stage);
|
|
|
|
stage_sdl->wrapper = wrapper;
|
2007-05-02 20:05:29 +00:00
|
|
|
|
2008-04-25 12:17:01 +00:00
|
|
|
backend_sdl->stage = stage_sdl;
|
|
|
|
|
|
|
|
return stage;
|
2007-05-02 20:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_sdl_init_events (ClutterBackend *backend)
|
|
|
|
{
|
|
|
|
_clutter_events_init (backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_sdl_finalize (GObject *gobject)
|
|
|
|
{
|
|
|
|
SDL_Quit();
|
|
|
|
|
|
|
|
if (backend_singleton)
|
|
|
|
backend_singleton = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_backend_sdl_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_sdl_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (gobject);
|
|
|
|
|
|
|
|
_clutter_events_uninit (CLUTTER_BACKEND (backend_sdl));
|
|
|
|
|
|
|
|
if (backend_sdl->stage)
|
|
|
|
{
|
2008-04-25 12:17:01 +00:00
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (backend_sdl->stage));
|
2007-05-02 20:05:29 +00:00
|
|
|
backend_sdl->stage = NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-07 15:03:59 +00:00
|
|
|
if (backend_sdl->timer)
|
|
|
|
{
|
|
|
|
g_timer_destroy (backend_sdl->timer);
|
|
|
|
backend_sdl->timer = NULL;
|
|
|
|
}
|
|
|
|
|
2007-05-02 20:05:29 +00:00
|
|
|
G_OBJECT_CLASS (clutter_backend_sdl_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
clutter_backend_sdl_constructor (GType gtype,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObjectClass *parent_class;
|
|
|
|
GObject *retval;
|
|
|
|
|
|
|
|
if (!backend_singleton)
|
|
|
|
{
|
|
|
|
parent_class = G_OBJECT_CLASS (clutter_backend_sdl_parent_class);
|
|
|
|
retval = parent_class->constructor (gtype, n_params, params);
|
|
|
|
|
|
|
|
backend_singleton = CLUTTER_BACKEND_SDL (retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warning ("Attempting to create a new backend object. This should "
|
|
|
|
"never happen, so we return the singleton instance.");
|
|
|
|
|
|
|
|
return g_object_ref (backend_singleton);
|
|
|
|
}
|
|
|
|
|
2007-07-26 20:08:09 +00:00
|
|
|
static ClutterFeatureFlags
|
2007-07-31 07:58:35 +00:00
|
|
|
clutter_backend_sdl_get_features (ClutterBackend *backend)
|
2007-07-26 20:08:09 +00:00
|
|
|
{
|
|
|
|
return CLUTTER_FEATURE_STAGE_CURSOR;
|
|
|
|
}
|
2007-05-02 20:05:29 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_sdl_class_init (ClutterBackendSDLClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->constructor = clutter_backend_sdl_constructor;
|
|
|
|
gobject_class->dispose = clutter_backend_sdl_dispose;
|
|
|
|
gobject_class->finalize = clutter_backend_sdl_finalize;
|
|
|
|
|
2008-06-25 13:32:03 +00:00
|
|
|
backend_class->pre_parse = clutter_backend_sdl_pre_parse;
|
|
|
|
backend_class->post_parse = clutter_backend_sdl_post_parse;
|
|
|
|
backend_class->init_events = clutter_backend_sdl_init_events;
|
|
|
|
backend_class->create_stage = clutter_backend_sdl_create_stage;
|
|
|
|
backend_class->ensure_context = clutter_backend_sdl_ensure_context;
|
|
|
|
backend_class->redraw = clutter_backend_sdl_redraw;
|
|
|
|
backend_class->get_features = clutter_backend_sdl_get_features;
|
2007-05-02 20:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_sdl_init (ClutterBackendSDL *backend_sdl)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend = CLUTTER_BACKEND (backend_sdl);
|
|
|
|
|
2007-08-02 09:58:18 +00:00
|
|
|
clutter_backend_set_resolution (backend, 96.0);
|
2007-05-10 12:49:34 +00:00
|
|
|
clutter_backend_set_double_click_time (backend, 250);
|
|
|
|
clutter_backend_set_double_click_distance (backend, 5);
|
2008-05-07 15:03:59 +00:00
|
|
|
|
|
|
|
backend_sdl->timer = g_timer_new ();
|
2007-05-02 20:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
_clutter_backend_impl_get_type (void)
|
|
|
|
{
|
|
|
|
return clutter_backend_sdl_get_type ();
|
|
|
|
}
|
|
|
|
|