New OpenGL classes

Discussion and support for general JUCE issues

New OpenGL classes

Postby jules » Fri Mar 30, 2012 3:50 pm

After much longer than I expected it to take, I've finally checked-in my changes to the way the openGL classes work!

The TL;DR is:

- OpenGLComponent no longer exists
- Instead, you create an OpenGLContext object yourself, and then attach it to ANY component using the attachTo() method.
- That'll take care of rendering the component paint() using a GL 2D context, so you can use it to GL-accelerate the rendering on any component without needing to change the component itself.
- If you want to use a renderOpenGL() callback, you just have to provide an object that inherits from OpenGLRenderer, and pass that to the context object to use. (Doing this means you'll end up with something pretty similar to the way it all used to work, as OpenGLRenderer has similar callbacks to the old OpenGLComponent class)
- Before you delete your OpenGLRenderer object or your component, you call OpenGLContext::detach() (or delete the context) to let it clean-up.
- If you want to specify pixel formats, etc, you tell the context object about that before calling attachTo()

This new arrangement also fits with the way the Android classes work, which means that GL's now also available on Android! (Well, on devices that support GLES 2.0)

Have a look at the juce demo for an example - in fact there are actually very few lines of code that needed to change to make that work.

Enjoy! Your feedback on whether it all works smoothly would be much appreciated, and let me know if I've forgotten to implement any vital bits of functionality that you need!
User avatar
jules
Fearless Leader
 
Posts: 17380
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: New OpenGL classes

Postby sonic59 » Fri Mar 30, 2012 4:21 pm

Nice work Jules!

Everything ran smoothly for me.

Tested:
OpenGL Demo
Graphics Rendering Demo using OpenGL Renderer

Tested On:
Win 7 x64 - Geforce GT 440
Win 7 x64 - Geforce 9400m
OS X 10.7 x64 - Geforce 9400m
Win 7 x64 - Radeon HD5770

No Issues.
sonic59
JUCE UberWeenie
 
Posts: 224
Joined: Tue Mar 09, 2010 5:51 pm

Re: New OpenGL classes

Postby OBO » Fri Mar 30, 2012 5:31 pm

Awesome work Jules.

Still crash though on intel series-4 integrated (two year old) systems, where the driver doesnt support some ogl extensions.
OBO
JUCE Obsessive
 
Posts: 85
Joined: Fri Sep 18, 2009 8:09 pm

Re: New OpenGL classes

Postby justin » Fri Mar 30, 2012 5:39 pm

Great work!

(Mac OS 10.6 NVIDIA GeForce 9400)
User avatar
justin
JUCE UberWeenie
 
Posts: 297
Joined: Mon May 19, 2008 1:37 pm
Location: Canada

Re: New OpenGL classes

Postby jfitzpat » Fri Mar 30, 2012 6:22 pm

Very cool!

Quick test on a MacBook pro, first running OS X 10.7, then bootcamp'ed to Windows 7 32 bit both looked good.

I'll try Android and iOS on devices soon.
User avatar
jfitzpat
JUCE UberWeenie
 
Posts: 251
Joined: Tue Jan 10, 2012 6:29 am
Location: Glendale, California

Re: New OpenGL classes

Postby steffen » Fri Mar 30, 2012 6:26 pm

Amazing job! I couldn't spot any difference in the rendering demos when switching to the OpenGL rendering, and all rendering times seem to decrease significantly (as long as I don't enable clipping).

Win 7 64bit / Geforce 8400 GT
steffen
JUCE UberWeenie
 
Posts: 140
Joined: Tue May 04, 2010 11:52 am

Re: New OpenGL classes

Postby TheVinn » Fri Mar 30, 2012 6:47 pm

I'm a little confused. Will this benefit my application's main window if I use it? Or do I need to draw in 3D or something?
Open Source: LayerEffects, VFLib, SimpleDJ, DSP Filters, LuaBridge, JUCE, FreeType, TagLib
"This isn't a big project, it shouldn't take long." - Jules
User avatar
TheVinn
JUCE UberWeenie
 
Posts: 2990
Joined: Sat Aug 29, 2009 11:31 am
Location: Marina del Rey, California

Re: New OpenGL classes

Postby steffen » Fri Mar 30, 2012 8:18 pm

TheVinn wrote:Will this benefit my application's main window if I use it?


