mirror of
https://github.com/brl/mutter.git
synced 2024-11-09 23:46:33 -05:00
058d79dce2
Previously if you need to depend on a new GL feature you had to: - Add typedefs for all of the functions in cogl-defines.h.in - Add function pointers for each of the functions in cogl-context-driver.h - Add an initializer for the function pointers in cogl-context-driver.c - Add a check for the extension and all of the functions in cogl_features_init. If the extension is available under multiple names then you have to duplicate the checks. This is quite tedious and error prone. This patch moves all of the features and their functions into a list of macro invocations in cogl-feature-functions.h. The macros can be redefined to implement all of the above tasks from the same header. The features are described in a struct with a pointer to a table of functions. A new function takes the feature description from this struct and checks for its availability. The feature can take a list of extension names with a list of alternate namespaces (such as "EXT" or "ARB"). It can also detect the feature from a particular version of GL. The typedefs are now gone and instead the function pointer in the Cogl context just directly contains the type. Some of the functions in the context were previously declared with the 'ARB' extension. This has been removed so that now all the functions have no suffix. This makes more sense when the extension could potentially be merged into GL core as well.
142 lines
4.3 KiB
C
142 lines
4.3 KiB
C
/*
|
|
* Cogl
|
|
*
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
*
|
|
* Copyright (C) 2009 Intel Corporation.
|
|
*
|
|
* 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 <string.h>
|
|
|
|
#include "cogl.h"
|
|
#include "cogl-context.h"
|
|
|
|
#include "cogl-feature-private.h"
|
|
|
|
gboolean
|
|
_cogl_feature_check (const CoglFeatureData *data,
|
|
guint gl_major, guint gl_minor,
|
|
const gchar *extensions_string)
|
|
|
|
{
|
|
const gchar *suffix = NULL;
|
|
int func_num;
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
/* First check whether the functions should be directly provided by
|
|
GL */
|
|
if (COGL_CHECK_GL_VERSION (gl_major, gl_minor,
|
|
data->min_gl_major, data->min_gl_minor))
|
|
suffix = "";
|
|
else
|
|
{
|
|
/* Otherwise try all of the extensions */
|
|
const gchar *namespace, *namespace_suffix;
|
|
guint namespace_len;
|
|
|
|
for (namespace = data->namespaces;
|
|
*namespace;
|
|
namespace += strlen (namespace) + 1)
|
|
{
|
|
const gchar *extension;
|
|
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)
|
|
{
|
|
g_string_set_size (full_extension_name, 0);
|
|
g_string_append (full_extension_name, "GL_");
|
|
g_string_append_len (full_extension_name,
|
|
namespace, namespace_len);
|
|
g_string_append_c (full_extension_name, '_');
|
|
g_string_append (full_extension_name, extension);
|
|
if (!cogl_check_extension (full_extension_name->str,
|
|
extensions_string))
|
|
break;
|
|
}
|
|
|
|
g_string_free (full_extension_name, TRUE);
|
|
|
|
/* If we found all of the extensions with this namespace
|
|
then use it as the suffix */
|
|
if (*extension == '\0')
|
|
{
|
|
suffix = namespace_suffix;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* If we couldn't find anything that provides the functions then
|
|
give up */
|
|
if (suffix == NULL)
|
|
return FALSE;
|
|
|
|
/* Try to get all of the entry points */
|
|
for (func_num = 0; data->functions[func_num].name; func_num++)
|
|
{
|
|
void *func;
|
|
gchar *full_function_name;
|
|
|
|
full_function_name = g_strconcat (data->functions[func_num].name,
|
|
suffix, NULL);
|
|
func = cogl_get_proc_address (full_function_name);
|
|
g_free (full_function_name);
|
|
|
|
if (func == NULL)
|
|
break;
|
|
|
|
/* Set the function pointer in the context */
|
|
*(void **) ((guchar *) ctx +
|
|
data->functions[func_num].pointer_offset) = func;
|
|
}
|
|
|
|
/* If one of the functions wasn't found then we should set all of
|
|
the function pointers back to NULL so that the rest of Cogl can
|
|
safely do feature testing by just looking at the function
|
|
pointers */
|
|
if (data->functions[func_num].name)
|
|
{
|
|
while (func_num-- > 0)
|
|
*(void **) ((guchar *) ctx +
|
|
data->functions[func_num].pointer_offset) = NULL;
|
|
return FALSE;
|
|
}
|
|
else
|
|
return TRUE;
|
|
}
|