1 /* 2 * This file is a part of the Cairo-Dock project 3 * 4 * Copyright : (C) see the 'copyright' file. 5 * E-mail : see the 'copyright' file. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 3 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __CAIRO_DOCK_OPENGL__ 21 #define __CAIRO_DOCK_OPENGL__ 22 23 #include <glib.h> 24 25 #include "gldi-config.h" 26 #include "cairo-dock-struct.h" 27 #include "cairo-dock-container.h" 28 29 G_BEGIN_DECLS 30 31 /** 32 *@file cairo-dock-opengl.h This class manages the OpenGL backend and context. 33 */ 34 35 /// This strucure summarizes the available OpenGL configuration on the system. 36 struct _CairoDockGLConfig { 37 gboolean bIndirectRendering; 38 gboolean bAlphaAvailable; 39 gboolean bStencilBufferAvailable; 40 gboolean bAccumBufferAvailable; 41 gboolean bFboAvailable; 42 gboolean bNonPowerOfTwoAvailable; 43 gboolean bTextureFromPixmapAvailable; 44 #ifdef HAVE_GLX 45 void (*bindTexImage) (Display *display, GLXDrawable drawable, int buffer, int *attribList); // texture from pixmap 46 void (*releaseTexImage) (Display *display, GLXDrawable drawable, int buffer); // texture from pixmap 47 #elif defined(HAVE_EGL) 48 void (*bindTexImage) (EGLDisplay *display, EGLSurface drawable, int buffer); // texture from pixmap 49 void (*releaseTexImage) (EGLDisplay *display, EGLSurface drawable, int buffer); // texture from pixmap 50 #endif 51 }; 52 53 struct _GldiGLManagerBackend { 54 gboolean (*init) (gboolean bForceOpenGL); 55 void (*stop) (void); 56 gboolean (*container_make_current) (GldiContainer *pContainer); 57 void (*container_end_draw) (GldiContainer *pContainer); 58 void (*container_init) (GldiContainer *pContainer); 59 void (*container_finish) (GldiContainer *pContainer); 60 }; 61 62 63 64 ///////////// 65 // BACKEND // 66 ///////////// 67 /** Initialize the OpenGL backend, by trying to get a suitable GLX configuration. 68 *@param bForceOpenGL whether to force the use of OpenGL, or let the function decide. 69 *@return TRUE if OpenGL is usable. 70 */ 71 gboolean gldi_gl_backend_init (gboolean bForceOpenGL); 72 73 void gldi_gl_backend_deactivate (void); 74 75 #define gldi_gl_backend_is_safe(...) (g_bUseOpenGL && ! g_openglConfig.bIndirectRendering && g_openglConfig.bAlphaAvailable && g_openglConfig.bStencilBufferAvailable) // bNonPowerOfTwoAvailable et FBO sont detectes une fois qu'on a un contexte OpenGL, on ne peut donc pas les inclure ici. 76 77 /* Toggle on/off the indirect rendering mode (for cards like Radeon 35xx). 78 */ 79 void gldi_gl_backend_force_indirect_rendering (void); 80 81 82 /////////////// 83 // CONTAINER // 84 /////////////// 85 86 /** Make a Container's OpenGL context the current one. 87 *@param pContainer the container 88 *@return TRUE if the Container's context is now the current one. 89 */ 90 gboolean gldi_gl_container_make_current (GldiContainer *pContainer); 91 92 /** Start drawing on a Container's OpenGL context. 93 *@param pContainer the container 94 *@param pArea optional area to clip the drawing (NULL to draw on the whole Container) 95 *@param bClear whether to clear the color buffer or not 96 */ 97 gboolean gldi_gl_container_begin_draw_full (GldiContainer *pContainer, GdkRectangle *pArea, gboolean bClear); 98 99 /** Start drawing on a Container's OpenGL context (draw on the whole Container and clear buffers). 100 *@param pContainer the container 101 */ 102 #define gldi_gl_container_begin_draw(pContainer) gldi_gl_container_begin_draw_full (pContainer, NULL, TRUE) 103 104 /** Ends the drawing on a Container's OpenGL context. 105 *@param pContainer the container 106 */ 107 void gldi_gl_container_end_draw (GldiContainer *pContainer); 108 109 110 /** Set a perspective view to the current GL context to fit a given Container. You may want to ensure the Container's context is really the current one. 111 *@param pContainer the container 112 */ 113 void gldi_gl_container_set_perspective_view (GldiContainer *pContainer); 114 115 /** Set a perspective view to the current GL context to fit a given Icon (which must be inside a Container). You may want to ensure the Icon's Container's context is really the current one. 116 *@param pIcon the icon 117 */ 118 void gldi_gl_container_set_perspective_view_for_icon (Icon *pIcon); 119 120 /** Set a orthogonal view to the current GL context to fit a given Container. You may want to ensure the Container's context is really the current one. 121 *@param pContainer the container 122 */ 123 void gldi_gl_container_set_ortho_view (GldiContainer *pContainer); 124 125 /** Set a orthogonal view to the current GL context to fit a given Icon (which must be inside a Container). You may want to ensure the Icon's Container's context is really the current one. 126 *@param pIcon the icon 127 */ 128 void gldi_gl_container_set_ortho_view_for_icon (Icon *pIcon); 129 130 /** Set a shared default-initialized GL context on a window. 131 *@param pContainer the container, not yet realized. 132 */ 133 void gldi_gl_container_init (GldiContainer *pContainer); 134 135 void gldi_gl_container_finish (GldiContainer *pContainer); 136 137 138 void gldi_gl_manager_register_backend (GldiGLManagerBackend *pBackend); 139 140 G_END_DECLS 141 #endif 142