com.jme3.renderer.Renderer Java Examples

The following examples show how to use com.jme3.renderer.Renderer. 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: JmeBatchRenderBackend.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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();
    }
}
 
Example #2
Source File: SinglePassLightingLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    int nbRenderedLights = 0;
    Renderer renderer = renderManager.getRenderer();
    int batchSize = renderManager.getSinglePassLightBatchSize();
    if (lights.size() == 0) {
        updateLightListUniforms(shader, geometry, lights, batchSize, renderManager, 0);
        renderer.setShader(shader);
        renderMeshFromGeometry(renderer, geometry);
    } else {
        while (nbRenderedLights < lights.size()) {
            nbRenderedLights = updateLightListUniforms(shader, geometry, lights, batchSize, renderManager, nbRenderedLights);
            renderer.setShader(shader);
            renderMeshFromGeometry(renderer, geometry);
        }
    }
}
 
Example #3
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int applyOverrides(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> overrides, int unit) {
    for (MatParamOverride override : overrides.getArray()) {
        VarType type = override.getVarType();

        MatParam paramDef = def.getMaterialParam(override.getName());

        if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) {
            continue;
        }

        Uniform uniform = shader.getUniform(override.getPrefixedName());

        if (override.getValue() != null) {
            if (type.isTextureType()) {
                renderer.setTexture(unit, (Texture) override.getValue());
                uniform.setValue(VarType.Int, unit);
                unit++;
            } else {
                uniform.setValue(type, override.getValue());
            }
        } else {
            uniform.clearValue();
        }
    }
    return unit;
}
 
Example #4
Source File: PreNormalCaching.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get pre-normals from the given rendering.
 * @param renderManager the render manager.
 * @param normalPass the normal pass.
 * @param viewPort the viewport.
 */
public static void getPreNormals(RenderManager renderManager, Pass normalPass, ViewPort viewPort) {
    curCount++;
    // do we already have a valid cache to set the framebuffer to?
    Renderer r = renderManager.getRenderer();
    if( cachedPreNormals != null ) {
        r.copyFrameBuffer(cachedPreNormals, normalPass.getRenderFrameBuffer(), false);
    } else {
        // lets make the prenormals
        r.setFrameBuffer(normalPass.getRenderFrameBuffer());
        renderManager.getRenderer().clearBuffers(true, true, true);
        if( renderManager.getRenderer().getCaps().contains(Caps.GLSL150) ) {
            renderManager.setForcedTechnique("PreNormalPass15");
        } else {
            renderManager.setForcedTechnique("PreNormalPass");                
        }
        renderManager.renderViewPortQueues(viewPort, false);
        renderManager.setForcedTechnique(null);
        // if we should cache this, do it now
        if( lastNormalPassesCount > 1 ) {
            cachedPreNormals = normalPass.getRenderFrameBuffer();
        }
    }
    renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
}
 
Example #5
Source File: TestFBOPassthrough.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleRender(RenderManager rm){
    Renderer r = rm.getRenderer();

    //do FBO rendering
    r.setFrameBuffer(fb);

    rm.setCamera(cam, false); // FBO uses current camera
    r.clearBuffers(true, true, true);
    rm.renderScene(fbNode, viewPort);
    rm.flushQueue(viewPort);

    //go back to default rendering and let
    //SimpleApplication render the default scene
    r.setFrameBuffer(null);
}
 
Example #6
Source File: HDRRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void renderProcessing(Renderer r, FrameBuffer dst, Material mat){
    if (dst == null){
        fsQuad.setWidth(mainSceneFB.getWidth());
        fsQuad.setHeight(mainSceneFB.getHeight());
        fbCam.resize(mainSceneFB.getWidth(), mainSceneFB.getHeight(), true);
    }else{
        fsQuad.setWidth(dst.getWidth());
        fsQuad.setHeight(dst.getHeight());
        fbCam.resize(dst.getWidth(), dst.getHeight(), true);
    }
    fsQuad.setMaterial(mat);
    fsQuad.updateGeometricState();
    renderManager.setCamera(fbCam, true);

    r.setFrameBuffer(dst);
    r.clearBuffers(true, true, true);
    renderManager.renderGeometry(fsQuad);
}
 
