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

The following examples show how to use android.opengl.GLES20#glUniform2fv() . 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: MediaEffectGLDilation.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
protected void preDraw(@NonNull final int[] tex_ids,
	final float[] tex_matrix, final int offset) {

	super.preDraw(tex_ids, tex_matrix, offset);
	// テクセルオフセット
	if (muTexOffsetLoc >= 0) {
		GLES20.glUniform2fv(muTexOffsetLoc, 41, mTexOffset, 0);
	}
}
 
Example 2
Source File: ShaderProgram.java    From Animer with Apache License 2.0 5 votes vote down vote up
public void setOnDrawFrame(float[] resolution,float time,float[] factors,float mode,float duration,float[] mainColor,float[] secondaryColor){
    // ######################### clear the canvas #########################
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    // #########################   first program  #########################
    GLES20.glUseProgram(program);
    if (positionLoc > -1){ GLES20.glVertexAttribPointer(positionLoc, mPositionDataSize, GLES20.GL_FLOAT, false,0, vertexBuffer); }
    if (resolutionLoc > -1) { GLES20.glUniform2fv(resolutionLoc,1,resolution,0); }
    if (timeLoc > -1) { GLES20.glUniform1f(timeLoc,time); }
    if (modeLoc > -1) { GLES20.glUniform1f(modeLoc,mode); }
    if (durationLoc > -1) { GLES20.glUniform1f(durationLoc,duration); }
    if (mainColorLoc > -1) { GLES20.glUniform3f(mainColorLoc,mainColor[0],mainColor[1],mainColor[2]); }
    if (secondaryColorLoc > -1) { GLES20.glUniform3f(secondaryColorLoc,secondaryColor[0],secondaryColor[1],secondaryColor[2]); }

    //5 Factors
    for (int i = 0; i < factorLength; ++i) { //factorLocs.length
        factorLocs[i] = GLES20.glGetUniformLocation(program,UNIFORM_FACTOR + (i+1));
        GLES20.glUniform1f(factorLocs[i],factors[i]);
    }


    //Draw the triangle facing straight on.
    if(mvpLoc > -1){
        Matrix.setIdentityM(mModelMatrix, 0);
        Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
        GLES20.glUniformMatrix4fv(mvpLoc, 1, false, mMVPMatrix, 0);
    }


    GLES20.glViewport(0,0,(int) resolution[0],(int) resolution[1]);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDrawArrays(GL_TRIANGLE_STRIP,0,4);
}
 
Example 3
Source File: SnowMovieFilter.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPreDraw(PhotoMovie photoMovie, int elapsedTime, FboTexture inputTexture) {
    super.onPreDraw(photoMovie, elapsedTime, inputTexture);
    float time = photoMovie==null?0f:elapsedTime/(float)photoMovie.getDuration();
    GLES20.glUniform1f(mTimeHandler,time*mSpeed);
    GLES20.glUniform2fv(mSizeHandler,1,new float[]{inputTexture.getWidth()/(float)inputTexture.getHeight()*mSnowSize,1f*mSnowSize},0);

}
 
Example 4
Source File: MediaEffectGLErosion.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
protected void preDraw(@NonNull final int[] tex_ids,
	final float[] tex_matrix, final int offset) {

	super.preDraw(tex_ids, tex_matrix, offset);
	// テクセルオフセット
	if (muTexOffsetLoc >= 0) {
		GLES20.glUniform2fv(muTexOffsetLoc, 41, mTexOffset, 0);
	}
}
 
Example 5
Source File: CameraFilterMosaic.java    From PLDroidMediaStreaming with Apache License 2.0 5 votes vote down vote up
@Override
protected void bindGLSLValues(float[] mvpMatrix, FloatBuffer vertexBuffer, int coordsPerVertex,
                              int vertexStride, FloatBuffer texBuffer, int texStride) {
    super.bindGLSLValues(mvpMatrix, vertexBuffer, coordsPerVertex, vertexStride,
            texBuffer, texStride);

    GLES20.glUniform2fv(muTexsizeLoc, 1, Texsize_array, 0);
}
 
Example 6
Source File: TextureKernelShaderProgram.java    From Spectaculum with Apache License 2.0 5 votes vote down vote up
@Override
public void setTextureSize(int width, int height) {
    //super.setTextureSize(width, height);
    float rw = 1.0f / width;
    float rh = 1.0f / height;

    float texOffset[] = new float[] {
            -rw, -rh,   0f, -rh,    rw, -rh,
            -rw, 0f,    0f, 0f,     rw, 0f,
            -rw, rh,    0f, rh,     rw, rh
    };

    GLES20.glUseProgram(getHandle());
    GLES20.glUniform2fv(mTexOffsetHandle, 9, texOffset, 0);
}
 
