2013-08-26 56 views
3

我在整個互聯網上搜索了好幾天,找到了解決方案,並且什麼也沒得到。在Android上的TextView上打印GPU信息(渲染器,版本,供應商)

我想獲得有關Android設備上的GPU(如RENDERER,VENDOR和VERSION)的主要信息,並且能夠在定義的XML佈局的textview上打印它。我嘗試了很多方法,沒有爲我工作。大家說,使用這樣的:

Log.d("GL", "GL_RENDERER = " + gl.glGetString(GL10.GL_RENDERER)); 
Log.d("GL", "GL_VENDOR = " + gl.glGetString(GL10.GL_VENDOR)); 
Log.d("GL", "GL_VERSION = " + gl.glGetString(GL10.GL_VERSION)); 
Log.i("GL", "GL_EXTENSIONS = " + gl.glGetString(GL10.GL_EXTENSIONS)); 

我實現了隔壁班:

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mGLView = new GLSurfaceView(this); 
    mGLView.setRenderer(new ClearRenderer()); 
    setContentView(mGLView); 

} 


private GLSurfaceView mGLView; 
static class ClearRenderer implements GLSurfaceView.Renderer { 

    public final static String renderer = null; 
    Random aleatorio = new Random(); 

    public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
     float r = aleatorio.nextFloat(); 
     float g = aleatorio.nextFloat(); 
     float b = aleatorio.nextFloat(); 
     gl.glClearColor(r, g, b, 1.0f); 

     Log.d("GL", "GL_RENDERER = " + gl.glGetString(GL10.GL_RENDERER)); 
     Log.d("GL", "GL_VENDOR = " + gl.glGetString(GL10.GL_VENDOR)); 
     Log.d("GL", "GL_VERSION = " + gl.glGetString(GL10.GL_VERSION)); 
     Log.i("GL", "GL_EXTENSIONS = " + gl.glGetString(GL10.GL_EXTENSIONS)); 

    } 

    public void onSurfaceChanged(GL10 gl, int w, int h) {   
    } 

    public void onDrawFrame(GL10 gl) { 
     gl.glClear(gl.GL_COLOR_BUFFER_BIT);   
    } 
} 
} 

偉大的工程,但我不知道如何把這些日誌到一個TextView。設置ContentView到我的GLSurfaceView我不知道如何在那裏使用TextView。

我ASLO使用tryed:

String renderer = gl.glGetString(GL10.GL_VENDOR); 
Log.d("GL", renderer); 
在同一個地方,以前的日誌是,這也workg偉大的,我可以看到在logcat的供應商的正確的價值

但我仍然不知道如何將此值傳遞給textview(例如tv.setText(renderer))並將其用於普通佈局。

如果有人能夠通過一個簡單的例子來幫助我解決這個問題,我將非常感激。考慮到我從來沒有使用OpenGL,我只想獲得關於它的信息。我也接受,如果你以另一種方式告訴我(如果可能,更簡單:D)以獲取該信息。

在此先感謝。

回答

2

最後,在解決了這個問題之後,我找到了一個可能的解決方案。也許這不是最好的,但我沒有其他的,它的工作。

我用共享喜好來存儲信息。我使用實現的GLSurfaceView創建了一個啓動器活動,延遲時間爲3秒(足以存儲所有字符串),在此延遲之後,我需要開始的活動。

的發射活動是這樣的:

package system.info.to.txt; 

import java.util.Random; 
import javax.microedition.khronos.egl.EGLConfig; 
import javax.microedition.khronos.opengles.GL10; 
import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.opengl.GLSurfaceView; 
import android.os.Bundle; 
import android.os.CountDownTimer; 
import android.util.Log; 

public class RendererLoader extends Activity { 

private static SharedPreferences prefs; 
private static SharedPreferences.Editor editor; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    prefs = this.getSharedPreferences("GPUinfo", Context.MODE_PRIVATE); 
    mGLView = new GLSurfaceView(this); 
    mGLView.setRenderer(new ClearRenderer()); 
    setContentView(mGLView);  

