15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    NV_DX_interop
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    WGL_NV_DX_interop
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContributors
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Michael Gold, NVIDIA
125bd8deadSopenharmony_ci    Nuno Subtil, 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 265 drivers, November 2010.
215bd8deadSopenharmony_ci
225bd8deadSopenharmony_ciVersion
235bd8deadSopenharmony_ci
245bd8deadSopenharmony_ci    Last Modified Date:         10/11/2010
255bd8deadSopenharmony_ci    Revision:                   1
265bd8deadSopenharmony_ci
275bd8deadSopenharmony_ciNumber
285bd8deadSopenharmony_ci
295bd8deadSopenharmony_ci    407
305bd8deadSopenharmony_ci
315bd8deadSopenharmony_ciDependencies
325bd8deadSopenharmony_ci
335bd8deadSopenharmony_ci    OpenGL 2.1 is required.
345bd8deadSopenharmony_ci
355bd8deadSopenharmony_ciOverview
365bd8deadSopenharmony_ci
375bd8deadSopenharmony_ci    This extension allows OpenGL to directly access DirectX buffers
385bd8deadSopenharmony_ci    and surfaces.  A DirectX vertex buffer may be shared as an OpenGL
395bd8deadSopenharmony_ci    buffer object and a DirectX surface may be shared as an OpenGL
405bd8deadSopenharmony_ci    texture or renderbuffer object.
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ciNew Procedures and Functions
435bd8deadSopenharmony_ci
445bd8deadSopenharmony_ci    BOOL wglDXSetResourceShareHandleNV(void *dxObject, HANDLE shareHandle);
455bd8deadSopenharmony_ci
465bd8deadSopenharmony_ci    HANDLE wglDXOpenDeviceNV(void *dxDevice);
475bd8deadSopenharmony_ci    BOOL wglDXCloseDeviceNV(HANDLE hDevice);
485bd8deadSopenharmony_ci    HANDLE wglDXRegisterObjectNV(HANDLE hDevice, void *dxObject,
495bd8deadSopenharmony_ci                                  GLuint name, GLenum type, GLenum access);
505bd8deadSopenharmony_ci    BOOL wglDXUnregisterObjectNV(HANDLE hDevice, HANDLE hObject);
515bd8deadSopenharmony_ci    BOOL wglDXObjectAccessNV(HANDLE hObject, GLenum access);
525bd8deadSopenharmony_ci    BOOL wglDXLockObjectsNV(HANDLE hDevice, GLint count, HANDLE *hObjects);
535bd8deadSopenharmony_ci    BOOL wglDXUnlockObjectsNV(HANDLE hDevice, GLint count, HANDLE *hObjects);
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ciNew Tokens
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ci    Accepted by the <access> parameters of wglDXRegisterObjectNV and
585bd8deadSopenharmony_ci    wglDXObjectAccessNV:
595bd8deadSopenharmony_ci
605bd8deadSopenharmony_ci      WGL_ACCESS_READ_ONLY_NV             0x0000
615bd8deadSopenharmony_ci      WGL_ACCESS_READ_WRITE_NV            0x0001
625bd8deadSopenharmony_ci      WGL_ACCESS_WRITE_DISCARD_NV         0x0002
635bd8deadSopenharmony_ci
645bd8deadSopenharmony_ciAdditions to the WGL Specification
655bd8deadSopenharmony_ci
665bd8deadSopenharmony_ci    OpenGL may directly access textures, surfaces and buffers created
675bd8deadSopenharmony_ci    by DirectX.  A DirectX device is prepared for interoperability
685bd8deadSopenharmony_ci    by calling
695bd8deadSopenharmony_ci
705bd8deadSopenharmony_ci        HANDLE wglDXOpenDeviceNV(void *dxDevice);
715bd8deadSopenharmony_ci
725bd8deadSopenharmony_ci    <dxDevice> is a pointer to a supported Direct3D device
735bd8deadSopenharmony_ci    object. Supported devices are listed in the wgl.devicetypes table,
745bd8deadSopenharmony_ci    along with applicable restrictions for each device. The return
755bd8deadSopenharmony_ci    value is a handle to a GL/DirectX interop device.
765bd8deadSopenharmony_ci
775bd8deadSopenharmony_ci    When wglDXOpenDeviceNV fails to open a Direct3D device, NULL is
785bd8deadSopenharmony_ci    returned. To get extended error information, call GetLastError.
795bd8deadSopenharmony_ci    Possible errors are as follows:
805bd8deadSopenharmony_ci
815bd8deadSopenharmony_ci      ERROR_OPEN_FAILED        Could not open the Direct3D device.
825bd8deadSopenharmony_ci
835bd8deadSopenharmony_ci      ERROR_NOT_SUPPORTED      The <dxDevice> is not supported.
845bd8deadSopenharmony_ci                               This can be caused either by passing in
855bd8deadSopenharmony_ci                               a device from an unsupported DirectX
865bd8deadSopenharmony_ci                               version, or by passing in a device
875bd8deadSopenharmony_ci                               referencing a display adapter that is
885bd8deadSopenharmony_ci                               not accessible to the GL.
895bd8deadSopenharmony_ci
905bd8deadSopenharmony_ci    Calling this entrypoint with an invalid <dxDevice> pointer results
915bd8deadSopenharmony_ci    in undefined behavior and may result in data corruption or program
925bd8deadSopenharmony_ci    termination.
935bd8deadSopenharmony_ci
945bd8deadSopenharmony_ci    Versions of the operating system that support the Windows Display
955bd8deadSopenharmony_ci    Driver Model (WDDM) support a sharing mechanism for DirectX
965bd8deadSopenharmony_ci    resources that makes use of WDDM share handles. The application may
975bd8deadSopenharmony_ci    obtain a share handle from the operating system to share a surface
985bd8deadSopenharmony_ci    among several Direct3D devices.
995bd8deadSopenharmony_ci
1005bd8deadSopenharmony_ci    This extension accommodates, but does not require use of WDDM share
1015bd8deadSopenharmony_ci    handles. An application should only obtain a WDDM share handle at
1025bd8deadSopenharmony_ci    resource creation time if it will share the resource with non-GL
1035bd8deadSopenharmony_ci    clients.
1045bd8deadSopenharmony_ci
1055bd8deadSopenharmony_ci    As of today, all versions of Microsoft Windows starting with Windows
1065bd8deadSopenharmony_ci    Vista use the Windows Display Driver Model, enabling the usage of
1075bd8deadSopenharmony_ci    WDDM share handles.
1085bd8deadSopenharmony_ci
1095bd8deadSopenharmony_ci    If the application wishes to share a DirectX version 9 resource
1105bd8deadSopenharmony_ci    under a WDDM operating system, it is required that the Direct3D
1115bd8deadSopenharmony_ci    device that owns the resource be a Direct3D9Ex device.
1125bd8deadSopenharmony_ci
1135bd8deadSopenharmony_ci    -------------------------------------------------------------------------
1145bd8deadSopenharmony_ci    DirectX device type      Device Restrictions
1155bd8deadSopenharmony_ci    -------------------------------------------------------------------------
1165bd8deadSopenharmony_ci    IDirect3DDevice9         can not be used on WDDM operating systems;
1175bd8deadSopenharmony_ci                             D3DCREATE_MULTITHREADED behavior flag must be
1185bd8deadSopenharmony_ci                             set at device creation time
1195bd8deadSopenharmony_ci
1205bd8deadSopenharmony_ci    IDirect3DDevice9Ex       D3DCREATE_MULTITHREADED behavior flag must be
1215bd8deadSopenharmony_ci                             set at device creation time
1225bd8deadSopenharmony_ci    -------------------------------------------------------------------------
1235bd8deadSopenharmony_ci    Table wgl.devicetypes - Valid device types for the <dxDevice> parameter of
1245bd8deadSopenharmony_ci    wglDXOpenDeviceNV and associated restrictions.
1255bd8deadSopenharmony_ci    -------------------------------------------------------------------------
1265bd8deadSopenharmony_ci
1275bd8deadSopenharmony_ci    If the application wishes to share a DirectX resource with GL and
1285bd8deadSopenharmony_ci    non-GL clients, it should request a share handle for the
1295bd8deadSopenharmony_ci    resource. It must also call
1305bd8deadSopenharmony_ci
1315bd8deadSopenharmony_ci        BOOL wglDXSetResourceShareHandleNV(void *dxResource, HANDLE shareHandle);
1325bd8deadSopenharmony_ci
1335bd8deadSopenharmony_ci    to associate the share handle with the DirectX resource prior to
1345bd8deadSopenharmony_ci    registering it with the GL. <dxResource> is a pointer to the DirectX
1355bd8deadSopenharmony_ci    resource that will be shared, <shareHandle> contains the share
1365bd8deadSopenharmony_ci    handle that the OS generated for the resource.
1375bd8deadSopenharmony_ci
1385bd8deadSopenharmony_ci    The return value for wglDXSetResourceShareHandleNV is FALSE if
1395bd8deadSopenharmony_ci    this function is called more than once for any resource; called
1405bd8deadSopenharmony_ci    with an invalid <shareHandle> parameter; or called for a resource
1415bd8deadSopenharmony_ci    that is already being shared with the GL; otherwise, the return
1425bd8deadSopenharmony_ci    value is TRUE. On a version of the OS that does not support WDDM,
1435bd8deadSopenharmony_ci    calling wglDXSetResourceShareHandleNV returns TRUE but has no
1445bd8deadSopenharmony_ci    effect.
1455bd8deadSopenharmony_ci
1465bd8deadSopenharmony_ci    Results are undefined if the <dxResource> pointer is invalid and
1475bd8deadSopenharmony_ci    may result in data corruption or program termination.
1485bd8deadSopenharmony_ci
1495bd8deadSopenharmony_ci    Calling
1505bd8deadSopenharmony_ci
1515bd8deadSopenharmony_ci        HANDLE wglDXRegisterObjectNV(HANDLE hDevice, void *dxResource,
1525bd8deadSopenharmony_ci                                     GLuint name, GLenum type, GLenum access);
1535bd8deadSopenharmony_ci
1545bd8deadSopenharmony_ci    prepares a DirectX object for use by the GL.  <hDevice> is a
1555bd8deadSopenharmony_ci    GL/DirectX interop device handle, as returned by wglDXOpenDeviceNV.
1565bd8deadSopenharmony_ci
1575bd8deadSopenharmony_ci    <dxResource> is a pointer to a DirectX resource to be registered
1585bd8deadSopenharmony_ci    with the GL. The resource must be of one of the types identified in
1595bd8deadSopenharmony_ci    table wgl.objtypes and must also obey the restrictions specified for
1605bd8deadSopenharmony_ci    that resource in table wgl.restrictions.
1615bd8deadSopenharmony_ci
1625bd8deadSopenharmony_ci    <type> identifies the GL object type that will map to the DirectX
1635bd8deadSopenharmony_ci    resource being shared and must be one of the types enumerated in
1645bd8deadSopenharmony_ci    table wgl.objtypes.  <name> is the GL object name to be assigned
1655bd8deadSopenharmony_ci    to the DirectX resource in the namespace of the objects identified
1665bd8deadSopenharmony_ci    by <type> in the current GL context. The valid combinations of
1675bd8deadSopenharmony_ci    <type> and <dxResource> are described in table wgl.objtypes.
1685bd8deadSopenharmony_ci
1695bd8deadSopenharmony_ci    <access> indicates the intended usage of the resource in GL and must
1705bd8deadSopenharmony_ci    be one of the following:
1715bd8deadSopenharmony_ci
1725bd8deadSopenharmony_ci        WGL_ACCESS_READ_ONLY_NV indicates that GL will read the
1735bd8deadSopenharmony_ci        DirectX resource but will not modify it.  If GL attempts to
1745bd8deadSopenharmony_ci        modify the data store of the resource, the result is undefined
1755bd8deadSopenharmony_ci        and may include program termination.
1765bd8deadSopenharmony_ci
1775bd8deadSopenharmony_ci        WGL_ACCESS_READ_WRITE_NV indicates that GL may read or write
1785bd8deadSopenharmony_ci        the data store of the resource.
1795bd8deadSopenharmony_ci
1805bd8deadSopenharmony_ci        WGL_ACCESS_WRITE_DISCARD_NV indicates that any previous
1815bd8deadSopenharmony_ci        contents of the object may be discarded and GL may write to
1825bd8deadSopenharmony_ci        the resource.  Any data written by GL may be reliably read in
1835bd8deadSopenharmony_ci        subsequent operations.  The result of subsequently reading
1845bd8deadSopenharmony_ci        data outside the region written by GL is undefined.
1855bd8deadSopenharmony_ci
1865bd8deadSopenharmony_ci    If the call is successful, the return value is a handle to a
1875bd8deadSopenharmony_ci    GL/DirectX interop object. A return value of NULL indicates that
1885bd8deadSopenharmony_ci    an error occurred. To obtain extended error information, call
1895bd8deadSopenharmony_ci    GetLastError. Possible errors are as follows:
1905bd8deadSopenharmony_ci
1915bd8deadSopenharmony_ci      ERROR_INVALID_HANDLE    No GL context is made current to the
1925bd8deadSopenharmony_ci                              calling thread.
1935bd8deadSopenharmony_ci
1945bd8deadSopenharmony_ci      ERROR_INVALID_DATA      Incorrect <name> <type> or <access>
1955bd8deadSopenharmony_ci                              parameters.
1965bd8deadSopenharmony_ci
1975bd8deadSopenharmony_ci      ERROR_OPEN_FAILED       Opening the Direct3D resource failed.
1985bd8deadSopenharmony_ci
1995bd8deadSopenharmony_ci    Calling wglDXRegisterObjectNV with an invalid <hDevice> handle
2005bd8deadSopenharmony_ci    results in undefined behavior and may result in data corruption or
2015bd8deadSopenharmony_ci    program termination.
2025bd8deadSopenharmony_ci
2035bd8deadSopenharmony_ci    If the application explicitly requests a share handle for a
2045bd8deadSopenharmony_ci    DirectX resource, results are undefined (and may result in data
2055bd8deadSopenharmony_ci    corruption, incorrect DirectX operation or program termination) if
2065bd8deadSopenharmony_ci    wglDXRegisterObjectNV is called before calling
2075bd8deadSopenharmony_ci    wglDXSetResourceShareHandleNV for the same resource. This
2085bd8deadSopenharmony_ci    restriction does not apply to non-WDDM operating systems.
2095bd8deadSopenharmony_ci
2105bd8deadSopenharmony_ci    --------------------------------------------------------------------------
2115bd8deadSopenharmony_ci    <type>              type of <name>     Valid DirectX resource types
2125bd8deadSopenharmony_ci    --------------------------------------------------------------------------
2135bd8deadSopenharmony_ci    TEXTURE_2D          texture            IDirect3DSurface9
2145bd8deadSopenharmony_ci                                           IDirect3DTexture9
2155bd8deadSopenharmony_ci
2165bd8deadSopenharmony_ci    TEXTURE_3D          texture            IDirect3DVolumeTexture9
2175bd8deadSopenharmony_ci
2185bd8deadSopenharmony_ci    TEXTURE_CUBE_MAP    texture            IDirect3DCubeTexture9
2195bd8deadSopenharmony_ci
2205bd8deadSopenharmony_ci    TEXTURE_RECTANGLE   texture            IDirect3DSurface9
2215bd8deadSopenharmony_ci                                           IDirect3DTexture9
2225bd8deadSopenharmony_ci
2235bd8deadSopenharmony_ci    RENDERBUFFER        renderbuffer       IDirect3DSurface9
2245bd8deadSopenharmony_ci
2255bd8deadSopenharmony_ci    NONE                buffer             IDirect3DIndexBuffer9
2265bd8deadSopenharmony_ci                                           IDirect3DVertexBuffer9
2275bd8deadSopenharmony_ci    --------------------------------------------------------------------------
2285bd8deadSopenharmony_ci    Table wgl.objtypes - Valid values for the <type> parameter of
2295bd8deadSopenharmony_ci    wglDXRegisterObjectNV and associated object types for GL and
2305bd8deadSopenharmony_ci    DirectX.
2315bd8deadSopenharmony_ci    --------------------------------------------------------------------------
2325bd8deadSopenharmony_ci
2335bd8deadSopenharmony_ci    --------------------------------------------------------------------------
2345bd8deadSopenharmony_ci    Resource Type            Resource Restrictions
2355bd8deadSopenharmony_ci    --------------------------------------------------------------------------
2365bd8deadSopenharmony_ci    IDirect3DSurface9        Must not be lockable
2375bd8deadSopenharmony_ci
2385bd8deadSopenharmony_ci    IDirect3DTexture9        Memory pool must be D3DPOOL_DEFAULT
2395bd8deadSopenharmony_ci
2405bd8deadSopenharmony_ci    IDirect3DCubeTexture9    Memory pool must be D3DPOOL_DEFAULT
2415bd8deadSopenharmony_ci
2425bd8deadSopenharmony_ci    IDirect3DVolumeTexture9  Memory pool must be D3DPOOL_DEFAULT
2435bd8deadSopenharmony_ci
2445bd8deadSopenharmony_ci    IDirect3DVertexBuffer9   Memory pool must be D3DPOOL_DEFAULT
2455bd8deadSopenharmony_ci
2465bd8deadSopenharmony_ci    IDirect3DIndexBuffer9    Memory pool must be D3DPOOL_DEFAULT
2475bd8deadSopenharmony_ci
2485bd8deadSopenharmony_ci   --------------------------------------------------------------------------
2495bd8deadSopenharmony_ci    Table wgl.restrictions - Restrictions on DirectX resources that can
2505bd8deadSopenharmony_ci    be registered via wglDXRegisterObjectNV
2515bd8deadSopenharmony_ci    --------------------------------------------------------------------------
2525bd8deadSopenharmony_ci
2535bd8deadSopenharmony_ci    Before a GL object which is associated with a DirectX resource may
2545bd8deadSopenharmony_ci    be used, it must be locked.  The function
2555bd8deadSopenharmony_ci
2565bd8deadSopenharmony_ci        BOOL wglDXLockObjectsNV(HANDLE hDevice, GLint count,
2575bd8deadSopenharmony_ci                                HANDLE *hObjects);
2585bd8deadSopenharmony_ci
2595bd8deadSopenharmony_ci    attempts to lock an array of <count> interop objects.  <hObjects>
2605bd8deadSopenharmony_ci    is an array of length <count> containing the handles of the
2615bd8deadSopenharmony_ci    objects to be locked.
2625bd8deadSopenharmony_ci
2635bd8deadSopenharmony_ci    A return value of TRUE indicates that all objects were
2645bd8deadSopenharmony_ci    successfully locked.  A return value of FALSE indicates an
2655bd8deadSopenharmony_ci    error. To get extended error information, call
2665bd8deadSopenharmony_ci    GetLastError. Possible errors are as follows:
2675bd8deadSopenharmony_ci
2685bd8deadSopenharmony_ci      ERROR_BUSY            One or more of the objects in <hObjects>
2695bd8deadSopenharmony_ci                            was already locked.
2705bd8deadSopenharmony_ci
2715bd8deadSopenharmony_ci      ERROR_INVALID_DATA    One or more of the objects in <hObjects>
2725bd8deadSopenharmony_ci                            does not belong to the interop device
2735bd8deadSopenharmony_ci                            specified by <hDevice>.
2745bd8deadSopenharmony_ci
2755bd8deadSopenharmony_ci      ERROR_LOCK_FAILED     One or more of the objects in <hObjects>
2765bd8deadSopenharmony_ci                            failed to lock.
2775bd8deadSopenharmony_ci
2785bd8deadSopenharmony_ci    If the function returns FALSE, none of the objects will be locked.
2795bd8deadSopenharmony_ci
2805bd8deadSopenharmony_ci    Attempting to access an interop object via GL when the object is
2815bd8deadSopenharmony_ci    not locked, or attempting to access the DirectX resource through
2825bd8deadSopenharmony_ci    the DirectX API when it is locked by GL, will result in undefined
2835bd8deadSopenharmony_ci    behavior and may result in data corruption or program
2845bd8deadSopenharmony_ci    termination. Likewise, passing invalid interop device or object
2855bd8deadSopenharmony_ci    handles to this function has undefined results, including program
2865bd8deadSopenharmony_ci    termination.
2875bd8deadSopenharmony_ci
2885bd8deadSopenharmony_ci    Locked objects are available for operations which read or write
2895bd8deadSopenharmony_ci    the data store, according to the access mode specified in
2905bd8deadSopenharmony_ci    wglDXRegisterObjectNV.  If a different access mode is required
2915bd8deadSopenharmony_ci    after the object has been registered, the access mode may be
2925bd8deadSopenharmony_ci    modified by calling
2935bd8deadSopenharmony_ci
2945bd8deadSopenharmony_ci        BOOL wglDXObjectAccessNV(HANDLE hObject, GLenum access);
2955bd8deadSopenharmony_ci
2965bd8deadSopenharmony_ci    <hObject> is an interop object handle returned by
2975bd8deadSopenharmony_ci    wglDXRegisterObjectNV and identifies the interop object for which
2985bd8deadSopenharmony_ci    the access mode should be modified.
2995bd8deadSopenharmony_ci
3005bd8deadSopenharmony_ci    <access> is a new access mode with the same meaning as the
3015bd8deadSopenharmony_ci    <access> parameter of wglDXRegisterObjectNV.  The access mode may
3025bd8deadSopenharmony_ci    be modified only when an object is not locked and will affect
3035bd8deadSopenharmony_ci    subsequent lock operations.
3045bd8deadSopenharmony_ci
3055bd8deadSopenharmony_ci    The return value is TRUE if the function succeeds. If an error
3065bd8deadSopenharmony_ci    occurs, the return will be FALSE. To get extended error
3075bd8deadSopenharmony_ci    information, call GetLastError. Possible errors are as follows:
3085bd8deadSopenharmony_ci
3095bd8deadSopenharmony_ci      ERROR_INVALID_DATA      Invalid <access> parameter.
3105bd8deadSopenharmony_ci
3115bd8deadSopenharmony_ci      ERROR_BUSY              <hObject> is currently locked for
3125bd8deadSopenharmony_ci                              GL access.
3135bd8deadSopenharmony_ci
3145bd8deadSopenharmony_ci    Operations which attempt to read or write an object in a manner
3155bd8deadSopenharmony_ci    inconsistent with the specified access mode will result in
3165bd8deadSopenharmony_ci    undefined behavior and may result in data corruption or program
3175bd8deadSopenharmony_ci    termination.
3185bd8deadSopenharmony_ci
3195bd8deadSopenharmony_ci    Calling wglDXObjectAccessNV with an invalid <hObject> parameter
3205bd8deadSopenharmony_ci    results in undefined behavior and may result in data corruption or
3215bd8deadSopenharmony_ci    program termination.
3225bd8deadSopenharmony_ci
3235bd8deadSopenharmony_ci    In order to return control of an object to DirectX, it must be unlocked
3245bd8deadSopenharmony_ci    by calling
3255bd8deadSopenharmony_ci
3265bd8deadSopenharmony_ci        BOOL wglDXUnlockObjectsNV(HANDLE hDevice, GLint count,
3275bd8deadSopenharmony_ci                                  HANDLE *hObjects);
3285bd8deadSopenharmony_ci
3295bd8deadSopenharmony_ci    A return value of TRUE indicates that the objects were
3305bd8deadSopenharmony_ci    successfully unlocked and DirectX may now safely access them.  A
3315bd8deadSopenharmony_ci    return value of FALSE indicates that an error occurred. To get
3325bd8deadSopenharmony_ci    extended error information, call GetLastError. Possible errors are
3335bd8deadSopenharmony_ci    as follows:
3345bd8deadSopenharmony_ci
3355bd8deadSopenharmony_ci      ERROR_NOT_LOCKED      One or more of the objects in <hObjects>
3365bd8deadSopenharmony_ci                            was not locked.
3375bd8deadSopenharmony_ci
3385bd8deadSopenharmony_ci      ERROR_INVALID_DATA    One or more of the objects in <hObjects>
3395bd8deadSopenharmony_ci                            does not belong to the interop device
3405bd8deadSopenharmony_ci                            identified by <hDevice>.
3415bd8deadSopenharmony_ci
3425bd8deadSopenharmony_ci      ERROR_LOCK_FAILED     One or more of the objects in <hObjects>
3435bd8deadSopenharmony_ci                            failed to unlock.
3445bd8deadSopenharmony_ci
3455bd8deadSopenharmony_ci    If the function returns FALSE, none of the objects are unlocked.
3465bd8deadSopenharmony_ci
3475bd8deadSopenharmony_ci    Results are undefined if any of the handles in <hObjects> are
3485bd8deadSopenharmony_ci    invalid and may result in data corruption or program termination.
3495bd8deadSopenharmony_ci
3505bd8deadSopenharmony_ci    When access to a DirectX resource from GL is no longer required, the
3515bd8deadSopenharmony_ci    association between the GL object and the DirectX resource should be
3525bd8deadSopenharmony_ci    terminated by calling
3535bd8deadSopenharmony_ci
3545bd8deadSopenharmony_ci        BOOL wglDXUnregisterObjectNV(HANDLE hObject);
3555bd8deadSopenharmony_ci
3565bd8deadSopenharmony_ci    where <hObject> is the interop object handle returned by
3575bd8deadSopenharmony_ci    wglDXRegisterObjectNV.  Any subsequent attempt to access
3585bd8deadSopenharmony_ci    <hObject> will result in undefined behavior and may result in data
3595bd8deadSopenharmony_ci    corruption or program termination.
3605bd8deadSopenharmony_ci
3615bd8deadSopenharmony_ci    A return value of TRUE indicates that the object was successfully
3625bd8deadSopenharmony_ci    unregistered and <hObject> is now invalid. A return value of FALSE
3635bd8deadSopenharmony_ci    indicates that an error occurred. To get extended error
3645bd8deadSopenharmony_ci    information, call GetLastError. Possible errors are as follows:
3655bd8deadSopenharmony_ci
3665bd8deadSopenharmony_ci      ERROR_BUSY      <hObject> is currently locked for access
3675bd8deadSopenharmony_ci                      by the GL
3685bd8deadSopenharmony_ci
3695bd8deadSopenharmony_ci    Results are undefined if <hObject> is invalid and may result in
3705bd8deadSopenharmony_ci    program termination or data corruption.
3715bd8deadSopenharmony_ci
3725bd8deadSopenharmony_ci    When all interop operations have been completed, the connection
3735bd8deadSopenharmony_ci    between OpenGL and DirectX may be terminated by calling
3745bd8deadSopenharmony_ci
3755bd8deadSopenharmony_ci        BOOL wglDXCloseDeviceNV(HANDLE hDevice);
3765bd8deadSopenharmony_ci
3775bd8deadSopenharmony_ci    where <hDevice> is the interop device handle returned by
3785bd8deadSopenharmony_ci    wglDXOpenDeviceNV.  Once the device is closed, any attempt to
3795bd8deadSopenharmony_ci    access DirectX resources through associated GL handles will result
3805bd8deadSopenharmony_ci    in undefined behavior and may result in data corruption or program
3815bd8deadSopenharmony_ci    termination.
3825bd8deadSopenharmony_ci
3835bd8deadSopenharmony_ci    A return value of TRUE indicates that the device was successfully
3845bd8deadSopenharmony_ci    closed and <hDevice> is now invalid. A return value of FALSE
3855bd8deadSopenharmony_ci    indicates an error. To get extended error information, call
3865bd8deadSopenharmony_ci    GetLastError. Possible errors are as follows:
3875bd8deadSopenharmony_ci
3885bd8deadSopenharmony_ci        ERROR_INVALID_DATA          The Direct3D device failed to
3895bd8deadSopenharmony_ci                                    close.
3905bd8deadSopenharmony_ci
3915bd8deadSopenharmony_ci    Calling this function with an invalid <hDevice> parameter results
3925bd8deadSopenharmony_ci    in undefined behavior and may result in data corruption or program
3935bd8deadSopenharmony_ci    termination.
3945bd8deadSopenharmony_ci
3955bd8deadSopenharmony_ciIssues
3965bd8deadSopenharmony_ci
3975bd8deadSopenharmony_ci    1) Should we support explicit usage of share handles under WDDM or
3985bd8deadSopenharmony_ci    disallow it entirely?
3995bd8deadSopenharmony_ci
4005bd8deadSopenharmony_ci    RESOLUTION: We should support it. Implicit share handles are
4015bd8deadSopenharmony_ci    useful when writing code that's meant to be portable between WDDM
4025bd8deadSopenharmony_ci    and non-WDDM operating systems; explicit share handles are useful
4035bd8deadSopenharmony_ci    when writing an application that needs to share resources with
4045bd8deadSopenharmony_ci    non-GL clients.
4055bd8deadSopenharmony_ci
4065bd8deadSopenharmony_ci    2) Can DirectX and OpenGL render concurrently to the same DirectX
4075bd8deadSopenharmony_ci    resource?
4085bd8deadSopenharmony_ci
4095bd8deadSopenharmony_ci    RESOLUTION: Concurrent rendering by OpenGL and DirectX to the same
4105bd8deadSopenharmony_ci    resource is not supported.
4115bd8deadSopenharmony_ci
4125bd8deadSopenharmony_ci    DISCUSSION: The Lock/Unlock calls serve as synchronization points
4135bd8deadSopenharmony_ci    between OpenGL and DirectX. They ensure that any rendering
4145bd8deadSopenharmony_ci    operations that affect the resource on one driver are complete
4155bd8deadSopenharmony_ci    before the other driver takes ownership of it.
4165bd8deadSopenharmony_ci
4175bd8deadSopenharmony_ci    When sharing a large resource, applications can potentially desire
4185bd8deadSopenharmony_ci    concurrent access to different regions of the resource (e.g., if
4195bd8deadSopenharmony_ci    the application is drawing a user interface in DirectX with an
4205bd8deadSopenharmony_ci    OpenGL viewport occupying a region of it, where the UI and OpenGL
4215bd8deadSopenharmony_ci    regions do not overlap). In this case, more fine-grained
4225bd8deadSopenharmony_ci    synchronization could be achieved by not doing implicit
4235bd8deadSopenharmony_ci    synchronization on the driver side and providing primitives to the
4245bd8deadSopenharmony_ci    application to enable it to synchronize on it's own, for instance,
4255bd8deadSopenharmony_ci    by allowing a DirectX 9 event query to be mapped and used as a GL
4265bd8deadSopenharmony_ci    sync object. This is, however, beyond the scope of the current
4275bd8deadSopenharmony_ci    extension.
4285bd8deadSopenharmony_ci
4295bd8deadSopenharmony_ci    3) If two GL contexts are sharing textures, what is the correct
4305bd8deadSopenharmony_ci    way to access a DirectX resource from both contexts?
4315bd8deadSopenharmony_ci
4325bd8deadSopenharmony_ci    RESOLUTION: Sharing a DirectX resource among multiple GL contexts is
4335bd8deadSopenharmony_ci    best achieved without having shared namespaces among the GL
4345bd8deadSopenharmony_ci    contexts, by simply registering the texture on each GL context
4355bd8deadSopenharmony_ci    separately.
4365bd8deadSopenharmony_ci
4375bd8deadSopenharmony_ci    If two GL contexts share namespaces, it is still necessary to lock
4385bd8deadSopenharmony_ci    the DirectX resource for each GL context that needs to access
4395bd8deadSopenharmony_ci    it. Note that only one GL context may hold the lock on the
4405bd8deadSopenharmony_ci    resource at any given time --- concurrent access from multiple GL
4415bd8deadSopenharmony_ci    contexts is not currently supported.
4425bd8deadSopenharmony_ci
4435bd8deadSopenharmony_ci    4) How do driver control panel settings regarding anti-aliasing
4445bd8deadSopenharmony_ci    modes affect this extension?
4455bd8deadSopenharmony_ci
4465bd8deadSopenharmony_ci    DISCUSSION: User-configurable system settings may allow users to
4475bd8deadSopenharmony_ci    force anti-aliasing for applications that do not support
4485bd8deadSopenharmony_ci    it. Usually, this causes the implementation to create multisampled
4495bd8deadSopenharmony_ci    surfaces for render targets that the application creates as
4505bd8deadSopenharmony_ci    non-multisampled.
4515bd8deadSopenharmony_ci
4525bd8deadSopenharmony_ci    GL API semantics for textures can differ between multisample and
4535bd8deadSopenharmony_ci    non-multisample textures. If the application creates a DirectX
4545bd8deadSopenharmony_ci    render target that is to be bound as a GL texture, it will have no
4555bd8deadSopenharmony_ci    way to know that the surface is actually multisampled, but GL will
4565bd8deadSopenharmony_ci    require that it is bound to the TEXTURE_2D_MULTISAMPLE target
4575bd8deadSopenharmony_ci    instead of the TEXTURE_2D target. Because of this, it is
4585bd8deadSopenharmony_ci    recommended that render targets be bound to GL renderbuffers
4595bd8deadSopenharmony_ci    instead.
4605bd8deadSopenharmony_ci
4615bd8deadSopenharmony_ci    Additionally, DirectX implementations are free to create render
4625bd8deadSopenharmony_ci    targets that do not match the number of samples that the app
4635bd8deadSopenharmony_ci    requested. Implementations are also free to create color and depth
4645bd8deadSopenharmony_ci    render targets with incompatible multisample modes. This can
4655bd8deadSopenharmony_ci    result in FBO completeness errors if incompatible color and depth
4665bd8deadSopenharmony_ci    render targets are bound for rendering to the same FBO. This
4675bd8deadSopenharmony_ci    problem also exists with pure DirectX applications and is not
4685bd8deadSopenharmony_ci    specific to this extension.
4695bd8deadSopenharmony_ci
4705bd8deadSopenharmony_ciSample Code
4715bd8deadSopenharmony_ci
4725bd8deadSopenharmony_ci    Render to Direct3D 9 multisample color and depth buffers with
4735bd8deadSopenharmony_ci    OpenGL under WDDM:
4745bd8deadSopenharmony_ci
4755bd8deadSopenharmony_ci    // create the Direct3D9Ex device:
4765bd8deadSopenharmony_ci    IDirect3D9Ex *direct3D;
4775bd8deadSopenharmony_ci    IDirect3DDevice9Ex *device;
4785bd8deadSopenharmony_ci    D3DPRESENT_PARAMETERS d3dpp;
4795bd8deadSopenharmony_ci
4805bd8deadSopenharmony_ci    direct3D = Direct3DCreate9Ex(D3D_SDK_VERSION, &direct3D);
4815bd8deadSopenharmony_ci
4825bd8deadSopenharmony_ci    <set appropriate device parameters in d3dpp>
4835bd8deadSopenharmony_ci
4845bd8deadSopenharmony_ci    direct3D->CreateDevice(D3DADAPTER_DEFAULT,
4855bd8deadSopenharmony_ci                           D3DDEVTYPE_HAL,
4865bd8deadSopenharmony_ci                           hWnd,
4875bd8deadSopenharmony_ci                           D3DCREATE_HARDWARE_VERTEXPROCESSING |
4885bd8deadSopenharmony_ci                           D3DCREATE_PUREDEVICE |
4895bd8deadSopenharmony_ci                           D3DCREATE_MULTITHREADED,
4905bd8deadSopenharmony_ci                           &d3dpp,
4915bd8deadSopenharmony_ci                           &device);
4925bd8deadSopenharmony_ci
4935bd8deadSopenharmony_ci    // create the Direct3D render targets
4945bd8deadSopenharmony_ci    IDirect3DSurface9 *dxColorBuffer;
4955bd8deadSopenharmony_ci    IDirect3DSurface9 *dxDepthBuffer;
4965bd8deadSopenharmony_ci
4975bd8deadSopenharmony_ci    device->CreateRenderTarget(width, height,
4985bd8deadSopenharmony_ci                               D3DFMT_A8R8G8B8,
4995bd8deadSopenharmony_ci                               D3DMULTISAMPLE_4_SAMPLES, 0,
5005bd8deadSopenharmony_ci                               FALSE,
5015bd8deadSopenharmony_ci                               &dxColorBuffer,
5025bd8deadSopenharmony_ci                               NULL);
5035bd8deadSopenharmony_ci
5045bd8deadSopenharmony_ci    device->CreateDepthStencilSurface(width, height,
5055bd8deadSopenharmony_ci                                      D3DFMT_D24S8,
5065bd8deadSopenharmony_ci                                      D3DMULTISAMPLE_4_SAMPLES, 0,
5075bd8deadSopenharmony_ci                                      FALSE,
5085bd8deadSopenharmony_ci                                      &dxDepthBuffer,
5095bd8deadSopenharmony_ci                                      NULL);
5105bd8deadSopenharmony_ci
5115bd8deadSopenharmony_ci    // register the Direct3D device with GL
5125bd8deadSopenharmony_ci    HANDLE gl_handleD3D;
5135bd8deadSopenharmony_ci    gl_handleD3D = wglDXOpenDeviceNV(device);
5145bd8deadSopenharmony_ci
5155bd8deadSopenharmony_ci    // register the Direct3D color and depth/stencil buffers as
5165bd8deadSopenharmony_ci    // 2D multisample textures in opengl
5175bd8deadSopenharmony_ci    GLuint gl_names[2];
5185bd8deadSopenharmony_ci    HANDLE gl_handles[2];
5195bd8deadSopenharmony_ci
5205bd8deadSopenharmony_ci    glGenTextures(2, gl_names);
5215bd8deadSopenharmony_ci
5225bd8deadSopenharmony_ci    gl_handles[0] = wglDXRegisterObjectNV(gl_handleD3D, dxColorBuffer,
5235bd8deadSopenharmony_ci                                          gl_names[0],
5245bd8deadSopenharmony_ci                                          GL_TEXTURE_2D_MULTISAMPLE,
5255bd8deadSopenharmony_ci                                          WGL_ACCESS_READ_WRITE_NV);
5265bd8deadSopenharmony_ci
5275bd8deadSopenharmony_ci    gl_handles[1] = wglDXRegisterObjectNV(gl_handleD3D, dxDepthBuffer,
5285bd8deadSopenharmony_ci                                          gl_names[1],
5295bd8deadSopenharmony_ci                                          GL_TEXTURE_2D_MULTISAMPLE,
5305bd8deadSopenharmony_ci                                          WGL_ACCESS_READ_WRITE_NV);
5315bd8deadSopenharmony_ci
5325bd8deadSopenharmony_ci    // attach the Direct3D buffers to an FBO
5335bd8deadSopenharmony_ci    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
5345bd8deadSopenharmony_ci    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
5355bd8deadSopenharmony_ci                           GL_TEXTURE_2D_MULTISAMPLE, gl_names[0]);
5365bd8deadSopenharmony_ci    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
5375bd8deadSopenharmony_ci                           GL_TEXTURE_2D_MULTISAMPLE, gl_names[1]);
5385bd8deadSopenharmony_ci    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
5395bd8deadSopenharmony_ci                           GL_TEXTURE_2D_MULTISAMPLE, gl_names[1]);
5405bd8deadSopenharmony_ci
5415bd8deadSopenharmony_ci    // rendering loop
5425bd8deadSopenharmony_ci    while (!done) {
5435bd8deadSopenharmony_ci          <direct3d renders to the render targets>
5445bd8deadSopenharmony_ci
5455bd8deadSopenharmony_ci          // lock the render targets for GL access
5465bd8deadSopenharmony_ci          wglDXLockObjectsNV(handleD3D, 2, gl_handles);
5475bd8deadSopenharmony_ci
5485bd8deadSopenharmony_ci          <opengl renders to the render targets>
5495bd8deadSopenharmony_ci
5505bd8deadSopenharmony_ci          // unlock the render targets
5515bd8deadSopenharmony_ci          wglDXUnlockObjectsNV(handleD3D, 2, gl_handles);
5525bd8deadSopenharmony_ci
5535bd8deadSopenharmony_ci          <direct3d renders to the render targets and presents
5545bd8deadSopenharmony_ci           the results on the screen>
5555bd8deadSopenharmony_ci    }
5565bd8deadSopenharmony_ci
5575bd8deadSopenharmony_ciRevision History
5585bd8deadSopenharmony_ci
5595bd8deadSopenharmony_ci    Revision 1, 2010/11/10
5605bd8deadSopenharmony_ci     - Initial public revision
561