OpenGL component broken


#1

Seems like openGL component is broken in juce 1.39.
If I minimize and then maximize juce demo,openGL component, seems to be gone. Happens both in Mac(intel) and Windows

Regards,
Yogesh


#2

I see what you mean (on Windows, haven’t tried the mac). It just seems to lose the textures though, so more of an opengl thing than a juce problem?

Might be a driver-specific thing - maybe it always unloads textures when a window gets minimised. Any opengl experts out there know any more about this?


#3

This problem didnt occur with eariler version of juce. I move my code from juce 1.26 to juce 1.39 and experienced this problem. With 1.26 the code just worked fine. So I guess there is some problem with juce_openGLComponent :frowning:

There seems to be changes made to the juce_OpenGLComponent since v1.26, that may have caused the bug.

Regards
Yogesh


#4

Ok, looking at this, it’s actually really trivial, and is just because the demo app was expecting a resized() callback that no longer happens. To fix it for now, you could juce tweak juce_OpenGLComponent.cpp like this:

[code] void initialise()
{
jassert (context == 0);

    if (context == 0)
    {
        context = juce_createOpenGLContext (owner,
                                            sharedContext != 0 ? sharedContext->context
                                                               : 0);

        if (context != 0)
        {
            componentMovedOrResized (true, true);
            owner->resized();
        }
    }
}[/code]

…but that’s actually a very poor design, so what I’ll do for next time is add a new method callback that lets the component know when a new openGL context is created, so that it can set it up correctly, rather than just setting it up when the comp is resized.


#5

It looks like OpenGL driver is deleting (textures) when the openGL context is deleted. juce_OpenGLComponent deletes and recreates context whenever the window is minimized and maximized. This forces our application to recreate textures when the window is minimized and maximized, which is unnecessary. So can u see to it that context wont be deleted and created again.

Regards
Bala


#6

I’ll see what I can do, though your code should be flexible enough to be able to handle a change of context if that’s necessary.


#7

In fact, I think it might be just a case of a small tweak to this method in juce_OpenGLComponent.cpp:

void componentVisibilityChanged (Component&) { if (wasShowing != owner->isShowing()) { wasShowing = owner->isShowing(); componentMovedOrResized (true, true); } }

Previously, it would re-create the context, but that’s probably not needed.


#8

Not sure but if you remove the “componentPeerChanged” calls in “componentVisibilityChanged” the “initialise” method will not be called and the context will stay null.

Is there any other place to call the “initialise” method, like an “activate” method ?


#9

Ah, yes, I’ve also made a couple of other changes since the 1.39 version that make it work ok here. You’d have add this too:

[code] void componentMovedOrResized (bool /wasMoved/, bool /wasResized/)
{
if (owner->getWidth() > 0 && owner->getHeight() > 0)
{
Component* const topComp = owner->getTopLevelComponent();

        if (topComp->getPeer() != 0)
        {
            needToUpdateViewport = true;

            if (context == 0)
            {
                if (owner->isShowing())
                    initialise();
                else
                    return;
            }

            if (context != 0)
                juce_updateOpenGLWindowPos (context, owner, topComp);
        }
    }
}

[/code]


#10