Search in sources :

Example 6 with RendererException

use of com.jme3.renderer.RendererException 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 7 with RendererException

use of com.jme3.renderer.RendererException 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 8 with RendererException

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

the class GLRenderer method updateShaderData.

public void updateShaderData(Shader shader) {
    int id = shader.getId();
    boolean needRegister = false;
    if (id == -1) {
        // create program
        id = gl.glCreateProgram();
        if (id == 0) {
            throw new RendererException("Invalid ID (" + id + ") received when trying to create shader program.");
        }
        shader.setId(id);
        needRegister = true;
    }
    // If using GLSL 1.5, we bind the outputs for the user
    // For versions 3.3 and up, user should use layout qualifiers instead.
    boolean bindFragDataRequired = false;
    for (ShaderSource source : shader.getSources()) {
        if (source.isUpdateNeeded()) {
            updateShaderSourceData(source);
        }
        if (source.getType() == ShaderType.Fragment && source.getLanguage().equals("GLSL150")) {
            bindFragDataRequired = true;
        }
        gl.glAttachShader(id, source.getId());
    }
    if (bindFragDataRequired) {
        // Check if GLSL version is 1.5 for shader
        gl3.glBindFragDataLocation(id, 0, "outFragColor");
        // For MRT
        for (int i = 0; i < limits.get(Limits.FrameBufferMrtAttachments); i++) {
            gl3.glBindFragDataLocation(id, i, "outFragData[" + i + "]");
        }
    }
    // Link shaders to program
    gl.glLinkProgram(id);
    // Check link status
    gl.glGetProgram(id, GL.GL_LINK_STATUS, intBuf1);
    boolean linkOK = intBuf1.get(0) == GL.GL_TRUE;
    String infoLog = null;
    if (VALIDATE_SHADER || !linkOK) {
        gl.glGetProgram(id, GL.GL_INFO_LOG_LENGTH, intBuf1);
        int length = intBuf1.get(0);
        if (length > 3) {
            // get infos
            infoLog = gl.glGetProgramInfoLog(id, length);
        }
    }
    if (linkOK) {
        if (infoLog != null) {
            logger.log(Level.WARNING, "Shader linked successfully. Linker warnings: \n{0}", infoLog);
        } else {
            logger.fine("Shader linked successfully.");
        }
        shader.clearUpdateNeeded();
        if (needRegister) {
            // Register shader for clean up if it was created in this method.
            objManager.registerObject(shader);
            statistics.onNewShader();
        } else {
            // OpenGL spec: uniform locations may change after re-link
            resetUniformLocations(shader);
        }
    } else {
        if (infoLog != null) {
            throw new RendererException("Shader failed to link, shader:" + shader + "\n" + infoLog);
        } else {
            throw new RendererException("Shader failed to link, shader:" + shader + "\ninfo: <not provided>");
        }
    }
}
Also used : ShaderSource(com.jme3.shader.Shader.ShaderSource)

Example 9 with RendererException

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

the class JoglContext method initContextFirstTime.

protected void initContextFirstTime() {
    if (GLContext.getCurrent().getGLVersionNumber().getMajor() < 2) {
        throw new RendererException("OpenGL 2.0 or higher is " + "required for jMonkeyEngine");
    }
    if (settings.getRenderer().startsWith("JOGL")) {
        com.jme3.renderer.opengl.GL gl = new JoglGL();
        GLExt glext = new JoglGLExt();
        GLFbo glfbo = new JoglGLFbo();
        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 = (com.jme3.renderer.opengl.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 = (com.jme3.renderer.opengl.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 (GLContext.getCurrentGL().isExtensionAvailable("GL_ARB_debug_output") && settings.getBoolean("GraphicsDebug")) {
        GLContext.getCurrent().enableGLDebugMessage(true);
        GLContext.getCurrent().addGLDebugListener(new JoglGLDebugOutputHandler());
    }
    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();
    }
    if (settings.isOpenCLSupport()) {
        initOpenCL();
    }
}
Also used : JoglGLFbo(com.jme3.renderer.jogl.JoglGLFbo) GLFbo(com.jme3.renderer.opengl.GLFbo) GLRenderer(com.jme3.renderer.opengl.GLRenderer) JoglGLFbo(com.jme3.renderer.jogl.JoglGLFbo) GLExt(com.jme3.renderer.opengl.GLExt) JoglGLExt(com.jme3.renderer.jogl.JoglGLExt) JoglGLExt(com.jme3.renderer.jogl.JoglGLExt) RendererException(com.jme3.renderer.RendererException) GLDebugDesktop(com.jme3.renderer.opengl.GLDebugDesktop) GLTimingState(com.jme3.renderer.opengl.GLTimingState) JoglGL(com.jme3.renderer.jogl.JoglGL)

Example 10 with RendererException

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

the class LwjglContextVR 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 : LwjglGL(com.jme3.renderer.lwjgl.LwjglGL) LwjglGLExt(com.jme3.renderer.lwjgl.LwjglGLExt) LwjglGLFboGL3(com.jme3.renderer.lwjgl.LwjglGLFboGL3) LwjglGLExt(com.jme3.renderer.lwjgl.LwjglGLExt) GLCapabilities(org.lwjgl.opengl.GLCapabilities) RendererException(com.jme3.renderer.RendererException) LwjglGLFboEXT(com.jme3.renderer.lwjgl.LwjglGLFboEXT) LwjglGL(com.jme3.renderer.lwjgl.LwjglGL)

Aggregations

RendererException (com.jme3.renderer.RendererException)4 LwjglGL (com.jme3.renderer.lwjgl.LwjglGL)2 LwjglGLExt (com.jme3.renderer.lwjgl.LwjglGLExt)2 LwjglGLFboEXT (com.jme3.renderer.lwjgl.LwjglGLFboEXT)2 LwjglGLFboGL3 (com.jme3.renderer.lwjgl.LwjglGLFboGL3)2 GLDebugDesktop (com.jme3.renderer.opengl.GLDebugDesktop)2 GLExt (com.jme3.renderer.opengl.GLExt)2 GLFbo (com.jme3.renderer.opengl.GLFbo)2 GLRenderer (com.jme3.renderer.opengl.GLRenderer)2 GLTimingState (com.jme3.renderer.opengl.GLTimingState)2 RenderBuffer (com.jme3.texture.FrameBuffer.RenderBuffer)2 Image (com.jme3.texture.Image)2 GLCapabilities (org.lwjgl.opengl.GLCapabilities)2 MatParam (com.jme3.material.MatParam)1 Material (com.jme3.material.Material)1 JoglGL (com.jme3.renderer.jogl.JoglGL)1 JoglGLExt (com.jme3.renderer.jogl.JoglGLExt)1 JoglGLFbo (com.jme3.renderer.jogl.JoglGLFbo)1 GL (com.jme3.renderer.opengl.GL)1 Geometry (com.jme3.scene.Geometry)1