Пример #1
0
    private void writeToTexture(RectanglePacker.Rectangle r, ByteBuffer data) {
      assert r.width * r.height * format.bytes == data.capacity()
          : r + " * " + format.bytes + " != " + data.capacity();

      GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

      GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, format.bytes);

      GL11.glTexSubImage2D(
          GL11.GL_TEXTURE_2D,
          0,
          r.x,
          r.y,
          r.width,
          r.height,
          format.glFormat,
          GL11.GL_UNSIGNED_BYTE,
          data);

      GLUtil.checkGLError();

      if (mipmap) {
        mipmapDirty = true;
      }
    }
Пример #2
0
    private void recreate() {
      id = GL11.glGenTextures();

      GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

      GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, format.bytes);

      ByteBuffer data =
          BufferUtils.createByteBuffer(size.getWidth() * size.getHeight() * format.bytes);

      if (mipmap) {
        GLU.gluBuild2DMipmaps(
            GL11.GL_TEXTURE_2D,
            format.glInternalFormat,
            size.getWidth(),
            size.getHeight(),
            format.glFormat,
            GL11.GL_UNSIGNED_BYTE,
            data);
      } else {
        GL11.glTexImage2D(
            GL11.GL_TEXTURE_2D,
            0,
            format.glInternalFormat,
            size.getWidth(),
            size.getHeight(),
            0,
            format.glFormat,
            GL11.GL_UNSIGNED_BYTE,
            data);
      }
      GLUtil.checkGLError();

      for (Texture t : residentTextures) {
        RectanglePacker.Rectangle rpr = packer.findRectangle(t.getSourceImage());

        if (rpr != null) {
          writeToTexture(rpr, t.getSourceImage().getData());
        }
      }

      regenerateMipmaps();
    }