Exemplo n.º 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 + ")");
    }
  }
 void read(ByteBuffer buffer) {
   EXTFramebufferObject.glBindFramebufferEXT(
       EXTFramebufferObject.GL_FRAMEBUFFER_EXT, frameBuffer);
   buffer.position(0);
   GL11.glReadPixels(
       x0, y0, width, height, MipmapHelper.TEX_FORMAT, MipmapHelper.TEX_DATA_TYPE, buffer);
 }
Exemplo n.º 3
0
 public void activate() {
   if (framebuffer == INVALID_BUFFER) return; // Can't set this to active if it's not created yet
   if (useEXT)
     EXTFramebufferObject.glBindFramebufferEXT(
         EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebuffer);
   else GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
   GL11.glViewport(0, 0, width, height);
 }
Exemplo n.º 4
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()
    }
  }
Exemplo n.º 5
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()
    }
  }
Exemplo n.º 6
0
 public void release() {
   if (framebuffer != INVALID_BUFFER) {
     if (useEXT)
       EXTFramebufferObject.glBindFramebufferEXT(
           EXTFramebufferObject.GL_FRAMEBUFFER_EXT, SCREEN_BUFFER);
     else GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, SCREEN_BUFFER);
     GL11.glViewport(0, 0, width, height);
   }
 }
Exemplo n.º 7
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);
  }
    void unbind() {
      GL11.glPopAttrib();

      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glPopMatrix();

      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glPopMatrix();

      if (lightmapEnabled) {
        GL13.glActiveTexture(GL13.GL_TEXTURE1);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
      }
      GL11.glEnable(GL11.GL_BLEND);
      GLAPI.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

      EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
    }
    void bind() {
      EXTFramebufferObject.glBindFramebufferEXT(
          EXTFramebufferObject.GL_FRAMEBUFFER_EXT, frameBuffer);

      GL11.glPushAttrib(glAttributes);
      GL11.glViewport(x0, y0, width, height);
      GL11.glEnable(GL11.GL_SCISSOR_TEST);
      GL11.glScissor(x0, y0, width, height);

      lightmapEnabled = false;
      if (gl13Supported) {
        GL13.glActiveTexture(GL13.GL_TEXTURE1);
        lightmapEnabled = GL11.glIsEnabled(GL11.GL_TEXTURE_2D);
        if (lightmapEnabled) {
          GL11.glDisable(GL11.GL_TEXTURE_2D);
        }
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
      }
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glDisable(GL11.GL_DEPTH_TEST);
      GLAPI.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
      GL11.glDisable(GL11.GL_LIGHTING);
      GL11.glEnable(GL11.GL_ALPHA_TEST);
      GLAPI.glAlphaFunc(GL11.GL_GREATER, 0.01f);
      if (useGL13) {
        GL11.glDisable(GL13.GL_MULTISAMPLE);
      }

      GLAPI.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glPushMatrix();
      GL11.glLoadIdentity();
      GL11.glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);

      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glPushMatrix();
      GL11.glLoadIdentity();
    }
    private FBO(int texture, boolean ownTexture, int x0, int y0, int width, int height) {
      this.texture = texture;
      this.ownTexture = ownTexture;
      this.x0 = x0;
      this.y0 = y0;
      this.width = width;
      this.height = height;

      frameBuffer = EXTFramebufferObject.glGenFramebuffersEXT();
      if (frameBuffer < 0) {
        throw new RuntimeException("could not get framebuffer object");
      }
      GLAPI.glBindTexture(texture);
      EXTFramebufferObject.glBindFramebufferEXT(
          EXTFramebufferObject.GL_FRAMEBUFFER_EXT, frameBuffer);
      EXTFramebufferObject.glFramebufferTexture2DEXT(
          EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
          EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT,
          GL11.GL_TEXTURE_2D,
          texture,
          0);
    }
Exemplo n.º 11
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 + ")");
    }
  }
 public static boolean update(TextureAtlasSprite icon, boolean itemFrameRenderer) {
   if (!initialized) {
     logger.finer("deferring %s update until initialization finishes", IconAPI.getIconName(icon));
     return false;
   }
   if (!active) {
     return false;
   }
   int oldFB = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
   if (oldFB != 0 && warnCount < 10) {
     logger.finer(
         "rendering %s while non-default framebuffer %d is active",
         IconAPI.getIconName(icon), oldFB);
     warnCount++;
   }
   int oldTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
   try {
     FancyDial instance = getInstance(icon);
     return instance != null && instance.render(itemFrameRenderer);
   } finally {
     EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFB);
     GLAPI.glBindTexture(oldTexture);
   }
 }
Exemplo n.º 13
0
 public void glBindFramebuffer(int target, int framebuffer) {
   EXTFramebufferObject.glBindFramebufferEXT(target, framebuffer);
 }
Exemplo n.º 14
0
  @Override
  public void writeGPU() {
    if (framebuffer != INVALID_BUFFER)
      throw new IllegalStateException("Framebuffer already created!");

    // Create the color buffer for this renderTexture
    textureID = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexImage2D(
        GL11.GL_TEXTURE_2D,
        0,
        GL11.GL_RGBA8,
        width,
        height,
        0,
        GL11.GL_RGBA,
        GL11.GL_INT,
        (java.nio.ByteBuffer) null); // Create the texture data

    if (useEXT) {
      framebuffer = EXTFramebufferObject.glGenFramebuffersEXT();

      EXTFramebufferObject.glBindFramebufferEXT(
          EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebuffer);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

      EXTFramebufferObject.glFramebufferTexture2DEXT(
          EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
          EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT,
          GL11.GL_TEXTURE_2D,
          textureID,
          0);

      if (useDepthBuffer) {
        depthTarget = GL30.glGenRenderbuffers();
        EXTFramebufferObject.glBindRenderbufferEXT(
            EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthTarget);
        EXTFramebufferObject.glRenderbufferStorageEXT(
            EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            GL11.GL_DEPTH_COMPONENT,
            this.getWidth(),
            this.getHeight());
        EXTFramebufferObject.glFramebufferRenderbufferEXT(
            EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            GL30.GL_DEPTH_ATTACHMENT,
            EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            depthTarget);
      }

      if (EXTFramebufferObject.glCheckFramebufferStatusEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT)
          != EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT) {
        System.out.println("ERROR: Framebuffer not complete");
        throw new ComputerIsPotatoException("Framebuffer not complete");
      }

    } else {
      framebuffer = GL30.glGenFramebuffers();
      GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

      GL30.glFramebufferTexture2D(
          GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, textureID, 0);

      if (useDepthBuffer) {
        depthTarget = GL30.glGenRenderbuffers();
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthTarget);
        GL30.glRenderbufferStorage(
            GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, this.getWidth(), this.getHeight());
        GL30.glFramebufferRenderbuffer(
            GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthTarget);
      }
      GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, SCREEN_BUFFER);

      if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) {
        System.out.println("ERROR: Framebuffer not complete");
        throw new ComputerIsPotatoException("Framebuffer not complete");
      }
    }
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
  }
Exemplo n.º 15
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);
  }