summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Müller <schnitzeltony@gmail.com>2018-08-29 00:19:54 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-09-04 11:03:55 +0100
commita6ea6216bdbf86fba38400ba02a8dd77165f7a8b (patch)
tree9bec2e09b548123c38cd65aa6deff4a076f9c4f8
parentabe5813b4b1977fa64a2418507a42af186cc3e5c (diff)
downloadpoky-a6ea6216bdbf86fba38400ba02a8dd77165f7a8b.tar.gz
libsdl2: Fix left rotated display for RaspPi/VC4/GLES2
The patch should increase performance for libsdl2 on GLES2 too. (From OE-Core rev: 52f9659f2bb44affec2f67935df01f13b6ff3e02) Signed-off-by: Andreas Müller <schnitzeltony@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-graphics/libsdl2/libsdl2/0001-GLES2-Get-sin-cos-out-of-vertex-shader.patch141
-rw-r--r--meta/recipes-graphics/libsdl2/libsdl2_2.0.8.bb1
2 files changed, 142 insertions, 0 deletions
diff --git a/meta/recipes-graphics/libsdl2/libsdl2/0001-GLES2-Get-sin-cos-out-of-vertex-shader.patch b/meta/recipes-graphics/libsdl2/libsdl2/0001-GLES2-Get-sin-cos-out-of-vertex-shader.patch
new file mode 100644
index 0000000000..9b32b3788d
--- /dev/null
+++ b/meta/recipes-graphics/libsdl2/libsdl2/0001-GLES2-Get-sin-cos-out-of-vertex-shader.patch
@@ -0,0 +1,141 @@
1From c215ba1d52a3d4ef03af3ab1a5baa1863f812aed Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
3Date: Fri, 24 Aug 2018 23:10:25 +0200
4Subject: [PATCH] GLES2: Get sin/cos out of vertex shader
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9The only place angle is activated and causes effect is RenderCopyEx. All other
10methods which use vertex shader, leave angle disabled and cause useless sin/cos
11calculation in shader.
12
13To get around shader's interface is changed to a vector that contains results
14of sin and cos. To behave properly when disabled, cos value is set with offset
15-1.0 making 0.0 default when deactivated.
16
17As nice side effect it simplifies GLES2_UpdateVertexBuffer: All attributes are
18vectors now.
19
20Additional background:
21
22* On RaspberryPi it gives a performace win for operations. Tested with
23 [1] numbers go down for 5-10% (not easy to estimate due to huge variation).
24* SDL_RenderCopyEx was tested with [2]
25* It works around left rotated display caused by low accuracy sin implemetation
26 in RaspberryPi/VC4 [3]
27
28Upstream-Status: Accepted [4]
29
30[1] https://github.com/schnitzeltony/sdl2box
31[2] https://github.com/schnitzeltony/sdl2rendercopyex
32[3] https://github.com/anholt/mesa/issues/110
33[4] https://hg.libsdl.org/SDL/rev/e5a666405750
34
35Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
36---
37 src/render/opengles2/SDL_render_gles2.c | 17 ++++++++++++-----
38 src/render/opengles2/SDL_shaders_gles2.c | 14 +++++++++-----
39 2 files changed, 21 insertions(+), 10 deletions(-)
40
41diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
42index 14671f7c8..7c54a7333 100644
43--- a/src/render/opengles2/SDL_render_gles2.c
44+++ b/src/render/opengles2/SDL_render_gles2.c
45@@ -1530,7 +1530,7 @@ GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr,
46 GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
47
48 #if !SDL_GLES2_USE_VBOS
49- data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, vertexData);
50+ data->glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, vertexData);
51 #else
52 if (!data->vertex_buffers[attr]) {
53 data->glGenBuffers(1, &data->vertex_buffers[attr]);
54@@ -1545,7 +1545,7 @@ GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr,
55 data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData);
56 }
57
58- data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, 0);
59+ data->glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, 0);
60 #endif
61
62 return 0;
63@@ -1853,6 +1853,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
64 return GL_CheckError("", renderer);
65 }
66
67+#define PI 3.14159265f
68+
69 static int
70 GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
71 const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
72@@ -1861,8 +1863,9 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
73 GLfloat vertices[8];
74 GLfloat texCoords[8];
75 GLfloat translate[8];
76- GLfloat fAngle[4];
77+ GLfloat fAngle[8];
78 GLfloat tmp;
79+ float radian_angle;
80
81 GLES2_ActivateRenderer(renderer);
82
83@@ -1872,7 +1875,11 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
84
85 data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_CENTER);
86 data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE);
87- fAngle[0] = fAngle[1] = fAngle[2] = fAngle[3] = (GLfloat)(360.0f - angle);
88+
89+ radian_angle = PI * (360.0f - angle) / 180.f;
90+ fAngle[0] = fAngle[2] = fAngle[4] = fAngle[6] = (GLfloat)sin(radian_angle);
91+ /* render expects cos value - 1 (see GLES2_VertexSrc_Default_) */
92+ fAngle[1] = fAngle[3] = fAngle[5] = fAngle[7] = (GLfloat)cos(radian_angle) - 1.0f;
93 /* Calculate the center of rotation */
94 translate[0] = translate[2] = translate[4] = translate[6] = (center->x + dstrect->x);
95 translate[1] = translate[3] = translate[5] = translate[7] = (center->y + dstrect->y);
96@@ -1901,7 +1908,7 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
97 data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate);
98 data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
99
100- GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 4 * sizeof(GLfloat));
101+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 8 * sizeof(GLfloat));
102 GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat));
103 GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
104
105diff --git a/src/render/opengles2/SDL_shaders_gles2.c b/src/render/opengles2/SDL_shaders_gles2.c
106index b0bcdff25..f428a4945 100644
107--- a/src/render/opengles2/SDL_shaders_gles2.c
108+++ b/src/render/opengles2/SDL_shaders_gles2.c
109@@ -30,20 +30,24 @@
110 /*************************************************************************************************
111 * Vertex/fragment shader source *
112 *************************************************************************************************/
113-
114+/* Notes on a_angle:
115+ * It is a vector containing sin and cos for rotation matrix
116+ * To get correct rotation for most cases when a_angle is disabled cos
117+ value is decremented by 1.0 to get proper output with 0.0 which is
118+ default value
119+*/
120 static const Uint8 GLES2_VertexSrc_Default_[] = " \
121 uniform mat4 u_projection; \
122 attribute vec2 a_position; \
123 attribute vec2 a_texCoord; \
124- attribute float a_angle; \
125+ attribute vec2 a_angle; \
126 attribute vec2 a_center; \
127 varying vec2 v_texCoord; \
128 \
129 void main() \
130 { \
131- float angle = radians(a_angle); \
132- float c = cos(angle); \
133- float s = sin(angle); \
134+ float s = a_angle[0]; \
135+ float c = a_angle[1] + 1.0; \
136 mat2 rotationMatrix = mat2(c, -s, s, c); \
137 vec2 position = rotationMatrix * (a_position - a_center) + a_center; \
138 v_texCoord = a_texCoord; \
139--
1402.14.4
141
diff --git a/meta/recipes-graphics/libsdl2/libsdl2_2.0.8.bb b/meta/recipes-graphics/libsdl2/libsdl2_2.0.8.bb
index accea38aaa..52bb93a17a 100644
--- a/meta/recipes-graphics/libsdl2/libsdl2_2.0.8.bb
+++ b/meta/recipes-graphics/libsdl2/libsdl2_2.0.8.bb
@@ -14,6 +14,7 @@ PROVIDES = "virtual/libsdl2"
14 14
15SRC_URI = "http://www.libsdl.org/release/SDL2-${PV}.tar.gz \ 15SRC_URI = "http://www.libsdl.org/release/SDL2-${PV}.tar.gz \
16 file://more-gen-depends.patch \ 16 file://more-gen-depends.patch \
17 file://0001-GLES2-Get-sin-cos-out-of-vertex-shader.patch \
17" 18"
18 19
19S = "${WORKDIR}/SDL2-${PV}" 20S = "${WORKDIR}/SDL2-${PV}"