示例#1
0
  public void setupBuffers(GL4 gl, int[] vbo, int index) {
    this.vbo = vbo;
    this.index = index;

    Vertex3D[] vertices = myShape.getVertices();
    int[] indices = myShape.getIndices();

    float[] fvalues = new float[indices.length * 3];
    float[] tvalues = new float[indices.length * 2];
    float[] nvalues = new float[indices.length * 3];

    for (int i = 0; i < indices.length; i++) {
      fvalues[i * 3] = (float) (vertices[indices[i]]).getX();
      fvalues[i * 3 + 1] = (float) (vertices[indices[i]]).getY();
      fvalues[i * 3 + 2] = (float) (vertices[indices[i]]).getZ();
      tvalues[i * 2] = (float) (vertices[indices[i]]).getS();
      tvalues[i * 2 + 1] = (float) (vertices[indices[i]]).getT();
      nvalues[i * 3] = (float) (vertices[indices[i]]).getNormalX();
      nvalues[i * 3 + 1] = (float) (vertices[indices[i]]).getNormalY();
      nvalues[i * 3 + 2] = (float) (vertices[indices[i]]).getNormalZ();
    }

    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index++]);
    FloatBuffer vertBuf = FloatBuffer.wrap(fvalues);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, vertBuf.limit() * 4, vertBuf, GL.GL_STATIC_DRAW);

    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index++]);
    FloatBuffer texBuf = FloatBuffer.wrap(tvalues);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, texBuf.limit() * 4, texBuf, GL.GL_STATIC_DRAW);

    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index++]);
    FloatBuffer norBuf = FloatBuffer.wrap(nvalues);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, norBuf.limit() * 4, norBuf, GL.GL_STATIC_DRAW);
  }
  private boolean initBuffer(GL4 gl4) {

    boolean validated = true;

    gl4.glGenBuffers(Buffer.MAX, bufferName);

    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
    gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
    BufferUtils.destroyDirectBuffer(elementBuffer);
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
    FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
    gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
    BufferUtils.destroyDirectBuffer(vertexBuffer);
    gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

    int[] uniformBufferOffset = {0};
    gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0);
    int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset[0]);

    gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
    gl4.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW);
    gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

    return validated;
  }
  private boolean initVertexBuffer(GL4 gl4) {

    gl4.glGenBuffers(Buffer.MAX.ordinal(), bufferName, 0);

    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName[Buffer.ELEMENT.ordinal()]);
    ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
    gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName[Buffer.F64.ordinal()]);
    DoubleBuffer positionBuffer = GLBuffers.newDirectDoubleBuffer(positionData);
    gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW);
    gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

    return checkError(gl4, "initArrayBuffer");
  }
示例#4
0
 public void allocate(
     long theBytes, GLDataAccesFrequency theAccessFrequency, GLDataAccesNature theAccessNature) {
   GL4 gl = GLGraphics.currentGL();
   gl.glBufferData(
       GL.GL_ARRAY_BUFFER,
       theBytes,
       null,
       getAcessFrequencyNature(theAccessFrequency, theAccessNature));
 }
示例#5
0
 /**
  * Creates and initializes a buffer object's data store. Creates a new data store for the buffer
  * object currently bound to target. Any pre-existing data store is deleted. The new data store is
  * created with the specified size in bytes and usage. If data is not <code>null</code>, the data
  * store is initialized with data from this Buffer. In its initial state, the new data store is
  * not mapped, it has a <code>null</code> mapped pointer, and its mapped access is GL_READ_WRITE.
  *
  * <p>usage is a hint to the GL implementation as to how a buffer object's data store will be
  * accessed. This enables the GL implementation to make more intelligent decisions that may
  * significantly impact buffer object performance. It does not, however, constrain the actual
  * usage of the data store. usage can be broken down into two parts: first, the frequency of
  * access (modification and usage), and second, the nature of that access.
  *
  * @param theSize Specifies the size in bytes of the buffer object's new data store.
  * @param theData Specifies a Buffer with data that will be copied into the data store for
  *     initialization, or null if no data is to be copied.
  * @param theAccessFrequency The frequency of gl data access
  * @param theAccessNature The nature of gl data access
  */
 public void data(
     long theSize,
     Buffer theData,
     GLDataAccesFrequency theAccessFrequency,
     GLDataAccesNature theAccessNature) {
   GL4 gl = GLGraphics.currentGL();
   gl.glBufferData(
       _myTarget.glID,
       theSize,
       theData,
       getAcessFrequencyNature(theAccessFrequency, theAccessNature));
   _mySize = theSize;
 }