Refactoring
This commit is contained in:
@@ -43,4 +43,8 @@ LVRC_API bool lvrcEndFrame(struct lvrcInstance * state);
|
||||
# include "lvrc_EGL.h"
|
||||
#endif // __egl_h_
|
||||
|
||||
#ifdef GLX_H
|
||||
# include "lvrc_GLX.h"
|
||||
#endif // GLX_H
|
||||
|
||||
#endif // LINUX_VR_COMPOSITOR_H
|
||||
|
||||
14
include/lvrc_GLX.h
Normal file
14
include/lvrc_GLX.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef LINUX_VR_COMPOSITOR_GLX_H
|
||||
#define LINUX_VR_COMPOSITOR_GLX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
LVRC_API bool lvrcInitRenderingGLX(struct lvrcInstance * state, Display* display, GLXDrawable drawable, GLXContext context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LINUX_VR_COMPOSITOR_GLX_H
|
||||
@@ -7,7 +7,7 @@ set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(OpenHMD REQUIRED)
|
||||
|
||||
add_library(lvrc ../include/lvrc.h ../include/lvrc_EGL.h lvrc.c lvrc_internal.h instance.c instance.h swapChain.c swapChain.h frame.c frame.h rendering_EGL.c)
|
||||
add_library(lvrc ../include/lvrc.h ../include/lvrc_EGL.h ../include/lvrc_GLX.h lvrc.c lvrc_EGL.c lvrc_GLX.c backend.c backend.h instance.c instance.h OpenGL/swapChain.c OpenGL/context.inl OpenGL/init.c OpenGL/resources.c OpenGL/data.h)
|
||||
|
||||
target_link_libraries(lvrc PUBLIC openhmd ${OPENGL_LIBRARIES} EGL)
|
||||
target_link_libraries(lvrc PUBLIC "${DRM_LIBRARY}" "gbm")
|
||||
|
||||
69
src/OpenGL/context.inl
Normal file
69
src/OpenGL/context.inl
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <EGL/egl.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static inline bool create_context(EGLenum platform, EGLNativeDisplayType nativeDisplay, EGLNativeWindowType nativeWindow, const EGLint * config_attribs, const EGLint * context_attribs, const EGLint * surface_attribs, EGLDisplay * outDisplay, EGLContext * outContext, EGLSurface * outSurface)
|
||||
{
|
||||
//
|
||||
// get an EGL display connection
|
||||
EGLDisplay display = eglGetPlatformDisplay(platform, nativeDisplay, (EGLAttrib*)0);
|
||||
|
||||
if (EGL_NO_DISPLAY == display)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// initialize the EGL display connection
|
||||
EGLint major, minor;
|
||||
|
||||
if (!eglInitialize(display, &major, &minor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// bind OpenGL API
|
||||
eglBindAPI(EGL_OPENGL_API);
|
||||
|
||||
//
|
||||
// get an appropriate EGL frame buffer configuration
|
||||
EGLint num_config;
|
||||
EGLConfig configs[128];
|
||||
|
||||
if (!eglChooseConfig(display, config_attribs, configs, 128, &num_config))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EGLConfig config = configs[0]; // FIXME
|
||||
|
||||
//
|
||||
// create context
|
||||
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribs);
|
||||
|
||||
if (EGL_NO_CONTEXT == context)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Surface
|
||||
EGLSurface surface = eglCreateWindowSurface(display, config, nativeWindow, surface_attribs);
|
||||
if (EGL_NO_SURFACE == surface)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Set current context
|
||||
if (!eglMakeCurrent(display, surface, surface, context))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
*outDisplay = display;
|
||||
*outContext = context;
|
||||
*outSurface = surface;
|
||||
|
||||
return true;
|
||||
}
|
||||
13
src/OpenGL/data.h
Normal file
13
src/OpenGL/data.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
struct data
|
||||
{
|
||||
EGLDisplay vr_display;
|
||||
EGLContext vr_context;
|
||||
EGLSurface vr_surface;
|
||||
|
||||
GLuint textures [2];
|
||||
};
|
||||
78
src/OpenGL/init.c
Normal file
78
src/OpenGL/init.c
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "../instance.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "context.inl"
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
#include "data.h"
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
extern bool InitFrameResources(Instance * instance);
|
||||
extern void OpenGL_Compose(Instance * instance);
|
||||
extern bool OpenGL_InitSwapChainEGL(Instance * instance, unsigned int width, unsigned int height, void * textures);
|
||||
extern bool OpenGL_ReleaseSwapChain(Instance * instance);
|
||||
|
||||
bool init_OpenGL_backend(Instance * instance)
|
||||
{
|
||||
//
|
||||
// Save context
|
||||
EGLDisplay old_display = eglGetCurrentDisplay();
|
||||
EGLSurface old_surface_draw = eglGetCurrentSurface(EGL_DRAW);
|
||||
EGLSurface old_surface_read = eglGetCurrentSurface(EGL_READ);
|
||||
EGLContext old_context = eglGetCurrentContext();
|
||||
|
||||
EGLNativeDisplayType nativeDisplay = instance->device;
|
||||
EGLNativeWindowType nativeWindow = instance->surface;
|
||||
|
||||
EGLDisplay display = EGL_NO_DISPLAY;
|
||||
EGLSurface surface = EGL_NO_SURFACE;
|
||||
EGLContext context = EGL_NO_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(instance);
|
||||
|
||||
struct data * data = calloc(1, sizeof(struct data));
|
||||
|
||||
data->vr_display = display;
|
||||
data->vr_context = context;
|
||||
data->vr_surface = surface;
|
||||
|
||||
instance->backend.Compose = OpenGL_Compose;
|
||||
instance->backend.InitSwapChainEGL = OpenGL_InitSwapChainEGL;
|
||||
instance->backend.ReleaseSwapChain = OpenGL_ReleaseSwapChain;
|
||||
instance->backend.data = data;
|
||||
|
||||
//
|
||||
// Restore context
|
||||
eglMakeCurrent(old_display, old_surface_draw, old_surface_read, old_context);
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
#include "frame.h"
|
||||
|
||||
#include "lvrc_internal.h"
|
||||
#include "instance.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <openhmd.h>
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
#include "../instance.h"
|
||||
|
||||
#include "data.h"
|
||||
|
||||
#define USE_ES_SHADERS 1
|
||||
|
||||
static const GLfloat textureVertices[] =
|
||||
@@ -144,11 +148,6 @@ bool InitFrameResources(Instance * instance)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lvrcBeginFrame(struct lvrcInstance * state)
|
||||
{
|
||||
return true; // nothing yet
|
||||
}
|
||||
|
||||
static void prepare(GLuint texture)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
@@ -170,17 +169,15 @@ static void draw()
|
||||
assert(GL_NO_ERROR == glGetError());
|
||||
}
|
||||
|
||||
bool lvrcSubmitFrameLeft(struct lvrcInstance * instance, GLuint texture)
|
||||
static bool SubmitFrameLeft(Instance * instance, GLuint texture)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
if (!internalInstance->mode)
|
||||
if (!instance->mode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int hmd_w = internalInstance->mode->hdisplay;
|
||||
unsigned int hmd_h = internalInstance->mode->vdisplay;
|
||||
unsigned int hmd_w = instance->mode->hdisplay;
|
||||
unsigned int hmd_h = instance->mode->vdisplay;
|
||||
|
||||
prepare(texture);
|
||||
|
||||
@@ -194,17 +191,15 @@ bool lvrcSubmitFrameLeft(struct lvrcInstance * instance, GLuint texture)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lvrcSubmitFrameRight(struct lvrcInstance * instance, GLuint texture)
|
||||
static bool SubmitFrameRight(Instance * instance, GLuint texture)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
if (!internalInstance->mode)
|
||||
if (!instance->mode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int hmd_w = internalInstance->mode->hdisplay;
|
||||
unsigned int hmd_h = internalInstance->mode->vdisplay;
|
||||
unsigned int hmd_w = instance->mode->hdisplay;
|
||||
unsigned int hmd_h = instance->mode->vdisplay;
|
||||
|
||||
prepare(texture);
|
||||
|
||||
@@ -218,18 +213,15 @@ bool lvrcSubmitFrameRight(struct lvrcInstance * instance, GLuint texture)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lvrcEndFrame(struct lvrcInstance * instance)
|
||||
void OpenGL_Compose(Instance * instance)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
struct data * data = instance->backend.data;
|
||||
|
||||
eglMakeCurrent(internalInstance->vr_display, internalInstance->vr_surface, internalInstance->vr_surface, internalInstance->vr_context);
|
||||
eglMakeCurrent(data->vr_display, data->vr_surface, data->vr_surface, data->vr_context);
|
||||
|
||||
lvrcSubmitFrameLeft(instance, internalInstance->textures[0]);
|
||||
lvrcSubmitFrameRight(instance, internalInstance->textures[1]);
|
||||
SubmitFrameLeft(instance, data->textures[0]);
|
||||
SubmitFrameRight(instance, data->textures[1]);
|
||||
|
||||
eglSwapBuffers(internalInstance->vr_display, internalInstance->vr_surface);
|
||||
eglSwapBuffers(data->vr_display, data->vr_surface);
|
||||
|
||||
SwapBuffers(internalInstance);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "swapChain.h"
|
||||
|
||||
#include "lvrc_internal.h"
|
||||
#include "instance.h"
|
||||
#include "../instance.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gbm.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "context.inl"
|
||||
|
||||
#include "frame.h"
|
||||
#include "data.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -26,15 +26,21 @@ typedef struct
|
||||
EGLuint64KHR modifiers;
|
||||
} dma_texture_params;
|
||||
|
||||
bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsigned int height, GLuint * textures)
|
||||
#define USE_GBM 0 // just a test
|
||||
|
||||
bool OpenGL_InitSwapChainEGL(Instance * instance, unsigned int width, unsigned int height, GLuint * textures)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
if (!internalInstance->user_context || !internalInstance->vr_context)
|
||||
struct data * data = internalInstance->backend.data;
|
||||
|
||||
if (!internalInstance->user_context || !data->vr_context)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Save context
|
||||
EGLDisplay old_display = eglGetCurrentDisplay();
|
||||
EGLSurface old_surface_draw = eglGetCurrentSurface(EGL_DRAW);
|
||||
EGLSurface old_surface_read = eglGetCurrentSurface(EGL_READ);
|
||||
@@ -64,11 +70,31 @@ bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsig
|
||||
return false;
|
||||
}
|
||||
|
||||
#if USE_GBM
|
||||
int fd = open("/dev/dri/renderD129", O_RDWR);
|
||||
struct gbm_device * device = gbm_create_device(fd);
|
||||
|
||||
EGLDisplay display = eglGetPlatformDisplay(EGL_PLATFORM_GBM_KHR, device, (EGLAttrib*)0);
|
||||
|
||||
EGLint major, minor;
|
||||
eglInitialize(display, &major, &minor);
|
||||
|
||||
eglBindAPI(EGL_OPENGL_API);
|
||||
|
||||
#else
|
||||
EGLDisplay display = internalInstance->user_display;
|
||||
#endif // USE_GBM
|
||||
|
||||
//
|
||||
// Create and export left image
|
||||
//
|
||||
|
||||
#if USE_GBM
|
||||
struct gbm_bo * left_bo = gbm_bo_create(device, width, height, GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING);
|
||||
EGLImage left_image = eglCreateImage(display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, left_bo, NULL);
|
||||
#else
|
||||
EGLImage left_image = eglCreateDRMImage(internalInstance->user_display, imageAttribs);
|
||||
#endif // USE_GBM
|
||||
|
||||
if (!left_image)
|
||||
{
|
||||
@@ -78,14 +104,19 @@ bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsig
|
||||
dma_texture_params left_texture_params;
|
||||
left_texture_params.width = width;
|
||||
left_texture_params.height = height;
|
||||
eglExportDMABUFImageQuery(internalInstance->user_display, left_image, &left_texture_params.fourcc, &left_texture_params.numplanes, &left_texture_params.modifiers);
|
||||
eglExportDMABUFImage(internalInstance->user_display, left_image, &left_texture_params.fd, &left_texture_params.stride, &left_texture_params.offset);
|
||||
eglExportDMABUFImageQuery(display, left_image, &left_texture_params.fourcc, &left_texture_params.numplanes, &left_texture_params.modifiers);
|
||||
eglExportDMABUFImage(display, left_image, &left_texture_params.fd, &left_texture_params.stride, &left_texture_params.offset);
|
||||
|
||||
//
|
||||
// Create and export right image
|
||||
//
|
||||
|
||||
#if USE_GBM
|
||||
struct gbm_bo * right_bo = gbm_bo_create(device, width, height, GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING);
|
||||
EGLImage right_image = eglCreateImage(display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, right_bo, NULL);
|
||||
#else
|
||||
EGLImage right_image = eglCreateDRMImage(internalInstance->user_display, imageAttribs);
|
||||
#endif // USE_GBM
|
||||
|
||||
if (!right_image)
|
||||
{
|
||||
@@ -95,8 +126,8 @@ bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsig
|
||||
dma_texture_params right_texture_params;
|
||||
right_texture_params.width = width;
|
||||
right_texture_params.height = height;
|
||||
eglExportDMABUFImageQuery(internalInstance->user_display, right_image, &right_texture_params.fourcc, &right_texture_params.numplanes, &right_texture_params.modifiers);
|
||||
eglExportDMABUFImage(internalInstance->user_display, right_image, &right_texture_params.fd, &right_texture_params.stride, &right_texture_params.offset);
|
||||
eglExportDMABUFImageQuery(display, right_image, &right_texture_params.fourcc, &right_texture_params.numplanes, &right_texture_params.modifiers);
|
||||
eglExportDMABUFImage(display, right_image, &right_texture_params.fd, &right_texture_params.stride, &right_texture_params.offset);
|
||||
|
||||
//
|
||||
// Import textures in user context
|
||||
@@ -130,11 +161,11 @@ bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsig
|
||||
// Import textures in VR context
|
||||
//
|
||||
|
||||
eglMakeCurrent(internalInstance->vr_display, EGL_NO_SURFACE, EGL_NO_SURFACE, internalInstance->vr_context);
|
||||
eglMakeCurrent(data->vr_display, EGL_NO_SURFACE, EGL_NO_SURFACE, data->vr_context);
|
||||
|
||||
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2D_VR = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress ("glEGLImageTargetTexture2DOES");
|
||||
|
||||
glGenTextures(2, internalInstance->textures);
|
||||
glGenTextures(2, data->textures);
|
||||
|
||||
//
|
||||
// LEFT
|
||||
@@ -151,9 +182,9 @@ bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsig
|
||||
EGL_NONE,
|
||||
};
|
||||
|
||||
EGLImage image_left = eglCreateImage(internalInstance->vr_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrib_list_left);
|
||||
EGLImage image_left = eglCreateImage(data->vr_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrib_list_left);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, internalInstance->textures[0]);
|
||||
glBindTexture(GL_TEXTURE_2D, data->textures[0]);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
@@ -180,9 +211,9 @@ bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsig
|
||||
EGL_NONE,
|
||||
};
|
||||
|
||||
EGLImage image_right = eglCreateImage(internalInstance->vr_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrib_list_right);
|
||||
EGLImage image_right = eglCreateImage(data->vr_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrib_list_right);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, internalInstance->textures[1]);
|
||||
glBindTexture(GL_TEXTURE_2D, data->textures[1]);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
@@ -201,8 +232,10 @@ bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsig
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lvrcReleaseSwapChain(struct lvrcInstance * instance)
|
||||
bool OpenGL_ReleaseSwapChain(Instance * instance)
|
||||
{
|
||||
return false;
|
||||
(void)instance;
|
||||
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
17
src/backend.c
Normal file
17
src/backend.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "backend.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern bool init_OpenGL_backend(Instance * instance);
|
||||
|
||||
static const bool bUseOpenGL = true;
|
||||
|
||||
bool init_rendering_backend(Instance * instance)
|
||||
{
|
||||
if (bUseOpenGL)
|
||||
{
|
||||
return init_OpenGL_backend(instance);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
21
src/backend.h
Normal file
21
src/backend.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef LINUX_VR_COMPOSITOR_BACKEND_H
|
||||
#define LINUX_VR_COMPOSITOR_BACKEND_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct Instance;
|
||||
typedef struct Instance Instance;
|
||||
|
||||
struct backend
|
||||
{
|
||||
void (*Compose)(Instance * instance);
|
||||
bool (*InitSwapChainEGL)(Instance * instance, unsigned int width, unsigned int height, void * textures);
|
||||
bool (*ReleaseSwapChain)(Instance * instance);
|
||||
void * data;
|
||||
};
|
||||
|
||||
typedef struct backend Backend;
|
||||
|
||||
bool init_rendering_backend(Instance * instance);
|
||||
|
||||
#endif // LINUX_VR_COMPOSITOR_BACKEND_H
|
||||
10
src/frame.h
10
src/frame.h
@@ -1,10 +0,0 @@
|
||||
#ifndef LINUX_VR_COMPOSITOR_FRAME_H
|
||||
#define LINUX_VR_COMPOSITOR_FRAME_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "instance.h"
|
||||
|
||||
bool InitFrameResources(Instance * instance);
|
||||
|
||||
#endif // LINUX_VR_COMPOSITOR_FRAME_H
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "instance.h"
|
||||
|
||||
#include "lvrc_internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -284,12 +282,8 @@ static int drm_find_psvr_xcb(Instance * instance)
|
||||
#endif // ENABLE_XCB
|
||||
|
||||
|
||||
struct lvrcInstance * lvrcCreateInstance(ohmd_device * hmd)
|
||||
bool InitInstance(Instance * instance)
|
||||
{
|
||||
Instance * instance = calloc(1, sizeof(Instance));
|
||||
|
||||
instance->hmd = hmd;
|
||||
|
||||
#ifdef ENABLE_XCB
|
||||
instance->connection = xcb_connect(NULL, &instance->screen);
|
||||
|
||||
@@ -306,34 +300,37 @@ struct lvrcInstance * lvrcCreateInstance(ohmd_device * hmd)
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "couldn't find devicee\n");
|
||||
free(instance);
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
instance->device = gbm_create_device(instance->fd);
|
||||
struct gbm_device * device = gbm_create_device(instance->fd);
|
||||
|
||||
if (instance->device == NULL)
|
||||
if (device == NULL)
|
||||
{
|
||||
fprintf(stderr, "couldn't create gbm device\n");
|
||||
free(instance);
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
instance->surface = gbm_surface_create(instance->device, instance->mode->hdisplay, instance->mode->vdisplay, GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
||||
struct gbm_surface * surface = gbm_surface_create(device, instance->mode->hdisplay, instance->mode->vdisplay, GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
||||
|
||||
if (instance->surface == NULL)
|
||||
if (surface == NULL)
|
||||
{
|
||||
fprintf(stderr, "couldn't create gbm surface\n");
|
||||
free(instance);
|
||||
return NULL;
|
||||
gbm_device_destroy(device);
|
||||
return false;
|
||||
}
|
||||
|
||||
return (struct lvrcInstance *)instance;
|
||||
instance->device = device;
|
||||
instance->surface = surface;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void lvrcDestroyInstance(struct lvrcInstance * instance)
|
||||
bool ReleaseInstance(Instance * instance)
|
||||
{
|
||||
free(instance);
|
||||
(void)instance;
|
||||
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
void SwapBuffers(Instance * instance)
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
typedef struct
|
||||
#include "backend.h"
|
||||
|
||||
struct Instance
|
||||
{
|
||||
ohmd_device * hmd;
|
||||
|
||||
@@ -37,18 +39,17 @@ typedef struct
|
||||
uint32_t fbid;
|
||||
struct gbm_bo * bo;
|
||||
|
||||
EGLDisplay vr_display;
|
||||
EGLContext vr_context;
|
||||
EGLSurface vr_surface;
|
||||
|
||||
EGLDisplay user_display;
|
||||
EGLContext user_context;
|
||||
EGLSurface user_surface;
|
||||
|
||||
GLuint textures [2];
|
||||
Backend backend;
|
||||
};
|
||||
|
||||
} Instance;
|
||||
typedef struct Instance Instance;
|
||||
|
||||
bool InitInstance(Instance * instance);
|
||||
bool ReleaseInstance(Instance * instance);
|
||||
void SwapBuffers(Instance * instance);
|
||||
|
||||
#endif // LINUX_VR_COMPOSITOR_STATE_H
|
||||
|
||||
106
src/lvrc.c
106
src/lvrc.c
@@ -1 +1,105 @@
|
||||
#include "lvrc_internal.h"
|
||||
#include <GL/gl.h> // GLuint
|
||||
#include <lvrc.h>
|
||||
|
||||
#include "instance.h"
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
/**
|
||||
* @brief lvrcCreateInstance
|
||||
* @param hmd
|
||||
* @return
|
||||
*/
|
||||
struct lvrcInstance * lvrcCreateInstance(ohmd_device * hmd)
|
||||
{
|
||||
Instance * internalInstance = calloc(1, sizeof(Instance));
|
||||
|
||||
internalInstance->hmd = hmd;
|
||||
|
||||
if (!InitInstance(internalInstance))
|
||||
{
|
||||
free(internalInstance);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct lvrcInstance *)internalInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief lvrcDestroyInstance
|
||||
* @param instance
|
||||
*/
|
||||
void lvrcDestroyInstance(struct lvrcInstance * instance)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
ReleaseInstance(internalInstance);
|
||||
|
||||
free(internalInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief lvrcInitSwapChain
|
||||
* @param instance
|
||||
* @param width
|
||||
* @param height
|
||||
* @param textures
|
||||
* @return
|
||||
*/
|
||||
bool lvrcInitSwapChain(struct lvrcInstance * instance, unsigned int width, unsigned int height, GLuint * textures)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
if (internalInstance->user_display && internalInstance->user_context && internalInstance->user_surface) // rendering was initialized with an EGL context ?
|
||||
{
|
||||
return internalInstance->backend.InitSwapChainEGL(internalInstance, width, height, textures);
|
||||
}
|
||||
else
|
||||
{
|
||||
// currently not possible
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief lvrcReleaseSwapChain
|
||||
* @param instance
|
||||
* @return
|
||||
*/
|
||||
bool lvrcReleaseSwapChain(struct lvrcInstance * instance)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
return internalInstance->backend.ReleaseSwapChain(internalInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief lvrcBeginFrame
|
||||
* @param instance
|
||||
* @return
|
||||
*/
|
||||
bool lvrcBeginFrame(struct lvrcInstance * instance)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
(void)internalInstance; // nothing yet
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief lvrcEndFrame
|
||||
* @param instance
|
||||
* @return
|
||||
*/
|
||||
bool lvrcEndFrame(struct lvrcInstance * instance)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
internalInstance->backend.Compose(internalInstance);
|
||||
|
||||
SwapBuffers(internalInstance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
31
src/lvrc_EGL.c
Normal file
31
src/lvrc_EGL.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GL/gl.h> // GLuint
|
||||
#include <lvrc.h>
|
||||
#include <lvrc_EGL.h>
|
||||
|
||||
#include "instance.h"
|
||||
|
||||
/**
|
||||
* @brief lvrcInitRenderingEGL
|
||||
* @param instance
|
||||
* @param user_display
|
||||
* @param user_context
|
||||
* @param user_surface
|
||||
* @return
|
||||
*/
|
||||
bool lvrcInitRenderingEGL(struct lvrcInstance * instance, EGLDisplay user_display, EGLContext user_context, EGLSurface user_surface)
|
||||
{
|
||||
Instance * internalInstance = (Instance*)instance;
|
||||
|
||||
internalInstance->user_display = user_display;
|
||||
internalInstance->user_context = user_context;
|
||||
internalInstance->user_surface = user_surface;
|
||||
|
||||
if (!init_rendering_backend(internalInstance))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
19
src/lvrc_GLX.c
Normal file
19
src/lvrc_GLX.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <GL/glx.h>
|
||||
#include <GL/gl.h> // GLuint
|
||||
#include <lvrc.h>
|
||||
#include <lvrc_GLX.h>
|
||||
|
||||
#include "instance.h"
|
||||
|
||||
/**
|
||||
* @brief lvrcInitRenderingGLX
|
||||
* @param instance
|
||||
* @param display
|
||||
* @param drawable
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
bool lvrcInitRenderingGLX(struct lvrcInstance * instance, Display* display, GLXDrawable drawable, GLXContext context)
|
||||
{
|
||||
return false; // TODO : currently not supported
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef LINUX_VR_COMPOSITOR_INTERNAL_H
|
||||
#define LINUX_VR_COMPOSITOR_INTERNAL_H
|
||||
|
||||
#define GL_GLES_PROTOTYPES 1
|
||||
#include <GLES2/gl2.h> // FIXME
|
||||
|
||||
#include <lvrc.h>
|
||||
|
||||
#endif // LINUX_VR_COMPOSITOR_INTERNAL_H
|
||||
@@ -1,85 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef LINUX_VR_COMPOSITOR_SWAPCHAIN_H
|
||||
#define LINUX_VR_COMPOSITOR_SWAPCHAIN_H
|
||||
|
||||
#include <openhmd.h>
|
||||
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
#include <gbm.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
} SwapChain;
|
||||
|
||||
|
||||
#endif // LINUX_VR_COMPOSITOR_SWAPCHAIN_H
|
||||
Reference in New Issue
Block a user