2016-12-21 11 views
1

をオフスクリーンレンダリングIは、ユーザコンテキストまたはユーザログインなしでサーバ上のハードウェアアクセラレーションを使用して、複雑な2Dおよび3D画像をレンダリングできるようにします。これまでにできることは、Mesa3Dですが、純粋なソフトウェア3Dレンダリングであるため、速度が遅く、ビデオハードウェアアクセラレーションを利用していません。 WindowsでもLinuxでもかまいません。私の仕事の大半はこれまでWindowsで行ってきました。のOpenGLまたはDirectXの

のOpenGLやDirectXのでこれを行う方法上の任意の提案? Linuxの場合

+2

を参照してください。 .html) – genpfault

+0

私は、windosセッション0ユーザーコンテキストの問題のために、私たちがmesa3dでハードウェアドライバを使用していないと思います...私は詳細を収集します... –

答えて

2

、EGL + MESA_platform_gbmあなたは完全にヘッドレス/ X11レスのOpenGLコンテキストを取得させてください。

スペックは親切使い方をデモプログラム例が含まれています

// This example program creates an EGL surface from a GBM surface. 
// 
// If the macro EGL_MESA_platform_gbm is defined, then the program 
// creates the surfaces using the methods defined in this specification. 
// Otherwise, it uses the methods defined by the EGL 1.4 specification. 
// 
// Compile with `cc -std=c99 example.c -lgbm -lEGL`. 

#include <stdlib.h> 
#include <string.h> 

#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h> 

#include <EGL/egl.h> 
#include <gbm.h> 

struct my_display { 
    struct gbm_device *gbm; 
    EGLDisplay egl; 
}; 

struct my_config { 
    struct my_display dpy; 
    EGLConfig egl; 
}; 

struct my_window { 
    struct my_config config; 
    struct gbm_surface *gbm; 
    EGLSurface egl; 
}; 

static void 
check_extensions(void) 
{ 
#ifdef EGL_MESA_platform_gbm 
    const char *client_extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); 

    if (!client_extensions) { 
     // EGL_EXT_client_extensions is unsupported. 
     abort(); 
    } 
    if (!strstr(client_extensions, "EGL_MESA_platform_gbm")) { 
     abort(); 
    } 
#endif 
} 

static struct my_display 
get_display(void) 
{ 
    struct my_display dpy; 

    int fd = open("/dev/dri/card0", O_RDWR | FD_CLOEXEC); 
    if (fd < 0) { 
     abort(); 
    } 

    dpy.gbm = gbm_create_device(fd); 
    if (!dpy.gbm) { 
     abort(); 
    } 


#ifdef EGL_MESA_platform_gbm 
    dpy.egl = eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA, dpy.gbm, NULL); 
#else 
    dpy.egl = eglGetDisplay(dpy.gbm); 
#endif 

    if (dpy.egl == EGL_NO_DISPLAY) { 
     abort(); 
    } 

    EGLint major, minor; 
    if (!eglInitialize(dpy.egl, &major, &minor)) { 
     abort(); 
    } 

    return dpy; 
} 

static struct my_config 
get_config(struct my_display dpy) 
{ 
    struct my_config config = { 
     .dpy = dpy, 
    }; 

    EGLint egl_config_attribs[] = { 
     EGL_BUFFER_SIZE,  32, 
     EGL_DEPTH_SIZE,   EGL_DONT_CARE, 
     EGL_STENCIL_SIZE,  EGL_DONT_CARE, 
     EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 
     EGL_SURFACE_TYPE,  EGL_WINDOW_BIT, 
     EGL_NONE, 
    }; 

    EGLint num_configs; 
    if (!eglGetConfigs(dpy.egl, NULL, 0, &num_configs)) { 
     abort(); 
    } 

    EGLConfig *configs = malloc(num_configs * sizeof(EGLConfig)); 
    if (!eglChooseConfig(dpy.egl, egl_config_attribs, 
         configs, num_configs, &num_configs)) { 
     abort(); 
    } 
    if (num_configs == 0) { 
     abort(); 
    } 

    // Find a config whose native visual ID is the desired GBM format. 
    for (int i = 0; i < num_configs; ++i) { 
     EGLint gbm_format; 

     if (!eglGetConfigAttrib(dpy.egl, configs[i], 
           EGL_NATIVE_VISUAL_ID, &gbm_format)) { 
      abort(); 
     } 

     if (gbm_format == GBM_FORMAT_XRGB8888) { 
      config.egl = configs[i]; 
      free(configs); 
      return config; 
     } 
    } 

    // Failed to find a config with matching GBM format. 
    abort(); 
} 

static struct my_window 
get_window(struct my_config config) 
{ 
    struct my_window window = { 
     .config = config, 
    }; 

    window.gbm = gbm_surface_create(config.dpy.gbm, 
            256, 256, 
            GBM_FORMAT_XRGB8888, 
            GBM_BO_USE_RENDERING); 
    if (!window.gbm) { 
     abort(); 
    } 

#ifdef EGL_MESA_platform_gbm 
    window.egl = eglCreatePlatformWindowSurfaceEXT(config.dpy.egl, 
                config.egl, 
                window.gbm, 
                NULL); 
#else 
    window.egl = eglCreateWindowSurface(config.dpy.egl, 
             config.egl, 
             window.gbm, 
             NULL); 
#endif 

    if (window.egl == EGL_NO_SURFACE) { 
     abort(); 
    } 

    return window; 
} 

int 
main(void) 
{ 
    check_extensions(); 

    struct my_display dpy = get_display(); 
    struct my_config config = get_config(dpy); 
    struct my_window window = get_window(config); 

    return 0; 
} 

あなたは代わりのOpenGL ESのOpenGLを使用するようにeglBindAPI(EGL_OPENGL_API)を使用することができます。 Windowsの場合

1

は、Windows 8/Server 2012の以降のハードウェアデバイスと(すなわち、出力ウィンドウ/スワップチェーンがなく、セッション0で実行されている)のDirect3D 11「ヘッドレス」を使用することができます。以前は、WARP(ソフトウェアレンダラー)やNULLデバイスを使用している人が多かったです。

は、「[メサ]それは遅く、ビデオハードウェアアクセラレーションを利用していないレンダリング純粋なソフトウェア3Dである」... [ワット](http://www.mesa3d.org/systems Direct3D 11.1 Features

関連する問題