Java Code Examples for android.opengl.GLES20#glBufferSubData()

The following examples show how to use android.opengl.GLES20#glBufferSubData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraFBORender.java    From AudioVideoCodec with Apache License 2.0 6 votes vote down vote up
/**
 * 创建vbo
 */
private void createVBO() {
    //1. 创建VBO
    int[] vbos = new int[1];
    GLES20.glGenBuffers(vbos.length, vbos, 0);
    vboId = vbos[0];
    //2. 绑定VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboId);
    //3. 分配VBO需要的缓存大小
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertexPoint.length * 4 + texturePoint.length * 4, null, GLES20.GL_STATIC_DRAW);
    //4. 为VBO设置顶点数据的值
    GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, 0, vertexPoint.length * 4, vertexBuffer);
    GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, vertexPoint.length * 4, texturePoint.length * 4, textureBuffer);
    //5. 解绑VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
 
Example 2
Source File: CameraRender.java    From AudioVideoCodec with Apache License 2.0 6 votes vote down vote up
/**
 * 创建vbo
 */
private void createVBO() {
    //1. 创建VBO
    int[] vbos = new int[1];
    GLES20.glGenBuffers(vbos.length, vbos, 0);
    vboId = vbos[0];
    //2. 绑定VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboId);
    //3. 分配VBO需要的缓存大小
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertexData.length * 4 + textureData.length * 4, null, GLES20.GL_STATIC_DRAW);
    //4. 为VBO设置顶点数据的值
    GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, 0, vertexData.length * 4, vertexBuffer);
    GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, vertexData.length * 4, textureData.length * 4, textureBuffer);
    //5. 解绑VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
 
Example 3
Source File: VideoEncodeRender.java    From AudioVideoCodec with Apache License 2.0 6 votes vote down vote up
/**
 * 创建vbo
 */
private void createVBO() {
    //1. 创建VBO
    int[] vbos = new int[1];
    GLES20.glGenBuffers(vbos.length, vbos, 0);
    vboId = vbos[0];
    //2. 绑定VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboId);
    //3. 分配VBO需要的缓存大小
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertexData.length * 4 + textureData.length * 4, null, GLES20.GL_STATIC_DRAW);
    //4. 为VBO设置顶点数据的值
    GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, 0, vertexData.length * 4, vertexBuffer);
    GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, vertexData.length * 4, textureData.length * 4, textureBuffer);
    //5. 解绑VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
 
Example 4
Source File: PointCloudRenderer.java    From justaline-android with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the OpenGL buffer contents to the provided point. Repeated calls with the same point
 * cloud will be ignored.
 */
public void update(PointCloud cloud) {
    if (lastPointCloud == cloud) {
        // Redundant call.
        return;
    }

    ShaderUtil.checkGLError(TAG, "before update");

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo);
    lastPointCloud = cloud;

    // If the VBO is not large enough to fit the new point cloud, resize it.
    numPoints = lastPointCloud.getPoints().remaining() / FLOATS_PER_POINT;
    if (numPoints * BYTES_PER_POINT > vboSize) {
        while (numPoints * BYTES_PER_POINT > vboSize) {
            vboSize *= 2;
        }
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vboSize, null, GLES20.GL_DYNAMIC_DRAW);
    }
    GLES20.glBufferSubData(
            GLES20.GL_ARRAY_BUFFER, 0, numPoints * BYTES_PER_POINT, lastPointCloud.getPoints());
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    ShaderUtil.checkGLError(TAG, "after update");
}
 
Example 5
Source File: PointCloudRenderer.java    From react-native-arcore with MIT License 6 votes vote down vote up
/**
 * Updates the OpenGL buffer contents to the provided point.  Repeated calls with the same
 * point cloud will be ignored.
 */
public void update(PointCloud cloud) {
    if (mLastPointCloud == cloud) {
        // Redundant call.
        return;
    }

    ShaderUtil.checkGLError(TAG, "before update");

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);
    mLastPointCloud = cloud;

    // If the VBO is not large enough to fit the new point cloud, resize it.
    mNumPoints = mLastPointCloud.getPoints().remaining() / FLOATS_PER_POINT;
    if (mNumPoints * BYTES_PER_POINT > mVboSize) {
        while (mNumPoints * BYTES_PER_POINT > mVboSize) {
            mVboSize *= 2;
        }
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVboSize, null, GLES20.GL_DYNAMIC_DRAW);
    }
    GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, 0, mNumPoints * BYTES_PER_POINT,
        mLastPointCloud.getPoints());
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    ShaderUtil.checkGLError(TAG, "after update");
}
 
Example 6
Source File: PointCloudRenderer.java    From poly-sample-android with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the OpenGL buffer contents to the provided point. Repeated calls with the same point
 * cloud will be ignored.
 */
public void update(PointCloud cloud) {
  if (lastPointCloud == cloud) {
    // Redundant call.
    return;
  }

  ShaderUtil.checkGLError(TAG, "before update");

  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo);
  lastPointCloud = cloud;

  // If the VBO is not large enough to fit the new point cloud, resize it.
  numPoints = lastPointCloud.getPoints().remaining() / FLOATS_PER_POINT;
  if (numPoints * BYTES_PER_POINT > vboSize) {
    while (numPoints * BYTES_PER_POINT > vboSize) {
      vboSize *= 2;
    }
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vboSize, null, GLES20.GL_DYNAMIC_DRAW);
  }
  GLES20.glBufferSubData(
      GLES20.GL_ARRAY_BUFFER, 0, numPoints * BYTES_PER_POINT, lastPointCloud.getPoints());
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

  ShaderUtil.checkGLError(TAG, "after update");
}
 
Example 7
Source File: LineShaderRenderer.java    From justaline-android with Apache License 2.0 4 votes vote down vote up
/**
     * This takes the float[] and creates FloatBuffers, Binds the VBO, and upload the Attributes to
     * correct locations with the correct offsets so the Vertex and Fragment shader can render the lines
     */
    public void upload() {
        bNeedsUpdate.set(false);

        FloatBuffer current = toFloatBuffer(mPositions);
        FloatBuffer next = toFloatBuffer(mNext);
        FloatBuffer previous = toFloatBuffer(mPrevious);

        FloatBuffer side = toFloatBuffer(mSide);
        FloatBuffer width = toFloatBuffer(mWidth);
        FloatBuffer lengths = toFloatBuffer(mLengths);
        FloatBuffer endCaps = toFloatBuffer(mEndCaps);


//        mNumPoints = mPositions.length;

        mPositionAddress = 0;
        mNextAddress = mPositionAddress + mNumBytes * 3 * BYTES_PER_FLOAT;
        mPreviousAddress = mNextAddress + mNumBytes * 3 * BYTES_PER_FLOAT;
        mSideAddress = mPreviousAddress + mNumBytes * 3 * BYTES_PER_FLOAT;
        mWidthAddress = mSideAddress + mNumBytes * BYTES_PER_FLOAT;
        mLengthAddress = mWidthAddress + mNumBytes * BYTES_PER_FLOAT;
        mEndCapsAddress = mLengthAddress + mNumBytes * BYTES_PER_FLOAT;
        mVboSize = mEndCapsAddress + mNumBytes * BYTES_PER_FLOAT;

        ShaderUtil.checkGLError(TAG, "before update");

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);

        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVboSize, null, GLES20.GL_DYNAMIC_DRAW);

        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mPositionAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                current);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mNextAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                next);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mPreviousAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                previous);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mSideAddress, mNumBytes * BYTES_PER_FLOAT,
                side);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mWidthAddress, mNumBytes * BYTES_PER_FLOAT,
                width);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mLengthAddress, mNumBytes * BYTES_PER_FLOAT,
                lengths);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mEndCapsAddress, mNumBytes * BYTES_PER_FLOAT,
                endCaps);


        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

        ShaderUtil.checkGLError(TAG, "after update");
    }
 
