examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutGLDXinterop.cpp
//
// COPY IMAGE PIXELS TO A TEXTURE
//
//
// Streaming Texture Upload
//
// From : http://www.songho.ca/opengl/gl_pbo.html
//
// No FBO used so none has to be passed
//

COPY IMAGE PIXELS TO A TEXTURE
Streaming Texture Upload



No FBO used so none has to be passed
COPY IMAGE PIXELS TO A TEXTURE Streaming Texture Upload No FBO used so none has to be passed
bool spoutGLDXinterop::LoadTexturePixels(GLuint TextureID, GLuint TextureTarget, 
										 unsigned int width, unsigned int height, 
										 const unsigned char *data, 
										 GLenum glFormat, bool bInvert)
{
	void *pboMemory = NULL;
	int channels = 4; 
	if(TextureID == 0 || data == NULL)
		return false;
	if(glFormat == GL_RGB || glFormat == GL_BGR_EXT) 
		channels = 3;
	if(m_fbo == 0) {
		glGenFramebuffersEXT(1, &m_fbo); 
	}
	if(!m_pbo[0]) glGenBuffersEXT(2, m_pbo);
	PboIndex = (PboIndex + 1) % 2;
	NextPboIndex = (PboIndex + 1) % 2;
	glBindTexture(TextureTarget, TextureID);
	glBindBufferEXT(GL_PIXEL_UNPACK_BUFFER, m_pbo[PboIndex]);
	glTexSubImage2D(TextureTarget, 0, 0, 0, width, height, glFormat, GL_UNSIGNED_BYTE, 0);
	glBindBufferEXT(GL_PIXEL_UNPACK_BUFFER, m_pbo[NextPboIndex]);
	glBufferDataEXT(GL_PIXEL_UNPACK_BUFFER, width*height*channels, 0, GL_STREAM_DRAW);
	pboMemory = (void *)glMapBufferEXT(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
	GLerror(); 
	if(pboMemory) {
		spoutcopy.CopyPixels((const unsigned char *)data, (unsigned char *)pboMemory, width, height, glFormat, bInvert);
		glUnmapBufferEXT(GL_PIXEL_UNPACK_BUFFER); 
	}
	else {
		glBindBufferEXT(GL_PIXEL_UNPACK_BUFFER, 0);
		return false;
	}
	glBindBufferEXT(GL_PIXEL_UNPACK_BUFFER, 0);
	return true;
}
bool spoutGLDXinterop :: LoadTexturePixels ( GLuint TextureID , GLuint TextureTarget , unsigned int width , unsigned int height , const unsigned char * data , GLenum glFormat , bool bInvert ) { void * pboMemory = NULL ; int channels = 4 ; if ( TextureID == 0 || data == NULL ) return false ; if ( glFormat == GL_RGB || glFormat == GL_BGR_EXT ) channels = 3 ; if ( m_fbo == 0 ) { glGenFramebuffersEXT ( 1 , & m_fbo ) ; } if ( ! m_pbo [ 0 ] ) glGenBuffersEXT ( 2 , m_pbo ) ; PboIndex = ( PboIndex + 1 ) % 2 ; NextPboIndex = ( PboIndex + 1 ) % 2 ; glBindTexture ( TextureTarget , TextureID ) ; glBindBufferEXT ( GL_PIXEL_UNPACK_BUFFER , m_pbo [ PboIndex ] ) ; glTexSubImage2D ( TextureTarget , 0 , 0 , 0 , width , height , glFormat , GL_UNSIGNED_BYTE , 0 ) ; glBindBufferEXT ( GL_PIXEL_UNPACK_BUFFER , m_pbo [ NextPboIndex ] ) ; glBufferDataEXT ( GL_PIXEL_UNPACK_BUFFER , width * height * channels , 0 , GL_STREAM_DRAW ) ; pboMemory = ( void * ) glMapBufferEXT ( GL_PIXEL_UNPACK_BUFFER , GL_WRITE_ONLY ) ; GLerror ( ) ; if ( pboMemory ) { spoutcopy . CopyPixels ( ( const unsigned char * ) data , ( unsigned char * ) pboMemory , width , height , glFormat , bInvert ) ; glUnmapBufferEXT ( GL_PIXEL_UNPACK_BUFFER ) ; } else { glBindBufferEXT ( GL_PIXEL_UNPACK_BUFFER , 0 ) ; return false ; } glBindBufferEXT ( GL_PIXEL_UNPACK_BUFFER , 0 ) ; return true ; }
COPY IMAGE PIXELS TO A TEXTURE
Streaming Texture Upload
COPY IMAGE PIXELS TO A TEXTURE Streaming Texture Upload
// RGBA or RGB
 // Create pbos if not already
 // Bind the texture and PBO
 // Copy pixels from PBO to the texture - use offset instead of pointer.
 // Bind PBO to update the texture
 // Call glBufferData() with a NULL pointer to clear the PBO data and avoid a stall.
 // Map the buffer object into client's memory
 // soak up the error for Processing - only happens once
 // Update data directly on the mapped buffer
 // release the mapped buffer
 // Release PBOs
