examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutGLDXinterop.cpp
// DRAW A TEXTURE INTO SHARED MEMORY - equivalent to DrawToSharedTexture

DRAW A TEXTURE INTO SHARED MEMORY - equivalent to DrawToSharedTexture
DRAW A TEXTURE INTO SHARED MEMORY - equivalent to DrawToSharedTexture
bool spoutGLDXinterop::DrawToSharedMemory(GLuint TexID, GLuint TextureTarget, 
										  unsigned int width, unsigned int height, 
										  float max_x, float max_y, float aspect, 
										  bool bInvert, GLuint HostFBO)
{
	unsigned int memWidth, memHeight;
	GLenum status;
	if(!memoryshare.GetSenderMemorySize(memWidth, memHeight))
		return false;
	if(width != memWidth || height != memHeight) 
		return false;
	unsigned char *pBuffer = memoryshare.LockSenderMemory();
	if(!pBuffer) {
		return false;
	}
	CheckOpenGLTexture(m_TexID, GL_RGBA, width, height, m_TexWidth, m_TexHeight);
	if(m_fbo == 0) glGenFramebuffersEXT(1, &m_fbo); 
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
	glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_TexID, 0);
	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if(status == GL_FRAMEBUFFER_COMPLETE_EXT) {
		glColor4f(1.f, 1.f, 1.f, 1.f);
		glEnable(TextureTarget);
		glBindTexture(TextureTarget, TexID);
		GLfloat tc[4][2] = {0};
		if(bInvert) {
			tc[0][0] = 0.0;   tc[0][1] = max_y;
			tc[1][0] = 0.0;   tc[1][1] = 0.0;
			tc[2][0] = max_x; tc[2][1] = 0.0;
			tc[3][0] = max_x; tc[3][1] = max_y;
		}
		else {
			tc[0][0] = 0.0;   tc[0][1] = 0.0;
			tc[1][0] = 0.0;   tc[1][1] = max_y;
			tc[2][0] = max_x; tc[2][1] = max_y;
			tc[3][0] = max_x; tc[3][1] = 0.0;
		}
		GLfloat verts[] =  {
						-aspect, -1.0,   
						-aspect,  1.0,   
						 aspect,  1.0,   
						 aspect, -1.0 }; 
		glEnableClientState( GL_TEXTURE_COORD_ARRAY );
		glTexCoordPointer(2, GL_FLOAT, 0, tc );
		glEnableClientState(GL_VERTEX_ARRAY);		
		glVertexPointer(2, GL_FLOAT, 0, verts );
		glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
		glDisableClientState(GL_VERTEX_ARRAY);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glBindTexture(TextureTarget, 0);
		glDisable(TextureTarget);
	}
	else {
		PrintFBOstatus(status);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, HostFBO);
		memoryshare.UnlockSenderMemory();
		return false;
	}
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, HostFBO);
	if(IsPBOavailable()) {
		UnloadTexturePixels(m_TexID, GL_TEXTURE_2D, width, height, pBuffer, GL_RGBA, false, HostFBO);
	}
	else {
		glBindTexture(GL_TEXTURE_2D, m_TexID);
		glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)pBuffer);
		glBindTexture(GL_TEXTURE_2D, 0);
	}
	memoryshare.UnlockSenderMemory();
	return true;
}
bool spoutGLDXinterop :: DrawToSharedMemory ( GLuint TexID , GLuint TextureTarget , unsigned int width , unsigned int height , float max_x , float max_y , float aspect , bool bInvert , GLuint HostFBO ) { unsigned int memWidth , memHeight ; GLenum status ; if ( ! memoryshare . GetSenderMemorySize ( memWidth , memHeight ) ) return false ; if ( width != memWidth || height != memHeight ) return false ; unsigned char * pBuffer = memoryshare . LockSenderMemory ( ) ; if ( ! pBuffer ) { return false ; } CheckOpenGLTexture ( m_TexID , GL_RGBA , width , height , m_TexWidth , m_TexHeight ) ; if ( m_fbo == 0 ) glGenFramebuffersEXT ( 1 , & m_fbo ) ; glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , m_fbo ) ; glFramebufferTexture2DEXT ( GL_READ_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT , GL_TEXTURE_2D , m_TexID , 0 ) ; status = glCheckFramebufferStatusEXT ( GL_FRAMEBUFFER_EXT ) ; if ( status == GL_FRAMEBUFFER_COMPLETE_EXT ) { glColor4f ( 1.f , 1.f , 1.f , 1.f ) ; glEnable ( TextureTarget ) ; glBindTexture ( TextureTarget , TexID ) ; GLfloat tc [ 4 ] [ 2 ] = { 0 } ; if ( bInvert ) { tc [ 0 ] [ 0 ] = 0.0 ; tc [ 0 ] [ 1 ] = max_y ; tc [ 1 ] [ 0 ] = 0.0 ; tc [ 1 ] [ 1 ] = 0.0 ; tc [ 2 ] [ 0 ] = max_x ; tc [ 2 ] [ 1 ] = 0.0 ; tc [ 3 ] [ 0 ] = max_x ; tc [ 3 ] [ 1 ] = max_y ; } else { tc [ 0 ] [ 0 ] = 0.0 ; tc [ 0 ] [ 1 ] = 0.0 ; tc [ 1 ] [ 0 ] = 0.0 ; tc [ 1 ] [ 1 ] = max_y ; tc [ 2 ] [ 0 ] = max_x ; tc [ 2 ] [ 1 ] = max_y ; tc [ 3 ] [ 0 ] = max_x ; tc [ 3 ] [ 1 ] = 0.0 ; } GLfloat verts [ ] = { - aspect , -1.0 , - aspect , 1.0 , aspect , 1.0 , aspect , -1.0 } ; glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; glTexCoordPointer ( 2 , GL_FLOAT , 0 , tc ) ; glEnableClientState ( GL_VERTEX_ARRAY ) ; glVertexPointer ( 2 , GL_FLOAT , 0 , verts ) ; glDrawArrays ( GL_TRIANGLE_FAN , 0 , 4 ) ; glDisableClientState ( GL_VERTEX_ARRAY ) ; glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ; glBindTexture ( TextureTarget , 0 ) ; glDisable ( TextureTarget ) ; } else { PrintFBOstatus ( status ) ; glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , HostFBO ) ; memoryshare . UnlockSenderMemory ( ) ; return false ; } glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , HostFBO ) ; if ( IsPBOavailable ( ) ) { UnloadTexturePixels ( m_TexID , GL_TEXTURE_2D , width , height , pBuffer , GL_RGBA , false , HostFBO ) ; } else { glBindTexture ( GL_TEXTURE_2D , m_TexID ) ; glGetTexImage ( GL_TEXTURE_2D , 0 , GL_RGBA , GL_UNSIGNED_BYTE , ( GLvoid * ) pBuffer ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; } memoryshare . UnlockSenderMemory ( ) ; return true ; }
DRAW A TEXTURE INTO SHARED MEMORY - equivalent to DrawToSharedTexture
DRAW A TEXTURE INTO SHARED MEMORY - equivalent to DrawToSharedTexture
// Get the memoryshare size
 // Sender size check - quit if not equal
 // Create or resize a local OpenGL texture
 // Create an fbo if not already
 //
 // Draw the input texture into the local texture via an fbo
 //
 // Destination is the fbo with local texture attached
 // Draw the input texture
 // Invert texture coord to user requirements
 // bottom left
 // top left
 // top right
 // bottom right
 // restore the previous fbo - default is 0
 // Now read the local opengl texture into the memory map buffer
 // Use PBO if supported