If I understand the demo code correctly, all you have to do is attach an OpenGLContext to your top-level component, and all your child component will paint into a Graphics context that will use OpenGL instead of the software renderer. Especially rendering scaled images is *a lot faster* in the demo then.

Or do I need to draw in 3D or something?

You don't have to, but if you want to use plain OpenGL code to render something special in 2d or 3d, you can now add standard child components on top (which wasn't possible before with the OpenGLComponent)
steffen
JUCE UberWeenie
 
Posts: 140
Joined: Tue May 04, 2010 11:52 am

Re: New OpenGL classes

Postby Steven » Sat Mar 31, 2012 3:18 am

This is pretty cool. Haven't tried it on Android devices yet, but I am having some problems getting it to deploy on iOS 5.0.1 on an iPad 1. I get the following error if I run it through XCode:

Code: Select all
JUCE Assertion failure in juce/extras/JuceDemo/Builds/iOS/../../../../modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp, line 2949
Last edited by Steven on Sun Apr 01, 2012 12:25 pm, edited 1 time in total.
Steven
JUCE Weenie
 
Posts: 9
Joined: Thu Mar 15, 2012 5:05 pm

Re: New OpenGL classes

Postby Xavi » Sat Mar 31, 2012 4:29 am

I've compiled the demo in Win XP Pro and it crashes. There's a problem rendering the title bar.
Run the app, click "Use OpenGL renderer" and move the window around, it crashes in a couple of secs.

"Unhandled exception at 0x009dc7a7 in JuceDemo.exe: 0xC0000005: Access violation writing location 0x987e9100."

Call stack:

JuceDemo.exe!juce::PixelARGB::set<juce::PixelARGB>(const juce::PixelARGB & src) Line 159 + 0xb bytes C++
JuceDemo.exe!juce::SoftwareRendererClasses::SolidColourEdgeTableRenderer<juce::PixelARGB,0>::replaceLine(juce::PixelARGB * dest, const juce::PixelARGB & colour, int width) Line 167 C++
JuceDemo.exe!juce::SoftwareRendererClasses::SolidColourEdgeTableRenderer<juce::PixelARGB,0>::handleEdgeTableLineFull(const int x, const int width) Line 99 C++
JuceDemo.exe!juce::SoftwareRendererClasses::ClipRegion_RectangleList::SubRectangleIterator::iterate<juce::SoftwareRendererClasses::SolidColourEdgeTableRenderer<juce::PixelARGB,0> >(juce::SoftwareRendererClasses::SolidColourEdgeTableRenderer<juce::PixelARGB,0> & r) Line 1577 C++
JuceDemo.exe!juce::SoftwareRendererClasses::ClipRegionBase::renderSolidFill<juce::SoftwareRendererClasses::ClipRegion_RectangleList::SubRectangleIterator,juce::PixelARGB>(juce::SoftwareRendererClasses::ClipRegion_RectangleList::SubRectangleIterator & iter, const juce::Image::BitmapData & destData, const juce::PixelARGB & fillColour, const bool replaceContents, juce::PixelARGB * __formal) Line 1163 C++
JuceDemo.exe!juce::SoftwareRendererClasses::ClipRegion_RectangleList::fillRectWithColour(juce::Image::BitmapData & destData, const juce::Rectangle<int> & area, const juce::PixelARGB & colour, bool replaceContents) Line 1472 + 0x18 bytes C++
JuceDemo.exe!juce::LowLevelGraphicsSoftwareRenderer::SavedState::fillRect(const juce::Rectangle<int> & r, const bool replaceContents) Line 1868 + 0x8f bytes C++
JuceDemo.exe!juce::LowLevelGraphicsSoftwareRenderer::fillRect(const juce::Rectangle<int> & r, const bool replaceExistingContents) Line 2177 C++
JuceDemo.exe!juce::Graphics::fillAll(const juce::Colour & colourToUse) Line 369 C++
JuceDemo.exe!ContentComp::paint(juce::Graphics & g) Line 55 C++
JuceDemo.exe!juce::Component::paintComponentAndChildren(juce::Graphics & g) Line 1880 C++
JuceDemo.exe!juce::Component::paintEntireComponent(juce::Graphics & g, const bool ignoreAlphaLevel) Line 1968 C++
JuceDemo.exe!juce::ComponentPeer::handlePaint(juce::LowLevelGraphicsContext & contextToPaintTo) Line 135 C++
JuceDemo.exe!juce::HWNDComponentPeer::handlePaintMessage() Line 1487 C++
> JuceDemo.exe!juce::HWNDComponentPeer::peerWindowProc(HWND__ * h, unsigned int message, unsigned int wParam, long lParam) Line 2156 C++
JuceDemo.exe!juce::HWNDComponentPeer::windowProc(HWND__ * h, unsigned int message, unsigned int wParam, long lParam) Line 2102 + 0x18 bytes C++
user32.dll!7e398734()
[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]
user32.dll!7e398816()
user32.dll!7e3aa013()
user32.dll!7e3aa039()
opengl32.dll!5f14699b()
user32.dll!7e398734()
user32.dll!7e3abdf1()
user32.dll!7e3a8ea0()
user32.dll!7e3a8eec()
ntdll.dll!7c91e453()
user32.dll!7e3a99ff()
JuceDemo.exe!juce::HWNDComponentPeer::setPosition(int x, int y) Line 550 C++
JuceDemo.exe!juce::FlacNamespace::add_subframe_(juce::FlacNamespace::FLAC__StreamEncoder * encoder, unsigned int blocksize, unsigned int subframe_bps, const juce::FlacNamespace::FLAC__Subframe * subframe, juce::FlacNamespace::FLAC__BitWriter * frame) Line 3424 + 0x8 bytes C++
Xavi
JUCE Geek
 
