Search in sources :

Example 21 with FrameBuffer

use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method updateRenderTexture.

public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
    Texture tex = rb.getTexture();
    Image image = tex.getImage();
    if (image.isUpdateNeeded()) {
        // Check NPOT requirements
        checkNonPowerOfTwo(tex);
        updateTexImageData(image, tex.getType(), 0, false);
        // NOTE: For depth textures, sets nearest/no-mips mode
        // Required to fix "framebuffer unsupported"
        // for old NVIDIA drivers!
        setupTextureParams(0, tex);
    }
    if (rb.getLayer() < 0) {
        glfbo.glFramebufferTexture2DEXT(GLFbo.GL_FRAMEBUFFER_EXT, convertAttachmentSlot(rb.getSlot()), convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()), image.getId(), 0);
    } else {
        gl3.glFramebufferTextureLayer(GLFbo.GL_FRAMEBUFFER_EXT, convertAttachmentSlot(rb.getSlot()), image.getId(), 0, rb.getLayer());
    }
}
Also used : Image(com.jme3.texture.Image) Texture(com.jme3.texture.Texture)

Example 22 with FrameBuffer

use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method setReadDrawBuffers.

public void setReadDrawBuffers(FrameBuffer fb) {
    if (gl2 == null) {
        return;
    }
    final int NONE = -2;
    final int INITIAL = -1;
    final int MRT_OFF = 100;
    if (fb == null) {
        // Set Read/Draw buffers to initial value.
        if (context.boundDrawBuf != INITIAL) {
            gl2.glDrawBuffer(context.initialDrawBuf);
            context.boundDrawBuf = INITIAL;
        }
        if (context.boundReadBuf != INITIAL) {
            gl2.glReadBuffer(context.initialReadBuf);
            context.boundReadBuf = INITIAL;
        }
    } else {
        if (fb.getNumColorBuffers() == 0) {
            // no color buffer attached.
            if (context.boundDrawBuf != NONE) {
                gl2.glDrawBuffer(GL.GL_NONE);
                context.boundDrawBuf = NONE;
            }
            if (context.boundReadBuf != NONE) {
                gl2.glReadBuffer(GL.GL_NONE);
                context.boundReadBuf = NONE;
            }
        } else {
            if (fb.getNumColorBuffers() > limits.get(Limits.FrameBufferAttachments)) {
                throw new RendererException("Framebuffer has more color " + "attachments than are supported" + " by the video hardware!");
            }
            if (fb.isMultiTarget()) {
                if (!caps.contains(Caps.FrameBufferMRT)) {
                    throw new RendererException("Multiple render targets " + " are not supported by the video hardware");
                }
                if (fb.getNumColorBuffers() > limits.get(Limits.FrameBufferMrtAttachments)) {
                    throw new RendererException("Framebuffer has more" + " multi targets than are supported" + " by the video hardware!");
                }
                intBuf16.clear();
                for (int i = 0; i < fb.getNumColorBuffers(); i++) {
                    intBuf16.put(GLFbo.GL_COLOR_ATTACHMENT0_EXT + i);
                }
                intBuf16.flip();
                glext.glDrawBuffers(intBuf16);
                context.boundDrawBuf = MRT_OFF + fb.getNumColorBuffers();
            } else {
                RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex());
                // select this draw buffer
                if (context.boundDrawBuf != rb.getSlot()) {
                    gl2.glDrawBuffer(GLFbo.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
                    context.boundDrawBuf = rb.getSlot();
                }
            }
        }
    }
}
Also used : RenderBuffer(com.jme3.texture.FrameBuffer.RenderBuffer)

Example 23 with FrameBuffer

use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method updateFrameBuffer.

