简体   繁体   中英

Called unimplemented OpenGL ES API Android

In my manifest i have this:

<uses-feature android:glEsVersion="0x00010001" android:required="true" />
<uses-sdk android:minSdkVersion="7"/>   

<uses-feature
    android:name="android.hardware.vibrate"
    android:required="false" />
<uses-feature
    android:name="android.hardware.wifi"
    android:required="false" />

<application
    android:hardwareAccelerated="true"
    android:debuggable="false"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" >
    <activity
        android:name=".Activity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar"
        android:windowSoftInputMode="stateHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

and this is my GLview Activity:

abstract class GLView extends SurfaceView implements SurfaceHolder.Callback {
private boolean hasSurface;
private boolean paused;
private EGL10 egl;
private EGLDisplay display;
private EGLConfig config;    
private EGLSurface surface;
private EGLContext eglContext;
private GL11 gl;
protected int width, height;
private boolean mIsLooping;

abstract void onDrawFrame(GL10 gl);
abstract void onSurfaceCreated(GL10 gl, int width, int height);

public String captureScreenshot() {
    Bitmap bitmap = getRawPixels(gl, width, height);
    Util.bitmapBGRtoRGB(bitmap, width, height);
    return Util.saveBitmap(bitmap, Grapher.SCREENSHOT_DIR, "calculator");
}

private static Bitmap getRawPixels(GL10 gl, int width, int height) {
    int size = width * height;
    ByteBuffer buf = ByteBuffer.allocateDirect(size * 4);
    buf.order(ByteOrder.nativeOrder());
    gl.glReadPixels(0, 0, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, buf);
    int data[] = new int[size];
    buf.asIntBuffer().get(data);
    buf = null;
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    bitmap.setPixels(data, size-width, -width, 0, 0, width, height);
    return bitmap;
}

private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            glDraw();

        }
    };

public GLView(Context context) {
    super(context);
    init();
}

public GLView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

private void init() {
    SurfaceHolder holder = getHolder();
    holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
    holder.addCallback(this);
}

public void onResume() {
    Calculator.log("onResume " + this);
    paused = false;
    if (hasSurface) {
        initGL();
    }
}

public void onPause() {
    Calculator.log("onPause " + this);
    deinitGL();
}

private void initGL() {
    egl = (EGL10) EGLContext.getEGL();
    display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);       
    int[] ver = new int[2];
    egl.eglInitialize(display, ver);

    int[] configSpec = {EGL10.EGL_NONE};
    EGLConfig[] configOut = new EGLConfig[1];
    int[] nConfig = new int[1];
    egl.eglChooseConfig(display, configSpec, configOut, 1, nConfig);

    config = configOut[0];

    eglContext = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null);
    surface = egl.eglCreateWindowSurface(display, config, getHolder(), null);
    egl.eglMakeCurrent(display, surface, surface, eglContext);
    gl = (GL11) eglContext.getGL();
    onSurfaceCreated(gl, width, height);
    requestDraw();
}


private void deinitGL() {
    paused = true;
    if (display != null) {
        egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        egl.eglDestroySurface(display, surface);
        egl.eglDestroyContext(display, eglContext);
        egl.eglTerminate(display);

        egl = null;
        config = null;
        eglContext = null;
        surface = null;
        display = null;
        gl = null;
    }
}

protected void glDraw() {
    if (hasSurface && !paused) {
        onDrawFrame(gl);
        if (!egl.eglSwapBuffers(display, surface)) {
            Calculator.log("swapBuffers error " + egl.eglGetError());
        }
        if (egl.eglGetError() == EGL11.EGL_CONTEXT_LOST) {
            Calculator.log("egl context lost " + this);
            paused = true;
        }
        if (mIsLooping) {
            requestDraw();
        }
    }
}

public void surfaceCreated(SurfaceHolder holder) {
    Calculator.log("surfaceCreated " + this);
}

public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    Calculator.log("surfaceChanged " + format + ' ' + this);
    this.width  = width;
    this.height = height;
    boolean doInit = !hasSurface && !paused;
    hasSurface = true;
    if (doInit) {
        initGL();
    }
}

public void surfaceDestroyed(SurfaceHolder holder) {
    Calculator.log("surfaceDestroyed " + this);
    hasSurface = false;
    deinitGL();
}

public void startLooping() {
    if (!mIsLooping) {
        Calculator.log("start looping");
        mIsLooping = true;
        glDraw();
    }
}

public void stopLooping() {
    if (mIsLooping) {
        Calculator.log("stop looping");
        mIsLooping = false;
    }
}

public boolean isLooping() {
    return mIsLooping;
}

public void requestDraw() {
    handler.sendEmptyMessage(1);
}
}

I'm having all these problems from when in manifest I've included this instruction:

Android: hardwareAccelerated = "true"

I do not know if the code I have added is sufficient to identify the problem, for now the code gives me this error:

Called unimplemented OpenGL ES API

I want to disabled android:hardwareAccelerated="true" when the activity call the OpenGL class

You have not enabled OpenGL ES in your manifest. You need to add this:

<uses-feature android:glEsVersion="0x00010001" android:required="true" />
<uses-sdk android:minSdkVersion="7"/>

See "Manifest Declarations for OpenGL ES" in this article:

http://software.intel.com/en-us/articles/porting-opengl-games-to-android-on-intel-atom-processors-part-2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM