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

Commit 894df17e authored by Alex Sakhartchouk's avatar Alex Sakhartchouk
Browse files

Fixing font renderer attribute slot locations.

Change-Id: I6377bb641df7d8372d873c00790189f9a190afd6
parent 2e10374d
Loading
Loading
Loading
Loading
+9 −7
Original line number Original line Diff line number Diff line
@@ -316,6 +316,8 @@ FontRenderer::FontRenderer() {
    mTextTexture = NULL;
    mTextTexture = NULL;


    mIndexBufferID = 0;
    mIndexBufferID = 0;
    mPositionAttrSlot = -1;
    mTexcoordAttrSlot = -1;


    mCacheWidth = DEFAULT_TEXT_CACHE_WIDTH;
    mCacheWidth = DEFAULT_TEXT_CACHE_WIDTH;
    mCacheHeight = DEFAULT_TEXT_CACHE_HEIGHT;
    mCacheHeight = DEFAULT_TEXT_CACHE_HEIGHT;
@@ -565,13 +567,8 @@ void FontRenderer::issueDrawCommand() {
    float* vtx = mTextMeshPtr;
    float* vtx = mTextMeshPtr;
    float* tex = vtx + 3;
    float* tex = vtx + 3;


    // position is slot 0
    glVertexAttribPointer(mPositionAttrSlot, 3, GL_FLOAT, false, 20, vtx);
    uint32_t slot = 0;
    glVertexAttribPointer(mTexcoordAttrSlot, 2, GL_FLOAT, false, 20, tex);
    glVertexAttribPointer(slot, 3, GL_FLOAT, false, 20, vtx);

    // texture0 is slot 1
    slot = 1;
    glVertexAttribPointer(slot, 2, GL_FLOAT, false, 20, tex);


    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBufferID);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBufferID);
    glDrawElements(GL_TRIANGLES, mCurrentQuadIndex * 6, GL_UNSIGNED_SHORT, NULL);
    glDrawElements(GL_TRIANGLES, mCurrentQuadIndex * 6, GL_UNSIGNED_SHORT, NULL);
@@ -718,6 +715,11 @@ bool FontRenderer::renderText(SkPaint* paint, const Rect* clip, const char *text
        return false;
        return false;
    }
    }


    if (mPositionAttrSlot < 0 || mTexcoordAttrSlot < 0) {
        LOGE("Font renderer unable to draw, attribute slots undefined");
        return false;
    }

    mDrawn = false;
    mDrawn = false;
    mBounds = bounds;
    mBounds = bounds;
    mClip = clip;
    mClip = clip;
+8 −0
Original line number Original line Diff line number Diff line
@@ -138,6 +138,11 @@ public:
        mGammaTable = gammaTable;
        mGammaTable = gammaTable;
    }
    }


    void setAttributeBindingSlots(int positionSlot, int texCoordSlot) {
        mPositionAttrSlot = positionSlot;
        mTexcoordAttrSlot = texCoordSlot;
    }

    void setFont(SkPaint* paint, uint32_t fontId, float fontSize);
    void setFont(SkPaint* paint, uint32_t fontId, float fontSize);
    bool renderText(SkPaint* paint, const Rect* clip, const char *text, uint32_t startIndex,
    bool renderText(SkPaint* paint, const Rect* clip, const char *text, uint32_t startIndex,
            uint32_t len, int numGlyphs, int x, int y, Rect* bounds);
            uint32_t len, int numGlyphs, int x, int y, Rect* bounds);
@@ -263,6 +268,9 @@ protected:


    uint32_t mIndexBufferID;
    uint32_t mIndexBufferID;


    int32_t mPositionAttrSlot;
    int32_t mTexcoordAttrSlot;

    const Rect* mClip;
    const Rect* mClip;
    Rect* mBounds;
    Rect* mBounds;
    bool mDrawn;
    bool mDrawn;
+5 −1
Original line number Original line Diff line number Diff line
@@ -1585,8 +1585,12 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
#else
#else
    bool hasActiveLayer = false;
    bool hasActiveLayer = false;
#endif
#endif

    mCaches.unbindMeshBuffer();
    mCaches.unbindMeshBuffer();

    // Tell font renderer the locations of position and texture coord
    // attributes so it can bind its data properly
    int positionSlot = mCaches.currentProgram->position;
    fontRenderer.setAttributeBindingSlots(positionSlot, mTexCoordsSlot);
    if (fontRenderer.renderText(paint, clip, text, 0, bytesCount, count, x, y,
    if (fontRenderer.renderText(paint, clip, text, 0, bytesCount, count, x, y,
            hasActiveLayer ? &bounds : NULL)) {
            hasActiveLayer ? &bounds : NULL)) {
#if RENDER_LAYERS_AS_REGIONS
#if RENDER_LAYERS_AS_REGIONS