Android Open GL ES 2.0 - 对顶点阵列对象(VAO)有什么要求?

时间:2016-11-16 17:25:58

标签: android c++ opengl-es android-ndk opengl-es-2.0

能够使用Vertex阵列对象有哪些要求? 我知道有些GPU支持它,有些则不支持。我想知道在编译时是否还有一些额外的要求。

是否需要使用最低限度的Android SDK版本?

Gradle(Android Studio)中的compileSdkVersion,minSdkVersion和targetSdkVersion的最小值是多少?

需要在设备上安装的最低Android版本是什么?

或者它可能根本不重要,GPU是否支持它?

1 个答案:

答案 0 :(得分:-1)

据我所知,API 9引入了openGL ES 2.0。在onCreate方法启动时,只需添加:

// Check if the system supports OpenGL ES 2.0.

final ActivityManager activityManager =
        (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo =
        activityManager.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

if (!supportsEs2)
{
    Log.i("WLGFX","Device does not support OpenGL ES 2.0");
    System.exit(-1);
    return;
}

自从我上次看过VAO以来,这已经很久了,我实际上认为他们完全摆脱了它们。为了提高性能,请使用VBO。它们同样易于创建和使用。以下是一些示例摘录:

void FFDisplay::init_texture_buffers() {    // for overlay screen
    GLfloat vertices[] = {
            -1.0f,  -1.0f,      0.0f,   1.0f,   // X, Y, U, V
            -1.0f,   1.0f,      0.0f,   0.0f,
            1.0f,    1.0f,      1.0f,   0.0f,
            1.0f,   -1.0f,      1.0f,   1.0f
    };

    GLushort indices[] = { 2, 1, 0, 2, 0, 3 };

    glGenBuffers(2, texture_buffers);
    glBindBuffer(GL_ARRAY_BUFFER, texture_buffers[0]);
    glBufferData(GL_ARRAY_BUFFER, 64, vertices, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, texture_buffers[1]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 12, indices, GL_DYNAMIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    texture_texture = 0;
}

void FFDisplay::init_overlay_texture() {
    glGenTextures(1, &overlay_texture);
    glBindTexture(GL_TEXTURE_2D, overlay_texture);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_HINT, GL_FALSE );
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, FFD_OVERLAY_WID, FFD_OVERLAY_HGT,
                 0, GL_RGBA, GL_UNSIGNED_BYTE, overlay_image);
}

void FFDisplay::draw_overlay() {
    glUseProgram(prog_texture);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, overlay_texture);

    glUniform1i(texture_texture, 0);

    glEnableVertexAttribArray(texture_vertex);
    glEnableVertexAttribArray(texture_uv);

    glBindBuffer(GL_ARRAY_BUFFER, texture_buffers[0]);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, texture_buffers[1]);

    glVertexAttribPointer(texture_vertex, 2, GL_FLOAT, GL_FALSE, 16, NULL);
    glVertexAttribPointer(texture_uv, 2, GL_FLOAT, GL_FALSE, 16, (void*)8);

    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);

    glDisableVertexAttribArray(texture_uv);
    glDisableVertexAttribArray(texture_vertex);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

有很多关于GLES 2.0的信息可以帮助您入门。