Difference between revisions of "GLES Shader Testing in Desktop"

m (love.graphics.validateShader)
(Update instructions)
Line 3: Line 3:
 
The answer is yes, there's a way.
 
The answer is yes, there's a way.
  
Desktop GPU nowadays (even integrated one) should supports creating OpenGLES context, which means all shaders must be GLSLES/ESSL compatible. We can make LOVE to use OpenGLES context by using environment variable <code>LOVE_GRAPHICS_USE_OPENGLES=1</code>.
+
Desktop GPU nowadays (even integrated one) should supports creating OpenGL ES context, which means all shaders must be GLSLES/ESSL compatible. We can make LOVE to use OpenGL ES context by using environment variable <code>LOVE_GRAPHICS_USE_OPENGLES=1</code>.
 +
 
 +
Note that this guide is mostly Windows oriented. For other desktop platforms, please adapt accordingly!
  
 
== love.graphics.validateShader ==
 
== love.graphics.validateShader ==
Line 11: Line 13:
 
== Requirements ==
 
== Requirements ==
  
You need GPU which supports OpenGLES context. As previously written, todays desktop GPU should support this.
+
You need GPU which supports OpenGL ES context. As previously written, todays desktop GPU should support this.
 
 
If your GPU doesn't supports it, you might can use [https://chromium.googlesource.com/angle/angle ANGLE]. If you're under Windows, you can actually run LOVE using only DirectX 9 capable GPU by using ANGLE (you can grab the DLLs from your Google Chrome or Firefox installation, named <code>libegl.dll</code> and <code>libopenglesv2.dll</code>. Just make sure it's 32-bit DLLs if you're using 32-bit version of LOVE (same also for 64-bit) and place it beside <code>love.exe</code>).
 
  
 
== Tell LOVE to use OpenGLES context ==
 
== Tell LOVE to use OpenGLES context ==
  
Now, we need to tell LOVE to use OpenGLES context. You need to set this environment variable before starting LOVE. It can be set using Command Prompt/Terminal and launching LOVE from same Terminal, or from Windows, from Advanced System Settings.
+
Now, we need to tell LOVE to use OpenGL ES context. You need to set this environment variable before starting LOVE. It can be set using Command Prompt/Terminal and launching LOVE from same Terminal, or from Windows, from Advanced System Settings.
  
* Windows: <code>set LOVE_GRAPHICS_USE_OPENGLES=1</code> then <code>lovec ...</code> (this assume [[0.10.2]] used)
+
* Windows: <code>set LOVE_GRAPHICS_USE_OPENGLES=1</code> then <code>lovec ...</code>. [[0.10.2]] or later is assumed.
  
 
* Linux/macOS: <code>LOVE_GRAPHICS_USE_OPENGLES=1 love ...</code>
 
* Linux/macOS: <code>LOVE_GRAPHICS_USE_OPENGLES=1 love ...</code>
  
Verify if LOVE uses OpenGLES context by calling [[love.graphics.getRendererInfo]] and check if the 1st return value is "OpenGL ES".
+
Verify if LOVE uses OpenGL ES context by calling [[love.graphics.getRendererInfo]] and check if the 1st return value is "OpenGL ES".
 +
 
 +
Once you got OpenGL ES context, you can test your shader code if it works under mobile devices. Otherwise, if you're on Windows, proceed below.
 +
 
 +
== Using ANGLE in Windows ==
 +
 
 +
[https://chromium.googlesource.com/angle/angle ANGLE] is an implementation of OpenGL ES 2.0 and 3.0 on top of other rendering backends. In Windows, it will run OpenGL ES using Direct3D 11 or Direct3D 9. If your GPU doesn't support OpenGL ES context or if you want to force ANGLE, you can copy '''libEGL.dll''' and '''libGLESv2.dll''' from one of these application:
 +
 
 +
* Google Chrome
 +
 
 +
* Microsoft Edge Chromium
 +
 
 +
* Visual Studio Code
 +
 
 +
* osu! stable (32-bit DLL)
 +
 
 +
Note: Using Firefox's DLLs doesn't work because it links with Firefox-specific DLLs and copying all the dependent DLLs can be troublesome.
 +
 
 +
One thing for sure is '''make sure the bitness of the DLL matches''', i.e. 64-bit Chrome has 64-bit DLLs and can only be used on 64-bit LOVE.
  
Once you got OpenGLES context, you can test your shader code if it works under mobile devices.
+
Next, set the environment <code>LOVE_GRAPHICS_USE_OPENGLES=1</code> and <code>SDL_OPENGL_ES_DRIVER=1</code> then launch LOVE. To confirm you're using ANGLE backend, check the 2nd return value of [[love.graphics.getRendererInfo]].
  
 
{{#set:LOVE Version=0.10.0}}
 
{{#set:LOVE Version=0.10.0}}
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Revision as of 11:05, 18 July 2020

Writing shaders to support mobile devices might be not trivial. You may wondering is there a way to test shader in mobile devices without really using mobile device.

The answer is yes, there's a way.

Desktop GPU nowadays (even integrated one) should supports creating OpenGL ES context, which means all shaders must be GLSLES/ESSL compatible. We can make LOVE to use OpenGL ES context by using environment variable LOVE_GRAPHICS_USE_OPENGLES=1.

Note that this guide is mostly Windows oriented. For other desktop platforms, please adapt accordingly!

love.graphics.validateShader

Since 11.0, there's love.graphics.validateShader which can be used to validate both GLSL and ESSL shader code. Note that it only validates, it doesn't run your shader code.

Requirements

You need GPU which supports OpenGL ES context. As previously written, todays desktop GPU should support this.

Tell LOVE to use OpenGLES context

Now, we need to tell LOVE to use OpenGL ES context. You need to set this environment variable before starting LOVE. It can be set using Command Prompt/Terminal and launching LOVE from same Terminal, or from Windows, from Advanced System Settings.

  • Windows: set LOVE_GRAPHICS_USE_OPENGLES=1 then lovec .... 0.10.2 or later is assumed.
  • Linux/macOS: LOVE_GRAPHICS_USE_OPENGLES=1 love ...

Verify if LOVE uses OpenGL ES context by calling love.graphics.getRendererInfo and check if the 1st return value is "OpenGL ES".

Once you got OpenGL ES context, you can test your shader code if it works under mobile devices. Otherwise, if you're on Windows, proceed below.

Using ANGLE in Windows

ANGLE is an implementation of OpenGL ES 2.0 and 3.0 on top of other rendering backends. In Windows, it will run OpenGL ES using Direct3D 11 or Direct3D 9. If your GPU doesn't support OpenGL ES context or if you want to force ANGLE, you can copy libEGL.dll and libGLESv2.dll from one of these application:

  • Google Chrome
  • Microsoft Edge Chromium
  • Visual Studio Code
  • osu! stable (32-bit DLL)

Note: Using Firefox's DLLs doesn't work because it links with Firefox-specific DLLs and copying all the dependent DLLs can be troublesome.

One thing for sure is make sure the bitness of the DLL matches, i.e. 64-bit Chrome has 64-bit DLLs and can only be used on 64-bit LOVE.

Next, set the environment LOVE_GRAPHICS_USE_OPENGLES=1 and SDL_OPENGL_ES_DRIVER=1 then launch LOVE. To confirm you're using ANGLE backend, check the 2nd return value of love.graphics.getRendererInfo.