[Qt-interest] QGL2PaintEngineEx vc QGLContext
Samuel Rødal
sroedal at trolltech.com
Thu Dec 10 18:50:21 CET 2009
John Clayton wrote:
>> John Clayton wrote:
>>> Hi All
>>> From testing - I notice that drawing a texture to my GL surface (on
>>> a Mac, using 4.6.0, in a QGraphicsItem paint() method) can be done
>>> in two different ways.
>>> Method 1 - use QPainter->drawImage(QRectF, QImage)
>>> or
>>> Method 2 - use QGLWidget->drawTexture(QRectF, int, int)
>>> Method 1 works perfectly in my case, and looking at its code it is
>>> using the new Qt4.6 opengl code.
>>> Method 2 fails to draw anything (it used to work in 4.5.3), and the
>>> code to draw looks *totally* different compared with Method 1.
>>> So, how can I use Method 1 to draw - given that i have a texture
>>> ID. My requirement is to draw textures into a QGraphicsItem, and
>>> QGLWidget- >drawTexture() appears to fit the bill - but it doesn't
>>> draw anything (unless I call beginNativePainting first - but that
>>> wipes out the clipping path).
>>> Is there a way I can use the QPainter based method to draw textures?
>>> Thanks
>>> --
>>> John Clayton
>>> Skype: johncclayton
>>
>> For the modelview and projection matrices to be set up as you would
>> expect you need to call beginNativePainting() in 4.6. How the GL paint
>> engine handles clipping is an internal detail, it might use the depth
>> buffer, stencil buffer, or a different approach, so we don't want to
>> expose that through beginNativePainting(). Instead you should manually
>> make sure to paint within the clip path, or ideally simplify your
>> graphics item so it only uses a rectangle clip (path clips are more
>> expensive in any case).
>>
>
> How can I manually ensure that? Isn't the whole point of the clip path
> the fact that I *dont* need to manually ensure this kind of thing while
> drawing? I can draw, it gets clipped - that's [I hope] what the API
> guarantee was/is supposed to be. But; do tell me if I read the docs
> wrong or am assuming to much here.
Yes, but using QGLWidget::drawTexture() is on the same level as issuing
raw OpenGL calls directly, which bypasses the painter completely. Thus
you can't assume that whatever OpenGL drawing you do is clipped by
QPainter's clipping state.
>> There _is_ a drawTexture call in QGL2PaintEngineEx (which you can get
>> by static_cast<QGL2PaintEngineEx *>(painter->paintEngine()) if the
>> paint engine's type function returns QPaintEngine::OpenGL2, but it's
>> internal private API, so you shouldn't use it unless you're prepared
>> that it might break in any future release. For now
>> QGLWidget::drawTexture() is the only supported way to go, but it
>> doesn't regard the current painter's state as you've noticed.
>>
>
> I'm missing something - what do you mean the drawTexture( ) disgregards
> the painter state - isn't the painter state simply a copy of the GL
> state? Hang on; are you saying that the methods used to draw a texture
> via QGLWidget bypass the painter state used to hold the clipping
> region? Putting two & two together from what I've read of the code so
> far - the clipping stuff looks like it is implemented in 4.6 as
> shader/vertex programs - and I'm not sure how that interacts in the
> render pipeline is one just renders a texture ala
> QGLWidget::drawTexture() - so is that why if I render with QGLWidget the
> entire texture surface is rendered, whereas the QPainter based routines
> are combining rendering of a texture with the already constructed
> shader/vertex code and thus honour clipping?
The painter state is the GL state in addition to some state variables in
the GL 2 paint engine. The issue is that drawTexture() is independent
from QPainter, it's original purpose was to simplifying drawing textures
when using raw OpenGL commands in an overloaded QGLWidget::paintGL().
How clipping is done for drawImage() etc is an implementation detail and
we don't want to expose that, as that would prevent us from possible
optimizations in the future.
> I did some more digging, and now I have a concrete error to work with.
> During the QGLContext::drawTexture() call - the glBindTexture(
Your message seems to have been cut off at this point.
--
Samuel
More information about the Qt-interest-old
mailing list