41package com.jogamp.opengl;
43import java.util.ArrayList;
46import com.jogamp.common.os.Platform;
47import com.jogamp.common.util.PropertyAccess;
48import com.jogamp.common.util.ReflectionUtil;
49import com.jogamp.opengl.GLAutoDrawableDelegate;
50import com.jogamp.opengl.GLRendererQuirks;
52import com.jogamp.nativewindow.AbstractGraphicsDevice;
53import com.jogamp.nativewindow.AbstractGraphicsScreen;
54import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
55import com.jogamp.nativewindow.CapabilitiesImmutable;
56import com.jogamp.nativewindow.NativeSurface;
57import com.jogamp.nativewindow.NativeWindowFactory;
58import com.jogamp.nativewindow.ProxySurface;
59import com.jogamp.nativewindow.UpstreamSurfaceHook;
61import jogamp.common.os.PlatformPropsImpl;
62import jogamp.opengl.Debug;
101 protected static final boolean DEBUG = Debug.debug(
"GLDrawable");
103 private static volatile boolean isInit =
false;
107 private static ArrayList<GLDrawableFactory> glDrawableFactories =
new ArrayList<GLDrawableFactory>();
122 private static final void initSingletonImpl() {
131 final String nwt = NativeWindowFactory.getNativeWindowType(
true);
133 String factoryClassName = PropertyAccess.getProperty(
"jogl.gldrawablefactory.class.name",
true);
135 if (
null == factoryClassName) {
136 if ( nwt == NativeWindowFactory.TYPE_X11 ) {
137 factoryClassName =
"jogamp.opengl.x11.glx.X11GLXDrawableFactory";
138 }
else if ( nwt == NativeWindowFactory.TYPE_WINDOWS ) {
139 factoryClassName =
"jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory";
140 }
else if ( nwt == NativeWindowFactory.TYPE_MACOSX ) {
141 factoryClassName =
"jogamp.opengl.macosx.cgl.MacOSXCGLDrawableFactory";
142 }
else if ( nwt == NativeWindowFactory.TYPE_IOS ) {
143 factoryClassName =
"jogamp.opengl.ios.eagl.IOSEAGLDrawableFactory";
146 if (
DEBUG || GLProfile.DEBUG) {
147 System.err.println(
"GLDrawableFactory.static - No native Windowing Factory for: "+nwt+
"; May use EGLDrawableFactory, if available." );
151 if ( !GLProfile.disableOpenGLDesktop || GLProfile.disabledEGL ) {
152 if (
null != factoryClassName ) {
153 if (
DEBUG || GLProfile.DEBUG) {
154 System.err.println(
"GLDrawableFactory.static - Native OS Factory for: "+nwt+
": "+factoryClassName);
158 }
catch (
final Exception jre) {
159 if (
DEBUG || GLProfile.DEBUG) {
160 System.err.println(
"Info: GLDrawableFactory.static - Native Platform: "+nwt+
" - not available: "+factoryClassName);
161 jre.printStackTrace();
164 if(
null != tmp && tmp.isComplete()) {
165 nativeOSFactory = tmp;
168 }
else if(
DEBUG || GLProfile.DEBUG ) {
169 System.err.println(
"Info: GLDrawableFactory.static - Desktop GLDrawableFactory unspecified!");
171 }
else if(
DEBUG || GLProfile.DEBUG ) {
172 System.err.println(
"Info: GLDrawableFactory.static - Desktop GLDrawableFactory - disabled!");
175 if(!GLProfile.disableOpenGLES && !GLProfile.disabledEGL) {
177 tmp = (
GLDrawableFactory) ReflectionUtil.createInstance(
"jogamp.opengl.egl.EGLDrawableFactory", cl);
178 }
catch (
final Exception jre) {
179 if (
DEBUG || GLProfile.DEBUG) {
180 System.err.println(
"Info: GLDrawableFactory.static - EGLDrawableFactory - not available");
181 jre.printStackTrace();
184 if(
null != tmp && tmp.isComplete()) {
187 }
else if(
DEBUG || GLProfile.DEBUG ) {
188 System.err.println(
"Info: GLDrawableFactory.static - EGLDrawableFactory - disabled!");
203 private static void shutdown0() {
207 synchronized(glDrawableFactories) {
208 final int gldfCount = glDrawableFactories.size();
210 System.err.println(
"GLDrawableFactory.shutdownAll "+gldfCount+
" instances, on thread "+
getThreadName());
212 for(
int i=0; i<gldfCount; i++) {
215 System.err.println(
"GLDrawableFactory.shutdownAll["+(i+1)+
"/"+gldfCount+
"]: "+gldf.getClass().getName());
218 gldf.resetAllDisplayGammaNoSync();
220 }
catch (
final Throwable t) {
221 System.err.println(
"GLDrawableFactory.shutdownImpl: Caught "+t.getClass().getName()+
" during factory shutdown #"+(i+1)+
"/"+gldfCount+
" "+gldf.getClass().getName());
227 glDrawableFactories.clear();
230 nativeOSFactory =
null;
235 System.err.println(
"GLDrawableFactory.shutdownAll.X on thread "+
getThreadName());
240 synchronized(glDrawableFactories) {
241 glDrawableFactories.add(
this);
245 protected static String
getThreadName() {
return Thread.currentThread().getName(); }
292 public abstract boolean setDisplayGamma(
final NativeSurface surface,
final float gamma,
final float brightness,
final float contrast)
throws IllegalArgumentException;
347 throw new InternalError(
"no default device available");
350 System.err.println(
"Info: "+getClass().getSimpleName()+
".validateDevice: using default device : "+device);
358 System.err.println(
"Info: "+getClass().getSimpleName()+
".validateDevice: device not compatible : "+device);
452 return nativeOSFactory;
484 throw new GLException(
"No GLDrawableFactory available for profile: "+glProfile);
500 if( useNativeGLES ) {
505 return nativeOSFactory;
509 return nativeOSFactory;
522 return nativeOSFactory;
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static synchronized void initSingleton()
Static one time initialization of this factory.
static void addCustomShutdownHook(final boolean head, final Runnable runnable)
Add a custom shutdown hook to be performed at JVM shutdown before shutting down NativeWindowFactory i...
Abstraction for an OpenGL rendering context.
static GLDrawableFactory getFactory(final boolean useNativeGLES)
Returns the sole GLDrawableFactory instance, either for mobile if usesNativeGLES is true,...
void enterThreadCriticalZone()
static GLDrawableFactory getEGLFactory()
Returns the sole GLDrawableFactory instance for EGL if exist or null.
abstract boolean createSharedResourceImpl(AbstractGraphicsDevice device)
abstract boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device)
Returns true if it is possible to create an external GLDrawable object via createExternalGLDrawable.
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable incl it's offscreen NativeSurface with the given capabilit...
abstract boolean hasOpenGLDesktopSupport()
Method returns true if underlying implementation may support native desktop OpenGL,...
abstract boolean hasOpenGLESSupport()
Method returns true if underlying implementation may support native embedded OpenGL ES,...
abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device, GLProfile glp)
Returns true if it is possible to create an pbuffer surface.
abstract boolean getIsDeviceCompatible(AbstractGraphicsDevice device)
static GLDrawableFactory getFactoryImpl(final boolean useNativeGLES)
abstract void resetDisplayGamma(final NativeSurface surface)
Resets the gamma, brightness and contrast values of the display associated with the given surface to ...
abstract GLDrawable createExternalGLDrawable()
final AbstractGraphicsDevice validateDevice(AbstractGraphicsDevice device)
abstract GLDrawable createOffscreenDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates an unrealized offscreen GLDrawable incl it's offscreen NativeSurface with the given capabilit...
abstract GLContext createExternalGLContext()
static String getThreadName()
abstract void shutdownImpl()
final List< GLCapabilitiesImmutable > getAvailableCapabilities(AbstractGraphicsDevice device)
Returns an array of available GLCapabilities for the device.
static GLDrawableFactory getDesktopFactory()
Returns the sole GLDrawableFactory instance for the desktop (X11, WGL, ..) if exist or null.
abstract void resetAllDisplayGammaNoSync()
void leaveThreadCriticalZone()
static final boolean DEBUG
abstract ProxySurface createProxySurface(AbstractGraphicsDevice device, int screenIdx, long windowHandle, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstream)
Creates a proxy NativeSurface w/ defined surface handle, i.e.
abstract AbstractGraphicsDevice getDefaultDevice()
Retrieve the default device connection, unit ID and unique ID name.
static GLDrawableFactory getFactory(final AbstractGraphicsDevice device)
Returns the sole GLDrawableFactory matching the given AbstractGraphicsDevice instance,...
abstract List< GLCapabilitiesImmutable > getAvailableCapabilitiesImpl(AbstractGraphicsDevice device)
static final void initSingleton()
Instantiate singleton factories if available, EGLES1, EGLES2 and the OS native ones.
abstract Thread getSharedResourceThread()
Validate and start the shared resource runner thread if necessary and if the implementation uses it.
abstract GLDrawable createGLDrawable(NativeSurface target)
Returns an unrealized GLDrawable according to it's chosen GLCapabilitiesImmutable,...
abstract GLDrawable createDummyDrawable(AbstractGraphicsDevice deviceReq, boolean createNewDevice, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser)
Creates an unrealized dummy GLDrawable.
final boolean createSharedResource(final AbstractGraphicsDevice device)
Create the shared resource used internally as a reference for capabilities etc.
abstract void resetAllDisplayGamma()
Resets the gamma, brightness and contrast values of all modified displays to their original values be...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
abstract boolean canCreateFBO(AbstractGraphicsDevice device, GLProfile glp)
Returns true if it is possible to create an framebuffer object (FBO).
abstract boolean isComplete()
Returns true if this factory is complete, i.e.
abstract GLAutoDrawable createDummyAutoDrawable(AbstractGraphicsDevice deviceReq, boolean createNewDevice, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser)
Creates a realized dummy GLAutoDrawable incl it's dummy, invisible NativeSurface as created with crea...
final boolean hasRendererQuirk(final AbstractGraphicsDevice device, final GLProfile glp, final int quirk)
Returns true if the quirk exist in the shared resource's context GLRendererQuirks.
static GLDrawableFactory getFactoryImpl(final String glProfileImplName)
abstract GLRendererQuirks getRendererQuirks(AbstractGraphicsDevice device, final GLProfile glp)
Returns the shared resource's context GLRendererQuirks.
abstract boolean setDisplayGamma(final NativeSurface surface, final float gamma, final float brightness, final float contrast)
Sets the gamma, brightness, and contrast of the display associated with the given surface.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
static boolean usesNativeGLES(final String profileImpl)
Indicates whether either of the native OpenGL ES profiles are in use.
static final boolean DEBUG
static void initSingleton()
Static initialization of JOGL.
GLRendererQuirks contains information of known bugs of various GL renderer.
final boolean exist(final int quirkBit)
Method tests whether the given quirk exists.
A interface describing a graphics device in a toolkit-independent manner.
Provides low-level information required for hardware-accelerated rendering using a surface in a platf...
Provides a mutable NativeSurface, i.e.
Interface allowing upstream caller to pass lifecycle actions and size info to a ProxySurface instance...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Provides a mechanism by which applications can customize the window type selection for a given GLCapa...
Specifies an immutable set of OpenGL capabilities.
An abstraction for an OpenGL rendering target.
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.