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

The following examples show how to use android.opengl.GLES20#glGenBuffers() . 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: Points.java    From ShapesInOpenGLES2.0 with MIT License 6 votes vote down vote up
/**
 * instantiate the Points shape object
 * @param aActivity
 * @param positions
 * @param colors
 */
public Points(Context aActivity, float[] positions, float[] colors){

    /** initialize the point program */
    final String pointVS = RawResourceReader.readTextFileFromRawResource(aActivity, R.raw.point_vertex_shader);
    final String pointFS = RawResourceReader.readTextFileFromRawResource(aActivity, R.raw.point_fragment_shader);

    final int pointVSHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, pointVS);
    final int pointFSHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, pointFS);

    aPointProgramHandle = ShaderHelper.createAndLinkProgram(pointVSHandle, pointFSHandle,
            new String[]{"a_Position", "a_Color"});

    // Second, copy these buffers into OpenGL's memory. After, we don't need to keep the client-side buffers around.
    GLES20.glGenBuffers(glPointBuffer.length, glPointBuffer, 0);

    createBuffers(positions, colors);
}
 
Example 2
Source File: Lines.java    From ShapesInOpenGLES2.0 with MIT License 6 votes vote down vote up
/**
 * instantiate the Lines shape object
 * @param activity
 * @param positions
 * @param colors
 */
public Lines(Context activity, float[] positions, float[] colors) {

    /** initialize the line program */
    final String lineVS = RawResourceReader.readTextFileFromRawResource(activity, R.raw.line_vertex_shader);
    final String lineFS = RawResourceReader.readTextFileFromRawResource(activity, R.raw.line_fragment_shader);

    final int lineVSHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, lineVS);
    final int lineFSHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, lineFS);

    aLineProgramHandle = ShaderHelper.createAndLinkProgram(lineVSHandle, lineFSHandle,
            new String[]{"a_Position", "a_Color"});

    // Second, copy these buffers into OpenGL's memory. After, we don't need to keep the client-side buffers around.
    GLES20.glGenBuffers(glLineBuffer.length, glLineBuffer, 0);

    createBuffers(positions, colors);
}
 
Example 3
Source File: HeightMap.java    From ShapesInOpenGLES2.0 with MIT License 6 votes vote down vote up
private void initializeGLProgram(Context context) {
    final String vertexShader = RawResourceReader.readTextFileFromRawResource(context,
            R.raw.heightmap_vertex_shader);
    final String fragmentShader = RawResourceReader.readTextFileFromRawResource(context,
            R.raw.heightmap_fragment_shader);

    final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
    final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);

    aProgramHandle = ShaderHelper.createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, new String[] {
            "a_Position", "a_Normal", "a_Color" });

    GLES20.glGenBuffers(1, vbo, 0);
    GLES20.glGenBuffers(1, ibo, 0);

    isActive = true;

}
 
Example 4
Source File: Quad.java    From ShapesInOpenGLES2.0 with MIT License 6 votes vote down vote up
/**
 * instantiate the Quad shape object
 * @param activity
 * @param positions
 * @param widths
 */
public Quad(Context activity, float[] positions, float[] widths) {

    final String vertexShader = RawResourceReader.readTextFileFromRawResource(activity,
            R.raw.quad_vertex_shader);
    final String fragmentShader = RawResourceReader.readTextFileFromRawResource(activity,
            R.raw.quad_fragment_shader);

    final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
    final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);

    aQuadProgramHandle = ShaderHelper.createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, new String[] {
            "a_Position", "a_Color", "a_TexCoordinate" });

    GLES20.glGenBuffers(1, qvbo, 0);
    GLES20.glGenBuffers(1, qibo, 0);

    createBuffers(positions, widths);
}
 
Example 5
Source File: CubeRenderer.java    From HoloKilo with GNU General Public License v3.0 6 votes vote down vote up
private void createVertexBuffers() {
    cubeBuffer.position(0);
    texBuffer.position(0);
    indexBuffer.position(0);

    GLES20.glGenBuffers(1, texturePointer, 0);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, texturePointer[0]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, tex.length * 4, texBuffer, GLES20.GL_STATIC_DRAW);

    GLES20.glGenBuffers(1, cubePointer, 0);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, cubePointer[0]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cube.length * 4, cubeBuffer, GLES20.GL_STATIC_DRAW);

    GLES20.glGenBuffers(1, indexPointer, 0);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexPointer[0]);
    GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, indeces.length * 4, indexBuffer, GLES20.GL_STATIC_DRAW);

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
 
