Пример #1
0
  public Skybox(String texture) {
    vertexBuffer = BufferUtils.newFloatBuffer(72);
    vertexBuffer.put(
        new float[] {
          -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
          -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
          0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f,
          0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f,
          0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f,
          -0.5f, 0.5f, -0.5f, 0.5f
        });
    vertexBuffer.rewind();

    texCoordBuffer = BufferUtils.newFloatBuffer(48);
    texCoordBuffer.put(
        new float[] {
          0.5f, 0.75f, 0.5f, 1.0f, 0.25f, 0.75f, 0.25f, 1.0f, // bottom
          0.25f, 0.75f, 0f, 0.75f, 0.25f, 0.5f, 0f, 0.5f, // left
          0.25f, 0.5f, 0.25f, 0.25f, 0.5f, 0.5f, 0.5f, 0.25f, // top
          0.5f, 0.5f, 0.75f, 0.5f, 0.5f, 0.75f, 0.75f, 0.75f, // right
          0.75f, 0.75f, 0.75f, 0.5f, 1f, 0.75f, 1.0f, 0.5f, // right right
          0.5f, 0.75f, 0.5f, 0.5f, 0.25f, 0.75f, 0.25f, 0.5f, // center
        });
    texCoordBuffer.rewind();

    tex = new Texture(Gdx.files.internal(texture));
    useTexture = true;
  }
Пример #2
0
 public static Face newMemoryFace(Library library, byte[] data, int dataSize, int faceIndex) {
   ByteBuffer buffer = BufferUtils.newUnsafeByteBuffer(data.length);
   BufferUtils.copy(data, 0, buffer, data.length);
   long address = newMemoryFace(library.address, buffer, dataSize, faceIndex);
   if (address == 0) {
     BufferUtils.disposeUnsafeByteBuffer(buffer);
     throw new GdxRuntimeException("Couldn't load font");
   } else {
     library.fontData.put(address, buffer);
     return new Face(address, library);
   }
 }
Пример #3
0
 private static int getMaxTextureUnits() {
   IntBuffer buffer = BufferUtils.newIntBuffer(16);
   if (Gdx.graphics.isGL20Available())
     Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, buffer);
   else Gdx.gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_UNITS, buffer);
   return buffer.get(0);
 }
Пример #4
0
    public ETC1Data(FileHandle pkmFile) {
      byte[] buffer = new byte[1024 * 10];
      DataInputStream in = null;
      try {
        in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(pkmFile.read())));
        int fileSize = in.readInt();
        compressedData = BufferUtils.newUnsafeByteBuffer(fileSize);
        int readBytes = 0;
        while ((readBytes = in.read(buffer)) != -1) {
          compressedData.put(buffer, 0, readBytes);
        }
        compressedData.position(0);
        compressedData.limit(compressedData.capacity());
      } catch (Exception e) {
        throw new GdxRuntimeException("Couldn't load pkm file '" + pkmFile + "'", e);
      } finally {
        if (in != null)
          try {
            in.close();
          } catch (Exception e) {
          }
      }

      width = getWidthPKM(compressedData, 0);
      height = getHeightPKM(compressedData, 0);
      dataOffset = PKM_HEADER_SIZE;
      compressedData.position(dataOffset);
    }
Пример #5
0
  private void convertMesh(ModelMesh modelMesh) {
    int numIndices = 0;
    for (ModelMeshPart part : modelMesh.parts) {
      numIndices += part.indices.length;
    }
    VertexAttributes attributes = new VertexAttributes(modelMesh.attributes);
    int numVertices = modelMesh.vertices.length / (attributes.vertexSize / 4);

    Mesh mesh = new Mesh(true, numVertices, numIndices, attributes);
    meshes.add(mesh);
    disposables.add(mesh);

    BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(), modelMesh.vertices.length, 0);
    int offset = 0;
    mesh.getIndicesBuffer().clear();
    for (ModelMeshPart part : modelMesh.parts) {
      MeshPart meshPart = new MeshPart();
      meshPart.id = part.id; // FIXME not storing the mesh name, part ids may collide!
      meshPart.primitiveType = part.primitiveType;
      meshPart.indexOffset = offset;
      meshPart.numVertices = part.indices.length;
      meshPart.mesh = mesh;
      mesh.getIndicesBuffer().put(part.indices);
      offset += meshPart.numVertices;
      meshParts.add(meshPart);
    }
    mesh.getIndicesBuffer().position(0);
  }
