Tizen 2.1 base
[sdk/emulator/qemu.git] / tizen / src / hw / gloffscreen.h
1 /*
2  *  Offscreen OpenGL abstraction layer
3  *
4  *  Copyright (c) 2010 Intel Corporation
5  *  Written by: 
6  *    Gordon Williams <gordon.williams@collabora.co.uk>
7  *    Ian Molton <ian.molton@collabora.co.uk>
8  *
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:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
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
25  * THE SOFTWARE.
26  */
27
28 #ifndef GLOFFSCREEN_H_
29 #define GLOFFSCREEN_H_
30
31 /* Used to hold data for the OpenGL context */
32 struct _GloContext;
33 typedef struct _GloContext GloContext;
34 /* Used to hold data for an offscreen surface. */
35 struct _GloSurface;
36 typedef struct _GloSurface GloSurface;
37
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)
42
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)
47
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)
52
53 #define GLO_FF_STENCIL_MASK   (0xF000)
54 #define GLO_FF_STENCIL_8      (0x1000)
55
56 /* The only currently supported format */
57 #define GLO_FF_DEFAULT     (GLO_FF_BITS_24|GLO_FF_DEPTH_24)
58
59 /* Has gloffscreen been previously initialised? */
60 extern int glo_initialised(void);
61
62 /* Initialise gloffscreen */
63 extern int glo_init(void);
64
65 /* Uninitialise gloffscreen */
66 extern void glo_kill(void);
67
68 /* Like wglGetProcAddress/glxGetProcAddress */
69 extern void *glo_getprocaddress(const char *procName);
70
71 /* OS-independent glXQueryExtensionsString */
72 extern const char *glo_glXQueryExtensionsString(void);
73
74 /* Create a light-weight context just for creating surface */
75 extern GloContext *__glo_context_create(int formatFlags);
76
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);
79
80 /* Destroy a previouslu created OpenGL context */
81 extern void glo_context_destroy(GloContext *context);
82
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);
85
86 /* Link the pixmap associated with surface as texture */
87 extern void glo_surface_as_texture(GloSurface *surface);
88
89 /* Create a surface with given width and height, */
90 extern GloSurface *glo_surface_create(int width, int height, GloContext *context);
91
92 /* Destroy the given surface */
93 extern void glo_surface_destroy(GloSurface *surface);
94
95 /* Make the given surface current */
96 extern int glo_surface_makecurrent(GloSurface *surface);
97
98 /* Get the contents of the given surface. Note that this is top-down, not
99  * bottom-up as glReadPixels would do. */
100 extern void glo_surface_getcontents(GloSurface *surface, int stride, int type, void *data);
101
102 /* Return the width and height of the given surface */
103 extern void glo_surface_get_size(GloSurface *surface, int *width, int *height);
104
105 /* Functions to decode the format flags */
106 extern int glo_flags_get_depth_bits(int formatFlags);
107 extern int glo_flags_get_stencil_bits(int formatFlags);
108 extern void glo_flags_get_rgba_bits(int formatFlags, int *rgba);
109 extern int glo_flags_get_bytes_per_pixel(int formatFlags);
110 extern void glo_flags_get_readpixel_type(int formatFlags, int *glFormat, int *glType);
111 /* Score how close the given format flags match. 0=great, >0 not so great */
112 extern int glo_flags_score(int formatFlagsExpected, int formatFlagsReal);
113
114 /* Create a set of format flags from a null-terminated list
115  * of GLX fbConfig flags. If assumeBooleans is set, items such
116  * as GLX_RGBA/GLX_DOUBLEBUFFER are treated as booleans, not key-value pairs
117  * (glXChooseVisual treats them as booleans, glXChooseFBConfig as key-value pairs)
118  */
119 extern int glo_flags_get_from_glx(const int *fbConfig, int assumeBooleans);
120 /* Use in place of glxGetConfig - returns information from flags based on a GLX enum */
121 extern int glo_get_glx_from_flags(int formatFlags, int glxEnum);
122
123 /* Get the width and height from attrib_list */
124 extern void glo_geometry_get_from_glx(const int* attrib_list, int* width, int* height);
125
126 /* In terms of speed, glReadPixels actually seems the best we can do.
127  * * On Windows PFB_DRAW_TO_BITMAP is software-only.
128  * * http://www.opengl.org/registry/specs/ARB/pixel_buffer_object.txt would be
129  * useful if we didn't want the data right away (as we could avoid flushing the
130  * pipeline).
131  * * The internal data format seems to be GL_BGRA - and this is indeed faster.
132  * * Apple suggests using GL_UNSIGNED_INT_8_8_8_8_REV instead of
133  * GL_UNSIGNED_BYTE, but there don't appear to be any speed increase from
134  * doing this on Windows at least.
135  */
136
137 #endif /* GLOFFSCREEN_H_ */