Example 6
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 7
Source File: ColorFade.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean initGLBuffers() {
    //Fill vertices
    setQuad(mVertexBuffer, 0, 0, mDisplayWidth, mDisplayHeight);

    // Setup GL Textures
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTexNames[0]);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER,
            GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER,
            GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S,
            GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T,
            GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);

    // Setup GL Buffers
    GLES20.glGenBuffers(2, mGLBuffers, 0);

    // fill vertex buffer
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLBuffers[0]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVertexBuffer.capacity() * 4,
                        mVertexBuffer, GLES20.GL_STATIC_DRAW);

    // fill tex buffer
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLBuffers[1]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mTexCoordBuffer.capacity() * 4,
                        mTexCoordBuffer, GLES20.GL_STATIC_DRAW);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    return true;
}
 
Example 8
Source File: GeometrySource.java    From Tanks with MIT License 5 votes vote down vote up
private static int loadGeometry(final FloatBuffer buffer)
{
  ResultRunnable<Integer> runnable = new ResultRunnable<Integer>()
  {
    @Override
    protected Integer onRun()
    {
      int error;
      int[] buffers = new int[1];

      GLES20.glGenBuffers(1, buffers, 0);
      if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
        throw new GLException(error, Integer.toString(error));

      GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
      if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
        throw new GLException(error, Integer.toString(error));

      GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, buffer.capacity() * 4, buffer, GLES20.GL_STATIC_DRAW);
      if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
        throw new GLException(error, Integer.toString(error));

      return buffers[0];
    }
  };

  GameContext.glThread.sendEvent(runnable);
  return runnable.getResult();
}
 
Example 9
Source File: PointCloudRenderer.java    From react-native-arcore with MIT License 5 votes vote down vote up
/**
 * Allocates and initializes OpenGL resources needed by the plane renderer.  Must be
 * called on the OpenGL thread, typically in
 * {@link GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)}.
 *
 * @param context Needed to access shader source.
 */
public void createOnGlThread(Context context) {
    ShaderUtil.checkGLError(TAG, "before create");

    int[] buffers = new int[1];
    GLES20.glGenBuffers(1, buffers, 0);
    mVbo = buffers[0];
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);

    mVboSize = INITIAL_BUFFER_POINTS * BYTES_PER_POINT;
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVboSize, null, GLES20.GL_DYNAMIC_DRAW);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    ShaderUtil.checkGLError(TAG, "buffer alloc");

    int vertexShader = ShaderUtil.loadGLShader(TAG, context,
        GLES20.GL_VERTEX_SHADER, R.raw.point_cloud_vertex);
    int passthroughShader = ShaderUtil.loadGLShader(TAG, context,
        GLES20.GL_FRAGMENT_SHADER, R.raw.passthrough_fragment);

    mProgramName = GLES20.glCreateProgram();
    GLES20.glAttachShader(mProgramName, vertexShader);
    GLES20.glAttachShader(mProgramName, passthroughShader);
    GLES20.glLinkProgram(mProgramName);
    GLES20.glUseProgram(mProgramName);

    ShaderUtil.checkGLError(TAG, "program");

    mPositionAttribute = GLES20.glGetAttribLocation(mProgramName, "a_Position");
    mColorUniform = GLES20.glGetUniformLocation(mProgramName, "u_Color");
    mModelViewProjectionUniform = GLES20.glGetUniformLocation(
        mProgramName, "u_ModelViewProjection");
    mPointSizeUniform = GLES20.glGetUniformLocation(mProgramName, "u_PointSize");

    ShaderUtil.checkGLError(TAG, "program  params");
}
 
Example 10
Source File: GLState.java    From tilt-game-android with MIT License 5 votes vote down vote up
public int generateArrayBuffer(final int pSize, final int pUsage) {
	GLES20.glGenBuffers(1, this.mHardwareIDContainer, 0);
	final int hardwareBufferID = this.mHardwareIDContainer[0];

	this.bindArrayBuffer(hardwareBufferID);
	GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, pSize, null, pUsage);
	this.bindArrayBuffer(0);

	return hardwareBufferID;
}
 
