Java Code Examples for com.jme3.renderer.RenderManager#getRenderer()

The following examples show how to use com.jme3.renderer.RenderManager#getRenderer() . 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: NiftyJmeDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public void initialize(RenderManager rm, ViewPort vp) {
        this.renderManager = rm;
        if (renderDev != null) {
          renderDev.setRenderManager(rm);
        } else {
          batchRendererBackend.setRenderManager(rm);
        }

        if (inputManager != null) {
//            inputSys.setInputManager(inputManager);
            inputManager.addRawInputListener(inputSys);
        }
        inited = true;
        this.vp = vp;
        this.renderer = rm.getRenderer();

        inputSys.reset();
        inputSys.setHeight(vp.getCamera().getHeight());
    }
 
Example 2
Source File: TestDepthStencil.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 3
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 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 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 6
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 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 renderManager The render manager to preload for
 */
public void preload(RenderManager renderManager, Geometry geometry) {
    if (technique == null) {
        selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    }
    TechniqueDef techniqueDef = technique.getDef();
    Renderer renderer = renderManager.getRenderer();
    EnumSet<Caps> rendererCaps = renderer.getCaps();

    if (techniqueDef.isNoRender()) {
        return;
    }
    // Get world overrides
    SafeArrayList<MatParamOverride> overrides = geometry.getWorldMatParamOverrides();

    Shader shader = technique.makeCurrent(renderManager, overrides, null, null, rendererCaps);
    updateShaderMaterialParameters(renderer, shader, overrides, null);
    renderManager.getRenderer().setShader(shader);
}
 
Example 7
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 8
Source File: NiftyJmeDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void initialize(RenderManager rm, ViewPort vp) {
    this.renderManager = rm;
    renderDev.setRenderManager(rm);
    inited = true;
    this.vp = vp;
    this.renderer = rm.getRenderer();
    
}
 
Example 9
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 10
Source File: NiftyJmeDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initialize(RenderManager rm, ViewPort vp) {
    this.renderManager = rm;
    renderDev.setRenderManager(rm);
    inited = true;
    this.vp = vp;
    this.renderer = rm.getRenderer();
    
    inputSys.setHeight(vp.getCamera().getHeight());
}
 
Example 11
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);
}
 
Example 12
Source File: DefaultTechniqueDefLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    Renderer renderer = renderManager.getRenderer();
    renderer.setShader(shader);
    renderMeshFromGeometry(renderer, geometry);
}
 
Example 13
Source File: HDRRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void initialize(RenderManager rm, ViewPort vp){
    if (!enabled)
        return;

    renderer = rm.getRenderer();
    renderManager = rm;
    viewPort = vp;

    // loadInitial()
    fsQuad = new Picture("HDR Fullscreen Quad");

    Format lumFmt = Format.RGB8;
    scene64FB = new FrameBuffer(64, 64, 1);
    scene64 = new Texture2D(64, 64, lumFmt);
    scene64FB.setColorTexture(scene64);
    scene64.setMagFilter(fbMagFilter);
    scene64.setMinFilter(fbMinFilter);

    scene8FB = new FrameBuffer(8, 8, 1);
    scene8 = new Texture2D(8, 8, lumFmt);
    scene8FB.setColorTexture(scene8);
    scene8.setMagFilter(fbMagFilter);
    scene8.setMinFilter(fbMinFilter);

    scene1FB[0] = new FrameBuffer(1, 1, 1);
    scene1[0] = new Texture2D(1, 1, lumFmt);
    scene1FB[0].setColorTexture(scene1[0]);

    scene1FB[1] = new FrameBuffer(1, 1, 1);
    scene1[1] = new Texture2D(1, 1, lumFmt);
    scene1FB[1].setColorTexture(scene1[1]);

    // prepare tonemap shader
    tone = new Material(manager, "Common/MatDefs/Hdr/ToneMap.j3md");
    tone.setFloat("A", 0.18f);
    tone.setFloat("White", 100);

    // load();
    int w = vp.getCamera().getWidth();
    int h = vp.getCamera().getHeight();
    reshape(vp, w, h);

    
}
 
Example 14
Source File: RenderDeviceJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setRenderManager(RenderManager rm){
    this.rm = rm;
    this.r = rm.getRenderer();
}
 
Example 15
Source File: ScreenshotAppState.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void initialize(RenderManager rm, ViewPort vp) {
    renderer = rm.getRenderer();
    reshape(vp, vp.getCamera().getWidth(), vp.getCamera().getHeight());
}
 
