Changeset 846 for trunk/src/opengl/qpaintengine_opengl.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/opengl/qpaintengine_opengl.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 61 61 #include <private/qbezier_p.h> 62 62 #include <qglframebufferobject.h> 63 #include <private/qstatictext_p.h> 63 64 64 65 #include "private/qtessellator_p.h" … … 72 73 #endif 73 74 74 #ifdef QT_OPENGL_ES_1_CL75 #include "qgl_cl_p.h"76 #endif77 78 75 #define QGL_FUNC_CONTEXT QGLContext *ctx = const_cast<QGLContext *>(device->context()); 79 76 … … 83 80 QT_BEGIN_NAMESPACE 84 81 85 extern QImage qt_imageForBrush(int brushStyle, bool invert); //in qbrush.cpp82 Q_DECL_IMPORT extern QImage qt_imageForBrush(int brushStyle, bool invert); //in qbrush.cpp 86 83 #ifdef QT_MAC_USE_COCOA 87 84 extern void *qt_current_nsopengl_context(); // qgl_mac.mm … … 510 507 ////////// GL program cache: start 511 508 512 typedef struct{509 struct GLProgram { 513 510 int brush; // brush index or mask index 514 511 int mode; // composition mode index 515 512 bool mask; 516 513 GLuint program; 517 } GLProgram;514 }; 518 515 519 516 typedef QMultiHash<const QGLContext *, GLProgram> QGLProgramHash; … … 672 669 , shader_ctx(0) 673 670 , grad_palette(0) 671 , tess_points(0) 674 672 , drawable_texture(0) 675 673 , ref_cleaner(this) … … 781 779 782 780 void composite(const QRectF &rect, const QPoint &maskOffset = QPoint()); 783 void composite(GLuint primitive, const q_vertexType*vertexArray, int vertexCount, const QPoint &maskOffset = QPoint());781 void composite(GLuint primitive, const GLfloat *vertexArray, int vertexCount, const QPoint &maskOffset = QPoint()); 784 782 785 783 bool createFragmentPrograms(); … … 924 922 stroker.setJoinStyle(cpen.joinStyle()); 925 923 stroker.setMiterLimit(cpen.miterLimit()); 924 stroker.setDashOffset(cpen.dashOffset()); 926 925 927 926 qreal width = cpen.widthF(); … … 1793 1792 QOpenGLTrapezoidToArrayTessellator() : vertices(0), allocated(0), size(0) {} 1794 1793 ~QOpenGLTrapezoidToArrayTessellator() { free(vertices); } 1795 q_vertexType*vertices;1794 GLfloat *vertices; 1796 1795 int allocated; 1797 1796 int size; … … 1814 1813 #endif 1815 1814 allocated = qMax(2*allocated, 512); 1816 vertices = ( q_vertexType *)realloc(vertices, allocated * sizeof(q_vertexType));1815 vertices = (GLfloat *)realloc(vertices, allocated * sizeof(GLfloat)); 1817 1816 } 1818 1817 … … 1820 1819 1821 1820 #ifndef QT_OPENGL_ES 1822 vertices[size++] = f2vt(t.topLeftX);1823 vertices[size++] = f2vt(t.top);1824 vertices[size++] = f2vt(t.topRightX);1825 vertices[size++] = f2vt(t.top);1826 vertices[size++] = f2vt(t.bottomRightX);1827 vertices[size++] = f2vt(t.bottom);1828 vertices[size++] = f2vt(t.bottomLeftX);1829 vertices[size++] = f2vt(t.bottom);1821 vertices[size++] = t.topLeftX; 1822 vertices[size++] = t.top; 1823 vertices[size++] = t.topRightX; 1824 vertices[size++] = t.top; 1825 vertices[size++] = t.bottomRightX; 1826 vertices[size++] = t.bottom; 1827 vertices[size++] = t.bottomLeftX; 1828 vertices[size++] = t.bottom; 1830 1829 #else 1831 1830 // First triangle 1832 vertices[size++] = f2vt(t.topLeftX);1833 vertices[size++] = f2vt(t.top);1834 vertices[size++] = f2vt(t.topRightX);1835 vertices[size++] = f2vt(t.top);1836 vertices[size++] = f2vt(t.bottomRightX);1837 vertices[size++] = f2vt(t.bottom);1831 vertices[size++] = t.topLeftX; 1832 vertices[size++] = t.top; 1833 vertices[size++] = t.topRightX; 1834 vertices[size++] = t.top; 1835 vertices[size++] = t.bottomRightX; 1836 vertices[size++] = t.bottom; 1838 1837 1839 1838 // Second triangle 1840 vertices[size++] = f2vt(t.bottomLeftX);1841 vertices[size++] = f2vt(t.bottom);1842 vertices[size++] = f2vt(t.topLeftX);1843 vertices[size++] = f2vt(t.top);1844 vertices[size++] = f2vt(t.bottomRightX);1845 vertices[size++] = f2vt(t.bottom);1839 vertices[size++] = t.bottomLeftX; 1840 vertices[size++] = t.bottom; 1841 vertices[size++] = t.topLeftX; 1842 vertices[size++] = t.top; 1843 vertices[size++] = t.bottomRightX; 1844 vertices[size++] = t.bottom; 1846 1845 #endif 1847 1846 } … … 1870 1869 composite(geometry_mode, tessellator.vertices, tessellator.size / 2); 1871 1870 } else { 1872 glVertexPointer(2, q_vertexTypeEnum, 0, tessellator.vertices);1871 glVertexPointer(2, GL_FLOAT, 0, tessellator.vertices); 1873 1872 glEnableClientState(GL_VERTEX_ARRAY); 1874 1873 glDrawArrays(geometry_mode, 0, tessellator.size/2); … … 1959 1958 void QOpenGLPaintEnginePrivate::drawVertexArrays() 1960 1959 { 1960 if (tess_points_stops.count() == 0) 1961 return; 1961 1962 glEnableClientState(GL_VERTEX_ARRAY); 1962 1963 glVertexPointer(2, GL_DOUBLE, 0, tess_points.data()); … … 2271 2272 } 2272 2273 2273 #if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_2) || defined(QT_OPENGL_ES_1_CL)2274 #if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_2) 2274 2275 glClearDepthf(0.0f); 2275 2276 #else … … 2287 2288 2288 2289 // rectangle count * 2 (triangles) * vertex count * component count (Z omitted) 2289 QDataBuffer< q_vertexType> clipVertex(rects.size()*2*3*2);2290 QDataBuffer<GLfloat> clipVertex(rects.size()*2*3*2); 2290 2291 for (int i = 0; i < rects.size(); ++i) { 2291 q_vertexType x = i2vt(rects.at(i).left());2292 q_vertexType w = i2vt(rects.at(i).width());2293 q_vertexType h = i2vt(rects.at(i).height());2294 q_vertexType y = i2vt(rects.at(i).top());2292 GLfloat x = GLfloat(rects.at(i).left()); 2293 GLfloat w = GLfloat(rects.at(i).width()); 2294 GLfloat h = GLfloat(rects.at(i).height()); 2295 GLfloat y = GLfloat(rects.at(i).top()); 2295 2296 2296 2297 // First triangle … … 2320 2321 2321 2322 glEnableClientState(GL_VERTEX_ARRAY); 2322 glVertexPointer(2, q_vertexTypeEnum, 0, clipVertex.data());2323 glVertexPointer(2, GL_FLOAT, 0, clipVertex.data()); 2323 2324 2324 2325 glDrawArrays(GL_TRIANGLES, 0, rects.size()*2*3); … … 3112 3113 } 3113 3114 3114 extern void qt_add_rect_to_array(const QRectF &r, q_vertexType*array);3115 extern void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, q_vertexType*array);3115 extern void qt_add_rect_to_array(const QRectF &r, GLfloat *array); 3116 extern void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array); 3116 3117 3117 3118 void QGLTrapezoidMaskGenerator::drawMask(const QRect &rect) … … 3144 3145 // clear mask 3145 3146 glBlendFunc(GL_ZERO, GL_ZERO); // clear 3146 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);3147 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 3147 3148 glEnableClientState(GL_VERTEX_ARRAY); 3148 3149 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); … … 3351 3352 QTransform inv_matrix = gl_to_qt * matrix().inverted() * translate; 3352 3353 3353 float m[3][4] = { { inv_matrix.m11(), inv_matrix.m12(), inv_matrix.m13() },3354 { inv_matrix.m21(), inv_matrix.m22(), inv_matrix.m23() },3355 { inv_matrix.m31(), inv_matrix.m32(), inv_matrix.m33() } };3354 float m[3][4] = { { float(inv_matrix.m11()), float(inv_matrix.m12()), float(inv_matrix.m13()) }, 3355 { float(inv_matrix.m21()), float(inv_matrix.m22()), float(inv_matrix.m23()) }, 3356 { float(inv_matrix.m31()), float(inv_matrix.m32()), float(inv_matrix.m33()) } }; 3356 3357 3357 3358 QPoint offs(screen_rect.left() - rect.left(), (offscreen->drawableSize().height() - screen_rect.top()) … … 3359 3360 3360 3361 // last component needs to be 1.0f to avoid Nvidia bug on linux 3361 float ellipse_offset[4] = { offs.x(), offs.y(), 0.0f, 1.0f };3362 float ellipse_offset[4] = { float(offs.x()), float(offs.y()), 0.0f, 1.0f }; 3362 3363 3363 3364 GLfloat vertexArray[4 * 2]; … … 3375 3376 3376 3377 glEnableClientState(GL_VERTEX_ARRAY); 3377 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);3378 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 3378 3379 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 3379 3380 glDisableClientState(GL_VERTEX_ARRAY); … … 3405 3406 DEBUG_ONCE_STR("QOpenGLPaintEngine::drawRects(): drawing fast rect"); 3406 3407 3407 q_vertexTypevertexArray[10];3408 GLfloat vertexArray[10]; 3408 3409 qt_add_rect_to_array(r, vertexArray); 3409 3410 … … 3426 3427 if (fast_style && has_fast_composition_mode) { 3427 3428 glEnableClientState(GL_VERTEX_ARRAY); 3428 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);3429 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 3429 3430 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 3430 3431 glDisableClientState(GL_VERTEX_ARRAY); … … 3445 3446 vertexArray[9] = vertexArray[1]; 3446 3447 3447 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);3448 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 3448 3449 glEnableClientState(GL_VERTEX_ARRAY); 3449 3450 glDrawArrays(GL_LINE_STRIP, 0, 5); … … 3552 3553 } 3553 3554 3554 static void addQuadAsTriangle( q_vertexType *quad, q_vertexType*triangle)3555 static void addQuadAsTriangle(GLfloat *quad, GLfloat *triangle) 3555 3556 { 3556 3557 triangle[0] = quad[0]; … … 3613 3614 3614 3615 if (d->has_fast_pen) { 3615 QVarLengthArray< q_vertexType> vertexArray(6 * pointCount);3616 QVarLengthArray<GLfloat> vertexArray(6 * pointCount); 3616 3617 3617 3618 glMatrixMode(GL_MODELVIEW); … … 3623 3624 QPointF mapped = d->matrix.map(points[i]); 3624 3625 3625 qreal xf = qRound(mapped.x()); 3626 qreal yf = qRound(mapped.y()); 3627 3628 q_vertexType x = f2vt(xf); 3629 q_vertexType y = f2vt(yf); 3626 GLfloat x = GLfloat(qRound(mapped.x())); 3627 GLfloat y = GLfloat(qRound(mapped.y())); 3630 3628 3631 3629 vertexArray[j++] = x; 3632 vertexArray[j++] = y - f2vt(0.5);3633 3634 vertexArray[j++] = x + f2vt(1.5);3635 vertexArray[j++] = y + f2vt(1.0);3630 vertexArray[j++] = y - 0.5f; 3631 3632 vertexArray[j++] = x + 1.5f; 3633 vertexArray[j++] = y + 1.0f; 3636 3634 3637 3635 vertexArray[j++] = x; 3638 vertexArray[j++] = y + f2vt(1.0);3636 vertexArray[j++] = y + 1.0f; 3639 3637 } 3640 3638 3641 3639 glEnableClientState(GL_VERTEX_ARRAY); 3642 3640 3643 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray.constData());3641 glVertexPointer(2, GL_FLOAT, 0, vertexArray.constData()); 3644 3642 glDrawArrays(GL_TRIANGLES, 0, pointCount*3); 3645 3643 … … 3658 3656 else { 3659 3657 Q_ASSERT(sizeof(QPointF) == 8); 3660 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);3658 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 3661 3659 } 3662 3660 … … 3726 3724 } 3727 3725 3728 q_vertexType endCap = f2vt(d->cpen.capStyle() == Qt::FlatCap ? 0 : 0.5);3726 GLfloat endCap = d->cpen.capStyle() == Qt::FlatCap ? 0.0f : 0.5f; 3729 3727 if (useRects) { 3730 QVarLengthArray< q_vertexType> vertexArray(12 * lineCount);3731 3732 q_vertexTypequad[8];3728 QVarLengthArray<GLfloat> vertexArray(12 * lineCount); 3729 3730 GLfloat quad[8]; 3733 3731 for (int i = 0; i < lineCount; ++i) { 3734 q_vertexType x1 = f2vt(lines[i].x1());3735 q_vertexType x2 = f2vt(lines[i].x2());3736 q_vertexType y1 = f2vt(lines[i].y1());3737 q_vertexType y2 = f2vt(lines[i].y2());3732 GLfloat x1 = lines[i].x1(); 3733 GLfloat x2 = lines[i].x2(); 3734 GLfloat y1 = lines[i].y1(); 3735 GLfloat y2 = lines[i].y2(); 3738 3736 3739 3737 if (x1 == x2) { … … 3741 3739 qSwap(y1, y2); 3742 3740 3743 quad[0] = x1 - f2vt(0.5);3741 quad[0] = x1 - 0.5f; 3744 3742 quad[1] = y1 - endCap; 3745 3743 3746 quad[2] = x1 + f2vt(0.5);3744 quad[2] = x1 + 0.5f; 3747 3745 quad[3] = y1 - endCap; 3748 3746 3749 quad[4] = x1 + f2vt(0.5);3747 quad[4] = x1 + 0.5f; 3750 3748 quad[5] = y2 + endCap; 3751 3749 3752 quad[6] = x1 - f2vt(0.5);3750 quad[6] = x1 - 0.5f; 3753 3751 quad[7] = y2 + endCap; 3754 3752 } else { … … 3757 3755 3758 3756 quad[0] = x1 - endCap; 3759 quad[1] = y1 + f2vt(0.5);3757 quad[1] = y1 + 0.5f; 3760 3758 3761 3759 quad[2] = x1 - endCap; 3762 quad[3] = y1 - f2vt(0.5);3760 quad[3] = y1 - 0.5f; 3763 3761 3764 3762 quad[4] = x2 + endCap; 3765 quad[5] = y1 - f2vt(0.5);3763 quad[5] = y1 - 0.5f; 3766 3764 3767 3765 quad[6] = x2 + endCap; 3768 quad[7] = y1 + f2vt(0.5);3766 quad[7] = y1 + 0.5f; 3769 3767 } 3770 3768 … … 3774 3772 glEnableClientState(GL_VERTEX_ARRAY); 3775 3773 3776 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray.constData());3774 glVertexPointer(2, GL_FLOAT, 0, vertexArray.constData()); 3777 3775 glDrawArrays(GL_TRIANGLES, 0, lineCount*6); 3778 3776 3779 3777 glDisableClientState(GL_VERTEX_ARRAY); 3780 3778 } else { 3781 QVarLengthArray< q_vertexType> vertexArray(4 * lineCount);3779 QVarLengthArray<GLfloat> vertexArray(4 * lineCount); 3782 3780 for (int i = 0; i < lineCount; ++i) { 3783 3781 const QPointF a = lines[i].p1(); 3784 vertexArray[4*i] = f2vt(lines[i].x1());3785 vertexArray[4*i+1] = f2vt(lines[i].y1());3786 vertexArray[4*i+2] = f2vt(lines[i].x2());3787 vertexArray[4*i+3] = f2vt(lines[i].y2());3782 vertexArray[4*i] = lines[i].x1(); 3783 vertexArray[4*i+1] = lines[i].y1(); 3784 vertexArray[4*i+2] = lines[i].x2(); 3785 vertexArray[4*i+3] = lines[i].y2(); 3788 3786 } 3789 3787 3790 3788 glEnableClientState(GL_VERTEX_ARRAY); 3791 3789 3792 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray.constData());3790 glVertexPointer(2, GL_FLOAT, 0, vertexArray.constData()); 3793 3791 glDrawArrays(GL_LINES, 0, lineCount*2); 3794 3792 3795 glVertexPointer(2, q_vertexTypeEnum, 4*sizeof(q_vertexType), vertexArray.constData() + 2);3793 glVertexPointer(2, GL_FLOAT, 4*sizeof(GLfloat), vertexArray.constData() + 2); 3796 3794 glDrawArrays(GL_POINTS, 0, lineCount); 3797 3795 … … 3880 3878 else { 3881 3879 Q_ASSERT(sizeof(QPointF) == 8); 3882 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);3880 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 3883 3881 } 3884 3882 … … 3899 3897 if (d->has_fast_pen && !d->high_quality_antialiasing) { 3900 3898 d->setGradientOps(d->cpen.brush(), bounds); 3901 QVarLengthArray< q_vertexType> vertexArray(pointCount*2 + 2);3902 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray.constData());3899 QVarLengthArray<GLfloat> vertexArray(pointCount*2 + 2); 3900 glVertexPointer(2, GL_FLOAT, 0, vertexArray.constData()); 3903 3901 int i; 3904 3902 for (i=0; i<pointCount; ++i) { 3905 vertexArray[i*2] = f2vt(points[i].x());3906 vertexArray[i*2+1] = f2vt(points[i].y());3903 vertexArray[i*2] = points[i].x(); 3904 vertexArray[i*2+1] = points[i].y(); 3907 3905 } 3908 3906 … … 3959 3957 } 3960 3958 3961 externbool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp3959 Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp 3962 3960 3963 3961 void QOpenGLPaintEnginePrivate::strokePath(const QPainterPath &path, bool use_cache) … … 4080 4078 case QPainterPath::MoveToElement: 4081 4079 if (i != 0) { 4082 glVertexPointer(2, q_vertexTypeEnum, 0, tess_points.data());4080 glVertexPointer(2, GL_FLOAT, 0, tess_points.data()); 4083 4081 glDrawArrays(GL_LINE_STRIP, 0, tess_points.size()); 4084 4082 tess_points.reset(); … … 4130 4128 } // end of switch 4131 4129 } 4132 glVertexPointer(2, q_vertexTypeEnum, 0, tess_points.data());4130 glVertexPointer(2, GL_FLOAT, 0, tess_points.data()); 4133 4131 glDrawArrays(GL_LINE_STRIP, 0, tess_points.size()); 4134 4132 glDisableClientState(GL_VERTEX_ARRAY); … … 4397 4395 } 4398 4396 4399 q_vertexTypevertexArray[4*2];4400 q_vertexTypetexCoordArray[4*2];4397 GLfloat vertexArray[4*2]; 4398 GLfloat texCoordArray[4*2]; 4401 4399 4402 4400 double offset_x = offset.x() / pm.width(); … … 4407 4405 tc_w + offset_x, tc_h + offset_y, texCoordArray); 4408 4406 4409 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);4410 glTexCoordPointer(2, q_vertexTypeEnum, 0, texCoordArray);4407 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 4408 glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray); 4411 4409 4412 4410 glEnableClientState(GL_VERTEX_ARRAY); … … 4489 4487 } 4490 4488 4491 q_vertexTypevertexArray[4*2];4492 q_vertexTypetexCoordArray[4*2];4489 GLfloat vertexArray[4*2]; 4490 GLfloat texCoordArray[4*2]; 4493 4491 4494 4492 qt_add_rect_to_array(r, vertexArray); 4495 4493 qt_add_texcoords_to_array(x1, y2, x2, y1, texCoordArray); 4496 4494 4497 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);4498 glTexCoordPointer(2, q_vertexTypeEnum, 0, texCoordArray);4495 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 4496 glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray); 4499 4497 4500 4498 glEnableClientState(GL_VERTEX_ARRAY); … … 4561 4559 ~QGLGlyphCache(); 4562 4560 QGLGlyphCoord *lookup(QFontEngine *, glyph_t); 4563 void cacheGlyphs(QGLContext *, const QTextItemInt &, const QVarLengthArray<glyph_t> &);4561 void cacheGlyphs(QGLContext *, QFontEngine *, glyph_t *glyphs, int numGlyphs); 4564 4562 void cleanCache(); 4565 4563 void allocTexture(int width, int height, GLuint texture); … … 4713 4711 #endif 4714 4712 4715 void QGLGlyphCache::cacheGlyphs(QGLContext *context, const QTextItemInt &ti,4716 const QVarLengthArray<glyph_t> &glyphs)4713 void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine, 4714 glyph_t *glyphs, int numGlyphs) 4717 4715 { 4718 4716 QGLContextHash::const_iterator dev_it = qt_context_cache.constFind(context); … … 4738 4736 // qDebug() << "new context" << context << font_cache; 4739 4737 qt_context_cache.insert(context, font_cache); 4740 if (context->isValid() && context->device()->devType() == QInternal::Widget) { 4741 QWidget *widget = static_cast<QWidget *>(context->device()); 4742 connect(widget, SIGNAL(destroyed(QObject*)), SLOT(widgetDestroyed(QObject*))); 4738 if (context->isValid()) { 4739 if (context->device()->devType() == QInternal::Widget) { 4740 QWidget *widget = static_cast<QWidget *>(context->device()); 4741 connect(widget, SIGNAL(destroyed(QObject*)), SLOT(widgetDestroyed(QObject*))); 4742 } 4743 4743 connect(QGLSignalProxy::instance(), 4744 4744 SIGNAL(aboutToDestroyContext(const QGLContext*)), … … 4750 4750 Q_ASSERT(font_cache != 0); 4751 4751 4752 QGLFontGlyphHash::const_iterator cache_it = font_cache->constFind( ti.fontEngine);4752 QGLFontGlyphHash::const_iterator cache_it = font_cache->constFind(fontEngine); 4753 4753 QGLGlyphHash *cache = 0; 4754 4754 if (cache_it == font_cache->constEnd()) { 4755 4755 cache = new QGLGlyphHash; 4756 font_cache->insert( ti.fontEngine, cache);4757 connect( ti.fontEngine, SIGNAL(destroyed(QObject*)), SLOT(fontEngineDestroyed(QObject*)));4756 font_cache->insert(fontEngine, cache); 4757 connect(fontEngine, SIGNAL(destroyed(QObject*)), SLOT(fontEngineDestroyed(QObject*))); 4758 4758 } else { 4759 4759 cache = cache_it.value(); … … 4762 4762 4763 4763 quint64 font_key = (reinterpret_cast<quint64>(context_key ? context_key : context) << 32) 4764 | reinterpret_cast<quint64>( ti.fontEngine);4764 | reinterpret_cast<quint64>(fontEngine); 4765 4765 QGLFontTexHash::const_iterator it = qt_font_textures.constFind(font_key); 4766 4766 QGLFontTexture *font_tex; … … 4768 4768 GLuint font_texture; 4769 4769 glGenTextures(1, &font_texture); 4770 GLint tex_height = qt_next_power_of_two(qRound( ti.ascent.toReal() + ti.descent.toReal())+2);4770 GLint tex_height = qt_next_power_of_two(qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2); 4771 4771 GLint tex_width = qt_next_power_of_two(tex_height*30); // ### 4772 4772 GLint max_tex_size; … … 4790 4790 } 4791 4791 4792 for (int i=0; i< glyphs.size(); ++i) {4792 for (int i=0; i< numGlyphs; ++i) { 4793 4793 QGLGlyphHash::const_iterator it = cache->constFind(glyphs[i]); 4794 4794 if (it == cache->constEnd()) { 4795 4795 // render new glyph and put it in the cache 4796 glyph_metrics_t metrics = ti.fontEngine->boundingBox(glyphs[i]);4796 glyph_metrics_t metrics = fontEngine->boundingBox(glyphs[i]); 4797 4797 int glyph_width = qRound(metrics.width.toReal())+2; 4798 int glyph_height = qRound( ti.ascent.toReal() + ti.descent.toReal())+2;4798 int glyph_height = qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2; 4799 4799 4800 4800 if (font_tex->x_offset + glyph_width + x_margin > font_tex->width) { 4801 int strip_height = qt_next_power_of_two(qRound( ti.ascent.toReal() + ti.descent.toReal())+2);4801 int strip_height = qt_next_power_of_two(qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2); 4802 4802 font_tex->x_offset = x_margin; 4803 4803 font_tex->y_offset += strip_height; … … 4832 4832 } 4833 4833 4834 QImage glyph_im( ti.fontEngine->alphaMapForGlyph(glyphs[i]));4834 QImage glyph_im(fontEngine->alphaMapForGlyph(glyphs[i])); 4835 4835 glyph_im = glyph_im.convertToFormat(QImage::Format_Indexed8); 4836 4836 glyph_width = glyph_im.width(); … … 4912 4912 } 4913 4913 4914 void QOpenGLPaintEngine::drawStaticTextItem(QStaticTextItem *textItem) 4915 { 4916 Q_D(QOpenGLPaintEngine); 4917 4918 d->flushDrawQueue(); 4919 4920 // make sure the glyphs we want to draw are in the cache 4921 qt_glyph_cache()->cacheGlyphs(d->device->context(), textItem->fontEngine(), textItem->glyphs, 4922 textItem->numGlyphs); 4923 4924 d->setGradientOps(Qt::SolidPattern, QRectF()); // turns off gradient ops 4925 qt_glColor4ubv(d->pen_color); 4926 glEnable(GL_TEXTURE_2D); 4927 4928 #ifdef Q_WS_QWS 4929 // XXX: it is necessary to disable alpha writes on GLES/embedded because we don't want 4930 // text rendering to update the alpha in the window surface. 4931 // XXX: This may not be needed as this behavior does seem to be caused by driver bug 4932 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); 4933 #endif 4934 4935 // do the actual drawing 4936 GLfloat vertexArray[4*2]; 4937 GLfloat texCoordArray[4*2]; 4938 4939 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 4940 glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray); 4941 4942 glEnableClientState(GL_VERTEX_ARRAY); 4943 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 4944 bool antialias = !(textItem->fontEngine()->fontDef.styleStrategy & QFont::NoAntialias) 4945 && (d->matrix.type() > QTransform::TxTranslate); 4946 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, antialias ? GL_LINEAR : GL_NEAREST); 4947 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, antialias ? GL_LINEAR : GL_NEAREST); 4948 4949 for (int i=0; i< textItem->numGlyphs; ++i) { 4950 QGLGlyphCoord *g = qt_glyph_cache()->lookup(textItem->fontEngine(), textItem->glyphs[i]); 4951 4952 // we don't cache glyphs with no width/height 4953 if (!g) 4954 continue; 4955 4956 qreal x1, x2, y1, y2; 4957 x1 = g->x; 4958 y1 = g->y; 4959 x2 = x1 + g->width; 4960 y2 = y1 + g->height; 4961 4962 QPointF logical_pos((textItem->glyphPositions[i].x - g->x_offset).toReal(), 4963 (textItem->glyphPositions[i].y + g->y_offset).toReal()); 4964 4965 qt_add_rect_to_array(QRectF(logical_pos, QSizeF(g->log_width, g->log_height)), vertexArray); 4966 qt_add_texcoords_to_array(x1, y1, x2, y2, texCoordArray); 4967 4968 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 4969 } 4970 4971 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 4972 glDisableClientState(GL_VERTEX_ARRAY); 4973 4974 glDisable(GL_TEXTURE_2D); 4975 4976 #ifdef Q_WS_QWS 4977 // XXX: This may not be needed as this behavior does seem to be caused by driver bug 4978 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 4979 #endif 4980 4981 } 4982 4914 4983 void QOpenGLPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) 4915 4984 { … … 4926 4995 } 4927 4996 4928 d->flushDrawQueue();4929 4930 4997 // add the glyphs used to the glyph texture cache 4931 4998 QVarLengthArray<QFixedPoint> positions; … … 4934 5001 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); 4935 5002 4936 // make sure the glyphs we want to draw are in the cache 4937 qt_glyph_cache()->cacheGlyphs(d->device->context(), ti, glyphs); 4938 4939 d->setGradientOps(Qt::SolidPattern, QRectF()); // turns off gradient ops 4940 qt_glColor4ubv(d->pen_color); 4941 glEnable(GL_TEXTURE_2D); 4942 4943 #ifdef Q_WS_QWS 4944 // XXX: it is necessary to disable alpha writes on GLES/embedded because we don't want 4945 // text rendering to update the alpha in the window surface. 4946 // XXX: This may not be needed as this behavior does seem to be caused by driver bug 4947 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); 4948 #endif 4949 4950 // do the actual drawing 4951 q_vertexType vertexArray[4*2]; 4952 q_vertexType texCoordArray[4*2]; 4953 4954 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray); 4955 glTexCoordPointer(2, q_vertexTypeEnum, 0, texCoordArray); 4956 4957 glEnableClientState(GL_VERTEX_ARRAY); 4958 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 4959 bool antialias = !(ti.fontEngine->fontDef.styleStrategy & QFont::NoAntialias) 4960 && (d->matrix.type() > QTransform::TxTranslate); 4961 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, antialias ? GL_LINEAR : GL_NEAREST); 4962 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, antialias ? GL_LINEAR : GL_NEAREST); 4963 4964 for (int i=0; i< glyphs.size(); ++i) { 4965 QGLGlyphCoord *g = qt_glyph_cache()->lookup(ti.fontEngine, glyphs[i]); 4966 4967 // we don't cache glyphs with no width/height 4968 if (!g) 4969 continue; 4970 4971 qreal x1, x2, y1, y2; 4972 x1 = g->x; 4973 y1 = g->y; 4974 x2 = x1 + g->width; 4975 y2 = y1 + g->height; 4976 4977 QPointF logical_pos((positions[i].x - g->x_offset).toReal(), 4978 (positions[i].y + g->y_offset).toReal()); 4979 4980 qt_add_rect_to_array(QRectF(logical_pos, QSizeF(g->log_width, g->log_height)), vertexArray); 4981 qt_add_texcoords_to_array(x1, y1, x2, y2, texCoordArray); 4982 4983 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 4984 } 4985 4986 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 4987 glDisableClientState(GL_VERTEX_ARRAY); 4988 4989 glDisable(GL_TEXTURE_2D); 4990 4991 #ifdef Q_WS_QWS 4992 // XXX: This may not be needed as this behavior does seem to be caused by driver bug 4993 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 4994 #endif 5003 { 5004 QStaticTextItem staticTextItem; 5005 staticTextItem.chars = const_cast<QChar *>(ti.chars); 5006 staticTextItem.setFontEngine(ti.fontEngine); 5007 staticTextItem.glyphs = glyphs.data(); 5008 staticTextItem.numChars = ti.num_chars; 5009 staticTextItem.numGlyphs = glyphs.size(); 5010 staticTextItem.glyphPositions = positions.data(); 5011 drawStaticTextItem(&staticTextItem); 5012 } 5013 4995 5014 } 4996 5015 … … 5166 5185 Q_UNUSED(maskOffset); 5167 5186 #else 5168 q_vertexTypevertexArray[8];5187 GLfloat vertexArray[8]; 5169 5188 qt_add_rect_to_array(rect, vertexArray); 5170 5189 … … 5174 5193 5175 5194 5176 void QOpenGLPaintEnginePrivate::composite(GLuint primitive, const q_vertexType*vertexArray, int vertexCount, const QPoint &maskOffset)5195 void QOpenGLPaintEnginePrivate::composite(GLuint primitive, const GLfloat *vertexArray, int vertexCount, const QPoint &maskOffset) 5177 5196 { 5178 5197 #ifdef QT_OPENGL_ES … … 5197 5216 5198 5217 for (int i = 0; i < vertexCount; ++i) { 5199 qreal x = v t2f(vertexArray[2 * i]);5200 qreal y = v t2f(vertexArray[2 * i + 1]);5218 qreal x = vertexArray[2 * i]; 5219 qreal y = vertexArray[2 * i + 1]; 5201 5220 5202 5221 qreal tx, ty; … … 5257 5276 5258 5277 glEnableClientState(GL_VERTEX_ARRAY); 5259 glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);5278 glVertexPointer(2, GL_FLOAT, 0, vertexArray); 5260 5279 glEnable(GL_FRAGMENT_PROGRAM_ARB); 5261 5280 GLuint program = qt_gl_program_cache()->getProgram(device->context(),
Note:
See TracChangeset
for help on using the changeset viewer.