Advertisement
Guest User

egl_windows.cpp

a guest
Dec 3rd, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.39 KB | None | 0 0
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.  *   Mupen64plus - egl_windows.cpp                                         *
  3.  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
  4.  *   Copyright (C) 2009 Richard Goedeken                                   *
  5.  *                                                                         *
  6.  *   This program is free software; you can redistribute it and/or modify  *
  7.  *   it under the terms of the GNU General Public License as published by  *
  8.  *   the Free Software Foundation; either version 2 of the License, or     *
  9.  *   (at your option) any later version.                                   *
  10.  *                                                                         *
  11.  *   This program is distributed in the hope that it will be useful,       *
  12.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  13.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  14.  *   GNU General Public License for more details.                          *
  15.  *                                                                         *
  16.  *   You should have received a copy of the GNU General Public License     *
  17.  *   along with this program; if not, write to the                         *
  18.  *   Free Software Foundation, Inc.,                                       *
  19.  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
  20.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  21.  
  22. #include <EGL/egl.h>
  23. #include <SDL_syswm.h>
  24.  
  25. #include "egl_windows.h"
  26.  
  27. /******************************************************************************
  28.  Global variables
  29. ******************************************************************************/
  30.  
  31. // EGL variables
  32. EGLDisplay          eglDisplay  = 0;
  33. EGLConfig           eglConfig   = 0;
  34. EGLSurface          eglSurface  = 0;
  35. EGLContext          eglContext  = 0;
  36.  
  37. EGLint pi32ConfigAttribs[] =
  38. {
  39. #ifdef HAVE_GLES2
  40.     EGL_RED_SIZE,           5,
  41.     EGL_GREEN_SIZE,         6,
  42.     EGL_BLUE_SIZE,          5,
  43.     EGL_ALPHA_SIZE,         0,
  44.     EGL_DEPTH_SIZE,         24,
  45.     EGL_LEVEL,              0,
  46.     EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
  47.     EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
  48.     EGL_NATIVE_RENDERABLE,  EGL_FALSE,
  49.     EGL_DEPTH_SIZE,         EGL_DONT_CARE,
  50.     EGL_NONE
  51. #else
  52.     EGL_RED_SIZE,           5,
  53.     EGL_GREEN_SIZE,         6,
  54.     EGL_BLUE_SIZE,          5,
  55.     EGL_ALPHA_SIZE,         0,
  56.     EGL_DEPTH_SIZE,         24,
  57.     EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
  58.     EGL_NONE
  59. #endif
  60. };
  61.  
  62. extern "C" void create_egl_windows(void)
  63. {
  64.     SDL_SysWMinfo sysInfo; //Will hold our Window information
  65.     SDL_VERSION(&sysInfo.version); //Set SDL version
  66.     if(SDL_GetWMInfo(&sysInfo) <= 0)
  67.     {
  68.         printf("Unable to get window handle");
  69.         destroy_egl_windows();
  70.     }
  71.  
  72.     NativeDisplayType   natDisplay = GetDC(sysInfo.window);
  73.     NativeWindowType    natWindow = sysInfo.window;
  74.  
  75.     if (!natDisplay)
  76.     {
  77.         printf("Unable to get display!n");
  78.         destroy_egl_windows();
  79.     }
  80.  
  81.     if (!natWindow)
  82.     {
  83.         printf("Unable to get window!n");
  84.         destroy_egl_windows();
  85.     }
  86.  
  87.     eglDisplay = eglGetDisplay((NativeDisplayType) natDisplay);
  88.  
  89.     if(eglDisplay == EGL_NO_DISPLAY)
  90.          eglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY);
  91.  
  92.     EGLint iMajorVersion, iMinorVersion;
  93.     if (!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion))
  94.     {
  95.         printf("eglInitialize() failed.");
  96.         destroy_egl_windows();
  97.     }
  98.  
  99. #ifdef HAVE_GLES2
  100.     eglBindAPI(EGL_OPENGL_ES_API);
  101. #endif
  102.  
  103.     EGLint iConfigs;
  104.     if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1))
  105.     {
  106.         printf("eglChooseConfig() failed.");
  107.         destroy_egl_windows();
  108.     }
  109.  
  110.     eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, natWindow, NULL);
  111.  
  112.     if(eglSurface == EGL_NO_SURFACE)
  113.     {
  114.         eglGetError();
  115.         eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, NULL, NULL);
  116.     }
  117.  
  118. #ifdef HAVE_GLES2
  119.     EGLint ai32ContextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
  120.     eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, ai32ContextAttribs);
  121. #else
  122.     eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
  123. #endif
  124.  
  125.     eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
  126. }
  127.  
  128. extern "C" void destroy_egl_windows(void)
  129. {
  130.     eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  131.     eglTerminate(eglDisplay);
  132. }
  133.  
  134. extern "C" void egl_swap_buffers(void)
  135. {
  136.     eglSwapBuffers(eglDisplay, eglSurface);
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement