Search in sources :

Example 21 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class OGLESContext method createView.

/**
     * <code>createView</code> creates the GLSurfaceView that the renderer will
     * draw to. <p> The result GLSurfaceView will receive input events and
     * forward them to the Application. Any rendering will be done into the
     * GLSurfaceView. Only one GLSurfaceView can be created at this time. The
     * given configType specifies how to determine the display configuration.
     *
     * @return GLSurfaceView The newly created view
     */
public GLSurfaceView createView(Context context) {
    // NOTE: We assume all ICS devices have OpenGL ES 2.0.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // below 4.0, check OpenGL ES 2.0 support.
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        if (info.reqGlEsVersion < 0x20000) {
            throw new UnsupportedOperationException("OpenGL ES 2.0 is not supported on this device");
        }
    } else if (Build.VERSION.SDK_INT < 9) {
        throw new UnsupportedOperationException("jME3 requires Android 2.3 or later");
    }
    // Start to set up the view
    GLSurfaceView view = new GLSurfaceView(context);
    logger.log(Level.INFO, "Android Build Version: {0}", Build.VERSION.SDK_INT);
    if (androidInput == null) {
        if (Build.VERSION.SDK_INT >= 14) {
            androidInput = new AndroidInputHandler14();
        } else if (Build.VERSION.SDK_INT >= 9) {
            androidInput = new AndroidInputHandler();
        }
    }
    androidInput.setView(view);
    androidInput.loadSettings(settings);
    // setEGLContextClientVersion must be set before calling setRenderer
    // this means it cannot be set in AndroidConfigChooser (too late)
    view.setEGLContextClientVersion(2);
    view.setFocusableInTouchMode(true);
    view.setFocusable(true);
    // setFormat must be set before AndroidConfigChooser is called by the surfaceview.
    // if setFormat is called after ConfigChooser is called, then execution
    // stops at the setFormat call without a crash.
    // We look at the user setting for alpha bits and set the surfaceview
    // PixelFormat to either Opaque, Transparent, or Translucent.
    // ConfigChooser will do it's best to honor the alpha requested by the user
    // For best rendering performance, use Opaque (alpha bits = 0).
    int curAlphaBits = settings.getAlphaBits();
    logger.log(Level.FINE, "curAlphaBits: {0}", curAlphaBits);
    if (curAlphaBits >= 8) {
        logger.log(Level.FINE, "Pixel Format: TRANSLUCENT");
        view.getHolder().setFormat(PixelFormat.TRANSLUCENT);
        view.setZOrderOnTop(true);
    } else if (curAlphaBits >= 1) {
        logger.log(Level.FINE, "Pixel Format: TRANSPARENT");
        view.getHolder().setFormat(PixelFormat.TRANSPARENT);
    } else {
        logger.log(Level.FINE, "Pixel Format: OPAQUE");
        view.getHolder().setFormat(PixelFormat.OPAQUE);
    }
    AndroidConfigChooser configChooser = new AndroidConfigChooser(settings);
    view.setEGLConfigChooser(configChooser);
    view.setRenderer(this);
    // reloading all the OpenGL objects.
    if (Build.VERSION.SDK_INT >= 11) {
        view.setPreserveEGLContextOnPause(true);
    }
    return view;
}
Also used : AndroidInputHandler(com.jme3.input.android.AndroidInputHandler) AndroidInputHandler14(com.jme3.input.android.AndroidInputHandler14) ActivityManager(android.app.ActivityManager) GLSurfaceView(android.opengl.GLSurfaceView) ConfigurationInfo(android.content.pm.ConfigurationInfo)

Example 22 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class LwjglContext 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);
}
Also used : GLFbo(com.jme3.renderer.opengl.GLFbo) GLRenderer(com.jme3.renderer.opengl.GLRenderer) GL(com.jme3.renderer.opengl.GL) LwjglGL(com.jme3.renderer.lwjgl.LwjglGL) LwjglGLExt(com.jme3.renderer.lwjgl.LwjglGLExt) LwjglGLFboGL3(com.jme3.renderer.lwjgl.LwjglGLFboGL3) LwjglGLExt(com.jme3.renderer.lwjgl.LwjglGLExt) GLExt(com.jme3.renderer.opengl.GLExt) GLCapabilities(org.lwjgl.opengl.GLCapabilities) RendererException(com.jme3.renderer.RendererException) GLDebugDesktop(com.jme3.renderer.opengl.GLDebugDesktop) GLTimingState(com.jme3.renderer.opengl.GLTimingState) LwjglGLFboEXT(com.jme3.renderer.lwjgl.LwjglGLFboEXT) LwjglGL(com.jme3.renderer.lwjgl.LwjglGL)

