Move SDL 2D texture into 3D OpenGL context

I’m transferring the contents of a SDL target texture (onto which I’ve drawn using SDL_RenderCopy() etc.) into an OpenGL texture (so I can render it in a 3D world); this is achieved by using SDL_RenderReadPixels() to get the contents of the SDL texture as a bitmap and glTexImage2D() to move it into the 3D context.

This works surprisingly well; I was concerned that it would be very slow (the SDL_RenderReadPixels() docs warn about this) but on Windows at least it’s acceptable. However since both textures are presumably under the control of the GPU I can’t help wondering if there is a better way. Is there?

Answering my own question: yes there’s a much better way. Setting SDL_GL_SHARE_WITH_CURRENT_CONTEXT before creating the 3D context means that any textures created by SDL can be seen by the 3D renderer, and can be incorporated in the 3D world without copying. Admittedly this means accessing a ‘private’ structure member (SDL_Texture -> driverdata -> texture) but it’s very much faster.