Update VR context creation
This commit is contained in:
@@ -10,14 +10,14 @@
|
||||
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "context.inl"
|
||||
|
||||
static EGLDisplay display;
|
||||
static EGLSurface surface;
|
||||
static EGLContext context;
|
||||
|
||||
static void create_vr_context(struct lvrcInstance * compositor)
|
||||
static const EGLint attribs[] =
|
||||
{
|
||||
static const EGLint attribs[] =
|
||||
{
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
@@ -26,98 +26,13 @@ static void create_vr_context(struct lvrcInstance * compositor)
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
};
|
||||
|
||||
static const EGLint context_attributes[] =
|
||||
{
|
||||
static const EGLint context_attributes[] =
|
||||
{
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
//
|
||||
// Get Native Display
|
||||
EGLNativeDisplayType nativeDisplay = lvrcSwapChainGetNativeDisplay(compositor);
|
||||
|
||||
if (!nativeDisplay)
|
||||
{
|
||||
fprintf(stderr, "invalid native display\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//
|
||||
// get an EGL display connection
|
||||
display = eglGetDisplay(nativeDisplay);
|
||||
|
||||
if (EGL_NO_DISPLAY == display)
|
||||
{
|
||||
fprintf(stderr, "eglGetDisplay() failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//
|
||||
// initialize the EGL display connection
|
||||
EGLint major, minor;
|
||||
|
||||
if (!eglInitialize(display, &major, &minor))
|
||||
{
|
||||
fprintf(stderr, "eglInitialize() failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//
|
||||
// bind OpenGL API
|
||||
eglBindAPI(EGL_OPENGL_API);
|
||||
|
||||
//
|
||||
// get an appropriate EGL frame buffer configuration
|
||||
EGLint num_config;
|
||||
EGLConfig configs[128];
|
||||
|
||||
if (!eglChooseConfig(display, attribs, configs, 128, &num_config))
|
||||
{
|
||||
fprintf(stderr, "eglChooseConfig() failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
EGLConfig config = configs[0]; // FIXME
|
||||
|
||||
//
|
||||
// create context
|
||||
context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attributes);
|
||||
|
||||
if (EGL_NO_CONTEXT == context)
|
||||
{
|
||||
fprintf(stderr, "failed to create context\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//
|
||||
// Get Native Window
|
||||
EGLNativeWindowType nativeWindow = lvrcSwapChainGetNativeWindow(compositor);
|
||||
|
||||
if (!nativeWindow)
|
||||
{
|
||||
fprintf(stderr, "invalid native window\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//
|
||||
// Create Surface
|
||||
surface = eglCreateWindowSurface(display, config, nativeWindow, NULL);
|
||||
if (EGL_NO_SURFACE == surface)
|
||||
{
|
||||
fprintf(stderr, "eglCreateWindowSurface() failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//
|
||||
// Set current context
|
||||
if (!eglMakeCurrent(display, surface, surface, context))
|
||||
{
|
||||
fprintf(stderr, "failed to make context current\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GLuint left_color_tex = 0;
|
||||
GLuint right_color_tex = 0;
|
||||
@@ -132,7 +47,33 @@ void init_vr_context(struct lvrcInstance * compositor, dma_texture_params * left
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
create_vr_context(compositor);
|
||||
//
|
||||
// Get Native Display
|
||||
EGLNativeDisplayType nativeDisplay = lvrcSwapChainGetNativeDisplay(compositor);
|
||||
|
||||
if (!nativeDisplay)
|
||||
{
|
||||
fprintf(stderr, "invalid native display\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//
|
||||
// Get Native Window
|
||||
EGLNativeWindowType nativeWindow = lvrcSwapChainGetNativeWindow(compositor);
|
||||
|
||||
if (!nativeWindow)
|
||||
{
|
||||
fprintf(stderr, "invalid native window\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
bool bContextCreated = create_context(nativeDisplay, nativeWindow, attribs, context_attributes, NULL, &display, &context, &surface);
|
||||
|
||||
if (!bContextCreated)
|
||||
{
|
||||
fprintf(stderr, "couldn't create compositor context\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress ("glEGLImageTargetTexture2DOES");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user