[client] egl: move rotation into the fragment shader

This commit is contained in:
Geoffrey McRae 2021-01-15 13:13:39 +11:00
parent 72c86d7125
commit cbeae46c0b
3 changed files with 32 additions and 68 deletions

View File

@ -97,48 +97,15 @@ static bool egl_cursor_tex_init(struct CursorTex * t,
static inline void egl_cursor_tex_uniforms(EGL_Cursor * cursor, struct CursorTex * t, bool mono) static inline void egl_cursor_tex_uniforms(EGL_Cursor * cursor, struct CursorTex * t, bool mono)
{ {
float x, y, w, h;
switch(cursor->rotate)
{
case LG_ROTATE_UP:
x = cursor->x;
y = cursor->y;
w = cursor->w;
h = cursor->h;
break;
case LG_ROTATE_DOWN:
x = -cursor->x;
y = -cursor->y;
w = cursor->w;
h = cursor->h;
break;
case LG_ROTATE_LEFT:
x = cursor->y;
y = -cursor->x;
w = cursor->h;
h = cursor->w;
break;
case LG_ROTATE_RIGHT:
x = -cursor->y;
y = cursor->x;
w = cursor->h;
h = cursor->w;
break;
}
if (mono) if (mono)
{ {
glUniform4f(t->uMousePos, x, y, w, h / 2); glUniform4f(t->uMousePos, cursor->x, cursor->y, cursor->w, cursor->h / 2);
glUniform1i(t->uRotate , cursor->rotate); glUniform1i(t->uRotate , cursor->rotate);
glUniform1i(t->uCBMode , cursor->cbMode); glUniform1i(t->uCBMode , cursor->cbMode);
} }
else else
{ {
glUniform4f(t->uMousePos, x, y, w, h); glUniform4f(t->uMousePos, cursor->x, cursor->y, cursor->w, cursor->h);
glUniform1i(t->uRotate , cursor->rotate); glUniform1i(t->uRotate , cursor->rotate);
glUniform1i(t->uCBMode , cursor->cbMode); glUniform1i(t->uCBMode , cursor->cbMode);
} }

View File

@ -4,22 +4,40 @@ layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV; layout(location = 1) in vec2 vertexUV;
uniform vec4 mouse; uniform vec4 mouse;
uniform lowp int rotate;
out highp vec2 uv; out highp vec2 uv;
void main() void main()
{ {
gl_Position.xyz = vertexPosition_modelspace; vec2 muv = vertexPosition_modelspace.xy;
gl_Position.w = 1.0; muv.x += 1.0f;
muv.y -= 1.0f;
muv.x *= mouse.z;
muv.y *= mouse.w;
muv.x += mouse.x;
muv.y -= mouse.y;
gl_Position.x += 1.0f; if (rotate == 0) // up
gl_Position.y -= 1.0f; {
gl_Position.xy = muv;
gl_Position.x *= mouse.z; }
gl_Position.y *= mouse.w; else if (rotate == 1) // down
{
gl_Position.x += mouse.x; gl_Position.x = -muv.x;
gl_Position.y -= mouse.y; gl_Position.y = -muv.y;
}
else if (rotate == 2) // left
{
gl_Position.x = -muv.y;
gl_Position.y = muv.x;
}
else if (rotate == 3) // right
{
gl_Position.x = muv.y;
gl_Position.y = -muv.x;
}
gl_Position.w = 1.0;
uv = vertexUV; uv = vertexUV;
} }

View File

@ -2,36 +2,15 @@
in highp vec2 uv; in highp vec2 uv;
out highp vec4 color; out highp vec4 color;
uniform int rotate;
uniform sampler2D sampler1; uniform sampler2D sampler1;
uniform lowp int rotate;
uniform int cbMode; uniform int cbMode;
void main() void main()
{ {
highp vec2 ruv; color = texture(sampler1, uv);
if (rotate == 0) // up
{
ruv = uv;
}
else if (rotate == 1) // down
{
ruv.x = -uv.x + 1.0f;
ruv.y = -uv.y + 1.0f;
}
else if (rotate == 2) // left
{
ruv.x = -uv.y + 1.0f;
ruv.y = uv.x;
}
else if (rotate == 3) // right
{
ruv.x = uv.y;
ruv.y = -uv.x + 1.0f;
}
color = texture(sampler1, ruv);
if (cbMode > 0) if (cbMode > 0)
{ {