src/video/mir/SDL_miropengl.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 02 Aug 2017 10:22:48 -0700
changeset 11175 cbc6a8a5b701
parent 11159 70eaadd05283
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Fixed bug 3690 - SDL2 KMS/DRM render context support

Manuel

The attached patch adds support for KMS/DRM context graphics.

It builds with no problem on X86_64 GNU/Linux systems, provided the needed libraries are present, and on ARM GNU/Linux systems that have KMS/DRM support and a GLES2 implementation.
Tested on Raspberry Pi: KMS/DRM is what the Raspberry Pi will use as default in the near future, once the propietary DispmanX API by Broadcom is overtaken by open graphics stack, it's possible to boot current Raspbian system in KMS mode by adding "dtoverlay=vc4-kms-v3d" to config.txt on Raspbian's boot partition.
X86 systems use KMS right away in every current GNU/Linux system.

Simple build instructions:

$./autogen.sh
$./configure --enable-video-kmsdrm
$make
icculus@8153
     1
/*
icculus@8153
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
icculus@8153
     4
icculus@8153
     5
  This software is provided 'as-is', without any express or implied
icculus@8153
     6
  warranty.  In no event will the authors be held liable for any damages
icculus@8153
     7
  arising from the use of this software.
icculus@8153
     8
icculus@8153
     9
  Permission is granted to anyone to use this software for any purpose,
icculus@8153
    10
  including commercial applications, and to alter it and redistribute it
icculus@8153
    11
  freely, subject to the following restrictions:
icculus@8153
    12
icculus@8153
    13
  1. The origin of this software must not be misrepresented; you must not
icculus@8153
    14
     claim that you wrote the original software. If you use this software
icculus@8153
    15
     in a product, an acknowledgment in the product documentation would be
icculus@8153
    16
     appreciated but is not required.
icculus@8153
    17
  2. Altered source versions must be plainly marked as such, and must not be
icculus@8153
    18
     misrepresented as being the original software.
icculus@8153
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@8153
    20
*/
icculus@8153
    21
icculus@8153
    22
/*
icculus@8153
    23
  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
icculus@8153
    24
*/
icculus@8153
    25
icculus@8154
    26
#include "../../SDL_internal.h"
icculus@8154
    27
icculus@8154
    28
#if SDL_VIDEO_DRIVER_MIR
icculus@8154
    29
icculus@8153
    30
#include "SDL_miropengl.h"
icculus@8153
    31
icculus@8159
    32
#include "SDL_mirdyn.h"
icculus@8159
    33
slouken@10690
    34
int
icculus@8153
    35
MIR_GL_SwapWindow(_THIS, SDL_Window* window)
icculus@8153
    36
{
icculus@8153
    37
    MIR_Window* mir_wind = window->driverdata;
icculus@8153
    38
slouken@10690
    39
    return SDL_EGL_SwapBuffers(_this, mir_wind->egl_surface);
icculus@8153
    40
}
icculus@8153
    41
icculus@8153
    42
int
icculus@8153
    43
MIR_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context)
icculus@8153
    44
{
icculus@8153
    45
  if (window) {
icculus@8153
    46
      EGLSurface egl_surface = ((MIR_Window*)window->driverdata)->egl_surface;
icculus@8153
    47
      return SDL_EGL_MakeCurrent(_this, egl_surface, context);
icculus@8153
    48
  }
icculus@8153
    49
icculus@8153
    50
  return SDL_EGL_MakeCurrent(_this, NULL, NULL);
icculus@8153
    51
}
icculus@8153
    52
icculus@8153
    53
SDL_GLContext
icculus@8153
    54
MIR_GL_CreateContext(_THIS, SDL_Window* window)
icculus@8153
    55
{
icculus@8153
    56
    MIR_Window* mir_window = window->driverdata;
icculus@8153
    57
icculus@8153
    58
    SDL_GLContext context;
icculus@8153
    59
    context = SDL_EGL_CreateContext(_this, mir_window->egl_surface);
icculus@8153
    60
icculus@8153
    61
    return context;
icculus@8153
    62
}
icculus@8153
    63
icculus@8153
    64
int
icculus@8153
    65
MIR_GL_LoadLibrary(_THIS, const char* path)
icculus@8153
    66
{
icculus@8153
    67
    MIR_Data* mir_data = _this->driverdata;
icculus@8153
    68
slouken@11175
    69
    SDL_EGL_LoadLibrary(_this, path, MIR_mir_connection_get_egl_native_display(mir_data->connection), 0);
icculus@8153
    70
icculus@8153
    71
    SDL_EGL_ChooseConfig(_this);
icculus@8153
    72
icculus@8153
    73
    return 0;
icculus@8153
    74
}
icculus@8153
    75
icculus@8154
    76
#endif /* SDL_VIDEO_DRIVER_MIR */
icculus@8154
    77
icculus@8154
    78
/* vi: set ts=4 sw=4 expandtab: */