Results 1 to 19 of 19

Thread: How to speed up a transparent QGraphicsTextItem in Opengl?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to speed up a transparent QGraphicsTextItem in Opengl?

    Your implementation of shape() and boundingRect() is awfully slow. You are creating painter paths all the time. Cache all the data you can (meaning the shape and the bounding rect), this should already give you some speed improvement.

    BTW. The background shouldn't influence the contents of the item's cache... I suspect this is caused by an incorrect result of boundingRect() at the time the cache is being enabled.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 90 Times in 88 Posts

    Default Re: How to speed up a transparent QGraphicsTextItem in Opengl?

    Quote Originally Posted by wysota View Post
    Your implementation of shape() and boundingRect() is awfully slow. You are creating painter paths all the time. Cache all the data you can (meaning the shape and the bounding rect), this should already give you some speed improvement.
    Yes, I know. But that's definitely not the speed problem. It makes no difference if I have just one TextItem (thus only one transformation, shape, boundingrect calculation) with a lot of text or lots of textitems with just one line of text. Both are equally slow.

    Quote Originally Posted by wysota View Post
    BTW. The background shouldn't influence the contents of the item's cache... I suspect this is caused by an incorrect result of boundingRect() at the time the cache is being enabled.
    That is definitely the case! The cache is enabled in the constructor. The boundingrect changes all the time. Through the perspective change..

    We are on to something here :->

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 90 Times in 88 Posts

    Default Re: How to speed up a transparent QGraphicsTextItem in Opengl?

    Mmh.. What can I do about it?

    The ProjectedItem changes its projection. And thus its boundingrect.

    I don't set the boundingrect of the textitem at all. I just leave it as it is. Because its a childitem of the projecteditem it gets drawn at the right place.

    The ProjectedParentItem has no caching activated.

    When would be the right time to activate caching?

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 90 Times in 88 Posts

    Default Re: How to speed up a transparent QGraphicsTextItem in Opengl?

    Hey Wysota!

    I took the time and added the TextItem to the Widget3D Demo.



    So whenever you have the time you are welcome to look at the code. If not, it'll stay that slow a little longer :->

    Most relevant file is widget3d.h (CGL3dProjectedItem, CGL3dTextItem, ..).

    There you can disable the cachemode. And it works just fine.

    I think the core problem is: How can I use caching when the transformation and thus the boundingrect changes all the time?

    Thx a lot for your help so far!

    Johannes
    Attached Files Attached Files

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to speed up a transparent QGraphicsTextItem in Opengl?

    You have to isolate why the background is black. You can see it is not black in my code so there is nothing wrong with the cache in general. As for your bounding rect - see that when your item has no children its bounding rect will be invalid. If you create the cache at that time and not pass the amount of memory you want allocated for the item's cache, it will allocate as much memory as needed to fit your bounding rect. Which in your case is... 0. This is likely to lead to problems although I'd expect everything to be black, not just the background.

    I suggest you start from scratch (or with my code) and build upon it until you encounter a situation where cache fails. It might take shorter than wild bug chasing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 90 Times in 88 Posts

    Default Re: How to speed up a transparent QGraphicsTextItem in Opengl?

    Caching is only enabled for the TextItem! That is a child to a projecteditem, whose shape/boundingrect code I have given you earlier. The caching of the TextItem should not be affected by that, or is it?

    The TextItems-Bounding-Rect seems to be fine, as the cache-related black background suggests.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to speed up a transparent QGraphicsTextItem in Opengl?

    So is everything alright now or not?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 90 Times in 88 Posts

    Default Re: How to speed up a transparent QGraphicsTextItem in Opengl?

    Hi there!

    I'm afraid it is not. The solid black background stays in my application. As you suggested, I continued our minimal error example in introducing the 3DTextItem and a dummy ProjectedItem. Sadly, still works.

    main.cpp:

    Qt Code:
    1. #include <QtGui>
    2. #include <QGLWidget>
    3. #include "textitem.h"
    4.  
    5. class CGLScene : public QGraphicsScene
    6. {
    7. protected:
    8. void drawBackground(QPainter *painter, const QRectF &rect)
    9. {
    10. glClearColor(1.0,1.0,0.0,1.0);
    11. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    12. }
    13. };
    14.  
    15. int main(int argc, char **argv){
    16. QApplication app(argc, argv);
    17. CGLScene scene;
    18.  
    19. view.setScene(&scene);
    20. view.setViewport(new QGLWidget);
    21.  
    22. CGL3dTextItem* item = new CGL3dTextItem("");
    23. item->setHTML("<font color=#FF0000>FAT TEST </font>");
    24.  
    25. scene.addItem(item);
    26.  
    27. QFont f;
    28. f.setPointSize(36);
    29. item->setFont(f);
    30. item->setFlag(QGraphicsItem::ItemIsMovable);
    31. //item->setCacheMode(QGraphicsItem::ItemCoordinateCache);
    32.  
    33. QTransform trans;
    34. trans.rotate(60, Qt::YAxis);
    35. item->setTransform(trans);
    36. item->setOpacity(1);
    37. view.show();
    38. return app.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 

    textitem.h - a separate header file for moc to start up.
    Qt Code:
    1. #ifndef TEXTITEM_H
    2. #define TEXTITEM_H
    3.  
    4. #include <QtGui>
    5. #include <QObject>
    6.  
    7. class CGL3dProjectedItem : public QObject, public QGraphicsItem
    8. { Q_OBJECT
    9. protected:
    10. virtual QRectF boundingRect() const {return shape().boundingRect();}
    11. virtual QPainterPath shape() const {QPainterPath p;QPolygonF polygon = mapToScene(this->childrenBoundingRect());p.addPolygon(polygon);return p;}
    12. virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) {}
    13. };
    14.  
    15. class CGL3dTextItem : public CGL3dProjectedItem
    16. { Q_OBJECT
    17. Q_PROPERTY(QObject* textitem READ getTextItem)
    18. Q_PROPERTY(QString text READ getText WRITE setText)
    19. Q_PROPERTY(QString html READ getHTML WRITE setHTML)
    20. Q_PROPERTY(QFont font READ getFont WRITE setFont)
    21. public:
    22. CGL3dTextItem(QString text) : CGL3dProjectedItem()
    23. {
    24. _textitem = new QGraphicsTextItem(text,this);
    25. _textitem->setTextInteractionFlags(Qt::TextBrowserInteraction);
    26. QTextOption textoption(Qt::AlignCenter);
    27. textoption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    28. _textitem->document()->setDefaultTextOption(textoption);
    29. _textitem->setCacheMode(QGraphicsItem::ItemCoordinateCache);
    30. //setHandlesChildEvents(true);
    31. }
    32. enum { Type = UserType+2};
    33. int type() const { return Type;}
    34. QObject* getTextItem() {return _textitem;}
    35. QString getText() {return _textitem->toPlainText();}
    36. void setText(QString plaintext) {_textitem->setPlainText(plaintext);TextChanged();}
    37. QString getHTML() {return _textitem->toHtml();}
    38. void setHTML(QString htmltext) {_textitem->setHtml(htmltext);TextChanged();}
    39. QFont getFont() {return _textitem->font();}
    40. void setFont(QFont f) {_textitem->setFont(f);TextChanged();}
    41. protected:
    42. void TextChanged()
    43. {
    44. // SetCenterPos(CGL3d(-_textitem->document()->size().width()/2,0,0));
    45. //qDebug() << "TextItem Center: " << CenterPos().toString();
    46. }
    47. private:
    48. QGraphicsTextItem* _textitem;
    49. };
    50.  
    51. #endif // TEXTITEM_H
    To copy to clipboard, switch view to plain text mode 

    So maybe the problem is hidden in the kind of transformation I am doing. I will investigate.

    Thx

    Joh

Similar Threads

  1. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 19:04
  2. Does OpenGL speed up the loading image?
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 4th December 2008, 10:26
  3. QMatrix rotate on QGraphicsTextItem speed on render..
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 22nd December 2007, 20:46
  4. OpenGL app at full speed? Can you do it?
    By mattropolis in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2007, 11:54
  5. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 08:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.