OpenGLTexture with custom ID


#1

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... :) )


#2

Hi @timo, did you get anywhere with this? I’m interested in sending animations to other apps, and been looking at the Syphon SDK. Would be good even if you have a starting point to look at.
Thanks


#3

@timo I was aso wondering the same thing. I want to create some A/V plugins with GLSL and Syphon, and I would love to help figure this out. Did you get anywhere or post your work in progress?


#4

oh is this related : https://github.com/benkuper/juce_sharedtexture


#5

Hello everybody!

I’m still Timo, but with a different account.

No, unfortunately I couldn’t figure that out, so I wrote the necessary parts with pure OpenGL, FBOs, PBOs and all that - at least to me - horrible stuff. I’ll be very happy if I could change it to a more jucy solution.

I’ll check the mentioned Spout solution more in detail when I have a bit time for that, and see how can I implement the Syphon part.


#6

@Sesores I contacted the developer, @benkuper . You may want to consort with him, as it sounds like you may have some complimentary knowledge. In my email I suggested referencing the Cinder Syphon implementation, as Ben was referencing the OpenFrameworks version and it was difficult to port. The Cinder version is a bit cleaner code and looks like it may be more relatable to the JUCE API, so it may be worth looking at and discussing any issues here, I am sure we can figure it out. :smiley:


#7

The syphon development forum might be useful for asking questions, Vade rocks:
http://v002.info/forums/forum/syphon/syphon-development/

I realize most of the implementation is in objective C, maybe its possible to integrate by using some pre-compiler directives in the JUCE project and connecting C++ with the objective C? I know very little about objC :confused:

I realize its an obvious place to check, but figured I would include this link:
http://syphon.v002.info/FrameworkDocumentation/