[cogl/wip/lazy-texture-allocate: 4/13] framebuffer: defer calculating level size until allocation
- From: Robert Bragg <rbragg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/lazy-texture-allocate: 4/13] framebuffer: defer calculating level size until allocation
- Date: Mon, 2 Dec 2013 15:27:49 +0000 (UTC)
commit 4e61f4e1865e258c4fa5ed8a54decfb919b51521
Author: Robert Bragg <robert linux intel com>
Date: Thu Jun 27 04:24:34 2013 +0100
framebuffer: defer calculating level size until allocation
The plan is to defer more of the work for creating a texture until
allocation time, but that means we won't be able to always assume
we can query the size of a texture when creating an offscreen
framebuffer from a texture (consider for example using
_texture_new_from_file() where the size isn't known until the file has
been loaded). This defers needing to know the size of the texture
underlying an offscreen framebuffer until calling
cogl_framebuffer_allocate().
cogl/cogl-framebuffer-private.h | 2 -
cogl/cogl-framebuffer.c | 28 ++++++++++----------
cogl/cogl-gles2-context.c | 13 ++++++++-
cogl/driver/gl/cogl-framebuffer-gl.c | 44 +++++++++++++++++++++------------
4 files changed, 53 insertions(+), 34 deletions(-)
---
diff --git a/cogl/cogl-framebuffer-private.h b/cogl/cogl-framebuffer-private.h
index 51c91c5..7ee113c 100644
--- a/cogl/cogl-framebuffer-private.h
+++ b/cogl/cogl-framebuffer-private.h
@@ -205,8 +205,6 @@ struct _CoglOffscreen
CoglTexture *texture;
int texture_level;
- int texture_level_width;
- int texture_level_height;
CoglTexture *depth_texture;
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index ef1327a..2f13701 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -607,34 +607,27 @@ _cogl_offscreen_new_with_texture_full (CoglTexture *texture,
CoglContext *ctx = texture->context;
CoglOffscreen *offscreen;
CoglFramebuffer *fb;
- int level_width;
- int level_height;
CoglOffscreen *ret;
_COGL_RETURN_VAL_IF_FAIL (cogl_is_texture (texture), NULL);
- _COGL_RETURN_VAL_IF_FAIL (level < _cogl_texture_get_n_levels (texture),
- NULL);
-
- _cogl_texture_get_level_size (texture,
- level,
- &level_width,
- &level_height,
- NULL);
offscreen = g_new0 (CoglOffscreen, 1);
offscreen->texture = cogl_object_ref (texture);
offscreen->texture_level = level;
- offscreen->texture_level_width = level_width;
- offscreen->texture_level_height = level_height;
offscreen->create_flags = create_flags;
fb = COGL_FRAMEBUFFER (offscreen);
+ /* NB: we can't assume we can query the texture's width yet, since
+ * it might not have been allocated yet and for example if the
+ * texture is being loaded from a file then the file might not
+ * have been read yet. */
+
_cogl_framebuffer_init (fb,
ctx,
COGL_FRAMEBUFFER_TYPE_OFFSCREEN,
- level_width,
- level_height);
+ -1, /* unknown width, until allocation */
+ -1); /* unknown height until allocation */
ret = _cogl_offscreen_object_new (offscreen);
@@ -727,6 +720,13 @@ cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
return FALSE;
}
+ /* Now that the texture has been allocated we can determine a
+ * size for the framebuffer... */
+ framebuffer->width = cogl_texture_get_width (offscreen->texture);
+ framebuffer->height = cogl_texture_get_height (offscreen->texture);
+ framebuffer->viewport_width = framebuffer->width;
+ framebuffer->viewport_height = framebuffer->height;
+
/* Forward the texture format as the internal format of the
* framebuffer */
framebuffer->internal_format =
diff --git a/cogl/cogl-gles2-context.c b/cogl/cogl-gles2-context.c
index 82ae324..ebe70e2 100644
--- a/cogl/cogl-gles2-context.c
+++ b/cogl/cogl-gles2-context.c
@@ -1688,6 +1688,8 @@ _cogl_gles2_offscreen_allocate (CoglOffscreen *offscreen,
const CoglWinsysVtable *winsys;
CoglError *internal_error = NULL;
CoglGLES2Offscreen *gles2_offscreen;
+ int level_width;
+ int level_height;
if (!framebuffer->allocated &&
!cogl_framebuffer_allocate (framebuffer, error))
@@ -1717,11 +1719,18 @@ _cogl_gles2_offscreen_allocate (CoglOffscreen *offscreen,
}
gles2_offscreen = g_slice_new0 (CoglGLES2Offscreen);
+
+ _cogl_texture_get_level_size (offscreen->texture,
+ offscreen->texture_level,
+ &level_width,
+ &level_height,
+ NULL);
+
if (!_cogl_framebuffer_try_creating_gl_fbo (gles2_context->context,
offscreen->texture,
offscreen->texture_level,
- offscreen->texture_level_width,
- offscreen->texture_level_height,
+ level_width,
+ level_height,
offscreen->depth_texture,
&COGL_FRAMEBUFFER (offscreen)->config,
offscreen->allocation_flags,
diff --git a/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/driver/gl/cogl-framebuffer-gl.c
index 77e72f3..2a2d7e9 100644
--- a/cogl/driver/gl/cogl-framebuffer-gl.c
+++ b/cogl/driver/gl/cogl-framebuffer-gl.c
@@ -735,14 +735,26 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
CoglContext *ctx = fb->context;
CoglOffscreenAllocateFlags flags;
CoglGLFramebuffer *gl_framebuffer = &offscreen->gl_framebuffer;
+ int level_width;
+ int level_height;
+
+ _COGL_RETURN_VAL_IF_FAIL (offscreen->texture_level <
+ _cogl_texture_get_n_levels (offscreen->texture),
+ NULL);
+
+ _cogl_texture_get_level_size (offscreen->texture,
+ offscreen->texture_level,
+ &level_width,
+ &level_height,
+ NULL);
if (fb->config.depth_texture_enabled &&
offscreen->depth_texture == NULL)
{
offscreen->depth_texture =
create_depth_texture (ctx,
- offscreen->texture_level_width,
- offscreen->texture_level_height);
+ level_width,
+ level_height);
if (!cogl_texture_allocate (offscreen->depth_texture, error))
{
@@ -771,8 +783,8 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
try_creating_fbo (ctx,
offscreen->texture,
offscreen->texture_level,
- offscreen->texture_level_width,
- offscreen->texture_level_height,
+ level_width,
+ level_height,
offscreen->depth_texture,
&fb->config,
flags = 0,
@@ -782,8 +794,8 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
try_creating_fbo (ctx,
offscreen->texture,
offscreen->texture_level,
- offscreen->texture_level_width,
- offscreen->texture_level_height,
+ level_width,
+ level_height,
offscreen->depth_texture,
&fb->config,
flags = ctx->last_offscreen_allocate_flags,
@@ -801,8 +813,8 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
try_creating_fbo (ctx,
offscreen->texture,
offscreen->texture_level,
- offscreen->texture_level_width,
- offscreen->texture_level_height,
+ level_width,
+ level_height,
offscreen->depth_texture,
&fb->config,
flags = COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH_STENCIL,
@@ -811,8 +823,8 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
try_creating_fbo (ctx,
offscreen->texture,
offscreen->texture_level,
- offscreen->texture_level_width,
- offscreen->texture_level_height,
+ level_width,
+ level_height,
offscreen->depth_texture,
&fb->config,
flags = COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH |
@@ -822,8 +834,8 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
try_creating_fbo (ctx,
offscreen->texture,
offscreen->texture_level,
- offscreen->texture_level_width,
- offscreen->texture_level_height,
+ level_width,
+ level_height,
offscreen->depth_texture,
&fb->config,
flags = COGL_OFFSCREEN_ALLOCATE_FLAG_STENCIL,
@@ -832,8 +844,8 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
try_creating_fbo (ctx,
offscreen->texture,
offscreen->texture_level,
- offscreen->texture_level_width,
- offscreen->texture_level_height,
+ level_width,
+ level_height,
offscreen->depth_texture,
&fb->config,
flags = COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH,
@@ -842,8 +854,8 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
try_creating_fbo (ctx,
offscreen->texture,
offscreen->texture_level,
- offscreen->texture_level_width,
- offscreen->texture_level_height,
+ level_width,
+ level_height,
offscreen->depth_texture,
&fb->config,
flags = 0,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]