GLES2: Get sin/cos out of vertex shader

The only place angle is activated and causes effect is RenderCopyEx. All other
methods which use vertex shader, leave angle disabled and cause useless sin/cos
calculation in shader.

To get around shader's interface is changed to a vector that contains results
of sin and cos. To behave properly when disabled, cos value is set with offset
-1.0 making 0.0 default when deactivated.

As nice side effect it simplifies GLES2_UpdateVertexBuffer: All attributes are
vectors now.

Additional background:

* On RaspberryPi it gives a performace win for operations. Tested with
  [1] numbers go down for 5-10% (not easy to estimate due to huge variation).
* SDL_RenderCopyEx was tested with [2]
* It works around left rotated display caused by low accuracy sin implemetation
  in RaspberryPi/VC4 [3]

[1] https://github.com/schnitzeltony/sdl2box
[2] https://github.com/schnitzeltony/sdl2rendercopyex
[3] https://github.com/anholt/mesa/issues/110

Signed-off-by: Andreas M?ller <schnitzeltony@gmail.com>
This commit is contained in:
Andreas M?ller 2018-08-28 12:57:51 -07:00
parent 044b00dcae
commit 87bc1fb552
2 changed files with 21 additions and 10 deletions

View file

@ -30,20 +30,24 @@
/*************************************************************************************************
* Vertex/fragment shader source *
*************************************************************************************************/
/* Notes on a_angle:
* It is a vector containing sin and cos for rotation matrix
* To get correct rotation for most cases when a_angle is disabled cos
value is decremented by 1.0 to get proper output with 0.0 which is
default value
*/
static const Uint8 GLES2_VertexSrc_Default_[] = " \
uniform mat4 u_projection; \
attribute vec2 a_position; \
attribute vec2 a_texCoord; \
attribute float a_angle; \
attribute vec2 a_angle; \
attribute vec2 a_center; \
varying vec2 v_texCoord; \
\
void main() \
{ \
float angle = radians(a_angle); \
float c = cos(angle); \
float s = sin(angle); \
float s = a_angle[0]; \
float c = a_angle[1] + 1.0; \
mat2 rotationMatrix = mat2(c, -s, s, c); \
vec2 position = rotationMatrix * (a_position - a_center) + a_center; \
v_texCoord = a_texCoord; \