mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-09 20:24:14 +00:00
[client] opengl: implement & fix opengl support
This commit is contained in:
@@ -22,7 +22,9 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_syswm.h>
|
||||
|
||||
#ifdef ENABLE_EGL
|
||||
#include <EGL/eglext.h>
|
||||
#endif
|
||||
|
||||
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
|
||||
#include <wayland-egl.h>
|
||||
@@ -58,6 +60,13 @@ static bool sdlProbe(void)
|
||||
|
||||
static bool sdlEarlyInit(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool sdlInit(const LG_DSInitParams params)
|
||||
{
|
||||
memset(&sdl, 0, sizeof(sdl));
|
||||
|
||||
// Allow screensavers for now: we will enable and disable as needed.
|
||||
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
|
||||
|
||||
@@ -67,12 +76,15 @@ static bool sdlEarlyInit(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool sdlInit(const LG_DSInitParams params)
|
||||
{
|
||||
memset(&sdl, 0, sizeof(sdl));
|
||||
if (params.opengl)
|
||||
{
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER , 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE , 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE , 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE , 8);
|
||||
}
|
||||
|
||||
sdl.window = SDL_CreateWindow(
|
||||
params.title,
|
||||
@@ -84,14 +96,15 @@ static bool sdlInit(const LG_DSInitParams params)
|
||||
SDL_WINDOW_HIDDEN |
|
||||
(params.resizable ? SDL_WINDOW_RESIZABLE : 0) |
|
||||
(params.borderless ? SDL_WINDOW_BORDERLESS : 0) |
|
||||
(params.maximize ? SDL_WINDOW_MAXIMIZED : 0)
|
||||
(params.maximize ? SDL_WINDOW_MAXIMIZED : 0) |
|
||||
(params.opengl ? SDL_WINDOW_OPENGL : 0)
|
||||
)
|
||||
);
|
||||
|
||||
if (sdl.window == NULL)
|
||||
{
|
||||
DEBUG_ERROR("Could not create an SDL window: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
goto fail_init;
|
||||
}
|
||||
|
||||
const uint8_t data[4] = {0xf, 0x9, 0x9, 0xf};
|
||||
@@ -115,6 +128,10 @@ static bool sdlInit(const LG_DSInitParams params)
|
||||
|
||||
SDL_SetEventFilter(sdlEventFilter, NULL);
|
||||
return true;
|
||||
|
||||
fail_init:
|
||||
SDL_Quit();
|
||||
return false;
|
||||
}
|
||||
|
||||
static void sdlStartup(void)
|
||||
@@ -123,11 +140,12 @@ static void sdlStartup(void)
|
||||
|
||||
static void sdlShutdown(void)
|
||||
{
|
||||
SDL_DestroyWindow(sdl.window);
|
||||
}
|
||||
|
||||
static void sdlFree(void)
|
||||
{
|
||||
SDL_DestroyWindow(sdl.window);
|
||||
|
||||
if (sdl.cursor)
|
||||
SDL_FreeCursor(sdl.cursor);
|
||||
|
||||
@@ -234,9 +252,29 @@ static void sdlEGLSwapBuffers(EGLDisplay display, EGLSurface surface)
|
||||
{
|
||||
eglSwapBuffers(display, surface);
|
||||
}
|
||||
#endif
|
||||
#endif //ENABLE_EGL
|
||||
|
||||
static void sdlSwapBuffers(void)
|
||||
static LG_DSGLContext sdlGLCreateContext(void)
|
||||
{
|
||||
return (LG_DSGLContext)SDL_GL_CreateContext(sdl.window);
|
||||
}
|
||||
|
||||
static void sdlGLDeleteContext(LG_DSGLContext context)
|
||||
{
|
||||
SDL_GL_DeleteContext((SDL_GLContext)context);
|
||||
}
|
||||
|
||||
static void sdlGLMakeCurrent(LG_DSGLContext context)
|
||||
{
|
||||
SDL_GL_MakeCurrent(sdl.window, (SDL_GLContext)context);
|
||||
}
|
||||
|
||||
static void sdlGLSetSwapInterval(int interval)
|
||||
{
|
||||
SDL_GL_SetSwapInterval(interval);
|
||||
}
|
||||
|
||||
static void sdlGLSwapBuffers(void)
|
||||
{
|
||||
SDL_GL_SwapWindow(sdl.window);
|
||||
}
|
||||
@@ -334,8 +372,9 @@ static int sdlEventFilter(void * userdata, SDL_Event * event)
|
||||
&border.bottom,
|
||||
&border.right
|
||||
);
|
||||
|
||||
app_handleResizeEvent(event->window.data1, event->window.data2,
|
||||
app_handleResizeEvent(
|
||||
event->window.data1,
|
||||
event->window.data2,
|
||||
border);
|
||||
break;
|
||||
}
|
||||
@@ -478,7 +517,11 @@ struct LG_DisplayServerOps LGDS_SDL =
|
||||
.eglSwapBuffers = sdlEGLSwapBuffers,
|
||||
#endif
|
||||
|
||||
.glSwapBuffers = sdlSwapBuffers,
|
||||
.glCreateContext = sdlGLCreateContext,
|
||||
.glDeleteContext = sdlGLDeleteContext,
|
||||
.glMakeCurrent = sdlGLMakeCurrent,
|
||||
.glSetSwapInterval = sdlGLSetSwapInterval,
|
||||
.glSwapBuffers = sdlGLSwapBuffers,
|
||||
|
||||
.showPointer = sdlShowPointer,
|
||||
.grabPointer = sdlGrabPointer,
|
||||
|
@@ -14,6 +14,8 @@ add_library(displayserver_X11 STATIC
|
||||
x11.c
|
||||
)
|
||||
|
||||
add_definitions(-D GLX_GLXEXT_PROTOTYPES)
|
||||
|
||||
target_link_libraries(displayserver_X11
|
||||
${DISPLAYSERVER_X11_PKGCONFIG_LIBRARIES}
|
||||
lg_common
|
||||
|
@@ -31,10 +31,14 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glxext.h>
|
||||
|
||||
#ifdef ENABLE_EGL
|
||||
#include <EGL/eglext.h>
|
||||
#include "egl_dynprocs.h"
|
||||
#endif
|
||||
|
||||
#include "app.h"
|
||||
#include "egl_dynprocs.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/thread.h"
|
||||
|
||||
@@ -44,9 +48,10 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
struct X11DSState
|
||||
{
|
||||
Display * display;
|
||||
Window window;
|
||||
int xinputOp;
|
||||
Display * display;
|
||||
Window window;
|
||||
XVisualInfo * visual;
|
||||
int xinputOp;
|
||||
|
||||
LGThread * eventThread;
|
||||
|
||||
@@ -137,6 +142,36 @@ static bool x11Init(const LG_DSInitParams params)
|
||||
PropertyChangeMask |
|
||||
ExposureMask
|
||||
};
|
||||
unsigned long swaMask = CWEventMask;
|
||||
|
||||
if (params.opengl)
|
||||
{
|
||||
GLint glXAttribs[] =
|
||||
{
|
||||
GLX_RGBA,
|
||||
GLX_DEPTH_SIZE , 24,
|
||||
GLX_STENCIL_SIZE , 0,
|
||||
GLX_RED_SIZE , 8,
|
||||
GLX_GREEN_SIZE , 8,
|
||||
GLX_BLUE_SIZE , 8,
|
||||
GLX_SAMPLE_BUFFERS, 0,
|
||||
GLX_SAMPLES , 0,
|
||||
None
|
||||
};
|
||||
|
||||
x11.visual = glXChooseVisual(x11.display,
|
||||
XDefaultScreen(x11.display), glXAttribs);
|
||||
|
||||
if (!x11.visual)
|
||||
{
|
||||
DEBUG_ERROR("glXChooseVisual failed");
|
||||
goto fail_display;
|
||||
}
|
||||
|
||||
swa.colormap = XCreateColormap(x11.display, XDefaultRootWindow(x11.display),
|
||||
x11.visual->visual, AllocNone);
|
||||
swaMask |= CWColormap;
|
||||
}
|
||||
|
||||
x11.window = XCreateWindow(
|
||||
x11.display,
|
||||
@@ -144,8 +179,10 @@ static bool x11Init(const LG_DSInitParams params)
|
||||
params.x, params.y,
|
||||
params.w, params.h,
|
||||
0,
|
||||
CopyFromParent, InputOutput,
|
||||
CopyFromParent, CWEventMask,
|
||||
x11.visual ? x11.visual->depth : CopyFromParent,
|
||||
InputOutput,
|
||||
x11.visual ? x11.visual->visual : CopyFromParent,
|
||||
swaMask,
|
||||
&swa);
|
||||
|
||||
if (!x11.window)
|
||||
@@ -835,6 +872,27 @@ static void x11EGLSwapBuffers(EGLDisplay display, EGLSurface surface)
|
||||
}
|
||||
#endif
|
||||
|
||||
static LG_DSGLContext x11GLCreateContext(void)
|
||||
{
|
||||
return (LG_DSGLContext)
|
||||
glXCreateContext(x11.display, x11.visual, NULL, GL_TRUE);
|
||||
}
|
||||
|
||||
static void x11GLDeleteContext(LG_DSGLContext context)
|
||||
{
|
||||
glXDestroyContext(x11.display, (GLXContext)context);
|
||||
}
|
||||
|
||||
static void x11GLMakeCurrent(LG_DSGLContext context)
|
||||
{
|
||||
glXMakeCurrent(x11.display, x11.window, (GLXContext)context);
|
||||
}
|
||||
|
||||
static void x11GLSetSwapInterval(int interval)
|
||||
{
|
||||
glXSwapIntervalEXT(x11.display, x11.window, interval);
|
||||
}
|
||||
|
||||
static void x11GLSwapBuffers(void)
|
||||
{
|
||||
glXSwapBuffers(x11.display, x11.window);
|
||||
@@ -1391,6 +1449,10 @@ struct LG_DisplayServerOps LGDS_X11 =
|
||||
.getEGLNativeWindow = x11GetEGLNativeWindow,
|
||||
.eglSwapBuffers = x11EGLSwapBuffers,
|
||||
#endif
|
||||
.glCreateContext = x11GLCreateContext,
|
||||
.glDeleteContext = x11GLDeleteContext,
|
||||
.glMakeCurrent = x11GLMakeCurrent,
|
||||
.glSetSwapInterval = x11GLSetSwapInterval,
|
||||
.glSwapBuffers = x11GLSwapBuffers,
|
||||
.showPointer = x11ShowPointer,
|
||||
.grabPointer = x11GrabPointer,
|
||||
|
Reference in New Issue
Block a user