Posts: 38
Joined: Tue Aug 30, 2011 5:59 pm

Re: New OpenGL classes

Postby jules » Sat Mar 31, 2012 9:20 am

Thanks folks!

Steven wrote:
Code: Select all
JUCE Assertion failure in /Users/spease/Documents/Projects/juce/extras/JuceDemo/Builds/iOS/../../../../modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp, line 2949


Erm.. That file only contain 2200 lines, I think you may need to sort out your version!

OBO wrote:Still crash though on intel series-4 integrated (two year old) systems, where the driver doesnt support some ogl extensions

Yes, I think I still need to sort out a few edge-cases.. Which extension in particular is failing?

I've compiled the demo in Win XP Pro and it crashes. There's a problem rendering the title bar.


That stack trace is from the fallback renderer, because your machine doesn't support shaders.. Thanks, I'll do a bit more testing of that code-path, (I've obviously been concentrating on getting shader stuff working)
User avatar
jules
Fearless Leader
 
Posts: 17380
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: New OpenGL classes

Postby Steven » Sun Apr 01, 2012 12:24 pm

You're right - I accidentally built from the wrong juce folder. I can't test it now, but if you don't hear anything further then you can assume that was the only issue. :)
Steven
JUCE Weenie
 
Posts: 9
Joined: Thu Mar 15, 2012 5:05 pm

Re: New OpenGL classes

Postby yairadix » Mon Apr 02, 2012 1:12 am

The new OpenGL classes don't seem to work with OS X 10.5 (tested only on ppc but I believe it's the same on intel, my intel machines have newer oses..).

The reason is that OS X 10.5 (and I believe 10.6 < 10.6.3) doesn't support OpenGL 3 functions such as glBindRenderbuffer. Instead, one needs to call an (afaik) identical function suffixed with EXT, such as glBindRenderbufferEXT.

I sent you a pull request for the fix at https://github.com/julianstorer/JUCE/pull/2
(btw congrats for the github move)
Cheers, Yair.
User avatar
yairadix
JUCE UberWeenie
 
Posts: 131
Joined: Fri Jul 23, 2010 10:38 pm

Re: New OpenGL classes

Postby TheVinn » Mon Apr 02, 2012 1:30 am

yairadix wrote:I sent you a pull request for the fix at https://github.com/julianstorer/JUCE/pull/2


Jules said no to accepting pull requests via github. Which is a little bit disappointing...
Open Source: LayerEffects, VFLib, SimpleDJ, DSP Filters, LuaBridge, JUCE, FreeType, TagLib
"This isn't a big project, it shouldn't take long." - Jules
User avatar
TheVinn
JUCE UberWeenie
 
Posts: 2990
Joined: Sat Aug 29, 2009 11:31 am
Location: Marina del Rey, California

Re: New OpenGL classes

Postby jules » Mon Apr 02, 2012 10:12 am

I'm not going to use any pull requests directly, but I will take a look at the diff so I can see what you've done, and will fix up the 10.5 calls, so thanks!
User avatar
jules
Fearless Leader
 
Posts: 17380
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Next

Return to General JUCE discussion

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 4 guests