【发布时间】:2017-01-25 17:04:33
【问题描述】:
问题描述
两年多来,我一直在使用 OpenTK 在各种 Windows 配置(7、8、8.1、10)和硬件(各种 AMD、nvidia GPU 和英特尔的图形芯片组)上创建 OpenGL 上下文,没有出现任何问题。
但是由于 nvidia 的 375.63 驱动程序更新和所有后续驱动程序更新(甚至是昨天发布的最新 378.49),当我尝试使用 OpenTK 创建 OpenGL 上下文时,我最终得到一个 OpenGL 1.1.0 上下文(供应商:Microsoft Corporation,渲染器:GDI 通用)。这看起来像是一个“后备”的 OpenGL 上下文,当然它缺少我需要的大多数 OpenGL 函数。
回滚到 373.06 或更早版本可以解决问题,但不是长期可行的解决方案。
观察
- 我已仔细阅读nvidia's released notes,但没有发现与该问题相关的任何问题或备注。
- 我怀疑由OpenTK创建的句柄初始化的像素格式突然变得不被nvidia的驱动程序支持。 (如果需要,我可以提供详细信息)
- 我已经使用 glfw 尝试了一些示例 C++ 代码,并且我可以获得正确的 OpenGL 上下文(版本:4.5.0,供应商:nvidia),因此它似乎不是低级驱动程序问题,而是创建的上下文以某种方式被破坏了。
我已开始深入研究 OpenTK 代码以缩小问题范围。 上下文是使用包装器创建的
Delegates.wglCreateContextAttribsARB((IntPtr)hDC, (IntPtr)hShareContext, (int*)attribList_ptr);
这个委托是使用 GetProcAddress 函数加载的:
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglGetProcAddress", ExactSpelling = true, SetLastError = true)]
internal extern static IntPtr GetProcAddress(String lpszProc);
其中 Wgl.Library 是“OPENGL32.dll”。函数加载正确。
传递的属性只是 GL_MAJOR = 1 GL_MINOR = 0 应该(并且总是)返回最新支持的 OpenGL 上下文。我还尝试将这些值分别强制为 4 和 5,但均未成功。
specs of wglCreateContextAttribsARB 没有提及任何“回退”上下文。 (注:我的显卡支持wglCreateContextAttribsARB)
问题
- 是否有人在创建 OpenGL 上下文时遇到过类似问题,您是如何解决的?
- 在 2 个驱动程序版本之间可能发生了什么变化会破坏这一点?
欢迎任何帮助或线索。如果需要,我可以详细说明一些具体点。
更新 (26.1.2017)
似乎获取像素模式的方式是问题的根源。初始化步骤尝试检索使用wglChoosePixelFormatARB 函数的 ARB 模式,并使用新驱动程序获取 0 个有效模式。
这里是代码块的相关部分。 (Wgl.Arb.ChoosePixelFormat 是 wglChoosePixelFormatARB 的包装)
...
int[] attribs = new int[]
{
(int)WGL_ARB_pixel_format.AccelerationArb,
(int)WGL_ARB_pixel_format.RedBitsArb,
(int)WGL_ARB_pixel_format.GreenBitsArb,
(int)WGL_ARB_pixel_format.BlueBitsArb,
(int)WGL_ARB_pixel_format.AlphaBitsArb,
(int)WGL_ARB_pixel_format.ColorBitsArb,
(int)WGL_ARB_pixel_format.DepthBitsArb,
(int)WGL_ARB_pixel_format.StencilBitsArb,
(int)WGL_ARB_multisample.SampleBuffersArb,
(int)WGL_ARB_multisample.SamplesArb,
(int)WGL_ARB_pixel_format.AccumRedBitsArb,
(int)WGL_ARB_pixel_format.AccumGreenBitsArb,
(int)WGL_ARB_pixel_format.AccumBlueBitsArb,
(int)WGL_ARB_pixel_format.AccumAlphaBitsArb,
(int)WGL_ARB_pixel_format.AccumBitsArb,
(int)WGL_ARB_pixel_format.DoubleBufferArb,
(int)WGL_ARB_pixel_format.StereoArb,
0
};
int[] values = new int[attribs.Length];
int[] attribs_values = new int[]
{
(int)WGL_ARB_pixel_format.AccelerationArb,
(int)WGL_ARB_pixel_format.FullAccelerationArb,
(int)WGL_ARB_pixel_format.SupportOpenglArb, 1,
(int)WGL_ARB_pixel_format.DrawToWindowArb, 1,
0, 0
};
int[] num_formats = new int[1];
// Get the number of available formats
if (Wgl.Arb.ChoosePixelFormat(window.DeviceContext, attribs_values, null, 0, null, num_formats))
{
// Create an array big enough to hold all available formats and get those formats
int[] pixel = new int[num_formats[0]];
//result differ here from one driver to the other :
//373.06 => num_formats[0] is 66
//378.49 => num_formats[0] is 0
if (Wgl.Arb.ChoosePixelFormat(window.DeviceContext, attribs_values, null, pixel.Length, pixel, num_formats))
{
//for loop to fetch all the modes
}
}
...
如您所见num_formats[0],为新驱动程序版本返回 0 个有效格式。从这里我猜最有可能的可能性是给定的标志不再正确,或者wglChoosePixelFormatARB 函数中存在一些错误。
【问题讨论】:
-
如果他们在您要求 1.0 时返回了最新版本,那么该错误是以前的,现在已得到纠正,您必须请求正确的主要/次要版本,即您的应用程序所针对的版本。
-
如前所述,我尝试将主要和次要分别设置为 4 和 5 以获得 OpenGL 4.5 上下文,但没有结果。
-
如果您在创建或请求上下文的位置添加代码,可能会更容易查看是否存在问题。另外,您正在使用 OpenTK.Graphics.OpenGL4 的功能,是吗?