Hey everyone!
I'm working on a Syphon binding for JUCE. Syphon (http://syphon.v002.info) is a wonderful tool to share GL textures between apps on OSX. (There's an equivalent for Windows called Spout, later I'd like to Jucify that too.)
My starting point was the already existing OFX (https://github.com/astellato/ofxSyphon) and Cinder (https://github.com/astellato/Cinder-Syphon) bindings. I've already changed a lot of stuff to fit better JUCE, I get the notifications about the Server list changes, etc. But I stucked where I have to load the texture. I can get the textureID and the dimensions of the shared texture, but have no idea how to get/use the actual image data.
Here are the two solutions for the other platforms:
OFX (mTex here is an ofTexture)
[(SyphonNameboundClient*)mClient lockClient]; SyphonClient *client = [(SyphonNameboundClient*)mClient client]; latestImage = [client newFrameImageForContext:CGLGetCurrentContext()]; NSSize texSize = [(SyphonImage*)latestImage textureSize]; // we now have to manually make our ofTexture's ofTextureData a proxy to our SyphonImage mTex.setUseExternalTextureID([(SyphonImage*)latestImage textureName]); mTex.texData.textureTarget = GL_TEXTURE_RECTANGLE_ARB; // Syphon always outputs rect textures. mTex.texData.width = texSize.width; mTex.texData.height = texSize.height; mTex.texData.tex_w = texSize.width; mTex.texData.tex_h = texSize.height; mTex.texData.tex_t = texSize.width; mTex.texData.tex_u = texSize.height; mTex.texData.glInternalFormat = GL_RGBA; #if (OF_VERSION_MAJOR == 0) && (OF_VERSION_MINOR < 8) mTex.texData.glType = GL_RGBA; mTex.texData.pixelType = GL_UNSIGNED_BYTE; #endif mTex.texData.bFlipTexture = YES; mTex.texData.bAllocated = YES; mTex.bind();
Cinder (mTex here is an ci::gl::Texture)
[(SyphonNameboundClient*)mClient lockClient]; SyphonClient *client = [(SyphonNameboundClient*)mClient client]; latestImage = [client newFrameImageForContext:CGLGetCurrentContext()]; NSSize texSize = [(SyphonImage*)latestImage textureSize]; GLuint m_id = [(SyphonImage*)latestImage textureName]; mTex = ci::gl::Texture::create(GL_TEXTURE_RECTANGLE_ARB, m_id, texSize.width, texSize.height, true); mTex->setFlipped(); mTex->bind();
As you can see, the key is to create the GL texture with the given size, id, pixel format, but in JUCE you can't create an OpenGLTexture this way. Should I write a custom OpenGLTexture class/subclass, or is there something I missed?
Thank you!
(If I can get this work, I'd like to share the code with you... :) )