cogl: Remove unused CoglTextureRectangle

https://gitlab.gnome.org/GNOME/mutter/merge_requests/546
This commit is contained in:
Adam Jackson 2019-03-08 12:16:44 -05:00
parent d79f176142
commit c881b4970d
23 changed files with 58 additions and 1373 deletions

View File

@ -50,7 +50,6 @@
#include "cogl-texture-driver.h"
#include "cogl-pipeline-cache.h"
#include "cogl-texture-2d.h"
#include "cogl-texture-rectangle.h"
#include "cogl-sampler-cache-private.h"
#include "cogl-gpu-info-private.h"
#include "cogl-gl-header.h"
@ -165,7 +164,6 @@ struct _CoglContext
/* Textures */
CoglTexture2D *default_gl_texture_2d_tex;
CoglTextureRectangle *default_gl_texture_rect_tex;
/* Central list of all framebuffers so all journals can be flushed
* at any time. */

View File

@ -40,7 +40,6 @@
#include "cogl-journal-private.h"
#include "cogl-texture-private.h"
#include "cogl-texture-2d-private.h"
#include "cogl-texture-rectangle-private.h"
#include "cogl-pipeline-private.h"
#include "cogl-framebuffer-private.h"
#include "cogl-onscreen-private.h"
@ -128,10 +127,8 @@ cogl_context_new (CoglDisplay *display,
{
CoglContext *context;
uint8_t white_pixel[] = { 0xff, 0xff, 0xff, 0xff };
CoglBitmap *white_pixel_bitmap;
const CoglWinsysVtable *winsys;
int i;
CoglError *internal_error = NULL;
_cogl_init ();
@ -279,7 +276,6 @@ cogl_context_new (CoglDisplay *display,
context->legacy_state_set = 0;
context->default_gl_texture_2d_tex = NULL;
context->default_gl_texture_rect_tex = NULL;
context->framebuffers = NULL;
context->current_draw_buffer = NULL;
@ -407,27 +403,6 @@ cogl_context_new (CoglDisplay *display,
white_pixel,
NULL); /* abort on error */
/* TODO: add cogl_texture_rectangle_new_from_data() */
white_pixel_bitmap =
cogl_bitmap_new_for_data (context,
1, 1, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */
white_pixel);
internal_error = NULL;
context->default_gl_texture_rect_tex =
cogl_texture_rectangle_new_from_bitmap (white_pixel_bitmap);
/* XXX: we need to allocate the texture now because the white_pixel
* data is on the stack */
cogl_texture_allocate (COGL_TEXTURE (context->default_gl_texture_rect_tex),
&internal_error);
if (internal_error)
cogl_error_free (internal_error);
cogl_object_unref (white_pixel_bitmap);
cogl_push_source (context->opaque_color_pipeline);
context->atlases = NULL;
@ -466,8 +441,6 @@ _cogl_context_free (CoglContext *context)
if (context->default_gl_texture_2d_tex)
cogl_object_unref (context->default_gl_texture_2d_tex);
if (context->default_gl_texture_rect_tex)
cogl_object_unref (context->default_gl_texture_rect_tex);
if (context->opaque_color_pipeline)
cogl_object_unref (context->opaque_color_pipeline);

View File

@ -1129,8 +1129,8 @@ cogl_framebuffer_clear4f (CoglFramebuffer *framebuffer,
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D or #CoglTextureRectangle are associated with
* layers of the given @pipeline.
* a GPU such as #CoglTexture2D are associated with layers of the given
* @pipeline.
*
* <note>This api doesn't support any of the legacy global state options such
* as cogl_set_depth_test_enabled(), cogl_set_backface_culling_enabled() or
@ -1171,8 +1171,8 @@ cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D or #CoglTextureRectangle are associated with
* layers of the given @pipeline.
* a GPU such as #CoglTexture2D are associated with layers of the given
* @pipeline.
*
* Stability: unstable
* Since: 1.10
@ -1214,8 +1214,8 @@ cogl_framebuffer_vdraw_attributes (CoglFramebuffer *framebuffer,
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D or #CoglTextureRectangle are associated with
* layers of the given @pipeline.
* a GPU such as #CoglTexture2D are associated with layers of the given
* @pipeline.
*
* <note>This api doesn't support any of the legacy global state options such
* as cogl_set_depth_test_enabled(), cogl_set_backface_culling_enabled() or
@ -1280,8 +1280,8 @@ cogl_framebuffer_draw_attributes (CoglFramebuffer *framebuffer,
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D or #CoglTextureRectangle are associated with
* layers of the given @pipeline.
* a GPU such as #CoglTexture2D are associated with layers of the given
* @pipeline.
*
* <note>This api doesn't support any of the legacy global state
* options such as cogl_set_depth_test_enabled(),
@ -1348,8 +1348,8 @@ cogl_framebuffer_vdraw_indexed_attributes (CoglFramebuffer *framebuffer,
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D or #CoglTextureRectangle are associated with
* layers of the given @pipeline.
* a GPU such as #CoglTexture2D are associated with layers of the given
* @pipeline.
*
* <note>This api doesn't support any of the legacy global state
* options such as cogl_set_depth_test_enabled(),
@ -1443,11 +1443,6 @@ cogl_framebuffer_draw_rectangle (CoglFramebuffer *framebuffer,
* bottom right. To map an entire texture across the rectangle pass
* in @s_1=0, @t_1=0, @s_2=1, @t_2=1.
*
* <note>Even if you have associated a #CoglTextureRectangle texture
* with one of your @pipeline layers which normally implies working
* with non-normalized texture coordinates this api should still be
* passed normalized texture coordinates.</note>
*
* Since: 1.10
* Stability: unstable
*/
@ -1500,9 +1495,7 @@ cogl_framebuffer_draw_textured_rectangle (CoglFramebuffer *framebuffer,
* <note>This api can not currently handle multiple high-level meta
* texture layers. The first layer may be a high level meta texture
* such as #CoglTexture2DSliced but all other layers much be low
* level textures such as #CoglTexture2D and additionally they
* should be textures that can be sampled using normalized coordinates
* (so not #CoglTextureRectangle textures).</note>
* level textures such as #CoglTexture2D.
*
* The top left texture coordinate for layer 0 of any pipeline will be
* (tex_coords[0], tex_coords[1]) and the bottom right coordinate will
@ -1516,11 +1509,6 @@ cogl_framebuffer_draw_textured_rectangle (CoglFramebuffer *framebuffer,
* in tex_coords[0]=0, tex_coords[1]=0, tex_coords[2]=1,
* tex_coords[3]=1.
*
* <note>Even if you have associated a #CoglTextureRectangle texture
* which normally implies working with non-normalized texture
* coordinates this api should still be passed normalized texture
* coordinates.</note>
*
* The first pair of coordinates are for the first layer (with the
* smallest layer index) and if you supply less texture coordinates
* than there are layers in the current source material then default
@ -1624,11 +1612,6 @@ cogl_framebuffer_draw_rectangles (CoglFramebuffer *framebuffer,
* in tex_coords[0]=0, tex_coords[1]=0, tex_coords[2]=1,
* tex_coords[3]=1.
*
* <note>Even if you have associated a #CoglTextureRectangle texture
* which normally implies working with non-normalized texture
* coordinates this api should still be passed normalized texture
* coordinates.</note>
*
* Since: 1.10
* Stability: unstable
*/

View File

@ -36,7 +36,7 @@
#include "cogl-matrix.h"
#include "cogl-spans.h"
#include "cogl-meta-texture.h"
#include "cogl-texture-rectangle-private.h"
#include "cogl-texture-private.h"
#include <string.h>
#include <math.h>
@ -316,16 +316,9 @@ foreach_clamped_region (CoglMetaTexture *meta_texture,
if (wrap_s == COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE)
{
float max_s_coord;
float max_s_coord = 1.0;
float half_texel_width;
/* Consider that rectangle textures have non-normalized
* coordinates... */
if (cogl_is_texture_rectangle (meta_texture))
max_s_coord = width;
else
max_s_coord = 1.0;
half_texel_width = max_s_coord / (width * 2);
/* Handle any left clamped region */
@ -375,16 +368,9 @@ foreach_clamped_region (CoglMetaTexture *meta_texture,
if (wrap_t == COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE)
{
float height = cogl_texture_get_height (COGL_TEXTURE (meta_texture));
float max_t_coord;
float max_t_coord = 1.0;
float half_texel_height;
/* Consider that rectangle textures have non-normalized
* coordinates... */
if (cogl_is_texture_rectangle (meta_texture))
max_t_coord = height;
else
max_t_coord = 1.0;
half_texel_height = max_t_coord / (height * 2);
/* Handle any top clamped region */
@ -466,33 +452,6 @@ normalize_meta_coords_cb (CoglTexture *slice_texture,
data->user_data);
}
typedef struct _UnNormalizeData
{
CoglMetaTextureCallback callback;
void *user_data;
float width;
float height;
} UnNormalizeData;
static void
un_normalize_slice_coords_cb (CoglTexture *slice_texture,
const float *slice_coords,
const float *meta_coords,
void *user_data)
{
UnNormalizeData *data = user_data;
float un_normalized_slice_coords[4] = {
slice_coords[0] * data->width,
slice_coords[1] * data->height,
slice_coords[2] * data->width,
slice_coords[3] * data->height
};
data->callback (slice_texture,
un_normalized_slice_coords, meta_coords,
data->user_data);
}
void
cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture,
float tx_1,
@ -539,8 +498,6 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture,
* coordinates beyond this point and only re-normalize just before
* calling the user's callback... */
if (!cogl_is_texture_rectangle (COGL_TEXTURE (meta_texture)))
{
normalize_data.callback = callback;
normalize_data.user_data = user_data;
normalize_data.s_normalize_factor = 1.0f / width;
@ -551,7 +508,6 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture,
ty_1 *= height;
tx_2 *= width;
ty_2 *= height;
}
/* XXX: at some point this wont be routed through the CoglTexture
* vtable, instead there will be a separate CoglMetaTexture
@ -609,21 +565,6 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture,
CoglSpan x_span = { 0, width, 0 };
CoglSpan y_span = { 0, height, 0 };
float meta_region_coords[4] = { tx_1, ty_1, tx_2, ty_2 };
UnNormalizeData un_normalize_data;
/* If we are dealing with a CoglTextureRectangle then we need a shim
* callback that un_normalizes the slice coordinates we get from
* _cogl_texture_spans_foreach_in_region before passing them to
* the user's callback. */
if (cogl_is_texture_rectangle (meta_texture))
{
un_normalize_data.callback = callback;
un_normalize_data.user_data = user_data;
un_normalize_data.width = width;
un_normalize_data.height = height;
callback = un_normalize_slice_coords_cb;
user_data = &un_normalize_data;
}
_cogl_texture_spans_foreach_in_region (&x_span, 1,
&y_span, 1,

View File

@ -75,8 +75,8 @@ GType cogl_offscreen_get_gtype (void);
* destroy the offscreen buffer before you can use the @texture again.
*
* <note>This api only works with low-level #CoglTexture types such as
* #CoglTexture2D and #CoglTextureRectangle, and not with meta-texture
* types such as #CoglTexture2DSliced.</note>
* #CoglTexture2D and not with meta-texture types such as
* #CoglTexture2DSliced.</note>
*
* The storage for the framebuffer is actually allocated lazily
* so this function will never return %NULL to indicate a runtime
@ -110,8 +110,8 @@ cogl_offscreen_new_with_texture (CoglTexture *texture);
* you can use the @texture again.
*
* <note>This only works with low-level #CoglTexture types such as
* #CoglTexture2D and #CoglTextureRectangle, and not with meta-texture
* types such as #CoglTexture2DSliced.</note>
* #CoglTexture2D and not with meta-texture types such as
* #CoglTexture2DSliced.</note>
*
* Return value: (transfer full): a newly instantiated #CoglOffscreen
* framebuffer or %NULL if it wasn't possible to create the

View File

@ -335,24 +335,6 @@ cogl_pipeline_set_layer_null_texture (CoglPipeline *pipeline,
int layer_index,
CoglTextureType texture_type)
{
CoglContext *ctx = _cogl_context_get_default ();
/* Disallow setting texture types that aren't supported */
switch (texture_type)
{
case COGL_TEXTURE_TYPE_2D:
break;
case COGL_TEXTURE_TYPE_RECTANGLE:
if (ctx->default_gl_texture_rect_tex == NULL)
{
g_warning ("The default rectangle texture was set on a pipeline but "
"rectangle textures are not supported");
texture_type = COGL_TEXTURE_TYPE_2D;
}
break;
}
_cogl_pipeline_set_layer_texture_type (pipeline, layer_index, texture_type);
_cogl_pipeline_set_layer_texture_data (pipeline, layer_index, NULL);
}

View File

@ -1904,7 +1904,6 @@ fallback_layer_cb (CoglPipelineLayer *layer, void *user_data)
{
CoglPipelineFallbackState *state = user_data;
CoglPipeline *pipeline = state->pipeline;
CoglTextureType texture_type = _cogl_pipeline_layer_get_texture_type (layer);
CoglTexture *texture = NULL;
COGL_STATIC_COUNTER (layer_fallback_counter,
"layer fallback counter",
@ -1919,16 +1918,7 @@ fallback_layer_cb (CoglPipelineLayer *layer, void *user_data)
COGL_COUNTER_INC (_cogl_uprof_context, layer_fallback_counter);
switch (texture_type)
{
case COGL_TEXTURE_TYPE_2D:
texture = COGL_TEXTURE (ctx->default_gl_texture_2d_tex);
break;
case COGL_TEXTURE_TYPE_RECTANGLE:
texture = COGL_TEXTURE (ctx->default_gl_texture_rect_tex);
break;
}
if (texture == NULL)
{

View File

@ -45,11 +45,10 @@ G_BEGIN_DECLS
* #CoglTexture2D.
*
* A #CoglPrimitiveTexture is a texture that is directly represented
* by a single texture on the GPU. For example these could be a
* #CoglTexture2D or #CoglTextureRectangle. This is opposed to high level
* meta textures which may be composed of multiple primitive textures or a
* sub-region of another texture such as #CoglAtlasTexture and
* #CoglTexture2DSliced.
* by a single texture on the GPU. For example this could be a
* #CoglTexture2D. This is opposed to high level meta textures which
* may be composed of multiple primitive textures or a sub-region of
* another texture such as #CoglAtlasTexture and #CoglTexture2DSliced.
*
* A texture that implements this interface can be directly used with
* the low level cogl_primitive_draw() API. Other types of textures

View File

@ -926,8 +926,8 @@ cogl_primitive_foreach_attribute (CoglPrimitive *primitive,
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D or #CoglTextureRectangle are associated
* with layers of the given @pipeline.
* a GPU such as #CoglTexture2D are associated with layers of the given
* @pipeline.
*
* Stability: unstable
* Since: 1.16

View File

@ -187,8 +187,6 @@ validate_first_layer_cb (CoglPipeline *pipeline,
* texture coordinates require repeating,
* - CoglTexture2DAtlas: if the users given texture coordinates require
* repeating,
* - CoglTextureRectangle: if the users given texture coordinates require
* repeating,
* - CoglTexturePixmap: if the users given texture coordinates require
* repeating
*/
@ -430,8 +428,6 @@ validate_tex_coords_cb (CoglPipeline *pipeline,
* - CoglTexture{1D,2D}: always.
* - CoglTexture2DAtlas: assuming the users given texture coordinates don't
* require repeating.
* - CoglTextureRectangle: assuming the users given texture coordinates don't
* require repeating.
* - CoglTexturePixmap: assuming the users given texture coordinates don't
* require repeating.
*/

View File

@ -40,7 +40,6 @@
#include "cogl-context-private.h"
#include "cogl-object.h"
#include "cogl-texture-driver.h"
#include "cogl-texture-rectangle-private.h"
#include "cogl-texture-2d.h"
#include "cogl-gtype-private.h"
#include "driver/gl/cogl-texture-gl-private.h"
@ -60,30 +59,13 @@ _cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex,
float *coords)
{
CoglTexture *tex = COGL_TEXTURE (sub_tex);
/* NB: coords[] come in as non-normalized if sub_tex->full_texture
* is a CoglTextureRectangle otherwhise they are normalized. The
* coordinates we write out though must always be normalized.
*
* NB: sub_tex->sub_x/y/width/height are in non-normalized
* coordinates.
*/
if (cogl_is_texture_rectangle (sub_tex->full_texture))
{
coords[0] = (coords[0] - sub_tex->sub_x) / tex->width;
coords[1] = (coords[1] - sub_tex->sub_y) / tex->height;
coords[2] = (coords[2] - sub_tex->sub_x) / tex->width;
coords[3] = (coords[3] - sub_tex->sub_y) / tex->height;
}
else
{
float width = cogl_texture_get_width (sub_tex->full_texture);
float height = cogl_texture_get_height (sub_tex->full_texture);
coords[0] = (coords[0] * width - sub_tex->sub_x) / tex->width;
coords[1] = (coords[1] * height - sub_tex->sub_y) / tex->height;
coords[2] = (coords[2] * width - sub_tex->sub_x) / tex->width;
coords[3] = (coords[3] * height - sub_tex->sub_y) / tex->height;
}
}
static void
@ -91,31 +73,13 @@ _cogl_sub_texture_map_quad (CoglSubTexture *sub_tex,
float *coords)
{
CoglTexture *tex = COGL_TEXTURE (sub_tex);
/* NB: coords[] always come in as normalized coordinates but may go
* out as non-normalized if sub_tex->full_texture is a
* CoglTextureRectangle.
*
* NB: sub_tex->sub_x/y/width/height are in non-normalized
* coordinates.
*/
if (cogl_is_texture_rectangle (sub_tex->full_texture))
{
coords[0] = coords[0] * tex->width + sub_tex->sub_x;
coords[1] = coords[1] * tex->height + sub_tex->sub_y;
coords[2] = coords[2] * tex->width + sub_tex->sub_x;
coords[3] = coords[3] * tex->height + sub_tex->sub_y;
}
else
{
float width = cogl_texture_get_width (sub_tex->full_texture);
float height = cogl_texture_get_height (sub_tex->full_texture);
coords[0] = (coords[0] * tex->width + sub_tex->sub_x) / width;
coords[1] = (coords[1] * tex->height + sub_tex->sub_y) / height;
coords[2] = (coords[2] * tex->width + sub_tex->sub_x) / width;
coords[3] = (coords[3] * tex->height + sub_tex->sub_y) / height;
}
}
typedef struct _CoglSubTextureForeachData
@ -165,8 +129,7 @@ _cogl_sub_texture_foreach_sub_texture_in_region (
_cogl_sub_texture_map_quad (sub_tex, mapped_coords);
/* TODO: Add something like cogl_is_low_level_texture() */
if (cogl_is_texture_2d (full_texture) ||
cogl_is_texture_rectangle (full_texture))
if (cogl_is_texture_2d (full_texture))
{
callback (sub_tex->full_texture,
mapped_coords,

View File

@ -1,66 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 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.
*
*
*/
#ifndef __COGL_TEXTURE_RECTANGLE_H
#define __COGL_TEXTURE_RECTANGLE_H
#include "cogl-pipeline-private.h"
#include "cogl-texture-private.h"
#include "cogl-texture-rectangle.h"
struct _CoglTextureRectangle
{
CoglTexture _parent;
/* The internal format of the texture represented as a
CoglPixelFormat */
CoglPixelFormat internal_format;
/* TODO: factor out these OpenGL specific members into some form
* of driver private state. */
/* The internal format of the GL texture represented as a GL enum */
GLenum gl_format;
/* The texture object number */
GLuint gl_texture;
GLenum gl_legacy_texobj_min_filter;
GLenum gl_legacy_texobj_mag_filter;
GLint gl_legacy_texobj_wrap_mode_s;
GLint gl_legacy_texobj_wrap_mode_t;
gboolean is_foreign;
};
CoglTextureRectangle *
_cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
GLuint width,
GLuint height,
CoglPixelFormat format);
#endif /* __COGL_TEXTURE_RECTANGLE_H */

View File

@ -1,776 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2010 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:
* Neil Roberts <neil@linux.intel.com>
*/
#include "cogl-config.h"
#include "cogl-private.h"
#include "cogl-util.h"
#include "cogl-texture-private.h"
#include "cogl-texture-rectangle-private.h"
#include "cogl-texture-driver.h"
#include "cogl-context-private.h"
#include "cogl-object-private.h"
#include "cogl-journal-private.h"
#include "cogl-error-private.h"
#include "cogl-gtype-private.h"
#include "driver/gl/cogl-pipeline-opengl-private.h"
#include "driver/gl/cogl-util-gl-private.h"
#include <string.h>
#include <math.h>
/* These aren't defined under GLES */
#ifndef GL_TEXTURE_RECTANGLE_ARB
#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
#endif
#ifndef GL_CLAMP
#define GL_CLAMP 0x2900
#endif
#ifndef GL_CLAMP_TO_BORDER
#define GL_CLAMP_TO_BORDER 0x812D
#endif
static void _cogl_texture_rectangle_free (CoglTextureRectangle *tex_rect);
COGL_TEXTURE_DEFINE (TextureRectangle, texture_rectangle);
COGL_GTYPE_DEFINE_CLASS (TextureRectangle, texture_rectangle,
COGL_GTYPE_IMPLEMENT_INTERFACE (texture));
static const CoglTextureVtable cogl_texture_rectangle_vtable;
static gboolean
can_use_wrap_mode (GLenum wrap_mode)
{
return (wrap_mode == GL_CLAMP ||
wrap_mode == GL_CLAMP_TO_EDGE ||
wrap_mode == GL_CLAMP_TO_BORDER);
}
static void
_cogl_texture_rectangle_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_p)
{
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
CoglContext *ctx = tex->context;
/* Only set the wrap mode if it's different from the current value
to avoid too many GL calls. Texture rectangle doesn't make use of
the r coordinate so we can ignore its wrap mode */
if (tex_rect->gl_legacy_texobj_wrap_mode_s != wrap_mode_s ||
tex_rect->gl_legacy_texobj_wrap_mode_t != wrap_mode_t)
{
g_assert (can_use_wrap_mode (wrap_mode_s));
g_assert (can_use_wrap_mode (wrap_mode_t));
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign);
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
GL_TEXTURE_WRAP_S, wrap_mode_s) );
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
GL_TEXTURE_WRAP_T, wrap_mode_t) );
tex_rect->gl_legacy_texobj_wrap_mode_s = wrap_mode_s;
tex_rect->gl_legacy_texobj_wrap_mode_t = wrap_mode_t;
}
}
static void
_cogl_texture_rectangle_free (CoglTextureRectangle *tex_rect)
{
if (!tex_rect->is_foreign && tex_rect->gl_texture)
_cogl_delete_gl_texture (tex_rect->gl_texture);
/* Chain up */
_cogl_texture_free (COGL_TEXTURE (tex_rect));
}
static gboolean
_cogl_texture_rectangle_can_create (CoglContext *ctx,
unsigned int width,
unsigned int height,
CoglPixelFormat internal_format,
CoglError **error)
{
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_RECTANGLE))
{
_cogl_set_error (error,
COGL_TEXTURE_ERROR,
COGL_TEXTURE_ERROR_TYPE,
"The CoglTextureRectangle feature isn't available");
return FALSE;
}
ctx->driver_vtable->pixel_format_to_gl (ctx,
internal_format,
&gl_intformat,
&gl_format,
&gl_type);
/* Check that the driver can create a texture with that size */
if (!ctx->texture_driver->size_supported (ctx,
GL_TEXTURE_RECTANGLE_ARB,
gl_intformat,
gl_format,
gl_type,
width,
height))
{
_cogl_set_error (error,
COGL_TEXTURE_ERROR,
COGL_TEXTURE_ERROR_SIZE,
"The requested texture size + format is unsupported");
return FALSE;
}
return TRUE;
}
static void
_cogl_texture_rectangle_set_auto_mipmap (CoglTexture *tex,
gboolean value)
{
/* Rectangle textures currently never support mipmapping so there's
no point in doing anything here */
}
static CoglTextureRectangle *
_cogl_texture_rectangle_create_base (CoglContext *ctx,
int width,
int height,
CoglPixelFormat internal_format,
CoglTextureLoader *loader)
{
CoglTextureRectangle *tex_rect = g_new (CoglTextureRectangle, 1);
CoglTexture *tex = COGL_TEXTURE (tex_rect);
_cogl_texture_init (tex, ctx, width, height,
internal_format, loader,
&cogl_texture_rectangle_vtable);
tex_rect->gl_texture = 0;
tex_rect->is_foreign = FALSE;
/* We default to GL_LINEAR for both filters */
tex_rect->gl_legacy_texobj_min_filter = GL_LINEAR;
tex_rect->gl_legacy_texobj_mag_filter = GL_LINEAR;
/* Wrap mode not yet set */
tex_rect->gl_legacy_texobj_wrap_mode_s = GL_FALSE;
tex_rect->gl_legacy_texobj_wrap_mode_t = GL_FALSE;
return _cogl_texture_rectangle_object_new (tex_rect);
}
CoglTextureRectangle *
cogl_texture_rectangle_new_with_size (CoglContext *ctx,
int width,
int height)
{
CoglTextureLoader *loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
loader->src.sized.width = width;
loader->src.sized.height = height;
return _cogl_texture_rectangle_create_base (ctx, width, height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
loader);
}
static gboolean
allocate_with_size (CoglTextureRectangle *tex_rect,
CoglTextureLoader *loader,
CoglError **error)
{
CoglTexture *tex = COGL_TEXTURE (tex_rect);
CoglContext *ctx = tex->context;
CoglPixelFormat internal_format;
int width = loader->src.sized.width;
int height = loader->src.sized.height;
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
GLenum gl_texture;
internal_format =
_cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY);
if (!_cogl_texture_rectangle_can_create (ctx,
width,
height,
internal_format,
error))
return FALSE;
ctx->driver_vtable->pixel_format_to_gl (ctx,
internal_format,
&gl_intformat,
&gl_format,
&gl_type);
gl_texture =
ctx->texture_driver->gen (ctx,
GL_TEXTURE_RECTANGLE_ARB,
internal_format);
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
gl_texture,
tex_rect->is_foreign);
/* Clear any GL errors */
_cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
width, height, 0, gl_format, gl_type, NULL);
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
{
GE( ctx, glDeleteTextures (1, &gl_texture) );
return FALSE;
}
tex_rect->internal_format = internal_format;
tex_rect->gl_texture = gl_texture;
tex_rect->gl_format = gl_intformat;
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect),
internal_format, width, height);
return TRUE;
}
static gboolean
allocate_from_bitmap (CoglTextureRectangle *tex_rect,
CoglTextureLoader *loader,
CoglError **error)
{
CoglTexture *tex = COGL_TEXTURE (tex_rect);
CoglContext *ctx = tex->context;
CoglPixelFormat internal_format;
CoglBitmap *bmp = loader->src.bitmap.bitmap;
int width = cogl_bitmap_get_width (bmp);
int height = cogl_bitmap_get_height (bmp);
gboolean can_convert_in_place = loader->src.bitmap.can_convert_in_place;
CoglBitmap *upload_bmp;
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
internal_format =
_cogl_texture_determine_internal_format (tex, cogl_bitmap_get_format (bmp));
if (!_cogl_texture_rectangle_can_create (ctx,
width,
height,
internal_format,
error))
return FALSE;
upload_bmp = _cogl_bitmap_convert_for_upload (bmp,
internal_format,
can_convert_in_place,
error);
if (upload_bmp == NULL)
return FALSE;
ctx->driver_vtable->pixel_format_to_gl (ctx,
cogl_bitmap_get_format (upload_bmp),
NULL, /* internal format */
&gl_format,
&gl_type);
ctx->driver_vtable->pixel_format_to_gl (ctx,
internal_format,
&gl_intformat,
NULL,
NULL);
tex_rect->gl_texture =
ctx->texture_driver->gen (ctx,
GL_TEXTURE_RECTANGLE_ARB,
internal_format);
if (!ctx->texture_driver->upload_to_gl (ctx,
GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
FALSE,
upload_bmp,
gl_intformat,
gl_format,
gl_type,
error))
{
cogl_object_unref (upload_bmp);
return FALSE;
}
tex_rect->gl_format = gl_intformat;
tex_rect->internal_format = internal_format;
cogl_object_unref (upload_bmp);
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect),
internal_format, width, height);
return TRUE;
}
static gboolean
allocate_from_gl_foreign (CoglTextureRectangle *tex_rect,
CoglTextureLoader *loader,
CoglError **error)
{
CoglTexture *tex = COGL_TEXTURE (tex_rect);
CoglContext *ctx = tex->context;
CoglPixelFormat format = loader->src.gl_foreign.format;
GLint gl_compressed = GL_FALSE;
GLenum gl_int_format = 0;
if (!ctx->texture_driver->allows_foreign_gl_target (ctx,
GL_TEXTURE_RECTANGLE_ARB))
{
_cogl_set_error (error,
COGL_SYSTEM_ERROR,
COGL_SYSTEM_ERROR_UNSUPPORTED,
"Foreign GL_TEXTURE_RECTANGLE textures are not "
"supported by your system");
return FALSE;
}
/* Make sure binding succeeds */
_cogl_gl_util_clear_gl_errors (ctx);
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
loader->src.gl_foreign.gl_handle, TRUE);
if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
{
_cogl_set_error (error,
COGL_SYSTEM_ERROR,
COGL_SYSTEM_ERROR_UNSUPPORTED,
"Failed to bind foreign GL_TEXTURE_RECTANGLE texture");
return FALSE;
}
/* Obtain texture parameters */
#ifdef HAVE_COGL_GL
if (_cogl_has_private_feature
(ctx, COGL_PRIVATE_FEATURE_QUERY_TEXTURE_PARAMETERS))
{
GLint val;
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
GL_TEXTURE_COMPRESSED,
&gl_compressed) );
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
GL_TEXTURE_INTERNAL_FORMAT,
&val) );
gl_int_format = val;
/* If we can query GL for the actual pixel format then we'll ignore
the passed in format and use that. */
if (!ctx->driver_vtable->pixel_format_from_gl_internal (ctx,
gl_int_format,
&format))
{
_cogl_set_error (error,
COGL_SYSTEM_ERROR,
COGL_SYSTEM_ERROR_UNSUPPORTED,
"Unsupported internal format for foreign texture");
return FALSE;
}
}
else
#endif
{
/* Otherwise we'll assume we can derive the GL format from the
passed in format */
ctx->driver_vtable->pixel_format_to_gl (ctx,
format,
&gl_int_format,
NULL,
NULL);
}
/* Compressed texture images not supported */
if (gl_compressed == GL_TRUE)
{
_cogl_set_error (error,
COGL_SYSTEM_ERROR,
COGL_SYSTEM_ERROR_UNSUPPORTED,
"Compressed foreign textures aren't currently supported");
return FALSE;
}
/* Setup bitmap info */
tex_rect->is_foreign = TRUE;
tex_rect->gl_texture = loader->src.gl_foreign.gl_handle;
tex_rect->gl_format = gl_int_format;
/* Unknown filter */
tex_rect->gl_legacy_texobj_min_filter = GL_FALSE;
tex_rect->gl_legacy_texobj_mag_filter = GL_FALSE;
tex_rect->internal_format = format;
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect),
format,
loader->src.gl_foreign.width,
loader->src.gl_foreign.height);
return TRUE;
}
static gboolean
_cogl_texture_rectangle_allocate (CoglTexture *tex,
CoglError **error)
{
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
CoglTextureLoader *loader = tex->loader;
_COGL_RETURN_VAL_IF_FAIL (loader, FALSE);
switch (loader->src_type)
{
case COGL_TEXTURE_SOURCE_TYPE_SIZED:
return allocate_with_size (tex_rect, loader, error);
case COGL_TEXTURE_SOURCE_TYPE_BITMAP:
return allocate_from_bitmap (tex_rect, loader, error);
case COGL_TEXTURE_SOURCE_TYPE_GL_FOREIGN:
return allocate_from_gl_foreign (tex_rect, loader, error);
default:
break;
}
g_return_val_if_reached (FALSE);
}
CoglTextureRectangle *
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp)
{
CoglTextureLoader *loader;
_COGL_RETURN_VAL_IF_FAIL (cogl_is_bitmap (bmp), NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_BITMAP;
loader->src.bitmap.bitmap = cogl_object_ref (bmp);
loader->src.bitmap.can_convert_in_place = FALSE; /* TODO add api for this */
return _cogl_texture_rectangle_create_base (_cogl_bitmap_get_context (bmp),
cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp),
cogl_bitmap_get_format (bmp),
loader);
}
CoglTextureRectangle *
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle,
int width,
int height,
CoglPixelFormat format)
{
CoglTextureLoader *loader;
/* NOTE: width, height and internal format are not queriable in
* GLES, hence such a function prototype. Also in the case of full
* opengl the user may be creating a Cogl texture for a
* texture_from_pixmap object where glTexImage2D may not have been
* called and the texture_from_pixmap spec doesn't clarify that it
* is reliable to query back the size from OpenGL.
*/
/* Assert that it is a valid GL texture object */
_COGL_RETURN_VAL_IF_FAIL (ctx->glIsTexture (gl_handle), NULL);
/* Validate width and height */
_COGL_RETURN_VAL_IF_FAIL (width > 0 && height > 0, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_GL_FOREIGN;
loader->src.gl_foreign.gl_handle = gl_handle;
loader->src.gl_foreign.width = width;
loader->src.gl_foreign.height = height;
loader->src.gl_foreign.format = format;
return _cogl_texture_rectangle_create_base (ctx, width, height,
format, loader);
}
static int
_cogl_texture_rectangle_get_max_waste (CoglTexture *tex)
{
return -1;
}
static gboolean
_cogl_texture_rectangle_is_sliced (CoglTexture *tex)
{
return FALSE;
}
static gboolean
_cogl_texture_rectangle_can_hardware_repeat (CoglTexture *tex)
{
return FALSE;
}
static void
_cogl_texture_rectangle_transform_coords_to_gl (CoglTexture *tex,
float *s,
float *t)
{
*s *= tex->width;
*t *= tex->height;
}
static CoglTransformResult
_cogl_texture_rectangle_transform_quad_coords_to_gl (CoglTexture *tex,
float *coords)
{
gboolean need_repeat = FALSE;
int i;
for (i = 0; i < 4; i++)
{
if (coords[i] < 0.0f || coords[i] > 1.0f)
need_repeat = TRUE;
coords[i] *= (i & 1) ? tex->height : tex->width;
}
return (need_repeat ? COGL_TRANSFORM_SOFTWARE_REPEAT
: COGL_TRANSFORM_NO_REPEAT);
}
static gboolean
_cogl_texture_rectangle_get_gl_texture (CoglTexture *tex,
GLuint *out_gl_handle,
GLenum *out_gl_target)
{
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
if (out_gl_handle)
*out_gl_handle = tex_rect->gl_texture;
if (out_gl_target)
*out_gl_target = GL_TEXTURE_RECTANGLE_ARB;
return TRUE;
}
static void
_cogl_texture_rectangle_gl_flush_legacy_texobj_filters (CoglTexture *tex,
GLenum min_filter,
GLenum mag_filter)
{
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
CoglContext *ctx = tex->context;
if (min_filter == tex_rect->gl_legacy_texobj_min_filter
&& mag_filter == tex_rect->gl_legacy_texobj_mag_filter)
return;
/* Rectangle textures don't support mipmapping */
g_assert (min_filter == GL_LINEAR || min_filter == GL_NEAREST);
/* Store new values */
tex_rect->gl_legacy_texobj_min_filter = min_filter;
tex_rect->gl_legacy_texobj_mag_filter = mag_filter;
/* Apply new filters to the texture */
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign);
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
mag_filter) );
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
min_filter) );
}
static void
_cogl_texture_rectangle_pre_paint (CoglTexture *tex,
CoglTexturePrePaintFlags flags)
{
/* Rectangle textures don't support mipmaps */
g_assert ((flags & COGL_TEXTURE_NEEDS_MIPMAP) == 0);
}
static void
_cogl_texture_rectangle_ensure_non_quad_rendering (CoglTexture *tex)
{
/* Nothing needs to be done */
}
static gboolean
_cogl_texture_rectangle_set_region (CoglTexture *tex,
int src_x,
int src_y,
int dst_x,
int dst_y,
int dst_width,
int dst_height,
int level,
CoglBitmap *bmp,
CoglError **error)
{
CoglBitmap *upload_bmp;
GLenum gl_format;
GLenum gl_type;
CoglContext *ctx = tex->context;
gboolean status;
upload_bmp =
_cogl_bitmap_convert_for_upload (bmp,
_cogl_texture_get_format (tex),
FALSE, /* can't convert in place */
error);
if (upload_bmp == NULL)
return FALSE;
ctx->driver_vtable->pixel_format_to_gl (ctx,
cogl_bitmap_get_format (upload_bmp),
NULL, /* internal format */
&gl_format,
&gl_type);
/* Send data to GL */
status =
ctx->texture_driver->upload_subregion_to_gl (ctx,
tex,
FALSE,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
level,
upload_bmp,
gl_format,
gl_type,
error);
cogl_object_unref (upload_bmp);
return status;
}
static gboolean
_cogl_texture_rectangle_get_data (CoglTexture *tex,
CoglPixelFormat format,
int rowstride,
uint8_t *data)
{
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
CoglContext *ctx = tex->context;
int bpp;
GLenum gl_format;
GLenum gl_type;
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
ctx->driver_vtable->pixel_format_to_gl (ctx,
format,
NULL, /* internal format */
&gl_format,
&gl_type);
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
rowstride,
tex->width,
bpp);
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign);
return ctx->texture_driver->gl_get_tex_image (ctx,
GL_TEXTURE_RECTANGLE_ARB,
gl_format,
gl_type,
data);
}
static CoglPixelFormat
_cogl_texture_rectangle_get_format (CoglTexture *tex)
{
return COGL_TEXTURE_RECTANGLE (tex)->internal_format;
}
static GLenum
_cogl_texture_rectangle_get_gl_format (CoglTexture *tex)
{
return COGL_TEXTURE_RECTANGLE (tex)->gl_format;
}
static gboolean
_cogl_texture_rectangle_is_foreign (CoglTexture *tex)
{
return COGL_TEXTURE_RECTANGLE (tex)->is_foreign;
}
static CoglTextureType
_cogl_texture_rectangle_get_type (CoglTexture *tex)
{
return COGL_TEXTURE_TYPE_RECTANGLE;
}
static const CoglTextureVtable
cogl_texture_rectangle_vtable =
{
TRUE, /* primitive */
_cogl_texture_rectangle_allocate,
_cogl_texture_rectangle_set_region,
NULL, /* is_get_data_supported */
_cogl_texture_rectangle_get_data,
NULL, /* foreach_sub_texture_in_region */
_cogl_texture_rectangle_get_max_waste,
_cogl_texture_rectangle_is_sliced,
_cogl_texture_rectangle_can_hardware_repeat,
_cogl_texture_rectangle_transform_coords_to_gl,
_cogl_texture_rectangle_transform_quad_coords_to_gl,
_cogl_texture_rectangle_get_gl_texture,
_cogl_texture_rectangle_gl_flush_legacy_texobj_filters,
_cogl_texture_rectangle_pre_paint,
_cogl_texture_rectangle_ensure_non_quad_rendering,
_cogl_texture_rectangle_gl_flush_legacy_texobj_wrap_modes,
_cogl_texture_rectangle_get_format,
_cogl_texture_rectangle_get_gl_format,
_cogl_texture_rectangle_get_type,
_cogl_texture_rectangle_is_foreign,
_cogl_texture_rectangle_set_auto_mipmap
};

