首页 文章

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

提问于
浏览
2

问题描述

我已经使用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,renderer: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没有提到任何"fall back"上下文 . (注意:我的显卡支持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 回答

  • 2

    看起来它无法找到NVIDIA OpenGL环境,并且正在回归到Windows附带的古老版本,并且在十多年内还没有更新 .

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

    看起来你不能用OpenTK为此打开拉取请求 . OpenTK可能以与GLFW不同的方式扫描和调用 wglCreateContextAttribsARB .

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

  • 1

    事实证明,我正在处理的代码库的OpenTK代码不是最新的 . 我上面发布的代码块已经过时了 . 它实际上看起来像是来自mono/opentk repo(确切的代码块是here) . 我已经研究了ARB扩展加载version 2.0-0(标签)的功能,它们改变了很多(code here) .

    底线

    我测试了version 2.0-0并解决了这个问题 .

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

相关问题