Java Code Examples for android.opengl.GLES30#glGetUniformLocation()

The following examples show how to use android.opengl.GLES30#glGetUniformLocation() . 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: GLDrawer2DES3.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * シェーダープログラム変更時の初期化処理
 * glUseProgramが呼ばれた状態で返る
 */
@Override
protected void init() {
	if (DEBUG) Log.v(TAG, "init:");
	GLES30.glUseProgram(hProgram);
	maPositionLoc = GLES30.glGetAttribLocation(hProgram, "aPosition");
	maTextureCoordLoc = GLES30.glGetAttribLocation(hProgram, "aTextureCoord");
	muMVPMatrixLoc = GLES30.glGetUniformLocation(hProgram, "uMVPMatrix");
	muTexMatrixLoc = GLES30.glGetUniformLocation(hProgram, "uTexMatrix");
	//
	GLES30.glUniformMatrix4fv(muMVPMatrixLoc,
		1, false, mMvpMatrix, 0);
	GLES30.glUniformMatrix4fv(muTexMatrixLoc,
		1, false, mMvpMatrix, 0);
	updateVertices();
}
 
Example 2
Source File: Square.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * Encapsulates the OpenGL ES instructions for drawing this shape.
 *
 * @param mvpMatrix - The Model View Project matrix in which to draw
 * this shape.
 */
public void draw(float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES30.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES30.glGetAttribLocation(mProgram, "vPosition");

    // Enable a handle to the triangle vertices
    GLES30.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES30.glVertexAttribPointer(
            mPositionHandle, COORDS_PER_VERTEX,
            GLES30.GL_FLOAT, false,
            vertexStride, vertexBuffer);

    // get handle to fragment shader's vColor member
    mColorHandle = GLES30.glGetUniformLocation(mProgram, "vColor");

    // Set color for drawing the triangle
    GLES30.glUniform4fv(mColorHandle, 1, color, 0);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgram, "uMVPMatrix");
    MyGLRenderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    MyGLRenderer.checkGlError("glUniformMatrix4fv");

    // Draw the square
    GLES30.glDrawElements(
            GLES30.GL_TRIANGLES, drawOrder.length,
            GLES30.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES30.glDisableVertexAttribArray(mPositionHandle);
}
 
Example 3
Source File: Triangle.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * Encapsulates the OpenGL ES instructions for drawing this shape.
 *
 * @param mvpMatrix - The Model View Project matrix in which to draw
 * this shape.
 */
public void draw(float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES30.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES30.glGetAttribLocation(mProgram, "vPosition");

    // Enable a handle to the triangle vertices
    GLES30.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES30.glVertexAttribPointer(
            mPositionHandle, COORDS_PER_VERTEX,
            GLES30.GL_FLOAT, false,
            vertexStride, vertexBuffer);

    // get handle to fragment shader's vColor member
    mColorHandle = GLES30.glGetUniformLocation(mProgram, "vColor");

    // Set color for drawing the triangle
    GLES30.glUniform4fv(mColorHandle, 1, color, 0);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgram, "uMVPMatrix");
    MyGLRenderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    MyGLRenderer.checkGlError("glUniformMatrix4fv");

    // Draw the triangle
    GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, vertexCount);

    // Disable vertex array
    GLES30.glDisableVertexAttribArray(mPositionHandle);
}
 
