OSDN Git Service

Fixing font renderer attribute slot locations.
authorAlex Sakhartchouk <alexst@google.com>
Fri, 18 Feb 2011 00:45:37 +0000 (16:45 -0800)
committerAlex Sakhartchouk <alexst@google.com>
Fri, 18 Feb 2011 00:45:37 +0000 (16:45 -0800)
Change-Id: I6377bb641df7d8372d873c00790189f9a190afd6

libs/hwui/FontRenderer.cpp
libs/hwui/FontRenderer.h
libs/hwui/OpenGLRenderer.cpp

index 0042f49..8bae684 100644 (file)
@@ -316,6 +316,8 @@ FontRenderer::FontRenderer() {
     mTextTexture = NULL;
 
     mIndexBufferID = 0;
+    mPositionAttrSlot = -1;
+    mTexcoordAttrSlot = -1;
 
     mCacheWidth = DEFAULT_TEXT_CACHE_WIDTH;
     mCacheHeight = DEFAULT_TEXT_CACHE_HEIGHT;
@@ -565,13 +567,8 @@ void FontRenderer::issueDrawCommand() {
     float* vtx = mTextMeshPtr;
     float* tex = vtx + 3;
 
-    // position is slot 0
-    uint32_t slot = 0;
-    glVertexAttribPointer(slot, 3, GL_FLOAT, false, 20, vtx);
-
-    // texture0 is slot 1
-    slot = 1;
-    glVertexAttribPointer(slot, 2, GL_FLOAT, false, 20, tex);
+    glVertexAttribPointer(mPositionAttrSlot, 3, GL_FLOAT, false, 20, vtx);
+    glVertexAttribPointer(mTexcoordAttrSlot, 2, GL_FLOAT, false, 20, tex);
 
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBufferID);
     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;
     }
 
+    if (mPositionAttrSlot < 0 || mTexcoordAttrSlot < 0) {
+        LOGE("Font renderer unable to draw, attribute slots undefined");
+        return false;
+    }
+
     mDrawn = false;
     mBounds = bounds;
     mClip = clip;
index 1005812..46f332e 100644 (file)
@@ -138,6 +138,11 @@ public:
         mGammaTable = gammaTable;
     }
 
+    void setAttributeBindingSlots(int positionSlot, int texCoordSlot) {
+        mPositionAttrSlot = positionSlot;
+        mTexcoordAttrSlot = texCoordSlot;
+    }
+
     void setFont(SkPaint* paint, uint32_t fontId, float fontSize);
     bool renderText(SkPaint* paint, const Rect* clip, const char *text, uint32_t startIndex,
             uint32_t len, int numGlyphs, int x, int y, Rect* bounds);
@@ -263,6 +268,9 @@ protected:
 
     uint32_t mIndexBufferID;
 
+    int32_t mPositionAttrSlot;
+    int32_t mTexcoordAttrSlot;
+
     const Rect* mClip;
     Rect* mBounds;
     bool mDrawn;
index 68b54fe..4a08f53 100644 (file)
@@ -1585,8 +1585,12 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
 #else
     bool hasActiveLayer = false;
 #endif
-
     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,
             hasActiveLayer ? &bounds : NULL)) {
 #if RENDER_LAYERS_AS_REGIONS