Example #7
Source File: TestFBOPassthrough.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleRender(RenderManager rm){
    Renderer r = rm.getRenderer();

    //do FBO rendering
    r.setFrameBuffer(fb);

    rm.setCamera(cam, false); // FBO uses current camera
    r.clearBuffers(true, true, true);
    rm.renderScene(fbNode, viewPort);
    rm.flushQueue(viewPort);

    //go back to default rendering and let
    //SimpleApplication render the default scene
    r.setFrameBuffer(null);
}
 
Example #8
Source File: JmeBatchRenderBackend.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void modifyTexture(
        final Texture2D textureAtlas,
        final com.jme3.texture.Image image,
        final int x,
        final int y) {
    Renderer renderer = display.getRenderer();
    if (renderer == null) {
        // we have no renderer (yet) so we'll need to cache this call to the next beginFrame() call
        modifyTextureCalls.add(new ModifyTexture(textureAtlas, image, x, y));
        return;
    }

    // all is well, we can execute the modify right away
    renderer.modifyTexture(textureAtlas, image, x, y);
}
 
Example #9
Source File: CartoonEdgeFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void postQueue(RenderQueue queue) {
    Renderer r = renderManager.getRenderer();
    r.setFrameBuffer(normalPass.getRenderFrameBuffer());
    renderManager.getRenderer().clearBuffers(true, true, true);
    renderManager.setForcedTechnique("PreNormalPass");
    renderManager.renderViewPortQueues(viewPort, false);
    renderManager.setForcedTechnique(null);
    renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
}
 
Example #10
Source File: PssmShadowRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void displayShadowMap(Renderer r) {
    Camera cam = viewPort.getCamera();
    renderManager.setCamera(cam, true);
    int h = cam.getHeight();
    for (int i = 0; i < dispPic.length; i++) {
        dispPic[i].setPosition(64 * (i + 1) + 128 * i, h / 20f);
        dispPic[i].setWidth(128);
        dispPic[i].setHeight(128);
        dispPic[i].updateGeometricState();
        renderManager.renderGeometry(dispPic[i]);
    }
    renderManager.setCamera(cam, false);
}
 
Example #11
Source File: MatParam.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void apply(Renderer r, Technique technique, int paramIndex) {
    TechniqueDef techDef = technique.getDef();
    if (techDef.isUsingShaders()) {
        Object value;
        if (multiData != null) {
            value = multiData;
            multiData.clear();
        } else {
            value = getValue();
        }
        technique.updateUniformParam(paramIndex, getVarType(), value, true);
    }
}
 
Example #12
Source File: SSAOFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void postQueue(RenderQueue queue) {
    if(!approximateNormals) {
        Renderer r = renderManager.getRenderer();
        r.setFrameBuffer(normalPass.getRenderFrameBuffer());
        renderManager.getRenderer().clearBuffers(true, true, true);
        renderManager.setForcedTechnique("PreNormalPass");
        renderManager.renderViewPortQueues(viewPort, false);
        renderManager.setForcedTechnique(null);
        renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
    }
}
 
Example #13
Source File: Filter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * cleanup this filter
 * @param r
 */
protected final void cleanup(Renderer r) {
    processor = null;
    if (defaultPass != null) {
        defaultPass.cleanup(r);
    }
    if (postRenderPasses != null) {
        for (Iterator<Pass> it = postRenderPasses.iterator(); it.hasNext();) {
            Pass pass = it.next();
            pass.cleanup(r);
        }
    }
    cleanUpFilter(r);
}
 
Example #14
Source File: HDRRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderToneMap(Renderer r, FrameBuffer out){
    tone.setFloat("A", exposure);
    tone.setFloat("White", whiteLevel);
    tone.setTexture("Lum", scene1[oppSrc]);
    tone.setTexture("Lum2", scene1[curSrc]);
    tone.setFloat("BlendFactor", blendFactor);
    renderProcessing(r, out, tone);
}
 