Example 16
Source File: ScreenshotAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void initialize(RenderManager rm, ViewPort vp) {
    renderer = rm.getRenderer();
    this.rm = rm;
    reshape(vp, vp.getCamera().getWidth(), vp.getCamera().getHeight());
}
 
Example 17
Source File: AWTComponentRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Copy the JMonkey frame buffer that has been rendered by the JMonkey engine and schedule the rendering of the component.
 * @param renderManager the JMonkey render manager.
 */
public void copyFrameBufferToImage(RenderManager renderManager) {

  while (!frameState.compareAndSet(WAITING_STATE, RUNNING_STATE)) {
    if (frameState.get() == DISPOSED_STATE) {
      return;
    }
  }

  // Convert screenshot.
  try {

    frameByteBuffer.clear();

    final Renderer renderer = renderManager.getRenderer();
    renderer.readFrameBufferWithFormat(frameBuffer, frameByteBuffer, Image.Format.RGBA8);

  } finally {
    if (!frameState.compareAndSet(RUNNING_STATE, WAITING_STATE)) {
      throw new RuntimeException("unknown problem with the frame state");
    }
  }

  synchronized (byteBuffer) {
    frameByteBuffer.get(byteBuffer);

    if (transferMode == TransferMode.ON_CHANGES) {

      final byte[] prevBuffer = getPrevImageByteBuffer();

      if (Arrays.equals(prevBuffer, byteBuffer)) {
        if (frameCount == 0) return;
      } else {
        frameCount = 2;
        System.arraycopy(byteBuffer, 0, prevBuffer, 0, byteBuffer.length);
      }

      frameByteBuffer.position(0);
      frameCount--;
    }
  }

  EventQueue.invokeLater(new Runnable() {

    @Override
    public void run() {
      writeFrame();
    }});
}
 
Example 18
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Called by {@link RenderManager} to render the geometry by
 * using this material.
 *
 * @param geom The geometry to render
 * @param rm The render manager requesting the rendering
 */
public void render(Geometry geom, RenderManager rm) {
    autoSelectTechnique(rm);

    Renderer r = rm.getRenderer();

    TechniqueDef techDef = technique.getDef();
    r.setShaderWithoutUpdateUniforms(technique.getShader());
    if (techDef.getLightMode() == LightMode.MultiPass
            && geom.getWorldLightList().size() == 0) {
        return;
    }

    if (rm.getForcedRenderState() != null) {
        r.applyRenderState(rm.getForcedRenderState());
    } else {
        if (techDef.getRenderState() != null) {
            r.applyRenderState(techDef.getRenderState().copyMergedTo(additionalState, mergedRenderState));
        } else {
            r.applyRenderState(RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState));
        }
    }

    boolean needReloadParams = false;
    if (technique.isNeedReload()) {
        technique.makeCurrent(def.getAssetManager(), paramValues);
        needReloadParams = true;
    }
    // update camera and world matrices
    // NOTE: setWorldTransform should have been called already
    if (techDef.isUsingShaders()) {
        // reset unchanged uniform flag
        clearUniformsSetByCurrent(technique.getShader());
        rm.updateUniformBindings(technique.getWorldBindUniforms());
    }

    // setup textures and uniforms
    for (int i = paramValues.size()-1; i >=0 ; i--) {
        MatParam param = paramValues.getValue(i);
        if (param != null) {
            param.apply(r, technique, i);
        }
    }

    Shader shader = technique.getShader();

    // send lighting information, if needed
    switch (techDef.getLightMode()) {
        case Disable:
            r.setLighting(null);
            break;
        case SinglePass:
            updateLightListUniforms(shader, geom, 4);
            break;
        case FixedPipeline:
            r.setLighting(geom.getWorldLightList());
            break;
        case MultiPass:
            // NOTE: Special case!
            resetUniformsNotSetByCurrent(shader);
            renderMultipassLighting(shader, geom, rm);
            // very important, notice the return statement!
            return;
    }

    // upload and bind shader
    if (techDef.isUsingShaders()) {
        // any unset uniforms will be set to 0
        resetUniformsNotSetByCurrent(shader);
        r.setShader(shader);
    }

    r.renderMesh(geom.getMesh(), geom.getLodLevel(), 1);
}
 
Example 19
Source File: RenderDeviceJme.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setRenderManager(RenderManager rm) {
    this.rm = rm;
    this.r = rm.getRenderer();
}
 