Example 23 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class ParticlePointMesh method updateParticleData.

@Override
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
    VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position);
    FloatBuffer positions = (FloatBuffer) pvb.getData();
    VertexBuffer cvb = getBuffer(VertexBuffer.Type.Color);
    ByteBuffer colors = (ByteBuffer) cvb.getData();
    VertexBuffer svb = getBuffer(VertexBuffer.Type.Size);
    FloatBuffer sizes = (FloatBuffer) svb.getData();
    VertexBuffer tvb = getBuffer(VertexBuffer.Type.TexCoord);
    FloatBuffer texcoords = (FloatBuffer) tvb.getData();
    float sizeScale = emitter.getWorldScale().x;
    // update data in vertex buffers
    positions.rewind();
    colors.rewind();
    sizes.rewind();
    texcoords.rewind();
    for (int i = 0; i < particles.length; i++) {
        Particle p = particles[i];
        positions.put(p.position.x).put(p.position.y).put(p.position.z);
        sizes.put(p.size * sizeScale);
        colors.putInt(p.color.asIntABGR());
        int imgX = p.imageIndex % imagesX;
        int imgY = (p.imageIndex - imgX) / imagesY;
        float startX = ((float) imgX) / imagesX;
        float startY = ((float) imgY) / imagesY;
        float endX = startX + (1f / imagesX);
        float endY = startY + (1f / imagesY);
        texcoords.put(startX).put(startY).put(endX).put(endY);
    }
    positions.flip();
    colors.flip();
    sizes.flip();
    texcoords.flip();
    // force renderer to re-send data to GPU
    pvb.updateData(positions);
    cvb.updateData(colors);
    svb.updateData(sizes);
    tvb.updateData(texcoords);
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 24 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class ParticleTriMesh method updateParticleData.