Example 4
Source File: GLES30WallpaperRenderer.java    From alynx-live-wallpaper with Apache License 2.0 4 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
    // No depth test for 2D video.
    GLES30.glDisable(GLES30.GL_DEPTH_TEST);
    GLES30.glDepthMask(false);
    GLES30.glDisable(GLES30.GL_CULL_FACE);
    GLES30.glDisable(GLES30.GL_BLEND);

    GLES30.glGenTextures(textures.length, textures, 0);
    GLES30.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
    GLES30.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES30.GL_TEXTURE_MIN_FILTER,
        GLES30.GL_LINEAR
    );
    GLES30.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES30.GL_TEXTURE_MAG_FILTER,
        GLES30.GL_LINEAR
    );
    GLES30.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES30.GL_TEXTURE_WRAP_S,
        GLES30.GL_CLAMP_TO_EDGE
    );
    GLES30.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES30.GL_TEXTURE_WRAP_T,
        GLES30.GL_CLAMP_TO_EDGE
    );

    program = Utils.linkProgramGLES30(
        Utils.compileShaderResourceGLES30(
            context, GLES30.GL_VERTEX_SHADER, R.raw.vertex_30
        ),
        Utils.compileShaderResourceGLES30(
            context, GLES30.GL_FRAGMENT_SHADER, R.raw.fragment_30
        )
    );
    mvpLocation = GLES30.glGetUniformLocation(program, "mvp");

    GLES30.glGenBuffers(buffers.length, buffers, 0);

    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, buffers[0]);
    GLES30.glBufferData(
        GLES30.GL_ARRAY_BUFFER, vertices.capacity() * BYTES_PER_FLOAT,
        vertices, GLES30.GL_STATIC_DRAW
    );
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);

    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, buffers[1]);
    GLES30.glBufferData(
        GLES30.GL_ARRAY_BUFFER, texCoords.capacity() * BYTES_PER_FLOAT,
        texCoords, GLES30.GL_STATIC_DRAW
    );
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);

    GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, buffers[2]);
    GLES30.glBufferData(
        GLES30.GL_ELEMENT_ARRAY_BUFFER, indices.capacity() * BYTES_PER_INT,
        indices, GLES30.GL_STATIC_DRAW
    );
    GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, 0);

    // Locations are set in shader sources.
    GLES30.glGenVertexArrays(vertexArrays.length, vertexArrays, 0);

    GLES30.glBindVertexArray(vertexArrays[0]);
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, buffers[0]);
    GLES30.glEnableVertexAttribArray(0);
    GLES30.glVertexAttribPointer(
        0, 2, GLES30.GL_FLOAT, false, 2 * BYTES_PER_FLOAT, 0
    );
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, buffers[1]);
    GLES30.glEnableVertexAttribArray(1);
    GLES30.glVertexAttribPointer(
        1, 2, GLES30.GL_FLOAT, false, 2 * BYTES_PER_FLOAT, 0
    );
    GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, buffers[2]);
    GLES30.glBindVertexArray(0);

    GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
 
Example 5
Source File: Pyramid.java    From opengl with Apache License 2.0 4 votes vote down vote up
public void draw(float[] mvpMatrix) {

        // Use the program object
        GLES30.glUseProgram(mProgramObject);

        // get handle to shape's transformation matrix
        mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgramObject, "uMVPMatrix");
        myRenderer.checkGlError("glGetUniformLocation");

        // get handle to fragment shader's vColor member
        mColorHandle = GLES30.glGetUniformLocation(mProgramObject, "vColor");


        // Apply the projection and view transformation
        GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
        myRenderer.checkGlError("glUniformMatrix4fv");

        int VERTEX_POS_INDX = 0;
        mVertices.position(VERTEX_POS_INDX);  //just in case.  We did it already though.

        //add all the points to the space, so they can be correct by the transformations.
        //would need to do this even if there were no transformations actually.
        GLES30.glVertexAttribPointer(VERTEX_POS_INDX, 3, GLES30.GL_FLOAT,
                false, 0, mVertices);
        GLES30.glEnableVertexAttribArray(VERTEX_POS_INDX);


        //Now we are ready to draw the cube finally.
        int startPos = 0;
        int verticesPerface = 3;

        //draw front face
        GLES30.glUniform4fv(mColorHandle, 1, colorblue, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface);
        startPos += verticesPerface;

        //draw right face
        GLES30.glUniform4fv(mColorHandle, 1, colorcyan, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface);
        startPos += verticesPerface;

        //draw back face
        GLES30.glUniform4fv(mColorHandle, 1, colorred, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface);
        startPos += verticesPerface;

        //draw left face
        GLES30.glUniform4fv(mColorHandle, 1, colorgray, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface);
        startPos += verticesPerface;


        //draw bottom face 1 tri square, so 6 faces.
        GLES30.glUniform4fv(mColorHandle, 1, coloryellow, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface);
        startPos += verticesPerface;

        //draw bottom face 2 tri square, so 6 faces.
        GLES30.glUniform4fv(mColorHandle, 1, coloryellow, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface);
        startPos += verticesPerface;
        //last face, so no need to increment.

    }
 
