@Override public void glBindVertexArray (int array) { GLES30.glBindVertexArray(array); }
@Override public void glGenVertexArrays (int n, int[] arrays, int offset) { GLES30.glGenVertexArrays(n, arrays, offset); }
@Override public String glGetStringi (int name, int index) { return GLES30.glGetStringi(name, index); }
public static int linkProgram(int vertexShaderId, int fragmentShaderId) { final int programObjectId = glCreateProgram(); if (programObjectId == 0) { Timber.d("Could not create new program"); return 0; } glAttachShader(programObjectId, vertexShaderId); glAttachShader(programObjectId, fragmentShaderId); glLinkProgram(programObjectId); final int[] linkStatus = new int[1]; glGetProgramiv(programObjectId, GL_LINK_STATUS, linkStatus, 0); Timber.d("Result of linking program:\n" + glGetProgramInfoLog(programObjectId)); if (linkStatus[0] == 0) { glDeleteProgram(programObjectId); Timber.d("Linking of program failed"); return 0; } return programObjectId; }
public void drawSelf(int texId) { //指定使用某套着色器程序 GLES30.glUseProgram(mProgram); //将最终变换矩阵传入渲染管线 GLES30.glActiveTexture(GLES30.GL_TEXTURE0); GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, texId); GLES30.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0); GLES30.glBindVertexArray(mVAOId); GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, mIndicesBufferId); //绑定纹理 GLES30.glDrawElements(GLES30.GL_TRIANGLES, vCount, GLES30.GL_UNSIGNED_BYTE, 0); // GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, vCount); GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, 0); GLES30.glBindVertexArray(0); } }
GLES30.glUseProgram(mProgram); GLES30.glUniformMatrix4fv(mModelMatrixHandle, 1, false, model, 0); glUniform4f(maColorHandle, 0.0f, 1.0f, 1.0f, 1.0f); GLES30.glEnableVertexAttribArray(maPositionHandle); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVertexBufferId); GLES30.glVertexAttribPointer(maPositionHandle, 3, GLES30.GL_FLOAT, false, 3 * 4, 0); GLES30.glEnableVertexAttribArray(uMatrixLocation1); GLES30.glEnableVertexAttribArray(uMatrixLocation2); GLES30.glEnableVertexAttribArray(uMatrixLocation3); GLES30.glEnableVertexAttribArray(uMatrixLocation4); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mModelBufferId); GLES30.glVertexAttribPointer(uMatrixLocation1, 4, GLES30.GL_FLOAT, false, 4 * 4, 0); GLES30.glVertexAttribPointer(uMatrixLocation2, 4, GLES30.GL_FLOAT, false, 4 * 4, 4); GLES30.glVertexAttribPointer(uMatrixLocation3, 4, GLES30.GL_FLOAT, false, 4 * 4, 8); GLES30.glVertexAttribPointer(uMatrixLocation4, 4, GLES30.GL_FLOAT, false, 4 * 4, 12); GLES30.glVertexAttribDivisor(uMatrixLocation1,1); GLES30.glVertexAttribDivisor(uMatrixLocation2,2); GLES30.glVertexAttribDivisor(uMatrixLocation3,3); GLES30.glVertexAttribDivisor(uMatrixLocation4,4); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
public void initVAO() { int[] vaoIds = new int[1]; GLES30.glGenVertexArrays(1, vaoIds, 0); mVAOId = vaoIds[0]; GLES30.glBindVertexArray(mVAOId); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVertexBufferId); GLES30.glEnableVertexAttribArray(maPositionHandle); GLES30.glVertexAttribPointer(maPositionHandle, 3, GLES30.GL_FLOAT, false, 3 * 4, 0); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mTextureBufferId); GLES30.glEnableVertexAttribArray(maTexCoorHandle); GLES30.glVertexAttribPointer(maTexCoorHandle, 2, GLES30.GL_FLOAT, false, 2 * 4, 0); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); // GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, mIndicesBufferId); // GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, 0); GLES30.glBindVertexArray(0); }
GLES30.glGenBuffers(3, bufferIds, 0); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVertexBufferId); GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, vertices.length * 4, mVertexBuffer, GLES30.GL_STATIC_DRAW); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mTextureBufferId); GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, textures.length * 4, mTextureBuffer, GLES30.GL_STATIC_DRAW); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, mIndicesBufferId); GLES30.glBufferData(GLES30.GL_ELEMENT_ARRAY_BUFFER, indices.length, mIndicesBuffer, GLES30.GL_STATIC_DRAW); GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, 0);
texture = new int[bufferCount]; bufferUsed = new Boolean[bufferCount]; GLES30.glGenBuffers(bufferCount, pbo, 0); GLES20.glGenFramebuffers(bufferCount, frameBuffer, 0); GLES20.glGenTextures(bufferCount, texture, 0); GLES30.glTexImage2D( GLES30.GL_TEXTURE_2D, 0, GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, pbo[i]); GLES30.glBufferData( GLES30.GL_PIXEL_PACK_BUFFER, pixelBufferSize, null, GLES30.GL_DYNAMIC_READ); GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0);
private void beginVAO() { IntBuffer vaoIdBuffer = IntBuffer.allocate(1); GLES30.glGenVertexArrays(1, vaoIdBuffer); vaoId = vaoIdBuffer.get(0); GLES30.glBindVertexArray(vaoId); }
@Override public int glGetError() { return GLES30.glGetError(); }
GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, pbo[bufferIndex]); GLES30.glReadBuffer(GLES30.GL_COLOR_ATTACHMENT0); GLES30.glReadPixels( 0, 0, GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0);
/** * Writes GL version info to the log. */ @SuppressLint("InlinedApi") public static void logVersionInfo() { Log.i(TAG, "vendor : " + GLES10.glGetString(GLES10.GL_VENDOR)); Log.i(TAG, "renderer: " + GLES10.glGetString(GLES10.GL_RENDERER)); Log.i(TAG, "version : " + GLES10.glGetString(GLES10.GL_VERSION)); if (BuildCheck.isAndroid4_3()) { final int[] values = new int[1]; GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0); final int majorVersion = values[0]; GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0); final int minorVersion = values[0]; if (GLES30.glGetError() == GLES30.GL_NO_ERROR) { Log.i(TAG, "version: " + majorVersion + "." + minorVersion); } } }
/** * Releases a previously requested frame buffer. If input buffer index is invalid, an exception * will be thrown. * * @param bufferIndex the index to the frame buffer to be acquired. It has to be a frame index * returned from submitFrame(). */ public void releaseFrame(int bufferIndex) { if (bufferIndex < 0 || bufferIndex >= bufferCount || !bufferUsed[bufferIndex]) { throw new RuntimeException("Invalid buffer index."); } GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, pbo[bufferIndex]); GLES30.glUnmapBuffer(GLES30.GL_PIXEL_PACK_BUFFER); GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0); bufferUsed[bufferIndex] = false; }
GLES30.glBlitFramebuffer( 0, 0, mWindowSurface.getWidth(), mWindowSurface.getHeight(), 0, 0, mRecordSurface.getWidth(), mRecordSurface.getHeight(), //must match the mediarecorder surface size if ((err = GLES30.glGetError()) != GLES30.GL_NO_ERROR) Log.w(TAG, "ERROR: glBlitFramebuffer failed: 0x" + Integer.toHexString(err));
public boolean SupportsExtension(String extension) { int[] num_ext = new int[1]; GLES30.glGetIntegerv(GLES30.GL_NUM_EXTENSIONS, num_ext, 0); for (int i = 0; i < num_ext[0]; ++i) { String ext = GLES30.glGetStringi(GLES30.GL_EXTENSIONS, i); if (ext.equals(extension)) return true; } return false; }
/** * Acquires the frame requested earlier. This routine returns a TextureReaderImage object that * contains the pixels mapped to the frame buffer requested previously through submitFrame(). * * <p>If input buffer index is invalid, an exception will be thrown. * * @param bufferIndex the index to the frame buffer to be acquired. It has to be a frame index * returned from submitFrame(). * @return a TextureReaderImage object if succeed. Null otherwise. */ public TextureReaderImage acquireFrame(int bufferIndex) { if (bufferIndex < 0 || bufferIndex >= bufferCount || !bufferUsed[bufferIndex]) { throw new RuntimeException("Invalid buffer index."); } // Bind the current PB and acquire the pixel buffer. GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, pbo[bufferIndex]); ByteBuffer mapped = (ByteBuffer) GLES30.glMapBufferRange( GLES30.GL_PIXEL_PACK_BUFFER, 0, pixelBufferSize, GLES30.GL_MAP_READ_BIT); // Wrap the mapped buffer into TextureReaderImage object. TextureReaderImage buffer = new TextureReaderImage(imageWidth, imageHeight, imageFormat, mapped); return buffer; }
@Override public void glBufferData(int target, int capacity, int usage) { GLES30.glBufferData(target, capacity, null, usage); }
@Override public void glBindBuffer(int target, int buffer) { GLES30.glBindBuffer(target, buffer); }
@Override public int glGenBuffers() { int[] buffer = new int[1]; GLES30.glGenBuffers(1, buffer, 0); return buffer[0]; }