示例#1
0
  private static void setupShadowFrameBuffer() {
    if (shadowPassInterval <= 0) {
      return;
    }

    setupShadowRenderTexture();

    glDeleteFramebuffersEXT(sfb);

    sfb = glGenFramebuffersEXT();
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, sfb);

    glDrawBuffer(GL_NONE);
    glReadBuffer(GL_NONE);

    glDeleteRenderbuffersEXT(sfbDepthBuffer);
    sfbDepthBuffer = glGenRenderbuffersEXT();
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, sfbDepthBuffer);
    glRenderbufferStorageEXT(
        GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, shadowMapWidth, shadowMapHeight);
    glFramebufferRenderbufferEXT(
        GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, sfbDepthBuffer);
    glFramebufferTexture2DEXT(
        GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, sfbDepthTexture, 0);

    int status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
      System.out.println("Failed creating shadow framebuffer! (Status " + status + ")");
    }
  }
示例#2
0
  public static void beginWeather() {
    glEnable(GL_BLEND);
    useProgram(Shaders.ProgramWeather);

    if (isShadowPass) {
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // will be set to sbf in endHand()
    }
  }
示例#3
0
  public static void endHand() {
    glDisable(GL_BLEND);
    useProgram(lightmapEnabled ? ProgramTexturedLit : ProgramTextured);

    if (isShadowPass) {
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, sfb); // was set to 0 in beginWeather()
    }
  }
示例#4
0
  public static void beginRender(Minecraft minecraft, float f, long l) {
    if (isShadowPass) {
      return;
    }

    mc = minecraft;

    if (!isInitialized) {
      init();
    }
    if (mc.displayWidth != renderWidth || mc.displayHeight != renderHeight) {
      resize();
    }

    if (shadowPassInterval > 0 && --shadowPassCounter <= 0) {
      // do shadow pass
      preShadowPassThirdPersonView = mc.gameSettings.thirdPersonView;

      mc.gameSettings.thirdPersonView = 1;

      isShadowPass = true;
      shadowPassCounter = shadowPassInterval;

      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, sfb);

      useProgram(ProgramNone);

      mc.entityRenderer.renderWorld(f, l);

      glFlush();

      isShadowPass = false;

      mc.gameSettings.thirdPersonView = preShadowPassThirdPersonView;
    }

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dfb);

    useProgram(lightmapEnabled ? ProgramTexturedLit : ProgramTextured);
  }
示例#5
0
  private static void setupFrameBuffer() {
    setupRenderTextures();

    if (dfb != 0) {
      glDeleteFramebuffersEXT(dfb);
      glDeleteRenderbuffersEXT(dfbRenderBuffers);
    }

    dfb = glGenFramebuffersEXT();
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dfb);

    glGenRenderbuffersEXT(dfbRenderBuffers);

    for (int i = 0; i < colorAttachments; ++i) {
      glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, dfbRenderBuffers.get(i));
      if (i == 1) { // depth buffer
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB32F_ARB, renderWidth, renderHeight);
      } else {
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, renderWidth, renderHeight);
      }
      glFramebufferRenderbufferEXT(
          GL_FRAMEBUFFER_EXT, dfbDrawBuffers.get(i), GL_RENDERBUFFER_EXT, dfbRenderBuffers.get(i));
      glFramebufferTexture2DEXT(
          GL_FRAMEBUFFER_EXT, dfbDrawBuffers.get(i), GL_TEXTURE_2D, dfbTextures.get(i), 0);
    }

    glDeleteRenderbuffersEXT(dfbDepthBuffer);
    dfbDepthBuffer = glGenRenderbuffersEXT();
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, dfbDepthBuffer);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, renderWidth, renderHeight);
    glFramebufferRenderbufferEXT(
        GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, dfbDepthBuffer);

    int status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
      System.out.println("Failed creating framebuffer! (Status " + status + ")");
    }
  }
示例#6
0
  public static void endRender() {
    if (isShadowPass) {
      return;
    }

    glPushMatrix();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glDisable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);

    // composite

    glDisable(GL_BLEND);

    useProgram(ProgramComposite);

    glDrawBuffers(dfbDrawBuffers);

    glBindTexture(GL_TEXTURE_2D, dfbTextures.get(0));
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, dfbTextures.get(1));
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, dfbTextures.get(2));
    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D, dfbTextures.get(3));

    if (colorAttachments >= 5) {
      glActiveTexture(GL_TEXTURE4);
      glBindTexture(GL_TEXTURE_2D, dfbTextures.get(4));
      if (colorAttachments >= 6) {
        glActiveTexture(GL_TEXTURE5);
        glBindTexture(GL_TEXTURE_2D, dfbTextures.get(5));
        if (colorAttachments >= 7) {
          glActiveTexture(GL_TEXTURE6);
          glBindTexture(GL_TEXTURE_2D, dfbTextures.get(6));
        }
      }
    }

    if (shadowPassInterval > 0) {
      glActiveTexture(GL_TEXTURE7);
      glBindTexture(GL_TEXTURE_2D, sfbDepthTexture);
    }

    glActiveTexture(GL_TEXTURE0);

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0.0f, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(1.0f, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(1.0f, 1.0f, 0.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0.0f, 1.0f, 0.0f);
    glEnd();

    // final

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

    useProgram(ProgramFinal);

    glClearColor(clearColor[0], clearColor[1], clearColor[2], 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBindTexture(GL_TEXTURE_2D, dfbTextures.get(0));
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, dfbTextures.get(1));
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, dfbTextures.get(2));
    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D, dfbTextures.get(3));

    if (colorAttachments >= 5) {
      glActiveTexture(GL_TEXTURE4);
      glBindTexture(GL_TEXTURE_2D, dfbTextures.get(4));
      if (colorAttachments >= 6) {
        glActiveTexture(GL_TEXTURE5);
        glBindTexture(GL_TEXTURE_2D, dfbTextures.get(5));
        if (colorAttachments >= 7) {
          glActiveTexture(GL_TEXTURE6);
          glBindTexture(GL_TEXTURE_2D, dfbTextures.get(6));
        }
      }
    }

    if (shadowPassInterval > 0) {
      glActiveTexture(GL_TEXTURE7);
      glBindTexture(GL_TEXTURE_2D, sfbDepthTexture);
    }

    glActiveTexture(GL_TEXTURE0);

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0.0f, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(1.0f, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(1.0f, 1.0f, 0.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0.0f, 1.0f, 0.0f);
    glEnd();

    glEnable(GL_BLEND);

    glPopMatrix();

    useProgram(ProgramNone);
  }