Пример #6
0
  protected void convertMesh(ModelMesh modelMesh) {
    int numIndices = 0;
    for (ModelMeshPart part : modelMesh.parts) {
      numIndices += part.indices.length;
    }
    VertexAttributes attributes = new VertexAttributes(modelMesh.attributes);
    int numVertices = modelMesh.vertices.length / (attributes.vertexSize / 4);

    Mesh mesh = new Mesh(true, numVertices, numIndices, attributes);
    meshes.add(mesh);
    disposables.add(mesh);

    BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(), modelMesh.vertices.length, 0);
    int offset = 0;
    mesh.getIndicesBuffer().clear();
    for (ModelMeshPart part : modelMesh.parts) {
      MeshPart meshPart = new MeshPart();
      meshPart.id = part.id;
      meshPart.primitiveType = part.primitiveType;
      meshPart.offset = offset;
      meshPart.size = part.indices.length;
      meshPart.mesh = mesh;
      mesh.getIndicesBuffer().put(part.indices);
      offset += meshPart.size;
      meshParts.add(meshPart);
    }
    mesh.getIndicesBuffer().position(0);
    for (MeshPart part : meshParts) part.update();
  }
Пример #7
0
 public static void doneFace(Face face) {
   doneFace(face.address);
   ByteBuffer buffer = face.library.fontData.get(face.address);
   if (buffer != null) {
     face.library.fontData.remove(face.address);
     BufferUtils.disposeUnsafeByteBuffer(buffer);
   }
 }
Пример #8
0
 @Override
 public void setVertices(float[] vertices, int offset, int count) {
   isDirty = true;
   BufferUtils.copy(vertices, buffer, count, offset);
   buffer.position(0);
   buffer.limit(count);
   bufferChanged();
 }
Пример #9
0
  /**
   * Constructs a new interleaved VertexBufferObject.
   *
   * @param isStatic whether the vertex data is static.
   * @param numVertices the maximum number of vertices
   * @param attributes the {@link VertexAttributes}.
   */
  public VertexArrayEmulator(boolean isStatic, int numVertices, VertexAttributes attributes) {
    this.isStatic = isStatic;
    this.attributes = attributes;

    buffer = BufferUtils.newFloatBuffer(this.attributes.vertexSize / 4 * numVertices);
    buffer.flip();
    bufferHandle = Gdx.gl20.glGenBuffer();
    usage = isStatic ? GL20.GL_STATIC_DRAW : GL20.GL_DYNAMIC_DRAW;
  }
Пример #10
0
 @Override
 public void updateVertices(int targetOffset, float[] vertices, int sourceOffset, int count) {
   isDirty = true;
   final int pos = buffer.position();
   buffer.position(targetOffset);
   BufferUtils.copy(vertices, sourceOffset, count, buffer);
   buffer.position(pos);
   bufferChanged();
 }
 public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) {
   final int len = (int) fileHandle.length();
   if (len <= 0) throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified");
   java.nio.ByteBuffer buff = BufferUtils.newByteBuffer(len);
   buff.put(fileHandle.readBytes());
   buff.position(0);
   boolean result = loadFileFromMemory(buff, len);
   //		com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff);
   return result;
 }
Пример #12
0
  public void CreateWall() {
    vertexBuffer = BufferUtils.newFloatBuffer(72);

    vertexBuffer.put(
        new float[] {
          -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
          -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
          0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f,
          0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f,
          0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f,
          -0.5f, 0.5f, -0.5f, 0.5f
        });
    vertexBuffer.rewind();

    texCoordBuffer = BufferUtils.newFloatBuffer(8);
    texCoordBuffer.put(new float[] {0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f});
    texCoordBuffer.rewind();

    // tex = new Texture(Gdx.files.internal("textures/block.jpg"));
  }