View File

@ -1,216 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2011 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 <robert@linux.intel.com>
*/
#ifndef __COGL_TEXURE_RECTANGLE_H
#define __COGL_TEXURE_RECTANGLE_H
#include "cogl-context.h"
G_BEGIN_DECLS
/**
* SECTION:cogl-texture-rectangle
* @short_description: Functions for creating and manipulating rectangle
* textures for use with non-normalized coordinates.
*
* These functions allow low-level "rectangle" textures to be allocated.
* These textures are never constrained to power-of-two sizes but they
* also don't support having a mipmap and can only be wrapped with
* %COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE.
*
* The most notable difference between rectangle textures and 2D
* textures is that rectangle textures are sampled using un-normalized
* texture coordinates, so instead of using coordinates (0,0) and
* (1,1) to map to the top-left and bottom right corners of the
* texture you would instead use (0,0) and (width,height).
*
* The use of non-normalized coordinates can be particularly
* convenient when writing glsl shaders that use a texture as a lookup
* table since you don't need to upload separate uniforms to map
* normalized coordinates to texels.
*
* If you want to sample from a rectangle texture from GLSL you should
* use the sampler2DRect sampler type.
*
* Applications wanting to use #CoglTextureRectangle should first check
* for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature using
* cogl_has_feature().
*/
typedef struct _CoglTextureRectangle CoglTextureRectangle;
#define COGL_TEXTURE_RECTANGLE(X) ((CoglTextureRectangle *)X)
/**
* cogl_texture_rectangle_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
GType cogl_texture_rectangle_get_gtype (void);
/**
* cogl_is_texture_rectangle:
* @object: A #CoglObject
*
* Gets whether the given object references an existing
* #CoglTextureRectangle object.
*
* Return value: %TRUE if the object references a
* #CoglTextureRectangle, %FALSE otherwise.
*/
gboolean
cogl_is_texture_rectangle (void *object);
/**
* cogl_texture_rectangle_new_with_size:
* @ctx: A #CoglContext pointer
* @width: The texture width to allocate
* @height: The texture height to allocate
*
* Creates a new #CoglTextureRectangle texture with a given @width,
* and @height. This texture is a low-level texture that the GPU can
* sample from directly unlike high-level textures such as
* #CoglTexture2DSliced and #CoglAtlasTexture.
*
* <note>Unlike for #CoglTexture2D textures, coordinates for
* #CoglTextureRectangle textures should not be normalized. So instead
* of using the coordinate (1, 1) to sample the bottom right corner of
* a rectangle texture you would use (@width, @height) where @width
* and @height are the width and height of the texture.</note>
*
* <note>If you want to sample from a rectangle texture from GLSL you
* should use the sampler2DRect sampler type.</note>
*
* <note>Applications wanting to use #CoglTextureRectangle should
* first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
* using cogl_has_feature().</note>
*
* The storage for the texture is not allocated before this function
* returns. You can call cogl_texture_allocate() to explicitly
* allocate the underlying storage or preferably let Cogl
* automatically allocate storage lazily when it may know more about
* how the texture is going to be used and can optimize how it is
* allocated.
*
* Returns value: (transfer full): A pointer to a new #CoglTextureRectangle
* object with no storage allocated yet.
*
* Since: 1.10
* Stability: unstable
*/
CoglTextureRectangle *
cogl_texture_rectangle_new_with_size (CoglContext *ctx,
int width,
int height);
/**
* cogl_texture_rectangle_new_from_bitmap:
* @bitmap: A #CoglBitmap
*
* Allocates a new #CoglTextureRectangle texture which will be
* initialized with the pixel data from @bitmap. This texture is a
* low-level texture that the GPU can sample from directly unlike
* high-level textures such as #CoglTexture2DSliced and
* #CoglAtlasTexture.
*
* <note>Unlike for #CoglTexture2D textures, coordinates for
* #CoglTextureRectangle textures should not be normalized. So instead
* of using the coordinate (1, 1) to sample the bottom right corner of
* a rectangle texture you would use (@width, @height) where @width
* and @height are the width and height of the texture.</note>
*
* <note>If you want to sample from a rectangle texture from GLSL you
* should use the sampler2DRect sampler type.</note>
*
* <note>Applications wanting to use #CoglTextureRectangle should
* first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
* using cogl_has_feature().</note>
*
* The storage for the texture is not allocated before this function
* returns. You can call cogl_texture_allocate() to explicitly
* allocate the underlying storage or preferably let Cogl
* automatically allocate storage lazily when it may know more about
* how the texture is going to be used and can optimize how it is
* allocated.
*
* Return value: (transfer full): A pointer to a new
* #CoglTextureRectangle texture.
* Since: 2.0
* Stability: unstable
*/
CoglTextureRectangle *
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap);
/**
* cogl_texture_rectangle_new_from_foreign:
* @ctx: A #CoglContext
* @gl_handle: A GL handle for a GL_TEXTURE_RECTANGLE texture object
* @width: Width of the foreign GL texture
* @height: Height of the foreign GL texture
* @format: The format of the texture
*
* Wraps an existing GL_TEXTURE_RECTANGLE texture object as a
* #CoglTextureRectangle. This can be used for integrating Cogl with
* software using OpenGL directly.
*
* <note>Unlike for #CoglTexture2D textures, coordinates for
* #CoglTextureRectangle textures should not be normalized. So instead
* of using the coordinate (1, 1) to sample the bottom right corner of
* a rectangle texture you would use (@width, @height) where @width
* and @height are the width and height of the texture.</note>
*
* <note>The results are undefined for passing an invalid @gl_handle
* or if @width or @height don't have the correct texture
* geometry.</note>
*
* <note>If you want to sample from a rectangle texture from GLSL you
* should use the sampler2DRect sampler type.</note>
*
* <note>Applications wanting to use #CoglTextureRectangle should
* first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
* using cogl_has_feature().</note>
*
* The texture is still configurable until it has been allocated so
* for example you can declare whether the texture is premultiplied
* with cogl_texture_set_premultiplied().
*
* Return value: (transfer full): A new #CoglTextureRectangle texture
*/
CoglTextureRectangle *
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle,
int width,
int height,
CoglPixelFormat format);
G_END_DECLS
#endif /* __COGL_TEXURE_RECTANGLE_H */

View File

@ -47,7 +47,6 @@
#include "cogl-texture-2d-sliced-private.h"
#include "cogl-texture-2d-private.h"
#include "cogl-texture-2d-gl.h"
#include "cogl-texture-rectangle-private.h"
#include "cogl-sub-texture-private.h"
#include "cogl-atlas-texture-private.h"
#include "cogl-pipeline.h"

View File

@ -110,7 +110,6 @@ typedef enum
/**
* CoglTextureType:
* @COGL_TEXTURE_TYPE_2D: A #CoglTexture2D
* @COGL_TEXTURE_TYPE_RECTANGLE: A #CoglTextureRectangle
*
* Constants representing the underlying hardware texture type of a
* #CoglTexture.
@ -121,7 +120,6 @@ typedef enum
typedef enum
{
COGL_TEXTURE_TYPE_2D,
COGL_TEXTURE_TYPE_RECTANGLE
} CoglTextureType;
uint32_t cogl_texture_error_quark (void);

View File

@ -105,7 +105,6 @@
#include <cogl/cogl-quaternion.h>
#include <cogl/cogl-texture-2d.h>
#include <cogl/cogl-texture-2d-gl.h>
#include <cogl/cogl-texture-rectangle.h>
#include <cogl/cogl-texture-2d-sliced.h>
#include <cogl/cogl-sub-texture.h>
#include <cogl/cogl-atlas-texture.h>

View File

@ -48,7 +48,6 @@
#include "cogl-bitmap-private.h"
#include "cogl-atlas-texture-private.h"
#include "cogl-error-private.h"
#include "cogl-texture-rectangle.h"
#include "cogl-sub-texture.h"
#include "cogl-texture-2d-gl.h"

View File

@ -764,15 +764,7 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data)
GLenum gl_target;
if (texture == NULL)
switch (_cogl_pipeline_layer_get_texture_type (layer))
{
case COGL_TEXTURE_TYPE_2D:
texture = COGL_TEXTURE (ctx->default_gl_texture_2d_tex);
break;
case COGL_TEXTURE_TYPE_RECTANGLE:
texture = COGL_TEXTURE (ctx->default_gl_texture_rect_tex);
break;
}
cogl_texture_get_gl_texture (texture,
&gl_texture,

View File

@ -148,11 +148,6 @@ _cogl_gl_util_get_texture_target_string (CoglTextureType texture_type,
tex_coord_swizzle = "st";
break;
case COGL_TEXTURE_TYPE_RECTANGLE:
target_string = "2DRect";
tex_coord_swizzle = "st";
break;
default:
target_string = "Unknown";
tex_coord_swizzle = NULL;

View File

@ -120,7 +120,6 @@ cogl_nonintrospected_headers = [
'cogl-matrix-stack.h',
'cogl-poll.h',
'cogl-texture-2d-gl.h',
'cogl-texture-rectangle.h',
'cogl-sub-texture.h',
'cogl-atlas-texture.h',
'cogl-meta-texture.h',
@ -311,8 +310,6 @@ cogl_sources = [
'cogl-texture.c',
'cogl-texture-2d.c',
'cogl-texture-2d-sliced.c',
'cogl-texture-rectangle-private.h',
'cogl-texture-rectangle.c',
'cogl-rectangle-map.h',
'cogl-rectangle-map.c',
'cogl-atlas.h',

View File

@ -44,7 +44,6 @@
#include "cogl-texture-driver.h"
#include "cogl-texture-2d-private.h"
#include "cogl-texture-2d-sliced.h"
#include "cogl-texture-rectangle-private.h"
#include "cogl-context-private.h"
#include "cogl-display-private.h"
#include "cogl-renderer-private.h"
@ -871,33 +870,6 @@ _cogl_texture_pixmap_x11_get_data (CoglTexture *tex,
return cogl_texture_get_data (child_tex, format, rowstride, data);
}
typedef struct _NormalizeCoordsWrapperData
{
int width;
int height;
CoglMetaTextureCallback callback;
void *user_data;
} NormalizeCoordsWrapperData;
static void
normalize_coords_wrapper_cb (CoglTexture *child_texture,
const float *child_texture_coords,
const float *meta_coords,
void *user_data)
{
NormalizeCoordsWrapperData *data = user_data;
float normalized_coords[4];
normalized_coords[0] = meta_coords[0] / data->width;
normalized_coords[1] = meta_coords[1] / data->height;
normalized_coords[2] = meta_coords[2] / data->width;
normalized_coords[3] = meta_coords[3] / data->height;
data->callback (child_texture,
child_texture_coords, normalized_coords,
data->user_data);
}
static void
_cogl_texture_pixmap_x11_foreach_sub_texture_in_region
(CoglTexture *tex,
@ -912,38 +884,6 @@ _cogl_texture_pixmap_x11_foreach_sub_texture_in_region
CoglTexture *child_tex = _cogl_texture_pixmap_x11_get_texture (tex_pixmap);
/* Forward on to the child texture */
/* tfp textures may be implemented in terms of a
* CoglTextureRectangle texture which uses un-normalized texture
* coordinates but we want to consistently deal with normalized
* texture coordinates with CoglTexturePixmapX11... */
if (cogl_is_texture_rectangle (child_tex))
{
NormalizeCoordsWrapperData data;
int width = tex->width;
int height = tex->height;
virtual_tx_1 *= width;
virtual_ty_1 *= height;
virtual_tx_2 *= width;
virtual_ty_2 *= height;
data.width = width;
data.height = height;
data.callback = callback;
data.user_data = user_data;
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (child_tex),
virtual_tx_1,
virtual_ty_1,
virtual_tx_2,
virtual_ty_2,
COGL_PIPELINE_WRAP_MODE_REPEAT,
COGL_PIPELINE_WRAP_MODE_REPEAT,
normalize_coords_wrapper_cb,
&data);
}
else
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (child_tex),
virtual_tx_1,
virtual_ty_1,

View File

@ -44,7 +44,6 @@
#include "cogl-glx-display-private.h"
#include "cogl-private.h"
#include "cogl-texture-2d-private.h"
#include "cogl-texture-rectangle-private.h"
#include "cogl-frame-info-private.h"
#include "cogl-framebuffer-private.h"
#include "cogl-onscreen-private.h"