private void renderToFB(double angle, FBO fbo) {
   if (fbo != null) {
     fbo.bind();
     renderImpl(angle);
     fbo.unbind();
   }
 }
Exemplo n.º 2
0
  public void renderingToFBO(
      GL2GL3 gl, FBO fbo, int offsetx, int offsety, int width, int height, boolean show) {
    shader.use(gl);
    fbo.bind(gl);
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    gl.glViewport(offsetx, offsety, width, height);

    shader.use(gl);
    updateligths(gl, shader);
    scene(gl, shader, show);

    shadertess.use(gl);
    updateligths(gl, shadertess);
    scenetess((GL3) gl, shadertess);
    shadertess.unuse(gl);

    fbo.unbind(gl);
    gl.glFlush();
  }
Exemplo n.º 3
0
  public void ShadowMap(GL2GL3 gl, boolean show) {
    smapfbo.bind(gl);
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    gl.glViewport(0, 0, smapwidth, smapheight);

    shadowmapshadertess.use(gl);
    gl.glUniform1i(gl.glGetUniformLocation(shadowmapshadertess.getID(), "stage"), 0);
    smapupdatelightstess(gl);
    scenetess((GL4) gl, shadowmapshadertess);

    shadowmapshader.use(gl);
    gl.glUniform1i(gl.glGetUniformLocation(shadowmapshader.getID(), "stage"), 0);
    smapupdatelights(gl);
    scene(gl, shadowmapshader, show);

    gl.glFlush();
    smapfbo.unbind(gl);
    Shader.unuse(gl);
  }
 private void finish() {
   for (int i = 0; i < scratchFBO.length; i++) {
     if (scratchFBO[i] != null) {
       scratchFBO[i].delete();
       scratchFBO[i] = null;
     }
   }
   if (itemsFBO != null) {
     itemsFBO.delete();
     itemsFBO = null;
   }
   itemFrames.clear();
   layers.clear();
   ok = false;
 }
  private void writeCustomImage() {
    try {
      BufferedImage image =
          new BufferedImage(width, outputFrames * height, BufferedImage.TYPE_INT_ARGB);
      IntBuffer intBuffer = scratchBuffer.asIntBuffer();
      int[] argb = new int[width * height];
      File path = MCPatcherUtils.getGamePath("custom_" + name + ".png");
      logger.info("generating %d %s frames", outputFrames, name);
      for (int i = 0; i < outputFrames; i++) {
        renderToItems(i * (360.0 / outputFrames));
        itemsFBO.read(scratchBuffer);
        intBuffer.position(0);
        for (int j = 0; j < argb.length; j++) {
          switch (MipmapHelper.TEX_FORMAT) {
            case GL12.GL_BGRA:
              int bgra = intBuffer.get(j);
              argb[j] =
                  (bgra << 24) | ((bgra & 0xff00) << 8) | ((bgra & 0xff0000) >> 8) | (bgra >>> 24);
              break;

            default:
              if (i == 0 && j == 0) {
                logger.warning(
                    "unhandled texture format %d, color channels may be incorrect",
                    MipmapHelper.TEX_FORMAT);
              }
              // fall through

            case GL11.GL_RGBA:
              argb[j] = Integer.rotateRight(intBuffer.get(j), 8);
              break;
          }
        }
        image.setRGB(0, i * height, width, height, argb, 0, width);
      }
      ImageIO.write(image, "png", path);
      logger.info("wrote %dx%d %s", image.getWidth(), image.getHeight(), path.getPath());
    } catch (Throwable e) {
      e.printStackTrace();
    }
  }
  private boolean render(boolean itemFrameRenderer) {
    if (!ok) {
      return false;
    }

    if (!itemFrameRenderer) {
      boolean changed = true;
      if (!keyboard.isEnabled()) {
        changed = false;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_NUMPAD2)) {
        scaleYDelta -= STEP;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_NUMPAD8)) {
        scaleYDelta += STEP;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_NUMPAD4)) {
        scaleXDelta -= STEP;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_NUMPAD6)) {
        scaleXDelta += STEP;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_DOWN)) {
        offsetYDelta += STEP;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_UP)) {
        offsetYDelta -= STEP;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_LEFT)) {
        offsetXDelta -= STEP;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_RIGHT)) {
        offsetXDelta += STEP;
      } else if (keyboard.isKeyPressed(Keyboard.KEY_MULTIPLY)) {
        scaleXDelta = scaleYDelta = offsetXDelta = offsetYDelta = 0.0f;
      } else {
        changed = false;
      }
      if (changed) {
        logger.info("");
        logger.info("scaleX  %+f", scaleXDelta);
        logger.info("scaleY  %+f", scaleYDelta);
        logger.info("offsetX %+f", offsetXDelta);
        logger.info("offsetY %+f", offsetYDelta);
        lastAngle = ANGLE_UNSET;
      }

      if (outputFrames > 0) {
        writeCustomImage();
        outputFrames = 0;
      }
    }

    double angle = getAngle(icon);
    if (!useScratchTexture) {
      // render directly to items.png
      if (angle != lastAngle) {
        renderToItems(angle);
        lastAngle = angle;
      }
    } else if (itemFrameRenderer) {
      // look in itemFrames cache first
      ByteBuffer buffer = itemFrames.get(angle);
      if (buffer == null) {
        logger.fine("rendering %s at angle %f for item frame", name, angle);
        buffer = ByteBuffer.allocateDirect(width * height * 4);
        renderToItems(angle);
        itemsFBO.read(buffer);
        itemFrames.put(angle, buffer);
      } else {
        itemsFBO.write(buffer);
      }
      lastItemFrameRenderer = true;
    } else if (lastAngle == ANGLE_UNSET) {
      // first time rendering - render all N copies
      for (FBO fbo : scratchFBO) {
        renderToFB(angle, fbo);
      }
      scratchFBO[0].read(scratchBuffer);
      itemsFBO.write(scratchBuffer);
      lastAngle = angle;
      scratchIndex = 0;
    } else if (lastItemFrameRenderer || angle != lastAngle) {
      // render to buffer i + 1
      // update items.png from buffer i
      int nextIndex = (scratchIndex + 1) % NUM_SCRATCH_TEXTURES;
      if (angle != lastAngle) {
        renderToFB(angle, scratchFBO[nextIndex]);
        scratchFBO[scratchIndex].read(scratchBuffer);
      }
      itemsFBO.write(scratchBuffer);
      lastAngle = angle;
      scratchIndex = nextIndex;
      lastItemFrameRenderer = false;
    }

    int glError = GL11.glGetError();
    if (glError != 0) {
      logger.severe("%s during %s update", GLU.gluErrorString(glError), name);
      ok = false;
    }
    return ok;
  }
