2009-09-25 09:34:34 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007,2008,2009 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
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2009-09-25 09:34:34 -04:00
|
|
|
*/
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
#ifndef __COGL_FRAMEBUFFER_PRIVATE_H
|
|
|
|
#define __COGL_FRAMEBUFFER_PRIVATE_H
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-11-05 08:28:33 -04:00
|
|
|
#include "cogl-object-private.h"
|
2009-09-25 09:34:34 -04:00
|
|
|
#include "cogl-matrix-stack.h"
|
2011-03-02 12:45:25 -05:00
|
|
|
#include "cogl-clip-state-private.h"
|
2011-01-06 08:25:45 -05:00
|
|
|
#include "cogl-journal-private.h"
|
2011-10-13 16:31:04 -04:00
|
|
|
#include "cogl-winsys-private.h"
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-11-05 08:28:33 -04:00
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef COGL_HAS_GLX_SUPPORT
|
|
|
|
#include <GL/glx.h>
|
|
|
|
#include <GL/glxext.h>
|
|
|
|
#endif
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
typedef enum _CoglFramebufferType {
|
|
|
|
COGL_FRAMEBUFFER_TYPE_ONSCREEN,
|
|
|
|
COGL_FRAMEBUFFER_TYPE_OFFSCREEN
|
|
|
|
} CoglFramebufferType;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-08-22 18:55:57 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CoglSwapChain *swap_chain;
|
|
|
|
gboolean need_stencil;
|
2011-08-21 16:27:13 -04:00
|
|
|
int samples_per_pixel;
|
2011-08-22 18:55:57 -04:00
|
|
|
} CoglFramebufferConfig;
|
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
/* Flags to pass to _cogl_offscreen_new_to_texture_full */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL = 1
|
|
|
|
} CoglOffscreenFlags;
|
|
|
|
|
2010-07-07 09:41:54 -04:00
|
|
|
struct _CoglFramebuffer
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2010-07-07 09:41:54 -04:00
|
|
|
CoglObject _parent;
|
2010-11-05 08:28:33 -04:00
|
|
|
CoglContext *context;
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglFramebufferType type;
|
2011-08-22 18:55:57 -04:00
|
|
|
|
|
|
|
/* The user configuration before allocation... */
|
|
|
|
CoglFramebufferConfig config;
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
int width;
|
|
|
|
int height;
|
2010-11-17 12:57:17 -05:00
|
|
|
/* Format of the pixels in the framebuffer (including the expected
|
|
|
|
premult state) */
|
|
|
|
CoglPixelFormat format;
|
2010-11-05 08:28:33 -04:00
|
|
|
gboolean allocated;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
CoglMatrixStack *modelview_stack;
|
|
|
|
CoglMatrixStack *projection_stack;
|
2011-02-01 11:51:58 -05:00
|
|
|
float viewport_x;
|
|
|
|
float viewport_y;
|
|
|
|
float viewport_width;
|
|
|
|
float viewport_height;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-04-14 14:41:08 -04:00
|
|
|
CoglClipState clip_state;
|
2010-04-26 13:08:45 -04:00
|
|
|
|
|
|
|
gboolean dirty_bitmasks;
|
|
|
|
int red_bits;
|
|
|
|
int blue_bits;
|
|
|
|
int green_bits;
|
|
|
|
int alpha_bits;
|
2011-01-06 08:25:45 -05:00
|
|
|
|
2011-07-13 11:33:25 -04:00
|
|
|
gboolean dither_enabled;
|
2011-07-10 21:27:54 -04:00
|
|
|
CoglColorMask color_mask;
|
2011-07-13 11:33:25 -04:00
|
|
|
|
2011-10-08 10:47:42 -04:00
|
|
|
int samples_per_pixel;
|
|
|
|
|
2011-01-06 08:25:45 -05:00
|
|
|
/* We journal the textured rectangles we want to submit to OpenGL so
|
|
|
|
* we have an oppertunity to batch them together into less draw
|
|
|
|
* calls. */
|
|
|
|
CoglJournal *journal;
|
|
|
|
|
|
|
|
/* The scene of a given framebuffer may depend on images in other
|
|
|
|
* framebuffers... */
|
|
|
|
GList *deps;
|
2011-01-12 17:12:41 -05:00
|
|
|
|
|
|
|
/* As part of an optimization for reading-back single pixels from a
|
|
|
|
* framebuffer in some simple cases where the geometry is still
|
|
|
|
* available in the journal we need to track the bounds of the last
|
|
|
|
* region cleared, its color and we need to track when something
|
|
|
|
* does in fact draw to that region so it is no longer clear.
|
|
|
|
*/
|
|
|
|
float clear_color_red;
|
|
|
|
float clear_color_green;
|
|
|
|
float clear_color_blue;
|
|
|
|
float clear_color_alpha;
|
|
|
|
int clear_clip_x0;
|
|
|
|
int clear_clip_y0;
|
|
|
|
int clear_clip_x1;
|
|
|
|
int clear_clip_y1;
|
|
|
|
gboolean clear_clip_dirty;
|
2010-07-07 09:41:54 -04:00
|
|
|
};
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
typedef struct _CoglOffscreen
|
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglFramebuffer _parent;
|
2009-09-25 09:34:34 -04:00
|
|
|
GLuint fbo_handle;
|
2009-11-30 15:04:41 -05:00
|
|
|
GSList *renderbuffers;
|
2011-08-22 18:55:57 -04:00
|
|
|
|
|
|
|
CoglTexture *texture;
|
2011-08-23 08:55:12 -04:00
|
|
|
int texture_level;
|
|
|
|
int texture_level_width;
|
|
|
|
int texture_level_height;
|
|
|
|
|
|
|
|
/* FIXME: _cogl_offscreen_new_to_texture_full should be made to use
|
|
|
|
* fb->config to configure if we want a depth or stencil buffer so
|
|
|
|
* we can get rid of these flags */
|
|
|
|
CoglOffscreenFlags create_flags;
|
2009-09-25 09:34:34 -04:00
|
|
|
} CoglOffscreen;
|
|
|
|
|
|
|
|
#define COGL_OFFSCREEN(X) ((CoglOffscreen *)(X))
|
|
|
|
|
|
|
|
void
|
2011-10-13 16:31:04 -04:00
|
|
|
_cogl_framebuffer_init (CoglFramebuffer *framebuffer,
|
|
|
|
CoglContext *ctx,
|
|
|
|
CoglFramebufferType type,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
int width,
|
|
|
|
int height);
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2011-10-13 16:31:04 -04:00
|
|
|
void _cogl_framebuffer_free (CoglFramebuffer *framebuffer);
|
|
|
|
|
|
|
|
const CoglWinsysVtable *
|
|
|
|
_cogl_framebuffer_get_winsys (CoglFramebuffer *framebuffer);
|
2011-02-22 13:25:29 -05:00
|
|
|
|
2011-01-05 10:30:04 -05:00
|
|
|
void
|
2011-08-03 12:06:10 -04:00
|
|
|
_cogl_framebuffer_clear_without_flush4f (CoglFramebuffer *framebuffer,
|
|
|
|
unsigned long buffers,
|
|
|
|
float red,
|
|
|
|
float green,
|
|
|
|
float blue,
|
|
|
|
float alpha);
|
2011-01-05 10:30:04 -05:00
|
|
|
|
2011-01-12 17:12:41 -05:00
|
|
|
void
|
|
|
|
_cogl_framebuffer_dirty (CoglFramebuffer *framebuffer);
|
|
|
|
|
2010-04-14 14:41:08 -04:00
|
|
|
CoglClipState *
|
2010-07-07 09:41:54 -04:00
|
|
|
_cogl_framebuffer_get_clip_state (CoglFramebuffer *framebuffer);
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2011-01-12 14:30:30 -05:00
|
|
|
/*
|
|
|
|
* _cogl_framebuffer_get_clip_stack:
|
|
|
|
* @framebuffer: A #CoglFramebuffer
|
|
|
|
*
|
|
|
|
* Gets a pointer to the current clip stack. This can be used to later
|
|
|
|
* return to the same clip stack state with
|
|
|
|
* _cogl_framebuffer_set_clip_stack(). A reference is not taken on the
|
|
|
|
* stack so if you want to keep it you should call
|
|
|
|
* _cogl_clip_stack_ref().
|
|
|
|
*
|
|
|
|
* Return value: a pointer to the @framebuffer clip stack.
|
|
|
|
*/
|
|
|
|
CoglClipStack *
|
|
|
|
_cogl_framebuffer_get_clip_stack (CoglFramebuffer *framebuffer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _cogl_framebuffer_set_clip_stack:
|
|
|
|
* @framebuffer: A #CoglFramebuffer
|
|
|
|
* @stack: a pointer to the replacement clip stack
|
|
|
|
*
|
|
|
|
* Replaces the @framebuffer clip stack with @stack.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_set_clip_stack (CoglFramebuffer *framebuffer,
|
|
|
|
CoglClipStack *stack);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *
|
2010-07-07 09:41:54 -04:00
|
|
|
_cogl_framebuffer_get_modelview_stack (CoglFramebuffer *framebuffer);
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *
|
2010-07-07 09:41:54 -04:00
|
|
|
_cogl_framebuffer_get_projection_stack (CoglFramebuffer *framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-01-06 08:25:45 -05:00
|
|
|
void
|
|
|
|
_cogl_framebuffer_add_dependency (CoglFramebuffer *framebuffer,
|
|
|
|
CoglFramebuffer *dependency);
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_remove_all_dependencies (CoglFramebuffer *framebuffer);
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_flush_journal (CoglFramebuffer *framebuffer);
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_flush_dependency_journals (CoglFramebuffer *framebuffer);
|
|
|
|
|
2011-01-12 17:12:41 -05:00
|
|
|
gboolean
|
|
|
|
_cogl_framebuffer_try_fast_read_pixel (CoglFramebuffer *framebuffer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
CoglReadPixelsFlags source,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
guint8 *pixel);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
typedef enum _CoglFramebufferFlushFlags
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
|
|
|
/* XXX: When using this, that imples you are going to manually load the
|
|
|
|
* modelview matrix (via glLoadMatrix). _cogl_matrix_stack_flush_to_gl wont
|
2009-11-26 14:06:35 -05:00
|
|
|
* be called for framebuffer->modelview_stack, and the modelview_stack will
|
2009-09-25 09:34:34 -04:00
|
|
|
* also be marked as dirty. */
|
2009-11-26 14:06:35 -05:00
|
|
|
COGL_FRAMEBUFFER_FLUSH_SKIP_MODELVIEW = 1L<<0,
|
2010-11-02 13:34:51 -04:00
|
|
|
/* Similarly this flag implies you are going to flush the clip state
|
|
|
|
yourself */
|
2010-11-05 08:28:33 -04:00
|
|
|
COGL_FRAMEBUFFER_FLUSH_SKIP_CLIP_STATE = 1L<<1,
|
|
|
|
/* When using this all that will be updated is the glBindFramebuffer
|
|
|
|
* state and corresponding winsys state to make the framebuffer
|
|
|
|
* current if it is a CoglOnscreen framebuffer. */
|
|
|
|
COGL_FRAMEBUFFER_FLUSH_BIND_ONLY = 1L<<2
|
2009-11-26 14:06:35 -05:00
|
|
|
} CoglFramebufferFlushFlags;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
void
|
2011-02-02 09:23:53 -05:00
|
|
|
_cogl_framebuffer_flush_state (CoglFramebuffer *draw_buffer,
|
|
|
|
CoglFramebuffer *read_buffer,
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglFramebufferFlushFlags flags);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-07-07 09:41:54 -04:00
|
|
|
CoglFramebuffer *
|
2011-03-10 16:33:31 -05:00
|
|
|
_cogl_get_read_framebuffer (void);
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
GSList *
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_create_framebuffer_stack (void);
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
void
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_free_framebuffer_stack (GSList *stack);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-11-11 10:28:44 -05:00
|
|
|
/*
|
|
|
|
* _cogl_offscreen_new_to_texture_full:
|
2011-08-24 16:30:34 -04:00
|
|
|
* @texture: A #CoglTexture pointer
|
2010-11-11 10:28:44 -05:00
|
|
|
* @create_flags: Flags specifying how to create the FBO
|
|
|
|
* @level: The mipmap level within the texture to target
|
|
|
|
*
|
|
|
|
* Creates a new offscreen buffer which will target the given
|
|
|
|
* texture. By default the buffer will have a depth and stencil
|
|
|
|
* buffer. This can be disabled by passing
|
|
|
|
* %COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL in @create_flags.
|
|
|
|
*
|
|
|
|
* Return value: the new CoglOffscreen object.
|
|
|
|
*/
|
|
|
|
CoglHandle
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_offscreen_new_to_texture_full (CoglTexture *texture,
|
2010-11-11 10:28:44 -05:00
|
|
|
CoglOffscreenFlags create_flags,
|
|
|
|
unsigned int level);
|
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
/*
|
|
|
|
* _cogl_push_framebuffers:
|
|
|
|
* @draw_buffer: A pointer to the buffer used for drawing
|
|
|
|
* @read_buffer: A pointer to the buffer used for reading back pixels
|
|
|
|
*
|
|
|
|
* Redirects drawing and reading to the specified framebuffers as in
|
|
|
|
* cogl_push_framebuffer() except that it allows the draw and read
|
|
|
|
* buffer to be different. The buffers are pushed as a pair so that
|
|
|
|
* they can later both be restored with a single call to
|
|
|
|
* cogl_pop_framebuffer().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_cogl_push_framebuffers (CoglFramebuffer *draw_buffer,
|
|
|
|
CoglFramebuffer *read_buffer);
|
|
|
|
|
2011-02-05 06:19:52 -05:00
|
|
|
/*
|
|
|
|
* _cogl_blit_framebuffer:
|
|
|
|
* @src_x: Source x position
|
|
|
|
* @src_y: Source y position
|
|
|
|
* @dst_x: Destination x position
|
|
|
|
* @dst_y: Destination y position
|
|
|
|
* @width: Width of region to copy
|
|
|
|
* @height: Height of region to copy
|
|
|
|
*
|
|
|
|
* This blits a region of the color buffer of the current draw buffer
|
|
|
|
* to the current read buffer. The draw and read buffers can be set up
|
|
|
|
* using _cogl_push_framebuffers(). This function should only be
|
2011-10-12 17:47:42 -04:00
|
|
|
* called if the COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT feature is
|
2011-02-05 06:19:52 -05:00
|
|
|
* advertised. The two buffers must both be offscreen and have the
|
|
|
|
* same format.
|
|
|
|
*
|
|
|
|
* Note that this function differs a lot from the glBlitFramebuffer
|
|
|
|
* function provided by the GL_EXT_framebuffer_blit extension. Notably
|
|
|
|
* it doesn't support having different sizes for the source and
|
|
|
|
* destination rectangle. This isn't supported by the corresponding
|
|
|
|
* GL_ANGLE_framebuffer_blit extension on GLES2.0 and it doesn't seem
|
|
|
|
* like a particularly useful feature. If the application wanted to
|
|
|
|
* scale the results it may make more sense to draw a primitive
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* We can only really support blitting between two offscreen buffers
|
|
|
|
* for this function on GLES2.0. This is because we effectively render
|
|
|
|
* upside down to offscreen buffers to maintain Cogl's representation
|
|
|
|
* of the texture coordinate system where 0,0 is the top left of the
|
|
|
|
* texture. If we were to blit from an offscreen to an onscreen buffer
|
|
|
|
* then we would need to mirror the blit along the x-axis but the GLES
|
|
|
|
* extension does not support this.
|
|
|
|
*
|
|
|
|
* The GL function is documented to be affected by the scissor. This
|
|
|
|
* function therefore ensure that an empty clip stack is flushed
|
|
|
|
* before performing the blit which means the scissor is effectively
|
|
|
|
* ignored.
|
|
|
|
*
|
|
|
|
* The function also doesn't support specifying the buffers to copy
|
|
|
|
* and instead only the color buffer is copied. When copying the depth
|
|
|
|
* or stencil buffers the extension on GLES2.0 only supports copying
|
|
|
|
* the full buffer which would be awkward to document with this
|
|
|
|
* API. If we wanted to support that feature it may be better to have
|
|
|
|
* a separate function to copy the entire buffer for a given mask.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_cogl_blit_framebuffer (unsigned int src_x,
|
|
|
|
unsigned int src_y,
|
|
|
|
unsigned int dst_x,
|
|
|
|
unsigned int dst_y,
|
|
|
|
unsigned int width,
|
|
|
|
unsigned int height);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
#endif /* __COGL_FRAMEBUFFER_PRIVATE_H */
|