    final Intent intent = new Intent(this, Info.class); 
    new CountDownTimer(3000, 9999) 
     { 
      public void onTick(long millisUntilFinished) { 
        // Not used 
      } 
      public void onFinish() {    
      startActivity(intent); 
      finish(); 
      } 
     }.start(); 
} 


private GLSurfaceView mGLView; 
class ClearRenderer implements GLSurfaceView.Renderer { 

    Random aleatorio = new Random(); 

    public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
     float r = aleatorio.nextFloat(); 
     float g = aleatorio.nextFloat(); 
     float b = aleatorio.nextFloat(); 
     gl.glClearColor(r, g, b, 1.0f); 

     editor = prefs.edit(); 
     editor.putString("RENDERER", gl.glGetString(GL10.GL_RENDERER)); 
     editor.putString("VENDOR", gl.glGetString(GL10.GL_VENDOR)); 
     editor.putString("VERSION", gl.glGetString(GL10.GL_VERSION)); 
     editor.putString("EXTENSIONS", gl.glGetString(GL10.GL_EXTENSIONS)); 
     editor.commit(); 

    } 

    public void onSurfaceChanged(GL10 gl, int w, int h) { 

    } 

    public void onDrawFrame(GL10 gl) { 
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 

    } 
    } 
} 

之後,你可以隨處檢索存儲的字符串中使用你的應用程序要:

SharedPreferences prefs =getSharedPreferences("GPUinfo",Context.MODE_PRIVATE); 
    String vendor = prefs.getString("VENDOR", null); 
    String renderer = prefs.getString("RENDERER", null); 
    String version = prefs.getString("VERSION", null); 
    String extensions = prefs.getString("EXTENSIONS", null); 

我希望這個答案將是有益的有同樣問題的人。任何其他解決方案也將有所幫助。

3

這是有點棘手,你不需要有GlSurfaceView作爲根,否則你將不會在佈局中預定義TextView

解決方案:

這是我能做到,我已經加入我的預先定義的佈局GlSurfaceView,然後刪除它,當我與信息完成。

xml文件將看起來像這樣與預定義TextView

gpu_info.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/rlRoot" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 


<TextView 
    android:id="@+id/tvVendor" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#FF0000" 
    /> 

和你Activity文件將看起來像這樣:

public class GpuInfoActivity extends Activity{ 

private RelativeLayout rlRoot; 
private TextView tvVendor; 
private String mVendor; 
private GLSurfaceView mGlSurfaceView; 
private GLSurfaceView.Renderer mGlRenderer = new Renderer() { 

    @Override 
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {// TODO Auto-generated method stub 
     Log.d(TAG, "gl renderer: "+gl.glGetString(GL10.GL_RENDERER)); 
     Log.d(TAG, "gl vendor: "+gl.glGetString(GL10.GL_VENDOR)); 
     Log.d(TAG, "gl version: "+gl.glGetString(GL10.GL_VERSION)); 
     Log.d(TAG, "gl extensions: "+gl.glGetString(GL10.GL_EXTENSIONS)); 

     mVendor = gl.glGetString(GL10.GL_VENDOR); 
     runOnUiThread(new Runnable() { 

      @Override 
      public void run() { 
       tvVendor.setText(mVendor); 
       rlRoot.removeView(mGlSurfaceView); 

      } 
     });} 

    @Override 
    public void onSurfaceChanged(GL10 gl, int width, int height) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onDrawFrame(GL10 gl) { 
     // TODO Auto-generated method stub 

    } 
}; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.gpu_info); 


    rlRoot = (RelativeLayout)findViewById(R.id.rlRoot); 
    tvVendor = (TextView)findViewById(R.id.tvVendor); 

    mGlSurfaceView = new GLSurfaceView(this); 
    mGlSurfaceView.setRenderer(mGlRenderer); 

    rlRoot.addView(mGlSurfaceView); 

    } 
} 

我希望它會有幫助!