diff options
| author | Jack Palevich <jackpal@google.com> | 2009-12-24 16:18:25 +0800 |
|---|---|---|
| committer | Jack Palevich <jackpal@google.com> | 2009-12-31 13:19:21 +0800 |
| commit | c1645153e799c488fc66eb0d481a3a3b21c94323 (patch) | |
| tree | 8845c0a7b5b8a0d127511c96354dc9907423f539 /samples/ApiDemos/src/com/example/android/apis/graphics/StaticTriangleRenderer.java | |
| parent | e499caf9616f574e4113f5ec86bf31d81793c088 (diff) | |
Tool for compressing/decompressing ETC1 textures.
The ETC1 texture format is commonly supported by
OpenGL ES 2.0-capable GPUs.
For historical reasons ETC1 texture files have the
default extension .PKM
This tool relies on the libETC1 library to
compress and decompress the image data.
Diffstat (limited to 'samples/ApiDemos/src/com/example/android/apis/graphics/StaticTriangleRenderer.java')
| -rw-r--r-- | samples/ApiDemos/src/com/example/android/apis/graphics/StaticTriangleRenderer.java | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/samples/ApiDemos/src/com/example/android/apis/graphics/StaticTriangleRenderer.java b/samples/ApiDemos/src/com/example/android/apis/graphics/StaticTriangleRenderer.java index c7e7e6409..7ef084105 100644 --- a/samples/ApiDemos/src/com/example/android/apis/graphics/StaticTriangleRenderer.java +++ b/samples/ApiDemos/src/com/example/android/apis/graphics/StaticTriangleRenderer.java @@ -50,9 +50,25 @@ import com.example.android.apis.R; */ public class StaticTriangleRenderer implements GLSurfaceView.Renderer{ + public interface TextureLoader { + /** + * Load a texture into the currently bound OpenGL texture. + */ + void load(GL10 gl); + } + public StaticTriangleRenderer(Context context) { + init(context, new RobotTextureLoader()); + } + + public StaticTriangleRenderer(Context context, TextureLoader loader) { + init(context, loader); + } + + private void init(Context context, TextureLoader loader) { mContext = context; mTriangle = new Triangle(); + mTextureLoader = loader; } public void onSurfaceCreated(GL10 gl, EGLConfig config) { @@ -99,22 +115,7 @@ public class StaticTriangleRenderer implements GLSurfaceView.Renderer{ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - - InputStream is = mContext.getResources() - .openRawResource(R.raw.robot); - Bitmap bitmap; - try { - bitmap = BitmapFactory.decodeStream(is); - } finally { - try { - is.close(); - } catch(IOException e) { - // Ignore. - } - } - - GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0); - bitmap.recycle(); + mTextureLoader.load(gl); } public void onDrawFrame(GL10 gl) { @@ -181,6 +182,27 @@ public class StaticTriangleRenderer implements GLSurfaceView.Renderer{ private Context mContext; private Triangle mTriangle; private int mTextureID; + private TextureLoader mTextureLoader; + + private class RobotTextureLoader implements TextureLoader { + public void load(GL10 gl) { + InputStream is = mContext.getResources().openRawResource( + R.raw.robot); + Bitmap bitmap; + try { + bitmap = BitmapFactory.decodeStream(is); + } finally { + try { + is.close(); + } catch (IOException e) { + // Ignore. + } + } + + GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0); + bitmap.recycle(); + } + } static class Triangle { public Triangle() { |
