use of com.jogamp.nativewindow.CapabilitiesChooser in project narchy by automenta.
the class NEWTWin method setMode.
/**
* @param dim
* @param mode
* @param fullscreen
* @param driverName
* @return enum Base.rserr_t
*/
public int setMode(GLProfile glp, Dimension dim, int mode, boolean fullscreen, String driverName) {
final Dimension newDim = new Dimension();
VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display for profile " + glp + '\n');
if (null == screen) {
screen = NewtFactory.createScreen(NewtFactory.createDisplay(null), 0);
// trigger native creation
screen.addReference();
} else if (!screen.isNativeValid()) {
// trigger native creation
screen.addReference();
}
if (!VID.GetModeInfo(newDim, mode)) {
VID.Printf(Defines.PRINT_ALL, " invalid mode\n");
return Base.rserr_invalid_mode;
}
VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ", " + newDim.getWidth() + " x " + newDim.getHeight() + ", fs " + fullscreen + ", driver " + driverName + '\n');
// destroy the existing window, not screen
shutdownImpl(false);
if (null != window) {
throw new InternalError("XXX");
}
final GLCapabilities caps = new GLCapabilities(glp);
// default
CapabilitiesChooser chooser = null;
final cvar_t v = Cvar.Get("jogl_rgb565", "0", 0);
if (v.value != 0f) {
caps.setRedBits(5);
caps.setGreenBits(6);
caps.setBlueBits(5);
// don't trust native GL-TK chooser
chooser = new GenericGLCapabilitiesChooser();
}
window = GLWindow.create(screen, caps);
window.setAutoSwapBufferMode(false);
// we do handle QUIT on our own, no GLWindow.display() called.
window.setDefaultCloseOperation(WindowClosingProtocol.WindowClosingMode.DO_NOTHING_ON_CLOSE);
window.setCapabilitiesChooser(chooser);
window.addWindowListener(new WindowAdapter() {
@Override
public void windowDestroyNotify(WindowEvent e) {
// not applet and not already in shutdown ?
shouldQuit = null != window;
}
@Override
public void windowResized(WindowEvent e) {
propagateNewSize();
}
});
window.setTitle("Jake2 (" + driverName + "-newt-" + glp.getName().toLowerCase() + ')');
animCtrl = new GameAnimatorControl();
window.setAnimator(animCtrl);
final MonitorDevice mainMonitor = window.getMainMonitor();
if (oldDisplayMode == null) {
oldDisplayMode = mainMonitor.getCurrentMode();
}
// We need to feed the NEWT Window to the NEWTKBD
NEWTKBD.Init(window);
window.addWindowListener(NEWTKBD.listener);
window.addKeyListener(NEWTKBD.listener);
window.addMouseListener(NEWTKBD.listener);
window.setSize(newDim.getWidth(), newDim.getHeight());
// no display() invocation on other thread!
isAnimating = true;
// if( !fullscreen && Globals.appletMode ) {
// forceReleaseCtx = FORCE_RELEASE_CTX_VAL;
//
// // Notify the size listener about the change
// final SizeChangeListener listener = Globals.sizeChangeListener;
// if (listener != null) {
// listener.sizeChanged(newDim.getWidth(), newDim.getHeight());
// }
// window.addKeyListener( new ReparentKeyListener() );
//
// final NativeSurface NativeSurface = NewtFactory.createWindow(window);
// final java.applet.Applet applet = (java.applet.Applet) Globals.applet;
// final Runnable appletAddAction = () -> {
// applet.add(NativeSurface, java.awt.BorderLayout.CENTER);
// applet.validate();
// NativeSurface.setFocusable(true);
// NativeSurface.requestFocus();
// if( Platform.OSType.MACOS == Platform.getOSType() && NativeSurface.isOffscreenLayerSurfaceEnabled() ) {
// System.err.println("XXX Relayout");
// // force relayout
// final int cW = NativeSurface.getWidth();
// final int cH = NativeSurface.getHeight();
// NativeSurface.setSize(cW+1, cH+1);
// NativeSurface.setSize(cW, cH);
// }
// };
// if( java.awt.EventQueue.isDispatchThread() ) {
// System.err.println("XXX Adding on AWT EDT - same thread");
// appletAddAction.run();
// } else {
// System.err.println("XXX Adding on AWT EDT - off thread");
// try {
// java.awt.EventQueue.invokeAndWait(appletAddAction);
// } catch (Exception e) {
// throw new RuntimeException("NEWT Exception during NativeSurface on AWT-EDT", e);
// }
// }
// canvasObj = NativeSurface;
// int w=0;
// while ( w<10 && !window.isNativeValid()|| !window.isRealized() ) {
// w++;
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {}
// }
// System.err.println("XXX waited = "+w+" * 100 ms");
// } else {
forceReleaseCtx = false;
canvasObj = null;
if (fullscreen) {
MonitorMode mm = findDisplayMode(newDim);
final DimensionImmutable smDim = mm.getSurfaceSize().getResolution();
newDim.setWidth(smDim.getWidth());
newDim.setHeight(smDim.getHeight());
mainMonitor.setCurrentMode(mm);
VID.Printf(Defines.PRINT_ALL, "...MonitorMode " + mm + '\n');
window.setFullscreen(true);
}
window.setVisible(true);
window.requestFocus();
if (!window.isNativeValid() || !window.isRealized()) {
throw new RuntimeException("NEWT window didn't not realize: " + window);
}
// force GL creation
window.display();
final GLContext ctx = window.getContext();
if (!ctx.isCreated()) {
System.err.println("Warning: GL context not created: " + ctx);
}
if (ctx.isCurrent()) {
throw new RuntimeException("NEWT GL context still current: " + ctx);
}
VID.Printf(Defines.PRINT_ALL, "...reques GLCaps " + window.getRequestedCapabilities() + '\n');
VID.Printf(Defines.PRINT_ALL, "...chosen GLCaps " + window.getChosenGLCapabilities() + '\n');
VID.Printf(Defines.PRINT_ALL, "...size " + window.getWidth() + " x " + window.getHeight() + '\n');
// propagateNewSize("init");
activateGLContext(true);
return Base.rserr_ok;
}
Aggregations