示例#1
0
文件: Bdx.java 项目: colepram/bdx
 public static void dispose() {
   modelBatch.dispose();
   spriteBatch.dispose();
   frameBuffer.dispose();
   tempBuffer.dispose();
   shaderProvider.dispose();
   for (ShaderProgram s : Bdx.matShaders.values()) {
     s.dispose();
   }
 }
示例#2
0
文件: Bdx.java 项目: colepram/bdx
  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();
    }
  }