Exemplo n.º 7
0
  public void initShadowmap(GL2GL3 gl, int lightcount, int width, int height) {
    initLight(lightcount);

    Ctrlpanel.getInstance().addLightCtrl(realLightcount, this);
    smapwidth = width;
    smapheight = height;

    Tex2DArray shadowmap =
        new Tex2DArray(
            GL2.GL_RGB16,
            GL2.GL_RGB,
            GL.GL_FLOAT,
            smapwidth,
            smapheight,
            realLightcount,
            GL.GL_LINEAR,
            "shadowmap");
    Tex2DArray shadowmapdepth =
        new Tex2DArray(
            GL2.GL_DEPTH_COMPONENT,
            GL2.GL_DEPTH_COMPONENT,
            GL.GL_FLOAT,
            smapwidth,
            smapheight,
            realLightcount,
            GL.GL_LINEAR,
            "shadowmapdepth");
    shadowmap.init(gl);
    shadowmapdepth.init(gl);
    shadowmapB = tum.bind(gl, shadowmap);
    smapfbo = new FBO(gl);
    smapfbo.attachTexture(gl, shadowmapB);
    smapfbo.attachDepth(gl, shadowmapdepth);

    /*シャドウマップ*/
    shadowmapshader =
        new Shader(
            "resources/ShaderSource/BaseShaders/Shadowmap/vertsimple.c",
            null,
            null,
            smapgsrc,
            smapfsrc);
    shadowmapshader.init(gl);
    shadowmapshader.use(gl);

    uniformlightsview = gl.glGetUniformLocation(shadowmapshader.getID(), "lightsview");
    uniformlightsproj = gl.glGetUniformLocation(shadowmapshader.getID(), "lightsproj");
    uniformlightscolor = gl.glGetUniformLocation(shadowmapshader.getID(), "lightscolor");
    uniformlightsattr = gl.glGetUniformLocation(shadowmapshader.getID(), "lightsattr");
    uniformlightcount = gl.glGetUniformLocation(shadowmapshader.getID(), "lightcount_real_virtual");

    /*シャドウマップテッセレーション*/
    shadowmapshadertess = new Shader(smapvsrc, smapcsrc, smapesrc, smapgsrc, smapfsrc);
    shadowmapshadertess.init(gl);
    shadowmapshadertess.use(gl);
    uniformlightsviewtess = gl.glGetUniformLocation(shadowmapshadertess.getID(), "lightsview");
    uniformlightsprojtess = gl.glGetUniformLocation(shadowmapshadertess.getID(), "lightsproj");
    uniformlightscolortess = gl.glGetUniformLocation(shadowmapshadertess.getID(), "lightscolor");
    uniformlightsattrtess = gl.glGetUniformLocation(shadowmapshader.getID(), "lightsattr");
    uniformlightcounttess =
        gl.glGetUniformLocation(shadowmapshadertess.getID(), "lightcount_real_virtual");
  }