Update API + example
This commit is contained in:
85
src/rendering_EGL.c
Normal file
85
src/rendering_EGL.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "instance.h"
|
||||
#include "frame.h"
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "lvrc_internal.h"
|
||||
|
||||
#include "context.inl"
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
bool lvrcInitRenderingEGL(struct lvrcInstance * instance, EGLDisplay user_display, EGLContext user_context, EGLSurface user_surface)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
if (!internalInstance->device)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static const EGLint attribs[] =
|
||||
{
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
//EGL_ALPHA_SIZE, 8,
|
||||
//EGL_DEPTH_SIZE, 16,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
static const EGLint context_attributes[] =
|
||||
{
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
//
|
||||
// Get Native Display
|
||||
EGLNativeDisplayType nativeDisplay = internalInstance->device;
|
||||
|
||||
if (!nativeDisplay)
|
||||
{
|
||||
fprintf(stderr, "invalid native display\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Native Window
|
||||
EGLNativeWindowType nativeWindow = internalInstance->surface;
|
||||
|
||||
if (!nativeWindow)
|
||||
{
|
||||
fprintf(stderr, "invalid native window\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
EGLDisplay display;
|
||||
EGLSurface surface;
|
||||
EGLContext context;
|
||||
|
||||
bool bContextCreated = create_context(EGL_PLATFORM_GBM_KHR, nativeDisplay, nativeWindow, attribs, context_attributes, NULL, &display, &context, &surface);
|
||||
|
||||
if (!bContextCreated)
|
||||
{
|
||||
fprintf(stderr, "couldn't create compositor context\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
InitFrameResources(internalInstance);
|
||||
|
||||
internalInstance->vr_display = display;
|
||||
internalInstance->vr_context = context;
|
||||
internalInstance->vr_surface = surface;
|
||||
|
||||
internalInstance->user_display = user_display;
|
||||
internalInstance->user_context = user_context;
|
||||
internalInstance->user_surface = user_surface;
|
||||
|
||||
eglMakeCurrent(user_display, user_surface, user_surface, user_context);
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user