Example 11
Source File: GLState.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public int generateIndexBuffer(final int pSize, final int pUsage) {
	GLES20.glGenBuffers(1, this.mHardwareIDContainer, 0);
	final int hardwareBufferID = this.mHardwareIDContainer[0];
	
	this.bindIndexBuffer(hardwareBufferID);
	GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, pSize, null, pUsage);
	this.bindIndexBuffer(0);
	
	return hardwareBufferID;
}
 
Example 12
Source File: GLES20IdImpl.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void glGenBuffers(int n, int[] buffers, int offset) {
    GLES20.glGenBuffers(n, buffers, offset);
    GLES20Canvas.checkError();
}
 
Example 13
Source File: GLState.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public int generateBuffer() {
	GLES20.glGenBuffers(1, this.mHardwareIDContainer, 0);
	return this.mHardwareIDContainer[0];
}
 
Example 14
Source File: CustomImageModel.java    From VIA-AI with MIT License 4 votes vote down vote up
private void checkAndInitGL()
{
    if(mIsModelGenerated == false) {
        // Add dummy surface for debug

        FloatBuffer vertexBuffer;
        FloatBuffer textureCoordinateBuffer;

        // VBO
        GLES20.glGenBuffers(1, mPositionVBO, 0);
        GLUtility.checkGlError("glGenBuffers");

        GLES20.glGenBuffers(1, mTextureCoordinateVBO, 0);
        GLUtility.checkGlError("glGenBuffers");

        // Initialize vertex byte buffer for shape coordinates
        ByteBuffer bb = ByteBuffer.allocateDirect(mPosition.length * 4);
        bb.order(ByteOrder.nativeOrder());
        vertexBuffer = bb.asFloatBuffer();
        vertexBuffer.put(mPosition);
        vertexBuffer.position(0);

        // VBO buffer vertex data
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mPositionVBO[0]);
        GLUtility.checkGlError("glBindBuffer");

        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mPosition.length * 4, vertexBuffer, GLES20.GL_STATIC_DRAW);
        GLUtility.checkGlError("glBufferData");

        // VBO buffer texture coord data
        bb = ByteBuffer.allocateDirect(mTextureCoordinate.length * 4);
        bb.order(ByteOrder.nativeOrder());
        textureCoordinateBuffer = bb.asFloatBuffer();
        textureCoordinateBuffer.put(mTextureCoordinate);
        textureCoordinateBuffer.position(0);

        GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mTextureCoordinateVBO[0]);
        GLUtility.checkGlError("glBindBuffer");

        GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, mTextureCoordinate.length * 4, textureCoordinateBuffer, GLES20.GL_STATIC_DRAW);
        GLUtility.checkGlError("glBufferData");


        // prepare shaders and OpenGL program
        int vertexShader = GLUtility.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
        int fragmentShader = GLUtility.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
        int fragmentShader_Luminance = GLUtility.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode_Luminance);

        mProgram = GLES20.glCreateProgram();
        GLUtility.checkGlError("glCreateProgram");
        GLES20.glAttachShader(mProgram, vertexShader);
        GLUtility.checkGlError("glAttachShader");
        GLES20.glAttachShader(mProgram, fragmentShader);
        GLUtility.checkGlError("glAttachShader");
        GLES20.glLinkProgram(mProgram);
        GLUtility.checkGlError("glLinkProgram");

        mProgram_Luminance = GLES20.glCreateProgram();
        GLUtility.checkGlError("glCreateProgram");
        GLES20.glAttachShader(mProgram_Luminance, vertexShader);
        GLUtility.checkGlError("glAttachShader");
        GLES20.glAttachShader(mProgram_Luminance, fragmentShader_Luminance);
        GLUtility.checkGlError("glAttachShader");
        GLES20.glLinkProgram(mProgram_Luminance);
        GLUtility.checkGlError("glLinkProgram");

        mIsModelGenerated = true;
    }
}
 
