2009-11-17 13:52:40 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-11-17 13:52:40 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Intel Corporation.
|
|
|
|
*
|
2014-02-22 01:28:54 +00: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:
|
2009-11-17 13:52:40 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2009-11-17 13:52:40 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00: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 12:56:10 +00:00
|
|
|
*
|
|
|
|
*
|
2009-11-17 13:52:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2009-11-17 13:52:40 +00:00
|
|
|
|
|
|
|
#include "cogl-feature-private.h"
|
2011-07-27 11:30:02 +00:00
|
|
|
#include "cogl-renderer-private.h"
|
2012-09-26 19:32:36 +00:00
|
|
|
#include "cogl-private.h"
|
2009-11-17 13:52:40 +00: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 20:56:40 +00:00
|
|
|
CoglBool
|
2011-07-27 11:30:02 +00:00
|
|
|
_cogl_feature_check (CoglRenderer *renderer,
|
2011-05-24 00:38:48 +00:00
|
|
|
const char *driver_prefix,
|
2010-06-02 16:55:56 +00:00
|
|
|
const CoglFeatureData *data,
|
2011-07-06 17:59:20 +00:00
|
|
|
int gl_major,
|
|
|
|
int gl_minor,
|
2011-07-07 19:44:56 +00:00
|
|
|
CoglDriver driver,
|
2012-09-26 19:32:36 +00:00
|
|
|
char * const *extensions,
|
2010-11-05 12:28:33 +00:00
|
|
|
void *function_table)
|
2009-11-17 13:52:40 +00:00
|
|
|
|
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
const char *suffix = NULL;
|
2009-11-17 13:52:40 +00:00
|
|
|
int func_num;
|
2014-04-01 13:54:38 +00:00
|
|
|
CoglExtGlesAvailability gles_availability = 0;
|
2012-06-20 11:42:31 +00:00
|
|
|
CoglBool in_core;
|
2009-11-17 13:52:40 +00:00
|
|
|
|
2014-04-01 13:54:38 +00:00
|
|
|
switch (driver)
|
|
|
|
{
|
|
|
|
case COGL_DRIVER_GLES1:
|
|
|
|
gles_availability = COGL_EXT_IN_GLES;
|
|
|
|
break;
|
|
|
|
case COGL_DRIVER_GLES2:
|
|
|
|
gles_availability = COGL_EXT_IN_GLES2;
|
|
|
|
|
|
|
|
if (COGL_CHECK_GL_VERSION (gl_major, gl_minor, 3, 0))
|
|
|
|
gles_availability |= COGL_EXT_IN_GLES3;
|
|
|
|
break;
|
|
|
|
case COGL_DRIVER_ANY:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
case COGL_DRIVER_WEBGL:
|
|
|
|
/* FIXME: WebGL should probably have its own COGL_EXT_IN_WEBGL flag */
|
|
|
|
break;
|
|
|
|
case COGL_DRIVER_NOP:
|
|
|
|
case COGL_DRIVER_GL:
|
|
|
|
case COGL_DRIVER_GL3:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-17 13:52:40 +00:00
|
|
|
/* First check whether the functions should be directly provided by
|
|
|
|
GL */
|
2012-09-26 19:32:36 +00:00
|
|
|
if (((driver == COGL_DRIVER_GL ||
|
|
|
|
driver == COGL_DRIVER_GL3) &&
|
2011-07-07 19:44:56 +00:00
|
|
|
COGL_CHECK_GL_VERSION (gl_major, gl_minor,
|
|
|
|
data->min_gl_major, data->min_gl_minor)) ||
|
2014-04-01 13:54:38 +00:00
|
|
|
(data->gles_availability & gles_availability))
|
2012-06-20 11:42:31 +00:00
|
|
|
{
|
|
|
|
suffix = "";
|
|
|
|
in_core = TRUE;
|
|
|
|
}
|
2009-11-17 13:52:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise try all of the extensions */
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
const char *namespace, *namespace_suffix;
|
|
|
|
unsigned int namespace_len;
|
2009-11-17 13:52:40 +00:00
|
|
|
|
|
|
|
for (namespace = data->namespaces;
|
|
|
|
*namespace;
|
|
|
|
namespace += strlen (namespace) + 1)
|
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
const char *extension;
|
2009-11-17 13:52:40 +00:00
|
|
|
GString *full_extension_name = g_string_new ("");
|
|
|
|
|
|
|
|
/* If the namespace part contains a ':' then the suffix for
|
|
|
|
the function names is different from the name space */
|
|
|
|
if ((namespace_suffix = strchr (namespace, ':')))
|
|
|
|
{
|
|
|
|
namespace_len = namespace_suffix - namespace;
|
|
|
|
namespace_suffix++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
namespace_len = strlen (namespace);
|
|
|
|
namespace_suffix = namespace;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (extension = data->extension_names;
|
|
|
|
*extension;
|
|
|
|
extension += strlen (extension) + 1)
|
|
|
|
{
|
2010-06-02 16:55:56 +00:00
|
|
|
g_string_assign (full_extension_name, driver_prefix);
|
|
|
|
g_string_append_c (full_extension_name, '_');
|
2009-11-17 13:52:40 +00:00
|
|
|
g_string_append_len (full_extension_name,
|
|
|
|
namespace, namespace_len);
|
|
|
|
g_string_append_c (full_extension_name, '_');
|
|
|
|
g_string_append (full_extension_name, extension);
|
2011-07-06 17:59:20 +00:00
|
|
|
if (_cogl_check_extension (full_extension_name->str,
|
2012-09-26 19:32:36 +00:00
|
|
|
extensions))
|
2009-11-17 13:52:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free (full_extension_name, TRUE);
|
|
|
|
|
2011-07-06 17:59:20 +00:00
|
|
|
/* If we found an extension with this namespace then use it
|
|
|
|
as the suffix */
|
|
|
|
if (*extension)
|
2009-11-17 13:52:40 +00:00
|
|
|
{
|
|
|
|
suffix = namespace_suffix;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-20 11:42:31 +00:00
|
|
|
|
|
|
|
in_core = FALSE;
|
2009-11-17 13:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we couldn't find anything that provides the functions then
|
|
|
|
give up */
|
|
|
|
if (suffix == NULL)
|
2011-05-24 00:38:48 +00:00
|
|
|
goto error;
|
2009-11-17 13:52:40 +00:00
|
|
|
|
|
|
|
/* Try to get all of the entry points */
|
|
|
|
for (func_num = 0; data->functions[func_num].name; func_num++)
|
|
|
|
{
|
|
|
|
void *func;
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
char *full_function_name;
|
2009-11-17 13:52:40 +00:00
|
|
|
|
|
|
|
full_function_name = g_strconcat (data->functions[func_num].name,
|
|
|
|
suffix, NULL);
|
2012-06-20 11:42:31 +00:00
|
|
|
func = _cogl_renderer_get_proc_address (renderer,
|
|
|
|
full_function_name,
|
|
|
|
in_core);
|
2009-11-17 13:52:40 +00:00
|
|
|
g_free (full_function_name);
|
|
|
|
|
|
|
|
if (func == NULL)
|
2011-05-24 00:38:48 +00:00
|
|
|
goto error;
|
2009-11-17 13:52:40 +00:00
|
|
|
|
|
|
|
/* Set the function pointer in the context */
|
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 20:56:40 +00:00
|
|
|
*(void **) ((uint8_t *) function_table +
|
2009-11-17 13:52:40 +00:00
|
|
|
data->functions[func_num].pointer_offset) = func;
|
|
|
|
}
|
|
|
|
|
2011-05-24 00:38:48 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* If the extension isn't found or one of the functions wasn't found
|
|
|
|
* then set all of the functions pointers to NULL so Cogl can safely
|
|
|
|
* do feature testing by just looking at the function pointers */
|
|
|
|
error:
|
|
|
|
for (func_num = 0; data->functions[func_num].name; func_num++)
|
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 20:56:40 +00:00
|
|
|
*(void **) ((uint8_t *) function_table +
|
2011-05-24 00:38:48 +00:00
|
|
|
data->functions[func_num].pointer_offset) = NULL;
|
|
|
|
|
|
|
|
return FALSE;
|
2009-11-17 13:52:40 +00:00
|
|
|
}
|
2011-07-06 17:59:20 +00:00
|
|
|
|
|
|
|
/* Define a set of arrays containing the functions required from GL
|
|
|
|
for each feature */
|
|
|
|
#define COGL_EXT_BEGIN(name, \
|
|
|
|
min_gl_major, min_gl_minor, \
|
|
|
|
gles_availability, \
|
|
|
|
namespaces, extension_names) \
|
|
|
|
static const CoglFeatureFunction cogl_ext_ ## name ## _funcs[] = {
|
|
|
|
#define COGL_EXT_FUNCTION(ret, name, args) \
|
|
|
|
{ G_STRINGIFY (name), G_STRUCT_OFFSET (CoglContext, name) },
|
|
|
|
#define COGL_EXT_END() \
|
|
|
|
{ NULL, 0 }, \
|
|
|
|
};
|
2012-01-01 21:45:07 +00:00
|
|
|
#include "gl-prototypes/cogl-all-functions.h"
|
2011-07-06 17:59:20 +00:00
|
|
|
|
|
|
|
/* Define an array of features */
|
|
|
|
#undef COGL_EXT_BEGIN
|
|
|
|
#define COGL_EXT_BEGIN(name, \
|
|
|
|
min_gl_major, min_gl_minor, \
|
|
|
|
gles_availability, \
|
|
|
|
namespaces, extension_names) \
|
|
|
|
{ min_gl_major, min_gl_minor, gles_availability, namespaces, \
|
|
|
|
extension_names, 0, 0, 0, \
|
|
|
|
cogl_ext_ ## name ## _funcs },
|
|
|
|
#undef COGL_EXT_FUNCTION
|
|
|
|
#define COGL_EXT_FUNCTION(ret, name, args)
|
|
|
|
#undef COGL_EXT_END
|
|
|
|
#define COGL_EXT_END()
|
|
|
|
|
|
|
|
static const CoglFeatureData
|
|
|
|
cogl_feature_ext_functions_data[] =
|
|
|
|
{
|
2012-01-01 21:45:07 +00:00
|
|
|
#include "gl-prototypes/cogl-all-functions.h"
|
2011-07-06 17:59:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_feature_check_ext_functions (CoglContext *context,
|
|
|
|
int gl_major,
|
|
|
|
int gl_minor,
|
2012-09-26 19:32:36 +00:00
|
|
|
char * const *gl_extensions)
|
2011-07-06 17:59:20 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (cogl_feature_ext_functions_data); i++)
|
2011-07-27 11:30:02 +00:00
|
|
|
_cogl_feature_check (context->display->renderer,
|
2011-07-06 17:59:20 +00:00
|
|
|
"GL", cogl_feature_ext_functions_data + i,
|
2011-07-07 19:44:56 +00:00
|
|
|
gl_major, gl_minor, context->driver,
|
2011-07-06 17:59:20 +00:00
|
|
|
gl_extensions,
|
|
|
|
context);
|
|
|
|
}
|