简体   繁体   English

无法在OSX 10.11(MBP,GeForce 750M)上使用SDL2创建有效的OpenGL 3.3上下文

[英]Cannot create working OpenGL 3.3 context with SDL2 on OSX 10.11 (MBP, GeForce 750M)

I have the following (working) setup code for OpenGL using SDL2: 我具有以下使用SDL2的OpenGL(工作)安装代码:

int main(int argc, char* argv[])
{
  SDL_SetMainReady();
  if (SDL_Init(SDL_INIT_VIDEO) != 0) return 1);

  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
  SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
  SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
  SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);

  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

   auto sdl_window = SDL_CreateWindow("GL Experiment",
     SDL_WINDOWPOS_CENTERED, // x position.
     SDL_WINDOWPOS_CENTERED, // y position.
     640, // Width.
     640, // Height.
     SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
   if (sdl_window == nullptr) return 2;
   auto sdl_gl_context = SDL_GL_CreateContext(sdl_window);
   if (sdl_gl_context == nullptr) return 3;

   ...

However, if I change the SDL_GL_CONTEXT_VERSION... lines to: 但是,如果我将SDL_GL_CONTEXT_VERSION...行更改为:

// Use a core profile setup.
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

Then it breaks in an odd way: 然后它以一种奇怪的方式破裂:

  • The program does not crash / exit with an error. 该程序不会崩溃/错误退出。
  • glClear appears to still work (the window has whatever background colour is chosen). glClear似乎仍然可以工作(窗口具有选择的任何背景色)。
  • No rendering appears (I am using the OpenGL SuperBible 'GLTools' code to do the rendering, which should only be using Core Profile calls, and works with the 2.1 context) 没有渲染出现(我正在使用OpenGL SuperBible'GLTools'代码进行渲染,该代码只能使用Core Profile调用,并且可以在2.1上下文中使用)
  • There are some oddities in the attributes the context reports: 上下文报告的属性中有些奇怪:

     SDL_GL_RED_SIZE: 0 SDL_GL_GREEN_SIZE: 0 SDL_GL_BLUE_SIZE: 0 SDL_GL_ALPHA_SIZE: 0 SDL_GL_BUFFER_SIZE: 4 SDL_GL_DOUBLEBUFFER: 1 SDL_GL_DEPTH_SIZE: 0 SDL_GL_STENCIL_SIZE: 0 SDL_GL_ACCUM_RED_SIZE: 0 SDL_GL_ACCUM_GREEN_SIZE: 0 SDL_GL_ACCUM_BLUE_SIZE: 0 SDL_GL_ACCUM_ALPHA_SIZE: 0 SDL_GL_STEREO: 0 SDL_GL_MULTISAMPLEBUFFERS: 0 SDL_GL_MULTISAMPLESAMPLES: 0 SDL_GL_ACCELERATED_VISUAL: 1 SDL_GL_CONTEXT_MAJOR_VERSION: 3 SDL_GL_CONTEXT_MINOR_VERSION: 3 SDL_GL_CONTEXT_FLAGS: 2 SDL_GL_CONTEXT_PROFILE_MASK: 1 SDL_GL_SHARE_WITH_CURRENT_CONTEXT: 0 SDL_GL_FRAMEBUFFER_SRGB_CAPABLE: 0 

So the context claims to have 0 bit colour bit depth etc. This seems inconsistent with the rendering of the initial glClear call though, which happily renders in colour. 因此,上下文声称具有0位颜色的位深度等。但这似乎与初始glClear调用的呈现不一致,后者很glClear以彩色呈现。

I've checked a few OpenGL functions and they appear to resolve to real function addresses (just using OSX's <opengl/gl3.h> to get these, but I've checked and they're the same addresses that loading the function pointers through SDL yields. 我已经检查了一些OpenGL函数,它们似乎可以解析为真实的函数地址(仅使用OSX的<opengl/gl3.h>即可获取这些地址,但我已经检查过了,它们与通过加载函数指针相同的地址SDL产量。

Update 更新资料

The output from glGetString is: glGetString的输出为:

    GL_VENDOR: NVIDIA Corporation
    GL_RENDERER: NVIDIA GeForce GT 750M OpenGL Engine
    GL_VERSION: 4.1 NVIDIA-10.6.47 310.42.05f01
    GL_SHADING_LANGUAGE_VERSION: 4.10

This is when 3.3/Core is requested, so clearly it gives a 4.1 context. 这是在请求3.3 / Core时,因此很明显它提供了4.1上下文。 When 2.1 is requested it's the same but correctly shows GL_VERSION: 2.1 ... . 请求2.1时相同,但正确显示GL_VERSION: 2.1 ...

It turns out the OpenGL context has been created successfully, ie the above code works just fine in terms of creating the context. 事实证明,OpenGL上下文已成功创建,即,上面的代码在创建上下文方面效果很好。

The issue therefore appears to be twofold: 因此,问题似乎是双重的:

  1. The OpenGL SuperBible (5th edition) drawing code must contain a bug in the form of Compatibility Profile code that prevents the actual rendering from working. OpenGL SuperBible(第5版)绘图代码必须包含兼容配置文件代码形式的错误,该错误会阻止实际的渲染工作。
  2. Either SDL 2.0.4, or the underlying OSX methods it uses, appear to contain a bug when reporting on the bit depth etc of the context created. 在报告所创建上下文的位深度等时,SDL 2.0.4或其所使用的基础OSX方法似乎都包含错误。

Update 更新资料

Having spent some time getting the OpenGl SuperBible examples in earlier chapters working with a 3.3 Core context, I discover in a later chapter that they deliberately target a Compatibility profile so the book will work on earlier systems. 花了一些时间在较早的章节中使用3.3核心上下文获取OpenGl SuperBible示例之后,我在随后的章节中发现,它们故意针对Compatibility概要文件,因此该书可在较早的系统上运行。 This explains point 1 above, and it is a shame they do not provide this information up front when describing how to get started! 这解释了上面的第1点,很可惜他们在描述如何入门时没有预先提供此信息!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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