ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME); int fragmentShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME); GLES20.glUseProgram(quadProgram); ShaderUtil.checkGLError(TAG, "Program creation"); ShaderUtil.checkGLError(TAG, "Program parameters");
/** * Converts a raw text file, saved as a resource, into an OpenGL ES shader. * * @param type The type of shader we will be creating. * @param filename The filename of the asset file about to be turned into a shader. * @return The shader object handler. */ public static int loadGLShader(String tag, Context context, int type, String filename) throws IOException { String code = readRawTextFileFromAssets(context, filename); int shader = GLES20.glCreateShader(type); GLES20.glShaderSource(shader, code); GLES20.glCompileShader(shader); // Get the compilation status. final int[] compileStatus = new int[1]; GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0); // If the compilation failed, delete the shader. if (compileStatus[0] == 0) { Log.e(tag, "Error compiling shader: " + GLES20.glGetShaderInfoLog(shader)); GLES20.glDeleteShader(shader); shader = 0; } if (shader == 0) { throw new RuntimeException("Error creating shader."); } return shader; }
/** * Updates the OpenGL buffer contents to the provided point. Repeated calls with the same point * cloud will be ignored. */ public void update(PointCloud cloud) { if (lastPointCloud == cloud) { // Redundant call. return; } ShaderUtil.checkGLError(TAG, "before update"); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo); lastPointCloud = cloud; // If the VBO is not large enough to fit the new point cloud, resize it. numPoints = lastPointCloud.getPoints().remaining() / FLOATS_PER_POINT; if (numPoints * BYTES_PER_POINT > vboSize) { while (numPoints * BYTES_PER_POINT > vboSize) { vboSize *= 2; } GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vboSize, null, GLES20.GL_DYNAMIC_DRAW); } GLES20.glBufferSubData( GLES20.GL_ARRAY_BUFFER, 0, numPoints * BYTES_PER_POINT, lastPointCloud.getPoints()); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "after update"); }
ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, "shaders/gpu_download.vert"); int fragmentShader = ShaderUtil.loadGLShader( TAG, context,
/** * Updates the OpenGL buffer contents to the provided point. Repeated calls with the same point * cloud will be ignored. */ public void update(PointCloud cloud) { if (lastPointCloud == cloud) { // Redundant call. return; } ShaderUtil.checkGLError(TAG, "before update"); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo); lastPointCloud = cloud; // If the VBO is not large enough to fit the new point cloud, resize it. numPoints = lastPointCloud.getPoints().remaining() / FLOATS_PER_POINT; if (numPoints * BYTES_PER_POINT > vboSize) { while (numPoints * BYTES_PER_POINT > vboSize) { vboSize *= 2; } GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vboSize, null, GLES20.GL_DYNAMIC_DRAW); } GLES20.glBufferSubData( GLES20.GL_ARRAY_BUFFER, 0, numPoints * BYTES_PER_POINT, lastPointCloud.getPoints()); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "after update"); }
ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME); int fragmentShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME); GLES20.glUseProgram(quadProgram); ShaderUtil.checkGLError(TAG, "Program creation"); ShaderUtil.checkGLError(TAG, "Program parameters");
/** * Renders the point cloud. ArCore point cloud is given in world space. * * @param cameraView the camera view matrix for this frame, typically from {@link * com.google.ar.core.Camera#getViewMatrix(float[], int)}. * @param cameraPerspective the camera projection matrix for this frame, typically from {@link * com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)}. */ public void draw(float[] cameraView, float[] cameraPerspective) { float[] modelViewProjection = new float[16]; Matrix.multiplyMM(modelViewProjection, 0, cameraPerspective, 0, cameraView, 0); ShaderUtil.checkGLError(TAG, "Before draw"); GLES20.glUseProgram(programName); GLES20.glEnableVertexAttribArray(positionAttribute); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo); GLES20.glVertexAttribPointer(positionAttribute, 4, GLES20.GL_FLOAT, false, BYTES_PER_POINT, 0); GLES20.glUniform4f(colorUniform, 31.0f / 255.0f, 188.0f / 255.0f, 210.0f / 255.0f, 1.0f); GLES20.glUniformMatrix4fv(modelViewProjectionUniform, 1, false, modelViewProjection, 0); GLES20.glUniform1f(pointSizeUniform, 5.0f); GLES20.glDrawArrays(GLES20.GL_POINTS, 0, numPoints); GLES20.glDisableVertexAttribArray(positionAttribute); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "Draw"); } }
/** * Converts a raw text file, saved as a resource, into an OpenGL ES shader. * * @param type The type of shader we will be creating. * @param filename The filename of the asset file about to be turned into a shader. * @return The shader object handler. */ public static int loadGLShader(String tag, Context context, int type, String filename) throws IOException { String code = readRawTextFileFromAssets(context, filename); int shader = GLES20.glCreateShader(type); GLES20.glShaderSource(shader, code); GLES20.glCompileShader(shader); // Get the compilation status. final int[] compileStatus = new int[1]; GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0); // If the compilation failed, delete the shader. if (compileStatus[0] == 0) { Log.e(tag, "Error compiling shader: " + GLES20.glGetShaderInfoLog(shader)); GLES20.glDeleteShader(shader); shader = 0; } if (shader == 0) { throw new RuntimeException("Error creating shader."); } return shader; }
ShaderUtil.checkGLError(TAG, "before create"); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "buffer alloc"); ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME); int passthroughShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME); GLES20.glUseProgram(programName); ShaderUtil.checkGLError(TAG, "program"); pointSizeUniform = GLES20.glGetUniformLocation(programName, "u_PointSize"); ShaderUtil.checkGLError(TAG, "program params");
/** * Renders the point cloud. ArCore point cloud is given in world space. * * @param cameraView the camera view matrix for this frame, typically from {@link * com.google.ar.core.Camera#getViewMatrix(float[], int)}. * @param cameraPerspective the camera projection matrix for this frame, typically from {@link * com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)}. */ public void draw(float[] cameraView, float[] cameraPerspective) { float[] modelViewProjection = new float[16]; Matrix.multiplyMM(modelViewProjection, 0, cameraPerspective, 0, cameraView, 0); ShaderUtil.checkGLError(TAG, "Before draw"); GLES20.glUseProgram(programName); GLES20.glEnableVertexAttribArray(positionAttribute); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo); GLES20.glVertexAttribPointer(positionAttribute, 4, GLES20.GL_FLOAT, false, BYTES_PER_POINT, 0); GLES20.glUniform4f(colorUniform, 31.0f / 255.0f, 188.0f / 255.0f, 210.0f / 255.0f, 1.0f); GLES20.glUniformMatrix4fv(modelViewProjectionUniform, 1, false, modelViewProjection, 0); GLES20.glUniform1f(pointSizeUniform, 5.0f); GLES20.glDrawArrays(GLES20.GL_POINTS, 0, numPoints); GLES20.glDisableVertexAttribArray(positionAttribute); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "Draw"); } }
ShaderUtil.checkGLError(TAG, "before create"); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "buffer alloc"); ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME); int passthroughShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME); GLES20.glUseProgram(programName); ShaderUtil.checkGLError(TAG, "program"); pointSizeUniform = GLES20.glGetUniformLocation(programName, "u_PointSize"); ShaderUtil.checkGLError(TAG, "program params");
private void draw(float[] cameraView, float[] cameraPerspective) { // Build the ModelView and ModelViewProjection matrices // for calculating cube position and light. Matrix.multiplyMM(modelViewMatrix, 0, cameraView, 0, modelMatrix, 0); Matrix.multiplyMM(modelViewProjectionMatrix, 0, cameraPerspective, 0, modelViewMatrix, 0); // Set the position of the plane vertexBuffer.rewind(); GLES20.glVertexAttribPointer( planeXZPositionAlphaAttribute, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, BYTES_PER_FLOAT * COORDS_PER_VERTEX, vertexBuffer); // Set the Model and ModelViewProjection matrices in the shader. GLES20.glUniformMatrix4fv(planeModelUniform, 1, false, modelMatrix, 0); GLES20.glUniformMatrix4fv( planeModelViewProjectionUniform, 1, false, modelViewProjectionMatrix, 0); indexBuffer.rewind(); GLES20.glDrawElements( GLES20.GL_TRIANGLE_STRIP, indexBuffer.limit(), GLES20.GL_UNSIGNED_SHORT, indexBuffer); ShaderUtil.checkGLError(TAG, "Drawing plane"); }
ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME); int passthroughShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME); GLES20.glUseProgram(planeProgram); ShaderUtil.checkGLError(TAG, "Program creation"); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); ShaderUtil.checkGLError(TAG, "Texture loading"); planeUvMatrixUniform = GLES20.glGetUniformLocation(planeProgram, "u_PlaneUvMatrix"); ShaderUtil.checkGLError(TAG, "Program parameters");
private void draw(float[] cameraView, float[] cameraPerspective) { // Build the ModelView and ModelViewProjection matrices // for calculating cube position and light. Matrix.multiplyMM(modelViewMatrix, 0, cameraView, 0, modelMatrix, 0); Matrix.multiplyMM(modelViewProjectionMatrix, 0, cameraPerspective, 0, modelViewMatrix, 0); // Set the position of the plane vertexBuffer.rewind(); GLES20.glVertexAttribPointer( planeXZPositionAlphaAttribute, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, BYTES_PER_FLOAT * COORDS_PER_VERTEX, vertexBuffer); // Set the Model and ModelViewProjection matrices in the shader. GLES20.glUniformMatrix4fv(planeModelUniform, 1, false, modelMatrix, 0); GLES20.glUniformMatrix4fv( planeModelViewProjectionUniform, 1, false, modelViewProjectionMatrix, 0); indexBuffer.rewind(); GLES20.glDrawElements( GLES20.GL_TRIANGLE_STRIP, indexBuffer.limit(), GLES20.GL_UNSIGNED_SHORT, indexBuffer); ShaderUtil.checkGLError(TAG, "Drawing plane"); }
ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME); int passthroughShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME); GLES20.glUseProgram(planeProgram); ShaderUtil.checkGLError(TAG, "Program creation"); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); ShaderUtil.checkGLError(TAG, "Texture loading"); planeUvMatrixUniform = GLES20.glGetUniformLocation(planeProgram, "u_PlaneUvMatrix"); ShaderUtil.checkGLError(TAG, "Program parameters");
ShaderUtil.checkGLError(TAG, "Setting up to draw planes"); GLES20.glDepthMask(true); ShaderUtil.checkGLError(TAG, "Cleaning up after drawing planes");
throws IOException { final int vertexShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME); final int fragmentShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME); GLES20.glUseProgram(program); ShaderUtil.checkGLError(TAG, "Program creation"); GLES20.glGetUniformLocation(program, "u_ColorCorrectionParameters"); ShaderUtil.checkGLError(TAG, "Program parameters"); ShaderUtil.checkGLError(TAG, "Texture loading"); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "OBJ buffer load");
ShaderUtil.checkGLError(TAG, "Setting up to draw planes"); GLES20.glDepthMask(true); ShaderUtil.checkGLError(TAG, "Cleaning up after drawing planes");
throws IOException { final int vertexShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME); final int fragmentShader = ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME); GLES20.glUseProgram(program); ShaderUtil.checkGLError(TAG, "Program creation"); GLES20.glGetUniformLocation(program, "u_ColorCorrectionParameters"); ShaderUtil.checkGLError(TAG, "Program parameters"); ShaderUtil.checkGLError(TAG, "Texture loading"); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "OBJ buffer load");
GLES20.glEnable(GLES20.GL_DEPTH_TEST); ShaderUtil.checkGLError(TAG, "Draw");