examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutGLDXinterop.cpp
//
// =================== DX9 ===============================
//
//		CreateDX9interop()
//	
//		bReceive		when receiving a texture from a DX application this must be set to true (default)
//						when sending a texture from GL to the DX application, set to false
//



bReceive                when receiving a texture from a DX application this must be set to true (default)
when sending a texture from GL to the DX application, set to false
bReceive when receiving a texture from a DX application this must be set to true ( default ) when sending a texture from GL to the DX application set to false
bool spoutGLDXinterop::CreateDX9interop(unsigned int width, unsigned int height, DWORD dwFormat, bool bReceive) 
{
	if (!bReceive) {
		m_dxShareHandle = NULL; 
	}
	if (m_dxTexture != NULL) {
		m_dxTexture->Release();
	}
	m_dxTexture = NULL;
	if(!spoutdx.CreateSharedDX9Texture(m_pDevice,
									   width,
									   height,
									   (D3DFORMAT)dwFormat,  
									   m_dxTexture,
									   m_dxShareHandle)) {
		printf("    CreateSharedDX9Texture failed\n");								   
		return false;
	}
	if(m_bUseCPU) {
		if(g_DX9surface != NULL) {
			g_DX9surface->Release();
			g_DX9surface = NULL;
		}
		HRESULT hr = m_pDevice->CreateOffscreenPlainSurface(width, height, (D3DFORMAT)dwFormat, D3DPOOL_SYSTEMMEM, &g_DX9surface, NULL);
		if(FAILED(hr)) {
			printf("    DX9 create texture surface failed\n");
			return false;
		}
	}
	else {
		if(m_hInteropDevice != NULL &&  m_hInteropObject != NULL) {
			wglDXUnregisterObjectNV(m_hInteropDevice, m_hInteropObject);
			m_hInteropObject = NULL;
		}
		m_hInteropObject = LinkGLDXtextures(m_pDevice, m_dxTexture, m_dxShareHandle, m_glTexture); 
		if(!m_hInteropObject) {
			printf("    DX9 LinkGLDXtextures failed\n");	
			return false;
		}
	}
	return true;
}
bool spoutGLDXinterop :: CreateDX9interop ( unsigned int width , unsigned int height , DWORD dwFormat , bool bReceive ) { if ( ! bReceive ) { m_dxShareHandle = NULL ; } if ( m_dxTexture != NULL ) { m_dxTexture -> Release ( ) ; } m_dxTexture = NULL ; if ( ! spoutdx . CreateSharedDX9Texture ( m_pDevice , width , height , ( D3DFORMAT ) dwFormat , m_dxTexture , m_dxShareHandle ) ) { printf ( " \n " ) ; return false ; } if ( m_bUseCPU ) { if ( g_DX9surface != NULL ) { g_DX9surface -> Release ( ) ; g_DX9surface = NULL ; } HRESULT hr = m_pDevice -> CreateOffscreenPlainSurface ( width , height , ( D3DFORMAT ) dwFormat , D3DPOOL_SYSTEMMEM , & g_DX9surface , NULL ) ; if ( FAILED ( hr ) ) { printf ( " \n " ) ; return false ; } } else { if ( m_hInteropDevice != NULL && m_hInteropObject != NULL ) { wglDXUnregisterObjectNV ( m_hInteropDevice , m_hInteropObject ) ; m_hInteropObject = NULL ; } m_hInteropObject = LinkGLDXtextures ( m_pDevice , m_dxTexture , m_dxShareHandle , m_glTexture ) ; if ( ! m_hInteropObject ) { printf ( " \n " ) ; return false ; } } return true ; }
DX9 
CreateDX9interop()
DX9 CreateDX9interop ()
// printf("CreateDX9interop(%dx%d, [Format = %d], %d (m_pDevice = %x)\n", width, height, dwFormat, bReceive, m_pDevice);
 // The shared texture handle of the Sender texture "m_dxShareHandle" 
 // is already set by getSharedTextureInfo, but should be NULL for a sender
 // printf("    sender - setting m_dxShareHandle to NULL\n");
 // Create a new shared DirectX resource m_dxTexture 
 // with new local handle m_dxShareHandle for a sender
 // A sender creates a new texture
 // Safety in case an application has crashed
 // printf("   releasing texture\n");
 // Create a shared DirectX9 texture - m_dxTexture
 // by giving it a sharehandle variable - m_dxShareHandle
 // For a SENDER : the sharehandle is NULL and a new texture is created
 // For a RECEIVER : the sharehandle is valid and becomes a handle to the existing shared texture
 // USAGE is D3DUSAGE_RENDERTARGET
 // default is D3DFMT_A8R8G8B8
 // printf("CreateDX9interop : m_dxTexture = [%x]\n");
 //
 // For CPU access to the shared texture a DX9 surface is created
 // and the GL/DX interop is not used
 //
 // DX9 texture surface in CPU memory
 // Create a CPU accessable surface to get pixels from the shared texture
 // For the GL/DX interop, link the shared DirectX texture to the OpenGL texture
 // This registers for interop and associates the opengl texture with the dx texture
 // by calling wglDXRegisterObjectNV which returns a handle to the interop object
 // (the shared texture) (m_hInteropObject)
 // When a sender size changes, the new texture has to be re-registered
 // printf("CreateInterop - wglDXUnregisterObjectNV\n");
