OpenGL ES support for Windows
This commit is contained in:
parent
239ba53a4c
commit
f21d3e7e2a
32 changed files with 6741 additions and 1210 deletions
|
@ -46,3 +46,5 @@ SDL_PROC(void, glBindFramebuffer, (GLenum, GLuint))
|
|||
SDL_PROC(void, glFramebufferTexture2D, (GLenum, GLenum, GLenum, GLuint, GLint))
|
||||
SDL_PROC(GLenum, glCheckFramebufferStatus, (GLenum))
|
||||
SDL_PROC(void, glDeleteFramebuffers, (GLsizei, const GLuint *))
|
||||
SDL_PROC(GLint, glGetAttribLocation, (GLuint, const GLchar *))
|
||||
|
|
@ -23,8 +23,9 @@
|
|||
#if SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "SDL_sysvideo.h"
|
||||
#include "SDL_egl.h"
|
||||
|
||||
#include "SDL_egl_c.h"
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_hints.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_RPI
|
||||
/* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
|
||||
|
@ -40,6 +41,13 @@
|
|||
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
|
||||
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
|
||||
|
||||
#elif SDL_VIDEO_DRIVER_WINDOWS
|
||||
/* EGL AND OpenGL ES support via ANGLE */
|
||||
#define DEFAULT_EGL "libEGL.dll"
|
||||
#define DEFAULT_OGL_ES2 "libGLESv2.dll"
|
||||
#define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
|
||||
#define DEFAULT_OGL_ES "libGLESv1_CM.dll"
|
||||
|
||||
#else
|
||||
/* Desktop Linux */
|
||||
#define DEFAULT_EGL "libEGL.so.1"
|
||||
|
@ -49,7 +57,7 @@
|
|||
#endif /* SDL_VIDEO_DRIVER_RPI */
|
||||
|
||||
#define LOAD_FUNC(NAME) \
|
||||
*((void**)&_this->egl_data->NAME) = dlsym(dll_handle, #NAME); \
|
||||
*((void**)&_this->egl_data->NAME) = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
|
||||
if (!_this->egl_data->NAME) \
|
||||
{ \
|
||||
return SDL_SetError("Could not retrieve EGL function " #NAME); \
|
||||
|
@ -61,12 +69,10 @@ void *
|
|||
SDL_EGL_GetProcAddress(_THIS, const char *proc)
|
||||
{
|
||||
static char procname[1024];
|
||||
void *handle;
|
||||
void *retval;
|
||||
|
||||
/* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
|
||||
#if !defined(SDL_VIDEO_DRIVER_ANDROID)
|
||||
handle = _this->egl_data->egl_dll_handle;
|
||||
#if !defined(SDL_VIDEO_DRIVER_ANDROID)
|
||||
if (_this->egl_data->eglGetProcAddress) {
|
||||
retval = _this->egl_data->eglGetProcAddress(proc);
|
||||
if (retval) {
|
||||
|
@ -75,15 +81,11 @@ SDL_EGL_GetProcAddress(_THIS, const char *proc)
|
|||
}
|
||||
#endif
|
||||
|
||||
handle = _this->gl_config.dll_handle;
|
||||
#if defined(__OpenBSD__) && !defined(__ELF__)
|
||||
#undef dlsym(x,y);
|
||||
#endif
|
||||
retval = dlsym(handle, proc);
|
||||
if (!retval && strlen(proc) <= 1022) {
|
||||
retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
|
||||
if (!retval && SDL_strlen(proc) <= 1022) {
|
||||
procname[0] = '_';
|
||||
strcpy(procname + 1, proc);
|
||||
retval = dlsym(handle, procname);
|
||||
SDL_strlcpy(procname + 1, proc, 1022);
|
||||
retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
@ -97,12 +99,12 @@ SDL_EGL_UnloadLibrary(_THIS)
|
|||
_this->egl_data->egl_display = NULL;
|
||||
}
|
||||
|
||||
if (_this->gl_config.dll_handle) {
|
||||
dlclose(_this->gl_config.dll_handle);
|
||||
_this->gl_config.dll_handle = NULL;
|
||||
if (_this->egl_data->dll_handle) {
|
||||
SDL_UnloadObject(_this->egl_data->dll_handle);
|
||||
_this->egl_data->dll_handle = NULL;
|
||||
}
|
||||
if (_this->egl_data->egl_dll_handle) {
|
||||
dlclose(_this->egl_data->egl_dll_handle);
|
||||
SDL_UnloadObject(_this->egl_data->egl_dll_handle);
|
||||
_this->egl_data->egl_dll_handle = NULL;
|
||||
}
|
||||
|
||||
|
@ -114,10 +116,12 @@ SDL_EGL_UnloadLibrary(_THIS)
|
|||
int
|
||||
SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display)
|
||||
{
|
||||
void *dll_handle, *egl_dll_handle; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
|
||||
char *path;
|
||||
int dlopen_flags;
|
||||
|
||||
void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
|
||||
char *path = NULL;
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
const char *d3dcompiler;
|
||||
#endif
|
||||
|
||||
if (_this->egl_data) {
|
||||
return SDL_SetError("OpenGL ES context already created");
|
||||
}
|
||||
|
@ -127,50 +131,63 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
|
|||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
#ifdef RTLD_GLOBAL
|
||||
dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
|
||||
#else
|
||||
dlopen_flags = RTLD_LAZY;
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
|
||||
if (!d3dcompiler) {
|
||||
/* By default we load the Vista+ compatible compiler */
|
||||
d3dcompiler = "d3dcompiler_46.dll";
|
||||
}
|
||||
if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
|
||||
SDL_LoadObject(d3dcompiler);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
|
||||
path = getenv("SDL_VIDEO_GL_DRIVER");
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
if ((path == NULL) | (egl_dll_handle == NULL)) {
|
||||
path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
|
||||
if (path != NULL) {
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
|
||||
if (egl_dll_handle == NULL) {
|
||||
if (_this->gl_config.major_version > 1) {
|
||||
path = DEFAULT_OGL_ES2;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
} else {
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
else {
|
||||
path = DEFAULT_OGL_ES;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
if (egl_dll_handle == NULL) {
|
||||
path = DEFAULT_OGL_ES_PVR;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
_this->egl_data->egl_dll_handle = egl_dll_handle;
|
||||
|
||||
if (egl_dll_handle == NULL) {
|
||||
return SDL_SetError("Could not initialize OpenGL ES library: %s", dlerror());
|
||||
return SDL_SetError("Could not initialize OpenGL ES library");
|
||||
}
|
||||
|
||||
|
||||
/* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
|
||||
dll_handle = dlopen(egl_path, dlopen_flags);
|
||||
if (egl_path != NULL) {
|
||||
dll_handle = SDL_LoadObject(egl_path);
|
||||
}
|
||||
/* Catch the case where the application isn't linked with EGL */
|
||||
if ((dlsym(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
|
||||
dlclose(dll_handle);
|
||||
path = getenv("SDL_VIDEO_EGL_DRIVER");
|
||||
if ((SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
|
||||
if (dll_handle != NULL) {
|
||||
SDL_UnloadObject(dll_handle);
|
||||
}
|
||||
path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
|
||||
if (path == NULL) {
|
||||
path = DEFAULT_EGL;
|
||||
}
|
||||
dll_handle = dlopen(path, dlopen_flags);
|
||||
dll_handle = SDL_LoadObject(path);
|
||||
if (dll_handle == NULL) {
|
||||
return SDL_SetError("Could not load EGL library");
|
||||
}
|
||||
}
|
||||
_this->gl_config.dll_handle = dll_handle;
|
||||
|
||||
if (dll_handle == NULL) {
|
||||
return SDL_SetError("Could not load EGL library: %s", dlerror());
|
||||
}
|
||||
_this->egl_data->dll_handle = dll_handle;
|
||||
|
||||
/* Load new function pointers */
|
||||
LOAD_FUNC(eglGetDisplay);
|
||||
|
@ -198,14 +215,14 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
|
|||
return SDL_SetError("Could not initialize EGL");
|
||||
}
|
||||
|
||||
_this->gl_config.dll_handle = dll_handle;
|
||||
_this->egl_data->dll_handle = dll_handle;
|
||||
_this->egl_data->egl_dll_handle = egl_dll_handle;
|
||||
_this->gl_config.driver_loaded = 1;
|
||||
|
||||
if (path) {
|
||||
strncpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
|
||||
SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
|
||||
} else {
|
||||
strcpy(_this->gl_config.driver_path, "");
|
||||
*_this->gl_config.driver_path = '\0';
|
||||
}
|
||||
|
||||
/* We need to select a config here to satisfy some video backends such as X11 */
|
||||
|
@ -217,10 +234,10 @@ SDL_EGL_ChooseConfig(_THIS)
|
|||
{
|
||||
/* 64 seems nice. */
|
||||
EGLint attribs[64];
|
||||
EGLint found_configs = 0;
|
||||
EGLint found_configs = 0, value;
|
||||
/* 128 seems even nicer here */
|
||||
EGLConfig configs[128];
|
||||
int i, j, best_bitdiff = -1, bitdiff, value;
|
||||
int i, j, best_bitdiff = -1, bitdiff;
|
||||
|
||||
if (!_this->egl_data) {
|
||||
/* The EGL library wasn't loaded, SDL_GetError() should have info */
|
||||
|
@ -283,10 +300,10 @@ SDL_EGL_ChooseConfig(_THIS)
|
|||
|
||||
/* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
|
||||
/* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
|
||||
|
||||
|
||||
for ( i=0; i<found_configs; i++ ) {
|
||||
bitdiff = 0;
|
||||
for (j = 0; ; j += 2) {
|
||||
for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
|
||||
if (attribs[j] == EGL_NONE) {
|
||||
break;
|
||||
}
|
||||
|
@ -298,7 +315,6 @@ SDL_EGL_ChooseConfig(_THIS)
|
|||
attribs[j] == EGL_ALPHA_SIZE ||
|
||||
attribs[j] == EGL_DEPTH_SIZE ||
|
||||
attribs[j] == EGL_STENCIL_SIZE)) {
|
||||
|
||||
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value);
|
||||
bitdiff += value - attribs[j + 1]; /* value is always >= attrib */
|
||||
}
|
||||
|
|
|
@ -25,62 +25,57 @@
|
|||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#if defined(__OpenBSD__) && !defined(__ELF__)
|
||||
#define dlsym(x,y) dlsym(x, "_" y)
|
||||
#endif
|
||||
#include "SDL_egl.h"
|
||||
|
||||
#include "SDL_sysvideo.h"
|
||||
|
||||
typedef struct SDL_EGL_VideoData
|
||||
{
|
||||
void *egl_dll_handle;
|
||||
void *egl_dll_handle, *dll_handle;
|
||||
EGLDisplay egl_display;
|
||||
EGLConfig egl_config;
|
||||
int egl_swapinterval;
|
||||
|
||||
EGLDisplay(*eglGetDisplay) (NativeDisplayType display);
|
||||
EGLBoolean(*eglInitialize) (EGLDisplay dpy, EGLint * major,
|
||||
EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display);
|
||||
EGLBoolean(EGLAPIENTRY *eglInitialize) (EGLDisplay dpy, EGLint * major,
|
||||
EGLint * minor);
|
||||
EGLBoolean(*eglTerminate) (EGLDisplay dpy);
|
||||
EGLBoolean(EGLAPIENTRY *eglTerminate) (EGLDisplay dpy);
|
||||
|
||||
void *(*eglGetProcAddress) (const char * procName);
|
||||
void *(EGLAPIENTRY *eglGetProcAddress) (const char * procName);
|
||||
|
||||
EGLBoolean(*eglChooseConfig) (EGLDisplay dpy,
|
||||
EGLBoolean(EGLAPIENTRY *eglChooseConfig) (EGLDisplay dpy,
|
||||
const EGLint * attrib_list,
|
||||
EGLConfig * configs,
|
||||
EGLint config_size, EGLint * num_config);
|
||||
|
||||
EGLContext(*eglCreateContext) (EGLDisplay dpy,
|
||||
EGLContext(EGLAPIENTRY *eglCreateContext) (EGLDisplay dpy,
|
||||
EGLConfig config,
|
||||
EGLContext share_list,
|
||||
const EGLint * attrib_list);
|
||||
|
||||
EGLBoolean(*eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
|
||||
EGLBoolean(EGLAPIENTRY *eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
|
||||
|
||||
EGLSurface(*eglCreateWindowSurface) (EGLDisplay dpy,
|
||||
EGLSurface(EGLAPIENTRY *eglCreateWindowSurface) (EGLDisplay dpy,
|
||||
EGLConfig config,
|
||||
NativeWindowType window,
|
||||
const EGLint * attrib_list);
|
||||
EGLBoolean(*eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
|
||||
EGLBoolean(EGLAPIENTRY *eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
|
||||
|
||||
EGLBoolean(*eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
|
||||
EGLBoolean(EGLAPIENTRY *eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
|
||||
EGLSurface read, EGLContext ctx);
|
||||
|
||||
EGLBoolean(*eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
|
||||
EGLBoolean(EGLAPIENTRY *eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
|
||||
|
||||
EGLBoolean(*eglSwapInterval) (EGLDisplay dpy, EGLint interval);
|
||||
EGLBoolean(EGLAPIENTRY *eglSwapInterval) (EGLDisplay dpy, EGLint interval);
|
||||
|
||||
const char *(*eglQueryString) (EGLDisplay dpy, EGLint name);
|
||||
const char *(EGLAPIENTRY *eglQueryString) (EGLDisplay dpy, EGLint name);
|
||||
|
||||
EGLBoolean(*eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
|
||||
EGLBoolean(EGLAPIENTRY *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
|
||||
EGLint attribute, EGLint * value);
|
||||
|
||||
EGLBoolean(*eglWaitNative) (EGLint engine);
|
||||
EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint engine);
|
||||
|
||||
EGLBoolean(*eglWaitGL)(void);
|
||||
EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
|
||||
} SDL_EGL_VideoData;
|
||||
|
||||
/* OpenGLES functions */
|
|
@ -25,7 +25,7 @@
|
|||
/* Android SDL video driver implementation */
|
||||
|
||||
#include "SDL_video.h"
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
#include "SDL_androidwindow.h"
|
||||
|
||||
#include "SDL_androidvideo.h"
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
static int Android_VideoInit(_THIS);
|
||||
static void Android_VideoQuit(_THIS);
|
||||
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
/* GL functions (SDL_androidgl.c) */
|
||||
extern SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window * window);
|
||||
extern int Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#define _SDL_androidwindow_h
|
||||
|
||||
#include "../../core/android/SDL_android.h"
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
extern int Android_CreateWindow(_THIS, SDL_Window * window);
|
||||
extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#if SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
/* OpenGLES functions */
|
||||
#define RPI_GLES_GetAttribute SDL_EGL_GetAttribute
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "SDL_assert.h"
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_windowsvideo.h"
|
||||
#include "SDL_windowsopengles.h"
|
||||
|
||||
/* WGL implementation of SDL OpenGL support */
|
||||
|
||||
|
@ -323,11 +324,35 @@ HasExtension(const char *extension, const char *extensions)
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
WIN_GL_InitExtensions(_THIS, HDC hdc)
|
||||
void
|
||||
WIN_GL_InitExtensions(_THIS)
|
||||
{
|
||||
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
|
||||
const char *extensions;
|
||||
HWND hwnd;
|
||||
HDC hdc;
|
||||
HGLRC hglrc;
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
|
||||
hwnd =
|
||||
CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
|
||||
10, 10, NULL, NULL, SDL_Instance, NULL);
|
||||
if (!hwnd) {
|
||||
return;
|
||||
}
|
||||
WIN_PumpEvents(_this);
|
||||
|
||||
hdc = GetDC(hwnd);
|
||||
|
||||
WIN_GL_SetupPixelFormat(_this, &pfd);
|
||||
|
||||
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
|
||||
|
||||
hglrc = _this->gl_data->wglCreateContext(hdc);
|
||||
if (!hglrc) {
|
||||
return;
|
||||
}
|
||||
_this->gl_data->wglMakeCurrent(hdc, hglrc);
|
||||
|
||||
wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
|
||||
_this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
|
||||
|
@ -369,6 +394,18 @@ WIN_GL_InitExtensions(_THIS, HDC hdc)
|
|||
_this->gl_data->wglSwapIntervalEXT = NULL;
|
||||
_this->gl_data->wglGetSwapIntervalEXT = NULL;
|
||||
}
|
||||
|
||||
/* Check for WGL_EXT_create_context_es2_profile */
|
||||
_this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_FALSE;
|
||||
if (HasExtension("WGL_EXT_create_context_es2_profile", extensions)) {
|
||||
_this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_TRUE;
|
||||
}
|
||||
|
||||
_this->gl_data->wglMakeCurrent(hdc, NULL);
|
||||
_this->gl_data->wglDeleteContext(hglrc);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
DestroyWindow(hwnd);
|
||||
WIN_PumpEvents(_this);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -396,8 +433,6 @@ WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
|
|||
if (hglrc) {
|
||||
_this->gl_data->wglMakeCurrent(hdc, hglrc);
|
||||
|
||||
WIN_GL_InitExtensions(_this, hdc);
|
||||
|
||||
if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
|
||||
_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
|
||||
1, &pixel_format,
|
||||
|
@ -548,6 +583,27 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
|
||||
HGLRC context, share_context;
|
||||
|
||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
|
||||
!_this->gl_data->HAS_WGL_EXT_create_context_es2_profile) {
|
||||
/* Switch to EGL based functions */
|
||||
WIN_GL_UnloadLibrary(_this);
|
||||
_this->GL_LoadLibrary = WIN_GLES_LoadLibrary;
|
||||
_this->GL_GetProcAddress = WIN_GLES_GetProcAddress;
|
||||
_this->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
|
||||
_this->GL_CreateContext = WIN_GLES_CreateContext;
|
||||
_this->GL_MakeCurrent = WIN_GLES_MakeCurrent;
|
||||
_this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
|
||||
_this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
|
||||
_this->GL_SwapWindow = WIN_GLES_SwapWindow;
|
||||
_this->GL_DeleteContext = WIN_GLES_DeleteContext;
|
||||
|
||||
if (WIN_GLES_LoadLibrary(_this, NULL) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return WIN_GLES_CreateContext(_this, window);
|
||||
}
|
||||
|
||||
if (_this->gl_config.share_with_current_context) {
|
||||
share_context = (HGLRC)SDL_GL_GetCurrentContext();
|
||||
} else {
|
||||
|
@ -622,8 +678,6 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
WIN_GL_InitExtensions(_this, hdc);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ struct SDL_GLDriverData
|
|||
{
|
||||
SDL_bool HAS_WGL_ARB_pixel_format;
|
||||
SDL_bool HAS_WGL_EXT_swap_control_tear;
|
||||
SDL_bool HAS_WGL_EXT_create_context_es2_profile;
|
||||
|
||||
void *(WINAPI * wglGetProcAddress) (const char *proc);
|
||||
HGLRC(WINAPI * wglCreateContext) (HDC hdc);
|
||||
|
@ -62,6 +63,7 @@ extern int WIN_GL_SetSwapInterval(_THIS, int interval);
|
|||
extern int WIN_GL_GetSwapInterval(_THIS);
|
||||
extern void WIN_GL_SwapWindow(_THIS, SDL_Window * window);
|
||||
extern void WIN_GL_DeleteContext(_THIS, SDL_GLContext context);
|
||||
extern void WIN_GL_InitExtensions(_THIS);
|
||||
|
||||
#ifndef WGL_ARB_pixel_format
|
||||
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
|
||||
|
|
141
src/video/windows/SDL_windowsopengles.c
Normal file
141
src/video/windows/SDL_windowsopengles.c
Normal file
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "SDL_windowsvideo.h"
|
||||
#include "SDL_windowsopengles.h"
|
||||
#include "SDL_windowsopengl.h"
|
||||
#include "SDL_log.h"
|
||||
|
||||
/* EGL implementation of SDL OpenGL support */
|
||||
|
||||
int
|
||||
WIN_GLES_LoadLibrary(_THIS, const char *path) {
|
||||
|
||||
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
|
||||
|
||||
/* If the profile requested is not GL ES, switch over to WIN_GL functions */
|
||||
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
#if SDL_VIDEO_OPENGL_WGL
|
||||
WIN_GLES_UnloadLibrary(_this);
|
||||
_this->GL_LoadLibrary = WIN_GL_LoadLibrary;
|
||||
_this->GL_GetProcAddress = WIN_GL_GetProcAddress;
|
||||
_this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
|
||||
_this->GL_CreateContext = WIN_GL_CreateContext;
|
||||
_this->GL_MakeCurrent = WIN_GL_MakeCurrent;
|
||||
_this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
|
||||
_this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
|
||||
_this->GL_SwapWindow = WIN_GL_SwapWindow;
|
||||
_this->GL_DeleteContext = WIN_GL_DeleteContext;
|
||||
return WIN_GL_LoadLibrary(_this, path);
|
||||
#else
|
||||
return SDL_SetError("SDL not configured with OpenGL/WGL support");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_this->egl_data == NULL) {
|
||||
return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_GLContext
|
||||
WIN_GLES_CreateContext(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_GLContext context;
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
|
||||
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
/* Switch to WGL based functions */
|
||||
WIN_GLES_UnloadLibrary(_this);
|
||||
_this->GL_LoadLibrary = WIN_GL_LoadLibrary;
|
||||
_this->GL_GetProcAddress = WIN_GL_GetProcAddress;
|
||||
_this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
|
||||
_this->GL_CreateContext = WIN_GL_CreateContext;
|
||||
_this->GL_MakeCurrent = WIN_GL_MakeCurrent;
|
||||
_this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
|
||||
_this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
|
||||
_this->GL_SwapWindow = WIN_GL_SwapWindow;
|
||||
_this->GL_DeleteContext = WIN_GL_DeleteContext;
|
||||
|
||||
if (WIN_GL_LoadLibrary(_this, NULL) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return WIN_GL_CreateContext(_this, window);
|
||||
}
|
||||
|
||||
context = SDL_EGL_CreateContext(_this, data->egl_surface);
|
||||
return context;
|
||||
}
|
||||
|
||||
void
|
||||
WIN_GLES_DeleteContext(_THIS, SDL_GLContext context)
|
||||
{
|
||||
SDL_EGL_DeleteContext(_this, context);
|
||||
WIN_GLES_UnloadLibrary(_this);
|
||||
}
|
||||
|
||||
SDL_EGL_SwapWindow_impl(WIN)
|
||||
SDL_EGL_MakeCurrent_impl(WIN)
|
||||
|
||||
int
|
||||
WIN_GLES_SetupWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
/* The current context is lost in here; save it and reset it. */
|
||||
SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
|
||||
SDL_Window *current_win = SDL_GL_GetCurrentWindow();
|
||||
SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
|
||||
|
||||
|
||||
if (_this->egl_data == NULL) {
|
||||
if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the GLES window surface */
|
||||
windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)windowdata->hwnd);
|
||||
|
||||
if (windowdata->egl_surface == EGL_NO_SURFACE) {
|
||||
return SDL_SetError("Could not create GLES window surface");
|
||||
}
|
||||
|
||||
return WIN_GLES_MakeCurrent(_this, current_win, current_ctx);
|
||||
}
|
||||
|
||||
int
|
||||
WIN_GLES_SetSwapInterval(_THIS, int interval)
|
||||
{
|
||||
/* FIXME: This should call SDL_EGL_SetSwapInterval, but ANGLE has a bug that prevents this
|
||||
* from working if we do (the window contents freeze and don't swap properly). So, we ignore
|
||||
* the request for now.
|
||||
*/
|
||||
SDL_Log("WARNING: Ignoring SDL_GL_SetSwapInterval call due to ANGLE bug");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
51
src/video/windows/SDL_windowsopengles.h
Normal file
51
src/video/windows/SDL_windowsopengles.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_winopengles_h
|
||||
#define _SDL_winopengles_h
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
/* OpenGLES functions */
|
||||
#define WIN_GLES_GetAttribute SDL_EGL_GetAttribute
|
||||
#define WIN_GLES_GetProcAddress SDL_EGL_GetProcAddress
|
||||
#define WIN_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
||||
#define WIN_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
||||
/* See the WIN_GLES_GetSwapInterval implementation to see why this is commented out */
|
||||
/*#define WIN_GLES_SetSwapInterval SDL_EGL_SetSwapInterval*/
|
||||
extern int WIN_GLES_SetSwapInterval(_THIS, int interval);
|
||||
|
||||
extern int WIN_GLES_LoadLibrary(_THIS, const char *path);
|
||||
extern SDL_GLContext WIN_GLES_CreateContext(_THIS, SDL_Window * window);
|
||||
extern void WIN_GLES_SwapWindow(_THIS, SDL_Window * window);
|
||||
extern int WIN_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
extern void WIN_GLES_DeleteContext(_THIS, SDL_GLContext context);
|
||||
extern int WIN_GLES_SetupWindow(_THIS, SDL_Window * window);
|
||||
|
||||
#endif /* SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
#endif /* _SDL_winopengles_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -44,6 +44,7 @@
|
|||
#include "SDL_windowsmodes.h"
|
||||
#include "SDL_windowsmouse.h"
|
||||
#include "SDL_windowsopengl.h"
|
||||
#include "SDL_windowsopengles.h"
|
||||
#include "SDL_windowswindow.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_loadso.h"
|
||||
|
|
|
@ -273,6 +273,32 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
|
|||
DestroyWindow(hwnd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_VIDEO_OPENGL_WGL
|
||||
/* We need to initialize the extensions before deciding how to create ES profiles */
|
||||
if (window->flags & SDL_WINDOW_OPENGL) {
|
||||
WIN_GL_InitExtensions(_this);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SDL_VIDEO_OPENGL_ES2
|
||||
if ((window->flags & SDL_WINDOW_OPENGL) &&
|
||||
_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
|
||||
#if SDL_VIDEO_OPENGL_WGL
|
||||
&& (!_this->gl_data || !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile)
|
||||
#endif
|
||||
) {
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
if (WIN_GLES_SetupWindow(_this, window) < 0) {
|
||||
WIN_DestroyWindow(_this, window);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
return SDL_SetError("Could not create GLES window surface (no EGL support available)");
|
||||
#endif /* SDL_VIDEO_OPENGL_EGL */
|
||||
} else
|
||||
#endif /* SDL_VIDEO_OPENGL_ES2 */
|
||||
|
||||
#if SDL_VIDEO_OPENGL_WGL
|
||||
if (window->flags & SDL_WINDOW_OPENGL) {
|
||||
if (WIN_GL_SetupWindow(_this, window) < 0) {
|
||||
|
@ -281,6 +307,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
#ifndef _SDL_windowswindow_h
|
||||
#define _SDL_windowswindow_h
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
#include "../SDL_egl_c.h"
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_Window *window;
|
||||
|
@ -35,6 +39,9 @@ typedef struct
|
|||
WPARAM mouse_button_flags;
|
||||
BOOL expected_resize;
|
||||
struct SDL_VideoData *videodata;
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
} SDL_WindowData;
|
||||
|
||||
extern int WIN_CreateWindow(_THIS, SDL_Window * window);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#if SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
typedef struct SDL_PrivateGLESData
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue