examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutGLDXinterop.cpp
//
// COPY AN OPENGL TEXTURE TO THE SHARED OPENGL TEXTURE
// 

COPY AN OPENGL TEXTURE TO THE SHARED OPENGL TEXTURE
COPY AN OPENGL TEXTURE TO THE SHARED OPENGL TEXTURE
bool spoutGLDXinterop::WriteGLDXtexture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert, GLuint HostFBO)
{
	GLenum status;
	if(m_hInteropDevice == NULL || m_hInteropObject == NULL) return false;
	if(width != m_TextureInfo.width || height != m_TextureInfo.height) return false;
	if(spoutdx.CheckAccess(m_hAccessMutex)) {
		if(LockInteropObject(m_hInteropDevice, &m_hInteropObject) == S_OK) {
			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
			glFramebufferTexture2DEXT(READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, TextureTarget, TextureID, 0);
			glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
			glFramebufferTexture2DEXT(DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, m_glTexture, 0);
			glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
			status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
			if(status == GL_FRAMEBUFFER_COMPLETE_EXT) {
				if(m_bBLITavailable) {
					if(bInvert) {
						glBlitFramebufferEXT(0, 0,			
											 width, height, 
											 0, height,		
											 width, 0,		
											 GL_COLOR_BUFFER_BIT, GL_NEAREST); 
					}
					else { 
						glBlitFramebufferEXT(0, 0,			
											 width, height,	
											 0, 0,			
											 width, height,	
											 GL_COLOR_BUFFER_BIT, GL_NEAREST); 
					}
				}
				else {
					glBindTexture(GL_TEXTURE_2D, m_glTexture);
					glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
					glBindTexture(GL_TEXTURE_2D, 0);
				}
			}
			else {
				PrintFBOstatus(status);
			}
			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, HostFBO);
			UnlockInteropObject(m_hInteropDevice, &m_hInteropObject);
			spoutdx.AllowAccess(m_hAccessMutex); 
			return true;
		}
	}
	spoutdx.AllowAccess(m_hAccessMutex); 
	return false;
}
bool spoutGLDXinterop :: WriteGLDXtexture ( GLuint TextureID , GLuint TextureTarget , unsigned int width , unsigned int height , bool bInvert , GLuint HostFBO ) { GLenum status ; if ( m_hInteropDevice == NULL || m_hInteropObject == NULL ) return false ; if ( width != m_TextureInfo . width || height != m_TextureInfo . height ) return false ; if ( spoutdx . CheckAccess ( m_hAccessMutex ) ) { if ( LockInteropObject ( m_hInteropDevice , & m_hInteropObject ) == S_OK ) { glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , m_fbo ) ; glFramebufferTexture2DEXT ( READ_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT , TextureTarget , TextureID , 0 ) ; glReadBuffer ( GL_COLOR_ATTACHMENT0_EXT ) ; glFramebufferTexture2DEXT ( DRAW_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT1_EXT , GL_TEXTURE_2D , m_glTexture , 0 ) ; glDrawBuffer ( GL_COLOR_ATTACHMENT1_EXT ) ; status = glCheckFramebufferStatusEXT ( GL_FRAMEBUFFER_EXT ) ; if ( status == GL_FRAMEBUFFER_COMPLETE_EXT ) { if ( m_bBLITavailable ) { if ( bInvert ) { glBlitFramebufferEXT ( 0 , 0 , width , height , 0 , height , width , 0 , GL_COLOR_BUFFER_BIT , GL_NEAREST ) ; } else { glBlitFramebufferEXT ( 0 , 0 , width , height , 0 , 0 , width , height , GL_COLOR_BUFFER_BIT , GL_NEAREST ) ; } } else { glBindTexture ( GL_TEXTURE_2D , m_glTexture ) ; glCopyTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , 0 , 0 , width , height ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; } } else { PrintFBOstatus ( status ) ; } glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , HostFBO ) ; UnlockInteropObject ( m_hInteropDevice , & m_hInteropObject ) ; spoutdx . AllowAccess ( m_hAccessMutex ) ; return true ; } } spoutdx . AllowAccess ( m_hAccessMutex ) ; return false ; }
COPY AN OPENGL TEXTURE TO THE SHARED OPENGL TEXTURE
COPY AN OPENGL TEXTURE TO THE SHARED OPENGL TEXTURE
// Wait for access to the texture
 // lock dx object
 // fbo is a  local FBO and width/height are the dimensions of the texture.
 // "TextureID" is the source texture, and "m_glTexture" is destination texture
 // which should have been already created
 // bind the FBO (for both, READ_FRAMEBUFFER_EXT and DRAW_FRAMEBUFFER_EXT)
 // Attach the Input texture to the color buffer in our frame buffer - note texturetarget 
 // Attach target texture (the shared texture we write into) to second attachment point
 // Default invert flag is false so do the flip to get it the right way up if the user wants that
 // Blit method with checks - 0.75 - 0.85 msec
 // copy one texture buffer to the other while flipping upside down (OpenGL and DirectX have different texture origins)
 // srcX0, srcY0, 
 // srcX1, srcY1
 // dstX0, dstY0,
 // dstX1, dstY1,
 // GLbitfield mask, GLenum filter
 // Do not flip during blit
 // srcX0, srcY0, 
 // srcX1, srcY1
 // dstX0, dstY0,
 // dstX1, dstY1,
 // GLbitfield mask, GLenum filter
 // No fbo blit extension
 // Copy from the fbo (input texture attached) to the shared texture
 // restore the previous fbo - default is 0
 // unlock dx object
 // Allow access to the texture
 // There is no reader
 // Allow access to the texture
