Java Code Examples for com.jme3.renderer.ViewPort#getProcessors()

The following examples show how to use com.jme3.renderer.ViewPort#getProcessors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AwtPanel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void reshapeInThread(int width, int height) {
        byteBuf = BufferUtils.ensureLargeEnough(byteBuf, width * height * 4);
        intBuf = byteBuf.asIntBuffer();
        
        fb = new FrameBuffer(width, height, 1);
        fb.setDepthBuffer(Format.Depth);
        fb.setColorBuffer(Format.RGB8);
        
        if (attachAsMain){
            rm.getRenderer().setMainFrameBufferOverride(fb);
        }
        
        synchronized (lock){
            img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        }
        
//        synchronized (lock){
//            img = (BufferedImage) getGraphicsConfiguration().createCompatibleImage(width, height);
//        }
        
        AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
        tx.translate(0, -img.getHeight());
        transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        
        for (ViewPort vp : viewPorts){
            if (!attachAsMain){
                vp.setOutputFrameBuffer(fb);
            }
            vp.getCamera().resize(width, height, true);
            
            // NOTE: Hack alert. This is done ONLY for custom framebuffers.
            // Main framebuffer should use RenderManager.notifyReshape().
            for (SceneProcessor sp : vp.getProcessors()){
                sp.reshape(vp, width, height);
            }
        }
    }
 
Example 2
Source File: AwtPanel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void reshapeInThread(int width, int height) {
        byteBuf = BufferUtils.ensureLargeEnough(byteBuf, width * height * 4);
        intBuf = byteBuf.asIntBuffer();

        if (fb != null) {
            fb.dispose();
            fb = null;
        }

        fb = new FrameBuffer(width, height, 1);
        fb.setDepthBuffer(Format.Depth);
        fb.setColorBuffer(Format.RGB8);
        fb.setSrgb(srgb);

        if (attachAsMain) {
            rm.getRenderer().setMainFrameBufferOverride(fb);
        }

        synchronized (lock) {
            img = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
        }

//        synchronized (lock){
//            img = (BufferedImage) getGraphicsConfiguration().createCompatibleImage(width, height);
//        }
        AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
        tx.translate(0, -img.getHeight());
        transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

        for (ViewPort vp : viewPorts) {
            if (!attachAsMain) {
                vp.setOutputFrameBuffer(fb);
            }
            vp.getCamera().resize(width, height, true);

            // NOTE: Hack alert. This is done ONLY for custom framebuffers.
            // Main framebuffer should use RenderManager.notifyReshape().
            for (SceneProcessor sp : vp.getProcessors()) {
                sp.reshape(vp, width, height);
            }
        }
    }
 
Example 3
Source File: AWTFrameProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Reshape the current view port.
 *
 * @param width  the width.
 * @param height the height.
 */
protected void reshapeCurrentViewPort(int width, int height) {

	ViewPort viewPort = getViewPort();
	Camera camera = viewPort.getCamera();
	int cameraAngle = getCameraAngle();
	float aspect = (float) camera.getWidth() / camera.getHeight();

	if (isMain()) {
		getRenderManager().notifyReshape(width, height);
		camera.setFrustumPerspective(cameraAngle, aspect, 1f, 10000);
		return;
	}

	camera.resize(width, height, true);
	camera.setFrustumPerspective(cameraAngle, aspect, 1f, 10000);

	final List<SceneProcessor> processors = viewPort.getProcessors();

	boolean found = false;
	Iterator<SceneProcessor> iter = processors.iterator();
	while(!found && iter.hasNext()) {
		if (!(iter.next() instanceof AWTFrameProcessor)) {
			found = true;
		}
	}

	if (found) {

		FrameBuffer frameBuffer = new FrameBuffer(width, height, 1);
		frameBuffer.setDepthBuffer(Image.Format.Depth);
		frameBuffer.setColorBuffer(Image.Format.RGBA8);
		frameBuffer.setSrgb(true);

		viewPort.setOutputFrameBuffer(frameBuffer);
	}

	for (final SceneProcessor sceneProcessor : processors) {
		if (!sceneProcessor.isInitialized()) {
			sceneProcessor.initialize(renderManager, viewPort);
		} else {
			sceneProcessor.reshape(viewPort, width, height);
		}
	}
}
 
Example 4
Source File: AbstractVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * 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 (environment != null){
		if(  getRightViewPort() == null ){
			return;
		}
		
		if (environment.getApplication() != null){
			// setup post processing filters
            if( getRightPostProcessor() == null ) {
                rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());               
                leftPostProcessor =  new FilterPostProcessor(environment.getApplication().getAssetManager());
            }
            // clear out all filters & processors, to start from scratch
            getRightPostProcessor().removeAllFilters();
            getLeftPostProcessor().removeAllFilters();
            getLeftViewPort().clearProcessors();
            getRightViewPort().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
            getLeftViewPort().addProcessor(getLeftPostProcessor());
            getRightViewPort().addProcessor(getRightPostProcessor());
            // go through all of the filters in the processors list
            // 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 {
                        	getLeftPostProcessor().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 {
                                f2 = f; // dof, bloom, lightscattering etc.
                            }                    
                            getRightPostProcessor().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());
                    getRightViewPort().getProcessors().add(0, dlsrRight);
                    getLeftViewPort().getProcessors().add(0, sceneProcessor);
                }
            }
            // make sure each has a translucent filter renderer
            getLeftPostProcessor().addFilter(new TranslucentBucketFilter());
            getRightPostProcessor().addFilter(new TranslucentBucketFilter());
		} else {
        	throw new IllegalStateException("The VR environment is not attached to any application.");
        }
		
        
	} else {
		throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
	}
	
    
}