Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39284b76 authored by Romain Guy's avatar Romain Guy
Browse files

Make gradients beautiful again

Bug #7239634

This change passes two matrices to the vertex shader instead of one.
We used to compute the final MVP matrix on the CPU to minimize the
number of operations in the vertex shaders. Shader compilers are
however smart enough to perform this optimization for us. Since we
need the MV matrix to properly compute gradients dithering, this
change splits the MVP matrix into two. This has the advantage of
removing one matrix multiplication per drawing operation on the
CPU.
The SGX 540 shader compiler produces the same number of instructions
in both cases. There is no penalty hit with having two matrices
instead of one. We also send so few vertices per frame that it
does not matter very much.

Change-Id: I17d47ac4772615418e0e1885b97493d31435a936
parent bd43152b
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -81,6 +81,7 @@ Program::Program(const ProgramDescription& description, const char* vertex, cons


    if (mInitialized) {
    if (mInitialized) {
        transform = addUniform("transform");
        transform = addUniform("transform");
        projection = addUniform("projection");
    }
    }
}
}


@@ -152,18 +153,20 @@ GLuint Program::buildShader(const char* source, GLenum type) {


void Program::set(const mat4& projectionMatrix, const mat4& modelViewMatrix,
void Program::set(const mat4& projectionMatrix, const mat4& modelViewMatrix,
        const mat4& transformMatrix, bool offset) {
        const mat4& transformMatrix, bool offset) {
    mat4 t(projectionMatrix);
    mat4 p(projectionMatrix);
    if (offset) {
    if (offset) {
        // offset screenspace xy by an amount that compensates for typical precision
        // offset screenspace xy by an amount that compensates for typical precision
        // issues in GPU hardware that tends to paint hor/vert lines in pixels shifted
        // issues in GPU hardware that tends to paint hor/vert lines in pixels shifted
        // up and to the left.
        // up and to the left.
        // This offset value is based on an assumption that some hardware may use as
        // This offset value is based on an assumption that some hardware may use as
        // little as 12.4 precision, so we offset by slightly more than 1/16.
        // little as 12.4 precision, so we offset by slightly more than 1/16.
        t.translate(.375, .375, 0);
        p.translate(.375, .375, 0);
    }
    }
    t.multiply(transformMatrix);

    mat4 t(transformMatrix);
    t.multiply(modelViewMatrix);
    t.multiply(modelViewMatrix);


    glUniformMatrix4fv(projection, 1, GL_FALSE, &p.data[0]);
    glUniformMatrix4fv(transform, 1, GL_FALSE, &t.data[0]);
    glUniformMatrix4fv(transform, 1, GL_FALSE, &t.data[0]);
}
}


+5 −0
Original line number Original line Diff line number Diff line
@@ -374,6 +374,11 @@ public:
     */
     */
    int transform;
    int transform;


    /**
     * Name of the projection uniform.
     */
    int projection;

protected:
protected:
    /**
    /**
     * Adds an attribute with the specified name.
     * Adds an attribute with the specified name.
+8 −7
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ const char* gVS_Header_Attributes_AAVertexShapeParameters =
const char* gVS_Header_Uniforms_TextureTransform =
const char* gVS_Header_Uniforms_TextureTransform =
        "uniform mat4 mainTextureTransform;\n";
        "uniform mat4 mainTextureTransform;\n";
const char* gVS_Header_Uniforms =
const char* gVS_Header_Uniforms =
        "uniform mat4 projection;\n" \
        "uniform mat4 transform;\n";
        "uniform mat4 transform;\n";
const char* gVS_Header_Uniforms_IsPoint =
const char* gVS_Header_Uniforms_IsPoint =
        "uniform mediump float pointSize;\n";
        "uniform mediump float pointSize;\n";
@@ -104,28 +105,28 @@ const char* gVS_Main_OutTransformedTexCoords =
const char* gVS_Main_OutGradient[6] = {
const char* gVS_Main_OutGradient[6] = {
        // Linear
        // Linear
        "    linear = vec2((screenSpace * position).x, 0.5);\n"
        "    linear = vec2((screenSpace * position).x, 0.5);\n"
        "    ditherTexCoords = (gl_Position * ditherSize).xy;\n",
        "    ditherTexCoords = (transform * position).xy * ditherSize;\n",
        "    linear = (screenSpace * position).x;\n"
        "    linear = (screenSpace * position).x;\n"
        "    ditherTexCoords = (gl_Position * ditherSize).xy;\n",
        "    ditherTexCoords = (transform * position).xy * ditherSize;\n",


        // Circular
        // Circular
        "    circular = (screenSpace * position).xy;\n"
        "    circular = (screenSpace * position).xy;\n"
        "    ditherTexCoords = (gl_Position * ditherSize).xy;\n",
        "    ditherTexCoords = (transform * position).xy * ditherSize;\n",
        "    circular = (screenSpace * position).xy;\n"
        "    circular = (screenSpace * position).xy;\n"
        "    ditherTexCoords = (gl_Position * ditherSize).xy;\n",
        "    ditherTexCoords = (transform * position).xy * ditherSize;\n",


        // Sweep
        // Sweep
        "    sweep = (screenSpace * position).xy;\n"
        "    sweep = (screenSpace * position).xy;\n"
        "    ditherTexCoords = (gl_Position * ditherSize).xy;\n",
        "    ditherTexCoords = (transform * position).xy * ditherSize;\n",
        "    sweep = (screenSpace * position).xy;\n"
        "    sweep = (screenSpace * position).xy;\n"
        "    ditherTexCoords = (gl_Position * ditherSize).xy;\n",
        "    ditherTexCoords = (transform * position).xy * ditherSize;\n",
};
};
const char* gVS_Main_OutBitmapTexCoords =
const char* gVS_Main_OutBitmapTexCoords =
        "    outBitmapTexCoords = (textureTransform * position).xy * textureDimension;\n";
        "    outBitmapTexCoords = (textureTransform * position).xy * textureDimension;\n";
const char* gVS_Main_OutPointBitmapTexCoords =
const char* gVS_Main_OutPointBitmapTexCoords =
        "    outPointBitmapTexCoords = (textureTransform * position).xy * textureDimension;\n";
        "    outPointBitmapTexCoords = (textureTransform * position).xy * textureDimension;\n";
const char* gVS_Main_Position =
const char* gVS_Main_Position =
        "    gl_Position = transform * position;\n";
        "    gl_Position = projection * transform * position;\n";
const char* gVS_Main_PointSize =
const char* gVS_Main_PointSize =
        "    gl_PointSize = pointSize;\n";
        "    gl_PointSize = pointSize;\n";
const char* gVS_Main_AALine =
const char* gVS_Main_AALine =