examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutGLDXinterop.cpp
//
//	GL/DX Interop lock
//
//	A return value of TRUE indicates that all objects were
//    successfully locked.  A return value of FALSE indicates an
//    error. If the function returns FALSE, none of the objects will be locked.
//
//	Attempting to access an interop object via GL when the object is
//    not locked, or attempting to access the DirectX resource through
//    the DirectX API when it is locked by GL, will result in undefined
//    behavior and may result in data corruption or program
//    termination. Likewise, passing invalid interop device or object
//    handles to this function has undefined results, including program
//    termination.
//
//	Note that only one GL context may hold the lock on the
//    resource at any given time --- concurrent access from multiple GL
//    contexts is not currently supported.
//
//	http://halogenica.net/sharing-resources-between-directx-and-opengl/
//
//	This lock triggers the GPU to perform the necessary flushing and stalling
//	to guarantee that the surface has finished being written to before reading from it. 
//
//	DISCUSSION: The Lock/Unlock calls serve as synchronization points
//    between OpenGL and DirectX. They ensure that any rendering
//    operations that affect the resource on one driver are complete
//    before the other driver takes ownership of it.
//
//	This function assumes only one object to 
//
//	Must return S_OK (0) - otherwise the error can be checked.
//

GL/DX Interop lock
A return value of TRUE indicates that all objects were
successfully locked.  A return value of FALSE indicates an
error. If the function returns FALSE, none of the objects will be locked.

Attempting to access an interop object via GL when the object is
not locked, or attempting to access the DirectX resource through
the DirectX API when it is locked by GL, will result in undefined
behavior and may result in data corruption or program
termination. Likewise, passing invalid interop device or object
handles to this function has undefined results, including program
termination.

Note that only one GL context may hold the lock on the
resource at any given time --- concurrent access from multiple GL
contexts is not currently supported.



This lock triggers the GPU to perform the necessary flushing and stalling
to guarantee that the surface has finished being written to before reading from it.

The Lock/Unlock calls serve as synchronization points
between OpenGL and DirectX. They ensure that any rendering
operations that affect the resource on one driver are complete
before the other driver takes ownership of it.

This function assumes only one object to

Must return S_OK (0) - otherwise the error can be checked.
GL / DX Interop lock A return value of TRUE indicates that all objects were successfully locked . A return value of FALSE indicates an error . If the function returns FALSE none of the objects will be locked . Attempting to access an interop object via GL when the object is not locked or attempting to access the DirectX resource through the DirectX API when it is locked by GL will result in undefined behavior and may result in data corruption or program termination . Likewise passing invalid interop device or object handles to this function has undefined results including program termination . Note that only one GL context may hold the lock on the resource at any given time --- concurrent access from multiple GL contexts is not currently supported . This lock triggers the GPU to perform the necessary flushing and stalling to guarantee that the surface has finished being written to before reading from it . The Lock / Unlock calls serve as synchronization points between OpenGL and DirectX . They ensure that any rendering operations that affect the resource on one driver are complete before the other driver takes ownership of it . This function assumes only one object to Must return S_OK ( 0 ) - otherwise the error can be checked .
HRESULT spoutGLDXinterop::LockInteropObject(HANDLE hDevice, HANDLE *hObject)
{
	DWORD dwError;
	HRESULT hr;
	if(hDevice == NULL || hObject == NULL || *hObject == NULL) {
		return E_HANDLE;
	}
	if(wglDXLockObjectsNV(hDevice, 1, hObject) == TRUE) {
		return S_OK;
	}
	else {
		dwError = GetLastError();
		switch (dwError) {
			case ERROR_BUSY :			
				hr = E_ACCESSDENIED;	
				break;
			case ERROR_INVALID_DATA :	
				hr = E_ABORT;			
				break;
			case ERROR_LOCK_FAILED :	
				hr = E_ABORT;			
				break;
			default:
				hr = E_FAIL;			
				break;
		} 
	} 
	return hr;
}
HRESULT spoutGLDXinterop :: LockInteropObject ( HANDLE hDevice , HANDLE * hObject ) { DWORD dwError ; HRESULT hr ; if ( hDevice == NULL || hObject == NULL || * hObject == NULL ) { return E_HANDLE ; } if ( wglDXLockObjectsNV ( hDevice , 1 , hObject ) == TRUE ) { return S_OK ; } else { dwError = GetLastError ( ) ; switch ( dwError ) { case ERROR_BUSY : hr = E_ACCESSDENIED ; break ; case ERROR_INVALID_DATA : hr = E_ABORT ; break ; case ERROR_LOCK_FAILED : hr = E_ABORT ; break ; default : hr = E_FAIL ; break ; } } return hr ; }
GL/DX Interop lock
A return value of TRUE indicates that all objects were
successfully locked.
GL / DX Interop lock A return value of TRUE indicates that all objects were successfully locked .
// lock dx object
 // One or more of the objects in <hObjects> was already locked.
 // General access denied error
 // printf("	spoutGLDXinterop::LockInteropObject ERROR_BUSY\n");
 // One or more of the objects in <hObjects>
 // does not belong to the interop device
 // specified by <hDevice>.
 // Operation aborted
 // printf("	spoutGLDXinterop::LockInteropObject ERROR_INVALID_DATA\n");
 // One or more of the objects in <hObjects> failed to 
 // Operation aborted
 // printf("	spoutGLDXinterop::LockInteropObject ERROR_LOCK_FAILED\n");
 // unspecified error
 // printf("	spoutGLDXinterop::LockInteropObject UNKNOWN_ERROR\n");
 // end switch
 // end false
