framebuffer: make format internal

This removes cogl_framebuffer_get_color_format() since the actual
internal format isn't strictly controlled by us. CoglFramebuffer::format
has been renamed to ::internal_format to make it clearer that it only
really represents the premultiplication status.

The plan is to make most of the work involved in creating a texture
happen lazily when allocating so this patch also changes
_cogl_framebuffer_init() to not take a format argument anymore since we
won't know the format of offscreen framebuffers until the framebuffer is
allocated, after the corresponding texture has been allocated. In the
case of offscreen framebuffers we now update the framebuffer
internal_format during allocation.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 8cc9e1c8bd2fac8b2a95087249c23c952d5e379f)

Note: Since we can't break API compatibility on the 1.x branch this
actually keeps the cogl_framebuffer_get_color_format() api but moves it
into a new deprecated/cogl-framebuffer-deprecated.c file and it now
returns the newly name ::internal_format.
This commit is contained in:
Robert Bragg 2013-06-26 21:26:40 +01:00
parent 8f19d01815
commit 2e61318914
10 changed files with 105 additions and 33 deletions

View File

@ -76,6 +76,7 @@ cogl_deprecated_h = \
$(srcdir)/deprecated/cogl-shader.h \
$(srcdir)/deprecated/cogl-clutter.h \
$(srcdir)/deprecated/cogl-type-casts.h \
$(srcdir)/deprecated/cogl-framebuffer-deprecated.h \
$(NULL)
# public 1.x api headers
@ -401,6 +402,7 @@ cogl_sources_c = \
$(srcdir)/deprecated/cogl-shader-private.h \
$(srcdir)/deprecated/cogl-shader.c \
$(srcdir)/deprecated/cogl-clutter.c \
$(srcdir)/deprecated/cogl-framebuffer-deprecated.c \
$(NULL)
if USE_GLIB

View File

@ -130,7 +130,7 @@ struct _CoglFramebuffer
int height;
/* Format of the pixels in the framebuffer (including the expected
premult state) */
CoglPixelFormat format;
CoglPixelFormat internal_format;
CoglBool allocated;
CoglMatrixStack *modelview_stack;
@ -222,7 +222,6 @@ void
_cogl_framebuffer_init (CoglFramebuffer *framebuffer,
CoglContext *ctx,
CoglFramebufferType type,
CoglPixelFormat format,
int width,
int height);

View File

@ -97,7 +97,6 @@ void
_cogl_framebuffer_init (CoglFramebuffer *framebuffer,
CoglContext *ctx,
CoglFramebufferType type,
CoglPixelFormat format,
int width,
int height)
{
@ -106,7 +105,7 @@ _cogl_framebuffer_init (CoglFramebuffer *framebuffer,
framebuffer->type = type;
framebuffer->width = width;
framebuffer->height = height;
framebuffer->format = format;
framebuffer->internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
framebuffer->viewport_x = 0;
framebuffer->viewport_y = 0;
framebuffer->viewport_width = width;
@ -638,7 +637,6 @@ _cogl_offscreen_new_with_texture_full (CoglTexture *texture,
_cogl_framebuffer_init (fb,
ctx,
COGL_FRAMEBUFFER_TYPE_OFFSCREEN,
cogl_texture_get_format (texture),
level_width,
level_height);
@ -748,6 +746,11 @@ cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
if (!cogl_texture_allocate (offscreen->texture, error))
return FALSE;
/* Forward the texture format as the internal format of the
* framebuffer */
framebuffer->internal_format =
cogl_texture_get_format (offscreen->texture);
if (!ctx->driver_vtable->offscreen_allocate (offscreen, error))
return FALSE;
}
@ -1312,12 +1315,6 @@ cogl_framebuffer_set_dither_enabled (CoglFramebuffer *framebuffer,
COGL_FRAMEBUFFER_STATE_DITHER;
}
CoglPixelFormat
cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer)
{
return framebuffer->format;
}
void
cogl_framebuffer_set_depth_texture_enabled (CoglFramebuffer *framebuffer,
CoglBool enabled)
@ -1617,7 +1614,7 @@ _cogl_blit_framebuffer (CoglFramebuffer *src,
_COGL_RETURN_IF_FAIL (cogl_is_offscreen (src));
_COGL_RETURN_IF_FAIL (cogl_is_offscreen (dest));
/* The buffers must be the same format */
_COGL_RETURN_IF_FAIL (src->format == dest->format);
_COGL_RETURN_IF_FAIL (src->internal_format == dest->internal_format);
/* Make sure the current framebuffers are bound. We explicitly avoid
flushing the clip state so we can bind our own empty state */

View File

@ -828,21 +828,6 @@ void
cogl_framebuffer_set_color_mask (CoglFramebuffer *framebuffer,
CoglColorMask color_mask);
/**
* cogl_framebuffer_get_color_format:
* @framebuffer: A #CoglFramebuffer framebuffer
*
* Queries the common #CoglPixelFormat of all color buffers attached
* to this framebuffer. For an offscreen framebuffer created with
* cogl_offscreen_new_with_texture() this will correspond to the format
* of the texture.
*
* Since: 1.8
* Stability: unstable
*/
CoglPixelFormat
cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer);
/**
* cogl_framebuffer_set_depth_texture_enabled:
* @framebuffer: A #CoglFramebuffer

View File

@ -69,7 +69,6 @@ _cogl_onscreen_new (void)
_cogl_framebuffer_init (COGL_FRAMEBUFFER (onscreen),
ctx,
COGL_FRAMEBUFFER_TYPE_ONSCREEN,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
0x1eadbeef, /* width */
0x1eadbeef); /* height */
/* NB: make sure to pass positive width/height numbers here
@ -104,7 +103,6 @@ cogl_onscreen_new (CoglContext *ctx, int width, int height)
_cogl_framebuffer_init (COGL_FRAMEBUFFER (onscreen),
ctx,
COGL_FRAMEBUFFER_TYPE_ONSCREEN,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
width, /* width */
height); /* height */

