Question

I searched the entire Internet for days now to find a solution and got nothing.

I want to get the main info about the GPU on Android devices (like RENDERER, VENDOR and VERSION) and be able to print it on a textview on a defined XML layout. I tryed a lot of methods and nothing worked for me. Everybody says to use this:

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));

I implemented the next class:

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);         
    }
}
}

which works great but I have no idea how to put those logs into a textview. Setting up the ContentView to my GLSurfaceView I don't know how to use a TextView in there.

I aslo tryed using:

String renderer = gl.glGetString(GL10.GL_VENDOR);
Log.d("GL", renderer);

in the same place where previous Logs are, which also workg great and I can see the right value of the vendor in the LogCat.

But still, I don't know how to pass this value to a textview (for example tv.setText(renderer)) and use it on a normal layout.

I will appreciate a lot if someone could help me solve this problem with a simple example. Take in considerations that I never used OpenGL and I only want to get that info about it. I also accept if you tell me another way (easier if possible :D) to get that info.

Thanks in advance.

Was it helpful?

Solution 2

Finally after struggling with this problem, I found a possible solution. Maybe it is not the best but I had no other and it workd.

I used shared preferences to store the info. I created a launcher activity with the implemented GLSurfaceView with a delay of 3 seconds (more than enough to store all the strings) and after this delay the activity I need starts.

The launcher activity looks like this:

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);

    }
  }
}

After that, you can retrieve the stored strings everywhere you want in your application using:

    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);

I hope this answer will be useful for the people with the same problem. Any other solution will be also helpful.

OTHER TIPS

It is bit tricky, you don't need to have GlSurfaceView as root , otherwise you will not have pre-defined TextView in layout.

Solution:

This is how I manage to do, I have added GlSurfaceView in my pre-defined layout and then removed it when I'm done with the information.

your xml file will be looking something like this with pre-defined 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"
    />

and your Activity file will be looking like this:

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);

    }
}

I hope it will be helpful !!

I'll do it on this way:

package com.paget96.lspeed.activities;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

import java.util.Random;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class GetGpuInfo extends Activity {

    // Variables
    private static SharedPreferences sharedPreferences;
    private static SharedPreferences.Editor editor;
    private GLSurfaceView mGLView;

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

        final Intent intent = new Intent(this, MainActivity.class);
    }


    class ClearRenderer implements GLSurfaceView.Renderer {

        Random random = new Random();

        @Override
        public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
            float r = random.nextFloat();
            float g = random.nextFloat();
            float b = random.nextFloat();
            gl10.glClearColor(r, g, b, 1.0f);

            editor = sharedPreferences.edit();
            editor.putString("gpu_vendor", gl10.glGetString(GL10.GL_VENDOR));
            editor.putString("gpu_renderer", gl10.glGetString(GL10.GL_RENDERER));
            editor.putString("gpu_version", gl10.glGetString(GL10.GL_VERSION));
            //editor.putString("gpu_extensions", gl10.glGetString(GL10.GL_EXTENSIONS));
            editor.apply();

            finish();
        }

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

        }

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

        }
    }
}

And then call the same activity to any other over the Intent (This one will be destroyed as soon as pass the all things in onSurfaceCreated(...)

final Intent intent = new Intent(this, GetGpuInfo.class);
startActivity(intent);

Now activity GetGpuInfo activity has collected GPU data to sharedPreferences, so you can access them to any fragment or so on. Like this:

vendor = sharedPreferences.getString("gpu_vendor", getActivity().getString(R.string.unknown));
        renderer = sharedPreferences.getString("gpu_renderer", getActivity().getString(R.string.unknown));
        version = sharedPreferences.getString("gpu_version", getActivity().getString(R.string.unknown));
        extensions = sharedPreferences.getString("gpu_extensions", getActivity().getString(R.string.unknown));

        gpuInfo.setText(String.format("%s\n%s\n%s",
                getString(R.string.vendor, vendor),
                getString(R.string.renderer, renderer),
                getString(R.string.version, version)
                /*,getString(R.string.extensions, extensions)*/));

Initialize getters of sharedPreferences as String, then you can put them to TextView like i have done here. I'm using String.format because it's easier to use a new row without a warning of String concentration.

That's all, cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top