Wayland support
Based on the original port to Wayland by: Joel Teichroeb, Benjamin Franzke, Scott Moreau, et al. Additional changes in this commit, done by me: * Wayland uses the common EGL framework * EGL can now create a desktop OpenGL context * testgl2 loads GL functions dynamically, no need to link to libGL anymore * Assorted fixes to the Wayland backend Tested on the Weston Compositor (v1.0.5) that ships with Ubuntu 13.10, running Weston under X. Tests ran: testrendercopyex (all backends), testgl2, testgles2,testintersections
This commit is contained in:
parent
4a8c296712
commit
ec1cb49eab
25 changed files with 2035 additions and 129 deletions
|
@ -128,13 +128,13 @@ testgesture$(EXE): $(srcdir)/testgesture.c
|
|||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testgl2$(EXE): $(srcdir)/testgl2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testgles$(EXE): $(srcdir)/testgles.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLESLIB@ @MATHLIB@
|
||||
|
||||
testgles2$(EXE): $(srcdir)/testgles2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLES2LIB@ @MATHLIB@
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testhaptic$(EXE): $(srcdir)/testhaptic.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
|
238
test/testgl2.c
238
test/testgl2.c
|
@ -24,11 +24,48 @@
|
|||
|
||||
#include "SDL_opengl.h"
|
||||
|
||||
typedef struct GL_Context
|
||||
{
|
||||
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
||||
#include "../src/render/opengl/SDL_glfuncs.h"
|
||||
#undef SDL_PROC
|
||||
} GL_Context;
|
||||
|
||||
|
||||
/* Undefine this if you want a flat cube instead of a rainbow cube */
|
||||
#define SHADED_CUBE
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_GLContext context;
|
||||
static GL_Context ctx;
|
||||
|
||||
static int LoadContext(GL_Context * data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_ANDROID
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_PANDORA
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#endif
|
||||
|
||||
#if defined __SDL_NOGETPROCADDR__
|
||||
#define SDL_PROC(ret,func,params) data->func=func;
|
||||
#else
|
||||
#define SDL_PROC(ret,func,params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
#endif /* _SDL_NOGETPROCADDR_ */
|
||||
|
||||
#include "../src/render/opengl/SDL_glfuncs.h"
|
||||
#undef SDL_PROC
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
|
@ -67,107 +104,107 @@ Render()
|
|||
};
|
||||
|
||||
/* Do our drawing, too. */
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
ctx.glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
ctx.glBegin(GL_QUADS);
|
||||
|
||||
#ifdef SHADED_CUBE
|
||||
glColor3fv(color[0]);
|
||||
glVertex3fv(cube[0]);
|
||||
glColor3fv(color[1]);
|
||||
glVertex3fv(cube[1]);
|
||||
glColor3fv(color[2]);
|
||||
glVertex3fv(cube[2]);
|
||||
glColor3fv(color[3]);
|
||||
glVertex3fv(cube[3]);
|
||||
ctx.glColor3fv(color[0]);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glColor3fv(color[1]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
ctx.glColor3fv(color[2]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glColor3fv(color[3]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
|
||||
glColor3fv(color[3]);
|
||||
glVertex3fv(cube[3]);
|
||||
glColor3fv(color[4]);
|
||||
glVertex3fv(cube[4]);
|
||||
glColor3fv(color[7]);
|
||||
glVertex3fv(cube[7]);
|
||||
glColor3fv(color[2]);
|
||||
glVertex3fv(cube[2]);
|
||||
ctx.glColor3fv(color[3]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
ctx.glColor3fv(color[4]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
ctx.glColor3fv(color[7]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
ctx.glColor3fv(color[2]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
|
||||
glColor3fv(color[0]);
|
||||
glVertex3fv(cube[0]);
|
||||
glColor3fv(color[5]);
|
||||
glVertex3fv(cube[5]);
|
||||
glColor3fv(color[6]);
|
||||
glVertex3fv(cube[6]);
|
||||
glColor3fv(color[1]);
|
||||
glVertex3fv(cube[1]);
|
||||
ctx.glColor3fv(color[0]);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glColor3fv(color[5]);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glColor3fv(color[6]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
ctx.glColor3fv(color[1]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
|
||||
glColor3fv(color[5]);
|
||||
glVertex3fv(cube[5]);
|
||||
glColor3fv(color[4]);
|
||||
glVertex3fv(cube[4]);
|
||||
glColor3fv(color[7]);
|
||||
glVertex3fv(cube[7]);
|
||||
glColor3fv(color[6]);
|
||||
glVertex3fv(cube[6]);
|
||||
ctx.glColor3fv(color[5]);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glColor3fv(color[4]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
ctx.glColor3fv(color[7]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
ctx.glColor3fv(color[6]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
|
||||
glColor3fv(color[5]);
|
||||
glVertex3fv(cube[5]);
|
||||
glColor3fv(color[0]);
|
||||
glVertex3fv(cube[0]);
|
||||
glColor3fv(color[3]);
|
||||
glVertex3fv(cube[3]);
|
||||
glColor3fv(color[4]);
|
||||
glVertex3fv(cube[4]);
|
||||
ctx.glColor3fv(color[5]);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glColor3fv(color[0]);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glColor3fv(color[3]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
ctx.glColor3fv(color[4]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
|
||||
glColor3fv(color[6]);
|
||||
glVertex3fv(cube[6]);
|
||||
glColor3fv(color[1]);
|
||||
glVertex3fv(cube[1]);
|
||||
glColor3fv(color[2]);
|
||||
glVertex3fv(cube[2]);
|
||||
glColor3fv(color[7]);
|
||||
glVertex3fv(cube[7]);
|
||||
ctx.glColor3fv(color[6]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
ctx.glColor3fv(color[1]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
ctx.glColor3fv(color[2]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glColor3fv(color[7]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
#else /* flat cube */
|
||||
glColor3f(1.0, 0.0, 0.0);
|
||||
glVertex3fv(cube[0]);
|
||||
glVertex3fv(cube[1]);
|
||||
glVertex3fv(cube[2]);
|
||||
glVertex3fv(cube[3]);
|
||||
ctx.glColor3f(1.0, 0.0, 0.0);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
|
||||
glColor3f(0.0, 1.0, 0.0);
|
||||
glVertex3fv(cube[3]);
|
||||
glVertex3fv(cube[4]);
|
||||
glVertex3fv(cube[7]);
|
||||
glVertex3fv(cube[2]);
|
||||
ctx.glColor3f(0.0, 1.0, 0.0);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
|
||||
glColor3f(0.0, 0.0, 1.0);
|
||||
glVertex3fv(cube[0]);
|
||||
glVertex3fv(cube[5]);
|
||||
glVertex3fv(cube[6]);
|
||||
glVertex3fv(cube[1]);
|
||||
ctx.glColor3f(0.0, 0.0, 1.0);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
|
||||
glColor3f(0.0, 1.0, 1.0);
|
||||
glVertex3fv(cube[5]);
|
||||
glVertex3fv(cube[4]);
|
||||
glVertex3fv(cube[7]);
|
||||
glVertex3fv(cube[6]);
|
||||
ctx.glColor3f(0.0, 1.0, 1.0);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
|
||||
glColor3f(1.0, 1.0, 0.0);
|
||||
glVertex3fv(cube[5]);
|
||||
glVertex3fv(cube[0]);
|
||||
glVertex3fv(cube[3]);
|
||||
glVertex3fv(cube[4]);
|
||||
ctx.glColor3f(1.0, 1.0, 0.0);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
|
||||
glColor3f(1.0, 0.0, 1.0);
|
||||
glVertex3fv(cube[6]);
|
||||
glVertex3fv(cube[1]);
|
||||
glVertex3fv(cube[2]);
|
||||
glVertex3fv(cube[7]);
|
||||
ctx.glColor3f(1.0, 0.0, 1.0);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
#endif /* SHADED_CUBE */
|
||||
|
||||
glEnd();
|
||||
ctx.glEnd();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glRotatef(5.0, 1.0, 1.0, 1.0);
|
||||
ctx.glMatrixMode(GL_MODELVIEW);
|
||||
ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -242,6 +279,13 @@ main(int argc, char *argv[])
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* Important: call this *after* creating the context */
|
||||
if (LoadContext(&ctx) < 0) {
|
||||
SDL_Log("Could not load GL functions\n");
|
||||
quit(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||
/* try late-swap-tearing first. If not supported, try normal vsync. */
|
||||
|
@ -260,10 +304,10 @@ main(int argc, char *argv[])
|
|||
SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
|
||||
SDL_Log("Draw Size : %d,%d\n", dw, dh);
|
||||
SDL_Log("\n");
|
||||
SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
|
||||
SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
|
||||
SDL_Log("Version : %s\n", glGetString(GL_VERSION));
|
||||
SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
|
||||
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
|
||||
SDL_Log("Renderer : %s\n", ctx.glGetString(GL_RENDERER));
|
||||
SDL_Log("Version : %s\n", ctx.glGetString(GL_VERSION));
|
||||
SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS));
|
||||
SDL_Log("\n");
|
||||
|
||||
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
|
||||
|
@ -319,14 +363,14 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Set rendering settings */
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
ctx.glMatrixMode(GL_PROJECTION);
|
||||
ctx.glLoadIdentity();
|
||||
ctx.glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
|
||||
ctx.glMatrixMode(GL_MODELVIEW);
|
||||
ctx.glLoadIdentity();
|
||||
ctx.glEnable(GL_DEPTH_TEST);
|
||||
ctx.glDepthFunc(GL_LESS);
|
||||
ctx.glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
|
@ -344,7 +388,7 @@ main(int argc, char *argv[])
|
|||
continue;
|
||||
SDL_GL_MakeCurrent(state->windows[i], context);
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
glViewport(0, 0, w, h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
Render();
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue