Ejemplo n.º 1
0
 public static void dispose() {
   modelBatch.dispose();
   spriteBatch.dispose();
   frameBuffer.dispose();
   tempBuffer.dispose();
   shaderProvider.dispose();
   for (ShaderProgram s : Bdx.matShaders.values()) {
     s.dispose();
   }
 }
Ejemplo n.º 2
0
  public static void resize(int width, int height) {
    spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);

    if (frameBuffer != null) frameBuffer.dispose();
    if (tempBuffer != null) tempBuffer.dispose();

    frameBuffer =
        new RenderBuffer(
            spriteBatch); // Have to recreate all render buffers and adjust the projection matrix as
                          // the window size has changed
    tempBuffer = new RenderBuffer(spriteBatch);
    for (Scene scene : scenes) {

      if (scene.lastFrameBuffer != null) scene.lastFrameBuffer.dispose();

      scene.lastFrameBuffer = new RenderBuffer(null);
    }
  }
Ejemplo n.º 3
0
  public static void main() {
    profiler.start("__graphics");
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    profiler.stop("__graphics");

    // -------- Update Input --------
    time += TICK_TIME;
    ++GdxProcessor.currentTick;
    fingers.clear();
    for (Finger f : allocatedFingers) {
      if (f.down() || f.up()) fingers.add(f);
    }
    // ------------------------------

    for (Component c : components) {
      if (c.state != null) c.state.main();
    }

    profiler.stop("__input");

    for (Scene scene : (ArrayListScenes) scenes.clone()) {
      scene.update();

      profiler.start("__render");

      // ------- Render Scene --------

      if (scene.filters.size() > 0) {
        frameBuffer.begin();
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      }

      Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
      modelBatch.begin(scene.camera.data);
      for (GameObject g : scene.objects) {
        if (g.visible() && g.insideFrustum()) {
          modelBatch.render(g.modelInstance, scene.environment);
        }
      }
      modelBatch.end();

      if (scene.filters.size() > 0) {

        frameBuffer.end();

        scene.lastFrameBuffer.getColorBufferTexture().bind(1);
        Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);

        for (ShaderProgram filter : scene.filters) {

          filter.begin();
          filter.setUniformf("time", Bdx.time);
          filter.setUniformi("lastFrame", 1);
          filter.setUniformf("screenWidth", Bdx.display.size().x);
          filter.setUniformf("screenHeight", Bdx.display.size().y);
          filter.end();

          tempBuffer.clear();

          int width = (int) (Gdx.graphics.getWidth() * filter.renderScale.x);
          int height = (int) (Gdx.graphics.getHeight() * filter.renderScale.y);

          if (tempBuffer.getWidth() != width || tempBuffer.getHeight() != height)
            tempBuffer = new RenderBuffer(spriteBatch, width, height);

          frameBuffer.drawTo(tempBuffer, filter);

          if (!filter.overlay) frameBuffer.clear();

          tempBuffer.drawTo(frameBuffer);
        }

        frameBuffer.drawTo(null); //  Draw to screen
        scene.lastFrameBuffer.clear();
        frameBuffer.drawTo(scene.lastFrameBuffer);
      }

      // ------- Render physics debug view --------

      Bullet.DebugDrawer debugDrawer = (Bullet.DebugDrawer) scene.world.getDebugDrawer();
      debugDrawer.drawWorld(scene.world, scene.camera.data);

      profiler.stop("__render");
    }
    mouse.wheelMove = 0;

    profiler.updateVariables();
    if (profiler.visible()) {
      profiler.updateVisible();

      // ------- Render profiler scene --------

      Scene profilerScene = profiler.scene;
      profilerScene.update();
      Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
      modelBatch.begin(profilerScene.camera.data);
      for (GameObject g : profilerScene.objects) {
        if (g.visible()) {
          modelBatch.render(g.modelInstance, profilerScene.environment);
        }
      }
      modelBatch.end();
    }
    if (profiler.gl.isEnabled()) {
      profiler.gl.updateFields();
    }
  }