use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.
the class JoglContext method initContextFirstTime.
protected void initContextFirstTime() {
if (GLContext.getCurrent().getGLVersionNumber().getMajor() < 2) {
throw new RendererException("OpenGL 2.0 or higher is " + "required for jMonkeyEngine");
}
if (settings.getRenderer().startsWith("JOGL")) {
com.jme3.renderer.opengl.GL gl = new JoglGL();
GLExt glext = new JoglGLExt();
GLFbo glfbo = new JoglGLFbo();
if (settings.getBoolean("GraphicsDebug")) {
gl = new GLDebugDesktop(gl, glext, glfbo);
glext = (GLExt) gl;
glfbo = (GLFbo) gl;
}
if (settings.getBoolean("GraphicsTiming")) {
GLTimingState timingState = new GLTimingState();
gl = (com.jme3.renderer.opengl.GL) GLTiming.createGLTiming(gl, timingState, GL.class, GL2.class, GL3.class, GL4.class);
glext = (GLExt) GLTiming.createGLTiming(glext, timingState, GLExt.class);
glfbo = (GLFbo) GLTiming.createGLTiming(glfbo, timingState, GLFbo.class);
}
if (settings.getBoolean("GraphicsTrace")) {
gl = (com.jme3.renderer.opengl.GL) GLTracer.createDesktopGlTracer(gl, GL.class, GL2.class, GL3.class, GL4.class);
glext = (GLExt) GLTracer.createDesktopGlTracer(glext, GLExt.class);
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class);
}
renderer = new GLRenderer(gl, glext, glfbo);
renderer.initialize();
} else {
throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer());
}
if (GLContext.getCurrentGL().isExtensionAvailable("GL_ARB_debug_output") && settings.getBoolean("GraphicsDebug")) {
GLContext.getCurrent().enableGLDebugMessage(true);
GLContext.getCurrent().addGLDebugListener(new JoglGLDebugOutputHandler());
}
renderer.setMainFrameBufferSrgb(settings.isGammaCorrection());
renderer.setLinearizeSrgbImages(settings.isGammaCorrection());
// Init input
if (keyInput != null) {
keyInput.initialize();
}
if (mouseInput != null) {
mouseInput.initialize();
}
if (joyInput != null) {
joyInput.initialize();
}
if (settings.isOpenCLSupport()) {
initOpenCL();
}
}
use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.
the class JmeBatchRenderBackend method beginFrame.
@Override
public void beginFrame() {
log.fine("beginFrame()");
for (int i = 0; i < batches.size(); i++) {
batchPool.free(batches.get(i));
}
batches.clear();
// in case we have pending modifyTexture calls we'll need to execute them now
if (!modifyTextureCalls.isEmpty()) {
Renderer renderer = display.getRenderer();
for (int i = 0; i < modifyTextureCalls.size(); i++) {
modifyTextureCalls.get(i).execute(renderer);
}
modifyTextureCalls.clear();
}
}
use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method syncScreenProcessing.
/**
* Sets the two views to use the list of {@link SceneProcessor processors}.
* @param sourceViewport the {@link ViewPort viewport} that contains the processors to use.
*/
public void syncScreenProcessing(ViewPort sourceViewport) {
if (rightViewport == null) {
return;
}
if (environment != null) {
if (environment.getApplication() != null) {
// setup post processing filters
if (rightPostProcessor == null) {
rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
leftPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
}
// clear out all filters & processors, to start from scratch
rightPostProcessor.removeAllFilters();
leftPostProcessor.removeAllFilters();
leftViewport.clearProcessors();
rightViewport.clearProcessors();
// if we have no processors to sync, don't add the FilterPostProcessor
if (sourceViewport.getProcessors().isEmpty())
return;
// add post processors we just made, which are empty
leftViewport.addProcessor(leftPostProcessor);
rightViewport.addProcessor(rightPostProcessor);
// add them to the left viewport processor & clone them to the right
for (SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
if (sceneProcessor instanceof FilterPostProcessor) {
for (Filter f : ((FilterPostProcessor) sceneProcessor).getFilterList()) {
if (f instanceof TranslucentBucketFilter) {
// just remove this filter, we will add it at the end manually
((FilterPostProcessor) sceneProcessor).removeFilter(f);
} else {
leftPostProcessor.addFilter(f);
// clone to the right
Filter f2;
if (f instanceof FogFilter) {
f2 = FilterUtil.cloneFogFilter((FogFilter) f);
} else if (f instanceof CartoonSSAO) {
f2 = new CartoonSSAO((CartoonSSAO) f);
} else if (f instanceof SSAOFilter) {
f2 = FilterUtil.cloneSSAOFilter((SSAOFilter) f);
} else if (f instanceof DirectionalLightShadowFilter) {
f2 = FilterUtil.cloneDirectionalLightShadowFilter(environment.getApplication().getAssetManager(), (DirectionalLightShadowFilter) f);
} else {
// dof, bloom, lightscattering etc.
f2 = f;
}
rightPostProcessor.addFilter(f2);
}
}
} else if (sceneProcessor instanceof VRDirectionalLightShadowRenderer) {
// shadow processing
// TODO: make right shadow processor use same left shadow maps for performance
VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
dlsrRight.setLight(dlsr.getLight());
rightViewport.getProcessors().add(0, dlsrRight);
leftViewport.getProcessors().add(0, sceneProcessor);
}
}
// make sure each has a translucent filter renderer
leftPostProcessor.addFilter(new TranslucentBucketFilter());
rightPostProcessor.addFilter(new TranslucentBucketFilter());
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.
the class VRApplication method start.
@Override
public void start() {
logger.config("Starting application...");
// set some default settings in-case
// settings dialog is not shown
boolean loadSettings = false;
if (settings == null) {
setSettings(new AppSettings(true));
loadSettings = true;
}
GraphicsDevice defDev = null;
try {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
defDev = ge.getDefaultScreenDevice();
} catch (Throwable e1) {
logger.log(Level.SEVERE, "Cannot access default screen device: " + e1.getMessage(), e1);
}
if (isInVR() && !compositorAllowed()) {
logger.warning("VR Composition is not allowed.");
// "easy extended" mode
// TO-DO: JFrame was removed in LWJGL 3, need to use new GLFW library to pick "monitor" display of VR device
// first, find the VR device
GraphicsDevice VRdev = null;
GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
// pick the display that isn't the default one
for (GraphicsDevice gd : devs) {
if (gd != defDev) {
VRdev = gd;
break;
}
}
// did we get the VR device?
if (VRdev != null) {
// set properties for VR acceleration
try {
java.awt.DisplayMode useDM = null;
int max = 0;
for (java.awt.DisplayMode dm : VRdev.getDisplayModes()) {
int check = dm.getHeight() + dm.getWidth() + dm.getRefreshRate() + dm.getBitDepth();
if (check > max) {
max = check;
useDM = dm;
}
}
// create a window for the VR device
settings.setWidth(useDM.getWidth());
settings.setHeight(useDM.getHeight());
settings.setBitsPerPixel(useDM.getBitDepth());
settings.setFrequency(useDM.getRefreshRate());
settings.setSwapBuffers(true);
// allow vsync on this display
settings.setVSync(true);
setSettings(settings);
// make sure we are in the right display mode
if (VRdev.getDisplayMode().equals(useDM) == false) {
VRdev.setDisplayMode(useDM);
}
// make a blank cursor to hide it
//BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
//Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
//VRwindow.setCursor(blankCursor);
//jmeCanvas.getCanvas().setCursor(blankCursor);
//VRwindow.pack();
//VRwindow.setVisible(true);
//startCanvas();
logger.config("Starting application [SUCCESS]");
return;
} catch (Exception e) {
logger.log(Level.SEVERE, "Error during application start: " + e.getMessage(), e);
}
}
}
if (!isInVR()) {
logger.config("VR mode disabled.");
// not in VR, show settings dialog
if (Platform.get() != Platform.MACOSX) {
if (!JmeSystem.showSettingsDialog(settings, loadSettings)) {
logger.config("Starting application [SUCCESS]");
return;
}
} else {
// GLFW workaround on macs
settings.setFrequency(defDev.getDisplayMode().getRefreshRate());
settings.setDepthBits(24);
settings.setVSync(true);
// try and read resolution from file in local dir
File resfile = new File("resolution.txt");
if (resfile.exists()) {
try {
BufferedReader br = new BufferedReader(new FileReader(resfile));
settings.setWidth(Integer.parseInt(br.readLine()));
settings.setHeight(Integer.parseInt(br.readLine()));
try {
settings.setFullscreen(br.readLine().toLowerCase(Locale.ENGLISH).contains("full"));
} catch (Exception e) {
settings.setFullscreen(false);
}
br.close();
} catch (Exception e) {
settings.setWidth(1280);
settings.setHeight(720);
}
} else {
settings.setWidth(1280);
settings.setHeight(720);
settings.setFullscreen(false);
}
settings.setResizable(false);
}
settings.setSwapBuffers(true);
} else {
logger.config("VR mode enabled.");
// use basic mirroring window, skip settings window
settings.setWidth(xWin);
settings.setHeight(yWin);
settings.setBitsPerPixel(24);
// never sleep in main loop
settings.setFrameRate(0);
settings.setFrequency(VRhardware.getDisplayFrequency());
settings.setFullscreen(false);
// stop vsyncing on primary monitor!
settings.setVSync(false);
settings.setSwapBuffers(!disableSwapBuffers || VRhardware instanceof OSVR);
settings.setTitle("Put Headset On Now: " + settings.getTitle());
settings.setResizable(true);
}
if (forceDisableMSAA) {
logger.config("Disabling multisampling.");
// disable multisampling, which is more likely to break things than be useful
settings.setSamples(1);
}
// set opengl mode
if (tryOpenGL3) {
logger.config("Using LWJGL OpenGL 3 renderer.");
settings.setRenderer(AppSettings.LWJGL_OPENGL3);
} else {
logger.config("Using LWJGL OpenGL 2 renderer.");
settings.setRenderer(AppSettings.LWJGL_OPENGL2);
}
setSettings(settings);
start(JmeContext.Type.Display, false);
// disable annoying warnings about GUI stuff being updated, which is normal behavior
// for late GUI placement for VR purposes
Logger.getLogger("com.jme3").setLevel(Level.SEVERE);
}
use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.
the class LwjglContextVR method initContextFirstTime.
protected void initContextFirstTime() {
final GLCapabilities capabilities = createCapabilities(settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3));
if (!capabilities.OpenGL20) {
throw new RendererException("OpenGL 2.0 or higher is required for jMonkeyEngine");
}
if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL2) || settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) {
GL gl = new LwjglGL();
GLExt glext = new LwjglGLExt();
GLFbo glfbo;
if (capabilities.OpenGL30) {
glfbo = new LwjglGLFboGL3();
} else {
glfbo = new LwjglGLFboEXT();
}
if (settings.getBoolean("GraphicsDebug")) {
gl = new GLDebugDesktop(gl, glext, glfbo);
glext = (GLExt) gl;
glfbo = (GLFbo) gl;
}
if (settings.getBoolean("GraphicsTiming")) {
GLTimingState timingState = new GLTimingState();
gl = (GL) GLTiming.createGLTiming(gl, timingState, GL.class, GL2.class, GL3.class, GL4.class);
glext = (GLExt) GLTiming.createGLTiming(glext, timingState, GLExt.class);
glfbo = (GLFbo) GLTiming.createGLTiming(glfbo, timingState, GLFbo.class);
}
if (settings.getBoolean("GraphicsTrace")) {
gl = (GL) GLTracer.createDesktopGlTracer(gl, GL.class, GL2.class, GL3.class, GL4.class);
glext = (GLExt) GLTracer.createDesktopGlTracer(glext, GLExt.class);
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class);
}
renderer = new GLRenderer(gl, glext, glfbo);
renderer.initialize();
} else {
throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer());
}
if (capabilities.GL_ARB_debug_output && settings.getBoolean("GraphicsDebug")) {
ARBDebugOutput.glDebugMessageCallbackARB(new LwjglGLDebugOutputHandler(), 0);
}
renderer.setMainFrameBufferSrgb(settings.isGammaCorrection());
renderer.setLinearizeSrgbImages(settings.isGammaCorrection());
// Init input
if (keyInput != null) {
keyInput.initialize();
}
if (mouseInput != null) {
mouseInput.initialize();
}
if (joyInput != null) {
joyInput.initialize();
}
renderable.set(true);
}
Aggregations