forked from 12to11/12to11
Add support for projective scale transforms to EGL renderer
* egl.c (struct _EglBuffer): New field `scale'. Save the projective scale here. (struct _CompositeProgram): New field `scale'. Save the index of new uniform here. (EglCompileCompositeProgram): Fetch location of new uniform. (ApplyTransform): Set scale. (Composite): Apply value of new uniform. (BufferFromDmaBuf, BufferFromShm): Initialize scale to 0. (UpdateBufferForDamage): Scale damage if it and damage are set. * shaders.txt (Composite Rectangle Fragment Shader RGBA) (Composite Rectangle Fragment Shader RGBX) (Composite Rectangle Fragment Shader External): New uniform `scale'. (main): Divide texcoord by scale.
This commit is contained in:
parent
b4ee06589e
commit
ab30a03d24
2 changed files with 41 additions and 6 deletions
35
egl.c
35
egl.c
|
@ -122,6 +122,9 @@ struct _EglBuffer
|
||||||
/* The width and height of the buffer. */
|
/* The width and height of the buffer. */
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
|
/* The projective scale factor. */
|
||||||
|
GLfloat scale;
|
||||||
|
|
||||||
/* Various different buffers. */
|
/* Various different buffers. */
|
||||||
union {
|
union {
|
||||||
/* The type of the buffer. */
|
/* The type of the buffer. */
|
||||||
|
@ -174,6 +177,9 @@ struct _CompositeProgram
|
||||||
|
|
||||||
/* The index of the texture uniform. */
|
/* The index of the texture uniform. */
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
|
|
||||||
|
/* The index of the scale uniform. */
|
||||||
|
GLuint scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* All known SHM formats. */
|
/* All known SHM formats. */
|
||||||
|
@ -706,6 +712,8 @@ EglCompileCompositeProgram (CompositeProgram *program,
|
||||||
"pos");
|
"pos");
|
||||||
program->texture = glGetUniformLocation (program->program,
|
program->texture = glGetUniformLocation (program->program,
|
||||||
"texture");
|
"texture");
|
||||||
|
program->scale = glGetUniformLocation (program->program,
|
||||||
|
"scale");
|
||||||
|
|
||||||
/* Now delete the shaders. */
|
/* Now delete the shaders. */
|
||||||
glDeleteShader (vertex);
|
glDeleteShader (vertex);
|
||||||
|
@ -1082,7 +1090,10 @@ ClearRectangle (RenderTarget target, int x, int y, int width, int height)
|
||||||
static void
|
static void
|
||||||
ApplyTransform (RenderBuffer buffer, double divisor)
|
ApplyTransform (RenderBuffer buffer, double divisor)
|
||||||
{
|
{
|
||||||
/* TODO... */
|
EglBuffer *egl_buffer;
|
||||||
|
|
||||||
|
egl_buffer = buffer.pointer;
|
||||||
|
egl_buffer->scale = 1.0f / (GLfloat) divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CompositeProgram *
|
static CompositeProgram *
|
||||||
|
@ -1198,6 +1209,7 @@ Composite (RenderBuffer buffer, RenderTarget target,
|
||||||
glUseProgram (program->program);
|
glUseProgram (program->program);
|
||||||
|
|
||||||
glUniform1i (program->texture, 0);
|
glUniform1i (program->texture, 0);
|
||||||
|
glUniform1f (program->scale, egl_buffer->scale);
|
||||||
glVertexAttribPointer (program->position, 2, GL_FLOAT,
|
glVertexAttribPointer (program->position, 2, GL_FLOAT,
|
||||||
GL_FALSE, 0, verts);
|
GL_FALSE, 0, verts);
|
||||||
glVertexAttribPointer (program->texcoord, 2, GL_FLOAT,
|
glVertexAttribPointer (program->texcoord, 2, GL_FLOAT,
|
||||||
|
@ -1348,6 +1360,7 @@ BufferFromDmaBuf (DmaBufAttributes *attributes, Bool *error)
|
||||||
buffer->texture = EGL_NO_TEXTURE;
|
buffer->texture = EGL_NO_TEXTURE;
|
||||||
buffer->width = attributes->width;
|
buffer->width = attributes->width;
|
||||||
buffer->height = attributes->height;
|
buffer->height = attributes->height;
|
||||||
|
buffer->scale = 1.0f;
|
||||||
buffer->u.type = DmaBufBuffer;
|
buffer->u.type = DmaBufBuffer;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
|
@ -1492,6 +1505,7 @@ BufferFromShm (SharedMemoryAttributes *attributes, Bool *error)
|
||||||
buffer->texture = EGL_NO_TEXTURE;
|
buffer->texture = EGL_NO_TEXTURE;
|
||||||
buffer->width = attributes->width;
|
buffer->width = attributes->width;
|
||||||
buffer->height = attributes->height;
|
buffer->height = attributes->height;
|
||||||
|
buffer->scale = 1.0f;
|
||||||
buffer->u.type = ShmBuffer;
|
buffer->u.type = ShmBuffer;
|
||||||
|
|
||||||
/* Record the buffer data. */
|
/* Record the buffer data. */
|
||||||
|
@ -1955,7 +1969,24 @@ UpdateBuffer (RenderBuffer buffer, pixman_region32_t *damage)
|
||||||
static void
|
static void
|
||||||
UpdateBufferForDamage (RenderBuffer buffer, pixman_region32_t *damage)
|
UpdateBufferForDamage (RenderBuffer buffer, pixman_region32_t *damage)
|
||||||
{
|
{
|
||||||
/* TODO: handle scaling. */
|
EglBuffer *egl_buffer;
|
||||||
|
pixman_region32_t region;
|
||||||
|
|
||||||
|
egl_buffer = buffer.pointer;
|
||||||
|
|
||||||
|
if (egl_buffer->scale != 1.0f && damage)
|
||||||
|
{
|
||||||
|
/* Scale the damage, specified in scaled coordinates, down to
|
||||||
|
texture coordinates. */
|
||||||
|
|
||||||
|
pixman_region32_init (®ion);
|
||||||
|
XLScaleRegion (®ion, damage,
|
||||||
|
1.0f / egl_buffer->scale,
|
||||||
|
1.0f / egl_buffer->scale);
|
||||||
|
UpdateBuffer (buffer, ®ion);
|
||||||
|
pixman_region32_fini (®ion);
|
||||||
|
}
|
||||||
|
else
|
||||||
UpdateBuffer (buffer, damage);
|
UpdateBuffer (buffer, damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
shaders.txt
10
shaders.txt
|
@ -43,24 +43,27 @@ main (void)
|
||||||
//== Composite Rectangle Fragment Shader RGBA
|
//== Composite Rectangle Fragment Shader RGBA
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
|
uniform float scale;
|
||||||
varying vec2 v_texcoord;
|
varying vec2 v_texcoord;
|
||||||
|
|
||||||
void
|
void
|
||||||
main (void)
|
main (void)
|
||||||
{
|
{
|
||||||
gl_FragColor = texture2D (texture, v_texcoord);
|
gl_FragColor = texture2D (texture, v_texcoord / scale);
|
||||||
}
|
}
|
||||||
//==
|
//==
|
||||||
|
|
||||||
//== Composite Rectangle Fragment Shader RGBX
|
//== Composite Rectangle Fragment Shader RGBX
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
|
uniform float scale;
|
||||||
varying vec2 v_texcoord;
|
varying vec2 v_texcoord;
|
||||||
|
|
||||||
void
|
void
|
||||||
main (void)
|
main (void)
|
||||||
{
|
{
|
||||||
gl_FragColor = vec4 (texture2D (texture, v_texcoord).rgb,
|
gl_FragColor = vec4 (texture2D (texture,
|
||||||
|
v_texcoord / scale).rgb,
|
||||||
1.0);
|
1.0);
|
||||||
}
|
}
|
||||||
//==
|
//==
|
||||||
|
@ -70,11 +73,12 @@ main (void)
|
||||||
|
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
uniform samplerExternalOES texture;
|
uniform samplerExternalOES texture;
|
||||||
|
uniform float scale;
|
||||||
varying vec2 v_texcoord;
|
varying vec2 v_texcoord;
|
||||||
|
|
||||||
void
|
void
|
||||||
main (void)
|
main (void)
|
||||||
{
|
{
|
||||||
gl_FragColor = texture2D (texture, v_texcoord);
|
gl_FragColor = texture2D (texture, v_texcoord / scale);
|
||||||
}
|
}
|
||||||
//==
|
//==
|
||||||
|
|
Loading…
Add table
Reference in a new issue