Search code examples
openglsdlsurfacegame-makerrender-to-texture

Blitting surfaces in OpenGL


Both SDL and Game Maker have the concept of surfaces, images that you may modify on the fly and display them. I'm using OpenGL 1 and i'd like to know if openGL has this concept of Surface.

The only way that i came up with was:

  • Every frame create / destroy a new texture based on needs.
  • Every frame, update said texture based on needs.

These approachs don't seem to be very performant, but i see no alternative. Maybe this is how they are implemented in the mentioned engines.


Solution

  • Yes these two are the ways you would do it in OpenGL 1.0. I dont think there are any other means as far as 1.0 spec is concerned. Link : https://www.opengl.org/registry/doc/glspec10.pdf

    Do note that the textures are stored on the device memory (GPU) which is fast to access for shading. And the above approaches copy it between host (CPU) memory and device memory. Hence the performance hit is the speed of host-device copy.

    Why are you limited to OpenGL 1.0 spec. You can go higher and then you start getting more options.

    1. Use GLSL shaders to directly edit content from one texture and output the same to another texture. Processing will be done on the GPU and a device-device copy is as fast as it gets.
    2. Use CUDA. Map a texture to a CUDA array, use your kernel to modify the content. Or use OpenCL for non-NVIDIA cards.

    This would be the better scenario so long as the modification can be executed in parallel this would benefit.

    I would suggest trying the CPU copy method, as it might be fast enough for your needs. The host-device copy is getting faster with latest hardware. You might be able to get real-time 60fps or higher even with this copy, unless its a lot of textures you plan to execute this for.