Example 20
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Called by {@link RenderManager} to render the geometry by
 * using this material.
 * <p>
 * The material is rendered as follows:
 * <ul>
 * <li>Determine which technique to use to render the material -
 * either what the user selected via
 * {@link #selectTechnique(java.lang.String, com.jme3.renderer.RenderManager)
 * Material.selectTechnique()},
 * or the first default technique that the renderer supports
 * (based on the technique's {@link TechniqueDef#getRequiredCaps() requested rendering capabilities})<ul>
 * <li>If the technique has been changed since the last frame, then it is notified via
 * {@link Technique#makeCurrent(com.jme3.renderer.RenderManager, com.jme3.util.SafeArrayList, com.jme3.util.SafeArrayList, com.jme3.light.LightList, java.util.EnumSet)
 * Technique.makeCurrent()}.
 * If the technique wants to use a shader to render the model, it should load it at this part -
 * the shader should have all the proper defines as declared in the technique definition,
 * including those that are bound to material parameters.
 * The technique can re-use the shader from the last frame if
 * no changes to the defines occurred.</li></ul>
 * <li>Set the {@link RenderState} to use for rendering. The render states are
 * applied in this order (later RenderStates override earlier RenderStates):<ol>
 * <li>{@link TechniqueDef#getRenderState() Technique Definition's RenderState}
 * - i.e. specific renderstate that is required for the shader.</li>
 * <li>{@link #getAdditionalRenderState() Material Instance Additional RenderState}
 * - i.e. ad-hoc renderstate set per model</li>
 * <li>{@link RenderManager#getForcedRenderState() RenderManager's Forced RenderState}
 * - i.e. renderstate requested by a {@link com.jme3.post.SceneProcessor} or
 * post-processing filter.</li></ol>
 * <li>If the technique uses a shader, then the uniforms of the shader must be updated.<ul>
 * <li>Uniforms bound to material parameters are updated based on the current material parameter values.</li>
 * <li>Uniforms bound to world parameters are updated from the RenderManager.
 * Internally {@link UniformBindingManager} is used for this task.</li>
 * <li>Uniforms bound to textures will cause the texture to be uploaded as necessary.
 * The uniform is set to the texture unit where the texture is bound.</li></ul>
 * <li>If the technique uses a shader, the model is then rendered according
 * to the lighting mode specified on the technique definition.<ul>
 * <li>{@link LightMode#SinglePass single pass light mode} fills the shader's light uniform arrays
 * with the first 4 lights and renders the model once.</li>
 * <li>{@link LightMode#MultiPass multi pass light mode} light mode renders the model multiple times,
 * for the first light it is rendered opaque, on subsequent lights it is
 * rendered with {@link BlendMode#AlphaAdditive alpha-additive} blending and depth writing disabled.</li>
 * </ul>
 * <li>For techniques that do not use shaders,
 * fixed function OpenGL is used to render the model (see {@link com.jme3.renderer.opengl.GLRenderer} interface):<ul>
 * <li>OpenGL state that is bound to material parameters is updated. </li>
 * <li>The texture set on the material is uploaded and bound.
 * Currently only 1 texture is supported for fixed function techniques.</li>
 * <li>If the technique uses lighting, then OpenGL lighting state is updated
 * based on the light list on the geometry, otherwise OpenGL lighting is disabled.</li>
 * <li>The mesh is uploaded and rendered.</li>
 * </ul>
 * </ul>
 *
 * @param geometry The geometry to render
 * @param lights Presorted and filtered light list to use for rendering
 * @param renderManager The render manager requesting the rendering
 */
public void render(Geometry geometry, LightList lights, RenderManager renderManager) {
    if (technique == null) {
        selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    }
    
    TechniqueDef techniqueDef = technique.getDef();
    Renderer renderer = renderManager.getRenderer();
    EnumSet<Caps> rendererCaps = renderer.getCaps();
    
    if (techniqueDef.isNoRender()) {
        return;
    }

    // Apply render state
    updateRenderState(renderManager, renderer, techniqueDef);

    // Get world overrides
    SafeArrayList<MatParamOverride> overrides = geometry.getWorldMatParamOverrides();

    // Select shader to use
    Shader shader = technique.makeCurrent(renderManager, overrides, renderManager.getForcedMatParams(), lights, rendererCaps);
    
    // Begin tracking which uniforms were changed by material.
    clearUniformsSetByCurrent(shader);
    
    // Set uniform bindings
    renderManager.updateUniformBindings(shader);
    
    // Set material parameters
    int unit = updateShaderMaterialParameters(renderer, shader, overrides, renderManager.getForcedMatParams());

    // Clear any uniforms not changed by material.
    resetUniformsNotSetByCurrent(shader);
    
    // Delegate rendering to the technique
    technique.render(renderManager, shader, geometry, lights, unit);
}