@Override
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
    //        System.arraycopy(particles, 0, particlesCopy, 0, particlesCopy.length);
    //        comparator.setCamera(cam);
    //        Arrays.sort(particlesCopy, comparator);
    //        SortUtil.qsort(particlesCopy, comparator);
    //        SortUtil.msort(particles, particlesCopy, comparator);
    //        particles = particlesCopy;
    VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position);
    FloatBuffer positions = (FloatBuffer) pvb.getData();
    VertexBuffer cvb = getBuffer(VertexBuffer.Type.Color);
    ByteBuffer colors = (ByteBuffer) cvb.getData();
    VertexBuffer tvb = getBuffer(VertexBuffer.Type.TexCoord);
    FloatBuffer texcoords = (FloatBuffer) tvb.getData();
    Vector3f camUp = cam.getUp();
    Vector3f camLeft = cam.getLeft();
    Vector3f camDir = cam.getDirection();
    inverseRotation.multLocal(camUp);
    inverseRotation.multLocal(camLeft);
    inverseRotation.multLocal(camDir);
    boolean facingVelocity = emitter.isFacingVelocity();
    Vector3f up = new Vector3f(), left = new Vector3f();
    if (!facingVelocity) {
        up.set(camUp);
        left.set(camLeft);
    }
    // update data in vertex buffers
    positions.clear();
    colors.clear();
    texcoords.clear();
    Vector3f faceNormal = emitter.getFaceNormal();
    for (int i = 0; i < particles.length; i++) {
        Particle p = particles[i];
        boolean dead = p.life == 0;
        if (dead) {
            positions.put(0).put(0).put(0);
            positions.put(0).put(0).put(0);
            positions.put(0).put(0).put(0);
            positions.put(0).put(0).put(0);
            continue;
        }
        if (facingVelocity) {
            left.set(p.velocity).normalizeLocal();
            camDir.cross(left, up);
            up.multLocal(p.size);
            left.multLocal(p.size);
        } else if (faceNormal != null) {
            up.set(faceNormal).crossLocal(Vector3f.UNIT_X);
            faceNormal.cross(up, left);
            up.multLocal(p.size);
            left.multLocal(p.size);
            if (p.angle != 0) {
                TempVars vars = TempVars.get();
                vars.vect1.set(faceNormal).normalizeLocal();
                vars.quat1.fromAngleNormalAxis(p.angle, vars.vect1);
                vars.quat1.multLocal(left);
                vars.quat1.multLocal(up);
                vars.release();
            }
        } else if (p.angle != 0) {
            float cos = FastMath.cos(p.angle) * p.size;
            float sin = FastMath.sin(p.angle) * p.size;
            left.x = camLeft.x * cos + camUp.x * sin;
            left.y = camLeft.y * cos + camUp.y * sin;
            left.z = camLeft.z * cos + camUp.z * sin;
            up.x = camLeft.x * -sin + camUp.x * cos;
            up.y = camLeft.y * -sin + camUp.y * cos;
            up.z = camLeft.z * -sin + camUp.z * cos;
        } else {
            up.set(camUp);
            left.set(camLeft);
            up.multLocal(p.size);
            left.multLocal(p.size);
        }
        positions.put(p.position.x + left.x + up.x).put(p.position.y + left.y + up.y).put(p.position.z + left.z + up.z);
        positions.put(p.position.x - left.x + up.x).put(p.position.y - left.y + up.y).put(p.position.z - left.z + up.z);
        positions.put(p.position.x + left.x - up.x).put(p.position.y + left.y - up.y).put(p.position.z + left.z - up.z);
        positions.put(p.position.x - left.x - up.x).put(p.position.y - left.y - up.y).put(p.position.z - left.z - up.z);
        if (uniqueTexCoords) {
            int imgX = p.imageIndex % imagesX;
            int imgY = (p.imageIndex - imgX) / imagesY;
            float startX = ((float) imgX) / imagesX;
            float startY = ((float) imgY) / imagesY;
            float endX = startX + (1f / imagesX);
            float endY = startY + (1f / imagesY);
            texcoords.put(startX).put(endY);
            texcoords.put(endX).put(endY);
            texcoords.put(startX).put(startY);
            texcoords.put(endX).put(startY);
        }
        int abgr = p.color.asIntABGR();
        colors.putInt(abgr);
        colors.putInt(abgr);
        colors.putInt(abgr);
        colors.putInt(abgr);
    }
    positions.clear();
    colors.clear();
    if (!uniqueTexCoords)
        texcoords.clear();
    else {
        texcoords.clear();
        tvb.updateData(texcoords);
    }
    // force renderer to re-send data to GPU
    pvb.updateData(positions);
    cvb.updateData(colors);
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer) TempVars(com.jme3.util.TempVars) ByteBuffer(java.nio.ByteBuffer)

Example 25 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method displayShadowMap.

/**
     * 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);
}
Also used : Camera(com.jme3.renderer.Camera)

Aggregations

Renderer (com.jme3.renderer.Renderer)17 Camera (com.jme3.renderer.Camera)7 Vector3f (com.jme3.math.Vector3f)5 Material (com.jme3.material.Material)4 SceneProcessor (com.jme3.post.SceneProcessor)3 RendererException (com.jme3.renderer.RendererException)3 GLExt (com.jme3.renderer.opengl.GLExt)3 GLFbo (com.jme3.renderer.opengl.GLFbo)3 GLRenderer (com.jme3.renderer.opengl.GLRenderer)3 Uniform (com.jme3.shader.Uniform)3 CartoonSSAO (com.jme3.post.CartoonSSAO)2 Filter (com.jme3.post.Filter)2 FilterPostProcessor (com.jme3.post.FilterPostProcessor)2 HDRRenderer (com.jme3.post.HDRRenderer)2 FogFilter (com.jme3.post.filters.FogFilter)2 TranslucentBucketFilter (com.jme3.post.filters.TranslucentBucketFilter)2 SSAOFilter (com.jme3.post.ssao.SSAOFilter)2 Caps (com.jme3.renderer.Caps)2 RenderManager (com.jme3.renderer.RenderManager)2 LwjglGL (com.jme3.renderer.lwjgl.LwjglGL)2