1 /* 2 This file is part of Warzone 2100. 3 Copyright (C) 2019 Warzone 2100 Project 4 5 Warzone 2100 is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 Warzone 2100 is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with Warzone 2100; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 #pragma once 21 22 #ifndef __INCLUDED_GFX_API_GL_SDL_H__ 23 #define __INCLUDED_GFX_API_GL_SDL_H__ 24 25 #include "lib/ivis_opengl/gfx_api_gl.h" 26 #include <SDL_video.h> 27 28 class sdl_OpenGL_Impl final : public gfx_api::backend_OpenGL_Impl 29 { 30 public: 31 sdl_OpenGL_Impl(SDL_Window* window, bool useOpenGLES, bool useOpenGLESLibrary); 32 33 virtual GLADloadproc getGLGetProcAddress() override; 34 virtual bool createGLContext() override; 35 virtual void swapWindow() override; 36 virtual void getDrawableSize(int* w, int* h) override; 37 38 virtual bool isOpenGLES() const override; 39 40 virtual bool setSwapInterval(gfx_api::context::swap_interval_mode mode) override; 41 virtual gfx_api::context::swap_interval_mode getSwapInterval() const override; 42 43 public: 44 45 enum GLContextRequests { 46 // Desktop OpenGL Context Requests 47 OpenGLCore_HighestAvailable, 48 OpenGL21Compat, 49 // OpenGL ES Context Requests 50 OpenGLES30, 51 OpenGLES20, 52 // 53 MAX_CONTEXT_REQUESTS 54 }; 55 56 static bool configureOpenGLContextRequest(GLContextRequests request, bool useOpenGLESLibrary); 57 static GLContextRequests getInitialContextRequest(bool useOpenglES = false); 58 59 private: 60 SDL_Window* window; 61 bool useOpenglES = false; 62 bool useOpenGLESLibrary = false; 63 64 GLContextRequests contextRequest = OpenGLCore_HighestAvailable; 65 66 private: 67 bool configureNextOpenGLContextRequest(); 68 std::string to_string(const GLContextRequests& request) const; 69 static void setOpenGLESDriver(bool useOpenGLESLibrary); 70 }; 71 72 #endif // __INCLUDED_GFX_API_GL_SDL_H__ 73