Example #1
0
// LJ DEBUG - TODO - not working
// Re-link a gl texture to the shared directX texture
bool spoutGLDXinterop::LinkGLtexture(GLuint glTexture) 
{
	// printf("LinkGLtexture(%d)\n", glTexture);
	if(g_pd3dDevice == NULL || g_pSharedTexture == NULL || m_dxShareHandle == NULL) {
		// printf("    null handles\n");
		return false;
	}

	if(m_hInteropDevice != NULL &&  m_hInteropObject != NULL) {
		// printf("    unregister\n");
		wglDXUnregisterObjectNV(m_hInteropDevice, m_hInteropObject);
		m_hInteropObject = NULL;
	}
	// printf("    unregister OK\n");

	if (m_hInteropDevice != NULL) {
		wglDXCloseDeviceNV(m_hInteropDevice);
	}

	// printf("    close device OK\n");
	m_hInteropDevice = NULL;
	m_hInteropObject = NULL;


	m_hInteropDevice = wglDXOpenDeviceNV(g_pd3dDevice);
	if (m_hInteropDevice == NULL) {
		// printf("    open device fail\n");
		return false;
	}
	// printf("    open device OK\n");

	// Prepare the DirectX texture for use by OpenGL
	// register for interop and associate the opengl texture with the dx texture
	m_hInteropObject = wglDXRegisterObjectNV(g_pd3dDevice, 
											 g_pSharedTexture,		// DX texture
											 glTexture,				// OpenGL texture
											 GL_TEXTURE_2D,			// Must be TEXTURE_2D
											 WGL_ACCESS_READ_WRITE_NV); // We will write and the receiver will read

	if(!m_hInteropObject) {
		// printf("    null InteropObject\n");
		return false;
	}

	// printf("    InteropObject OK\n");

	return true;

}
 void RenderManagerD3D11OpenGL::cleanupGL() {
     if (m_glD3DHandle) {
         for (size_t i = 0; i < m_oglToD3D.size(); i++) {
             wglDXUnregisterObjectNV(m_glD3DHandle,
                                     m_oglToD3D[i].glColorHandle);
         }
         wglDXCloseDeviceNV(m_glD3DHandle);
         m_glD3DHandle = nullptr;
     }
     delete m_buffers.OpenGL;
     m_buffers.OpenGL = nullptr;
     delete m_library.OpenGL;
     m_library.OpenGL = nullptr;
     removeOpenGLContexts();
 }
Example #3
0
D3DPresentEngine::~D3DPresentEngine()
{
	if (gl_handleD3D) {
		releaseSharedTexture() ;

		printf("WMFVideoPlayer : Killing present engine.....");
		if (wglDXCloseDeviceNV(gl_handleD3D)) 
		{
			printf("SUCCESS\n");
		}
		else printf("FAILED closing handle\n");
	}
    SAFE_RELEASE(m_pDevice);
    SAFE_RELEASE(m_pSurfaceRepaint);
    SAFE_RELEASE(m_pDeviceManager);
    SAFE_RELEASE(m_pD3D9);
}
D3DPresentEngine::~D3DPresentEngine()
{
	if (gl_handleD3D) {
		releaseSharedTexture() ;

		CI_LOG_I("Killing present engine.....");
		if (wglDXCloseDeviceNV(gl_handleD3D)) 
		{
			CI_LOG_I( "SUCCESS" );
		}
		else {
			CI_LOG_I( "FAILED closing handle" );
		}
	}
    SAFE_RELEASE(m_pDevice);
    SAFE_RELEASE(m_pSurfaceRepaint);
    SAFE_RELEASE(m_pDeviceManager);
    SAFE_RELEASE(m_pD3D9);
}
Example #5
0
// this is the function that cleans up Direct3D and the gldx interop
// The exit flag is a fix - trouble is with wglDXUnregisterObjectNV
// which crashes on exit to the program but not if called
// while the program is running. Likely due to no GL context on exit
void spoutGLDXinterop::CleanupInterop(bool bExit)
{
	// Some of these things need an opengl context so check
	if(wglGetCurrentContext() != NULL) {
		// Problem here on exit, but not on change of resolution while the program is running !?
		// On exit there may be no openGL context but while the program is running there is
		if(!bExit && m_hInteropDevice != NULL && m_hInteropObject != NULL) {
			wglDXUnregisterObjectNV(m_hInteropDevice, m_hInteropObject);
			m_hInteropObject = NULL;
		}
		if (m_hInteropDevice != NULL) {
			wglDXCloseDeviceNV(m_hInteropDevice);
			m_hInteropDevice = NULL;
		}

		if(m_glTexture)	{
			glDeleteTextures(1, &m_glTexture);
			m_glTexture = 0;
		}

		if(m_fbo) {
			glDeleteFramebuffersEXT(1, &m_fbo);
			m_fbo = 0;
		}

	} // endif there is an opengl context

	CleanupDirectX();

	// Close general texture access mutex
	spoutdx.CloseAccessMutex(m_hAccessMutex);
	m_hAccessMutex = NULL; // Double check that the global handle is NULL

	m_bInitialized = false;

}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WGLNVDXInterop_nwglDXCloseDeviceNV(JNIEnv *__env, jclass clazz, jlong deviceAddress, jlong __functionAddress) {
	HANDLE device = (HANDLE)(intptr_t)deviceAddress;
	wglDXCloseDeviceNVPROC wglDXCloseDeviceNV = (wglDXCloseDeviceNVPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	return (jint)wglDXCloseDeviceNV(device);
}