使用OpenTK创建图形上下文会返回1.1 OpenGL上下文,因为nvidia的375.63驱动程序更新

时间:2017-01-25 17:04:33

标签: c# opengl nvidia opentk

问题描述

我已经使用OpenTK在各种Windows配置(7,8,8.1,10)和硬件(各种AMD,nvidia GPU和intel的图形芯片组)上创建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上下文时是否有人遇到类似问题,您是如何解决的?
  • 两个驱动程序版本之间可能会发生什么变化?

欢迎任何帮助或线索。如果需要,我可以详细说明一些具体要点。

更新(26.1.2017)

似乎获得像素模式的方法是问题的根源。启动步骤尝试检索使用wglChoosePixelFormatARB函数的ARB模式,并使用新驱动程序获得0个有效模式。

这是代码块的相关部分。 (Wgl.Arb.ChoosePixelFormatwglChoosePixelFormatARB

的包装
 ...
 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函数中存在一些错误。

2 个答案:

答案 0 :(得分:2)

看起来它无法找到NVIDIA OpenGL背景,并且正在回归Windows附带的古老版本,并且已经过十多年的更新。

我唯一能找到的是this old issue on the OpenTK repo。它应该在任何最新版本的OpenTK中修复,但问题可能会再次出现。

看起来您已经做了很多工作来隔离问题并使其可重现。用OpenTK打开拉取请求并不是不可能的。 OpenTK可能以与GLFW不同的方式扫描和调用wglCreateContextAttribsARB

如果您可以查看并比较GLFW和OpenTK上下文初始化,那么问题可能会出现在那里。

答案 1 :(得分:1)

事实证明,我正在处理的代码库的OpenTK代码不是最新的。我上面发布的代码块已经过时了。实际上看起来代码来自mono/opentk repo(确切的代码块是here)。我查看了加载version 2.0-0(标记)函数的ARB扩展,它们发生了很大变化(code here)。

底线

我使用version 2.0-0 进行了测试,解决了这个问题。

感谢Robert Rouhani指出这是一个老问题。