Image processing is done on fragment shader. Vertex shader is used to display the quad and does simple model, view, projection transformation. It does it by loading an image and mapping it as texture on a rectangular plane (a quad). Sample demo is Android application that does simple image processing using shader. To test shader code in Android emulator, you must create Android Virtual Device (AVD) with minimum target API Level 15 and select Use Host GPU to enable GPU emulation, otherwise your application may crash. OpenGL ES 2.0 support in Android Virtual Device is available with Android API level 15 release. GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, indexBuffer) Running Shader on Android Virtual Device We use 2 triangles to draw a quad with each triangle that consists of 3 indices. GLES20.glEnableVertexAttribArray(g_posHandle) DrawĪfter vertex buffer filled, texture is set and model, view, projection transformation, we need to draw quad using glDrawElements(). GLES20.glVertexAttribPointer(g_posHandle, Both methods return handle to variable location. First parameter is program handle and second parameter is string name of variables as written in shader source code. To copy data into uniform variables or attribute variables, you need to get handle to location of that uniform or attribute using glGetUniformLocation() than glGetAttribLocation() that previously bound to program. GLES20.glGetProgramInfoLog(programHandle)) īefore you can copy data to program, make sure to activate the program by calling glUseProgram() and pass program handle that you want to make active. GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, linkStatus, 0) get linking status final int linkStatus = new int Bind attributes if (attributes != null) GLES20.glAttachShader(programHandle, pxlShader) GLES20.glAttachShader(programHandle, vtxShader) Int programHandle=GLES20.glCreateProgram() Public static int createProgram( final int vtxShader, final int pxlShader,
0 Comments
Leave a Reply. |