Beispiel #1
0
 /**
  * maps all or part of the data store of a buffer object into the client's address space. offset
  * and length indicate the range of data in the buffer object that is to be mapped, in terms of
  * basic machine units. access is a bitfield containing flags which describe the requested
  * mapping. These flags are described below.
  *
  * <p>If no error occurs, a pointer to the beginning of the mapped range is returned once all
  * pending operations on that buffer have completed, and may be used to modify and/or query the
  * corresponding range of the buffer, according to the following flag bits set in access:
  *
  * <ul>
  *   <li>{@linkplain #MAP_READ_BIT}
  *   <li>{@linkplain #MAP_WRITE_BIT}
  * </ul>
  *
  * Furthermore, the following optional flag bits in access may be used to modify the mapping:
  *
  * <ul>
  *   <li>{@linkplain #MAP_INVALIDATE_RANGE_BIT}
  *   <li>{@linkplain #MAP_INVALIDATE_BUFFER_BIT}
  *   <li>{@linkplain #MAP_FLUSH_EXPLICIT_BIT}
  *   <li>{@linkplain #MAP_UNSYNCHRONIZED_BIT}
  * </ul>
  *
  * <p>If an error occurs, glMapBufferRange returns a NULL pointer. If no error occurs, the
  * returned pointer will reflect an alignment of at least GL_MIN_MAP_BUFFER_ALIGNMENT basic
  * machine units. The value of GL_MIN_MAP_BUFFER_ALIGNMENT can be retrieved by calling glGet with
  * pname set to GL_MIN_MAP_BUFFER_ALIGNMENT and must be a power of two that is at least 64.
  * Subtracting offset from this returned pointed will always produce a multiple of
  * GL_MIN_MAP_BUFFER_ALINMENT.
  */
 public ByteBuffer mapRange(int theOffset, int theLength, int theAccess) {
   bind();
   GL4 gl = GLGraphics.currentGL();
   ByteBuffer myResult = gl.glMapBufferRange(_myTarget.glID, theOffset, theLength, theAccess);
   //		unbind();
   return myResult;
 }
  @Override
  protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    {
      gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
      ByteBuffer pointer =
          gl4.glMapBufferRange(
              GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

      Mat4 projection =
          glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f);
      Mat4 model = new Mat4(1.0f);

      pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

      // Make sure the uniform buffer is uploaded
      gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, new float[] {1.0f, 0.5f, 0.0f, 1.0f}, 0);

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBufferBase(
        GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glDrawElementsInstancedBaseVertexBaseInstance(
        GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

    return true;
  }