SDL_windowsopengles.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../../SDL_internal.h"
  19. #if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL
  20. #include "SDL_windowsvideo.h"
  21. #include "SDL_windowsopengles.h"
  22. #include "SDL_windowsopengl.h"
  23. /* EGL implementation of SDL OpenGL support */
  24. int
  25. WIN_GLES_LoadLibrary(_THIS, const char *path) {
  26. /* If the profile requested is not GL ES, switch over to WIN_GL functions */
  27. if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
  28. #if SDL_VIDEO_OPENGL_WGL
  29. WIN_GLES_UnloadLibrary(_this);
  30. _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
  31. _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
  32. _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
  33. _this->GL_CreateContext = WIN_GL_CreateContext;
  34. _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
  35. _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
  36. _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
  37. _this->GL_SwapWindow = WIN_GL_SwapWindow;
  38. _this->GL_DeleteContext = WIN_GL_DeleteContext;
  39. return WIN_GL_LoadLibrary(_this, path);
  40. #else
  41. return SDL_SetError("SDL not configured with OpenGL/WGL support");
  42. #endif
  43. }
  44. if (_this->egl_data == NULL) {
  45. return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0);
  46. }
  47. return 0;
  48. }
  49. SDL_GLContext
  50. WIN_GLES_CreateContext(_THIS, SDL_Window * window)
  51. {
  52. SDL_GLContext context;
  53. SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
  54. #if SDL_VIDEO_OPENGL_WGL
  55. if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
  56. /* Switch to WGL based functions */
  57. WIN_GLES_UnloadLibrary(_this);
  58. _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
  59. _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
  60. _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
  61. _this->GL_CreateContext = WIN_GL_CreateContext;
  62. _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
  63. _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
  64. _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
  65. _this->GL_SwapWindow = WIN_GL_SwapWindow;
  66. _this->GL_DeleteContext = WIN_GL_DeleteContext;
  67. if (WIN_GL_LoadLibrary(_this, NULL) != 0) {
  68. return NULL;
  69. }
  70. return WIN_GL_CreateContext(_this, window);
  71. }
  72. #endif
  73. context = SDL_EGL_CreateContext(_this, data->egl_surface);
  74. return context;
  75. }
  76. void
  77. WIN_GLES_DeleteContext(_THIS, SDL_GLContext context)
  78. {
  79. SDL_EGL_DeleteContext(_this, context);
  80. WIN_GLES_UnloadLibrary(_this);
  81. }
  82. SDL_EGL_SwapWindow_impl(WIN)
  83. SDL_EGL_MakeCurrent_impl(WIN)
  84. int
  85. WIN_GLES_SetupWindow(_THIS, SDL_Window * window)
  86. {
  87. /* The current context is lost in here; save it and reset it. */
  88. SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
  89. SDL_Window *current_win = SDL_GL_GetCurrentWindow();
  90. SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
  91. if (_this->egl_data == NULL) {
  92. SDL_assert(!_this->gl_config.driver_loaded);
  93. if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0) < 0) {
  94. SDL_EGL_UnloadLibrary(_this);
  95. return -1;
  96. }
  97. _this->gl_config.driver_loaded = 1;
  98. }
  99. /* Create the GLES window surface */
  100. windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)windowdata->hwnd);
  101. if (windowdata->egl_surface == EGL_NO_SURFACE) {
  102. return SDL_SetError("Could not create GLES window surface");
  103. }
  104. return WIN_GLES_MakeCurrent(_this, current_win, current_ctx);
  105. }
  106. #endif /* SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL */
  107. /* vi: set ts=4 sw=4 expandtab: */