diff options
author | Neil Roberts <neil@linux.intel.com> | 2012-02-09 12:52:45 +0000 |
---|---|---|
committer | Neil Roberts <neil@linux.intel.com> | 2012-02-13 17:09:34 +0000 |
commit | b96e6900f5865684a01cff85b46de089b89d8448 (patch) | |
tree | 2a9c9a41cd33f453ed0cf816ac329e53d813c936 /cogl/cogl-context.c | |
parent | 8012eee31f01011d4b6572d924d7a979470c4afe (diff) | |
download | cogl-b96e6900f5865684a01cff85b46de089b89d8448.tar.gz |
cogl-pipeline-layer: Use CoglTextureType instead of GL target enum
Instead of storing the GLenum for the target of the last used texture
for a layer it now stores the CoglTextureType instead. The state name
has been renamed to 'texture type' instead of 'texture target'.
Previously the default pipeline layer would store 0 here to represent
that there is no texture. This has been changed to store
COGL_TEXTURE_TYPE_2D instead which means that all pipeline layers
always have a valid value for the texture type. Any places that were
previously fetching the texture from a layer to determine the target
(for example when generating shaders or when enabling a particular
texture target) now use the texture type instead. This means they will
work even for layers that don't have a texture.
This also changes it so that when binding a fallback texture instead
of always using a 2D texture it will now use the default texture
corresponding to the texture type of the layer. That way when the
generated shader tries to do a texture lookup for that type of texture
it will get a valid texture object. To make this work the patch adds a
default texture for 3D textures to the context and also makes the
default rectangle texture actually be a rectangle texture instead of
using a 2D texture.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Diffstat (limited to 'cogl/cogl-context.c')
-rw-r--r-- | cogl/cogl-context.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c index 21c10b78..e773006f 100644 --- a/cogl/cogl-context.c +++ b/cogl/cogl-context.c @@ -38,6 +38,9 @@ #include "cogl-renderer-private.h" #include "cogl-journal-private.h" #include "cogl-texture-private.h" +#include "cogl-texture-2d-private.h" +#include "cogl-texture-3d-private.h" +#include "cogl-texture-rectangle-private.h" #include "cogl-pipeline-private.h" #include "cogl-pipeline-opengl-private.h" #include "cogl-framebuffer-private.h" @@ -130,6 +133,7 @@ cogl_context_new (CoglDisplay *display, { CoglContext *context; GLubyte default_texture_data[] = { 0xff, 0xff, 0xff, 0x0 }; + CoglBitmap *default_texture_bitmap; const CoglWinsysVtable *winsys; int i; @@ -275,6 +279,7 @@ cogl_context_new (CoglDisplay *display, context->legacy_state_set = 0; context->default_gl_texture_2d_tex = NULL; + context->default_gl_texture_3d_tex = NULL; context->default_gl_texture_rect_tex = NULL; context->framebuffers = NULL; @@ -376,25 +381,36 @@ cogl_context_new (CoglDisplay *display, _cogl_matrix_stack_init_cache (&_context->builtin_flushed_projection); _cogl_matrix_stack_init_cache (&_context->builtin_flushed_modelview); + default_texture_bitmap = + _cogl_bitmap_new_from_data (default_texture_data, + COGL_PIXEL_FORMAT_RGBA_8888_PRE, + 1, 1, /* width/height */ + 4, /* rowstride */ + NULL, /* destroy function */ + NULL /* destroy function data */); + /* Create default textures used for fall backs */ context->default_gl_texture_2d_tex = - cogl_texture_new_from_data (1, /* width */ - 1, /* height */ - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */ - /* internal format */ - COGL_PIXEL_FORMAT_RGBA_8888_PRE, - 0, /* auto calc row stride */ - default_texture_data); + _cogl_texture_2d_new_from_bitmap (default_texture_bitmap, + COGL_TEXTURE_NONE, + /* internal format */ + COGL_PIXEL_FORMAT_RGBA_8888_PRE, + NULL); + /* If 3D or rectangle textures aren't supported then these should + just silently return NULL */ + context->default_gl_texture_3d_tex = + _cogl_texture_3d_new_from_bitmap (default_texture_bitmap, + 1, /* height */ + 1, /* depth */ + COGL_TEXTURE_NONE, + COGL_PIXEL_FORMAT_RGBA_8888_PRE, + NULL); context->default_gl_texture_rect_tex = - cogl_texture_new_from_data (1, /* width */ - 1, /* height */ - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */ - /* internal format */ - COGL_PIXEL_FORMAT_RGBA_8888_PRE, - 0, /* auto calc row stride */ - default_texture_data); + _cogl_texture_rectangle_new_from_bitmap (default_texture_bitmap, + COGL_TEXTURE_NONE, + COGL_PIXEL_FORMAT_RGBA_8888_PRE); + + cogl_object_unref (default_texture_bitmap); cogl_push_source (context->opaque_color_pipeline); _cogl_pipeline_flush_gl_state (context->opaque_color_pipeline, FALSE, 0); @@ -433,6 +449,8 @@ _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_3d_tex) + cogl_object_unref (context->default_gl_texture_3d_tex); if (context->default_gl_texture_rect_tex) cogl_object_unref (context->default_gl_texture_rect_tex); |