void paintComponent()
    {
        // you mustn't set your own cached image object when attaching a GL context!
        jassert (get (component) == this);

        updateViewportSize (false);

        if (! ensureFrameBufferSize())
            return;

        RectangleList invalid (viewportArea);
        invalid.subtract (validArea);
        validArea = viewportArea;

        if (! invalid.isEmpty())
        {
            clearRegionInFrameBuffer (invalid, (float) scale);

            {
                ScopedPointer<LowLevelGraphicsContext> g (createOpenGLGraphicsContext (context, cachedImageFrameBuffer));
                g->addTransform (AffineTransform::scale ((float) scale));
                g->clipToRectangleList (invalid);

                paintOwner (*g);
                JUCE_CHECK_OPENGL_ERROR
            }

            if (! context.isActive())
                context.makeActive();
        }
    void paintComponent()
    {
        if (needsUpdate)
        {
            MessageManagerLock mm (this);
            if (! mm.lockWasGained())
                return;

            needsUpdate = false;

            // you mustn't set your own cached image object when attaching a GL context!
            jassert (get (component) == this);

            const Rectangle<int> bounds (component.getLocalBounds());
            if (! ensureFrameBufferSize (bounds.getWidth(), bounds.getHeight()))
                return;

            RectangleList invalid (bounds);
            invalid.subtract (validArea);
            validArea = bounds;

            if (! invalid.isEmpty())
            {
                clearRegionInFrameBuffer (invalid);

                {
                    ScopedPointer<LowLevelGraphicsContext> g (createOpenGLGraphicsContext (context, cachedImageFrameBuffer));
                    g->clipToRectangleList (invalid);
                    paintOwner (*g);
                    JUCE_CHECK_OPENGL_ERROR
                }

                if (! context.isActive())
                    context.makeActive();
            }

            JUCE_CHECK_OPENGL_ERROR
        }
예제 #3
0
bool OpenGLComponent::performRender()
{
    const ScopedLock sl (contextLock);

   #if JUCE_LINUX
    updateContext();
   #endif

    if (context != nullptr)
    {
        if (! makeCurrentRenderingTarget())
            return false;

        if (needToUpdateViewport)
        {
            needToUpdateViewport = false;
            glViewport (0, 0, getWidth(), getHeight());
        }

        renderOpenGL();

        if (needToRepaint && (flags & allowSubComponents) != 0)
        {
            needToRepaint = false;

            contextLock.exit(); // (MM must be locked before the context lock)
            MessageManagerLock mmLock (renderThread);
            contextLock.enter();

            if (! mmLock.lockWasGained())
                return false;

            // you mustn't set your own cached image object for an OpenGLComponent!
            jassert (dynamic_cast<OpenGLCachedComponentImage*> (getCachedComponentImage()) == cachedImage);

            const Rectangle<int> bounds (getLocalBounds());
            OpenGLFrameBuffer& frameBuffer = cachedImage->getFrameBuffer (bounds.getWidth(), bounds.getHeight());

            {
                RectangleList invalid (bounds);
                invalid.subtract (cachedImage->validArea);
                cachedImage->validArea = bounds;

                if (! invalid.isEmpty())
                {
                    jassert (getCurrentContext() != nullptr);

                    {
                        OpenGLGraphicsContext g (*getCurrentContext(), frameBuffer);
                        g.clipToRectangleList (invalid);

                        g.setFill (Colours::transparentBlack);
                        g.fillRect (bounds, true);
                        g.setFill (Colours::black);

                        paintSelf (g);
                    }

                    makeCurrentRenderingTarget();
                }
            }

            glEnable (GL_TEXTURE_2D);
            context->extensions.glActiveTexture (GL_TEXTURE0);
            glBindTexture (GL_TEXTURE_2D, frameBuffer.getTextureID());

            context->copyTexture (bounds, Rectangle<int> (bounds.getWidth(),
                                                          bounds.getHeight()));
            glBindTexture (GL_TEXTURE_2D, 0);
        }

        swapBuffers();
    }

    return true;
}