Пример #13
0
  public static void create(int vertexPointer) {

    CannonGraphic.vertexPointer = vertexPointer;

    // VERTEX ARRAY IS FILLED HERE
    float[] array = {-20f, 60f, -20f, -60f, 20f, -60f, 20f, 60f};

    vertexBuffer = BufferUtils.newFloatBuffer(8);
    vertexBuffer.put(array);
    vertexBuffer.rewind();
  }
Пример #14
0
 /** @return Pixmap representing the glyph, needs to be disposed manually. */
 public Pixmap getPixmap(Format format) {
   Pixmap pixmap = new Pixmap(getWidth(), getRows(), Format.Alpha);
   BufferUtils.copy(getBuffer(), pixmap.getPixels(), pixmap.getPixels().capacity());
   Pixmap converted = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), format);
   Blending blending = Pixmap.getBlending();
   Pixmap.setBlending(Blending.None);
   converted.drawPixmap(pixmap, 0, 0);
   Pixmap.setBlending(blending);
   pixmap.dispose();
   return converted;
 }
Пример #15
0
            @Override
            public void run() {
              ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024 * Float.SIZE / 8);
              buffer.order(ByteOrder.nativeOrder());
              FloatBuffer floatBuffer = buffer.asFloatBuffer();
              IntBuffer intBuffer = buffer.asIntBuffer();

              float[] floatArray = new float[1024 * 1024];
              int[] intArray = new int[1024 * 1024];

              // single put
              tic();
              for (int tries = 0; tries < TRIES; tries++) {
                for (int i = 0; i < floatArray.length; i++) floatBuffer.put(floatArray[i]);
                floatBuffer.clear();
              }
              toc("single put");

              // single indexed put
              tic();
              for (int tries = 0; tries < TRIES; tries++) {
                for (int i = 0; i < floatArray.length; i++) floatBuffer.put(i, floatArray[i]);
                floatBuffer.clear();
              }
              toc("single indexed put");

              // bulk put
              tic();
              for (int tries = 0; tries < TRIES; tries++) {
                floatBuffer.put(floatArray);
                floatBuffer.clear();
              }
              toc("vector put");

              // convert bulk put
              tic();
              for (int tries = 0; tries < TRIES; tries++) {
                for (int i = 0; i < floatArray.length; i++)
                  intArray[i] = Float.floatToIntBits(floatArray[i]);
                intBuffer.put(intArray);
                intBuffer.clear();
              }
              toc("convert bulk put");

              // jni bulk put
              tic();
              for (int tries = 0; tries < TRIES; tries++) {
                BufferUtils.copy(floatArray, floatBuffer, floatArray.length, 0);
                floatBuffer.clear();
              }
              toc("jni bulk put");
            }
Пример #16
0
  /** Releases all resources associated with the FrameBuffer. */
  public void dispose() {
    GL20 gl = Gdx.graphics.getGL20();

    IntBuffer handle = BufferUtils.newIntBuffer(1);

    colorTexture.dispose();
    if (hasDepth) {
      handle.put(depthbufferHandle);
      handle.flip();
      gl.glDeleteRenderbuffers(1, handle);
    }

    handle.clear();
    handle.put(framebufferHandle);
    handle.flip();
    gl.glDeleteFramebuffers(1, handle);

    if (buffers.get(Gdx.app) != null) buffers.get(Gdx.app).removeValue(this, true);
  }
Пример #17
0
 /** Releases the native resources of the ETC1Data instance. */
 public void dispose() {
   BufferUtils.disposeUnsafeByteBuffer(compressedData);
 }
Пример #18
0
 private static int getMaxTextureUnits() {
   IntBuffer buffer = BufferUtils.newIntBuffer(16);
   Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, buffer);
   return buffer.get(0);
 }
