OpenGLContext handling


#1

Hello,


I am trying to get started with JUCE and OpenGL, however I run into some problems. I can't get an OpenGLTexture object initialized at program initialization, since there is no active context at that time. The docs say that the context should not be made active by the user, however I want to allocate my resources before the first call to render. If there's lots of memory to be allocated or transferred to GPU, that's not something you want to do inside the first actual render call. This will make things very sluggish when working with several dynamic Components using GL rendering, which is a requirement here. I need to be able to allocate my GPU-side resources as soon as I know I'll need them.


Calling makeActive() myself just before initializing the texture with loadARGB does not work, it still fails with OpenGLContext::getCurrentContext() != nullptr assertion in juce_OpenGLTexture.cpp:53. What is the intended way to go about this? Is there some high-level documentation on the OpenGL abstraction in JUCE? Anyways here's my relevant code:


// initialize glContext as class-member of Main, default constructor

// set up 
glContext.setComponentPaintingEnabled(false);
glContext.setContinuousRepainting(true);
glContext.setPixelFormat(OpenGLPixelFormat());
glContext.attachTo(*this);
glContext.setRenderer(&analysisRenderer);
glContext.makeActive();

// use
pTexture = new OpenGLTexture;
PixelARGB aPixel[1];
aPixel[0].setARGB(255, 255, 255, 255);
pTexture->loadARGB(aPixel, 1, 1);

 

I know that you are aware of the fact that the OpenGL implementation right now has conceptional problems which will be resolved (hopefully!) very soon after JUCE4 appears. However I need to get going on this project and need stuff to work as of now. Since you said the new OpenGL abstraction is already more or less finished and used by ROLI, is there a git branch where I could already make use of the changed interfaces? Might even be helpful for you, since I've been in the graphics domain for quite some years I might provide feedback as a pre-release tester in case you are interested. I could imagine that helps smoothing things out before the actual release.


Thanks for your support!
 


#2

Ok having looked closer at the OpenGLAppExample generated by the template project, and having some advice from a colleague who has more experience with the JUCE specifics, I see that all initialization is supposed to be performed in newOpenGLContextCreated(). Will this be called only once? It might seem a bit odd not to blindly follow the example in the first place, but having worked with bare OpenGL for a long time I really want to understand how the things are working under the hood in JUCE. Seems to work fine for now, sorry for the noise!

Still in order not to duplicate effort, is there any way to get my hands on the new GL abstraction already? Thanks!