Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opengl es 为什么可以';我是否使用SDL2创建OpenGLES3.0上下文?_Opengl Es_Sdl 2 - Fatal编程技术网

Opengl es 为什么可以';我是否使用SDL2创建OpenGLES3.0上下文?

Opengl es 为什么可以';我是否使用SDL2创建OpenGLES3.0上下文?,opengl-es,sdl-2,Opengl Es,Sdl 2,我在Debian stable上使用SDL2 2.0.2,并试图用它获取OpenGL ES 3.0上下文。如果我请求一个OpenGL ES 2.0上下文,这是可行的,但如果我直接请求一个OpenGL ES 3.0上下文,则不可行 考虑以下计划: #include <GLES3/gl3.h> #include <SDL2/SDL.h> int main( int argc, char **argv ) { SDL_GLContext context

我在Debian stable上使用SDL2 2.0.2,并试图用它获取OpenGL ES 3.0上下文。如果我请求一个OpenGL ES 2.0上下文,这是可行的,但如果我直接请求一个OpenGL ES 3.0上下文,则不可行

考虑以下计划:

#include <GLES3/gl3.h>
#include <SDL2/SDL.h>

int main(
    int argc,
    char **argv
) {
    SDL_GLContext context;
    int rc;
    const GLubyte *version;
    SDL_Window *window;

    rc = SDL_Init(SDL_INIT_VIDEO);

    if (rc < 0) {
        return EXIT_FAILURE;
    }

    atexit(SDL_Quit);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#ifdef THIS_SHOULD_WORK_TOO
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#else
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif

    window = SDL_CreateWindow("OpenGL", 100, 100, 800, 600, SDL_WINDOW_OPENGL);
    context = SDL_GL_CreateContext(window);
    version = glGetString(GL_VERSION);

    if (version == 0) {
        printf(
            "Unable to get OpenGL ES version string: %d\n",
            glGetError()
        );
        return EXIT_FAILURE;
    }

    printf("Version string: %s\n", version);

    SDL_GL_DeleteContext(context);

    return EXIT_SUCCESS;
}
但是,当我请求OpenGL ES 3.0上下文时,该程序将失败,并且没有明确的错误消息:

$ c99 -DTHIS_SHOULD_WORK_TOO example.c -lSDL2 -lGLESv2
$ ./a.out
Unable to get OpenGL ES version string: 0
为什么会这样

我怀疑这是因为
-lGLESv2
,主要是因为OpenGL ES上下文报告它是3.0版,并且因为确实提供
libGLESv3的平台。因此
将其作为符号链接发送到
libGLESv2。因此
(,例如)。

这是:

SDL的EGL代码(用于在Windows/Linux/Android等平台上创建OpenGL ES上下文)似乎只正确支持OpenGL ES 1和2上下文

特别是,如果请求GLES2,当前代码将EGL_RENDERABLE_TYPE config属性设置为EGL_OPENGL_ES2_位,而在所有其他情况下,将EGL_OPENGL_ES_位设置为EGL_OPENGL_ES2_位。它从不使用EGL_OPENGL_ES3_BIT/EGL_OPENGL_ES3_BIT_KHR,即使请求了GLES3.0+。当请求3.1时,它也不使用EGL_CONTEXT_MINOR_VERSION_KHR在SDL_EGL_CreateContext中将版本设置为3.1而不是3.0

这意味着对OpenGL ES 3.0的请求将转换为对OpenGL ES 1.0的请求。由于OpenGL ES 3.0与OpenGL ES 1.0向后不兼容,因此请求最终失败(我认为)

已合并到主分支,并计划发布:

  • 添加了EGL_KHR_create_上下文支持,以允许在某些平台上选择OpenGL ES版本
$ c99 -DTHIS_SHOULD_WORK_TOO example.c -lSDL2 -lGLESv2
$ ./a.out
Unable to get OpenGL ES version string: 0