Пример #19
0
  private void build() {
    if (!Gdx.graphics.isGL20Available()) throw new GdxRuntimeException("GL2 is required.");

    GL20 gl = Gdx.graphics.getGL20();

    // iOS uses a different framebuffer handle! (not necessarily 0)
    if (!defaultFramebufferHandleInitialized) {
      defaultFramebufferHandleInitialized = true;
      if (Gdx.app.getType() == ApplicationType.iOS) {
        IntBuffer intbuf =
            ByteBuffer.allocateDirect(16 * Integer.SIZE / 8)
                .order(ByteOrder.nativeOrder())
                .asIntBuffer();
        gl.glGetIntegerv(GL20.GL_FRAMEBUFFER_BINDING, intbuf);
        defaultFramebufferHandle = intbuf.get(0);
      } else {
        defaultFramebufferHandle = 0;
      }
    }

    setupTexture();

    IntBuffer handle = BufferUtils.newIntBuffer(1);
    gl.glGenFramebuffers(1, handle);
    framebufferHandle = handle.get(0);

    if (hasDepth) {
      handle.clear();
      gl.glGenRenderbuffers(1, handle);
      depthbufferHandle = handle.get(0);
    }

    gl.glBindTexture(GL20.GL_TEXTURE_2D, colorTexture.getTextureObjectHandle());

    if (hasDepth) {
      gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, depthbufferHandle);
      gl.glRenderbufferStorage(
          GL20.GL_RENDERBUFFER,
          GL20.GL_DEPTH_COMPONENT16,
          colorTexture.getWidth(),
          colorTexture.getHeight());
    }

    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, framebufferHandle);
    gl.glFramebufferTexture2D(
        GL20.GL_FRAMEBUFFER,
        GL20.GL_COLOR_ATTACHMENT0,
        GL20.GL_TEXTURE_2D,
        colorTexture.getTextureObjectHandle(),
        0);
    if (hasDepth) {
      gl.glFramebufferRenderbuffer(
          GL20.GL_FRAMEBUFFER, GL20.GL_DEPTH_ATTACHMENT, GL20.GL_RENDERBUFFER, depthbufferHandle);
    }
    int result = gl.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);

    gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, 0);
    gl.glBindTexture(GL20.GL_TEXTURE_2D, 0);
    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, defaultFramebufferHandle);

    if (result != GL20.GL_FRAMEBUFFER_COMPLETE) {
      colorTexture.dispose();
      if (hasDepth) {
        handle.clear();
        handle.put(depthbufferHandle);
        handle.flip();
        gl.glDeleteRenderbuffers(1, handle);
      }

      colorTexture.dispose();
      handle.clear();
      handle.put(framebufferHandle);
      handle.flip();
      gl.glDeleteFramebuffers(1, handle);

      if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)
        throw new IllegalStateException(
            "frame buffer couldn't be constructed: incomplete attachment");
      if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS)
        throw new IllegalStateException(
            "frame buffer couldn't be constructed: incomplete dimensions");
      if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
        throw new IllegalStateException("frame buffer couldn't be constructed: missing attachment");
      if (result == GL20.GL_FRAMEBUFFER_UNSUPPORTED)
        throw new IllegalStateException(
            "frame buffer couldn't be constructed: unsupported combination of formats");
      throw new IllegalStateException(
          "frame buffer couldn't be constructed: unknown error " + result);
    }
  }
 public void setHardwareBufferNeedsUpdate() {
   BufferUtils.copy(mBufferData, mFloatBuffer, mFloatBuffer.capacity(), 0);
   this.mHardwareBufferNeedsUpdate = true;
 }
 public BufferObject(final int pCapacity, final int pDrawType) {
   this.mDrawType = pDrawType;
   this.mBufferData = new float[pCapacity];
   this.mFloatBuffer = BufferUtils.newFloatBuffer(pCapacity);
 }
Пример #22
0
 public static void doneFreeType(Library library) {
   doneFreeType(library.address);
   for (ByteBuffer buffer : library.fontData.values()) {
     BufferUtils.disposeUnsafeByteBuffer(buffer);
   }
 }