2008-04-25 09:37:36 -04:00
|
|
|
/*
|
2009-04-27 10:48:12 -04:00
|
|
|
* Cogl
|
2008-04-25 09:37:36 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2008-04-25 09:37:36 -04:00
|
|
|
*
|
2013-05-14 08:39:48 -04:00
|
|
|
* Copyright (C) 2011,2013 Intel Corporation.
|
2008-04-25 09:37:36 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2008-04-25 09:37:36 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2008-04-25 09:37:36 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-03-01 07:56:10 -05:00
|
|
|
*
|
|
|
|
*
|
2011-12-14 07:09:53 -05:00
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
2008-04-25 09:37:36 -04:00
|
|
|
*/
|
|
|
|
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
#include <SDL.h>
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
#include "cogl-renderer-private.h"
|
|
|
|
#include "cogl-display-private.h"
|
|
|
|
#include "cogl-framebuffer-private.h"
|
|
|
|
#include "cogl-swap-chain-private.h"
|
|
|
|
#include "cogl-onscreen-template-private.h"
|
|
|
|
#include "cogl-context-private.h"
|
|
|
|
#include "cogl-onscreen-private.h"
|
2012-03-06 13:21:28 -05:00
|
|
|
#include "cogl-winsys-sdl-private.h"
|
2012-08-31 14:28:27 -04:00
|
|
|
#include "cogl-error-private.h"
|
2013-04-18 09:19:43 -04:00
|
|
|
#include "cogl-poll-private.h"
|
2011-12-14 07:09:53 -05:00
|
|
|
|
|
|
|
typedef struct _CoglRendererSdl
|
|
|
|
{
|
2013-04-18 09:19:43 -04:00
|
|
|
CoglClosure *resize_notify_idle;
|
2011-12-14 07:09:53 -05:00
|
|
|
} CoglRendererSdl;
|
|
|
|
|
|
|
|
typedef struct _CoglDisplaySdl
|
|
|
|
{
|
|
|
|
SDL_Surface *surface;
|
2012-06-20 11:22:36 -04:00
|
|
|
CoglOnscreen *onscreen;
|
2011-12-19 06:51:58 -05:00
|
|
|
Uint32 video_mode_flags;
|
2011-12-14 07:09:53 -05:00
|
|
|
} CoglDisplaySdl;
|
|
|
|
|
|
|
|
static CoglFuncPtr
|
|
|
|
_cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer,
|
2012-07-31 10:03:59 -04:00
|
|
|
const char *name,
|
|
|
|
CoglBool in_core)
|
2011-12-14 07:09:53 -05:00
|
|
|
{
|
2013-04-27 21:42:24 -04:00
|
|
|
CoglFuncPtr ptr;
|
|
|
|
|
2012-06-20 07:42:31 -04:00
|
|
|
/* XXX: It's not totally clear whether it's safe to call this for
|
|
|
|
* core functions. From the code it looks like the implementations
|
|
|
|
* will fall back to using some form of dlsym if the winsys
|
|
|
|
* GetProcAddress function returns NULL. Presumably this will work
|
|
|
|
* in most cases apart from EGL platforms that return invalid
|
|
|
|
* pointers for core functions. It's awkward for this code to get a
|
|
|
|
* handle to the GL module that SDL has chosen to load so just
|
|
|
|
* calling SDL_GL_GetProcAddress is probably the best we can do
|
|
|
|
* here. */
|
|
|
|
|
2011-12-19 06:51:58 -05:00
|
|
|
#ifdef COGL_HAS_SDL_GLES_SUPPORT
|
|
|
|
if (renderer->driver != COGL_DRIVER_GL)
|
|
|
|
return SDL_GLES_GetProcAddress (name);
|
|
|
|
#endif
|
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
return SDL_GL_GetProcAddress (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
|
|
|
|
{
|
|
|
|
SDL_Quit ();
|
|
|
|
|
|
|
|
g_slice_free (CoglRendererSdl, renderer->winsys);
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-12-14 07:09:53 -05:00
|
|
|
_cogl_winsys_renderer_connect (CoglRenderer *renderer,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2011-12-14 07:09:53 -05:00
|
|
|
{
|
2013-04-27 21:42:24 -04:00
|
|
|
#ifdef USING_EMSCRIPTEN
|
|
|
|
if (renderer->driver != COGL_DRIVER_GLES2)
|
|
|
|
{
|
|
|
|
_cogl_set_error (error, COGL_WINSYS_ERROR,
|
|
|
|
COGL_WINSYS_ERROR_INIT,
|
|
|
|
"The SDL winsys with emscripten only supports "
|
|
|
|
"the GLES2 driver");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#elif !defined (COGL_HAS_SDL_GLES_SUPPORT)
|
2011-12-14 07:09:53 -05:00
|
|
|
if (renderer->driver != COGL_DRIVER_GL)
|
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error, COGL_WINSYS_ERROR,
|
2011-12-14 07:09:53 -05:00
|
|
|
COGL_WINSYS_ERROR_INIT,
|
|
|
|
"The SDL winsys only supports the GL driver");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-04-27 21:42:24 -04:00
|
|
|
#endif
|
2011-12-14 07:09:53 -05:00
|
|
|
|
|
|
|
if (SDL_Init (SDL_INIT_VIDEO) == -1)
|
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error, COGL_WINSYS_ERROR,
|
2011-12-14 07:09:53 -05:00
|
|
|
COGL_WINSYS_ERROR_INIT,
|
|
|
|
"SDL_Init failed: %s",
|
|
|
|
SDL_GetError ());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer->winsys = g_slice_new0 (CoglRendererSdl);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_winsys_display_destroy (CoglDisplay *display)
|
|
|
|
{
|
|
|
|
CoglDisplaySdl *sdl_display = display->winsys;
|
|
|
|
|
|
|
|
_COGL_RETURN_IF_FAIL (sdl_display != NULL);
|
|
|
|
|
|
|
|
/* No need to destroy the surface - it is freed by SDL_Quit */
|
|
|
|
|
|
|
|
g_slice_free (CoglDisplaySdl, display->winsys);
|
|
|
|
display->winsys = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_gl_attribs_from_framebuffer_config (CoglFramebufferConfig *config)
|
|
|
|
{
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1);
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE,
|
|
|
|
config->need_stencil ? 1 : 0);
|
|
|
|
|
2012-11-13 07:10:13 -05:00
|
|
|
if (config->swap_chain->length >= 0)
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER,
|
|
|
|
config->swap_chain->length > 1 ? 1 : 0);
|
2011-12-14 07:09:53 -05:00
|
|
|
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE,
|
|
|
|
config->swap_chain->has_alpha ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-12-14 07:09:53 -05:00
|
|
|
_cogl_winsys_display_setup (CoglDisplay *display,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2011-12-14 07:09:53 -05:00
|
|
|
{
|
|
|
|
CoglDisplaySdl *sdl_display;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (display->winsys == NULL, FALSE);
|
|
|
|
|
|
|
|
sdl_display = g_slice_new0 (CoglDisplaySdl);
|
|
|
|
display->winsys = sdl_display;
|
|
|
|
|
|
|
|
set_gl_attribs_from_framebuffer_config (&display->onscreen_template->config);
|
|
|
|
|
2011-12-19 06:51:58 -05:00
|
|
|
switch (display->renderer->driver)
|
|
|
|
{
|
|
|
|
case COGL_DRIVER_GL:
|
|
|
|
sdl_display->video_mode_flags = SDL_OPENGL;
|
|
|
|
break;
|
|
|
|
|
2012-09-26 15:32:36 -04:00
|
|
|
case COGL_DRIVER_GL3:
|
|
|
|
_cogl_set_error (error, COGL_WINSYS_ERROR,
|
|
|
|
COGL_WINSYS_ERROR_INIT,
|
|
|
|
"The SDL winsys does not support GL 3");
|
|
|
|
goto error;
|
|
|
|
|
2011-12-19 06:51:58 -05:00
|
|
|
#ifdef COGL_HAS_SDL_GLES_SUPPORT
|
|
|
|
case COGL_DRIVER_GLES2:
|
|
|
|
sdl_display->video_mode_flags = SDL_OPENGLES;
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_DRIVER_GLES1:
|
|
|
|
sdl_display->video_mode_flags = SDL_OPENGLES;
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
|
|
|
break;
|
2013-04-27 21:42:24 -04:00
|
|
|
|
|
|
|
#elif defined (USING_EMSCRIPTEN)
|
|
|
|
case COGL_DRIVER_GLES2:
|
|
|
|
sdl_display->video_mode_flags = SDL_OPENGL;
|
|
|
|
break;
|
|
|
|
#endif
|
2011-12-19 06:51:58 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
/* There's no way to know what size the application will need until
|
|
|
|
it creates the first onscreen but we need to set the video mode
|
|
|
|
now so that we can get a GL context. We'll have to just guess at
|
|
|
|
a size an resize it later */
|
2011-12-19 06:51:58 -05:00
|
|
|
sdl_display->surface = SDL_SetVideoMode (640, 480, /* width/height */
|
|
|
|
0, /* bitsperpixel */
|
|
|
|
sdl_display->video_mode_flags);
|
2011-12-14 07:09:53 -05:00
|
|
|
|
|
|
|
if (sdl_display->surface == NULL)
|
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error, COGL_WINSYS_ERROR,
|
2011-12-14 07:09:53 -05:00
|
|
|
COGL_WINSYS_ERROR_INIT,
|
|
|
|
"SDL_SetVideoMode failed: %s",
|
|
|
|
SDL_GetError ());
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
_cogl_winsys_display_destroy (display);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-18 09:19:43 -04:00
|
|
|
static void
|
|
|
|
flush_pending_resize_notification_idle (void *user_data)
|
|
|
|
{
|
|
|
|
CoglContext *context = user_data;
|
|
|
|
CoglRenderer *renderer = context->display->renderer;
|
|
|
|
CoglRendererSdl *sdl_renderer = renderer->winsys;
|
|
|
|
CoglDisplaySdl *sdl_display = context->display->winsys;
|
|
|
|
CoglOnscreen *onscreen = sdl_display->onscreen;
|
|
|
|
|
|
|
|
/* This needs to be disconnected before invoking the callbacks in
|
|
|
|
* case the callbacks cause it to be queued again */
|
|
|
|
_cogl_closure_disconnect (sdl_renderer->resize_notify_idle);
|
|
|
|
sdl_renderer->resize_notify_idle = NULL;
|
|
|
|
|
|
|
|
_cogl_onscreen_notify_resize (onscreen);
|
|
|
|
}
|
|
|
|
|
2012-06-20 11:22:36 -04:00
|
|
|
static CoglFilterReturn
|
|
|
|
sdl_event_filter_cb (SDL_Event *event, void *data)
|
|
|
|
{
|
2013-05-14 08:39:48 -04:00
|
|
|
CoglContext *context = data;
|
|
|
|
CoglDisplay *display = context->display;
|
|
|
|
CoglDisplaySdl *sdl_display = display->winsys;
|
|
|
|
CoglFramebuffer *framebuffer;
|
|
|
|
|
|
|
|
if (!sdl_display->onscreen)
|
|
|
|
return COGL_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
framebuffer = COGL_FRAMEBUFFER (sdl_display->onscreen);
|
|
|
|
|
2012-06-20 11:22:36 -04:00
|
|
|
if (event->type == SDL_VIDEORESIZE)
|
|
|
|
{
|
2013-04-18 09:19:43 -04:00
|
|
|
CoglRenderer *renderer = display->renderer;
|
|
|
|
CoglRendererSdl *sdl_renderer = renderer->winsys;
|
2012-06-20 11:22:36 -04:00
|
|
|
float width = event->resize.w;
|
|
|
|
float height = event->resize.h;
|
|
|
|
|
|
|
|
sdl_display->surface = SDL_SetVideoMode (width, height,
|
|
|
|
0, /* bitsperpixel */
|
|
|
|
sdl_display->video_mode_flags);
|
|
|
|
|
|
|
|
_cogl_framebuffer_winsys_update_size (framebuffer, width, height);
|
|
|
|
|
|
|
|
/* We only want to notify that a resize happened when the
|
2013-04-16 18:46:03 -04:00
|
|
|
* application calls cogl_context_dispatch so instead of
|
2013-04-18 09:19:43 -04:00
|
|
|
* immediately notifying we queue an idle callback */
|
|
|
|
if (!sdl_renderer->resize_notify_idle)
|
|
|
|
{
|
|
|
|
sdl_renderer->resize_notify_idle =
|
|
|
|
_cogl_poll_renderer_add_idle (renderer,
|
|
|
|
flush_pending_resize_notification_idle,
|
|
|
|
context,
|
|
|
|
NULL);
|
|
|
|
}
|
2012-06-20 11:22:36 -04:00
|
|
|
|
|
|
|
return COGL_FILTER_CONTINUE;
|
|
|
|
}
|
2013-05-14 08:39:48 -04:00
|
|
|
else if (event->type == SDL_VIDEOEXPOSE)
|
|
|
|
{
|
|
|
|
CoglOnscreenDirtyInfo info;
|
|
|
|
|
|
|
|
/* Sadly SDL doesn't seem to report the rectangle of the expose
|
|
|
|
* event so we'll just queue the whole window */
|
|
|
|
info.x = 0;
|
|
|
|
info.y = 0;
|
|
|
|
info.width = framebuffer->width;
|
|
|
|
info.height = framebuffer->height;
|
|
|
|
|
|
|
|
_cogl_onscreen_queue_dirty (COGL_ONSCREEN (framebuffer), &info);
|
|
|
|
}
|
2012-06-20 11:22:36 -04:00
|
|
|
|
|
|
|
return COGL_FILTER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_winsys_context_init (CoglContext *context, CoglError **error)
|
2011-12-14 07:09:53 -05:00
|
|
|
{
|
2012-04-06 06:16:19 -04:00
|
|
|
CoglRenderer *renderer = context->display->renderer;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (renderer->sdl_event_type_set == FALSE))
|
|
|
|
g_error ("cogl_sdl_renderer_set_event_type() or cogl_sdl_context_new() "
|
|
|
|
"must be called during initialization");
|
|
|
|
|
2012-06-20 11:22:36 -04:00
|
|
|
_cogl_renderer_add_native_filter (renderer,
|
|
|
|
(CoglNativeFilterFunc)sdl_event_filter_cb,
|
|
|
|
context);
|
|
|
|
|
2013-05-14 08:39:48 -04:00
|
|
|
/* We'll manually handle queueing dirty events in response to
|
|
|
|
* SDL_VIDEOEXPOSE events */
|
2013-11-25 11:11:36 -05:00
|
|
|
COGL_FLAGS_SET (context->private_features,
|
|
|
|
COGL_PRIVATE_FEATURE_DIRTY_EVENTS,
|
|
|
|
TRUE);
|
2013-05-14 08:39:48 -04:00
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
return _cogl_context_update_features (context, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_winsys_context_deinit (CoglContext *context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
|
|
|
|
CoglDisplay *display = context->display;
|
|
|
|
CoglDisplaySdl *sdl_display = display->winsys;
|
|
|
|
|
2012-06-20 11:22:36 -04:00
|
|
|
sdl_display->onscreen = NULL;
|
2011-12-14 07:09:53 -05:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-12-14 07:09:53 -05:00
|
|
|
_cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2011-12-14 07:09:53 -05:00
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglContext *context = framebuffer->context;
|
|
|
|
CoglDisplay *display = context->display;
|
|
|
|
CoglDisplaySdl *sdl_display = display->winsys;
|
2012-11-20 13:50:42 -05:00
|
|
|
CoglBool flags_changed = FALSE;
|
2011-12-14 07:09:53 -05:00
|
|
|
int width, height;
|
|
|
|
|
2012-06-20 11:22:36 -04:00
|
|
|
if (sdl_display->onscreen)
|
2011-12-14 07:09:53 -05:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error, COGL_WINSYS_ERROR,
|
2011-12-14 07:09:53 -05:00
|
|
|
COGL_WINSYS_ERROR_CREATE_ONSCREEN,
|
|
|
|
"SDL winsys only supports a single onscreen window");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = cogl_framebuffer_get_width (framebuffer);
|
|
|
|
height = cogl_framebuffer_get_height (framebuffer);
|
|
|
|
|
2012-11-20 13:50:42 -05:00
|
|
|
if (cogl_onscreen_get_resizable (onscreen))
|
|
|
|
{
|
|
|
|
sdl_display->video_mode_flags |= SDL_RESIZABLE;
|
|
|
|
flags_changed = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
/* Try to update the video size using the onscreen size */
|
|
|
|
if (width != sdl_display->surface->w ||
|
2012-11-20 13:50:42 -05:00
|
|
|
height != sdl_display->surface->h ||
|
|
|
|
flags_changed)
|
2011-12-14 07:09:53 -05:00
|
|
|
{
|
2011-12-19 06:51:58 -05:00
|
|
|
sdl_display->surface = SDL_SetVideoMode (width, height,
|
|
|
|
0, /* bitsperpixel */
|
|
|
|
sdl_display->video_mode_flags);
|
2011-12-14 07:09:53 -05:00
|
|
|
|
|
|
|
if (sdl_display->surface == NULL)
|
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error, COGL_WINSYS_ERROR,
|
2011-12-14 07:09:53 -05:00
|
|
|
COGL_WINSYS_ERROR_CREATE_ONSCREEN,
|
|
|
|
"SDL_SetVideoMode failed: %s",
|
|
|
|
SDL_GetError ());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_framebuffer_winsys_update_size (framebuffer,
|
|
|
|
sdl_display->surface->w,
|
|
|
|
sdl_display->surface->h);
|
|
|
|
|
2012-06-20 11:22:36 -04:00
|
|
|
sdl_display->onscreen = onscreen;
|
2011-12-14 07:09:53 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-07 12:59:51 -05:00
|
|
|
_cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
|
|
|
|
const int *rectangles,
|
|
|
|
int n_rectangles)
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
{
|
2011-12-14 07:09:53 -05:00
|
|
|
SDL_GL_SwapBuffers ();
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
static void
|
|
|
|
_cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
/* SDL doesn't appear to provide a way to set this */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool visibility)
|
2011-12-14 07:09:53 -05:00
|
|
|
{
|
|
|
|
/* SDL doesn't appear to provide a way to set this */
|
|
|
|
}
|
|
|
|
|
2012-06-20 11:22:36 -04:00
|
|
|
static void
|
|
|
|
_cogl_winsys_onscreen_set_resizable (CoglOnscreen *onscreen,
|
|
|
|
CoglBool resizable)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglContext *context = framebuffer->context;
|
|
|
|
CoglDisplay *display = context->display;
|
|
|
|
CoglDisplaySdl *sdl_display = display->winsys;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
width = cogl_framebuffer_get_width (framebuffer);
|
|
|
|
height = cogl_framebuffer_get_height (framebuffer);
|
|
|
|
|
|
|
|
if (resizable)
|
|
|
|
sdl_display->video_mode_flags |= SDL_RESIZABLE;
|
|
|
|
else
|
|
|
|
sdl_display->video_mode_flags &= ~SDL_RESIZABLE;
|
|
|
|
|
|
|
|
sdl_display->surface = SDL_SetVideoMode (width, height,
|
|
|
|
0, /* bitsperpixel */
|
|
|
|
sdl_display->video_mode_flags);
|
|
|
|
}
|
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
const CoglWinsysVtable *
|
|
|
|
_cogl_winsys_sdl_get_vtable (void)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool vtable_inited = FALSE;
|
2011-12-14 07:09:53 -05:00
|
|
|
static CoglWinsysVtable vtable;
|
|
|
|
|
|
|
|
/* It would be nice if we could use C99 struct initializers here
|
|
|
|
like the GLX backend does. However this code is more likely to be
|
|
|
|
compiled using Visual Studio which (still!) doesn't support them
|
|
|
|
so we initialize it in code instead */
|
|
|
|
|
|
|
|
if (!vtable_inited)
|
|
|
|
{
|
|
|
|
memset (&vtable, 0, sizeof (vtable));
|
|
|
|
|
|
|
|
vtable.id = COGL_WINSYS_ID_SDL;
|
|
|
|
vtable.name = "SDL";
|
|
|
|
vtable.renderer_get_proc_address = _cogl_winsys_renderer_get_proc_address;
|
|
|
|
vtable.renderer_connect = _cogl_winsys_renderer_connect;
|
|
|
|
vtable.renderer_disconnect = _cogl_winsys_renderer_disconnect;
|
|
|
|
vtable.display_setup = _cogl_winsys_display_setup;
|
|
|
|
vtable.display_destroy = _cogl_winsys_display_destroy;
|
|
|
|
vtable.context_init = _cogl_winsys_context_init;
|
|
|
|
vtable.context_deinit = _cogl_winsys_context_deinit;
|
|
|
|
vtable.onscreen_init = _cogl_winsys_onscreen_init;
|
|
|
|
vtable.onscreen_deinit = _cogl_winsys_onscreen_deinit;
|
|
|
|
vtable.onscreen_bind = _cogl_winsys_onscreen_bind;
|
2012-02-07 12:59:51 -05:00
|
|
|
vtable.onscreen_swap_buffers_with_damage =
|
|
|
|
_cogl_winsys_onscreen_swap_buffers_with_damage;
|
2011-12-14 07:09:53 -05:00
|
|
|
vtable.onscreen_update_swap_throttled =
|
|
|
|
_cogl_winsys_onscreen_update_swap_throttled;
|
|
|
|
vtable.onscreen_set_visibility = _cogl_winsys_onscreen_set_visibility;
|
2012-06-20 11:22:36 -04:00
|
|
|
vtable.onscreen_set_resizable = _cogl_winsys_onscreen_set_resizable;
|
|
|
|
|
2011-12-14 07:09:53 -05:00
|
|
|
vtable_inited = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &vtable;
|
|
|
|
}
|