Search in sources :

Example 6 with GL

use of com.jme3.renderer.opengl.GL 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 GL

use of com.jme3.renderer.opengl.GL in project jmonkeyengine by jMonkeyEngine.

the class OGLESContext method initInThread.

protected void initInThread() {
    created.set(true);
    logger.fine("OGLESContext create");
    logger.log(Level.FINE, "Running on thread: {0}", Thread.currentThread().getName());
    // Setup unhandled Exception Handler
    Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        public void uncaughtException(Thread thread, Throwable thrown) {
            listener.handleError("Exception thrown in " + thread.toString(), thrown);
        }
    });
    timer = new NanoTimer();
    Object gl = new AndroidGL();
    // gl = GLTracer.createGlesTracer((GL)gl, (GLExt)gl);
    // gl = new GLDebugES((GL)gl, (GLExt)gl);
    renderer = new GLRenderer((GL) gl, (GLExt) gl, (GLFbo) gl);
    renderer.initialize();
    JmeSystem.setSoftTextDialogInput(this);
    needClose.set(false);
}
Also used : GLExt(com.jme3.renderer.opengl.GLExt) AndroidGL(com.jme3.renderer.android.AndroidGL) GLRenderer(com.jme3.renderer.opengl.GLRenderer) GLFbo(com.jme3.renderer.opengl.GLFbo) GL(com.jme3.renderer.opengl.GL) AndroidGL(com.jme3.renderer.android.AndroidGL)

Example 8 with GL

use of com.jme3.renderer.opengl.GL in project jmonkeyengine by jMonkeyEngine.

the class IGLESContext method create.

@Override
public void create(boolean waitFor) {
    logger.log(Level.FINE, "IGLESContext create");
    GL gl = new IosGL();
    GLExt glext = (GLExt) gl;
    //        if (settings.getBoolean("GraphicsDebug")) {
    gl = new GLDebugES(gl, glext, (GLFbo) glext);
    glext = (GLExt) gl;
    //        }
    renderer = new GLRenderer(gl, glext, (GLFbo) glext);
    renderer.initialize();
    input = new IosInputHandler();
    timer = new NanoTimer();
    //synchronized (createdLock){
    created.set(true);
    //createdLock.notifyAll();
    //}
    listener.initialize();
    if (waitFor) {
    //waitFor(true);
    }
    logger.log(Level.FINE, "IGLESContext created");
}
Also used : GLExt(com.jme3.renderer.opengl.GLExt) GLFbo(com.jme3.renderer.opengl.GLFbo) GLRenderer(com.jme3.renderer.opengl.GLRenderer) IosInputHandler(com.jme3.input.ios.IosInputHandler) GL(com.jme3.renderer.opengl.GL) IosGL(com.jme3.renderer.ios.IosGL) IosGL(com.jme3.renderer.ios.IosGL) GLDebugES(com.jme3.renderer.opengl.GLDebugES)

Example 9 with GL

use of com.jme3.renderer.opengl.GL 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 GL

use of com.jme3.renderer.opengl.GL in project jmonkeyengine by jMonkeyEngine.

the class TextureUtil method uploadTexture.

public static void uploadTexture(Image image, int target, int index, int border, boolean linearizeSrgb) {
    GL gl = GLContext.getCurrentGL();
    Image.Format fmt = image.getFormat();
    GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb);
    ByteBuffer data;
    if (index >= 0 && image.getData() != null && image.getData().size() > 0) {
        data = image.getData(index);
    } else {
        data = null;
    }
    int width = image.getWidth();
    int height = image.getHeight();
    int depth = image.getDepth();
    if (data != null) {
        if (abgrToRgbaConversionEnabled) {
            convertABGRtoRGBA(data);
        }
        gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    }
    int[] mipSizes = image.getMipMapSizes();
    int pos = 0;
    // TODO: Remove unneccessary allocation
    if (mipSizes == null) {
        if (data != null)
            mipSizes = new int[] { data.capacity() };
        else
            mipSizes = new int[] { width * height * fmt.getBitsPerPixel() / 8 };
    }
    boolean subtex = false;
    int samples = image.getMultiSamples();
    for (int i = 0; i < mipSizes.length; i++) {
        int mipWidth = Math.max(1, width >> i);
        int mipHeight = Math.max(1, height >> i);
        int mipDepth = Math.max(1, depth >> i);
        if (data != null) {
            data.position(pos);
            data.limit(pos + mipSizes[i]);
        }
        if (glFmt.compressed && data != null) {
            if (target == GL2ES2.GL_TEXTURE_3D) {
                gl.getGL2ES2().glCompressedTexImage3D(target, i, glFmt.internalFormat, mipWidth, mipHeight, mipDepth, data.remaining(), border, data);
            } else {
                //all other targets use 2D: array, cubemap, 2d
                gl.glCompressedTexImage2D(target, i, glFmt.internalFormat, mipWidth, mipHeight, data.remaining(), border, data);
            }
        } else {
            if (target == GL2ES2.GL_TEXTURE_3D) {
                gl.getGL2ES2().glTexImage3D(target, i, glFmt.internalFormat, mipWidth, mipHeight, mipDepth, border, glFmt.format, glFmt.dataType, data);
            } else if (target == GL2ES3.GL_TEXTURE_2D_ARRAY) {
                // or upload slice
                if (index == -1) {
                    gl.getGL2ES2().glTexImage3D(target, 0, glFmt.internalFormat, mipWidth, mipHeight, //# of slices
                    image.getData().size(), border, glFmt.format, glFmt.dataType, data);
                } else {
                    gl.getGL2ES2().glTexSubImage3D(target, // level
                    i, // xoffset
                    0, // yoffset
                    0, // zoffset
                    index, // width
                    width, // height
                    height, // depth
                    1, glFmt.format, glFmt.dataType, data);
                }
            } else {
                if (subtex) {
                    if (samples > 1) {
                        throw new IllegalStateException("Cannot update multisample textures");
                    }
                    gl.glTexSubImage2D(target, i, 0, 0, mipWidth, mipHeight, glFmt.format, glFmt.dataType, data);
                } else {
                    if (samples > 1) {
                        if (gl.isGL2GL3()) {
                            gl.getGL3().glTexImage2DMultisample(target, samples, glFmt.internalFormat, mipWidth, mipHeight, true);
                        }
                    } else {
                        gl.glTexImage2D(target, i, glFmt.internalFormat, mipWidth, mipHeight, border, glFmt.format, glFmt.dataType, data);
                    }
                }
            }
        }
        pos += mipSizes[i];
    }
}
Also used : GL(com.jogamp.opengl.GL) Format(com.jme3.texture.Image.Format) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer)

Aggregations

GLExt (com.jme3.renderer.opengl.GLExt)4 GLFbo (com.jme3.renderer.opengl.GLFbo)4 GLRenderer (com.jme3.renderer.opengl.GLRenderer)4 RendererException (com.jme3.renderer.RendererException)3 GL (com.jme3.renderer.opengl.GL)3 Image (com.jme3.texture.Image)3 GL (com.jogamp.opengl.GL)3 JoglGL (com.jme3.renderer.jogl.JoglGL)2 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 GLTimingState (com.jme3.renderer.opengl.GLTimingState)2 Format (com.jme3.texture.Image.Format)2 ByteBuffer (java.nio.ByteBuffer)2 GLCapabilities (org.lwjgl.opengl.GLCapabilities)2 IosInputHandler (com.jme3.input.ios.IosInputHandler)1 Material (com.jme3.material.Material)1 Caps (com.jme3.renderer.Caps)1