Java Code Examples for android.opengl.GLES20#glDisableVertexAttribArray()
The following examples show how to use
android.opengl.GLES20#glDisableVertexAttribArray() .
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: GlPreview.java From CameraRecorder-android with MIT License | 6 votes |
public void draw(final int texName, final float[] mvpMatrix, final float[] stMatrix, final float aspectRatio) { useProgram(); GLES20.glUniformMatrix4fv(getHandle("uMVPMatrix"), 1, false, mvpMatrix, 0); GLES20.glUniformMatrix4fv(getHandle("uSTMatrix"), 1, false, stMatrix, 0); GLES20.glUniform1f(getHandle("uCRatio"), aspectRatio); GLES20.glBindBuffer(GL_ARRAY_BUFFER, getVertexBufferName()); GLES20.glEnableVertexAttribArray(getHandle("aPosition")); GLES20.glVertexAttribPointer(getHandle("aPosition"), VERTICES_DATA_POS_SIZE, GL_FLOAT, false, VERTICES_DATA_STRIDE_BYTES, VERTICES_DATA_POS_OFFSET); GLES20.glEnableVertexAttribArray(getHandle("aTextureCoord")); GLES20.glVertexAttribPointer(getHandle("aTextureCoord"), VERTICES_DATA_UV_SIZE, GL_FLOAT, false, VERTICES_DATA_STRIDE_BYTES, VERTICES_DATA_UV_OFFSET); GLES20.glActiveTexture(GL_TEXTURE0); GLES20.glBindTexture(texTarget, texName); GLES20.glUniform1i(getHandle(DEFAULT_UNIFORM_SAMPLER), 0); GLES20.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); GLES20.glDisableVertexAttribArray(getHandle("aPosition")); GLES20.glDisableVertexAttribArray(getHandle("aTextureCoord")); GLES20.glBindBuffer(GL_ARRAY_BUFFER, 0); GLES20.glBindTexture(GL_TEXTURE_2D, 0); }
Example 2
Source File: Triangle.java From AndroidPlayground with MIT License | 6 votes |
void draw(float[] matrix) { GLES20.glUseProgram(mProgram); GLES20.glEnableVertexAttribArray(mPositionHandle); GLES20.glVertexAttribPointer(mPositionHandle, COORD_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mBuffer); GLES20.glUniform4fv(mColorHandle, 1, COLOR, 0); GLES20.glUniformMatrix4fv(mMatrixHandle, 1, false, matrix, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, VERTEX_COUNT); count++; if (count == 10) { Utils.sendImage(1000, 1000); } GLES20.glDisableVertexAttribArray(mPositionHandle); }
Example 3
Source File: GPUImageFilter.java From SimpleVideoEditor with Apache License 2.0 | 6 votes |
public void onDraw(final int textureId, final FloatBuffer cubeBuffer, final FloatBuffer textureBuffer) { GLES20.glUseProgram(mGLProgId); runPendingOnDrawTasks(); if (!mIsInitialized) { return; } cubeBuffer.position(0); GLES20.glVertexAttribPointer(mGLAttribPosition, 2, GLES20.GL_FLOAT, false, 0, cubeBuffer); GLES20.glEnableVertexAttribArray(mGLAttribPosition); textureBuffer.position(0); GLES20.glVertexAttribPointer(mGLAttribTextureCoordinate, 2, GLES20.GL_FLOAT, false, 0, textureBuffer); GLES20.glEnableVertexAttribArray(mGLAttribTextureCoordinate); if (textureId != OpenGlUtils.NO_TEXTURE) { GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glUniform1i(mGLUniformTexture, 0); } onDrawArraysPre(); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glDisableVertexAttribArray(mGLAttribPosition); GLES20.glDisableVertexAttribArray(mGLAttribTextureCoordinate); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); }
Example 4
Source File: Triangle.java From Android-9-Development-Cookbook with MIT License | 6 votes |
public void draw(float[] mvpMatrix) { GLES20.glUseProgram(mProgram); mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); GLES20.glEnableVertexAttribArray(mPositionHandle); GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); GLES20.glUniform4fv(mColorHandle, 1, color, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); GLES20.glDisableVertexAttribArray(mPositionHandle); }
Example 5
Source File: MagicCameraInputFilter.java From TikTok with Apache License 2.0 | 5 votes |
@Override public int onDrawFrame(int textureId) { GLES20.glUseProgram(mGLProgId); runPendingOnDrawTasks(); if(!isInitialized()) { return OpenGlUtils.NOT_INIT; } mGLCubeBuffer.position(0); GLES20.glVertexAttribPointer(mGLAttribPosition, 2, GLES20.GL_FLOAT, false, 0, mGLCubeBuffer); GLES20.glEnableVertexAttribArray(mGLAttribPosition); mGLTextureBuffer.position(0); GLES20.glVertexAttribPointer(mGLAttribTextureCoordinate, 2, GLES20.GL_FLOAT, false, 0, mGLTextureBuffer); GLES20.glEnableVertexAttribArray(mGLAttribTextureCoordinate); GLES20.glUniformMatrix4fv(mTextureTransformMatrixLocation, 1, false, mTextureTransformMatrix, 0); if(isBeautyChange){ GLES20.glUniform1f(mParamsLocation, mLevel); isBeautyChange = false; } if(textureId != OpenGlUtils.NO_TEXTURE){ GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId); GLES20.glUniform1i(mGLUniformTexture, 0); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glDisableVertexAttribArray(mGLAttribPosition); GLES20.glDisableVertexAttribArray(mGLAttribTextureCoordinate); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); return OpenGlUtils.ON_DRAWN; }
Example 6
Source File: PositionTextureCoordinatesPositionInterpolationTextureSelectShaderProgram.java From tilt-game-android with MIT License | 5 votes |
@Override public void unbind(final GLState pGLState) { GLES20.glEnableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION); GLES20.glEnableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION); GLES20.glDisableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_POSITION_0_LOCATION); GLES20.glDisableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_POSITION_1_LOCATION); super.unbind(pGLState); }
Example 7
Source File: VideoEncodeRender.java From AudioVideoCodec with Apache License 2.0 | 5 votes |
@Override public void onDrawFrame() { //清空颜色 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); //设置背景颜色 GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //使用程序 GLES20.glUseProgram(program); GLES20.glUniform1i(changeType, type); GLES20.glUniform3fv(changeColor, 1, color, 0); //设置纹理 //绑定渲染纹理 默认是第0个位置 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glEnableVertexAttribArray(avPosition); GLES20.glEnableVertexAttribArray(afPosition); //使用VBO设置纹理和顶点值 useVboSetVertext(); //绘制 GLES20.GL_TRIANGLE_STRIP:复用坐标 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glDisableVertexAttribArray(avPosition); GLES20.glDisableVertexAttribArray(afPosition); //解绑纹理 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); //开始绘制 drawWater(); }
Example 8
Source File: PositionTextureCoordinatesShaderProgram.java From 30-android-libraries-in-30-days with Apache License 2.0 | 5 votes |
@Override public void bind(final GLState pGLState, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) { GLES20.glDisableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION); super.bind(pGLState, pVertexBufferObjectAttributes); GLES20.glUniformMatrix4fv(PositionTextureCoordinatesShaderProgram.sUniformModelViewPositionMatrixLocation, 1, false, pGLState.getModelViewProjectionGLMatrix(), 0); GLES20.glUniform1i(PositionTextureCoordinatesShaderProgram.sUniformTexture0Location, 0); }
Example 9
Source File: FlatShadedProgram.java From FuAgoraDemoDroid with MIT License | 5 votes |
/** * Issues the draw call. Does the full setup on every call. * * @param mvpMatrix The 4x4 projection matrix. * @param color A 4-element color vector. * @param vertexBuffer Buffer with vertex 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 data for each vertex (often vertexCount * * sizeof(float)). */ public void draw(float[] mvpMatrix, float[] color, FloatBuffer vertexBuffer, int firstVertex, int vertexCount, int coordsPerVertex, int vertexStride) { GlUtil.checkGlError("draw start"); // Select the program. GLES20.glUseProgram(mProgramHandle); GlUtil.checkGlError("glUseProgram"); // Copy the model / view / projection matrix over. GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0); GlUtil.checkGlError("glUniformMatrix4fv"); // Copy the color vector in. GLES20.glUniform4fv(muColorLoc, 1, color, 0); GlUtil.checkGlError("glUniform4fv "); // 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"); // Draw the rect. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount); GlUtil.checkGlError("glDrawArrays"); // Done -- disable vertex array and program. GLES20.glDisableVertexAttribArray(maPositionLoc); GLES20.glUseProgram(0); }
Example 10
Source File: FlatShadedProgram.java From AndroidPlayground with MIT License | 5 votes |
/** * Issues the draw call. Does the full setup on every call. * * @param mvpMatrix The 4x4 projection matrix. * @param color A 4-element color vector. * @param vertexBuffer Buffer with vertex 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 data for each vertex (often vertexCount * * sizeof(float)). */ public void draw(float[] mvpMatrix, float[] color, FloatBuffer vertexBuffer, int firstVertex, int vertexCount, int coordsPerVertex, int vertexStride) { GlUtil.checkGlError("draw start"); // Select the program. GLES20.glUseProgram(mProgramHandle); GlUtil.checkGlError("glUseProgram"); // Copy the model / view / projection matrix over. GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0); GlUtil.checkGlError("glUniformMatrix4fv"); // Copy the color vector in. GLES20.glUniform4fv(muColorLoc, 1, color, 0); GlUtil.checkGlError("glUniform4fv "); // 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"); // Draw the rect. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount); GlUtil.checkGlError("glDrawArrays"); // Done -- disable vertex array and program. GLES20.glDisableVertexAttribArray(maPositionLoc); GLES20.glUseProgram(0); }
Example 11
Source File: Triangle.java From opengl with Apache License 2.0 | 5 votes |
/** * 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 GLES20.glUseProgram(mProgram); // get handle to vertex shader's vPosition member mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES20.glEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES20.glVertexAttribPointer( mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); // get handle to fragment shader's vColor member mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); // Set color for drawing the triangle GLES20.glUniform4fv(mColorHandle, 1, color, 0); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); MyGLRenderer.checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); MyGLRenderer.checkGlError("glUniformMatrix4fv"); // Draw the triangle GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); }
Example 12
Source File: Attribute.java From PD-classes with GNU General Public License v3.0 | 4 votes |
public void disable() { GLES20.glDisableVertexAttribArray( location ); }
Example 13
Source File: Triangle.java From Eye-blink-detector with MIT License | 4 votes |
public void draw(float[] mvpMatrix) { ByteBuffer bb = ByteBuffer.allocateDirect( // (number of coordinate values * 4 bytes per float) triangleCoords.length * 4); // use the device hardware's native byte order bb.order(ByteOrder.nativeOrder()); // create a floating point buffer from the ByteBuffer vertexBuffer = bb.asFloatBuffer(); // add the coordinates to the FloatBuffer vertexBuffer.put(triangleCoords); // set the buffer to read the first coordinate vertexBuffer.position(0); // Add program to OpenGL ES environment GLES20.glUseProgram(mProgram); // get handle to vertex shader's vPosition member mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES20.glEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,GLES20.GL_FLOAT,false, vertexStride, vertexBuffer); // get handle to fragment shader's vColor member mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); // Set color for drawing the triangle GLES20.glUniform4fv(mColorHandle, 1, color, 0); // Draw the triangle GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); // Disable vertex array //GLES20.glDisableVertexAttribArray(mPositionHandle); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); // Pass the projection and view transformation to the shader GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); // Draw the triangle GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); }
Example 14
Source File: InstantCameraView.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private void onDraw(Integer cameraId) { if (!initied) { return; } if (!eglContext.equals(egl10.eglGetCurrentContext()) || !eglSurface.equals(egl10.eglGetCurrentSurface(EGL10.EGL_DRAW))) { if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { if (BuildVars.LOGS_ENABLED) { FileLog.e("eglMakeCurrent failed " + GLUtils.getEGLErrorString(egl10.eglGetError())); } return; } } cameraSurface.updateTexImage(); if (!recording) { videoEncoder.startRecording(cameraFile, EGL14.eglGetCurrentContext()); recording = true; int orientation = currentSession.getCurrentOrientation(); if (orientation == 90 || orientation == 270) { float temp = scaleX; scaleX = scaleY; scaleY = temp; } } videoEncoder.frameAvailable(cameraSurface, cameraId, System.nanoTime()); cameraSurface.getTransformMatrix(mSTMatrix); GLES20.glUseProgram(drawProgram); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, cameraTexture[0]); GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 12, vertexBuffer); GLES20.glEnableVertexAttribArray(positionHandle); GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer); GLES20.glEnableVertexAttribArray(textureHandle); GLES20.glUniformMatrix4fv(textureMatrixHandle, 1, false, mSTMatrix, 0); GLES20.glUniformMatrix4fv(vertexMatrixHandle, 1, false, mMVPMatrix, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glDisableVertexAttribArray(positionHandle); GLES20.glDisableVertexAttribArray(textureHandle); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); GLES20.glUseProgram(0); egl10.eglSwapBuffers(eglDisplay, eglSurface); }
Example 15
Source File: Texture2dProgram.java From MockCamera with Apache License 2.0 | 4 votes |
/** * 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(programHandle); GlUtil.checkGlError("glUseProgram"); // Set the texture. GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(textureTarget, textureId); // Copy the model / view / projection matrix over. GLES20.glUniformMatrix4fv(mvpMatrixLoc, 1, false, mvpMatrix, 0); GlUtil.checkGlError("glUniformMatrix4fv"); // Copy the texture transformation matrix over. GLES20.glUniformMatrix4fv(texMatrixLoc, 1, false, texMatrix, 0); GlUtil.checkGlError("glUniformMatrix4fv"); // Enable the "aPosition" vertex attribute. GLES20.glEnableVertexAttribArray(positionLoc); GlUtil.checkGlError("glEnableVertexAttribArray"); // Connect vertexBuffer to "aPosition". GLES20.glVertexAttribPointer(positionLoc, coordsPerVertex, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); GlUtil.checkGlError("glVertexAttribPointer"); // Enable the "aTextureCoord" vertex attribute. GLES20.glEnableVertexAttribArray(textureCoordLoc); GlUtil.checkGlError("glEnableVertexAttribArray"); // Connect texBuffer to "aTextureCoord". GLES20.glVertexAttribPointer(textureCoordLoc, 2, GLES20.GL_FLOAT, false, texStride, texBuffer); GlUtil.checkGlError("glVertexAttribPointer"); // Populate the convolution kernel, if present. if (kernelLoc >= 0) { GLES20.glUniform1fv(kernelLoc, KERNEL_SIZE, kernel, 0); GLES20.glUniform2fv(texOffsetLoc, KERNEL_SIZE, texOffset, 0); GLES20.glUniform1f(colorAdjustLoc, colorAdjust); } // Draw the rect. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount); GlUtil.checkGlError("glDrawArrays"); // Done -- disable vertex array, texture, and program. GLES20.glDisableVertexAttribArray(positionLoc); GLES20.glDisableVertexAttribArray(textureCoordLoc); GLES20.glBindTexture(textureTarget, 0); GLES20.glUseProgram(0); }
Example 16
Source File: EglViewport.java From Lassi-Android with MIT License | 4 votes |
/** * The issue with the CIRCLE shader is that if the textureMatrix has a scale value, * it fails miserably, not taking the scale into account. * So what we can do here is * <p> * - read textureMatrix scaleX and scaleY values. This is pretty much impossible to do from the matrix itself * without making risky assumptions over the order of operations. * https://www.opengl.org/discussion_boards/showthread.php/159215-Is-it-possible-to-extract-rotation-translation-scale-given-a-matrix * So we prefer passing scaleX and scaleY here to the draw function. * - pass these values to the vertex shader * - pass them to the fragment shader * - in the fragment shader, take this scale value into account */ private void drawFrame(int textureId, float[] textureMatrix, FloatBuffer vertexBuffer, FloatBuffer texBuffer) { check("draw start"); // Select the program. GLES20.glUseProgram(mProgramHandle); check("glUseProgram"); // Set the texture. GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(mTextureTarget, textureId); // Copy the model / view / projection matrix over. GLES20.glUniformMatrix4fv(muMVPMatrixLocation, 1, false, IDENTITY_MATRIX, 0); check("glUniformMatrix4fv"); // Copy the texture transformation matrix over. GLES20.glUniformMatrix4fv(muTexMatrixLocation, 1, false, textureMatrix, 0); check("glUniformMatrix4fv"); // Enable the "aPosition" vertex attribute. // Connect vertexBuffer to "aPosition". GLES20.glEnableVertexAttribArray(maPositionLocation); check("glEnableVertexAttribArray"); GLES20.glVertexAttribPointer(maPositionLocation, 2, GLES20.GL_FLOAT, false, 8, vertexBuffer); check("glVertexAttribPointer"); // Enable the "aTextureCoord" vertex attribute. // Connect texBuffer to "aTextureCoord". GLES20.glEnableVertexAttribArray(maTextureCoordLocation); check("glEnableVertexAttribArray"); GLES20.glVertexAttribPointer(maTextureCoordLocation, 2, GLES20.GL_FLOAT, false, 8, texBuffer); check("glVertexAttribPointer"); // Draw the rect. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, VERTEX_COUNT); check("glDrawArrays"); // Done -- disable vertex array, texture, and program. GLES20.glDisableVertexAttribArray(maPositionLocation); GLES20.glDisableVertexAttribArray(maTextureCoordLocation); GLES20.glBindTexture(mTextureTarget, 0); GLES20.glUseProgram(0); }
Example 17
Source File: TwoTextureMovieFilter.java From PhotoMovie with Apache License 2.0 | 4 votes |
@Override public void drawFrame(PhotoMovie photoMovie, int elapsedTime, FboTexture inputTexture) { if (!mIsInitialized) { return; } GLHelper.checkGlError(); if (!GLES20.glIsProgram(mProgId)) { initShader(); GlUtil.checkGlError("initShader"); } GLES20.glUseProgram(mProgId); loadBitmap(); onPreDraw(photoMovie, elapsedTime, inputTexture); FloatBuffer cubeBuffer = mCubeBuffer; FloatBuffer textureCubeBuffer = mTextureCubeBuffer; ; if (mIsOpaque) { GLES20.glDisable(GLES20.GL_BLEND); } else { GLES20.glEnable(GLES20.GL_BLEND); } cubeBuffer.position(0); GLES20.glVertexAttribPointer(mAttribPosition, 2, GLES20.GL_FLOAT, false, 0, cubeBuffer); GLES20.glEnableVertexAttribArray(mAttribPosition); textureCubeBuffer.position(0); GLES20.glVertexAttribPointer(mAttribTexCoord, 2, GLES20.GL_FLOAT, false, 0, textureCubeBuffer); GLES20.glEnableVertexAttribArray(mAttribTexCoord); int glTextureId = inputTexture.getId(); if (glTextureId != GLHelper.NO_TEXTURE) { GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, glTextureId); GLES20.glUniform1i(mUniformTexture, 0); } //加载第二纹理 if (mTexture2CoordinateAttribute >= 0) { GLES20.glEnableVertexAttribArray(mTexture2CoordinateAttribute); mTexture2CoordinatesBuffer.position(0); GLES20.glVertexAttribPointer(mTexture2CoordinateAttribute, 2, GLES20.GL_FLOAT, false, 0, mTexture2CoordinatesBuffer); } if (mTexture2Id >= 0) { GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture2Id); GLES20.glUniform1i(mTexture2Uniform2, 3); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glDisableVertexAttribArray(mAttribPosition); GLES20.glDisableVertexAttribArray(mAttribTexCoord); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glDisable(GLES20.GL_BLEND); }
Example 18
Source File: ShapeBuffer.java From AndroidDemoProjects with Apache License 2.0 | 4 votes |
/** * Draws all the triangles currently in the buffer. * * @param mvpMatrix the combined model, view, and projection matrices. */ public void draw(float[] mvpMatrix) { if (mCurrentIndex == 0) { // Nothing to draw. return; } // Load up our data: checkGlError("draw init"); mVertexBuffer.clear(); mVertexBuffer.put(mVertexData); mVertexBuffer.position(0); mColorBuffer.clear(); mColorBuffer.put(mColorData); mColorBuffer.position(0); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); checkGlError("draw start"); // Add program to OpenGL environment. GLES20.glUseProgram(mShaderProgram); checkGlError("glUseProgram"); // Enable a handle to the triangle vertices. GLES20.glEnableVertexAttribArray(mPositionAttributeHandle); // Prepare the triangle coordinate data. GLES20.glVertexAttribPointer(mPositionAttributeHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mVertexBuffer); checkGlError("glVertexAttribPointer - vert"); // Enable a handle to the triangle vertices. GLES20.glEnableVertexAttribArray(mColorAttributeHandle); // Prepare the color data. GLES20.glVertexAttribPointer(mColorAttributeHandle, COLOR_CHANNELS_PER_VERTEX, GLES20.GL_UNSIGNED_BYTE, true, COLOR_STRIDE, mColorBuffer); checkGlError("glVertexAttribPointer - color"); // Apply the projection and view transformation. GLES20.glUniformMatrix4fv(mMVPMatrixUniformHandle, 1, false, mvpMatrix, 0); checkGlError("glUniformMatrix4fv"); // Draw the buffers! GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mCurrentIndex); checkGlError("draw call"); // Disable vertex arrays. GLES20.glDisableVertexAttribArray(mPositionAttributeHandle); checkGlError("position attrib arrays disabled"); GLES20.glDisableVertexAttribArray(mColorAttributeHandle); checkGlError("vertex attrib arrays disabled"); }
Example 19
Source File: GLLabel.java From Tanks with MIT License | 4 votes |
@Override public void draw(RendererContext context) { Data data = dataProvider.get(); Vector3 color = data.colorCoefficients; ShaderLabel shader = (ShaderLabel)Shader.getCurrent(); // get dynamic resources Geometry geometryData = GameContext.resources.getGeometry(new LabelGeometrySource(data.value, data.mode, data.charWidth, data.charHeight)); // build result matrix Matrix.multiplyMM(modelViewMatrix, 0, context.getOrthoMatrix(), 0, data.modelMatrix, 0); // bind texture to 0 slot GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle()); // send data to shader GLES20.glUniform1i(shader.uniformTextureHandle, 0); GLES20.glUniformMatrix4fv(shader.uniformModelViewMatrixHandle, 1, false, modelViewMatrix, 0); GLES20.glUniform4f(shader.uniformColorCoefficients, color.getX(), color.getY(), color.getZ(), 1); // set buffer or reset if dynamic GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle()); switch (geometryData.getMode()) { case Static: GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, 0); GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, 8); break; case Dynamic: FloatBuffer buffer = geometryData.getData(); buffer.position(0); GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, buffer); buffer.position(2); GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, buffer); break; } // enable arrays GLES20.glEnableVertexAttribArray(shader.attributePositionHandle); GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle); // validating if debug shader.validate(); geometryData.validate(); textureData.validate(); // draw GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount()); // disable arrays GLES20.glDisableVertexAttribArray(shader.attributePositionHandle); GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle); // release dynamic resources GameContext.resources.release(geometryData); }
Example 20
Source File: Texture2dProgram.java From pause-resume-video-recording with Apache License 2.0 | 4 votes |
/** * 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); }