使用Cube Map,首先要检测设备是否支持Cube Map 材质,本例使用以下代码检测设备是否支持Cube Map。
- private boolean checkIfContextSupportsCubeMap(GL10 gl) {
- return checkIfContextSupportsExtension(gl, "GL_OES_texture_cube_map");
- }
- /**
- * This is not the fastest way to check for an extension, but fine if
- * we are only checking for a few extensions each time a context is created.
- * @param gl
- * @param extension
- * @return true if the extension is present in the current context.
- */
- private boolean checkIfContextSupportsExtension(GL10 gl, String extension) {
- String extensions = " " + gl.glGetString(GL10.GL_EXTENSIONS) + " ";
- // The extensions string is padded with spaces between extensions, but not
- // necessarily at the beginning or end. For simplicity, add spaces at the
- // beginning and end of the extensions string and the extension string.
- // This means we can avoid special-case checks for the first or last
- // extension, as well as avoid special-case checks when an extension name
- // is the same as the first part of another extension name.
- return extensions.indexOf(" " + extension + " ") >= 0;
- }
