| 1 |
.. _programming-guide-opengles: |
| 2 |
|
| 3 |
|
| 4 |
OpenGL ES |
| 5 |
========= |
| 6 |
|
| 7 |
Pyglet has experimental support for OpenGL ES 3.2, with some limitations. Devices like Raspberry Pi 4 |
| 8 |
and 5 supports OpenGL ES 3.1 with extensions covering most of the missing 3.2 features (with the |
| 9 |
exception of tessellation shaders). There are likely other devices with ES support that can run Pyglet. |
| 10 |
|
| 11 |
Creating a window / context |
| 12 |
--------------------------- |
| 13 |
|
| 14 |
In order to successfully create a context and window with OpenGL ES we first need to: |
| 15 |
|
| 16 |
* Likely disable the shadow window because very few environments supports this |
| 17 |
* Pass in a custom config at window creation specifying OpenGL ES and version |
| 18 |
|
| 19 |
Example:: |
| 20 |
|
| 21 |
import pyglet |
| 22 |
|
| 23 |
# Disable shadow window |
| 24 |
pyglet.options.shadow_window = False |
| 25 |
|
| 26 |
# Query the best config for the screen |
| 27 |
display = pyglet.display.get_display() |
| 28 |
screen = display.get_default_screen() |
| 29 |
config = screen.get_best_config() |
| 30 |
|
| 31 |
# Specify that we want to use OpenGL ES 3.1 |
| 32 |
# This is very specific to the Raspberry Pi 4 and 5. Use 3.2 if you can. |
| 33 |
config.opengl_api = "gles" |
| 34 |
config.major_version = 3 |
| 35 |
config.minor_version = 1 |
| 36 |
|
| 37 |
# Create the window |
| 38 |
window = pyglet.window.Window(config=config) |
| 39 |
|
| 40 |
|
| 41 |
Limitations |
| 42 |
----------- |
| 43 |
|
| 44 |
Multisampling |
| 45 |
~~~~~~~~~~~~~ |
| 46 |
|
| 47 |
Be careful with enabling multisampling on the window. Likely |
| 48 |
``get_best_config()`` will not have multisampling enabled. |
| 49 |
|
| 50 |
Textures |
| 51 |
~~~~~~~~ |
| 52 |
|
| 53 |
Pixel format for textures and images are limited to ``RGBA``. If you try to |
| 54 |
load any other pixel format through pyglet's image loading functions you |
| 55 |
will get an error when they are turned into OpenGL textures later. |
| 56 |
|
| 57 |
The reason for this limitation is that OpenGL ES does not support pixel |
| 58 |
format conversion during pixel transfer, meaning when calling ``glTexImage`` |
| 59 |
to upload pixel data to the GPU, the pixel format must match the internalformat. |
| 60 |
In desktop OpenGL an RGB image will be automatically converted to RGBA during |
| 61 |
this transfer. This is not supported in OpenGL ES. |
| 62 |
|
| 63 |
You are, however, free to create your own textures with any pixel format |
| 64 |
using the gl bindings directly. |
| 65 |
|
| 66 |
Compute Shader |
| 67 |
~~~~~~~~~~~~~~ |
| 68 |
|
| 69 |
If you are planning to bind textures to image units with the intention of |
| 70 |
using them in a compute shader, you need to create these textures yourself |
| 71 |
using the gl bindings and allocate space using ``glTexStorage``. Pyglet is |
| 72 |
using ``glTexImage`` to allocate space and upload the pixel data for textures. |
| 73 |
|
| 74 |
The difference here is that ``glTexStorage`` creates immutable storage. You can |
| 75 |
only call it once and then fill the allocated space with pixel data using |
| 76 |
``glTexSubImage``. ``glTexImage`` on the other hand can be called multiple times |
| 77 |
reallocating the texture storage each time. Likely OpenGL ES doesn't want to |
| 78 |
deal with the extra complexity of validating the texture storage of images |
| 79 |
every time a compute shader is dispatched. |
| 80 |
|
| 81 |
In short: Create your own textures with immutable storage if you are planning |
| 82 |
to use them in a compute shader. |
| 83 |
|
| 84 |
Shaders |
| 85 |
------- |
| 86 |
|
| 87 |
Pyglet's shader system supports basic conversion between GLSL 1.5/3.3 shaders |
| 88 |
to GLES 3.2 shaders when running in OpenGL ES mode. This is to ensure that |
| 89 |
pyglet's built-in shaders also works with GL ES. This system is not perfect |
| 90 |
and are likely to have some flaws. |
| 91 |
|
| 92 |
Currently the shaders are converted to ES 3.1 shaders as a careful approach |
| 93 |
manually enabling extensions needed for ES 3.2. Precisions qualifiers are |
| 94 |
injected using ``mediump`` by default. |