examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutGLDXinterop.cpp
bool spoutGLDXinterop::ReadGLDXtexture(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 != (unsigned int)m_TextureInfo.width || height != (unsigned int)m_TextureInfo.height) return false;
	if(spoutdx.CheckAccess(m_hAccessMutex)) {

		// lock interop
		if(LockInteropObject(m_hInteropDevice, &m_hInteropObject) == S_OK) {

			// bind the FBO (for both, READ_FRAMEBUFFER_EXT and DRAW_FRAMEBUFFER_EXT)
			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);

			// Attach the Input texture (the shared texture) to the color buffer in our frame buffer - note texturetarget 
			glFramebufferTexture2DEXT(READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_glTexture, 0);
			glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);

			// Attach target texture (the one we write into and return) to second attachment point
			glFramebufferTexture2DEXT(DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, TextureTarget, TextureID, 0);
			glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);

			status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
			if(status == GL_FRAMEBUFFER_COMPLETE_EXT) {
				if(m_bBLITavailable) {
					// Flip if the user wants that
					if(bInvert) {
						// copy one texture buffer to the other while flipping upside down
						glBlitFramebufferEXT(0,     0,		// srcX0, srcY0, 
											 width, height, // srcX1, srcY1
											 0,     height,	// dstX0, dstY0,
											 width, 0,		// dstX1, dstY1,
											 GL_COLOR_BUFFER_BIT, GL_LINEAR);
					}
					else { 
						// Do not flip during blit
						glBlitFramebufferEXT(0, 0,			// srcX0, srcY0, 
											 width, height,	// srcX1, srcY1
											 0, 0,			// dstX0, dstY0,
											 width, height,	// dstX1, dstY1,
											 GL_COLOR_BUFFER_BIT, GL_NEAREST); // GLbitfield mask, GLenum filter
					}
				}
				else { 
					// No fbo blit extension available
					// Copy from the fbo (shared texture attached) to the dest texture
					glBindTexture(TextureTarget, TextureID);
					glCopyTexSubImage2D(TextureTarget, 0, 0, 0, 0, 0, width, height);
					glBindTexture(TextureTarget, 0);
				}
			}
			else {
				PrintFBOstatus(status);
			}

			glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // 04.01.16

			// restore the previous fbo - default is 0
			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, HostFBO);

			// unlock dx object
			UnlockInteropObject(m_hInteropDevice, &m_hInteropObject);
			spoutdx.AllowAccess(m_hAccessMutex);
			return true;
		}
	}

	spoutdx.AllowAccess(m_hAccessMutex);

	return false;

}
//
// COPY FROM THE SHARED OPENGL TEXTURE TO AN OPENGL TEXTURE
//

COPY FROM THE SHARED OPENGL TEXTURE TO AN OPENGL TEXTURE
COPY FROM THE SHARED OPENGL TEXTURE TO AN OPENGL TEXTURE
bool spoutGLDXinterop::ReadGLDXtexture(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 != (unsigned int)m_TextureInfo.width || height != (unsigned int)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, GL_TEXTURE_2D, m_glTexture, 0);
			glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
			glFramebufferTexture2DEXT(DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, TextureTarget, TextureID, 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_LINEAR);
					}
					else { 
						glBlitFramebufferEXT(0, 0,			
											 width, height,	
											 0, 0,			
											 width, height,	
											 GL_COLOR_BUFFER_BIT, GL_NEAREST); 
					}
				}
				else { 
					glBindTexture(TextureTarget, TextureID);
					glCopyTexSubImage2D(TextureTarget, 0, 0, 0, 0, 0, width, height);
					glBindTexture(TextureTarget, 0);
				}
			}
			else {
				PrintFBOstatus(status);
			}
			glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); 
			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, HostFBO);
			UnlockInteropObject(m_hInteropDevice, &m_hInteropObject);
			spoutdx.AllowAccess(m_hAccessMutex);
			return true;
		}
	}
	spoutdx.AllowAccess(m_hAccessMutex);
	return false;
}
bool spoutGLDXinterop :: ReadGLDXtexture ( 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 != ( unsigned int ) m_TextureInfo . width || height != ( unsigned int ) 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 , GL_TEXTURE_2D , m_glTexture , 0 ) ; glReadBuffer ( GL_COLOR_ATTACHMENT0_EXT ) ; glFramebufferTexture2DEXT ( DRAW_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT1_EXT , TextureTarget , TextureID , 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_LINEAR ) ; } else { glBlitFramebufferEXT ( 0 , 0 , width , height , 0 , 0 , width , height , GL_COLOR_BUFFER_BIT , GL_NEAREST ) ; } } else { glBindTexture ( TextureTarget , TextureID ) ; glCopyTexSubImage2D ( TextureTarget , 0 , 0 , 0 , 0 , 0 , width , height ) ; glBindTexture ( TextureTarget , 0 ) ; } } else { PrintFBOstatus ( status ) ; } glDrawBuffer ( GL_COLOR_ATTACHMENT0_EXT ) ; glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , HostFBO ) ; UnlockInteropObject ( m_hInteropDevice , & m_hInteropObject ) ; spoutdx . AllowAccess ( m_hAccessMutex ) ; return true ; } } spoutdx . AllowAccess ( m_hAccessMutex ) ; return false ; }
COPY FROM THE SHARED OPENGL TEXTURE TO AN OPENGL TEXTURE
COPY FROM THE SHARED OPENGL TEXTURE TO AN OPENGL TEXTURE
// lock interop
 // bind the FBO (for both, READ_FRAMEBUFFER_EXT and DRAW_FRAMEBUFFER_EXT)
 // Attach the Input texture (the shared texture) to the color buffer in our frame buffer - note texturetarget 
 // Attach target texture (the one we write into and return) to second attachment point
 // Flip if the user wants that
 // copy one texture buffer to the other while flipping upside down
 // srcX0, srcY0, 
 // srcX1, srcY1
 // dstX0, dstY0,
 // dstX1, dstY1,
 // Do not flip during blit
 // srcX0, srcY0, 
 // srcX1, srcY1
 // dstX0, dstY0,
 // dstX1, dstY1,
 // GLbitfield mask, GLenum filter
 // No fbo blit extension available
 // Copy from the fbo (shared texture attached) to the dest texture
 // 04.01.16
 // restore the previous fbo - default is 0
 // unlock dx object