Example #15
Source File: MatParamTexture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void apply(Renderer r, Technique technique) {
    TechniqueDef techDef = technique.getDef();
    r.setTexture(getUnit(), getTextureValue());
    if (techDef.isUsingShaders()) {
        technique.updateUniformParam(getPrefixedName(), getVarType(), getUnit(), true);
    }
}
 
Example #16
Source File: VideoRecorderAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addImage(Renderer renderer, FrameBuffer out) {
    if (freeItems == null) {
        return;
    }
    try {
        final WorkItem item = freeItems.take();
        usedItems.add(item);
        item.buffer.clear();
        renderer.readFrameBufferWithFormat(out, item.buffer, Image.Format.BGRA8);
        executor.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Screenshots.convertScreenShot(item.buffer, item.image);
                item.data = writer.writeImageToBytes(item.image, quality);
                while (usedItems.peek() != item) {
                    Thread.sleep(1);
                }
                writer.addImage(item.data);
                usedItems.poll();
                freeItems.add(item);
                return null;
            }
        });
    } catch (InterruptedException ex) {
        Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example #17
Source File: TranslucentBucketFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void cleanUpFilter(Renderer r) {
    if (renderManager != null) {
        renderManager.setHandleTranslucentBucket(true);
    }

    initSoftParticles(viewPort, false);
}
 
Example #18
Source File: VideoRecorderAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addImage(Renderer renderer, FrameBuffer out) {
    if (freeItems == null) {
        return;
    }
    try {
        final WorkItem item = freeItems.take();
        usedItems.add(item);
        item.buffer.clear();
        renderer.readFrameBufferWithFormat(out, item.buffer, Image.Format.BGRA8);
        executor.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                if (fastMode) {
                    item.data = item.buffer.array();
                } else {
                    AndroidScreenshots.convertScreenShot(item.buffer, item.image);
                    item.data = writer.writeImageToBytes(item.image, quality);
                }
                while (usedItems.peek() != item) {
                    Thread.sleep(1);
                }
                writer.addImage(item.data);
                usedItems.poll();
                freeItems.add(item);
                return null;
            }
        });
    } catch (InterruptedException ex) {
        Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example #19
Source File: AbstractShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * For debugging purposes, display depth shadow maps.
 */
protected void displayShadowMap(Renderer r) {
    Camera cam = viewPort.getCamera();
    renderManager.setCamera(cam, true);
    int h = cam.getHeight();
    for (int i = 0; i < dispPic.length; i++) {
        dispPic[i].setPosition((128 * i) + (150 + 64 * (i + 1)), h / 20f);
        dispPic[i].setWidth(128);
        dispPic[i].setHeight(128);
        dispPic[i].updateGeometricState();
        renderManager.renderGeometry(dispPic[i]);
    }
    renderManager.setCamera(cam, false);
}
 
Example #20
Source File: SSAOFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void postQueue(RenderQueue queue) {
    Renderer r = renderManager.getRenderer();
    r.setFrameBuffer(normalPass.getRenderFrameBuffer());
    renderManager.getRenderer().clearBuffers(true, true, true);
    renderManager.setForcedTechnique("PreNormalPass");
    renderManager.renderViewPortQueues(viewPort, false);
    renderManager.setForcedTechnique(null);
    renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
}
 
Example #21
Source File: BufferObject.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void deleteObject(final Object rendererObject) {

    if (!(rendererObject instanceof Renderer)) {
        throw new IllegalArgumentException("This bo can't be deleted from " + rendererObject);
    }

    ((Renderer) rendererObject).deleteBuffer(this);
}
 
Example #22
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Preloads this material for the given render manager.
 * <p>
 * Preloading the material can ensure that when the material is first
 * used for rendering, there won't be any delay since the material has
 * been already been setup for rendering.
 *
 * @param rm The render manager to preload for
 */
public void preload(RenderManager rm) {
    autoSelectTechnique(rm);

    Renderer r = rm.getRenderer();
    TechniqueDef techDef = technique.getDef();

    Collection<MatParam> params = paramValues.values();
    for (MatParam param : params) {
        if (param instanceof MatParamTexture) {
            MatParamTexture texParam = (MatParamTexture) param;
            r.setTexture(0, texParam.getTextureValue());
        } else {
            if (!techDef.isUsingShaders()) {
                continue;
            }

            technique.updateUniformParam(param.getName(),
                    param.getVarType(),
                    param.getValue(), true);
        }
    }

    Shader shader = technique.getShader();
    if (techDef.isUsingShaders()) {
        r.setShader(shader);
    }
}
 
Example #23
Source File: HDRRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public HDRRenderer(AssetManager manager, Renderer renderer){
    this.manager = manager;
    this.renderer = renderer;
    
    Collection<Caps> caps = renderer.getCaps();
    if (caps.contains(Caps.PackedFloatColorBuffer))
        bufFormat = Format.RGB111110F;
    else if (caps.contains(Caps.FloatColorBuffer))
        bufFormat = Format.RGB16F;
    else{
        enabled = false;
        return;
    }
}
 
Example #24
Source File: Filter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void cleanup(Renderer r) {
    renderFrameBuffer.dispose();
    renderedTexture.getImage().dispose();
    if(depthTexture!=null){
        depthTexture.getImage().dispose();
    }  
}
 
Example #25
Source File: Filter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * cleanup this filter
 * @param r
 */
protected final void cleanup(Renderer r) {   
    processor = null;
    if (defaultPass != null) {
        defaultPass.cleanup(r);
    }
    if (postRenderPasses != null) {
        for (Iterator<Pass> it = postRenderPasses.iterator(); it.hasNext();) {
            Pass pass = it.next();
            pass.cleanup(r);
        }
    }
    cleanUpFilter(r);
}
 
Example #26
Source File: PssmShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void displayShadowMap(Renderer r) {
    Camera cam = viewPort.getCamera();
    renderManager.setCamera(cam, true);
    int h = cam.getHeight();
    for (int i = 0; i < dispPic.length; i++) {
        dispPic[i].setPosition((128 * i) + (150 + 64 * (i + 1)), h / 20f);
        dispPic[i].setWidth(128);
        dispPic[i].setHeight(128);
        dispPic[i].updateGeometricState();
        renderManager.renderGeometry(dispPic[i]);
    }
    renderManager.setCamera(cam, false);
}
 
Example #27
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * For debugging purposes, display depth shadow maps.
 */
protected void displayShadowMap(Renderer r) {
    Camera cam = viewPort.getCamera();
    renderManager.setCamera(cam, true);
    int h = cam.getHeight();
    for (int i = 0; i < dispPic.length; i++) {
        dispPic[i].setPosition((128 * i) + (150 + 64 * (i + 1)), h / 20f);
        dispPic[i].setWidth(128);
        dispPic[i].setHeight(128);
        dispPic[i].updateGeometricState();
        renderManager.renderGeometry(dispPic[i]);
    }
    renderManager.setCamera(cam, false);
}
 
Example #28
Source File: DefaultTechniqueDefLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void renderMeshFromGeometry(Renderer renderer, Geometry geom) {
    Mesh mesh = geom.getMesh();
    int lodLevel = geom.getLodLevel();
    if (geom instanceof InstancedGeometry) {
        InstancedGeometry instGeom = (InstancedGeometry) geom;
        renderer.renderMesh(mesh, lodLevel, instGeom.getActualNumInstances(),
                instGeom.getAllInstanceData());
    } else {
        renderer.renderMesh(mesh, lodLevel, 1, null);
    }
}
 
Example #29
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateRenderState(RenderManager renderManager, Renderer renderer, TechniqueDef techniqueDef) {
    if (renderManager.getForcedRenderState() != null) {
        renderer.applyRenderState(renderManager.getForcedRenderState());
    } else {
        if (techniqueDef.getRenderState() != null) {
            renderer.applyRenderState(techniqueDef.getRenderState().copyMergedTo(additionalState, mergedRenderState));
        } else {
            renderer.applyRenderState(RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState));
        }
    }
}
 
Example #30
Source File: StaticPassLightingLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    Renderer renderer = renderManager.getRenderer();
    Matrix4f viewMatrix = renderManager.getCurrentCamera().getViewMatrix();
    updateLightListUniforms(viewMatrix, shader, lights);
    renderer.setShader(shader);
    renderMeshFromGeometry(renderer, geometry);
}