examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutGLDXinterop.cpp
//
// COPY THE SHARED TEXTURE TO IMAGE PIXELS
//

COPY THE SHARED TEXTURE TO IMAGE PIXELS
COPY THE SHARED TEXTURE TO IMAGE PIXELS
bool spoutGLDXinterop::ReadGLDXpixels(unsigned char *pixels, 
										 unsigned int width, 
										 unsigned int height, 
										 GLenum glFormat,
										 bool bInvert, 
										 GLuint HostFBO)
{
	GLenum status;
	GLenum glformat = glFormat;
	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) {
			glPixelStorei(GL_PACK_ALIGNMENT, 1);
			CheckOpenGLTexture(m_TexID, GL_RGBA, width, height, m_TexWidth, m_TexHeight);
			CopyTexture(m_glTexture, GL_TEXTURE_2D, m_TexID, GL_TEXTURE_2D, width, height, bInvert, HostFBO);
			if(IsPBOavailable()) { 
				UnloadTexturePixels(m_TexID, GL_TEXTURE_2D, width, height, pixels, glFormat, false, HostFBO);
			}
			else {
				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 
				glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_TexID, 0);
				status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
				if(status == GL_FRAMEBUFFER_COMPLETE_EXT) {
					glReadPixels(0, 0, width, height, glformat, GL_UNSIGNED_BYTE, pixels);
				}
				else {
					PrintFBOstatus(status);
				}
				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, HostFBO);
			}
			glPixelStorei(GL_PACK_ALIGNMENT, 4);
			UnlockInteropObject(m_hInteropDevice, &m_hInteropObject);
			spoutdx.AllowAccess(m_hAccessMutex);
			return true;
		} 
	} 
	spoutdx.AllowAccess(m_hAccessMutex);
	return false;
}
bool spoutGLDXinterop :: ReadGLDXpixels ( unsigned char * pixels , unsigned int width , unsigned int height , GLenum glFormat , bool bInvert , GLuint HostFBO ) { GLenum status ; GLenum glformat = glFormat ; 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 ) { glPixelStorei ( GL_PACK_ALIGNMENT , 1 ) ; CheckOpenGLTexture ( m_TexID , GL_RGBA , width , height , m_TexWidth , m_TexHeight ) ; CopyTexture ( m_glTexture , GL_TEXTURE_2D , m_TexID , GL_TEXTURE_2D , width , height , bInvert , HostFBO ) ; if ( IsPBOavailable ( ) ) { UnloadTexturePixels ( m_TexID , GL_TEXTURE_2D , width , height , pixels , glFormat , false , HostFBO ) ; } else { glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , m_fbo ) ; glFramebufferTexture2DEXT ( GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT , GL_TEXTURE_2D , m_TexID , 0 ) ; status = glCheckFramebufferStatusEXT ( GL_FRAMEBUFFER_EXT ) ; if ( status == GL_FRAMEBUFFER_COMPLETE_EXT ) { glReadPixels ( 0 , 0 , width , height , glformat , GL_UNSIGNED_BYTE , pixels ) ; } else { PrintFBOstatus ( status ) ; } glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , HostFBO ) ; } glPixelStorei ( GL_PACK_ALIGNMENT , 4 ) ; UnlockInteropObject ( m_hInteropDevice , & m_hInteropObject ) ; spoutdx . AllowAccess ( m_hAccessMutex ) ; return true ; } } spoutdx . AllowAccess ( m_hAccessMutex ) ; return false ; }
COPY THE SHARED TEXTURE TO IMAGE PIXELS
COPY THE SHARED TEXTURE TO IMAGE PIXELS
// retrieve opengl texture data directly to image pixels rather than via an fbo and texture
 // Wait for access to the texture
 // lock gl/dx interop object
 // Set single pixel alignment in case of rgb source
 // Create or resize a local OpenGL texture
 // Copy the shared texture to the local texture, inverting if necessary
 // Extract the pixels from the local texture - changing to the user passed format
 // PBO method
 //
 // fbo attachment method - current fbo has to be passed in
 //
 // Bind our local fbo
 // Attach the local rgba texture to the color buffer in our frame buffer
 // read the pixels from the framebuffer in the user provided format
 // restore the previous fbo - default is 0
 // Unlock interop object
 // interop lock failed
 // mutex access failed
