sdl

FORK: Simple Directmedia Layer
git clone https://git.neptards.moe/neptards/sdl.git
Log | Files | Refs

SDL_offscreenopengl.c (2556B)


      1 /*
      2   Simple DirectMedia Layer
      3   Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
      4 
      5   This software is provided 'as-is', without any express or implied
      6   warranty.  In no event will the authors be held liable for any damages
      7   arising from the use of this software.
      8 
      9   Permission is granted to anyone to use this software for any purpose,
     10   including commercial applications, and to alter it and redistribute it
     11   freely, subject to the following restrictions:
     12 
     13   1. The origin of this software must not be misrepresented; you must not
     14      claim that you wrote the original software. If you use this software
     15      in a product, an acknowledgment in the product documentation would be
     16      appreciated but is not required.
     17   2. Altered source versions must be plainly marked as such, and must not be
     18      misrepresented as being the original software.
     19   3. This notice may not be removed or altered from any source distribution.
     20 */
     21 
     22 #include "../../SDL_internal.h"
     23 
     24 #if SDL_VIDEO_DRIVER_OFFSCREEN
     25 
     26 #include "SDL_offscreenopengl.h"
     27 
     28 #include "SDL_opengl.h"
     29 
     30 int
     31 OFFSCREEN_GL_SwapWindow(_THIS, SDL_Window* window)
     32 {
     33     OFFSCREEN_Window* offscreen_wind = window->driverdata;
     34 
     35     SDL_EGL_SwapBuffers(_this, offscreen_wind->egl_surface);
     36     return 0;
     37 }
     38 
     39 int
     40 OFFSCREEN_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context)
     41 {
     42   if (window) {
     43       EGLSurface egl_surface = ((OFFSCREEN_Window*)window->driverdata)->egl_surface;
     44       return SDL_EGL_MakeCurrent(_this, egl_surface, context);
     45   }
     46 
     47   return SDL_EGL_MakeCurrent(_this, NULL, NULL);
     48 }
     49 
     50 SDL_GLContext
     51 OFFSCREEN_GL_CreateContext(_THIS, SDL_Window* window)
     52 {
     53     OFFSCREEN_Window* offscreen_window = window->driverdata;
     54 
     55     SDL_GLContext context;
     56     context = SDL_EGL_CreateContext(_this, offscreen_window->egl_surface);
     57 
     58     return context;
     59 }
     60 
     61 int
     62 OFFSCREEN_GL_LoadLibrary(_THIS, const char* path)
     63 {
     64     int ret = SDL_EGL_LoadLibraryOnly(_this, path);
     65     if (ret != 0) {
     66         return ret;
     67     }
     68 
     69     ret = SDL_EGL_InitializeOffscreen(_this, 0);
     70     if (ret != 0) {
     71         return ret;
     72     }
     73 
     74     ret = SDL_EGL_ChooseConfig(_this);
     75     if (ret != 0) {
     76         return ret;
     77     }
     78 
     79     return 0;
     80 }
     81 
     82 void
     83 OFFSCREEN_GL_UnloadLibrary(_THIS)
     84 {
     85     SDL_EGL_UnloadLibrary(_this);
     86 }
     87 
     88 void*
     89 OFFSCREEN_GL_GetProcAddress(_THIS, const char* proc)
     90 {
     91     void* proc_addr = SDL_EGL_GetProcAddress(_this, proc);
     92 
     93     if (!proc_addr) {
     94         SDL_SetError("Failed to find proc address!");
     95     }
     96 
     97     return proc_addr;
     98 }
     99 
    100 #endif /* SDL_VIDEO_DRIVER_OFFSCREEN */
    101 
    102 /* vi: set ts=4 sw=4 expandtab: */