Example 8
Source File: DebugMeshShaderRenderer.java    From justaline-android with Apache License 2.0 4 votes vote down vote up
/**
     * This takes the float[] and creates FloatBuffers, Binds the VBO, and upload the Attributes to
     * correct locations with the correct offsets so the Vertex and Fragment shader can render the lines
     */
    public void upload() {
        bNeedsUpdate.set(false);

        FloatBuffer current = toFloatBuffer(mPositions);
        FloatBuffer next = toFloatBuffer(mNext);
        FloatBuffer previous = toFloatBuffer(mPrevious);

        FloatBuffer side = toFloatBuffer(mSide);
        FloatBuffer width = toFloatBuffer(mWidth);
        FloatBuffer counter = toFloatBuffer(mCounters);


//        mNumPoints = mPositions.length;

        mPositionAddress = 0;
        mNextAddress = mPositionAddress + mNumBytes * 3 * BYTES_PER_FLOAT;
        mPreviousAddress = mNextAddress + mNumBytes * 3 * BYTES_PER_FLOAT;
        mSideAddress = mPreviousAddress + mNumBytes * 3 * BYTES_PER_FLOAT;

        mWidthAddress = mSideAddress + mNumBytes * BYTES_PER_FLOAT;
        mCounterAddress = mWidthAddress + mNumBytes * BYTES_PER_FLOAT;
        mVboSize = mCounterAddress + mNumBytes * BYTES_PER_FLOAT;

        ShaderUtil.checkGLError(TAG, "before update");

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);

        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVboSize, null, GLES20.GL_DYNAMIC_DRAW);

        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mPositionAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                current);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mNextAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                next);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mPreviousAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                previous);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mSideAddress, mNumBytes * BYTES_PER_FLOAT,
                side);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mWidthAddress, mNumBytes * BYTES_PER_FLOAT,
                width);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mCounterAddress, mNumBytes * BYTES_PER_FLOAT,
                counter);


        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

        ShaderUtil.checkGLError(TAG, "after update");
    }
 
Example 9
Source File: LineShaderRenderer.java    From ar-drawing-java with Apache License 2.0 4 votes vote down vote up
/**
     * This takes the float[] and creates FloatBuffers, Binds the VBO, and upload the Attributes to
     * correct locations with the correct offsets so the Vertex and Fragment shader can render the lines
     */
    public void upload() {
        bNeedsUpdate.set(false);

        FloatBuffer current = toFloatBuffer(mPositions);
        FloatBuffer next = toFloatBuffer(mNext);
        FloatBuffer previous = toFloatBuffer(mPrevious);

        FloatBuffer side = toFloatBuffer(mSide);
        FloatBuffer width = toFloatBuffer(mWidth);
        FloatBuffer counter = toFloatBuffer(mCounters);


//        mNumPoints = mPositions.length;

        mPositionAddress = 0;
        mNextAddress = mPositionAddress + mNumBytes * 3 * BYTES_PER_FLOAT;
        mPreviousAddress = mNextAddress + mNumBytes * 3 * BYTES_PER_FLOAT;
        mSideAddress = mPreviousAddress + mNumBytes *3 * BYTES_PER_FLOAT;

        mWidthAddress = mSideAddress + mNumBytes * BYTES_PER_FLOAT;
        mCounterAddress = mWidthAddress + mNumBytes * BYTES_PER_FLOAT;
        mVboSize = mCounterAddress + mNumBytes * BYTES_PER_FLOAT;

        ShaderUtil.checkGLError(TAG, "before update");

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);

        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVboSize, null, GLES20.GL_DYNAMIC_DRAW);

        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mPositionAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                current);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mNextAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                next);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mPreviousAddress, mNumBytes * 3 * BYTES_PER_FLOAT,
                previous);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mSideAddress, mNumBytes * BYTES_PER_FLOAT,
                side);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mWidthAddress, mNumBytes * BYTES_PER_FLOAT,
                width);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, mCounterAddress, mNumBytes * BYTES_PER_FLOAT,
                counter);


        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

        ShaderUtil.checkGLError(TAG, "after update");
    }
 
Example 10
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void bufferSubData(int target, int offset, int size, Buffer data) {
    GLES20.glBufferSubData(target, offset, size, data);
}