15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    NV_DX_interop2
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    WGL_NV_DX_interop2
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContributors
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Nuno Subtil, NVIDIA
125bd8deadSopenharmony_ci    Kedarnath Thangudu, NVIDIA
135bd8deadSopenharmony_ci
145bd8deadSopenharmony_ciContact
155bd8deadSopenharmony_ci
165bd8deadSopenharmony_ci    Nuno Subtil, NVIDIA Corporation (nsubtil 'at' nvidia.com)
175bd8deadSopenharmony_ci
185bd8deadSopenharmony_ciStatus
195bd8deadSopenharmony_ci
205bd8deadSopenharmony_ci    Complete. Shipping with NVIDIA release 275 drivers, June 2011.
215bd8deadSopenharmony_ci
225bd8deadSopenharmony_ciVersion
235bd8deadSopenharmony_ci
245bd8deadSopenharmony_ci    Last Modified Date:   October 4, 2011
255bd8deadSopenharmony_ci    Author Revision:      2
265bd8deadSopenharmony_ci
275bd8deadSopenharmony_ciNumber
285bd8deadSopenharmony_ci
295bd8deadSopenharmony_ci    412
305bd8deadSopenharmony_ci
315bd8deadSopenharmony_ciDependencies
325bd8deadSopenharmony_ci
335bd8deadSopenharmony_ci    OpenGL 2.1 is required.
345bd8deadSopenharmony_ci    WGL_NV_DX_interop is required.
355bd8deadSopenharmony_ci    Windows Display Driver Model (WDDM) capable operating system 
365bd8deadSopenharmony_ci      (such as Vista or Windows 7) required.
375bd8deadSopenharmony_ci    Direct3D 10-capable GPU required for ID3D10Device usage.
385bd8deadSopenharmony_ci    Direct3D 11-capable GPU required for ID3D11Device usage.
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ciOverview
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ci    This extension expands on the specification of WGL_NV_DX_interop
435bd8deadSopenharmony_ci    to add support for DirectX version 10, 10.1 and 11 resources.
445bd8deadSopenharmony_ci
455bd8deadSopenharmony_ciNew Procedures and Functions
465bd8deadSopenharmony_ci
475bd8deadSopenharmony_ci    None
485bd8deadSopenharmony_ci
495bd8deadSopenharmony_ciNew Tokens
505bd8deadSopenharmony_ci
515bd8deadSopenharmony_ci    None
525bd8deadSopenharmony_ci
535bd8deadSopenharmony_ciAdditions to the WGL Specification
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ci    None
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ciAdditions to the WGL_NV_DX_interop specification
585bd8deadSopenharmony_ci
595bd8deadSopenharmony_ci    Add to the description of wglDXSetResourceShareHandleNV:
605bd8deadSopenharmony_ci
615bd8deadSopenharmony_ci    wglDXSetResourceShareHandle does not need to be called for DirectX
625bd8deadSopenharmony_ci    version 10 and 11 resources. Calling this function for DirectX 10
635bd8deadSopenharmony_ci    and 11 resources is not an error but has no effect.
645bd8deadSopenharmony_ci
655bd8deadSopenharmony_ci    Modify the last paragraph in the description of
665bd8deadSopenharmony_ci    wglDXRegisterObjectNV:
675bd8deadSopenharmony_ci    
685bd8deadSopenharmony_ci    If the application explicitly requests a share handle for a DirectX
695bd8deadSopenharmony_ci    resource, results are undefined (and may include data corruption,
705bd8deadSopenharmony_ci    incorrect DirectX operation or program termination) if
715bd8deadSopenharmony_ci    wglDXRegisterObjectNV is called before calling
725bd8deadSopenharmony_ci    wglDXSetResourceShareHandleNV for the same resource. This
735bd8deadSopenharmony_ci    restriction does not apply to non-WDDM operating systems. This
745bd8deadSopenharmony_ci    restriction also does not apply to DirectX version 10 and 11
755bd8deadSopenharmony_ci    resources.
765bd8deadSopenharmony_ci    
775bd8deadSopenharmony_ci    Add the following supported devices to table wgl.devicetypes:
785bd8deadSopenharmony_ci
795bd8deadSopenharmony_ci    -------------------------------------------------------------------------
805bd8deadSopenharmony_ci    DirectX device type      Device Restrictions
815bd8deadSopenharmony_ci    -------------------------------------------------------------------------
825bd8deadSopenharmony_ci    ID3D10Device             can only be used on WDDM operating systems;
835bd8deadSopenharmony_ci                             Must be multithreaded
845bd8deadSopenharmony_ci    ID3D11Device             can only be used on WDDM operating systems;
855bd8deadSopenharmony_ci                             XXX Must be multithreaded
865bd8deadSopenharmony_ci    -------------------------------------------------------------------------
875bd8deadSopenharmony_ci    Table wgl.devicetypes - Valid device types for the <dxDevice> parameter of
885bd8deadSopenharmony_ci    wglDXOpenDeviceNV and associated restrictions.
895bd8deadSopenharmony_ci    -------------------------------------------------------------------------
905bd8deadSopenharmony_ci
915bd8deadSopenharmony_ci    Add the following resources to table wgl.objtypes:
925bd8deadSopenharmony_ci
935bd8deadSopenharmony_ci    --------------------------------------------------------------------------
945bd8deadSopenharmony_ci    <type>              type of <name>     Valid DirectX resource types
955bd8deadSopenharmony_ci    --------------------------------------------------------------------------
965bd8deadSopenharmony_ci    TEXTURE_1D          texture            ID3D10Texture1D
975bd8deadSopenharmony_ci                                           ID3D11Texture1D
985bd8deadSopenharmony_ci    TEXTURE_1D_ARRAY    texture            ID3D10Texture1D
995bd8deadSopenharmony_ci                                           ID3D11Texture1D
1005bd8deadSopenharmony_ci    TEXTURE_2D          texture            ID3D10Texture2D
1015bd8deadSopenharmony_ci                                           ID3D11Texture2D
1025bd8deadSopenharmony_ci    TEXTURE_2D_ARRAY    texture            ID3D10Texture2D
1035bd8deadSopenharmony_ci                                           ID3D11Texture2D
1045bd8deadSopenharmony_ci    TEXTURE_3D          texture            ID3D10Texture3D
1055bd8deadSopenharmony_ci                                           ID3D11Texture3D
1065bd8deadSopenharmony_ci    TEXTURE_CUBE_MAP    texture            ID3D10Texture2D
1075bd8deadSopenharmony_ci                                           ID3D11Texture2D
1085bd8deadSopenharmony_ci    TEXTURE_RECTANGLE   texture            ID3D10Texture2D
1095bd8deadSopenharmony_ci                                           ID3D11Texture2D
1105bd8deadSopenharmony_ci    RENDERBUFFER        renderbuffer       ID3D10Texture2D
1115bd8deadSopenharmony_ci                                           ID3D11Texture2D
1125bd8deadSopenharmony_ci    NONE                buffer             ID3D10Buffer
1135bd8deadSopenharmony_ci                                           ID3D11Buffer
1145bd8deadSopenharmony_ci    --------------------------------------------------------------------------
1155bd8deadSopenharmony_ci    Table wgl.objtypes - Valid values for the <type> parameter of
1165bd8deadSopenharmony_ci    wglDXRegisterObjectNV, and associated object types for GL and
1175bd8deadSopenharmony_ci    DirectX.
1185bd8deadSopenharmony_ci    --------------------------------------------------------------------------
1195bd8deadSopenharmony_ci
1205bd8deadSopenharmony_ci    Add the following resources to table wgl.restrictions:
1215bd8deadSopenharmony_ci
1225bd8deadSopenharmony_ci    --------------------------------------------------------------------------
1235bd8deadSopenharmony_ci    Resource Type            Resource Restrictions
1245bd8deadSopenharmony_ci    --------------------------------------------------------------------------
1255bd8deadSopenharmony_ci    ID3D10Texture1D          Usage flags must be D3D10_USAGE_DEFAULT
1265bd8deadSopenharmony_ci    ID3D10Texture2D          Usage flags must be D3D10_USAGE_DEFAULT
1275bd8deadSopenharmony_ci    ID3D10Texture3D          Usage flags must be D3D10_USAGE_DEFAULT
1285bd8deadSopenharmony_ci    ID3D10Buffer             Usage flags must be D3D10_USAGE_DEFAULT
1295bd8deadSopenharmony_ci    ID3D11Texture1D          Usage flags must be D3D11_USAGE_DEFAULT
1305bd8deadSopenharmony_ci    ID3D11Texture2D          Usage flags must be D3D11_USAGE_DEFAULT
1315bd8deadSopenharmony_ci    ID3D11Texture3D          Usage flags must be D3D11_USAGE_DEFAULT
1325bd8deadSopenharmony_ci    ID3D11Buffer             Usage flags must be D3D11_USAGE_DEFAULT
1335bd8deadSopenharmony_ci    --------------------------------------------------------------------------
1345bd8deadSopenharmony_ci    Table wgl.restrictions - Restrictions on DirectX resources that can
1355bd8deadSopenharmony_ci    be registered via wglDXRegisterObjectNV
1365bd8deadSopenharmony_ci    --------------------------------------------------------------------------
1375bd8deadSopenharmony_ci
1385bd8deadSopenharmony_ciIssues
1395bd8deadSopenharmony_ci
1405bd8deadSopenharmony_ci    1) How do we share D3D "tbuffers" with OpenGL?
1415bd8deadSopenharmony_ci    
1425bd8deadSopenharmony_ci    RESOLUTION: D3D "tbuffers" are analogous to buffer textures in OpenGL
1435bd8deadSopenharmony_ci    and do not have their own resource type. The ID3D1xBuffer backing the
1445bd8deadSopenharmony_ci    "tbuffer" could be shared with OpenGL and attached to a buffer texture
1455bd8deadSopenharmony_ci    by passing the interop buffer ID to TexBuffer().
1465bd8deadSopenharmony_ci
1475bd8deadSopenharmony_ci
1485bd8deadSopenharmony_ciSample Code
1495bd8deadSopenharmony_ci    Example: Render to Direct3D 11 backbuffer with openGL.
1505bd8deadSopenharmony_ci    
1515bd8deadSopenharmony_ci    // create D3D11 device, context and swap chain.
1525bd8deadSopenharmony_ci    ID3D11Device *device;
1535bd8deadSopenharmony_ci    ID3D11DeviceContext *devCtx;
1545bd8deadSopenharmony_ci    IDXGISwapChain *swapChain;
1555bd8deadSopenharmony_ci    
1565bd8deadSopenharmony_ci    DXGI_SWAP_CHAIN_DESC scd;
1575bd8deadSopenharmony_ci    
1585bd8deadSopenharmony_ci    <set appropriate swap chain parameters in scd>
1595bd8deadSopenharmony_ci    
1605bd8deadSopenharmony_ci    hr = D3D11CreateDeviceAndSwapChain(NULL,                        // pAdapter
1615bd8deadSopenharmony_ci                                       D3D_DRIVER_TYPE_HARDWARE,    // DriverType
1625bd8deadSopenharmony_ci                                       NULL,                        // Software
1635bd8deadSopenharmony_ci                                       0,                           // Flags (Do not set D3D11_CREATE_DEVICE_SINGLETHREADED)
1645bd8deadSopenharmony_ci                                       NULL,                        // pFeatureLevels
1655bd8deadSopenharmony_ci                                       0,                           // FeatureLevels
1665bd8deadSopenharmony_ci                                       D3D11_SDK_VERSION,           // SDKVersion
1675bd8deadSopenharmony_ci                                       &scd,                        // pSwapChainDesc
1685bd8deadSopenharmony_ci                                       &swapChain,                  // ppSwapChain
1695bd8deadSopenharmony_ci                                       &device,                     // ppDevice
1705bd8deadSopenharmony_ci                                       NULL,                        // pFeatureLevel
1715bd8deadSopenharmony_ci                                       &devCtx);                    // ppImmediateContext
1725bd8deadSopenharmony_ci
1735bd8deadSopenharmony_ci    // Fetch the swapchain backbuffer
1745bd8deadSopenharmony_ci    ID3D11Texture2D *dxColorbuffer;
1755bd8deadSopenharmony_ci    swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID *)&dxColorbuffer);
1765bd8deadSopenharmony_ci    
1775bd8deadSopenharmony_ci    // Create depth stencil texture
1785bd8deadSopenharmony_ci    ID3D11Texture2D *dxDepthBuffer;
1795bd8deadSopenharmony_ci    D3D11_TEXTURE2D_DESC depthDesc;
1805bd8deadSopenharmony_ci    depthDesc.Usage = D3D11_USAGE_DEFAULT;
1815bd8deadSopenharmony_ci    <set other depthDesc parameters appropriately>
1825bd8deadSopenharmony_ci    
1835bd8deadSopenharmony_ci    // Create Views
1845bd8deadSopenharmony_ci    ID3D11RenderTargetView *colorBufferView;
1855bd8deadSopenharmony_ci    D3D11_RENDER_TARGET_VIEW_DESC rtd;
1865bd8deadSopenharmony_ci    <set rtd parameters appropriately>
1875bd8deadSopenharmony_ci    device->CreateRenderTargetView(dxColorbuffer, &rtd, &colorBufferView);
1885bd8deadSopenharmony_ci    
1895bd8deadSopenharmony_ci    ID3D11DepthStencilView *depthBufferView;
1905bd8deadSopenharmony_ci    D3D11_DEPTH_STENCIL_VIEW_DESC dsd;
1915bd8deadSopenharmony_ci    <set dsd parameters appropriately>
1925bd8deadSopenharmony_ci    device->CreateDepthStencilView(dxDepthBuffer, &dsd, &depthBufferView);
1935bd8deadSopenharmony_ci    
1945bd8deadSopenharmony_ci    // Attach back buffer and depth texture to redertarget for the device.
1955bd8deadSopenharmony_ci    devCtx->OMSetRenderTargets(1, &colorBufferView, depthBufferView);
1965bd8deadSopenharmony_ci    
1975bd8deadSopenharmony_ci    // Register D3D11 device with GL
1985bd8deadSopenharmony_ci    HANDLE gl_handleD3D;
1995bd8deadSopenharmony_ci    gl_handleD3D = wglDXOpenDeviceNV(device);
2005bd8deadSopenharmony_ci
2015bd8deadSopenharmony_ci    // register the Direct3D color and depth/stencil buffers as
2025bd8deadSopenharmony_ci    // renderbuffers in opengl
2035bd8deadSopenharmony_ci    GLuint gl_names[2];
2045bd8deadSopenharmony_ci    HANDLE gl_handles[2];
2055bd8deadSopenharmony_ci
2065bd8deadSopenharmony_ci    glGenRenderbuffers(2, gl_names);
2075bd8deadSopenharmony_ci
2085bd8deadSopenharmony_ci    gl_handles[0] = wglDXRegisterObjectNV(gl_handleD3D, dxColorBuffer,
2095bd8deadSopenharmony_ci                                          gl_names[0],
2105bd8deadSopenharmony_ci                                          GL_RENDERBUFFER,
2115bd8deadSopenharmony_ci                                          WGL_ACCESS_READ_WRITE_NV);
2125bd8deadSopenharmony_ci
2135bd8deadSopenharmony_ci    gl_handles[1] = wglDXRegisterObjectNV(gl_handleD3D, dxDepthBuffer,
2145bd8deadSopenharmony_ci                                          gl_names[1],
2155bd8deadSopenharmony_ci                                          GL_RENDERBUFFER,
2165bd8deadSopenharmony_ci                                          WGL_ACCESS_READ_WRITE_NV);
2175bd8deadSopenharmony_ci
2185bd8deadSopenharmony_ci    // attach the Direct3D buffers to an FBO
2195bd8deadSopenharmony_ci    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2205bd8deadSopenharmony_ci    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2215bd8deadSopenharmony_ci                              GL_RENDERBUFFER, gl_names[0]);
2225bd8deadSopenharmony_ci    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
2235bd8deadSopenharmony_ci                              GL_RENDERBUFFER, gl_names[1]);
2245bd8deadSopenharmony_ci    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
2255bd8deadSopenharmony_ci                              GL_RENDERBUFFER, gl_names[1]);
2265bd8deadSopenharmony_ci
2275bd8deadSopenharmony_ci    while (!done) {
2285bd8deadSopenharmony_ci          <direct3d renders to the render targets>
2295bd8deadSopenharmony_ci
2305bd8deadSopenharmony_ci          // lock the render targets for GL access
2315bd8deadSopenharmony_ci          wglDXLockObjectsNVX(handleD3D, 2, gl_handles);
2325bd8deadSopenharmony_ci
2335bd8deadSopenharmony_ci          <opengl renders to the render targets>
2345bd8deadSopenharmony_ci
2355bd8deadSopenharmony_ci          // unlock the render targets
2365bd8deadSopenharmony_ci          wglDXUnlockObjectsNVX(handleD3D, 2, gl_handles);
2375bd8deadSopenharmony_ci
2385bd8deadSopenharmony_ci          <direct3d renders to the render targets and presents
2395bd8deadSopenharmony_ci           the results on the screen>
2405bd8deadSopenharmony_ci    }
2415bd8deadSopenharmony_ci
2425bd8deadSopenharmony_ciRevision History
2435bd8deadSopenharmony_ci
2445bd8deadSopenharmony_ci    Revision 1, 2009/06/13
2455bd8deadSopenharmony_ci     - Initial revision
2465bd8deadSopenharmony_ci    Revision 2, 2011/10/04
2475bd8deadSopenharmony_ci     - Updated supported DX10/11 resources types and their restrictions.
2485bd8deadSopenharmony_ci     - Updated the dependecies section.
2495bd8deadSopenharmony_ci     - Added an issue explaining DX "tbuffer" sharing.
2505bd8deadSopenharmony_ci     - Added sample code.
251