2 * Offscreen OpenGL abstraction layer
4 * Copyright (c) 2010 Intel Corporation
6 * Gordon Williams <gordon.williams@collabora.co.uk>
7 * Ian Molton <ian.molton@collabora.co.uk>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #ifndef GLOFFSCREEN_H_
29 #define GLOFFSCREEN_H_
31 /* Used to hold data for the OpenGL context */
33 typedef struct _GloContext GloContext;
34 /* Used to hold data for an offscreen surface. */
36 typedef struct _GloSurface GloSurface;
38 /* Format flags for glo_surface_create */
39 #define GLO_FF_ALPHA_MASK (0x0001)
40 #define GLO_FF_NOALPHA (0x0000)
41 #define GLO_FF_ALPHA (0x0001)
43 #define GLO_FF_BITS_MASK (0x00F0)
44 #define GLO_FF_BITS_16 (0x0020)
45 #define GLO_FF_BITS_24 (0x0030)
46 #define GLO_FF_BITS_32 (0x0040)
48 #define GLO_FF_DEPTH_MASK (0x0F00)
49 #define GLO_FF_DEPTH_16 (0x0100)
50 #define GLO_FF_DEPTH_24 (0x0200)
51 #define GLO_FF_DEPTH_32 (0x0300)
53 #define GLO_FF_STENCIL_MASK (0xF000)
54 #define GLO_FF_STENCIL_8 (0x1000)
56 /* The only currently supported format */
57 #define GLO_FF_DEFAULT (GLO_FF_BITS_24|GLO_FF_DEPTH_24)
59 /* Has gloffscreen been previously initialised? */
60 extern int glo_initialised(void);
62 /* Initialise gloffscreen */
63 extern int glo_init(void);
65 /* Uninitialise gloffscreen */
66 extern void glo_kill(void);
68 /* Like wglGetProcAddress/glxGetProcAddress */
69 extern void *glo_getprocaddress(const char *procName);
71 /* OS-independent glXQueryExtensionsString */
72 extern const char *glo_glXQueryExtensionsString(void);
74 /* Create a light-weight context just for creating surface */
75 extern GloContext *__glo_context_create(int formatFlags);
77 /* Create an OpenGL context for a certain pixel format. formatflags are from the GLO_ constants */
78 extern GloContext *glo_context_create(int formatFlags, GloContext *shareLists);
80 /* Destroy a previouslu created OpenGL context */
81 extern void glo_context_destroy(GloContext *context);
83 /* Update the context in surface and free previous light-weight context */
84 extern void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags);
86 /* Link the pixmap/pbuffer associated with surface as texture.
87 * ctxt is the target context for the texture operation
89 extern void glo_surface_as_texture(GloContext *ctxt, GloSurface *surface);
91 /* Create a surface with given width and height, */
92 extern GloSurface *glo_surface_create(int width, int height, GloContext *context);
94 /* Destroy the given surface */
95 extern void glo_surface_destroy(GloSurface *surface);
97 /* Make the given surface current */
98 extern int glo_surface_makecurrent(GloSurface *surface);
100 /* Get the contents of the given surface. Note that this is top-down, not
101 * bottom-up as glReadPixels would do. */
102 extern void glo_surface_getcontents(GloSurface *surface, int stride, int type, void *data);
104 /* Return the width and height of the given surface */
105 extern void glo_surface_get_size(GloSurface *surface, int *width, int *height);
107 /* Functions to decode the format flags */
108 extern int glo_flags_get_depth_bits(int formatFlags);
109 extern int glo_flags_get_stencil_bits(int formatFlags);
110 extern void glo_flags_get_rgba_bits(int formatFlags, int *rgba);
111 extern int glo_flags_get_bytes_per_pixel(int formatFlags);
112 extern void glo_flags_get_readpixel_type(int formatFlags, int *glFormat, int *glType);
113 /* Score how close the given format flags match. 0=great, >0 not so great */
114 extern int glo_flags_score(int formatFlagsExpected, int formatFlagsReal);
116 /* Create a set of format flags from a null-terminated list
117 * of GLX fbConfig flags. If assumeBooleans is set, items such
118 * as GLX_RGBA/GLX_DOUBLEBUFFER are treated as booleans, not key-value pairs
119 * (glXChooseVisual treats them as booleans, glXChooseFBConfig as key-value pairs)
121 extern int glo_flags_get_from_glx(const int *fbConfig, int assumeBooleans);
122 /* Use in place of glxGetConfig - returns information from flags based on a GLX enum */
123 extern int glo_get_glx_from_flags(int formatFlags, int glxEnum);
125 /* Get the width and height from attrib_list */
126 extern void glo_geometry_get_from_glx(const int* attrib_list, int* width, int* height);
128 /* In terms of speed, glReadPixels actually seems the best we can do.
129 * * On Windows PFB_DRAW_TO_BITMAP is software-only.
130 * * http://www.opengl.org/registry/specs/ARB/pixel_buffer_object.txt would be
131 * useful if we didn't want the data right away (as we could avoid flushing the
133 * * The internal data format seems to be GL_BGRA - and this is indeed faster.
134 * * Apple suggests using GL_UNSIGNED_INT_8_8_8_8_REV instead of
135 * GL_UNSIGNED_BYTE, but there don't appear to be any speed increase from
136 * doing this on Windows at least.
139 #endif /* GLOFFSCREEN_H_ */