2

I need to share texture data between two OpenGL context, one is core profile (version 4.1 on current 10.10 OS X) and the other is legacy (version 2.1). Legacy profile is created by a third party library.

Apple documentation say that to share ressources between contexts, they must be similar (eg. same profile).

Not every context can be shared with every other context. Both contexts must share the same OpenGL profile.

Is there another way to achieve this avoiding memory transfers ?

(currently working solution is to download texture to CPU first and then re upload to GPU on the second context which is ok but very slow...)

rma
  • 115
  • 1
  • 1
  • 10
  • Did you try sharing 2 context with different profiles?Try it first.Maybe it will work. – Michael IV Aug 26 '15 at 11:52
  • OS X does not have compatibility profiles, incidentally. You have a core profile (3.2+), and then a legacy context (2.1). Pedantic, I know, but if it had a compatibility profile you'd have access to 3.0+ functionality and deprecated stuff simultaneously. – Andon M. Coleman Aug 26 '15 at 12:10
  • Michael > You get kCGLBadMatch error during context creation (with CGLCreateContext) – rma Aug 26 '15 at 12:22
  • Andon > Thanks, I fixed that – rma Aug 26 '15 at 12:23
  • You might be able to use the IOSurface mechanism for sharing images between contexts. Not sure if it will work, but you may want to at least look into it. – Reto Koradi Aug 26 '15 at 14:50
  • Reto > Thanks, in fact I'm currently trying just that. I'll update if I make any progress – rma Aug 26 '15 at 14:57
  • Using IOSurface backed texture I'm able to display a texture painted from a legacy profile context in a core context (with CGLTexImageIOSurface2D). I have yet to confirm no memory transfer occurs but it seems like a good solution. – rma Aug 27 '15 at 13:02

3 Answers3

3

On OSX you can share textures between different contexts (whatever the opengl profile) using IOSurface. It's easy. You create an IOSurface (IOSurfaceCreate) and then create textures based on this IOSurface in both contexts (using CGLTexImageIOSurface2D), I think they are just wrappers to the same VRAM location. So easy :-)

matthieu
  • 343
  • 2
  • 7
0

While it is true that you sometimes are not able to share the textures between the contexts but you can copy a texture from one context to another texture in other context with CopyImageSubDataNV.

I don't know if this is support in OpenGL on Mac but when I was doing multi-gpu rendering, I was not able to share texture between contexts because they were on two different gpus but I copied the texture from one context to other one and it was much faster than transferring to cpu manually and copying it to the other texture.

You can find more information Here.

mmostajab
  • 1,937
  • 1
  • 16
  • 37
  • This is not available on OS X as far as I know (checked on my setup). The standard version gl_arb_copy_image is core since GL 4.3 but thanks anyway – rma Aug 27 '15 at 06:15
0

It's possible to share all the OpenGL resources (even shader or FBO) between context. For more information we should consider that as duplicate of How to share textures between an NSOpenGLView and a full screen context in Mac OS?

Stefano Buora
  • 1,052
  • 6
  • 12
  • Have you checked that this work between context of different profile (core profile with compatibility, eg. sharing between opengl 2.1 and 4.1) ? – rma Jun 06 '17 at 06:33
  • I see what you mean, sorry posted an answer to a different question. The matter of sharing thing between 2 NSOpengLView made me so mad that I only though about sharing the long research I did to make it works (I didn't find any exhaustive post, only fragment of answer). Ending in posting it in the wrong place. My bad. – Stefano Buora Jun 06 '17 at 15:13
  • Anyway, I don't have the chance of creating the situation above described (different profiles). Honestly I think it may work for simple things like textures and openGL resource types in common between the two profiles. – Stefano Buora Jun 06 '17 at 15:17
  • No problem I understand :) I would be good to test it but I think it's probably not the case (cf. link to Apple documentation in the question), thanks for sharing your finding anyway. – rma Jun 07 '17 at 18:37