I need to share a texture between two OpenGL contexts. One OpenGL context is my own GameWindow, the other is a 3rd party API view that I host on a Windows form. I don't have access to its OpenGL context, so I don't think there is any way for me to share resources between this 3rd party API and my GameWindow. However, I can copy a texture from this API into main memory as a bitmap, using the following routine:
// render the left STK view STK_OpenGL.Form1.SceneL.Render(); // copy the render from the back buffer into textureLstk GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, textureLstk); GL.CopyTexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, 0, 0, 640, 800, 0); // copy textureLstk into a bitmap in main memory dataL = bmL.LockBits(new Rectangle(0, 0, bmL.Width, bmL.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.GetTexImage(TextureTarget.Texture2D, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, dataL.Scan0); bmL.UnlockBits(dataL);
Then I can load this Bitmap into a texture in my GameWindow context. Of course, working with main memory is very slow, so I was wondering if it would be possible to write the Bitmap to an address in GPU memory using OpenCL. Any ideas?