diff --git a/cogl/cogl/cogl-atlas-texture.c b/cogl/cogl/cogl-atlas-texture.c index 04d8880854d645176a43e3bab3e20b4f25eee423..5374629fc0ae4812e625f8e935db209f370d18c2 100644 --- a/cogl/cogl/cogl-atlas-texture.c +++ b/cogl/cogl/cogl-atlas-texture.c @@ -48,7 +48,6 @@ #include "cogl1-context.h" #include "cogl-sub-texture.h" #include "cogl-gtype-private.h" -#include "driver/gl/cogl-pipeline-opengl-private.h" #include "driver/gl/cogl-texture-gl-private.h" #include diff --git a/cogl/cogl/cogl-attribute.c b/cogl/cogl/cogl-attribute.c index 6c1842e172988829c35b8eed95c2e1368ed5a444..1c0c88d0b988110b1972a1fdff5cef20a337522b 100644 --- a/cogl/cogl/cogl-attribute.c +++ b/cogl/cogl/cogl-attribute.c @@ -51,11 +51,6 @@ #include #include -/* This isn't defined in the GLES headers */ -#ifndef GL_UNSIGNED_INT -#define GL_UNSIGNED_INT 0x1405 -#endif - static void _cogl_attribute_free (CoglAttribute *attribute); COGL_OBJECT_DEFINE (Attribute, attribute); diff --git a/cogl/cogl/cogl-boxed-value.c b/cogl/cogl/cogl-boxed-value.c index 7d55231c0f901e2b5a952dc79447c8a3ea948797..9a9ba41c21887e68d74731547c558969d0f365c0 100644 --- a/cogl/cogl/cogl-boxed-value.c +++ b/cogl/cogl/cogl-boxed-value.c @@ -34,7 +34,6 @@ #include "cogl-boxed-value.h" #include "cogl-context-private.h" -#include "driver/gl/cogl-util-gl-private.h" gboolean _cogl_boxed_value_equal (const CoglBoxedValue *bva, @@ -286,90 +285,5 @@ _cogl_boxed_value_set_uniform (CoglContext *ctx, GLint location, const CoglBoxedValue *value) { - switch (value->type) - { - case COGL_BOXED_NONE: - break; - - case COGL_BOXED_INT: - { - const int *ptr; - - if (value->count == 1) - ptr = value->v.int_value; - else - ptr = value->v.int_array; - - switch (value->size) - { - case 1: - GE( ctx, glUniform1iv (location, value->count, ptr) ); - break; - case 2: - GE( ctx, glUniform2iv (location, value->count, ptr) ); - break; - case 3: - GE( ctx, glUniform3iv (location, value->count, ptr) ); - break; - case 4: - GE( ctx, glUniform4iv (location, value->count, ptr) ); - break; - } - } - break; - - case COGL_BOXED_FLOAT: - { - const float *ptr; - - if (value->count == 1) - ptr = value->v.float_value; - else - ptr = value->v.float_array; - - switch (value->size) - { - case 1: - GE( ctx, glUniform1fv (location, value->count, ptr) ); - break; - case 2: - GE( ctx, glUniform2fv (location, value->count, ptr) ); - break; - case 3: - GE( ctx, glUniform3fv (location, value->count, ptr) ); - break; - case 4: - GE( ctx, glUniform4fv (location, value->count, ptr) ); - break; - } - } - break; - - case COGL_BOXED_MATRIX: - { - const float *ptr; - - if (value->count == 1) - ptr = value->v.matrix; - else - ptr = value->v.float_array; - - switch (value->size) - { - case 2: - GE( ctx, glUniformMatrix2fv (location, value->count, - FALSE, ptr) ); - break; - case 3: - GE( ctx, glUniformMatrix3fv (location, value->count, - FALSE, ptr) ); - break; - case 4: - GE( ctx, glUniformMatrix4fv (location, value->count, - FALSE, ptr) ); - break; - } - } - break; - } + ctx->driver_vtable->set_uniform (ctx, location, value); } diff --git a/cogl/cogl/cogl-context-private.h b/cogl/cogl/cogl-context-private.h index 8dc5c2c23b5b5a76116416b345b0eeca53837c91..79d4f7b5ed72f744b1edc269c58ceb2f90c88042 100644 --- a/cogl/cogl/cogl-context-private.h +++ b/cogl/cogl/cogl-context-private.h @@ -46,7 +46,6 @@ #include "cogl-pipeline-cache.h" #include "cogl-texture-2d.h" #include "cogl-sampler-cache-private.h" -#include "cogl-gpu-info-private.h" #include "cogl-gl-header.h" #include "cogl-framebuffer-private.h" #include "cogl-onscreen-private.h" @@ -70,14 +69,12 @@ struct _CoglContext CoglDriver driver; - /* Information about the GPU and driver which we can use to - determine certain workarounds */ - CoglGpuInfo gpu; - /* vtables for the driver functions */ const CoglDriverVtable *driver_vtable; const CoglTextureDriver *texture_driver; + void *driver_context; + int glsl_major; int glsl_minor; @@ -124,9 +121,6 @@ struct _CoglContext CoglMatrixEntry identity_entry; - GArray *texture_units; - int active_texture_unit; - /* Only used for comparing other pipelines when reading pixels. */ CoglPipeline *opaque_color_pipeline; @@ -315,18 +309,4 @@ void _cogl_context_set_current_modelview_entry (CoglContext *context, CoglMatrixEntry *entry); -/* - * _cogl_context_get_gl_extensions: - * @context: A CoglContext - * - * Return value: a NULL-terminated array of strings representing the - * supported extensions by the current driver. This array is owned - * by the caller and should be freed with g_strfreev(). - */ -char ** -_cogl_context_get_gl_extensions (CoglContext *context); - -const char * -_cogl_context_get_gl_version (CoglContext *context); - #endif /* __COGL_CONTEXT_PRIVATE_H */ diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index 50b4b68aed621667fdbcfe5780eb0c14918c043f..dc99f3508627859cb1d153269ece1d58b4072b09 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -45,40 +45,12 @@ #include "cogl-onscreen-private.h" #include "cogl-attribute-private.h" #include "cogl1-context.h" -#include "cogl-gpu-info-private.h" #include "cogl-gtype-private.h" #include "winsys/cogl-winsys-private.h" #include #include -/* These aren't defined in the GLES headers */ -#ifndef GL_POINT_SPRITE -#define GL_POINT_SPRITE 0x8861 -#endif - -#ifndef GL_NUM_EXTENSIONS -#define GL_NUM_EXTENSIONS 0x821D -#endif - -/* This is a relatively new extension */ -#ifndef GL_PURGED_CONTEXT_RESET_NV -#define GL_PURGED_CONTEXT_RESET_NV 0x92BB -#endif - -/* These aren't defined in the GLES2 headers */ -#ifndef GL_GUILTY_CONTEXT_RESET_ARB -#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 -#endif - -#ifndef GL_INNOCENT_CONTEXT_RESET_ARB -#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 -#endif - -#ifndef GL_UNKNOWN_CONTEXT_RESET_ARB -#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 -#endif - static void _cogl_context_free (CoglContext *context); COGL_OBJECT_DEFINE (Context, context); @@ -470,94 +442,6 @@ _cogl_context_set_current_modelview_entry (CoglContext *context, context->current_modelview_entry = entry; } -char ** -_cogl_context_get_gl_extensions (CoglContext *context) -{ - const char *env_disabled_extensions; - char **ret; - - /* In GL 3, querying GL_EXTENSIONS is deprecated so we have to build - * the array using glGetStringi instead */ -#ifdef HAVE_COGL_GL - if (context->driver == COGL_DRIVER_GL3) - { - int num_extensions, i; - - context->glGetIntegerv (GL_NUM_EXTENSIONS, &num_extensions); - - ret = g_malloc (sizeof (char *) * (num_extensions + 1)); - - for (i = 0; i < num_extensions; i++) - { - const char *ext = - (const char *) context->glGetStringi (GL_EXTENSIONS, i); - ret[i] = g_strdup (ext); - } - - ret[num_extensions] = NULL; - } - else -#endif - { - const char *all_extensions = - (const char *) context->glGetString (GL_EXTENSIONS); - - ret = g_strsplit (all_extensions, " ", 0 /* max tokens */); - } - - if ((env_disabled_extensions = g_getenv ("COGL_DISABLE_GL_EXTENSIONS"))) - { - char **split_env_disabled_extensions; - char **src, **dst; - - if (env_disabled_extensions) - split_env_disabled_extensions = - g_strsplit (env_disabled_extensions, - ",", - 0 /* no max tokens */); - else - split_env_disabled_extensions = NULL; - - for (dst = ret, src = ret; - *src; - src++) - { - char **d; - - if (split_env_disabled_extensions) - for (d = split_env_disabled_extensions; *d; d++) - if (!strcmp (*src, *d)) - goto disabled; - - *(dst++) = *src; - continue; - - disabled: - g_free (*src); - continue; - } - - *dst = NULL; - - if (split_env_disabled_extensions) - g_strfreev (split_env_disabled_extensions); - } - - return ret; -} - -const char * -_cogl_context_get_gl_version (CoglContext *context) -{ - const char *version_override; - - if ((version_override = g_getenv ("COGL_OVERRIDE_GL_VERSION"))) - return version_override; - else - return (const char *) context->glGetString (GL_VERSION); - -} - int64_t cogl_get_clock_time (CoglContext *context) { @@ -572,24 +456,11 @@ cogl_get_clock_time (CoglContext *context) CoglGraphicsResetStatus cogl_get_graphics_reset_status (CoglContext *context) { - if (!context->glGetGraphicsResetStatus) - return COGL_GRAPHICS_RESET_STATUS_NO_ERROR; - - switch (context->glGetGraphicsResetStatus ()) - { - case GL_GUILTY_CONTEXT_RESET_ARB: - return COGL_GRAPHICS_RESET_STATUS_GUILTY_CONTEXT_RESET; - - case GL_INNOCENT_CONTEXT_RESET_ARB: - return COGL_GRAPHICS_RESET_STATUS_INNOCENT_CONTEXT_RESET; - - case GL_UNKNOWN_CONTEXT_RESET_ARB: - return COGL_GRAPHICS_RESET_STATUS_UNKNOWN_CONTEXT_RESET; - - case GL_PURGED_CONTEXT_RESET_NV: - return COGL_GRAPHICS_RESET_STATUS_PURGED_CONTEXT_RESET; + return context->driver_vtable->get_graphics_reset_status (context); +} - default: - return COGL_GRAPHICS_RESET_STATUS_NO_ERROR; - } +gboolean +cogl_context_is_hardware_accelerated (CoglContext *context) +{ + return context->driver_vtable->is_hardware_accelerated (context); } diff --git a/cogl/cogl/cogl-context.h b/cogl/cogl/cogl-context.h index 2807f2a5ac39999d6303df9cc807436f6e3c72cc..e0d79d92780fb9abf634e65a11c53dfed9906c8d 100644 --- a/cogl/cogl/cogl-context.h +++ b/cogl/cogl/cogl-context.h @@ -357,6 +357,16 @@ typedef enum _CoglGraphicsResetStatus COGL_EXPORT CoglGraphicsResetStatus cogl_get_graphics_reset_status (CoglContext *context); +/** + * cogl_context_is_hardware_accelerated: + * @context: a #CoglContext pointer + * + * Returns: %TRUE if the @context is hardware accelerated, or %FALSE if + * not. + */ +COGL_EXPORT gboolean +cogl_context_is_hardware_accelerated (CoglContext *context); + G_END_DECLS #endif /* __COGL_CONTEXT_H__ */ diff --git a/cogl/cogl/cogl-driver.h b/cogl/cogl/cogl-driver.h index 5dcecf86298db6252bbdb23678a88316a0f22bab..d8f3cc18fe6f152f74ecb5deec51360432a40071 100644 --- a/cogl/cogl/cogl-driver.h +++ b/cogl/cogl/cogl-driver.h @@ -35,6 +35,7 @@ #include "cogl-offscreen.h" #include "cogl-framebuffer-private.h" #include "cogl-attribute-private.h" +#include "cogl-sampler-cache-private.h" typedef struct _CoglDriverVtable CoglDriverVtable; @@ -46,6 +47,12 @@ struct _CoglDriverVtable void (* context_deinit) (CoglContext *context); + gboolean + (* is_hardware_accelerated) (CoglContext *context); + + CoglGraphicsResetStatus + (* get_graphics_reset_status) (CoglContext *context); + /* TODO: factor this out since this is OpenGL specific and * so can be ignored by non-OpenGL drivers. */ gboolean @@ -262,6 +269,19 @@ struct _CoglDriverVtable const void *data, unsigned int size, GError **error); + + void + (*sampler_init) (CoglContext *context, + CoglSamplerCacheEntry *entry); + + void + (*sampler_free) (CoglContext *context, + CoglSamplerCacheEntry *entry); + + void + (* set_uniform) (CoglContext *ctx, + GLint location, + const CoglBoxedValue *value); }; #define COGL_DRIVER_ERROR (_cogl_driver_error_quark ()) diff --git a/cogl/cogl/cogl-glsl-shader-private.h b/cogl/cogl/cogl-glsl-shader-private.h deleted file mode 100644 index 9899c12c15d849612b545acccdc5a97150973366..0000000000000000000000000000000000000000 --- a/cogl/cogl/cogl-glsl-shader-private.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Cogl - * - * A Low Level GPU Graphics and Utilities API - * - * Copyright (C) 2012 Intel Corporation. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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. - */ - -#ifndef _COGL_GLSL_SHADER_PRIVATE_H_ -#define _COGL_GLSL_SHADER_PRIVATE_H_ - -void -_cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx, - GLuint shader_gl_handle, - GLenum shader_gl_type, - CoglPipeline *pipeline, - GLsizei count_in, - const char **strings_in, - const GLint *lengths_in); - -#endif /* _COGL_GLSL_SHADER_PRIVATE_H_ */ diff --git a/cogl/cogl/cogl-glsl-shader.c b/cogl/cogl/cogl-glsl-shader.c deleted file mode 100644 index fda923c34339b20df6e386a0ac102d76be562a25..0000000000000000000000000000000000000000 --- a/cogl/cogl/cogl-glsl-shader.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Cogl - * - * A Low Level GPU Graphics and Utilities API - * - * Copyright (C) 2012 Intel Corporation. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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. - * - * - * - * Authors: - * Robert Bragg - * Neil Roberts - */ - -#include "cogl-config.h" - -#include "cogl-context-private.h" -#include "cogl-glsl-shader-private.h" -#include "cogl-glsl-shader-boilerplate.h" -#include "driver/gl/cogl-util-gl-private.h" - -#include - -#include - -static gboolean -add_layer_vertex_boilerplate_cb (CoglPipelineLayer *layer, - void *user_data) -{ - GString *layer_declarations = user_data; - int unit_index = _cogl_pipeline_layer_get_unit_index (layer); - g_string_append_printf (layer_declarations, - "attribute vec4 cogl_tex_coord%d_in;\n" - "#define cogl_texture_matrix%i cogl_texture_matrix[%i]\n" - "#define cogl_tex_coord%i_out _cogl_tex_coord[%i]\n", - layer->index, - layer->index, - unit_index, - layer->index, - unit_index); - return TRUE; -} - -static gboolean -add_layer_fragment_boilerplate_cb (CoglPipelineLayer *layer, - void *user_data) -{ - GString *layer_declarations = user_data; - g_string_append_printf (layer_declarations, - "#define cogl_tex_coord%i_in _cogl_tex_coord[%i]\n", - layer->index, - _cogl_pipeline_layer_get_unit_index (layer)); - return TRUE; -} - -void -_cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx, - GLuint shader_gl_handle, - GLenum shader_gl_type, - CoglPipeline *pipeline, - GLsizei count_in, - const char **strings_in, - const GLint *lengths_in) -{ - const char *vertex_boilerplate; - const char *fragment_boilerplate; - - const char **strings = g_alloca (sizeof (char *) * (count_in + 4)); - GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 4)); - char *version_string; - int count = 0; - - int n_layers; - - vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE; - fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE; - - version_string = g_strdup_printf ("#version %i\n\n", - ctx->glsl_version_to_use); - strings[count] = version_string; - lengths[count++] = -1; - - if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_EGL_IMAGE_EXTERNAL)) - { - static const char image_external_extension[] = - "#extension GL_OES_EGL_image_external : require\n"; - strings[count] = image_external_extension; - lengths[count++] = sizeof (image_external_extension) - 1; - } - - if (shader_gl_type == GL_VERTEX_SHADER) - { - strings[count] = vertex_boilerplate; - lengths[count++] = strlen (vertex_boilerplate); - } - else if (shader_gl_type == GL_FRAGMENT_SHADER) - { - strings[count] = fragment_boilerplate; - lengths[count++] = strlen (fragment_boilerplate); - } - - n_layers = cogl_pipeline_get_n_layers (pipeline); - if (n_layers) - { - GString *layer_declarations = ctx->codegen_boilerplate_buffer; - g_string_set_size (layer_declarations, 0); - - g_string_append_printf (layer_declarations, - "varying vec4 _cogl_tex_coord[%d];\n", - n_layers); - - if (shader_gl_type == GL_VERTEX_SHADER) - { - g_string_append_printf (layer_declarations, - "uniform mat4 cogl_texture_matrix[%d];\n", - n_layers); - - _cogl_pipeline_foreach_layer_internal (pipeline, - add_layer_vertex_boilerplate_cb, - layer_declarations); - } - else if (shader_gl_type == GL_FRAGMENT_SHADER) - { - _cogl_pipeline_foreach_layer_internal (pipeline, - add_layer_fragment_boilerplate_cb, - layer_declarations); - } - - strings[count] = layer_declarations->str; - lengths[count++] = -1; /* null terminated */ - } - - memcpy (strings + count, strings_in, sizeof (char *) * count_in); - if (lengths_in) - memcpy (lengths + count, lengths_in, sizeof (GLint) * count_in); - else - { - int i; - - for (i = 0; i < count_in; i++) - lengths[count + i] = -1; /* null terminated */ - } - count += count_in; - - if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE))) - { - GString *buf = g_string_new (NULL); - int i; - - g_string_append_printf (buf, - "%s shader:\n", - shader_gl_type == GL_VERTEX_SHADER ? - "vertex" : "fragment"); - for (i = 0; i < count; i++) - if (lengths[i] != -1) - g_string_append_len (buf, strings[i], lengths[i]); - else - g_string_append (buf, strings[i]); - - g_message ("%s", buf->str); - - g_string_free (buf, TRUE); - } - - GE( ctx, glShaderSource (shader_gl_handle, count, - (const char **) strings, lengths) ); - - g_free (version_string); -} diff --git a/cogl/cogl/cogl-gpu-info-private.h b/cogl/cogl/cogl-gpu-info-private.h deleted file mode 100644 index 7ab4950f8ace568df5e2f906a95c27dc650a6830..0000000000000000000000000000000000000000 --- a/cogl/cogl/cogl-gpu-info-private.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Cogl - * - * A Low Level GPU Graphics and Utilities API - * - * Copyright (C) 2012 Intel Corporation. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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. - * - * - */ - -#ifndef __COGL_GPU_INFO_PRIVATE_H -#define __COGL_GPU_INFO_PRIVATE_H - -#include "cogl-context.h" - -typedef enum _CoglGpuInfoArchitectureFlag -{ - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE, - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_TILED, - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_SOFTWARE, - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE, - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_DEFERRED, - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_SOFTWARE -} CoglGpuInfoArchitectureFlag; - -typedef enum _CoglGpuInfoArchitecture -{ - COGL_GPU_INFO_ARCHITECTURE_UNKNOWN, - COGL_GPU_INFO_ARCHITECTURE_SANDYBRIDGE, - COGL_GPU_INFO_ARCHITECTURE_SGX, - COGL_GPU_INFO_ARCHITECTURE_MALI, - COGL_GPU_INFO_ARCHITECTURE_LLVMPIPE, - COGL_GPU_INFO_ARCHITECTURE_SOFTPIPE, - COGL_GPU_INFO_ARCHITECTURE_SWRAST -} CoglGpuInfoArchitecture; - -typedef enum -{ - COGL_GPU_INFO_VENDOR_UNKNOWN, - COGL_GPU_INFO_VENDOR_INTEL, - COGL_GPU_INFO_VENDOR_IMAGINATION_TECHNOLOGIES, - COGL_GPU_INFO_VENDOR_ARM, - COGL_GPU_INFO_VENDOR_QUALCOMM, - COGL_GPU_INFO_VENDOR_NVIDIA, - COGL_GPU_INFO_VENDOR_ATI, - COGL_GPU_INFO_VENDOR_MESA -} CoglGpuInfoVendor; - -typedef enum -{ - COGL_GPU_INFO_DRIVER_PACKAGE_UNKNOWN, - COGL_GPU_INFO_DRIVER_PACKAGE_MESA -} CoglGpuInfoDriverPackage; - -typedef enum -{ - COGL_GPU_INFO_DRIVER_STUB -} CoglGpuInfoDriverBug; - -typedef struct _CoglGpuInfoVersion CoglGpuInfoVersion; - -typedef struct _CoglGpuInfo CoglGpuInfo; - -struct _CoglGpuInfo -{ - CoglGpuInfoVendor vendor; - const char *vendor_name; - - CoglGpuInfoDriverPackage driver_package; - const char *driver_package_name; - int driver_package_version; - - CoglGpuInfoArchitecture architecture; - const char *architecture_name; - CoglGpuInfoArchitectureFlag architecture_flags; - - CoglGpuInfoDriverBug driver_bugs; -}; - -/* - * _cogl_gpu_info_init: - * @ctx: A #CoglContext - * @gpu: A return location for the GPU information - * - * Determines information about the GPU and driver from the given - * context. - */ -void -_cogl_gpu_info_init (CoglContext *ctx, - CoglGpuInfo *gpu); - -#endif /* __COGL_GPU_INFO_PRIVATE_H */ diff --git a/cogl/cogl/cogl-gpu-info.c b/cogl/cogl/cogl-gpu-info.c deleted file mode 100644 index f44319e96e8f63301ec04f9c7463a0682607d8cb..0000000000000000000000000000000000000000 --- a/cogl/cogl/cogl-gpu-info.c +++ /dev/null @@ -1,572 +0,0 @@ -/* - * Cogl - * - * A Low Level GPU Graphics and Utilities API - * - * Copyright (C) 2012 Intel Corporation. - * - * 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: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * 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. - * - * - */ - -#include "cogl-config.h" - -#include -#include - -#include - -#include "cogl-gpu-info-private.h" -#include "cogl-context-private.h" -#include "cogl-version.h" - -typedef struct -{ - const char *renderer_string; - const char *version_string; - const char *vendor_string; -} CoglGpuInfoStrings; - -typedef struct CoglGpuInfoArchitectureDescription -{ - CoglGpuInfoArchitecture architecture; - const char *name; - CoglGpuInfoArchitectureFlag flags; - gboolean (* check_function) (const CoglGpuInfoStrings *strings); - -} CoglGpuInfoArchitectureDescription; - -typedef struct -{ - CoglGpuInfoVendor vendor; - const char *name; - gboolean (* check_function) (const CoglGpuInfoStrings *strings); - const CoglGpuInfoArchitectureDescription *architectures; - -} CoglGpuInfoVendorDescription; - -typedef struct -{ - CoglGpuInfoDriverPackage driver_package; - const char *name; - gboolean (* check_function) (const CoglGpuInfoStrings *strings, - int *version_out); -} CoglGpuInfoDriverPackageDescription; - -static gboolean -_cogl_gpu_info_parse_version_string (const char *version_string, - int n_components, - const char **tail, - int *version_ret) -{ - int version = 0; - uint64_t part; - int i; - - for (i = 0; ; i++) - { - errno = 0; - part = g_ascii_strtoull (version_string, - (char **) &version_string, - 10); - - if (errno || part > COGL_VERSION_MAX_COMPONENT_VALUE) - return FALSE; - - version |= part << ((2 - i) * COGL_VERSION_COMPONENT_BITS); - - if (i + 1 >= n_components) - break; - - if (*version_string != '.') - return FALSE; - - version_string++; - } - - if (version_ret) - *version_ret = version; - if (tail) - *tail = version_string; - - return TRUE; -} - -static gboolean -match_phrase (const char *string, const char *phrase) -{ - const char *part = strstr (string, phrase); - int len; - - if (part == NULL) - return FALSE; - - /* The match must either be at the beginning of the string or - preceded by a space. */ - if (part > string && part[-1] != ' ') - return FALSE; - - /* Also match must either be at end of string or followed by a - * space. */ - len = strlen (phrase); - if (part[len] != '\0' && part[len] != ' ') - return FALSE; - - return TRUE; -} - -static gboolean -check_intel_vendor (const CoglGpuInfoStrings *strings) -{ - return match_phrase (strings->renderer_string, "Intel(R)"); -} - -static gboolean -check_imagination_technologies_vendor (const CoglGpuInfoStrings *strings) -{ - if (strcmp (strings->vendor_string, "Imagination Technologies") != 0) - return FALSE; - return TRUE; -} - -static gboolean -check_arm_vendor (const CoglGpuInfoStrings *strings) -{ - if (strcmp (strings->vendor_string, "ARM") != 0) - return FALSE; - return TRUE; -} - -static gboolean -check_qualcomm_vendor (const CoglGpuInfoStrings *strings) -{ - if (strcmp (strings->vendor_string, "Qualcomm") != 0) - return FALSE; - return TRUE; -} - -static gboolean -check_nvidia_vendor (const CoglGpuInfoStrings *strings) -{ - if (strcmp (strings->vendor_string, "NVIDIA") != 0 && - strcmp (strings->vendor_string, "NVIDIA Corporation") != 0) - return FALSE; - - return TRUE; -} - -static gboolean -check_ati_vendor (const CoglGpuInfoStrings *strings) -{ - if (strcmp (strings->vendor_string, "ATI") != 0) - return FALSE; - - return TRUE; -} - -static gboolean -check_mesa_vendor (const CoglGpuInfoStrings *strings) -{ - if (strcmp (strings->vendor_string, "Tungsten Graphics, Inc") == 0) - return TRUE; - else if (strcmp (strings->vendor_string, "VMware, Inc.") == 0) - return TRUE; - else if (strcmp (strings->vendor_string, "Mesa Project") == 0) - return TRUE; - - return FALSE; -} - -static gboolean -check_true (const CoglGpuInfoStrings *strings) -{ - /* This is a last resort so it always matches */ - return TRUE; -} - -static gboolean -check_sandybridge_architecture (const CoglGpuInfoStrings *strings) -{ - return match_phrase (strings->renderer_string, "Sandybridge"); -} - -static gboolean -check_llvmpipe_architecture (const CoglGpuInfoStrings *strings) -{ - return match_phrase (strings->renderer_string, "llvmpipe"); -} - -static gboolean -check_softpipe_architecture (const CoglGpuInfoStrings *strings) -{ - return match_phrase (strings->renderer_string, "softpipe"); -} - -static gboolean -check_swrast_architecture (const CoglGpuInfoStrings *strings) -{ - return match_phrase (strings->renderer_string, "software rasterizer") || - match_phrase (strings->renderer_string, "Software Rasterizer"); -} - -static gboolean -check_sgx_architecture (const CoglGpuInfoStrings *strings) -{ - if (strncmp (strings->renderer_string, "PowerVR SGX", 12) != 0) - return FALSE; - - return TRUE; -} - -static gboolean -check_mali_architecture (const CoglGpuInfoStrings *strings) -{ - if (strncmp (strings->renderer_string, "Mali-", 5) != 0) - return FALSE; - - return TRUE; -} - -static const CoglGpuInfoArchitectureDescription -intel_architectures[] = - { - { - COGL_GPU_INFO_ARCHITECTURE_SANDYBRIDGE, - "Sandybridge", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE, - check_sandybridge_architecture - }, - { - COGL_GPU_INFO_ARCHITECTURE_UNKNOWN, - "Unknown", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE, - check_true - } - }; - -static const CoglGpuInfoArchitectureDescription -powervr_architectures[] = - { - { - COGL_GPU_INFO_ARCHITECTURE_SGX, - "SGX", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_TILED | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_DEFERRED, - check_sgx_architecture - }, - { - COGL_GPU_INFO_ARCHITECTURE_UNKNOWN, - "Unknown", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_TILED | - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_TILED, - check_true - } - }; - -static const CoglGpuInfoArchitectureDescription -arm_architectures[] = - { - { - COGL_GPU_INFO_ARCHITECTURE_MALI, - "Mali", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_TILED | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE, - check_mali_architecture - }, - { - COGL_GPU_INFO_ARCHITECTURE_UNKNOWN, - "Unknown", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_TILED | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE, - check_true - } - }; - -static const CoglGpuInfoArchitectureDescription -mesa_architectures[] = - { - { - COGL_GPU_INFO_ARCHITECTURE_LLVMPIPE, - "LLVM Pipe", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_SOFTWARE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_SOFTWARE, - check_llvmpipe_architecture - }, - { - COGL_GPU_INFO_ARCHITECTURE_SOFTPIPE, - "Softpipe", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_SOFTWARE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_SOFTWARE, - check_softpipe_architecture - }, - { - COGL_GPU_INFO_ARCHITECTURE_SWRAST, - "SWRast", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_SOFTWARE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_SOFTWARE, - check_swrast_architecture - }, - { - COGL_GPU_INFO_ARCHITECTURE_UNKNOWN, - "Unknown", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE, - check_true - } - }; - -static const CoglGpuInfoArchitectureDescription -unknown_architectures[] = - { - { - COGL_GPU_INFO_ARCHITECTURE_UNKNOWN, - "Unknown", - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE | - COGL_GPU_INFO_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE, - check_true - } - }; - -static const CoglGpuInfoVendorDescription -_cogl_gpu_info_vendors[] = - { - { - COGL_GPU_INFO_VENDOR_INTEL, - "Intel", - check_intel_vendor, - intel_architectures - }, - { - COGL_GPU_INFO_VENDOR_IMAGINATION_TECHNOLOGIES, - "Imagination Technologies", - check_imagination_technologies_vendor, - powervr_architectures - }, - { - COGL_GPU_INFO_VENDOR_ARM, - "ARM", - check_arm_vendor, - arm_architectures - }, - { - COGL_GPU_INFO_VENDOR_QUALCOMM, - "Qualcomm", - check_qualcomm_vendor, - unknown_architectures - }, - { - COGL_GPU_INFO_VENDOR_NVIDIA, - "Nvidia", - check_nvidia_vendor, - unknown_architectures - }, - { - COGL_GPU_INFO_VENDOR_ATI, - "ATI", - check_ati_vendor, - unknown_architectures - }, - /* Must be last */ - { - COGL_GPU_INFO_VENDOR_MESA, - "Mesa", - check_mesa_vendor, - mesa_architectures - }, - { - COGL_GPU_INFO_VENDOR_UNKNOWN, - "Unknown", - check_true, - unknown_architectures - } - }; - -static gboolean -check_mesa_driver_package (const CoglGpuInfoStrings *strings, - int *version_ret) -{ - uint64_t micro_part; - const char *v; - - /* The version string should always begin a two-part GL version - number */ - if (!_cogl_gpu_info_parse_version_string (strings->version_string, - 2, /* n_components */ - &v, /* tail */ - NULL /* version_ret */)) - return FALSE; - - /* In mesa this will be followed optionally by "(Core Profile)" and - * then "Mesa" */ - v = strstr (v, " Mesa "); - if (!v) - return FALSE; - - v += 6; - - /* Next there will be a version string that is at least two - components. On a git devel build the version will be something - like "-devel" instead */ - if (!_cogl_gpu_info_parse_version_string (v, - 2, /* n_components */ - &v, /* tail */ - version_ret)) - return FALSE; - - /* If it is a development build then we'll just leave the micro - number as 0 */ - if (g_str_has_prefix (v, "-devel")) - return TRUE; - - /* Otherwise there should be a micro version number */ - if (*v != '.') - return FALSE; - - errno = 0; - micro_part = g_ascii_strtoull (v + 1, NULL /* endptr */, 10 /* base */); - if (errno || micro_part > COGL_VERSION_MAX_COMPONENT_VALUE) - return FALSE; - - *version_ret = COGL_VERSION_ENCODE (COGL_VERSION_GET_MAJOR (*version_ret), - COGL_VERSION_GET_MINOR (*version_ret), - micro_part); - - return TRUE; -} - -UNIT_TEST (check_mesa_driver_package_parser, - 0, /* no requirements */ - 0 /* no failure cases */) -{ - /* renderer_string, version_string, vendor_string;*/ - const CoglGpuInfoStrings test_strings[2] = { - { NULL, "3.1 Mesa 9.2-devel15436ad", NULL }, - { NULL, "3.1 (Core Profile) Mesa 9.2.0-devel (git-15436ad)", NULL } - }; - int i; - int version; - - for (i = 0; i < G_N_ELEMENTS (test_strings); i++) - { - g_assert (check_mesa_driver_package (&test_strings[i], &version)); - g_assert_cmpint (version, ==, COGL_VERSION_ENCODE (9, 2, 0)); - } -} - -static gboolean -check_unknown_driver_package (const CoglGpuInfoStrings *strings, - int *version_out) -{ - *version_out = 0; - - /* This is a last resort so it always matches */ - return TRUE; -} - -static const CoglGpuInfoDriverPackageDescription -_cogl_gpu_info_driver_packages[] = - { - { - COGL_GPU_INFO_DRIVER_PACKAGE_MESA, - "Mesa", - check_mesa_driver_package - }, - /* Must be last */ - { - COGL_GPU_INFO_DRIVER_PACKAGE_UNKNOWN, - "Unknown", - check_unknown_driver_package - } - }; - -void -_cogl_gpu_info_init (CoglContext *ctx, - CoglGpuInfo *gpu) -{ - CoglGpuInfoStrings strings; - int i; - - strings.renderer_string = (const char *) ctx->glGetString (GL_RENDERER); - strings.version_string = _cogl_context_get_gl_version (ctx); - strings.vendor_string = (const char *) ctx->glGetString (GL_VENDOR); - - /* Determine the driver package */ - for (i = 0; ; i++) - { - const CoglGpuInfoDriverPackageDescription *description = - _cogl_gpu_info_driver_packages + i; - - if (description->check_function (&strings, &gpu->driver_package_version)) - { - gpu->driver_package = description->driver_package; - gpu->driver_package_name = description->name; - break; - } - } - - /* Determine the GPU vendor */ - for (i = 0; ; i++) - { - const CoglGpuInfoVendorDescription *description = - _cogl_gpu_info_vendors + i; - - if (description->check_function (&strings)) - { - int j; - - gpu->vendor = description->vendor; - gpu->vendor_name = description->name; - - for (j = 0; ; j++) - { - const CoglGpuInfoArchitectureDescription *architecture = - description->architectures + j; - - if (architecture->check_function (&strings)) - { - gpu->architecture = architecture->architecture; - gpu->architecture_name = architecture->name; - gpu->architecture_flags = architecture->flags; - goto probed; - } - } - } - } - -probed: - - COGL_NOTE (WINSYS, "Driver package = %s, vendor = %s, architecture = %s\n", - gpu->driver_package_name, - gpu->vendor_name, - gpu->architecture_name); - - /* Determine the driver bugs */ - gpu->driver_bugs = 0; -} diff --git a/cogl/cogl/cogl-matrix-stack.c b/cogl/cogl/cogl-matrix-stack.c index 2e5150afa7c25b0417cd5c2b7d4492fa186e8a26..138d3ac545fbba6423bf96a9f808a46f3c0a37ac 100644 --- a/cogl/cogl/cogl-matrix-stack.c +++ b/cogl/cogl/cogl-matrix-stack.c @@ -41,7 +41,6 @@ #include "cogl-matrix-private.h" #include "cogl-magazine-private.h" #include "cogl-gtype-private.h" -#include "driver/gl/cogl-util-gl-private.h" static void _cogl_matrix_stack_free (CoglMatrixStack *stack); diff --git a/cogl/cogl/cogl-pipeline-layer.c b/cogl/cogl/cogl-pipeline-layer.c index c6f13696a8e3f9fa6d1946d88274b3942833cc9b..3362c62204b9e416e18293204ab4814fbb0d4e1d 100644 --- a/cogl/cogl/cogl-pipeline-layer.c +++ b/cogl/cogl/cogl-pipeline-layer.c @@ -44,7 +44,6 @@ #include "cogl-node-private.h" #include "cogl-context-private.h" #include "cogl-texture-private.h" -#include "driver/gl/cogl-pipeline-opengl-private.h" #include @@ -342,8 +341,6 @@ _cogl_pipeline_layer_pre_change_notify (CoglPipeline *required_owner, CoglPipelineLayer *layer, CoglPipelineLayerState change) { - CoglTextureUnit *unit; - /* Identify the case where the layer is new with no owner or * dependants and so we don't need to do anything. */ if (_cogl_list_empty (&COGL_NODE (layer)->children) && @@ -403,15 +400,6 @@ _cogl_pipeline_layer_pre_change_notify (CoglPipeline *required_owner, progend->layer_pre_change_notify (required_owner, layer, change); } - /* If the layer being changed is the same as the last layer we - * flushed to the corresponding texture unit then we keep a track of - * the changes so we can try to minimize redundant OpenGL calls if - * the same layer is flushed again. - */ - unit = _cogl_get_texture_unit (_cogl_pipeline_layer_get_unit_index (layer)); - if (unit->layer == layer) - unit->layer_changes_since_flush |= change; - init_layer_state: if (required_owner) diff --git a/cogl/cogl/cogl-pixel-buffer.c b/cogl/cogl/cogl-pixel-buffer.c index 7abebacccef8315ca7d0589148f70fde1dd95b43..d7d38397159a8342a7d4c1e89d407f6b5303ed71 100644 --- a/cogl/cogl/cogl-pixel-buffer.c +++ b/cogl/cogl/cogl-pixel-buffer.c @@ -51,22 +51,6 @@ #include "cogl-pixel-buffer.h" #include "cogl-gtype-private.h" -/* - * GL/GLES compatibility defines for the buffer API: - */ - -#if defined (HAVE_COGL_GL) - -#ifndef GL_PIXEL_UNPACK_BUFFER -#define GL_PIXEL_UNPACK_BUFFER GL_PIXEL_UNPACK_BUFFER_ARB -#endif - -#ifndef GL_PIXEL_PACK_BUFFER -#define GL_PIXEL_PACK_BUFFER GL_PIXEL_PACK_BUFFER_ARB -#endif - -#endif - static void _cogl_pixel_buffer_free (CoglPixelBuffer *buffer); diff --git a/cogl/cogl/cogl-sampler-cache.c b/cogl/cogl/cogl-sampler-cache.c index f2dbaeb6312ad269aaea57d5ceb2cbb67a815c58..2e0e761f0082fcbf4c1b00eb15763860bf5ae962 100644 --- a/cogl/cogl/cogl-sampler-cache.c +++ b/cogl/cogl/cogl-sampler-cache.c @@ -34,11 +34,6 @@ #include "cogl-sampler-cache-private.h" #include "cogl-context-private.h" -#include "driver/gl/cogl-util-gl-private.h" - -#ifndef GL_TEXTURE_WRAP_R -#define GL_TEXTURE_WRAP_R 0x8072 -#endif struct _CoglSamplerCache { @@ -54,10 +49,6 @@ struct _CoglSamplerCache GL state. */ GHashTable *hash_table_cogl; GHashTable *hash_table_gl; - - /* This is used for generated fake unique sampler object numbers - when the sampler object extension is not supported */ - GLuint next_fake_sampler_object_number; }; static CoglSamplerCacheWrapMode @@ -176,22 +167,10 @@ _cogl_sampler_cache_new (CoglContext *context) sampler_state_equal_gl); cache->hash_table_cogl = g_hash_table_new (hash_sampler_state_cogl, sampler_state_equal_cogl); - cache->next_fake_sampler_object_number = 1; return cache; } -static void -set_wrap_mode (CoglContext *context, - GLuint sampler_object, - GLenum param, - CoglSamplerCacheWrapMode wrap_mode) -{ - GE( context, glSamplerParameteri (sampler_object, - param, - wrap_mode) ); -} - static CoglSamplerCacheEntry * _cogl_sampler_cache_get_entry_gl (CoglSamplerCache *cache, const CoglSamplerCacheEntry *key) @@ -202,39 +181,9 @@ _cogl_sampler_cache_get_entry_gl (CoglSamplerCache *cache, if (entry == NULL) { - CoglContext *context = cache->context; - entry = g_slice_dup (CoglSamplerCacheEntry, key); - if (_cogl_has_private_feature (context, - COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS)) - { - GE( context, glGenSamplers (1, &entry->sampler_object) ); - - GE( context, glSamplerParameteri (entry->sampler_object, - GL_TEXTURE_MIN_FILTER, - entry->min_filter) ); - GE( context, glSamplerParameteri (entry->sampler_object, - GL_TEXTURE_MAG_FILTER, - entry->mag_filter) ); - - set_wrap_mode (context, - entry->sampler_object, - GL_TEXTURE_WRAP_S, - entry->wrap_mode_s); - set_wrap_mode (context, - entry->sampler_object, - GL_TEXTURE_WRAP_T, - entry->wrap_mode_t); - } - else - { - /* If sampler objects aren't supported then we'll invent a - unique number so that pipelines can still compare the - unique state just by comparing the sampler object - numbers */ - entry->sampler_object = cache->next_fake_sampler_object_number++; - } + cache->context->driver_vtable->sampler_init (cache->context, entry); g_hash_table_insert (cache->hash_table_gl, entry, entry); } @@ -320,9 +269,7 @@ hash_table_free_gl_cb (void *key, CoglContext *context = user_data; CoglSamplerCacheEntry *entry = value; - if (_cogl_has_private_feature (context, - COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS)) - GE( context, glDeleteSamplers (1, &entry->sampler_object) ); + context->driver_vtable->sampler_free (context, entry); g_slice_free (CoglSamplerCacheEntry, entry); } diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index c82481156ce0f993916098c098a5a59e8aadbde3..2481943c8b7fbc85725daac60d69bd488cf7f987 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -62,11 +62,6 @@ #include #include -/* This isn't defined in the GLES headers */ -#ifndef GL_RED -#define GL_RED 0x1903 -#endif - COGL_GTYPE_DEFINE_INTERFACE (Texture, texture); uint32_t @@ -786,8 +781,6 @@ cogl_texture_get_data (CoglTexture *texture, if (texture_format == COGL_PIXEL_FORMAT_A_8) { closest_format = COGL_PIXEL_FORMAT_A_8; - closest_gl_format = GL_RED; - closest_gl_type = GL_UNSIGNED_BYTE; } else if (format == COGL_PIXEL_FORMAT_A_8) { @@ -798,8 +791,6 @@ cogl_texture_get_data (CoglTexture *texture, * pre-multiplied here because we're only going to look at * the alpha component */ closest_format = COGL_PIXEL_FORMAT_RGBA_8888; - closest_gl_format = GL_RGBA; - closest_gl_type = GL_UNSIGNED_BYTE; } } diff --git a/cogl/cogl/deprecated/cogl-program.c b/cogl/cogl/deprecated/cogl-program.c index adf5543d2b028b9e4a06b7c55e6c4ca365776ea9..65904c6b5db05d486c54ca7a8b48e52b81ba21a1 100644 --- a/cogl/cogl/deprecated/cogl-program.c +++ b/cogl/cogl/deprecated/cogl-program.c @@ -31,7 +31,6 @@ #include "cogl-config.h" #include "cogl-util.h" -#include "driver/gl/cogl-util-gl-private.h" #include "cogl-context-private.h" #include "cogl-object-private.h" diff --git a/cogl/cogl/deprecated/cogl-shader-private.h b/cogl/cogl/deprecated/cogl-shader-private.h index f19aaa22c858989d7833bdf02782980878fa79d1..ae47f18795f6d4381748e58d097c980eefb014fa 100644 --- a/cogl/cogl/deprecated/cogl-shader-private.h +++ b/cogl/cogl/deprecated/cogl-shader-private.h @@ -47,16 +47,4 @@ struct _CoglShader char *source; }; -void -_cogl_shader_compile_real (CoglHandle handle, - CoglPipeline *pipeline); - -void -_cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle, - GLenum shader_gl_type, - int n_tex_coord_attribs, - GLsizei count_in, - const char **strings_in, - const GLint *lengths_in); - #endif /* __COGL_SHADER_H */ diff --git a/cogl/cogl/deprecated/cogl-shader.c b/cogl/cogl/deprecated/cogl-shader.c index 7015454775ce9296881f6e88d0ad8cab01c3a10e..ec899ce34ff528ce0af807854b72190c423e2909 100644 --- a/cogl/cogl/deprecated/cogl-shader.c +++ b/cogl/cogl/deprecated/cogl-shader.c @@ -32,7 +32,6 @@ #include "cogl-context-private.h" #include "cogl-object-private.h" -#include "cogl-glsl-shader-private.h" #include "cogl-glsl-shader-boilerplate.h" #include "driver/gl/cogl-util-gl-private.h" #include "deprecated/cogl-shader-private.h" @@ -45,13 +44,6 @@ static void _cogl_shader_free (CoglShader *shader); COGL_HANDLE_DEFINE (Shader, shader); -#ifndef GL_FRAGMENT_SHADER -#define GL_FRAGMENT_SHADER 0x8B30 -#endif -#ifndef GL_VERTEX_SHADER -#define GL_VERTEX_SHADER 0x8B31 -#endif - static void _cogl_shader_free (CoglShader *shader) { @@ -91,23 +83,6 @@ cogl_create_shader (CoglShaderType type) return _cogl_shader_handle_new (shader); } -static void -delete_shader (CoglShader *shader) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - if (shader->gl_handle) - GE (ctx, glDeleteShader (shader->gl_handle)); - - shader->gl_handle = 0; - - if (shader->compilation_pipeline) - { - cogl_object_unref (shader->compilation_pipeline); - shader->compilation_pipeline = NULL; - } -} - void cogl_shader_source (CoglHandle handle, const char *source) @@ -124,77 +99,6 @@ cogl_shader_source (CoglHandle handle, shader->source = g_strdup (source); } -void -_cogl_shader_compile_real (CoglHandle handle, - CoglPipeline *pipeline) -{ - CoglShader *shader = handle; - GLenum gl_type; - GLint status; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - if (shader->gl_handle) - { - CoglPipeline *prev = shader->compilation_pipeline; - - /* XXX: currently the only things that will affect the - * boilerplate for user shaders, apart from driver features, - * are the pipeline layer-indices and texture-unit-indices - */ - if (pipeline == prev || - _cogl_pipeline_layer_and_unit_numbers_equal (prev, pipeline)) - return; - } - - if (shader->gl_handle) - delete_shader (shader); - - switch (shader->type) - { - case COGL_SHADER_TYPE_VERTEX: - gl_type = GL_VERTEX_SHADER; - break; - case COGL_SHADER_TYPE_FRAGMENT: - gl_type = GL_FRAGMENT_SHADER; - break; - default: - g_assert_not_reached (); - break; - } - - shader->gl_handle = ctx->glCreateShader (gl_type); - - _cogl_glsl_shader_set_source_with_boilerplate (ctx, - shader->gl_handle, - gl_type, - pipeline, - 1, - (const char **) - &shader->source, - NULL); - - GE (ctx, glCompileShader (shader->gl_handle)); - - shader->compilation_pipeline = cogl_object_ref (pipeline); - - GE (ctx, glGetShaderiv (shader->gl_handle, GL_COMPILE_STATUS, &status)); - if (!status) - { - char buffer[512]; - int len = 0; - - ctx->glGetShaderInfoLog (shader->gl_handle, 511, &len, buffer); - buffer[len] = '\0'; - - g_warning ("Failed to compile GLSL program:\n" - "src:\n%s\n" - "error:\n%s\n", - shader->source, - buffer); - } -} - CoglShaderType cogl_shader_get_type (CoglHandle handle) { diff --git a/cogl/cogl/driver/gl/cogl-pipeline-fragend-glsl.c b/cogl/cogl/driver/gl/cogl-pipeline-fragend-glsl.c index 0e95fb3909fc92f95c557714f8ed87c00d6f264a..4d754d9b33f271025796d673791f406d9f5c0e1c 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-fragend-glsl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-fragend-glsl.c @@ -43,11 +43,11 @@ #include "cogl-snippet-private.h" #include "cogl-list.h" #include "driver/gl/cogl-util-gl-private.h" +#include "driver/gl/cogl-pipeline-opengl-private.h" #include "cogl-context-private.h" #include "cogl-object-private.h" #include "cogl-pipeline-cache.h" -#include "cogl-glsl-shader-private.h" #include "driver/gl/cogl-pipeline-fragend-glsl-private.h" #include "deprecated/cogl-shader-private.h" #include "deprecated/cogl-program-private.h" diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h b/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h index afcb4460ee5cc1c309e14bd31a9303cb50f02b6d..62846237c7a83508190b33bcf8a696c3b6fe87d4 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h +++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h @@ -146,5 +146,27 @@ _cogl_pipeline_flush_gl_state (CoglContext *context, gboolean skip_gl_state, gboolean unknown_color_alpha); +void +_cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx, + GLuint shader_gl_handle, + GLenum shader_gl_type, + CoglPipeline *pipeline, + GLsizei count_in, + const char **strings_in, + const GLint *lengths_in); + +void +_cogl_sampler_gl_init (CoglContext *context, + CoglSamplerCacheEntry *entry); + +void +_cogl_sampler_gl_free (CoglContext *context, + CoglSamplerCacheEntry *entry); + +void +_cogl_gl_set_uniform (CoglContext *ctx, + GLint location, + const CoglBoxedValue *value); + #endif /* __COGL_PIPELINE_OPENGL_PRIVATE_H */ diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c index 44a968a2cf6972459394d2a3045a2a265f43a1f7..da13e293b11d9673a157963b6fd54424591b7650 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c @@ -94,47 +94,51 @@ CoglTextureUnit * _cogl_get_texture_unit (int index_) { _COGL_GET_CONTEXT (ctx, NULL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - if (ctx->texture_units->len < (index_ + 1)) + if (glctx->texture_units->len < (index_ + 1)) { int i; - int prev_len = ctx->texture_units->len; - ctx->texture_units = g_array_set_size (ctx->texture_units, index_ + 1); + int prev_len = glctx->texture_units->len; + glctx->texture_units = g_array_set_size (glctx->texture_units, + index_ + 1); for (i = prev_len; i <= index_; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); texture_unit_init (ctx, unit, i); } } - return &g_array_index (ctx->texture_units, CoglTextureUnit, index_); + return &g_array_index (glctx->texture_units, CoglTextureUnit, index_); } void _cogl_destroy_texture_units (CoglContext *ctx) { int i; + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - for (i = 0; i < ctx->texture_units->len; i++) + for (i = 0; i < glctx->texture_units->len; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); texture_unit_free (unit); } - g_array_free (ctx->texture_units, TRUE); + g_array_free (glctx->texture_units, TRUE); } void _cogl_set_active_texture_unit (int unit_index) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - if (ctx->active_texture_unit != unit_index) + if (glctx->active_texture_unit != unit_index) { GE (ctx, glActiveTexture (GL_TEXTURE0 + unit_index)); - ctx->active_texture_unit = unit_index; + glctx->active_texture_unit = unit_index; } } @@ -190,11 +194,12 @@ _cogl_delete_gl_texture (GLuint gl_texture) int i; _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - for (i = 0; i < ctx->texture_units->len; i++) + for (i = 0; i < glctx->texture_units->len; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); if (unit->gl_texture == gl_texture) { @@ -218,11 +223,12 @@ _cogl_pipeline_texture_storage_change_notify (CoglTexture *texture) int i; _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - for (i = 0; i < ctx->texture_units->len; i++) + for (i = 0; i < glctx->texture_units->len; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); if (unit->layer && _cogl_pipeline_layer_get_texture (unit->layer) == texture) @@ -688,6 +694,48 @@ _cogl_pipeline_layer_forward_wrap_modes (CoglPipelineLayer *layer, gl_wrap_mode_t); } +void +_cogl_sampler_gl_init (CoglContext *context, CoglSamplerCacheEntry *entry) +{ + if (_cogl_has_private_feature (context, + COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS)) + { + GE( context, glGenSamplers (1, &entry->sampler_object) ); + + GE( context, glSamplerParameteri (entry->sampler_object, + GL_TEXTURE_MIN_FILTER, + entry->min_filter) ); + GE( context, glSamplerParameteri (entry->sampler_object, + GL_TEXTURE_MAG_FILTER, + entry->mag_filter) ); + + GE (context, glSamplerParameteri (entry->sampler_object, + GL_TEXTURE_WRAP_S, + entry->wrap_mode_s) ); + GE (context, glSamplerParameteri (entry->sampler_object, + GL_TEXTURE_WRAP_T, + entry->wrap_mode_t) ); + } + else + { + CoglGLContext *gl_context = context->driver_context; + + /* If sampler objects aren't supported then we'll invent a + unique number so that pipelines can still compare the + unique state just by comparing the sampler object + numbers */ + entry->sampler_object = gl_context->next_fake_sampler_object_number++; + } +} + +void +_cogl_sampler_gl_free (CoglContext *context, CoglSamplerCacheEntry *entry) +{ + if (_cogl_has_private_feature (context, + COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS)) + GE( context, glDeleteSamplers (1, &entry->sampler_object) ); +} + /* OpenGL associates the min/mag filters and repeat modes with the * texture object not the texture unit so we always have to re-assert * the filter and repeat modes whenever we use a texture since it may @@ -704,11 +752,12 @@ foreach_texture_unit_update_filter_and_wrap_modes (void) int i; _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - for (i = 0; i < ctx->texture_units->len; i++) + for (i = 0; i < glctx->texture_units->len; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); if (unit->layer) { @@ -1141,3 +1190,95 @@ done: COGL_TIMER_STOP (_cogl_uprof_context, pipeline_flush_timer); } +void +_cogl_gl_set_uniform (CoglContext *ctx, + GLint location, + const CoglBoxedValue *value) +{ + switch (value->type) + { + case COGL_BOXED_NONE: + break; + + case COGL_BOXED_INT: + { + const int *ptr; + + if (value->count == 1) + ptr = value->v.int_value; + else + ptr = value->v.int_array; + + switch (value->size) + { + case 1: + GE( ctx, glUniform1iv (location, value->count, ptr) ); + break; + case 2: + GE( ctx, glUniform2iv (location, value->count, ptr) ); + break; + case 3: + GE( ctx, glUniform3iv (location, value->count, ptr) ); + break; + case 4: + GE( ctx, glUniform4iv (location, value->count, ptr) ); + break; + } + } + break; + + case COGL_BOXED_FLOAT: + { + const float *ptr; + + if (value->count == 1) + ptr = value->v.float_value; + else + ptr = value->v.float_array; + + switch (value->size) + { + case 1: + GE( ctx, glUniform1fv (location, value->count, ptr) ); + break; + case 2: + GE( ctx, glUniform2fv (location, value->count, ptr) ); + break; + case 3: + GE( ctx, glUniform3fv (location, value->count, ptr) ); + break; + case 4: + GE( ctx, glUniform4fv (location, value->count, ptr) ); + break; + } + } + break; + + case COGL_BOXED_MATRIX: + { + const float *ptr; + + if (value->count == 1) + ptr = value->v.matrix; + else + ptr = value->v.float_array; + + switch (value->size) + { + case 2: + GE( ctx, glUniformMatrix2fv (location, value->count, + FALSE, ptr) ); + break; + case 3: + GE( ctx, glUniformMatrix3fv (location, value->count, + FALSE, ptr) ); + break; + case 4: + GE( ctx, glUniformMatrix4fv (location, value->count, + FALSE, ptr) ); + break; + } + } + break; + } +} diff --git a/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c b/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c index 3a049a70b0bbe9f5497cbb4181cfb1dda2d46392..083308cedcdebdc5f8d90e38ef04df3ba8e7a907 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c @@ -633,6 +633,82 @@ _cogl_pipeline_progend_glsl_start (CoglPipeline *pipeline) return TRUE; } +static void +_cogl_shader_compile_real (CoglHandle handle, + CoglPipeline *pipeline) +{ + CoglShader *shader = handle; + GLenum gl_type; + GLint status; + + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (shader->gl_handle) + { + CoglPipeline *prev = shader->compilation_pipeline; + + /* XXX: currently the only things that will affect the + * boilerplate for user shaders, apart from driver features, + * are the pipeline layer-indices and texture-unit-indices + */ + if (pipeline == prev || + _cogl_pipeline_layer_and_unit_numbers_equal (prev, pipeline)) + return; + + GE (ctx, glDeleteShader (shader->gl_handle)); + shader->gl_handle = 0; + + if (shader->compilation_pipeline) + { + cogl_object_unref (shader->compilation_pipeline); + shader->compilation_pipeline = NULL; + } + } + + switch (shader->type) + { + case COGL_SHADER_TYPE_VERTEX: + gl_type = GL_VERTEX_SHADER; + break; + case COGL_SHADER_TYPE_FRAGMENT: + gl_type = GL_FRAGMENT_SHADER; + break; + default: + g_assert_not_reached (); + break; + } + + shader->gl_handle = ctx->glCreateShader (gl_type); + + _cogl_glsl_shader_set_source_with_boilerplate (ctx, + shader->gl_handle, + gl_type, + pipeline, + 1, + (const char **) + &shader->source, + NULL); + GE (ctx, glCompileShader (shader->gl_handle)); + + shader->compilation_pipeline = cogl_object_ref (pipeline); + + GE (ctx, glGetShaderiv (shader->gl_handle, GL_COMPILE_STATUS, &status)); + if (!status) + { + char buffer[512]; + int len = 0; + + ctx->glGetShaderInfoLog (shader->gl_handle, 511, &len, buffer); + buffer[len] = '\0'; + + g_warning ("Failed to compile GLSL program:\n" + "src:\n%s\n" + "error:\n%s\n", + shader->source, + buffer); + } +} + static void _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline, unsigned long pipelines_difference) @@ -877,6 +953,7 @@ _cogl_pipeline_progend_glsl_layer_pre_change_notify ( CoglPipelineLayerState change) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglTextureUnit *unit; if ((change & (_cogl_pipeline_get_layer_state_for_fragment_codegen (ctx) | COGL_PIPELINE_LAYER_STATE_AFFECTS_VERTEX_CODEGEN))) @@ -901,6 +978,15 @@ _cogl_pipeline_progend_glsl_layer_pre_change_notify ( program_state->unit_state[unit_index].dirty_texture_matrix = TRUE; } } + + /* If the layer being changed is the same as the last layer we + * flushed to the corresponding texture unit then we keep a track of + * the changes so we can try to minimize redundant OpenGL calls if + * the same layer is flushed again. + */ + unit = _cogl_get_texture_unit (_cogl_pipeline_layer_get_unit_index (layer)); + if (unit->layer == layer) + unit->layer_changes_since_flush |= change; } static void diff --git a/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c b/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c index c69f50ae890029a7476bfd897f52edb21f4231d8..7ef7a49937c7cf00d59dff262abfe2692fdd6031 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c @@ -45,7 +45,7 @@ #include "cogl-context-private.h" #include "cogl-object-private.h" #include "cogl-pipeline-state-private.h" -#include "cogl-glsl-shader-private.h" +#include "cogl-glsl-shader-boilerplate.h" #include "driver/gl/cogl-pipeline-vertend-glsl-private.h" #include "deprecated/cogl-program-private.h" @@ -132,6 +132,150 @@ dirty_shader_state (CoglPipeline *pipeline) NULL); } +static gboolean +add_layer_vertex_boilerplate_cb (CoglPipelineLayer *layer, + void *user_data) +{ + GString *layer_declarations = user_data; + int unit_index = _cogl_pipeline_layer_get_unit_index (layer); + g_string_append_printf (layer_declarations, + "attribute vec4 cogl_tex_coord%d_in;\n" + "#define cogl_texture_matrix%i cogl_texture_matrix[%i]\n" + "#define cogl_tex_coord%i_out _cogl_tex_coord[%i]\n", + layer->index, + layer->index, + unit_index, + layer->index, + unit_index); + return TRUE; +} + +static gboolean +add_layer_fragment_boilerplate_cb (CoglPipelineLayer *layer, + void *user_data) +{ + GString *layer_declarations = user_data; + g_string_append_printf (layer_declarations, + "#define cogl_tex_coord%i_in _cogl_tex_coord[%i]\n", + layer->index, + _cogl_pipeline_layer_get_unit_index (layer)); + return TRUE; +} + +void +_cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx, + GLuint shader_gl_handle, + GLenum shader_gl_type, + CoglPipeline *pipeline, + GLsizei count_in, + const char **strings_in, + const GLint *lengths_in) +{ + const char *vertex_boilerplate; + const char *fragment_boilerplate; + + const char **strings = g_alloca (sizeof (char *) * (count_in + 4)); + GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 4)); + char *version_string; + int count = 0; + + int n_layers; + + vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE; + fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE; + + version_string = g_strdup_printf ("#version %i\n\n", + ctx->glsl_version_to_use); + strings[count] = version_string; + lengths[count++] = -1; + + if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_EGL_IMAGE_EXTERNAL)) + { + static const char image_external_extension[] = + "#extension GL_OES_EGL_image_external : require\n"; + strings[count] = image_external_extension; + lengths[count++] = sizeof (image_external_extension) - 1; + } + + if (shader_gl_type == GL_VERTEX_SHADER) + { + strings[count] = vertex_boilerplate; + lengths[count++] = strlen (vertex_boilerplate); + } + else if (shader_gl_type == GL_FRAGMENT_SHADER) + { + strings[count] = fragment_boilerplate; + lengths[count++] = strlen (fragment_boilerplate); + } + + n_layers = cogl_pipeline_get_n_layers (pipeline); + if (n_layers) + { + GString *layer_declarations = ctx->codegen_boilerplate_buffer; + g_string_set_size (layer_declarations, 0); + + g_string_append_printf (layer_declarations, + "varying vec4 _cogl_tex_coord[%d];\n", + n_layers); + + if (shader_gl_type == GL_VERTEX_SHADER) + { + g_string_append_printf (layer_declarations, + "uniform mat4 cogl_texture_matrix[%d];\n", + n_layers); + + _cogl_pipeline_foreach_layer_internal (pipeline, + add_layer_vertex_boilerplate_cb, + layer_declarations); + } + else if (shader_gl_type == GL_FRAGMENT_SHADER) + { + _cogl_pipeline_foreach_layer_internal (pipeline, + add_layer_fragment_boilerplate_cb, + layer_declarations); + } + + strings[count] = layer_declarations->str; + lengths[count++] = -1; /* null terminated */ + } + + memcpy (strings + count, strings_in, sizeof (char *) * count_in); + if (lengths_in) + memcpy (lengths + count, lengths_in, sizeof (GLint) * count_in); + else + { + int i; + + for (i = 0; i < count_in; i++) + lengths[count + i] = -1; /* null terminated */ + } + count += count_in; + + if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE))) + { + GString *buf = g_string_new (NULL); + int i; + + g_string_append_printf (buf, + "%s shader:\n", + shader_gl_type == GL_VERTEX_SHADER ? + "vertex" : "fragment"); + for (i = 0; i < count; i++) + if (lengths[i] != -1) + g_string_append_len (buf, strings[i], lengths[i]); + else + g_string_append (buf, strings[i]); + + g_message ("%s", buf->str); + + g_string_free (buf, TRUE); + } + + GE( ctx, glShaderSource (shader_gl_handle, count, + (const char **) strings, lengths) ); + + g_free (version_string); +} GLuint _cogl_pipeline_vertend_glsl_get_shader (CoglPipeline *pipeline) { diff --git a/cogl/cogl/driver/gl/cogl-util-gl-private.h b/cogl/cogl/driver/gl/cogl-util-gl-private.h index 52279be678ec7a0ecd3b3d9c8ca22e803099372a..c3f550863707ed6dac02f5ff647a74749e3a7ffc 100644 --- a/cogl/cogl/driver/gl/cogl-util-gl-private.h +++ b/cogl/cogl/driver/gl/cogl-util-gl-private.h @@ -76,6 +76,18 @@ _cogl_gl_error_to_string (GLenum error_code); #endif /* COGL_GL_DEBUG */ +typedef struct _CoglGLContext { + GArray *texture_units; + int active_texture_unit; + + /* This is used for generated fake unique sampler object numbers + when the sampler object extension is not supported */ + GLuint next_fake_sampler_object_number; +} CoglGLContext; + +CoglGLContext * +_cogl_driver_gl_context (CoglContext *context); + gboolean _cogl_driver_gl_context_init (CoglContext *context); @@ -91,6 +103,23 @@ _cogl_gl_util_clear_gl_errors (CoglContext *ctx); gboolean _cogl_gl_util_catch_out_of_memory (CoglContext *ctx, GError **error); +gboolean +_cogl_driver_gl_is_hardware_accelerated (CoglContext *context); + +/* + * _cogl_context_get_gl_extensions: + * @context: A CoglContext + * + * Return value: a NULL-terminated array of strings representing the + * supported extensions by the current driver. This array is owned + * by the caller and should be freed with g_strfreev(). + */ +char ** +_cogl_context_get_gl_extensions (CoglContext *context); + +const char * +_cogl_context_get_gl_version (CoglContext *context); + /* Parses a GL version number stored in a string. @version_string must * point to the beginning of the version number (ie, it can't point to * the "OpenGL ES" part on GLES). The version number can be followed @@ -102,4 +131,7 @@ _cogl_gl_util_parse_gl_version (const char *version_string, int *major_out, int *minor_out); +CoglGraphicsResetStatus +_cogl_gl_get_graphics_reset_status (CoglContext *context); + #endif /* _COGL_UTIL_GL_PRIVATE_H_ */ diff --git a/cogl/cogl/driver/gl/cogl-util-gl.c b/cogl/cogl/driver/gl/cogl-util-gl.c index 34488c7d8fd37cb1594cd9bd392543b50aaaeaf0..e41c17c93d21ed4acd35c29ab5a2b8c2f1076745 100644 --- a/cogl/cogl/driver/gl/cogl-util-gl.c +++ b/cogl/cogl/driver/gl/cogl-util-gl.c @@ -37,6 +37,24 @@ #include "driver/gl/cogl-pipeline-opengl-private.h" #include "driver/gl/cogl-util-gl-private.h" +/* This is a relatively new extension */ +#ifndef GL_PURGED_CONTEXT_RESET_NV +#define GL_PURGED_CONTEXT_RESET_NV 0x92BB +#endif + +/* These aren't defined in the GLES2 headers */ +#ifndef GL_GUILTY_CONTEXT_RESET_ARB +#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 +#endif + +#ifndef GL_INNOCENT_CONTEXT_RESET_ARB +#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 +#endif + +#ifndef GL_UNKNOWN_CONTEXT_RESET_ARB +#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 +#endif + #ifdef COGL_GL_DEBUG /* GL error to string conversion */ static const struct { @@ -75,15 +93,31 @@ _cogl_gl_error_to_string (GLenum error_code) } #endif /* COGL_GL_DEBUG */ +CoglGLContext * +_cogl_driver_gl_context (CoglContext *context) +{ + return context->driver_context; +} + gboolean _cogl_driver_gl_context_init (CoglContext *context) { - context->texture_units = + CoglGLContext *gl_context; + + if (!context->driver_context) + context->driver_context = g_new0 (CoglContext, 1); + + gl_context = _cogl_driver_gl_context (context); + if (!gl_context) + return FALSE; + + gl_context->next_fake_sampler_object_number = 1; + gl_context->texture_units = g_array_new (FALSE, FALSE, sizeof (CoglTextureUnit)); /* See cogl-pipeline.c for more details about why we leave texture unit 1 * active by default... */ - context->active_texture_unit = 1; + gl_context->active_texture_unit = 1; GE (context, glActiveTexture (GL_TEXTURE1)); return TRUE; @@ -93,6 +127,7 @@ void _cogl_driver_gl_context_deinit (CoglContext *context) { _cogl_destroy_texture_units (context); + g_free (context->driver_context); } GLenum @@ -147,6 +182,94 @@ _cogl_gl_util_catch_out_of_memory (CoglContext *ctx, GError **error) return FALSE; } +char ** +_cogl_context_get_gl_extensions (CoglContext *context) +{ + const char *env_disabled_extensions; + char **ret; + + /* In GL 3, querying GL_EXTENSIONS is deprecated so we have to build + * the array using glGetStringi instead */ +#ifdef HAVE_COGL_GL + if (context->driver == COGL_DRIVER_GL3) + { + int num_extensions, i; + + context->glGetIntegerv (GL_NUM_EXTENSIONS, &num_extensions); + + ret = g_malloc (sizeof (char *) * (num_extensions + 1)); + + for (i = 0; i < num_extensions; i++) + { + const char *ext = + (const char *) context->glGetStringi (GL_EXTENSIONS, i); + ret[i] = g_strdup (ext); + } + + ret[num_extensions] = NULL; + } + else +#endif + { + const char *all_extensions = + (const char *) context->glGetString (GL_EXTENSIONS); + + ret = g_strsplit (all_extensions, " ", 0 /* max tokens */); + } + + if ((env_disabled_extensions = g_getenv ("COGL_DISABLE_GL_EXTENSIONS"))) + { + char **split_env_disabled_extensions; + char **src, **dst; + + if (env_disabled_extensions) + split_env_disabled_extensions = + g_strsplit (env_disabled_extensions, + ",", + 0 /* no max tokens */); + else + split_env_disabled_extensions = NULL; + + for (dst = ret, src = ret; + *src; + src++) + { + char **d; + + if (split_env_disabled_extensions) + for (d = split_env_disabled_extensions; *d; d++) + if (!strcmp (*src, *d)) + goto disabled; + + *(dst++) = *src; + continue; + + disabled: + g_free (*src); + continue; + } + + *dst = NULL; + + if (split_env_disabled_extensions) + g_strfreev (split_env_disabled_extensions); + } + + return ret; +} + +const char * +_cogl_context_get_gl_version (CoglContext *context) +{ + const char *version_override; + + if ((version_override = g_getenv ("COGL_OVERRIDE_GL_VERSION"))) + return version_override; + else + return (const char *) context->glGetString (GL_VERSION); + +} + gboolean _cogl_gl_util_parse_gl_version (const char *version_string, int *major_out, @@ -179,3 +302,53 @@ _cogl_gl_util_parse_gl_version (const char *version_string, return TRUE; } + +/* + * This should arguably use something like GLX_MESA_query_renderer, but + * a) that's GLX-only, and you could add it to EGL too but + * b) that'd make this a winsys query when really it's not a property of + * the winsys but the renderer, and + * c) only Mesa really supports it anyway, and + * d) Mesa is the only software renderer of interest. + * + * So instead just check a list of known software renderer strings. + */ +gboolean +_cogl_driver_gl_is_hardware_accelerated (CoglContext *ctx) +{ + const char *renderer = (const char *) ctx->glGetString (GL_RENDERER); + gboolean software; + + software = strstr (renderer, "llvmpipe") != NULL || + strstr (renderer, "softpipe") != NULL || + strstr (renderer, "software rasterizer") != NULL || + strstr (renderer, "Software Rasterizer") != NULL || + strstr (renderer, "SWR"); + + return !software; +} + +CoglGraphicsResetStatus +_cogl_gl_get_graphics_reset_status (CoglContext *context) +{ + if (!context->glGetGraphicsResetStatus) + return COGL_GRAPHICS_RESET_STATUS_NO_ERROR; + + switch (context->glGetGraphicsResetStatus ()) + { + case GL_GUILTY_CONTEXT_RESET_ARB: + return COGL_GRAPHICS_RESET_STATUS_GUILTY_CONTEXT_RESET; + + case GL_INNOCENT_CONTEXT_RESET_ARB: + return COGL_GRAPHICS_RESET_STATUS_INNOCENT_CONTEXT_RESET; + + case GL_UNKNOWN_CONTEXT_RESET_ARB: + return COGL_GRAPHICS_RESET_STATUS_UNKNOWN_CONTEXT_RESET; + + case GL_PURGED_CONTEXT_RESET_NV: + return COGL_GRAPHICS_RESET_STATUS_PURGED_CONTEXT_RESET; + + default: + return COGL_GRAPHICS_RESET_STATUS_NO_ERROR; + } +} diff --git a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c index 220c581e991434d0f424fef158ccf790f9aa9e3d..3c2231ebc36941e2bba40e371bafd4ade0a7e13d 100644 --- a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c @@ -42,6 +42,7 @@ #include "driver/gl/cogl-attribute-gl-private.h" #include "driver/gl/cogl-clip-stack-gl-private.h" #include "driver/gl/cogl-buffer-gl-private.h" +#include "driver/gl/cogl-pipeline-opengl-private.h" static gboolean _cogl_driver_gl_real_context_init (CoglContext *context) @@ -419,8 +420,6 @@ _cogl_driver_update_features (CoglContext *ctx, _cogl_get_gl_version (ctx, &gl_major, &gl_minor); - _cogl_gpu_info_init (ctx, &ctx->gpu); - ctx->glsl_major = 1; ctx->glsl_minor = 2; ctx->glsl_version_to_use = 120; @@ -532,6 +531,8 @@ _cogl_driver_gl = { _cogl_driver_gl_real_context_init, _cogl_driver_gl_context_deinit, + _cogl_driver_gl_is_hardware_accelerated, + _cogl_gl_get_graphics_reset_status, _cogl_driver_pixel_format_from_gl_internal, _cogl_driver_pixel_format_to_gl, _cogl_driver_update_features, @@ -563,4 +564,7 @@ _cogl_driver_gl = _cogl_buffer_gl_map_range, _cogl_buffer_gl_unmap, _cogl_buffer_gl_set_data, + _cogl_sampler_gl_init, + _cogl_sampler_gl_free, + _cogl_gl_set_uniform, /* XXX name is weird... */ }; diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c index daaaec44f0661db3d7213d2813dac117b3f54efe..3cb11af6996c474ca91ee32e674fa50de8e5f25d 100644 --- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c @@ -42,6 +42,7 @@ #include "driver/gl/cogl-attribute-gl-private.h" #include "driver/gl/cogl-clip-stack-gl-private.h" #include "driver/gl/cogl-buffer-gl-private.h" +#include "driver/gl/cogl-pipeline-opengl-private.h" #ifndef GL_UNSIGNED_INT_24_8 #define GL_UNSIGNED_INT_24_8 0x84FA @@ -282,8 +283,6 @@ _cogl_driver_update_features (CoglContext *context, context->glsl_minor = 0; context->glsl_version_to_use = 100; - _cogl_gpu_info_init (context, &context->gpu); - if (!_cogl_get_gl_version (context, &gl_major, &gl_minor)) { gl_major = 1; @@ -396,6 +395,8 @@ _cogl_driver_gles = { _cogl_driver_gl_context_init, _cogl_driver_gl_context_deinit, + _cogl_driver_gl_is_hardware_accelerated, + _cogl_gl_get_graphics_reset_status, _cogl_driver_pixel_format_from_gl_internal, _cogl_driver_pixel_format_to_gl, _cogl_driver_update_features, @@ -427,4 +428,7 @@ _cogl_driver_gles = _cogl_buffer_gl_map_range, _cogl_buffer_gl_unmap, _cogl_buffer_gl_set_data, + _cogl_sampler_gl_init, + _cogl_sampler_gl_free, + _cogl_gl_set_uniform, }; diff --git a/cogl/cogl/driver/nop/cogl-driver-nop.c b/cogl/cogl/driver/nop/cogl-driver-nop.c index 3594a966b21ad17b7006944e8770b0dba7e74d3b..f7e6d948f60434c28b1d29b43269b50f02fbdd72 100644 --- a/cogl/cogl/driver/nop/cogl-driver-nop.c +++ b/cogl/cogl/driver/nop/cogl-driver-nop.c @@ -45,8 +45,6 @@ static gboolean _cogl_driver_update_features (CoglContext *ctx, GError **error) { - /* _cogl_gpu_info_init (ctx, &ctx->gpu); */ - memset (ctx->private_features, 0, sizeof (ctx->private_features)); return TRUE; @@ -63,11 +61,19 @@ _cogl_driver_nop_context_deinit (CoglContext *context) { } +static gboolean +_cogl_driver_nop_is_hardware_accelerated (CoglContext *context) +{ + return FALSE; +} + const CoglDriverVtable _cogl_driver_nop = { _cogl_driver_nop_context_init, _cogl_driver_nop_context_deinit, + _cogl_driver_nop_is_hardware_accelerated, + NULL, /* get_graphics_reset_status */ NULL, /* pixel_format_from_gl_internal */ NULL, /* pixel_format_to_gl */ _cogl_driver_update_features, diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build index 21f6d8c0cf9da5e1c38e2dae2f9086bfab9950f1..edcac793e3629fc2edcdcade02210ccb50a3d9cf 100644 --- a/cogl/cogl/meson.build +++ b/cogl/cogl/meson.build @@ -208,8 +208,6 @@ cogl_sources = [ 'cogl-debug.h', 'cogl-debug-options.h', 'cogl-dma-buf-handle.c', - 'cogl-gpu-info.c', - 'cogl-gpu-info-private.h', 'cogl-context-private.h', 'cogl-context.c', 'cogl-renderer-private.h', @@ -276,8 +274,6 @@ cogl_sources = [ 'cogl-pipeline-layer-state.c', 'cogl-pipeline-state-private.h', 'cogl-pipeline-debug.c', - 'cogl-glsl-shader.c', - 'cogl-glsl-shader-private.h', 'cogl-glsl-shader-boilerplate.h', 'cogl-pipeline-snippet-private.h', 'cogl-pipeline-snippet.c', diff --git a/src/backends/meta-renderer.c b/src/backends/meta-renderer.c index 983a570e1c8bd126d2fa66b126f8b9f9677fae64..b5cc37efbfcfdc29161b8ec818dca418869a33d7 100644 --- a/src/backends/meta-renderer.c +++ b/src/backends/meta-renderer.c @@ -194,23 +194,8 @@ meta_renderer_is_hardware_accelerated (MetaRenderer *renderer) ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); - CoglGpuInfo *info = &cogl_context->gpu; - switch (info->architecture) - { - case COGL_GPU_INFO_ARCHITECTURE_UNKNOWN: - case COGL_GPU_INFO_ARCHITECTURE_SANDYBRIDGE: - case COGL_GPU_INFO_ARCHITECTURE_SGX: - case COGL_GPU_INFO_ARCHITECTURE_MALI: - return TRUE; - case COGL_GPU_INFO_ARCHITECTURE_LLVMPIPE: - case COGL_GPU_INFO_ARCHITECTURE_SOFTPIPE: - case COGL_GPU_INFO_ARCHITECTURE_SWRAST: - return FALSE; - } - - g_assert_not_reached (); - return FALSE; + return cogl_context_is_hardware_accelerated (cogl_context); } static void