Example 6
Source File: Cube.java    From opengl with Apache License 2.0 4 votes vote down vote up
public void draw(float[] mvpMatrix) {

        // Use the program object
        GLES30.glUseProgram(mProgramObject);

        // get handle to shape's transformation matrix
        mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgramObject, "uMVPMatrix");
        myRenderer.checkGlError("glGetUniformLocation");

        // get handle to fragment shader's vColor member
        mColorHandle = GLES30.glGetUniformLocation(mProgramObject, "vColor");


        // Apply the projection and view transformation
        GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
        myRenderer.checkGlError("glUniformMatrix4fv");

        int VERTEX_POS_INDX = 0;
        mVertices.position(VERTEX_POS_INDX);  //just in case.  We did it already though.

        //add all the points to the space, so they can be correct by the transformations.
        //would need to do this even if there were no transformations actually.
        GLES30.glVertexAttribPointer(VERTEX_POS_INDX, 3, GLES30.GL_FLOAT,
                false, 0, mVertices);
        GLES30.glEnableVertexAttribArray(VERTEX_POS_INDX);

        //Now we are ready to draw the cube finally.
        int startPos =0;
        int verticesPerface = 6;

        //draw front face
        GLES30.glUniform4fv(mColorHandle, 1, colorblue, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        startPos += verticesPerface;

        //draw back face
        GLES30.glUniform4fv(mColorHandle, 1, colorcyan, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface);
        startPos += verticesPerface;

        //draw left face
        GLES30.glUniform4fv(mColorHandle, 1, colorred, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        startPos += verticesPerface;

        //draw right face
        GLES30.glUniform4fv(mColorHandle, 1, colorgray, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        startPos += verticesPerface;

        //draw top face
        GLES30.glUniform4fv(mColorHandle, 1, colorgreen, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        startPos += verticesPerface;

        //draw bottom face
        GLES30.glUniform4fv(mColorHandle, 1, coloryellow, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        //last face, so no need to increment.

    }
 
Example 7
Source File: Cube.java    From opengl with Apache License 2.0 4 votes vote down vote up
public void draw(float[] mvpMatrix) {

        // Use the program object
        GLES30.glUseProgram(mProgramObject);

        // get handle to shape's transformation matrix
        mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgramObject, "uMVPMatrix");
        myRenderer.checkGlError("glGetUniformLocation");

        // get handle to fragment shader's vColor member
        mColorHandle = GLES30.glGetUniformLocation(mProgramObject, "vColor");


        // Apply the projection and view transformation
        GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
        myRenderer.checkGlError("glUniformMatrix4fv");

        int VERTEX_POS_INDX = 0;
        mVertices.position(VERTEX_POS_INDX);  //just in case.  We did it already though.

        //add all the points to the space, so they can be correct by the transformations.
        //would need to do this even if there were no transformations actually.
        GLES30.glVertexAttribPointer(VERTEX_POS_INDX, 3, GLES30.GL_FLOAT,
                false, 0, mVertices);
        GLES30.glEnableVertexAttribArray(VERTEX_POS_INDX);

        //Now we are ready to draw the cube finally.
        int startPos =0;
        int verticesPerface = 6;

        //draw front face
        GLES30.glUniform4fv(mColorHandle, 1, colorblue, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        startPos += verticesPerface;

        //draw back face
        GLES30.glUniform4fv(mColorHandle, 1, colorcyan, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface);
        startPos += verticesPerface;

        //draw left face
        GLES30.glUniform4fv(mColorHandle, 1, colorred, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        startPos += verticesPerface;

        //draw right face
        GLES30.glUniform4fv(mColorHandle, 1, colorgray, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        startPos += verticesPerface;

        //draw top face
        GLES30.glUniform4fv(mColorHandle, 1, colorgreen, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        startPos += verticesPerface;

        //draw bottom face
        GLES30.glUniform4fv(mColorHandle, 1, coloryellow, 0);
        GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface);
        //last face, so no need to increment.

    }
 
Example 8
Source File: GLDrawer2DES3.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * ユニフォーム変数のロケーションを取得
 * glUseProgramが呼ばれた状態で返る
 * IShaderDrawer2dの実装
 * @param name
 * @return
 */
@Override
public int glGetUniformLocation(@NonNull final String name) {
	GLES30.glUseProgram(hProgram);
	return GLES30.glGetUniformLocation(hProgram, name);
}