View File

@ -79,6 +79,7 @@
#include <cogl/deprecated/cogl-fixed.h>
#include <cogl/deprecated/cogl-material-compat.h>
#include <cogl/deprecated/cogl-shader.h>
#include <cogl/deprecated/cogl-framebuffer-deprecated.h>
#endif
/* It would be good to move these casts up into 1.x only api if we can

View File

@ -0,0 +1,36 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2014 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*
*/
#include <config.h>
#include "cogl-types.h"
#include "cogl-framebuffer-private.h"
#include "cogl-framebuffer-deprecated.h"
CoglPixelFormat
cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer)
{
return framebuffer->internal_format;
}

View File

@ -0,0 +1,55 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2014 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*
*/
#ifndef __COGL_FRAMEBUFFER_DEPRECATED_H__
#define __COGL_FRAMEBUFFER_DEPRECATED_H__
#include <cogl/cogl-macros.h>
/* XXX: Since this api was marked unstable, maybe we can just
* remove this api if we can't find anyone is using it. */
/**
* cogl_framebuffer_get_color_format:
* @framebuffer: A #CoglFramebuffer framebuffer
*
* Queries the common #CoglPixelFormat of all color buffers attached
* to this framebuffer. For an offscreen framebuffer created with
* cogl_offscreen_new_with_texture() this will correspond to the format
* of the texture.
*
* This API is deprecated because it is missleading to report a
* #CoglPixelFormat for the internal format of the @framebuffer since
* #CoglPixelFormat is such a precise format description and it's
* only the set of components and the premultiplied alpha status
* that is really known.
*
* Since: 1.8
* Stability: unstable
* Deprecated 1.18: Removed since it is misleading
*/
COGL_DEPRECATED_IN_1_18
CoglPixelFormat
cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer);
#endif /* __COGL_FRAMEBUFFER_DEPRECATED_H__ */

View File

@ -1004,7 +1004,7 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
* stored in the red component */
if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_ALPHA_TEXTURES) &&
framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN &&
framebuffer->format == COGL_PIXEL_FORMAT_A_8)
framebuffer->internal_format == COGL_PIXEL_FORMAT_A_8)
{
framebuffer->bits.alpha = framebuffer->bits.red;
framebuffer->bits.red = 0;
@ -1375,7 +1375,7 @@ _cogl_framebuffer_gl_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (read_format))
read_format = ((read_format & ~COGL_PREMULT_BIT) |
(framebuffer->format & COGL_PREMULT_BIT));
(framebuffer->internal_format & COGL_PREMULT_BIT));
tmp_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
width, height,
@ -1429,7 +1429,7 @@ _cogl_framebuffer_gl_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
* converted to the right format below */
if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (format))
bmp_format = ((format & ~COGL_PREMULT_BIT) |
(framebuffer->format & COGL_PREMULT_BIT));
(framebuffer->internal_format & COGL_PREMULT_BIT));
else
bmp_format = format;

View File

@ -521,7 +521,6 @@ cogl_framebuffer_get_viewport_y
cogl_framebuffer_get_viewport_width
cogl_framebuffer_get_viewport_height
cogl_framebuffer_get_viewport4fv
cogl_framebuffer_get_color_format
cogl_framebuffer_get_red_bits
cogl_framebuffer_get_green_bits
cogl_framebuffer_get_blue_bits