Use case for Libretro OpenGL API

What do most modern platforms have in common?

Answer: OpenGL or OpenGL ES.

These APIs allow us to write 3D graphics-based applications:
* In a platform-agnostic way
* With hardware acceleration
* Using a standard language/API

What do these platforms not have in common?

What is not portable about OpenGL?

Libretro's OpenGL implementation is designed specifically to address the practicalities of extending OpenGL and OpenGL ES hardware acceleration to the wide variety of architectures and environments supported by the libretro ecosystem.

Implementing OpenGL accelerated cores

Libretro GL provides a portable solution for OpenGL-based hardware acceleration along with the rest of libretro's simple but comprehensive API. The Libretro API allows cores to use OpenGL (GL2+ or GLES2) directly in addition to frontend features, such as multi-pass shaders. This is accomplished by letting cores render to frame buffer objects (FBOs) instead of the back buffer.

Important

GL drivers must support render-to-texture extensions for this to work.

Application model

Using OpenGL in a libretro context is somewhat different than when you use libraries like SDL, GLFW or SFML. In libretro, the frontend owns the OpenGL context. For an application using conventional libraries like SDL, the application will do this:

Using libretro API, platform specifics like managing windows, rendering surfaces and input are all handled by the frontend. The core will only deal with rendering to a surface. The core renders to an FBO of fixed size, determined by the core. The frontend takes this rendered data and stretches to screen as desired by the user. It can apply shaders, change aspect ratio, etc. This model is equivalent to software rendering where retro_video_refresh_t_callback is called.

Using OpenGL in libretro

Important considerations in the OpenGL code

The frontend and libretro core share OpenGL context state. Some considerations have to be taken into account for this cooperation to work nicely.

Test implementations

Building a libretro core

Libretro is an interface, and not a utility library. Libretro cores are built as standalone dynamic or static libraries, and as they use GL symbols here,
they must link against GL symbols themselves. An example of how this can be done is shown in the test implementation.