OSX Mojave openGLContext.attachTo() issue if more than one context is used


#1

Because JUCE 2D rendering on OSX is quite slow in comparison to Windows we use a method discussed in several threads on this forum by just attaching an OpenGLContext to our components.
That method improves the OSX rendering speed of our audio analyzer GUI by at least a factor of 10 and brings it on the same level as the Windows rendering.

Up to OSX High Sierra we where able to use the method described in the code example below which is just a simple extension of the AudioPlugin and Component templates.

-------- EDIT: Issue has been solved (pls. see below), BUT! ----------

The issue comes with OSX Mojave where the VST3 plugin within the JUCE AudioPluginHost as well as the Standalone Application blocks rendering of the components completely as soon as more than one OpenGLContext is active.
All plugin formats do work in Reaper64, Cubase and Pro Tools but show rendering issues on an intermittent basis.
We’re testing on the latest JUCE development build.
There is no problem on Windows 10 by using this method, although it does not improve the rendering speed anyway.

My questions are:
1.) Is there any other way to accelerate the rendering on OSX?
2.) Do we use the OpenGLContext in the correct way?
3.) Will there be an alternative as soon as Apple drops OpenGL completely after deprecating it in Mojave?

Code Example:
The code example should render the 2 components above each other.
That works quite ok for the plugin formats, although the resizer seems to disappear, which does not happen if there is no or just one OpenGLContext attached.
In case of the Standalone Application and the JUCE AudioPluginHost it seems that the 2 OpenGLContexts block each other so that nothing is rendered at all.
It is even impossible to close the app (beach ball).
If only one context is active - for example attached to the PluginEditor - everything works fine.

PluginEditor Header:

#pragma once

#include "../JuceLibraryCode/JuceHeader.h"
#include "PluginProcessor.h"
#include "TestComponent.h"

class OglconAudioProcessorEditor  : public AudioProcessorEditor
{
public:
    OglconAudioProcessorEditor (OglconAudioProcessor&);
    ~OglconAudioProcessorEditor();

    void paint (Graphics&) override;
    void resized() override;

private:
    OglconAudioProcessor& processor;
    
    TestComponent testComponent1;
    TestComponent testComponent2;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OglconAudioProcessorEditor)
};

PluginEditor:

 #include "PluginProcessor.h"
 #include "PluginEditor.h"
 
 OglconAudioProcessorEditor::OglconAudioProcessorEditor (OglconAudioProcessor& p) : AudioProcessorEditor (p), processor (p)
 {
 	setOpaque(true);
 	setResizeLimits(200, 200, 1000, 1000);
 	addAndMakeVisible(testComponent1);
 	addAndMakeVisible(testComponent2);
 }
 
 OglconAudioProcessorEditor::~OglconAudioProcessorEditor()
 {
 }
 
 void OglconAudioProcessorEditor::paint (Graphics& g)
 {
 }
 
 void OglconAudioProcessorEditor::resized()
 {
 	testComponent1.setBounds(0, 0, getWidth(), getHeight() / 2);
 	testComponent2.setBounds(0, getHeight() / 2, getWidth(), getHeight() / 2);
 }

TestComponent Header:

 #pragma once
 
 #include "../JuceLibraryCode/JuceHeader.h"
 
 class TestComponent    : public Component
 {
 public:
	TestComponent();
	~TestComponent();
 
	void paint (Graphics&) override;
	void resized() override;
 
 private:
	OpenGLContext openGLContext;
     
	JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TestComponent)
 };

TestComponent:

 #include "../JuceLibraryCode/JuceHeader.h"
 #include "TestComponent.h"
 
 
 TestComponent::TestComponent()
 {
	setOpaque(true); 
	openGLContext.attachTo(*this);
 }
 
 TestComponent::~TestComponent()
 {
	openGLContext.detach();
 }
 
 void TestComponent::paint (Graphics& g)
 {
	g.setColour(Colours::black);
	g.fillRect(getLocalBounds());
	g.setColour (Colours::white);
	g.drawRect (getLocalBounds(), 1);
	g.setFont (14.0f);
	g.drawText ("TestComponent", getLocalBounds(),Justification::centred, true);
 }
 
 void TestComponent::resized()
 {
 }

#2

Well, the latest OSX Mojave update solved the issue :slightly_smiling_face:

Nevertheless, it would be extremely important to clarify the following questions:
1.) Is there any other way to accelerate the 2D rendering on OSX?
2.) Do we use the OpenGLContext in the correct way (pls. see above)?
3.) Will there be an alternative as soon as Apple drops OpenGL completely, after deprecating it in Mojave?