public void updateFrameBuffer(FrameBuffer fb) {
    if (fb.getNumColorBuffers() == 0 && fb.getDepthBuffer() == null) {
        throw new IllegalArgumentException("The framebuffer: " + fb + "\nDoesn't have any color/depth buffers");
    }
    int id = fb.getId();
    if (id == -1) {
        glfbo.glGenFramebuffersEXT(intBuf1);
        id = intBuf1.get(0);
        fb.setId(id);
        objManager.registerObject(fb);
        statistics.onNewFrameBuffer();
    }
    bindFrameBuffer(fb);
    FrameBuffer.RenderBuffer depthBuf = fb.getDepthBuffer();
    if (depthBuf != null) {
        updateFrameBufferAttachment(fb, depthBuf);
    }
    for (int i = 0; i < fb.getNumColorBuffers(); i++) {
        FrameBuffer.RenderBuffer colorBuf = fb.getColorBuffer(i);
        updateFrameBufferAttachment(fb, colorBuf);
    }
    setReadDrawBuffers(fb);
    checkFrameBufferError();
    fb.clearUpdateNeeded();
}
Also used : FrameBuffer(com.jme3.texture.FrameBuffer) RenderBuffer(com.jme3.texture.FrameBuffer.RenderBuffer)

Example 24 with FrameBuffer

use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.

the class AwtPanel method reshapeInThread.

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);
        // Main framebuffer should use RenderManager.notifyReshape().
        for (SceneProcessor sp : vp.getProcessors()) {
            sp.reshape(vp, width, height);
        }
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) ViewPort(com.jme3.renderer.ViewPort) FrameBuffer(com.jme3.texture.FrameBuffer) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp) SceneProcessor(com.jme3.post.SceneProcessor)

Example 25 with FrameBuffer

use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.

the class TestRenderToCubemap method setupOffscreenView.

public Texture setupOffscreenView() {
    Camera offCamera = new Camera(512, 512);
    offView = renderManager.createPreView("Offscreen View", offCamera);
    offView.setClearFlags(true, true, true);
    offView.setBackgroundColor(ColorRGBA.DarkGray);
    // create offscreen framebuffer
    FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);
    //setup framebuffer's cam
    offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
    offCamera.setLocation(new Vector3f(0f, 0f, -5f));
    offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
    //setup framebuffer's texture
    TextureCubeMap offTex = new TextureCubeMap(512, 512, Format.RGBA8);
    offTex.setMinFilter(Texture.MinFilter.Trilinear);
    offTex.setMagFilter(Texture.MagFilter.Bilinear);
    //setup framebuffer to use texture
    offBuffer.setDepthBuffer(Format.Depth);
    offBuffer.setMultiTarget(true);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeX);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveX);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeY);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveY);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeZ);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveZ);
    //set viewport to render to offscreen framebuffer
    offView.setOutputFrameBuffer(offBuffer);
    // setup framebuffer's scene
    Box boxMesh = new Box(1, 1, 1);
    Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
    offBox = new Geometry("box", boxMesh);
    offBox.setMaterial(material);
    // attach the scene to the viewport to be rendered
    offView.attachScene(offBox);
    return offTex;
}
Also used : Geometry(com.jme3.scene.Geometry) Vector3f(com.jme3.math.Vector3f) TextureCubeMap(com.jme3.texture.TextureCubeMap) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) FrameBuffer(com.jme3.texture.FrameBuffer)

Aggregations

FrameBuffer (com.jme3.texture.FrameBuffer)23 Texture2D (com.jme3.texture.Texture2D)18 Material (com.jme3.material.Material)12 Camera (com.jme3.renderer.Camera)10 ViewPort (com.jme3.renderer.ViewPort)7 Geometry (com.jme3.scene.Geometry)7 Picture (com.jme3.ui.Picture)5 Vector3f (com.jme3.math.Vector3f)4 Box (com.jme3.scene.shape.Box)4 RenderBuffer (com.jme3.texture.FrameBuffer.RenderBuffer)4 Spatial (com.jme3.scene.Spatial)3 Matrix4f (com.jme3.math.Matrix4f)2 SceneProcessor (com.jme3.post.SceneProcessor)2 Sphere (com.jme3.scene.shape.Sphere)2 Texture (com.jme3.texture.Texture)2 ActionListener (com.jme3.input.controls.ActionListener)1 KeyTrigger (com.jme3.input.controls.KeyTrigger)1 Quaternion (com.jme3.math.Quaternion)1 Vector2f (com.jme3.math.Vector2f)1 NiftyJmeDisplay (com.jme3.niftygui.NiftyJmeDisplay)1