Example 7
Source File: GPUImageFilterE.java    From Fatigue-Detection with MIT License 5 votes vote down vote up
protected void b(int paramInt1, int paramInt2, int paramInt3)
{
    float[] arrayOfFloat = new float[2];
    arrayOfFloat[0] = (this.aV.i[paramInt2][paramInt3].x / this.aW);
    if (this.aY) {
        arrayOfFloat[1] = (1.0F - this.aV.i[paramInt2][paramInt3].y / this.aX);
    } else {
        arrayOfFloat[1] = (this.aV.i[paramInt2][paramInt3].y / this.aX);
    }
    GLES20.glUniform2fv(paramInt1, 1, arrayOfFloat, 0);
}
 
Example 8
Source File: AbsFilter.java    From In77Camera with MIT License 4 votes vote down vote up
public void setUniform2fv(final int programId, final String name,final float[] arrayValue) {
    int location=GLES20.glGetUniformLocation(programId,name);
    GLES20.glUniform2fv(location, 1, FloatBuffer.wrap(arrayValue));
}
 
Example 9
Source File: Texture2dProgram.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.  (Primarily intended
 *        for use with SurfaceTexture.)
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
        int vertexCount, int coordsPerVertex, int vertexStride,
        float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
        GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 10
Source File: Texture2dProgram.java    From LiveVideoBroadcaster with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.  (Primarily intended
 *        for use with SurfaceTexture.)
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
                 int vertexCount, int coordsPerVertex, int vertexStride,
                 float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
            GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
        GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 11
Source File: Texture2dProgram.java    From pause-resume-video-recording with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.  (Primarily intended
 *        for use with SurfaceTexture.)
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
        int vertexCount, int coordsPerVertex, int vertexStride,
        float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
        GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 12
Source File: AbsFilter.java    From Fatigue-Detection with MIT License 4 votes vote down vote up
public void setUniform2fv(final int programId, final String name,final float[] arrayValue) {
    int location=GLES20.glGetUniformLocation(programId,name);
    GLES20.glUniform2fv(location, 1, FloatBuffer.wrap(arrayValue));
}
 
Example 13
Source File: Texture2dProgram.java    From PLDroidShortVideo with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix       The 4x4 projection matrix.
 * @param vertexBuffer    Buffer with vertex position data.
 * @param firstVertex     Index of first vertex to use in vertexBuffer.
 * @param vertexCount     Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride    Width, in bytes, of the position data for each vertex (often
 *                        vertexCount * sizeof(float)).
 * @param texMatrix       A 4x4 transformation matrix for texture coords.  (Primarily intended
 *                        for use with SurfaceTexture.)
 * @param texBuffer       Buffer with vertex texture data.
 * @param texStride       Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
                 int vertexCount, int coordsPerVertex, int vertexStride,
                 float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
            GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 14
Source File: Texture2dProgram.java    From VideoRecorder with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.  (Primarily intended
 *        for use with SurfaceTexture.)
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
        int vertexCount, int coordsPerVertex, int vertexStride,
        float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GLUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GLUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GLUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GLUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GLUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GLUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GLUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
        GLUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GLUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 15
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void uniform2fv(int location, int count, float[] v, int offset) {
    GLES20.glUniform2fv(location, count, v, offset);
}
 
Example 16
Source File: ShaderProgram.java    From VideoRecorder with Apache License 2.0 4 votes vote down vote up
public void setFloatVec2(final int location, final float[] arrayValue) {
    GLES20.glUniform2fv(location, 1, FloatBuffer.wrap(arrayValue));
}
 
Example 17
Source File: Texture2dProgram.java    From PhotoMovie with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.  (Primarily intended
 *        for use with SurfaceTexture.)
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
        int vertexCount, int coordsPerVertex, int vertexStride,
        float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
        GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 18
Source File: CameoMovieFilter.java    From PhotoMovie with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPreDraw(PhotoMovie photoMovie, int elapsedTime, FboTexture inputTexture) {
    super.onPreDraw(photoMovie, elapsedTime,inputTexture);
    GLES20.glUniform2fv(mTexSizeHandle,1,new float[]{inputTexture.getTextureWidth(),inputTexture.getTextureHeight()},0);
}
 
Example 19
Source File: Texture2dProgram.java    From kickflip-android-sdk with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
                 int vertexCount, int coordsPerVertex, int vertexStride,
                 float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
            GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Populate touch position data, if present
    if (muTouchPositionLoc >= 0){
        GLES20.glUniform2fv(muTouchPositionLoc, 1, mSummedTouchPosition, 0);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 20
Source File: Texture2dProgram.java    From AndroidPlayground with MIT License 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.  (Primarily intended
 *        for use with SurfaceTexture.)
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
        int vertexCount, int coordsPerVertex, int vertexStride,
        float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
        GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}