Skip to content

Render API

WangBin edited this page Dec 2, 2019 · 22 revisions

MDK supports rendering video via OpenGL and D3D11. You can choose which api to use at runtime via Player.setRenderAPI(RenderAPI* api, void* vo_opaque = nullptr). More graphics apis will be supported in the future, for example vulkan and metal.

OpenGL is the default api if you don't call setRenderAPI(). To use another api, a concrete RenderAPI subclass object is required. For example to use d3d11

D3D11RenderAPI ra; // set ra.context and ra.rtv if provided by app player.setRenderAPI(&ra);

Render in a User Provided Context

It's named "Foreign Context". Usually you have to render a frame in a correct rendering thread of the gui toolkit or app. For example, call Player.renderVideo() in QOpenGLWidget::paintGL() or similar events for Qt Apps, in GLSurfaceView.RendereronDrawFrame(GL10 gl) for android apps. The callback of Player.setRenderCallback(callback) will be called if a new frame is ready to display, you can notify your gui toolkit or app in this callback.

To use a RenderAPI other than OpenGL, a concrete RenderAPI subclass object with some valid members is required. For example a D3D11RenderAPI requires context and rtv member are valid

D3D11RenderAPI ra; ra.context = immediateContext; // immediateContext is provied by app, can not be null ra.rtv = renderTargetView; // renderTargetView is provided by app, can not be null player.setRenderAPI(&ra);

examples:

Render On a Platform Surface

MDK use another project UGS to create and drive a rendering loop for a platform native surface. A platform native surface is HWND on windows, ANativeWindow* on android, CALayer* or UIView* on iOS, ICoreWindow* or ISwapChainPanel* on UWP/WinRT. Call updateNativeSurface() with such a surface value when surface changes, or a null value to create internally. A null value also works for X11 Window or wl_egl_window* or gbm_surface* on linux, EGL_DISPMANX_WINDOW_T* on raspberry pi(legacy driver).

No need to call setRenderCallback() and renderVideo().

To use a RenderAPI other than OpenGL, a concrete RenderAPI with default initialized members is required. For example a D3D11RenderAPI requires context and rtv member can be null. And setRenderAPI() MUST be called before the first Player.updateNativeSurface()

D3D11RenderAPI ra; player.setRenderAPI(&ra); // ... player.updateNativeSurface(....);

examples:

Render On a Surface Created Internally

examples:

Clone this wiki locally