diff options
| author | Andreas Müller <schnitzeltony@gmail.com> | 2018-09-27 21:06:48 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-10-10 13:26:25 +0100 |
| commit | 3acc7a6e28a980cf662a7aa600d5503780c522e8 (patch) | |
| tree | 4cadbea1fdfce8aa1164e2519ac195cdfa2da9af | |
| parent | 5b544a3bce46f5ff5f42a43468eef3cb80095678 (diff) | |
| download | poky-3acc7a6e28a980cf662a7aa600d5503780c522e8.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)
(From OE-Core rev: 80b6a08f55e322bfc41f69476509dc5a62ada83f)
Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Armin Kuster <akuster808@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.patch | 141 | ||||
| -rw-r--r-- | meta/recipes-graphics/libsdl2/libsdl2_2.0.8.bb | 1 |
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 @@ | |||
| 1 | From c215ba1d52a3d4ef03af3ab1a5baa1863f812aed Mon Sep 17 00:00:00 2001 | ||
| 2 | From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com> | ||
| 3 | Date: Fri, 24 Aug 2018 23:10:25 +0200 | ||
| 4 | Subject: [PATCH] GLES2: Get sin/cos out of vertex shader | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | The only place angle is activated and causes effect is RenderCopyEx. All other | ||
| 10 | methods which use vertex shader, leave angle disabled and cause useless sin/cos | ||
| 11 | calculation in shader. | ||
| 12 | |||
| 13 | To get around shader's interface is changed to a vector that contains results | ||
| 14 | of sin and cos. To behave properly when disabled, cos value is set with offset | ||
| 15 | -1.0 making 0.0 default when deactivated. | ||
| 16 | |||
| 17 | As nice side effect it simplifies GLES2_UpdateVertexBuffer: All attributes are | ||
| 18 | vectors now. | ||
| 19 | |||
| 20 | Additional 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 | |||
| 28 | Upstream-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 | |||
| 35 | Signed-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 | |||
| 41 | diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c | ||
| 42 | index 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 | |||
| 105 | diff --git a/src/render/opengles2/SDL_shaders_gles2.c b/src/render/opengles2/SDL_shaders_gles2.c | ||
| 106 | index 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 | -- | ||
| 140 | 2.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 c0cf70d7fd..8092fad11e 100644 --- a/meta/recipes-graphics/libsdl2/libsdl2_2.0.8.bb +++ b/meta/recipes-graphics/libsdl2/libsdl2_2.0.8.bb | |||
| @@ -16,6 +16,7 @@ DEPENDS_class-nativesdk = "${@bb.utils.contains('DISTRO_FEATURES', 'x11', 'virtu | |||
| 16 | 16 | ||
| 17 | SRC_URI = " \ | 17 | SRC_URI = " \ |
| 18 | http://www.libsdl.org/release/SDL2-${PV}.tar.gz \ | 18 | http://www.libsdl.org/release/SDL2-${PV}.tar.gz \ |
| 19 | file://0001-GLES2-Get-sin-cos-out-of-vertex-shader.patch \ | ||
| 19 | " | 20 | " |
| 20 | 21 | ||
| 21 | S = "${WORKDIR}/SDL2-${PV}" | 22 | S = "${WORKDIR}/SDL2-${PV}" |
