summaryrefslogtreecommitdiff
path: root/cogl/driver/gl
diff options
context:
space:
mode:
Diffstat (limited to 'cogl/driver/gl')
-rw-r--r--cogl/driver/gl/cogl-attribute-gl.c4
-rw-r--r--cogl/driver/gl/cogl-buffer-gl.c43
-rw-r--r--cogl/driver/gl/cogl-pipeline-fragend-fixed.c16
-rw-r--r--cogl/driver/gl/cogl-pipeline-fragend-glsl.c13
-rw-r--r--cogl/driver/gl/cogl-pipeline-opengl.c129
-rw-r--r--cogl/driver/gl/cogl-texture-2d-gl.c2
-rw-r--r--cogl/driver/gl/gles/cogl-driver-gles.c487
-rw-r--r--cogl/driver/gl/gles/cogl-texture-driver-gles.c652
8 files changed, 50 insertions, 1296 deletions
diff --git a/cogl/driver/gl/cogl-attribute-gl.c b/cogl/driver/gl/cogl-attribute-gl.c
index 34ddb559..410c5788 100644
--- a/cogl/driver/gl/cogl-attribute-gl.c
+++ b/cogl/driver/gl/cogl-attribute-gl.c
@@ -66,7 +66,7 @@ toggle_builtin_attribute_enabled_cb (int bit_num, void *user_data)
(context, COGL_PRIVATE_FEATURE_GL_FIXED),
FALSE);
-#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
+#if defined (HAVE_COGL_GL)
{
CoglBool enabled = _cogl_bitmask_get (state->new_bits, bit_num);
GLenum cap;
@@ -105,7 +105,7 @@ toggle_texcood_attribute_enabled_cb (int bit_num, void *user_data)
(context, COGL_PRIVATE_FEATURE_GL_FIXED),
FALSE);
-#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
+#if defined (HAVE_COGL_GL)
{
CoglBool enabled = _cogl_bitmask_get (state->new_bits, bit_num);
diff --git a/cogl/driver/gl/cogl-buffer-gl.c b/cogl/driver/gl/cogl-buffer-gl.c
index 0f984064..ce9eb6d8 100644
--- a/cogl/driver/gl/cogl-buffer-gl.c
+++ b/cogl/driver/gl/cogl-buffer-gl.c
@@ -41,44 +41,6 @@
#include "cogl-error-private.h"
#include "cogl-util-gl-private.h"
-/*
- * GL/GLES compatibility defines for the buffer API:
- */
-
-#ifndef GL_PIXEL_PACK_BUFFER
-#define GL_PIXEL_PACK_BUFFER 0x88EB
-#endif
-#ifndef GL_PIXEL_UNPACK_BUFFER
-#define GL_PIXEL_UNPACK_BUFFER 0x88EC
-#endif
-#ifndef GL_ARRAY_BUFFER
-#define GL_ARRAY_BUFFER 0x8892
-#endif
-#ifndef GL_ELEMENT_ARRAY_BUFFER
-#define GL_ARRAY_BUFFER 0x8893
-#endif
-#ifndef GL_READ_ONLY
-#define GL_READ_ONLY 0x88B8
-#endif
-#ifndef GL_WRITE_ONLY
-#define GL_WRITE_ONLY 0x88B9
-#endif
-#ifndef GL_READ_WRITE
-#define GL_READ_WRITE 0x88BA
-#endif
-#ifndef GL_MAP_READ_BIT
-#define GL_MAP_READ_BIT 0x0001
-#endif
-#ifndef GL_MAP_WRITE_BIT
-#define GL_MAP_WRITE_BIT 0x0002
-#endif
-#ifndef GL_MAP_INVALIDATE_RANGE_BIT
-#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004
-#endif
-#ifndef GL_MAP_INVALIDATE_BUFFER_BIT
-#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
-#endif
-
void
_cogl_buffer_gl_create (CoglBuffer *buffer)
{
@@ -106,9 +68,8 @@ update_hints_to_gl_enum (CoglBuffer *buffer)
case COGL_BUFFER_UPDATE_HINT_STREAM:
/* OpenGL ES 1.1 only knows about STATIC_DRAW and DYNAMIC_DRAW */
-#if defined(HAVE_COGL_GL) || defined(HAVE_COGL_GLES2)
- if (buffer->context->driver != COGL_DRIVER_GLES1)
- return GL_STREAM_DRAW;
+#if defined(HAVE_COGL_GL)
+ return GL_STREAM_DRAW;
#else
return GL_DYNAMIC_DRAW;
#endif
diff --git a/cogl/driver/gl/cogl-pipeline-fragend-fixed.c b/cogl/driver/gl/cogl-pipeline-fragend-fixed.c
index 55b09568..541c4259 100644
--- a/cogl/driver/gl/cogl-pipeline-fragend-fixed.c
+++ b/cogl/driver/gl/cogl-pipeline-fragend-fixed.c
@@ -390,22 +390,6 @@ _cogl_pipeline_fragend_fixed_end (CoglPipeline *pipeline,
GE (ctx, glFogfv (GL_FOG_COLOR, fogColor));
- if (ctx->driver == COGL_DRIVER_GLES1)
- switch (fog_state->mode)
- {
- case COGL_FOG_MODE_LINEAR:
- gl_mode = GL_LINEAR;
- break;
- case COGL_FOG_MODE_EXPONENTIAL:
- gl_mode = GL_EXP;
- break;
- case COGL_FOG_MODE_EXPONENTIAL_SQUARED:
- gl_mode = GL_EXP2;
- break;
- }
- /* TODO: support other modes for GLES2 */
-
- /* NB: GLES doesn't have glFogi */
GE (ctx, glFogf (GL_FOG_MODE, gl_mode));
GE (ctx, glHint (GL_FOG_HINT, GL_NICEST));
diff --git a/cogl/driver/gl/cogl-pipeline-fragend-glsl.c b/cogl/driver/gl/cogl-pipeline-fragend-glsl.c
index 6fdb3a12..01371303 100644
--- a/cogl/driver/gl/cogl-pipeline-fragend-glsl.c
+++ b/cogl/driver/gl/cogl-pipeline-fragend-glsl.c
@@ -58,15 +58,6 @@
#include <glib.h>
-/*
- * GL/GLES compatability defines for pipeline thingies:
- */
-
-/* This might not be defined on GLES */
-#ifndef GL_TEXTURE_3D
-#define GL_TEXTURE_3D 0x806F
-#endif
-
const CoglPipelineFragend _cogl_pipeline_glsl_backend;
typedef struct _UnitState
@@ -927,7 +918,7 @@ _cogl_pipeline_fragend_glsl_add_layer (CoglPipeline *pipeline,
/* GLES2 and GL3 don't have alpha testing so we need to implement it
in the shader */
-#if defined(HAVE_COGL_GLES2) || defined(HAVE_COGL_GL)
+#if defined(HAVE_COGL_GL)
static void
add_alpha_test_snippet (CoglPipeline *pipeline,
@@ -1043,7 +1034,7 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
g_string_append (shader_state->source,
" cogl_color_out = cogl_color_in;\n");
-#if defined(HAVE_COGL_GLES2) || defined (HAVE_COGL_GL)
+#if defined(HAVE_COGL_GL)
if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_ALPHA_TEST))
add_alpha_test_snippet (pipeline, shader_state);
#endif
diff --git a/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/driver/gl/cogl-pipeline-opengl.c
index c7b44ee7..0bd0ff45 100644
--- a/cogl/driver/gl/cogl-pipeline-opengl.c
+++ b/cogl/driver/gl/cogl-pipeline-opengl.c
@@ -50,24 +50,6 @@
#include <glib.h>
#include <string.h>
-/*
- * GL/GLES compatability defines for pipeline thingies:
- */
-
-/* These aren't defined in the GLES headers */
-#ifndef GL_POINT_SPRITE
-#define GL_POINT_SPRITE 0x8861
-#endif
-#ifndef GL_COORD_REPLACE
-#define GL_COORD_REPLACE 0x8862
-#endif
-#ifndef GL_CLAMP_TO_BORDER
-#define GL_CLAMP_TO_BORDER 0x812d
-#endif
-#ifndef GL_PROGRAM_POINT_SIZE
-#define GL_PROGRAM_POINT_SIZE 0x8642
-#endif
-
static void
texture_unit_init (CoglContext *ctx,
CoglTextureUnit *unit,
@@ -396,7 +378,7 @@ _cogl_use_vertex_program (GLuint gl_program, CoglPipelineProgramType type)
ctx->current_vertex_program_type = type;
}
-#if defined(HAVE_COGL_GLES2) || defined(HAVE_COGL_GL)
+#if defined(HAVE_COGL_GL)
static CoglBool
blend_factor_uses_constant (GLenum blend_factor)
@@ -441,9 +423,8 @@ flush_depth_state (CoglContext *ctx,
ctx->depth_writing_enabled_cache = depth_writing_enabled;
}
- if (ctx->driver != COGL_DRIVER_GLES1 &&
- (ctx->depth_range_near_cache != depth_state->range_near ||
- ctx->depth_range_far_cache != depth_state->range_far))
+ if (ctx->depth_range_near_cache != depth_state->range_near ||
+ ctx->depth_range_far_cache != depth_state->range_far)
{
if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_EMBEDDED))
GE (ctx, glDepthRangef (depth_state->range_near,
@@ -522,60 +503,50 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state (
CoglPipelineBlendState *blend_state =
&authority->big_state->blend_state;
- /* GLES 1 only has glBlendFunc */
- if (ctx->driver == COGL_DRIVER_GLES1)
- {
- GE (ctx, glBlendFunc (blend_state->blend_src_factor_rgb,
- blend_state->blend_dst_factor_rgb));
- }
-#if defined(HAVE_COGL_GLES2) || defined(HAVE_COGL_GL)
- else
+#if defined(HAVE_COGL_GL)
+ if (blend_factor_uses_constant (blend_state->blend_src_factor_rgb) ||
+ blend_factor_uses_constant (blend_state
+ ->blend_src_factor_alpha) ||
+ blend_factor_uses_constant (blend_state->blend_dst_factor_rgb) ||
+ blend_factor_uses_constant (blend_state->blend_dst_factor_alpha))
{
- if (blend_factor_uses_constant (blend_state->blend_src_factor_rgb) ||
- blend_factor_uses_constant (blend_state
- ->blend_src_factor_alpha) ||
- blend_factor_uses_constant (blend_state->blend_dst_factor_rgb) ||
- blend_factor_uses_constant (blend_state->blend_dst_factor_alpha))
- {
- float red =
- cogl_color_get_red_float (&blend_state->blend_constant);
- float green =
- cogl_color_get_green_float (&blend_state->blend_constant);
- float blue =
- cogl_color_get_blue_float (&blend_state->blend_constant);
- float alpha =
- cogl_color_get_alpha_float (&blend_state->blend_constant);
-
+ float red =
+ cogl_color_get_red_float (&blend_state->blend_constant);
+ float green =
+ cogl_color_get_green_float (&blend_state->blend_constant);
+ float blue =
+ cogl_color_get_blue_float (&blend_state->blend_constant);
+ float alpha =
+ cogl_color_get_alpha_float (&blend_state->blend_constant);
- GE (ctx, glBlendColor (red, green, blue, alpha));
- }
- if (ctx->glBlendEquationSeparate &&
- blend_state->blend_equation_rgb !=
- blend_state->blend_equation_alpha)
- GE (ctx,
- glBlendEquationSeparate (blend_state->blend_equation_rgb,
- blend_state->blend_equation_alpha));
- else
- GE (ctx, glBlendEquation (blend_state->blend_equation_rgb));
-
- if (ctx->glBlendFuncSeparate &&
- (blend_state->blend_src_factor_rgb !=
- blend_state->blend_src_factor_alpha ||
- (blend_state->blend_dst_factor_rgb !=
- blend_state->blend_dst_factor_alpha)))
- GE (ctx, glBlendFuncSeparate (blend_state->blend_src_factor_rgb,
- blend_state->blend_dst_factor_rgb,
- blend_state->blend_src_factor_alpha,
- blend_state->blend_dst_factor_alpha));
- else
- GE (ctx, glBlendFunc (blend_state->blend_src_factor_rgb,
- blend_state->blend_dst_factor_rgb));
+ GE (ctx, glBlendColor (red, green, blue, alpha));
}
-#endif
+
+ if (ctx->glBlendEquationSeparate &&
+ blend_state->blend_equation_rgb !=
+ blend_state->blend_equation_alpha)
+ GE (ctx,
+ glBlendEquationSeparate (blend_state->blend_equation_rgb,
+ blend_state->blend_equation_alpha));
+ else
+ GE (ctx, glBlendEquation (blend_state->blend_equation_rgb));
+
+ if (ctx->glBlendFuncSeparate &&
+ (blend_state->blend_src_factor_rgb !=
+ blend_state->blend_src_factor_alpha ||
+ (blend_state->blend_dst_factor_rgb !=
+ blend_state->blend_dst_factor_alpha)))
+ GE (ctx, glBlendFuncSeparate (blend_state->blend_src_factor_rgb,
+ blend_state->blend_dst_factor_rgb,
+ blend_state->blend_src_factor_alpha,
+ blend_state->blend_dst_factor_alpha));
+ else
+ GE (ctx, glBlendFunc (blend_state->blend_src_factor_rgb,
+ blend_state->blend_dst_factor_rgb));
}
-#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
+#if defined (HAVE_COGL_GL)
if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_ALPHA_TEST))
{
@@ -758,21 +729,7 @@ get_max_activateable_texture_units (void)
}
#endif /* HAVE_COGL_GL */
-#ifdef HAVE_COGL_GLES2
- if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_EMBEDDED) &&
- _cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_PROGRAMMABLE))
- {
- GE (ctx, glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, values + n_values));
- /* Two of the vertex attribs need to be used for the position
- and color */
- values[n_values++] -= 2;
-
- GE (ctx, glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
- values + n_values++));
- }
-#endif
-
-#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
+#if defined (HAVE_COGL_GL)
if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_FIXED))
{
/* GL_MAX_TEXTURE_UNITS defines the number of units that are
@@ -917,7 +874,7 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data)
* this point we can't currently tell if we are using the fixed or
* glsl progend.
*/
-#if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GL)
+#if defined (HAVE_COGL_GL)
if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_FIXED) &&
(layers_difference & COGL_PIPELINE_LAYER_STATE_POINT_SPRITE_COORDS))
{
diff --git a/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/driver/gl/cogl-texture-2d-gl.c
index 8675f520..78295553 100644
--- a/cogl/driver/gl/cogl-texture-2d-gl.c
+++ b/cogl/driver/gl/cogl-texture-2d-gl.c
@@ -612,7 +612,7 @@ _cogl_texture_2d_gl_generate_mipmap (CoglTexture2D *tex_2d)
GL_GENERATE_MIPMAP and reuploading the first pixel */
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
_cogl_texture_gl_generate_mipmaps (COGL_TEXTURE (tex_2d));
-#if defined(HAVE_COGL_GLES) || defined(HAVE_COGL_GL)
+#if defined(HAVE_COGL_GL)
else
{
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
diff --git a/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/driver/gl/gles/cogl-driver-gles.c
deleted file mode 100644
index e94449f4..00000000
--- a/cogl/driver/gl/gles/cogl-driver-gles.c
+++ /dev/null
@@ -1,487 +0,0 @@
-/*
- * Cogl
- *
- * A Low Level GPU Graphics and Utilities API
- *
- * Copyright (C) 2007,2008,2009 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.
- *
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <string.h>
-
-#include "cogl-context-private.h"
-#include "cogl-util-gl-private.h"
-#include "cogl-feature-private.h"
-#include "cogl-renderer-private.h"
-#include "cogl-private.h"
-#include "cogl-framebuffer-gl-private.h"
-#include "cogl-texture-2d-gl-private.h"
-#include "cogl-attribute-gl-private.h"
-#include "cogl-clip-stack-gl-private.h"
-#include "cogl-buffer-gl-private.h"
-
-#ifndef GL_UNSIGNED_INT_24_8
-#define GL_UNSIGNED_INT_24_8 0x84FA
-#endif
-#ifndef GL_DEPTH_STENCIL
-#define GL_DEPTH_STENCIL 0x84F9
-#endif
-#ifndef GL_RG
-#define GL_RG 0x8227
-#endif
-#ifndef GL_RG8
-#define GL_RG8 0x822B
-#endif
-
-static CoglBool
-_cogl_driver_pixel_format_from_gl_internal (CoglContext *context,
- GLenum gl_int_format,
- CoglPixelFormat *out_format)
-{
- return TRUE;
-}
-
-static CoglPixelFormat
-_cogl_driver_pixel_format_to_gl (CoglContext *context,
- CoglPixelFormat format,
- GLenum *out_glintformat,
- GLenum *out_glformat,
- GLenum *out_gltype)
-{
- CoglPixelFormat required_format;
- GLenum glintformat;
- GLenum glformat = 0;
- GLenum gltype;
-
- required_format = format;
-
- /* Find GL equivalents */
- switch (format)
- {
- case COGL_PIXEL_FORMAT_A_8:
- glintformat = GL_ALPHA;
- glformat = GL_ALPHA;
- gltype = GL_UNSIGNED_BYTE;
- break;
- case COGL_PIXEL_FORMAT_G_8:
- glintformat = GL_LUMINANCE;
- glformat = GL_LUMINANCE;
- gltype = GL_UNSIGNED_BYTE;
- break;
-
- case COGL_PIXEL_FORMAT_RG_88:
- if (cogl_has_feature (context, COGL_FEATURE_ID_TEXTURE_RG))
- {
- glintformat = GL_RG8;
- glformat = GL_RG;
- }
- else
- {
- /* If red-green textures aren't supported then we'll use RGB
- * as an internal format. Note this should only end up
- * mattering for downloading the data because Cogl will
- * refuse to allocate a texture with RG components if RG
- * textures aren't supported */
- glintformat = GL_RGB;
- glformat = GL_RGB;
- required_format = COGL_PIXEL_FORMAT_RGB_888;
- }
- gltype = GL_UNSIGNED_BYTE;
- break;
-
- case COGL_PIXEL_FORMAT_BGRA_8888:
- case COGL_PIXEL_FORMAT_BGRA_8888_PRE:
- /* There is an extension to support this format */
- if (_cogl_has_private_feature
- (context, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888))
- {
- /* For some reason the extension says you have to specify
- BGRA for the internal format too */
- glintformat = GL_BGRA_EXT;
- glformat = GL_BGRA_EXT;
- gltype = GL_UNSIGNED_BYTE;
- required_format = format;
- break;
- }
- /* flow through */
-
- /* Just one 24-bit ordering supported */
- case COGL_PIXEL_FORMAT_RGB_888:
- case COGL_PIXEL_FORMAT_BGR_888:
- glintformat = GL_RGB;
- glformat = GL_RGB;
- gltype = GL_UNSIGNED_BYTE;
- required_format = COGL_PIXEL_FORMAT_RGB_888;
- break;
-
- /* Just one 32-bit ordering supported */
- case COGL_PIXEL_FORMAT_RGBA_8888:
- case COGL_PIXEL_FORMAT_RGBA_8888_PRE:
- case COGL_PIXEL_FORMAT_ARGB_8888:
- case COGL_PIXEL_FORMAT_ARGB_8888_PRE:
- case COGL_PIXEL_FORMAT_ABGR_8888:
- case COGL_PIXEL_FORMAT_ABGR_8888_PRE:
- case COGL_PIXEL_FORMAT_RGBA_1010102:
- case COGL_PIXEL_FORMAT_RGBA_1010102_PRE:
- case COGL_PIXEL_FORMAT_BGRA_1010102:
- case COGL_PIXEL_FORMAT_BGRA_1010102_PRE:
- case COGL_PIXEL_FORMAT_ABGR_2101010:
- case COGL_PIXEL_FORMAT_ABGR_2101010_PRE:
- case COGL_PIXEL_FORMAT_ARGB_2101010:
- case COGL_PIXEL_FORMAT_ARGB_2101010_PRE:
- glintformat = GL_RGBA;
- glformat = GL_RGBA;
- gltype = GL_UNSIGNED_BYTE;
- required_format = COGL_PIXEL_FORMAT_RGBA_8888;
- required_format |= (format & COGL_PREMULT_BIT);
- break;
-
- /* The following three types of channel ordering
- * are always defined using system word byte
- * ordering (even according to GLES spec) */
- case COGL_PIXEL_FORMAT_RGB_565:
- glintformat = GL_RGB;
- glformat = GL_RGB;
- gltype = GL_UNSIGNED_SHORT_5_6_5;
- break;
- case COGL_PIXEL_FORMAT_RGBA_4444:
- case COGL_PIXEL_FORMAT_RGBA_4444_PRE:
- glintformat = GL_RGBA;
- glformat = GL_RGBA;
- gltype = GL_UNSIGNED_SHORT_4_4_4_4;
- break;
- case COGL_PIXEL_FORMAT_RGBA_5551:
- case COGL_PIXEL_FORMAT_RGBA_5551_PRE:
- glintformat = GL_RGBA;
- glformat = GL_RGBA;
- gltype = GL_UNSIGNED_SHORT_5_5_5_1;
- break;
-
- case COGL_PIXEL_FORMAT_DEPTH_16:
- glintformat = GL_DEPTH_COMPONENT;
- glformat = GL_DEPTH_COMPONENT;
- gltype = GL_UNSIGNED_SHORT;
- break;
- case COGL_PIXEL_FORMAT_DEPTH_32:
- glintformat = GL_DEPTH_COMPONENT;
- glformat = GL_DEPTH_COMPONENT;
- gltype = GL_UNSIGNED_INT;
- break;
-
- case COGL_PIXEL_FORMAT_DEPTH_24_STENCIL_8:
- glintformat = GL_DEPTH_STENCIL;
- glformat = GL_DEPTH_STENCIL;
- gltype = GL_UNSIGNED_INT_24_8;
- break;
-
- case COGL_PIXEL_FORMAT_ANY:
- case COGL_PIXEL_FORMAT_YUV:
- g_assert_not_reached ();
- break;
- }
-
- /* All of the pixel formats are handled above so if this hits then
- we've been given an invalid pixel format */
- g_assert (glformat != 0);
-
- if (out_glintformat != NULL)
- *out_glintformat = glintformat;
- if (out_glformat != NULL)
- *out_glformat = glformat;
- if (out_gltype != NULL)
- *out_gltype = gltype;
-
- return required_format;
-}
-
-static CoglBool
-_cogl_get_gl_version (CoglContext *ctx,
- int *major_out,
- int *minor_out)
-{
- const char *version_string;
-
- /* Get the OpenGL version number */
- if ((version_string = _cogl_context_get_gl_version (ctx)) == NULL)
- return FALSE;
-
- if (!g_str_has_prefix (version_string, "OpenGL ES "))
- return FALSE;
-
- return _cogl_gl_util_parse_gl_version (version_string + 10,
- major_out,
- minor_out);
-}
-
-static CoglBool
-_cogl_driver_update_features (CoglContext *context,
- CoglError **error)
-{
- unsigned long private_features
- [COGL_FLAGS_N_LONGS_FOR_SIZE (COGL_N_PRIVATE_FEATURES)] = { 0 };
- CoglFeatureFlags flags = 0;
- char **gl_extensions;
- int gl_major, gl_minor;
- int i;
-
- /* We have to special case getting the pointer to the glGetString
- function because we need to use it to determine what functions we
- can expect */
- context->glGetString =
- (void *) _cogl_renderer_get_proc_address (context->display->renderer,
- "glGetString",
- TRUE);
-
- gl_extensions = _cogl_context_get_gl_extensions (context);
-
- if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_WINSYS)))
- {
- char *all_extensions = g_strjoinv (" ", gl_extensions);
-
- COGL_NOTE (WINSYS,
- "Checking features\n"
- " GL_VENDOR: %s\n"
- " GL_RENDERER: %s\n"
- " GL_VERSION: %s\n"
- " GL_EXTENSIONS: %s",
- context->glGetString (GL_VENDOR),
- context->glGetString (GL_RENDERER),
- _cogl_context_get_gl_version (context),
- all_extensions);
-
- g_free (all_extensions);
- }
-
- context->glsl_major = 1;
- 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;
- gl_minor = 1;
- }
-
- _cogl_feature_check_ext_functions (context,
- gl_major,
- gl_minor,
- gl_extensions);
-
-#ifdef HAVE_COGL_GLES
- if (context->driver == COGL_DRIVER_GLES1)
- {
- int max_clip_planes;
- GE( context, glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
- if (max_clip_planes >= 4)
- COGL_FLAGS_SET (private_features,
- COGL_PRIVATE_FEATURE_FOUR_CLIP_PLANES, TRUE);
- }
-#endif
-
- if (context->driver == COGL_DRIVER_GLES2)
- {
- flags |= COGL_FEATURE_SHADERS_GLSL | COGL_FEATURE_OFFSCREEN;
- /* Note GLES 2 core doesn't support mipmaps for npot textures or
- * repeat modes other than CLAMP_TO_EDGE. */
- flags |= COGL_FEATURE_TEXTURE_NPOT_BASIC;
- flags |= COGL_FEATURE_DEPTH_RANGE;
- COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_GLSL, TRUE);
- COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_OFFSCREEN, TRUE);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_TEXTURE_NPOT_BASIC, TRUE);
- COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_DEPTH_RANGE, TRUE);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_MIRRORED_REPEAT, TRUE);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_PER_VERTEX_POINT_SIZE, TRUE);
-
- COGL_FLAGS_SET (private_features,
- COGL_PRIVATE_FEATURE_BLEND_CONSTANT, TRUE);
- }
- else if (context->driver == COGL_DRIVER_GLES1)
- {
- COGL_FLAGS_SET (private_features, COGL_PRIVATE_FEATURE_GL_FIXED, TRUE);
- COGL_FLAGS_SET (private_features, COGL_PRIVATE_FEATURE_ALPHA_TEST, TRUE);
- COGL_FLAGS_SET (private_features,
- COGL_PRIVATE_FEATURE_BUILTIN_POINT_SIZE_UNIFORM, TRUE);
- }
-
- COGL_FLAGS_SET (private_features, COGL_PRIVATE_FEATURE_VBOS, TRUE);
- COGL_FLAGS_SET (private_features, COGL_PRIVATE_FEATURE_ANY_GL, TRUE);
- COGL_FLAGS_SET (private_features, COGL_PRIVATE_FEATURE_ALPHA_TEXTURES, TRUE);
-
- /* Both GLES 1.1 and GLES 2.0 support point sprites in core */
- flags |= COGL_FEATURE_POINT_SPRITE;
- COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_POINT_SPRITE, TRUE);
-
- if (context->glGenRenderbuffers)
- {
- flags |= COGL_FEATURE_OFFSCREEN;
- COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_OFFSCREEN, TRUE);
- }
-
- if (context->glBlitFramebuffer)
- COGL_FLAGS_SET (private_features,
- COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT, TRUE);
-
- if (_cogl_check_extension ("GL_OES_element_index_uint", gl_extensions))
- {
- flags |= COGL_FEATURE_UNSIGNED_INT_INDICES;
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_UNSIGNED_INT_INDICES, TRUE);
- }
-
- if (_cogl_check_extension ("GL_OES_depth_texture", gl_extensions))
- {
- flags |= COGL_FEATURE_DEPTH_TEXTURE;
- COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_DEPTH_TEXTURE, TRUE);
- }
-
- if (_cogl_check_extension ("GL_OES_texture_npot", gl_extensions))
- {
- flags |= (COGL_FEATURE_TEXTURE_NPOT |
- COGL_FEATURE_TEXTURE_NPOT_BASIC |
- COGL_FEATURE_TEXTURE_NPOT_MIPMAP |
- COGL_FEATURE_TEXTURE_NPOT_REPEAT);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_TEXTURE_NPOT, TRUE);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_TEXTURE_NPOT_BASIC, TRUE);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP, TRUE);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_TEXTURE_NPOT_REPEAT, TRUE);
- }
- else if (_cogl_check_extension ("GL_IMG_texture_npot", gl_extensions))
- {
- flags |= (COGL_FEATURE_TEXTURE_NPOT_BASIC |
- COGL_FEATURE_TEXTURE_NPOT_MIPMAP);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_TEXTURE_NPOT_BASIC, TRUE);
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP, TRUE);
- }
-
- if (context->glTexImage3D)
- {
- flags |= COGL_FEATURE_TEXTURE_3D;
- COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_TEXTURE_3D, TRUE);
- }
-
- if (context->glMapBuffer)
- {
- /* The GL_OES_mapbuffer extension doesn't support mapping for
- read */
- flags |= COGL_FEATURE_MAP_BUFFER_FOR_WRITE;
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_MAP_BUFFER_FOR_WRITE, TRUE);
- }
-
- if (context->glMapBufferRange)
- {
- /* MapBufferRange in ES3+ does support mapping for read */
- flags |= (COGL_FEATURE_MAP_BUFFER_FOR_WRITE |
- COGL_FEATURE_MAP_BUFFER_FOR_READ);
- COGL_FLAGS_SET(context->features,
- COGL_FEATURE_ID_MAP_BUFFER_FOR_WRITE, TRUE);
- COGL_FLAGS_SET(context->features,
- COGL_FEATURE_ID_MAP_BUFFER_FOR_READ, TRUE);
- }
-
- if (context->glEGLImageTargetTexture2D)
- COGL_FLAGS_SET (private_features,
- COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE, TRUE);
-
- if (_cogl_check_extension ("GL_OES_packed_depth_stencil", gl_extensions))
- COGL_FLAGS_SET (private_features,
- COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL, TRUE);
-
- if (_cogl_check_extension ("GL_EXT_texture_format_BGRA8888", gl_extensions))
- COGL_FLAGS_SET (private_features,
- COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888, TRUE);
-
- if (_cogl_check_extension ("GL_EXT_unpack_subimage", gl_extensions))
- COGL_FLAGS_SET (private_features,
- COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE, TRUE);
-
- /* A nameless vendor implemented the extension, but got the case wrong
- * per the spec. */
- if (_cogl_check_extension ("GL_OES_EGL_sync", gl_extensions) ||
- _cogl_check_extension ("GL_OES_egl_sync", gl_extensions))
- COGL_FLAGS_SET (private_features, COGL_PRIVATE_FEATURE_OES_EGL_SYNC, TRUE);
-
- if (_cogl_check_extension ("GL_EXT_texture_rg", gl_extensions))
- COGL_FLAGS_SET (context->features,
- COGL_FEATURE_ID_TEXTURE_RG,
- TRUE);
-
- /* Cache features */
- for (i = 0; i < G_N_ELEMENTS (private_features); i++)
- context->private_features[i] |= private_features[i];
- context->feature_flags |= flags;
-
- g_strfreev (gl_extensions);
-
- return TRUE;
-}
-
-const CoglDriverVtable
-_cogl_driver_gles =
- {
- _cogl_driver_pixel_format_from_gl_internal,
- _cogl_driver_pixel_format_to_gl,
- _cogl_driver_update_features,
- _cogl_offscreen_gl_allocate,
- _cogl_offscreen_gl_free,
- _cogl_framebuffer_gl_flush_state,
- _cogl_framebuffer_gl_clear,
- _cogl_framebuffer_gl_query_bits,
- _cogl_framebuffer_gl_finish,
- _cogl_framebuffer_gl_discard_buffers,
- _cogl_framebuffer_gl_draw_attributes,
- _cogl_framebuffer_gl_draw_indexed_attributes,
- _cogl_framebuffer_gl_read_pixels_into_bitmap,
- _cogl_texture_2d_gl_free,
- _cogl_texture_2d_gl_can_create,
- _cogl_texture_2d_gl_init,
- _cogl_texture_2d_gl_allocate,
- _cogl_texture_2d_gl_copy_from_framebuffer,
- _cogl_texture_2d_gl_get_gl_handle,
- _cogl_texture_2d_gl_generate_mipmap,
- _cogl_texture_2d_gl_copy_from_bitmap,
- NULL, /* texture_2d_get_data */
- _cogl_gl_flush_attributes_state,
- _cogl_clip_stack_gl_flush,
- _cogl_buffer_gl_create,
- _cogl_buffer_gl_destroy,
- _cogl_buffer_gl_map_range,
- _cogl_buffer_gl_unmap,
- _cogl_buffer_gl_set_data,
- };
diff --git a/cogl/driver/gl/gles/cogl-texture-driver-gles.c b/cogl/driver/gl/gles/cogl-texture-driver-gles.c
deleted file mode 100644
index f87f1e90..00000000
--- a/cogl/driver/gl/gles/cogl-texture-driver-gles.c
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
- * Cogl
- *
- * A Low Level GPU Graphics and Utilities API
- *
- * Copyright (C) 2007,2008,2009 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:
- * Matthew Allum <mallum@openedhand.com>
- * Neil Roberts <neil@linux.intel.com>
- * Robert Bragg <robert@linux.intel.com>
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "cogl-private.h"
-#include "cogl-util.h"
-#include "cogl-bitmap.h"
-#include "cogl-bitmap-private.h"
-#include "cogl-texture-private.h"
-#include "cogl-pipeline.h"
-#include "cogl-pipeline-opengl-private.h"
-#include "cogl-context-private.h"
-#include "cogl-object-private.h"
-#include "cogl-primitives.h"
-#include "cogl-util-gl-private.h"
-#include "cogl-error-private.h"
-#include "cogl-texture-gl-private.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-
-#ifndef GL_TEXTURE_3D
-#define GL_TEXTURE_3D 0x806F
-#endif
-#ifndef GL_MAX_3D_TEXTURE_SIZE_OES
-#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073
-#endif
-
-/* This extension isn't available for GLES 1.1 so these won't be
- defined */
-#ifndef GL_UNPACK_ROW_LENGTH
-#define GL_UNPACK_ROW_LENGTH 0x0CF2
-#endif
-#ifndef GL_UNPACK_SKIP_ROWS
-#define GL_UNPACK_SKIP_ROWS 0x0CF3
-#endif
-#ifndef GL_UNPACK_SKIP_PIXELS
-#define GL_UNPACK_SKIP_PIXELS 0x0CF4
-#endif
-
-static GLuint
-_cogl_texture_driver_gen (CoglContext *ctx,
- GLenum gl_target,
- CoglPixelFormat internal_format)
-{
- GLuint tex;
-
- GE (ctx, glGenTextures (1, &tex));
-
- _cogl_bind_gl_texture_transient (gl_target, tex, FALSE);
-
- switch (gl_target)
- {
- case GL_TEXTURE_2D:
- case GL_TEXTURE_3D:
- /* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
- GE( ctx, glTexParameteri (gl_target,
- GL_TEXTURE_MIN_FILTER,
- GL_LINEAR) );
- break;
-
- default:
- g_assert_not_reached();
- }
-
- return tex;
-}
-
-static void
-prep_gl_for_pixels_upload_full (CoglContext *ctx,
- int pixels_rowstride,
- int pixels_src_x,
- int pixels_src_y,
- int pixels_bpp)
-{
- if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE))
- {
- GE( ctx, glPixelStorei (GL_UNPACK_ROW_LENGTH,
- pixels_rowstride / pixels_bpp) );
-
- GE( ctx, glPixelStorei (GL_UNPACK_SKIP_PIXELS, pixels_src_x) );
- GE( ctx, glPixelStorei (GL_UNPACK_SKIP_ROWS, pixels_src_y) );
- }
- else
- {
- g_assert (pixels_src_x == 0);
- g_assert (pixels_src_y == 0);
- }
-
- _cogl_texture_gl_prep_alignment_for_pixels_upload (ctx, pixels_rowstride);
-}
-
-static void
-_cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *ctx,
- int pixels_rowstride,
- int pixels_bpp)
-{
- prep_gl_for_pixels_upload_full (ctx,
- pixels_rowstride,
- 0, 0, /* src_x/y */
- pixels_bpp);
-}
-
-static void
-_cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
- int pixels_rowstride,
- int image_width,
- int pixels_bpp)
-{
- _cogl_texture_gl_prep_alignment_for_pixels_download (ctx,
- pixels_bpp,
- image_width,
- pixels_rowstride);
-}
-
-static CoglBitmap *
-prepare_bitmap_alignment_for_upload (CoglContext *ctx,
- CoglBitmap *src_bmp,
- CoglError **error)
-{
- CoglPixelFormat format = cogl_bitmap_get_format (src_bmp);
- int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
- int src_rowstride = cogl_bitmap_get_rowstride (src_bmp);
- int width = cogl_bitmap_get_width (src_bmp);
- int alignment = 1;
-
- if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE) ||
- src_rowstride == 0)
- return cogl_object_ref (src_bmp);
-
- /* Work out the alignment of the source rowstride */
- alignment = 1 << (_cogl_util_ffs (src_rowstride) - 1);
- alignment = MIN (alignment, 8);
-
- /* If the aligned data equals the rowstride then we can upload from
- the bitmap directly using GL_UNPACK_ALIGNMENT */
- if (((width * bpp + alignment - 1) & ~(alignment - 1)) == src_rowstride)
- return cogl_object_ref (src_bmp);
- /* Otherwise we need to copy the bitmap to pack the alignment
- because GLES has no GL_ROW_LENGTH */
- else
- return _cogl_bitmap_copy (src_bmp, error);
-}
-
-static CoglBool
-_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
- CoglTexture *texture,
- CoglBool is_foreign,
- int src_x,
- int src_y,
- int dst_x,
- int dst_y,
- int width,
- int height,
- int level,
- CoglBitmap *source_bmp,
- GLuint source_gl_format,
- GLuint source_gl_type,
- CoglError **error)
-{
- GLenum gl_target;
- GLuint gl_handle;
- uint8_t *data;
- CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
- int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
- CoglBitmap *slice_bmp;
- int rowstride;
- GLenum gl_error;
- CoglBool status = TRUE;
- CoglError *internal_error = NULL;
- int level_width;
- int level_height;
-
- cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);
-
- /* If we have the GL_EXT_unpack_subimage extension then we can
- upload from subregions directly. Otherwise we may need to copy
- the bitmap */
- if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE) &&
- (src_x != 0 || src_y != 0 ||
- width != cogl_bitmap_get_width (source_bmp) ||
- height != cogl_bitmap_get_height (source_bmp)))
- {
- slice_bmp =
- _cogl_bitmap_new_with_malloc_buffer (ctx,
- width, height,
- source_format,
- error);
- if (!slice_bmp)
- return FALSE;
-
- if (!_cogl_bitmap_copy_subregion (source_bmp,
- slice_bmp,
- src_x, src_y,
- 0, 0, /* dst_x/y */
- width, height,
- error))
- {
- cogl_object_unref (slice_bmp);
- return FALSE;
- }
-
- src_x = src_y = 0;
- }
- else
- {
- slice_bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp, error);
- if (!slice_bmp)
- return FALSE;
- }
-
- rowstride = cogl_bitmap_get_rowstride (slice_bmp);
-
- /* Setup gl alignment to match rowstride and top-left corner */
- prep_gl_for_pixels_upload_full (ctx, rowstride, src_x, src_y, bpp);
-
- data = _cogl_bitmap_gl_bind (slice_bmp, COGL_BUFFER_ACCESS_READ, 0, &internal_error);
-
- /* NB: _cogl_bitmap_gl_bind() may return NULL when successfull so we
- * have to explicitly check the cogl error pointer to catch
- * problems... */
- if (internal_error)
- {
- _cogl_propagate_error (error, internal_error);
- cogl_object_unref (slice_bmp);
- return FALSE;
- }
-
- _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
-
- /* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
-
- _cogl_texture_get_level_size (texture,
- level,
- &level_width,
- &level_height,
- NULL);
-
- if (level_width == width && level_height == height)
- {
- /* GL gets upset if you use glTexSubImage2D to define the
- * contents of a mipmap level so we make sure to use
- * glTexImage2D if we are uploading a full mipmap level.
- */
- ctx->glTexImage2D (gl_target,
- level,
- _cogl_texture_gl_get_format (texture),
- width,
- height,
- 0,
- source_gl_format,
- source_gl_type,
- data);
- }
- else
- {
- /* GL gets upset if you use glTexSubImage2D to initialize the
- * contents of a mipmap level so if this is the first time
- * we've seen a request to upload to this level we call
- * glTexImage2D first to assert that the storage for this
- * level exists.
- */
- if (texture->max_level < level)
- {
- ctx->glTexImage2D (gl_target,
- level,
- _cogl_texture_gl_get_format (texture),
- level_width,
- level_height,
- 0,
- source_gl_format,
- source_gl_type,
- NULL);
- }
-
- ctx->glTexSubImage2D (gl_target,
- level,
- dst_x, dst_y,
- width, height,
- source_gl_format,
- source_gl_type,
- data);
- }
-
- if (_cogl_gl_util_catch_out_of_memory (ctx, error))
- status = FALSE;
-
- _cogl_bitmap_gl_unbind (slice_bmp);
-
- cogl_object_unref (slice_bmp);
-
- return status;
-}
-
-static CoglBool
-_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
- GLenum gl_target,
- GLuint gl_handle,
- CoglBool is_foreign,
- CoglBitmap *source_bmp,
- GLint internal_gl_format,
- GLuint source_gl_format,
- GLuint source_gl_type,
- CoglError **error)
-{
- CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
- int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
- int rowstride;
- int bmp_width = cogl_bitmap_get_width (source_bmp);
- int bmp_height = cogl_bitmap_get_height (source_bmp);
- CoglBitmap *bmp;
- uint8_t *data;
- GLenum gl_error;
- CoglError *internal_error = NULL;
- CoglBool status = TRUE;
-
- bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp, error);
- if (!bmp)
- return FALSE;
-
- rowstride = cogl_bitmap_get_rowstride (bmp);
-
- /* Setup gl alignment to match rowstride and top-left corner */
- _cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
-
- _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
-
- data = _cogl_bitmap_gl_bind (bmp,
- COGL_BUFFER_ACCESS_READ,
- 0, /* hints */
- &internal_error);
-
- /* NB: _cogl_bitmap_gl_bind() may return NULL when successful so we
- * have to explicitly check the cogl error pointer to catch
- * problems... */
- if (internal_error)
- {
- cogl_object_unref (bmp);
- _cogl_propagate_error (error, internal_error);
- return FALSE;
- }
-
- /* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
-
- ctx->glTexImage2D (gl_target, 0,
- internal_gl_format,
- bmp_width, bmp_height,
- 0,
- source_gl_format,
- source_gl_type,
- data);
-
- if (_cogl_gl_util_catch_out_of_memory (ctx, error))
- status = FALSE;
-
- _cogl_bitmap_gl_unbind (bmp);
-
- cogl_object_unref (bmp);
-
- return status;
-}
-
-static CoglBool
-_cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
- GLenum gl_target,
- GLuint gl_handle,
- CoglBool is_foreign,
- GLint height,
- GLint depth,
- CoglBitmap *source_bmp,
- GLint internal_gl_format,
- GLuint source_gl_format,
- GLuint source_gl_type,
- CoglError **error)
-{
- CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
- int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
- int rowstride = cogl_bitmap_get_rowstride (source_bmp);
- int bmp_width = cogl_bitmap_get_width (source_bmp);
- int bmp_height = cogl_bitmap_get_height (source_bmp);
- uint8_t *data;
- GLenum gl_error;
-
- _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
-
- /* If the rowstride or image height can't be specified with just
- GL_ALIGNMENT alone then we need to copy the bitmap because there
- is no GL_ROW_LENGTH */
- if (rowstride / bpp != bmp_width ||
- height != bmp_height / depth)
- {
- CoglBitmap *bmp;
- int image_height = bmp_height / depth;
- CoglPixelFormat source_bmp_format = cogl_bitmap_get_format (source_bmp);
- int i;
-
- _cogl_texture_driver_prep_gl_for_pixels_upload (ctx, bmp_width * bpp, bpp);
-
- /* Initialize the texture with empty data and then upload each
- image with a sub-region update */
-
- /* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
-
- ctx->glTexImage3D (gl_target,
- 0, /* level */
- internal_gl_format,
- bmp_width,
- height,
- depth,
- 0,
- source_gl_format,
- source_gl_type,
- NULL);
-
- if (_cogl_gl_util_catch_out_of_memory (ctx, error))
- return FALSE;
-
- bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
- bmp_width,
- height,
- source_bmp_format,
- error);
- if (!bmp)
- return FALSE;
-
- for (i = 0; i < depth; i++)
- {
- if (!_cogl_bitmap_copy_subregion (source_bmp,
- bmp,
- 0, image_height * i,
- 0, 0,
- bmp_width,
- height,
- error))
- {
- cogl_object_unref (bmp);
- return FALSE;
- }
-
- data = _cogl_bitmap_gl_bind (bmp,
- COGL_BUFFER_ACCESS_READ, 0, error);
- if (!data)
- {
- cogl_object_unref (bmp);
- return FALSE;
- }
-
- /* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
-
- ctx->glTexSubImage3D (gl_target,
- 0, /* level */
- 0, /* xoffset */
- 0, /* yoffset */
- i, /* zoffset */
- bmp_width, /* width */
- height, /* height */
- 1, /* depth */
- source_gl_format,
- source_gl_type,
- data);
-
- if (_cogl_gl_util_catch_out_of_memory (ctx, error))
- {
- cogl_object_unref (bmp);
- _cogl_bitmap_gl_unbind (bmp);
- return FALSE;
- }
-
- _cogl_bitmap_gl_unbind (bmp);
- }
-
- cogl_object_unref (bmp);
- }
- else
- {
- data = _cogl_bitmap_gl_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0, error);
- if (!data)
- return FALSE;
-
- _cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
-
- /* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
-
- ctx->glTexImage3D (gl_target,
- 0, /* level */
- internal_gl_format,
- bmp_width,
- height,
- depth,
- 0,
- source_gl_format,
- source_gl_type,
- data);
-
- if (_cogl_gl_util_catch_out_of_memory (ctx, error))
- {
- _cogl_bitmap_gl_unbind (source_bmp);
- return FALSE;
- }
-
- _cogl_bitmap_gl_unbind (source_bmp);
- }
-
- return TRUE;
-}
-
-/* NB: GLES doesn't support glGetTexImage2D, so cogl-texture will instead
- * fallback to a generic render + readpixels approach to downloading
- * texture data. (See _cogl_texture_draw_and_read() ) */
-static CoglBool
-_cogl_texture_driver_gl_get_tex_image (CoglContext *ctx,
- GLenum gl_target,
- GLenum dest_gl_format,
- GLenum dest_gl_type,
- uint8_t *dest)
-{
- return FALSE;
-}
-
-static CoglBool
-_cogl_texture_driver_size_supported_3d (CoglContext *ctx,
- GLenum gl_target,
- GLenum gl_format,
- GLenum gl_type,
- int width,
- int height,
- int depth)
-{
- GLint max_size;
-
- /* GLES doesn't support a proxy texture target so let's at least
- check whether the size is greater than
- GL_MAX_3D_TEXTURE_SIZE_OES */
- GE( ctx, glGetIntegerv (GL_MAX_3D_TEXTURE_SIZE_OES, &max_size) );
-
- return width <= max_size && height <= max_size && depth <= max_size;
-}
-
-static CoglBool
-_cogl_texture_driver_size_supported (CoglContext *ctx,
- GLenum gl_target,
- GLenum gl_intformat,
- GLenum gl_format,
- GLenum gl_type,
- int width,
- int height)
-{
- GLint max_size;
-
- /* GLES doesn't support a proxy texture target so let's at least
- check whether the size is greater than GL_MAX_TEXTURE_SIZE */
- GE( ctx, glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size) );
-
- return width <= max_size && height <= max_size;
-}
-
-static void
-_cogl_texture_driver_try_setting_gl_border_color
- (CoglContext *ctx,
- GLuint gl_target,
- const GLfloat *transparent_color)
-{
- /* FAIL! */
-}
-
-static CoglBool
-_cogl_texture_driver_allows_foreign_gl_target (CoglContext *ctx,
- GLenum gl_target)
-{
- /* Allow 2-dimensional textures only */
- if (gl_target != GL_TEXTURE_2D)
- return FALSE;
- return TRUE;
-}
-
-static CoglPixelFormat
-_cogl_texture_driver_find_best_gl_get_data_format
- (CoglContext *context,
- CoglPixelFormat format,
- GLenum *closest_gl_format,
- GLenum *closest_gl_type)
-{
- /* Find closest format that's supported by GL
- (Can't use _cogl_pixel_format_to_gl since available formats
- when reading pixels on GLES are severely limited) */
- *closest_gl_format = GL_RGBA;
- *closest_gl_type = GL_UNSIGNED_BYTE;
- return COGL_PIXEL_FORMAT_RGBA_8888;
-}
-
-const CoglTextureDriver
-_cogl_texture_driver_gles =
- {
- _cogl_texture_driver_gen,
- _cogl_texture_driver_prep_gl_for_pixels_upload,
- _cogl_texture_driver_upload_subregion_to_gl,
- _cogl_texture_driver_upload_to_gl,
- _cogl_texture_driver_upload_to_gl_3d,
- _cogl_texture_driver_prep_gl_for_pixels_download,
- _cogl_texture_driver_gl_get_tex_image,
- _cogl_texture_driver_size_supported,
- _cogl_texture_driver_size_supported_3d,
- _cogl_texture_driver_try_setting_gl_border_color,
- _cogl_texture_driver_allows_foreign_gl_target,
- _cogl_texture_driver_find_best_gl_get_data_format
- };