examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutGLDXinterop.cpp
//
// Draw the shared DirectX 11 texture
// equivalent to DrawSharedTexture for the shared OpenGL texture
//

Draw the shared DirectX 11 texture
equivalent to DrawSharedTexture for the shared OpenGL texture
Draw the shared DirectX 11 texture equivalent to DrawSharedTexture for the shared OpenGL texture
bool spoutGLDXinterop::DrawDX11texture(float max_x, float max_y, float aspect, bool bInvert, GLuint HostFBO)
{
	D3D11_MAPPED_SUBRESOURCE mappedSubResource;
	HRESULT hr;
	void * dataPointer = NULL;
	unsigned int width, height;
	UNREFERENCED_PARAMETER(HostFBO);
	if(GetDX9())
		return false;
	width  = m_TextureInfo.width;
	height = m_TextureInfo.height;
	if(!CheckStagingTexture(width, height))
		return false;
	CheckOpenGLTexture(m_TexID, GL_RGBA, width, height, m_TexWidth, m_TexHeight);
	if(ReadTexture(&g_pStagingTexture)) {
		FlushWait(); 
		if(g_pImmediateContext) {
			hr = g_pImmediateContext->Map(g_pStagingTexture, 0, D3D11_MAP_READ, 0, &mappedSubResource);
			if(SUCCEEDED(hr)) {
				dataPointer = mappedSubResource.pData;
				if(dataPointer) {
					glBindTexture(GL_TEXTURE_2D, m_TexID);
					glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, dataPointer);
					glBindTexture(GL_TEXTURE_2D, 0);
					SaveOpenGLstate(width, height);
					glEnable(GL_TEXTURE_2D);
					glBindTexture(GL_TEXTURE_2D, m_TexID); 
					glColor4f(1.f, 1.f, 1.f, 1.f);
					glBegin(GL_QUADS);
					if(bInvert) {
						glTexCoord2f(0.0,   0.0);	glVertex2f(-aspect,-1.0); 
						glTexCoord2f(0.0,   max_y);	glVertex2f(-aspect, 1.0); 
						glTexCoord2f(max_x, max_y);	glVertex2f( aspect, 1.0); 
						glTexCoord2f(max_x, 0.0);	glVertex2f( aspect,-1.0); 
					}
					else {
						glTexCoord2f(0.0,	max_y);	glVertex2f(-aspect,-1.0); 
						glTexCoord2f(0.0,	0.0);	glVertex2f(-aspect, 1.0); 
						glTexCoord2f(max_x, 0.0);	glVertex2f( aspect, 1.0); 
						glTexCoord2f(max_x, max_y);	glVertex2f( aspect,-1.0); 
					}
					glEnd();
					glBindTexture(GL_TEXTURE_2D, 0); 
					glDisable(GL_TEXTURE_2D);
					RestoreOpenGLstate();
				}
				g_pImmediateContext->Unmap(g_pStagingTexture, 0);
				return true;
			}
		} 
	} 
	return false;
}
bool spoutGLDXinterop :: DrawDX11texture ( float max_x , float max_y , float aspect , bool bInvert , GLuint HostFBO ) { D3D11_MAPPED_SUBRESOURCE mappedSubResource ; HRESULT hr ; void * dataPointer = NULL ; unsigned int width , height ; UNREFERENCED_PARAMETER ( HostFBO ) ; if ( GetDX9 ( ) ) return false ; width = m_TextureInfo . width ; height = m_TextureInfo . height ; if ( ! CheckStagingTexture ( width , height ) ) return false ; CheckOpenGLTexture ( m_TexID , GL_RGBA , width , height , m_TexWidth , m_TexHeight ) ; if ( ReadTexture ( & g_pStagingTexture ) ) { FlushWait ( ) ; if ( g_pImmediateContext ) { hr = g_pImmediateContext -> Map ( g_pStagingTexture , 0 , D3D11_MAP_READ , 0 , & mappedSubResource ) ; if ( SUCCEEDED ( hr ) ) { dataPointer = mappedSubResource . pData ; if ( dataPointer ) { glBindTexture ( GL_TEXTURE_2D , m_TexID ) ; glTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , width , height , GL_BGRA_EXT , GL_UNSIGNED_BYTE , dataPointer ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; SaveOpenGLstate ( width , height ) ; glEnable ( GL_TEXTURE_2D ) ; glBindTexture ( GL_TEXTURE_2D , m_TexID ) ; glColor4f ( 1.f , 1.f , 1.f , 1.f ) ; glBegin ( GL_QUADS ) ; if ( bInvert ) { glTexCoord2f ( 0.0 , 0.0 ) ; glVertex2f ( - aspect , -1.0 ) ; glTexCoord2f ( 0.0 , max_y ) ; glVertex2f ( - aspect , 1.0 ) ; glTexCoord2f ( max_x , max_y ) ; glVertex2f ( aspect , 1.0 ) ; glTexCoord2f ( max_x , 0.0 ) ; glVertex2f ( aspect , -1.0 ) ; } else { glTexCoord2f ( 0.0 , max_y ) ; glVertex2f ( - aspect , -1.0 ) ; glTexCoord2f ( 0.0 , 0.0 ) ; glVertex2f ( - aspect , 1.0 ) ; glTexCoord2f ( max_x , 0.0 ) ; glVertex2f ( aspect , 1.0 ) ; glTexCoord2f ( max_x , max_y ) ; glVertex2f ( aspect , -1.0 ) ; } glEnd ( ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glDisable ( GL_TEXTURE_2D ) ; RestoreOpenGLstate ( ) ; } g_pImmediateContext -> Unmap ( g_pStagingTexture , 0 ) ; return true ; } } } return false ; }
Draw the shared DirectX 11 texture
equivalent to DrawSharedTexture for the shared OpenGL texture
Draw the shared DirectX 11 texture equivalent to DrawSharedTexture for the shared OpenGL texture
// Only for DX11 mode
 // If a staging texture has not been created or it is a different size, create a new one
 // Create or resize a local OpenGL texture
 // Read the shared texture data into the staging texture so it can be accessed
 // Wait for access to the staging texture
 // Map the staging texture resource to access the pixels
 // Get a pointer to the staging texture data
 // Copy the DX11 pixels to it
 // Draw the local texture and invert as necessary
 // bind texture
 // DirectX coordinates are already inverted
 // lower left
 // upper left
 // upper right
 // lower right
 // lower left
 // upper left
 // upper right
 // lower right
 // unbind shared texture
 // endif DX11 map OK
 // endif ReadTexture OK
