Search in sources :

Example 1 with ShadowMappingShaderPre

use of net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderPre in project tdme by andreasdr.

the class Engine method init.

/**
	 * Initialize render engine
	 * @param drawable
	 * @param debug
	 */
public void init(GLAutoDrawable drawable, boolean debug) {
    // exit if already initialized like a offscreen engine instance
    if (initialized == true)
        return;
    //
    GLContext glContext = drawable.getGL().getContext();
    if (drawable.getGL().isGL3()) {
        GL3 gl = (GL3) drawable.getGL().getGL3();
        if (debug == true) {
            drawable.setGL(new DebugGL3(gl));
        }
        // use gl3 renderer
        renderer = new GL3Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GL3");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // engine defaults
        shadowMappingEnabled = true;
        animationProcessingTarget = AnimationProcessingTarget.CPU;
        ShadowMapping.setShadowMapSize(2048, 2048);
    } else if (drawable.getGL().isGL2()) {
        GL2 gl = (GL2) drawable.getGL().getGL2();
        if (debug == true) {
            drawable.setGL(new DebugGL2(gl));
        }
        // use gl2 renderer
        renderer = new GL2Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GL2");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // engine defaults
        shadowMappingEnabled = true;
        animationProcessingTarget = AnimationProcessingTarget.CPU;
        ShadowMapping.setShadowMapSize(2048, 2048);
    } else if (drawable.getGL().isGLES2()) {
        GLES2 gl = (GLES2) drawable.getGL().getGLES2();
        if (debug == true) {
            drawable.setGL(new DebugGLES2(gl));
        }
        // use gl es 2 renderer
        renderer = new GLES2Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GLES2");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // is shadow mapping available?
        if (renderer.isBufferObjectsAvailable() == true && renderer.isDepthTextureAvailable() == true) {
            // yep, nice
            shadowMappingEnabled = true;
            animationProcessingTarget = AnimationProcessingTarget.CPU;
            ShadowMapping.setShadowMapSize(512, 512);
        } else {
            // nope, renderer skinning on GPU to speed up things and do not shadow mapping
            shadowMappingEnabled = false;
            animationProcessingTarget = AnimationProcessingTarget.GPU;
        }
    } else {
        System.out.println("Engine::init(): unsupported GL!");
        return;
    }
    // init
    initialized = true;
    renderer.init();
    renderer.renderingTexturingClientState = false;
    // create manager
    textureManager = new TextureManager(renderer);
    vboManager = new VBOManager(renderer);
    meshManager = new MeshManager();
    // create object 3d vbo renderer
    object3DVBORenderer = new Object3DVBORenderer(this, renderer);
    object3DVBORenderer.init();
    // create GUI
    guiRenderer = new GUIRenderer(renderer);
    guiRenderer.init();
    gui = new GUI(this, guiRenderer);
    gui.init();
    // create camera
    camera = new Camera(renderer);
    partition = new PartitionQuadTree();
    // create lights
    for (int i = 0; i < lights.length; i++) lights[i] = new Light(renderer, i);
    // create lighting shader
    lightingShader = new LightingShader(renderer);
    lightingShader.init();
    // create particles shader
    particlesShader = new ParticlesShader(this, renderer);
    particlesShader.init();
    // create GUI shader
    guiShader = new GUIShader(renderer);
    guiShader.init();
    // check if VBOs are available
    if (renderer.isBufferObjectsAvailable()) {
        System.out.println("TDME::VBOs are available.");
    } else {
        System.out.println("TDME::VBOs are not available! Engine will not work!");
        initialized = false;
    }
    // check FBO support
    if (glContext.hasBasicFBOSupport() == false) {
        System.out.println("TDME::Basic FBOs are not available!");
        shadowMappingEnabled = false;
    } else {
        System.out.println("TDME::Basic FBOs are available.");
    }
    // initialize shadow mapping
    if (shadowMappingEnabled == true) {
        System.out.println("TDME::Using shadow mapping");
        shadowMappingShaderPre = new ShadowMappingShaderPre(renderer);
        shadowMappingShaderPre.init();
        shadowMappingShaderRender = new ShadowMappingShaderRender(renderer);
        shadowMappingShaderRender.init();
        shadowMapping = new ShadowMapping(this, renderer, object3DVBORenderer);
    } else {
        System.out.println("TDME::Not using shadow mapping");
    }
    // print out animation processing target
    System.out.println("TDME: animation processing target: " + animationProcessingTarget);
    // determine initialized from sub systems
    initialized &= shadowMappingShaderPre == null ? true : shadowMappingShaderPre.isInitialized();
    initialized &= shadowMappingShaderRender == null ? true : shadowMappingShaderRender.isInitialized();
    initialized &= lightingShader.isInitialized();
    initialized &= particlesShader.isInitialized();
    initialized &= guiShader.isInitialized();
    //
    System.out.println("TDME::initialized & ready: " + initialized);
}
Also used : ParticlesShader(net.drewke.tdme.engine.subsystems.particlesystem.ParticlesShader) ShadowMappingShaderRender(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderRender) ShadowMappingShaderPre(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderPre) VBOManager(net.drewke.tdme.engine.subsystems.manager.VBOManager) GLContext(com.jogamp.opengl.GLContext) LightingShader(net.drewke.tdme.engine.subsystems.lighting.LightingShader) GUIShader(net.drewke.tdme.gui.renderer.GUIShader) DebugGLES2(com.jogamp.opengl.DebugGLES2) GUIRenderer(net.drewke.tdme.gui.renderer.GUIRenderer) ShadowMapping(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping) Object3DVBORenderer(net.drewke.tdme.engine.subsystems.object.Object3DVBORenderer) DebugGL2(com.jogamp.opengl.DebugGL2) GUI(net.drewke.tdme.gui.GUI) DebugGL3(com.jogamp.opengl.DebugGL3) MeshManager(net.drewke.tdme.engine.subsystems.manager.MeshManager) GLES2Renderer(net.drewke.tdme.engine.subsystems.renderer.GLES2Renderer) GL2Renderer(net.drewke.tdme.engine.subsystems.renderer.GL2Renderer) GL3Renderer(net.drewke.tdme.engine.subsystems.renderer.GL3Renderer) GL2(com.jogamp.opengl.GL2) DebugGL2(com.jogamp.opengl.DebugGL2) GL3(com.jogamp.opengl.GL3) DebugGL3(com.jogamp.opengl.DebugGL3) TextureManager(net.drewke.tdme.engine.subsystems.manager.TextureManager) DebugGLES2(com.jogamp.opengl.DebugGLES2) GLES2(com.jogamp.opengl.GLES2)

Aggregations

DebugGL2 (com.jogamp.opengl.DebugGL2)1 DebugGL3 (com.jogamp.opengl.DebugGL3)1 DebugGLES2 (com.jogamp.opengl.DebugGLES2)1 GL2 (com.jogamp.opengl.GL2)1 GL3 (com.jogamp.opengl.GL3)1 GLContext (com.jogamp.opengl.GLContext)1 GLES2 (com.jogamp.opengl.GLES2)1 LightingShader (net.drewke.tdme.engine.subsystems.lighting.LightingShader)1 MeshManager (net.drewke.tdme.engine.subsystems.manager.MeshManager)1 TextureManager (net.drewke.tdme.engine.subsystems.manager.TextureManager)1 VBOManager (net.drewke.tdme.engine.subsystems.manager.VBOManager)1 Object3DVBORenderer (net.drewke.tdme.engine.subsystems.object.Object3DVBORenderer)1 ParticlesShader (net.drewke.tdme.engine.subsystems.particlesystem.ParticlesShader)1 GL2Renderer (net.drewke.tdme.engine.subsystems.renderer.GL2Renderer)1 GL3Renderer (net.drewke.tdme.engine.subsystems.renderer.GL3Renderer)1 GLES2Renderer (net.drewke.tdme.engine.subsystems.renderer.GLES2Renderer)1 ShadowMapping (net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping)1 ShadowMappingShaderPre (net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderPre)1 ShadowMappingShaderRender (net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderRender)1 GUI (net.drewke.tdme.gui.GUI)1