Example 15
Source File: EglUtil.java    From Mp4Composer-android with MIT License 4 votes vote down vote up
public static int createBuffer(final FloatBuffer data) {
    final int[] buffers = new int[1];
    GLES20.glGenBuffers(buffers.length, buffers, 0);
    updateBufferData(buffers[0], data);
    return buffers[0];
}
 
Example 16
Source File: CameraViewModel.java    From VIA-AI with MIT License 4 votes vote down vote up
private void checkAndInitGL()
{
    if(mIsModelGenerated == false) {
        FloatBuffer vertexBuffer;
        FloatBuffer textureCoordinateBuffer;

        // VBO
        GLES20.glGenBuffers(1, mPositionVBO, 0);
        GLUtility.checkGlError("glGenBuffers");

        // Initialize vertex byte buffer for shape coordinates
        ByteBuffer bb = ByteBuffer.allocateDirect(mPosition.length * 4);
        bb.order(ByteOrder.nativeOrder());
        vertexBuffer = bb.asFloatBuffer();
        vertexBuffer.put(mPosition);
        vertexBuffer.position(0);

        // VBO buffer vertex data
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mPositionVBO[0]);
        GLUtility.checkGlError("glBindBuffer");

        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mPosition.length * 4, vertexBuffer, GLES20.GL_STATIC_DRAW);
        GLUtility.checkGlError("glBufferData");



        // VBO buffer texture coord data
        bb = ByteBuffer.allocateDirect(mTextureCoordinate.length * 4);
        bb.order(ByteOrder.nativeOrder());
        textureCoordinateBuffer = bb.asFloatBuffer();
        textureCoordinateBuffer.put(mTextureCoordinate);
        textureCoordinateBuffer.position(0);

        GLES20.glGenBuffers(1, mTextureCoordinateVBO, 0);
        GLUtility.checkGlError("glGenBuffers");

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mTextureCoordinateVBO[0]);
        GLUtility.checkGlError("glBindBuffer");

        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mTextureCoordinate.length * 4, textureCoordinateBuffer, GLES20.GL_STATIC_DRAW);
        GLUtility.checkGlError("glBufferData");


        // VBO buffer index
        GLES20.glGenBuffers(1, mIndexVBO, 0);
        GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mIndexVBO[0]);
        GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, mIndex.length * 2, mIndexBuffer, GLES20.GL_STATIC_DRAW);
        GLUtility.checkGlError("glBufferData");



        // prepare shaders and OpenGL program
        int vertexShader = GLUtility.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
        int fragmentShader = GLUtility.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

        mProgram = GLES20.glCreateProgram();
        GLUtility.checkGlError("glCreateProgram");
        GLES20.glAttachShader(mProgram, vertexShader);
        GLUtility.checkGlError("glAttachShader");
        GLES20.glAttachShader(mProgram, fragmentShader);
        GLUtility.checkGlError("glAttachShader");
        GLES20.glLinkProgram(mProgram);
        GLUtility.checkGlError("glLinkProgram");

        mIsModelGenerated = true;
    }
}
 
Example 17
Source File: EglUtil.java    From SimpleVideoEdit with Apache License 2.0 4 votes vote down vote up
public static int createBuffer(final FloatBuffer data) {
    final int[] buffers = new int[1];
    GLES20.glGenBuffers(buffers.length, buffers, 0);
    updateBufferData(buffers[0], data);
    return buffers[0];
}
 
Example 18
Source File: Framebuffer.java    From PD-classes with GNU General Public License v3.0 4 votes vote down vote up
public Framebuffer() {
	int[] buffers = new int[1];
	GLES20.glGenBuffers( 1, buffers, 0 );
	id = buffers[0];
}
 
Example 19
Source File: GLState.java    From tilt-game-android with MIT License 4 votes vote down vote up
public int generateBuffer() {
	GLES20.glGenBuffers(1, this.mHardwareIDContainer, 0);
	return this.mHardwareIDContainer[0];
}
 
Example 20
Source File: GLES20IdImpl.java    From android-openGL-canvas with Apache License 2.0 4 votes vote down vote up
@Override
public void glGenBuffers(int n, int[] buffers, int offset) {
    GLES20.glGenBuffers(n, buffers, offset);
    GLES20Canvas.checkError();
}