Fix texture sharing between GPUs
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
static inline bool create_context(EGLNativeDisplayType nativeDisplay, EGLNativeWindowType nativeWindow, const EGLint * config_attribs, const EGLint * context_attribs, const EGLint * surface_attribs, EGLDisplay * outDisplay, EGLContext * outContext, EGLSurface * outSurface)
|
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
|
// get an EGL display connection
|
||||||
EGLDisplay display = eglGetDisplay(nativeDisplay);
|
EGLDisplay display = eglGetPlatformDisplay(platform, nativeDisplay, (EGLAttrib*)0);
|
||||||
|
|
||||||
if (EGL_NO_DISPLAY == display)
|
if (EGL_NO_DISPLAY == display)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ void init_gl(gl_ctx* ctx, int w, int h)
|
|||||||
ctx->h = h;
|
ctx->h = h;
|
||||||
ctx->is_fullscreen = 0;
|
ctx->is_fullscreen = 0;
|
||||||
|
|
||||||
bool bContextCreated = create_context(EGL_DEFAULT_DISPLAY, ctx->x_window, egl_config_attribs, egl_context_attribs, egl_surface_attribs, &ctx->egl_display, &ctx->egl_context, &ctx->egl_surface);
|
bool bContextCreated = create_context(EGL_PLATFORM_X11_KHR, EGL_DEFAULT_DISPLAY, ctx->x_window, egl_config_attribs, egl_context_attribs, egl_surface_attribs, &ctx->egl_display, &ctx->egl_context, &ctx->egl_surface);
|
||||||
|
|
||||||
if(!bContextCreated || ctx->egl_context == EGL_NO_CONTEXT)
|
if(!bContextCreated || ctx->egl_context == EGL_NO_CONTEXT)
|
||||||
{
|
{
|
||||||
@@ -289,14 +289,19 @@ GLuint compile_shader(const char* vertex, const char* fragment)
|
|||||||
return programShader;
|
return programShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_fbo(int eye_width, int eye_height, GLuint* fbo, GLuint* color_tex, GLuint* depth_tex)
|
void create_fbo(int eye_width, int eye_height, GLuint* fbo, GLuint* color_tex, GLuint* depth_tex, EGLImage image)
|
||||||
{
|
{
|
||||||
glGenTextures(1, color_tex);
|
glGenTextures(1, color_tex);
|
||||||
glGenTextures(1, depth_tex);
|
glGenTextures(1, depth_tex);
|
||||||
glGenFramebuffers(1, fbo);
|
glGenFramebuffers(1, fbo);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, *color_tex);
|
glBindTexture(GL_TEXTURE_2D, *color_tex);
|
||||||
|
#if 0
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, eye_width, eye_height, 0, GL_RGBA, GL_UNSIGNED_INT, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, eye_width, eye_height, 0, GL_RGBA, GL_UNSIGNED_INT, NULL);
|
||||||
|
#else
|
||||||
|
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress ("glEGLImageTargetTexture2DOES");
|
||||||
|
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
|
||||||
|
#endif // 0
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void perspective(gl_ctx* ctx);
|
|||||||
void init_gl(gl_ctx* ctx, int w, int h);
|
void init_gl(gl_ctx* ctx, int w, int h);
|
||||||
void draw_cube();
|
void draw_cube();
|
||||||
GLuint compile_shader(const char* vertex, const char* fragment);
|
GLuint compile_shader(const char* vertex, const char* fragment);
|
||||||
void create_fbo(int eye_width, int eye_height, GLuint* fbo, GLuint* color_tex, GLuint* depth_tex);
|
void create_fbo(int eye_width, int eye_height, GLuint* fbo, GLuint* color_tex, GLuint* depth_tex, EGLImage image);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -171,19 +171,34 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
GLuint list = gen_cubes();
|
GLuint list = gen_cubes();
|
||||||
|
|
||||||
|
|
||||||
int eye_w = hmd_w/2*OVERSAMPLE_SCALE;
|
int eye_w = hmd_w/2*OVERSAMPLE_SCALE;
|
||||||
int eye_h = hmd_h*OVERSAMPLE_SCALE;
|
int eye_h = hmd_h*OVERSAMPLE_SCALE;
|
||||||
|
|
||||||
|
EGLint imageAttribs[] = {
|
||||||
|
EGL_WIDTH, eye_w,
|
||||||
|
EGL_HEIGHT, eye_h,
|
||||||
|
EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
|
||||||
|
EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SHARE_MESA,
|
||||||
|
EGL_NONE
|
||||||
|
};
|
||||||
|
|
||||||
|
PFNEGLCREATEDRMIMAGEMESAPROC eglCreateDRMImage = (PFNEGLCREATEDRMIMAGEMESAPROC) eglGetProcAddress("eglCreateDRMImageMESA");
|
||||||
|
|
||||||
|
EGLImage left_image = eglCreateDRMImage(gl.egl_display, imageAttribs);
|
||||||
|
EGLImage right_image = eglCreateDRMImage(gl.egl_display, imageAttribs);
|
||||||
|
|
||||||
GLuint left_color_tex = 0, left_depth_tex = 0, left_fbo = 0;
|
GLuint left_color_tex = 0, left_depth_tex = 0, left_fbo = 0;
|
||||||
create_fbo(eye_w, eye_h, &left_fbo, &left_color_tex, &left_depth_tex);
|
create_fbo(eye_w, eye_h, &left_fbo, &left_color_tex, &left_depth_tex, left_image);
|
||||||
|
|
||||||
GLuint right_color_tex = 0, right_depth_tex = 0, right_fbo = 0;
|
GLuint right_color_tex = 0, right_depth_tex = 0, right_fbo = 0;
|
||||||
create_fbo(eye_w, eye_h, &right_fbo, &right_color_tex, &right_depth_tex);
|
create_fbo(eye_w, eye_h, &right_fbo, &right_color_tex, &right_depth_tex, right_image);
|
||||||
|
|
||||||
PFNEGLEXPORTDMABUFIMAGEMESAPROC eglExportDMABUFImage = (PFNEGLEXPORTDMABUFIMAGEMESAPROC) eglGetProcAddress("eglExportDMABUFImageMESA");
|
PFNEGLEXPORTDMABUFIMAGEMESAPROC eglExportDMABUFImage = (PFNEGLEXPORTDMABUFIMAGEMESAPROC) eglGetProcAddress("eglExportDMABUFImageMESA");
|
||||||
PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC eglExportDMABUFImageQuery = (PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC) eglGetProcAddress("eglExportDMABUFImageQueryMESA");
|
PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC eglExportDMABUFImageQuery = (PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC) eglGetProcAddress("eglExportDMABUFImageQueryMESA");
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
EGLImage left_image = eglCreateImage(gl.egl_display, gl.egl_context, EGL_GL_TEXTURE_2D, (EGLClientBuffer)(left_color_tex), NULL);
|
//EGLImage left_image = eglCreateImage(gl.egl_display, gl.egl_context, EGL_GL_TEXTURE_2D, (EGLClientBuffer)(left_color_tex), NULL);
|
||||||
|
|
||||||
dma_texture_params left_texture_params;
|
dma_texture_params left_texture_params;
|
||||||
left_texture_params.width = eye_w;
|
left_texture_params.width = eye_w;
|
||||||
@@ -193,7 +208,7 @@ int main(int argc, char** argv)
|
|||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
EGLImage right_image = eglCreateImage(gl.egl_display, gl.egl_context, EGL_GL_TEXTURE_2D, (EGLClientBuffer)(right_color_tex), NULL);
|
//EGLImage right_image = eglCreateImage(gl.egl_display, gl.egl_context, EGL_GL_TEXTURE_2D, (EGLClientBuffer)(right_color_tex), NULL);
|
||||||
|
|
||||||
dma_texture_params right_texture_params;
|
dma_texture_params right_texture_params;
|
||||||
right_texture_params.width = eye_w;
|
right_texture_params.width = eye_w;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ void init_vr_context(struct lvrcInstance * compositor, dma_texture_params * left
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bContextCreated = create_context(nativeDisplay, nativeWindow, attribs, context_attributes, NULL, &display, &context, &surface);
|
bool bContextCreated = create_context(EGL_PLATFORM_GBM_KHR, nativeDisplay, nativeWindow, attribs, context_attributes, NULL, &display, &context, &surface);
|
||||||
|
|
||||||
if (!bContextCreated)
|
if (!bContextCreated)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user