1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 * 16 * The Original Code is Copyright (C) 2014 Blender Foundation. 17 * All rights reserved. 18 */ 19 20 /** \file 21 * \ingroup GHOST 22 */ 23 24 #pragma once 25 26 #include "GHOST_Context.h" 27 28 extern "C" { 29 #include "SDL.h" 30 } 31 32 #ifndef GHOST_OPENGL_SDL_CONTEXT_FLAGS 33 # ifdef WITH_GPU_DEBUG 34 # define GHOST_OPENGL_SDL_CONTEXT_FLAGS SDL_GL_CONTEXT_DEBUG_FLAG 35 # else 36 # define GHOST_OPENGL_SDL_CONTEXT_FLAGS 0 37 # endif 38 #endif 39 40 #ifndef GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY 41 # define GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY 0 42 #endif 43 44 class GHOST_ContextSDL : public GHOST_Context { 45 public: 46 /** 47 * Constructor. 48 */ 49 GHOST_ContextSDL(bool stereoVisual, 50 SDL_Window *window, 51 int contextProfileMask, 52 int contextMajorVersion, 53 int contextMinorVersion, 54 int contextFlags, 55 int contextResetNotificationStrategy); 56 57 /** 58 * Destructor. 59 */ 60 ~GHOST_ContextSDL(); 61 62 /** 63 * Swaps front and back buffers of a window. 64 * \return A boolean success indicator. 65 */ 66 GHOST_TSuccess swapBuffers(); 67 68 /** 69 * Activates the drawing context of this window. 70 * \return A boolean success indicator. 71 */ 72 GHOST_TSuccess activateDrawingContext(); 73 74 /** 75 * Release the drawing context of the calling thread. 76 * \return A boolean success indicator. 77 */ 78 GHOST_TSuccess releaseDrawingContext(); 79 80 /** 81 * Call immediately after new to initialize. If this fails then immediately delete the object. 82 * \return Indication as to whether initialization has succeeded. 83 */ 84 GHOST_TSuccess initializeDrawingContext(); 85 86 /** 87 * Removes references to native handles from this context and then returns 88 * \return GHOST_kSuccess if it is OK for the parent to release the handles and 89 * GHOST_kFailure if releasing the handles will interfere with sharing 90 */ 91 GHOST_TSuccess releaseNativeHandles(); 92 93 /** 94 * Sets the swap interval for swapBuffers. 95 * \param interval The swap interval to use. 96 * \return A boolean success indicator. 97 */ 98 GHOST_TSuccess setSwapInterval(int interval); 99 100 /** 101 * Gets the current swap interval for swapBuffers. 102 * \param intervalOut Variable to store the swap interval if it can be read. 103 * \return Whether the swap interval can be read. 104 */ 105 GHOST_TSuccess getSwapInterval(int &intervalOut); 106 107 private: 108 SDL_Window *m_window; 109 SDL_Window *m_hidden_window; 110 111 const int m_contextProfileMask; 112 const int m_contextMajorVersion; 113 const int m_contextMinorVersion; 114 const int m_contextFlags; 115 const int m_contextResetNotificationStrategy; 116 117 SDL_GLContext m_context; /* m_sdl_glcontext */ 118 119 /** The first created OpenGL context (for sharing display lists) */ 120 static SDL_GLContext s_sharedContext; 121 static int s_sharedCount; 122 }; 123