Created
May 30, 2013 03:31
-
-
Save tsohr/5675570 to your computer and use it in GitHub Desktop.
Get the max limit texture size supported on the device dynamically.
based on: http://android-developers.blogspot.kr/2009/04/introducing-glsurfaceview.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.apis.graphics; | |
import java.nio.IntBuffer; | |
import javax.microedition.khronos.egl.EGLConfig; | |
import javax.microedition.khronos.opengles.GL10; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.opengl.GLSurfaceView; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.MotionEvent; | |
public class ClearActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mGLView = new ClearGLSurfaceView(this); | |
setContentView(mGLView); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
mGLView.onPause(); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
mGLView.onResume(); | |
} | |
private GLSurfaceView mGLView; | |
} | |
class ClearGLSurfaceView extends GLSurfaceView { | |
public ClearGLSurfaceView(Context context) { | |
super(context); | |
mRenderer = new ClearRenderer(); | |
setRenderer(mRenderer); | |
} | |
public boolean onTouchEvent(final MotionEvent event) { | |
queueEvent(new Runnable(){ | |
public void run() { | |
mRenderer.setColor(event.getX() / getWidth(), | |
event.getY() / getHeight(), 1.0f); | |
}}); | |
return true; | |
} | |
ClearRenderer mRenderer; | |
} | |
class ClearRenderer implements GLSurfaceView.Renderer { | |
private int mTextureLimit; | |
public void onSurfaceCreated(GL10 gl, EGLConfig config) { | |
IntBuffer textureLimit = IntBuffer.allocate(1); | |
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, textureLimit); | |
mTextureLimit = textureLimit.get(0); | |
Log.i(this.getClass().getSimpleName(), "texture limit = " + mTextureLimit); | |
} | |
public void onSurfaceChanged(GL10 gl, int w, int h) { | |
gl.glViewport(0, 0, w, h); | |
Log.i(this.getClass().getSimpleName(), "w = " + w + ", h = " + h); | |
} | |
public void onDrawFrame(GL10 gl) { | |
gl.glClearColor(mRed, mGreen, mBlue, 1.0f); | |
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); | |
} | |
public void setColor(float r, float g, float b) { | |
mRed = r; | |
mGreen = g; | |
mBlue = b; | |
} | |
private float mRed; | |
private float mGreen; | |
private float mBlue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment