odraencoded's picture

Functions.DescribePixelFormat takes about 20 seconds to execute

Project:The Open Toolkit library
Category:support request
Status:need info

Hello, I'm sort of new to openGL, .Net and openTK so if this issue is my fault, I'm sorry.
When I run my app with visual studio hosting process disabled, it takes about 20 seconds for the window to actually appear. Enabling it, and, of course, running the app with msvs debugger, solves the issue and the window appears in about 1 second.
After some line-by-line step-in debugging I found that the method that takes most of the time is Functions.DescribePixelFormat in the API.cs file.


OpenTK.dll!OpenTK.Platform.Windows.WinGLContext.SetGraphicsModePFD({OpenTK.Graphics.GraphicsMode}, {OpenTK.Platform.Windows.WinWindowInfo})	C#
OpenTK.dll!OpenTK.Platform.Windows.WinGLContext.WinGLContext({OpenTK.Graphics.GraphicsMode}, {OpenTK.Platform.Windows.WinWindowInfo}, null, 1, 0, Default)	C#
OpenTK.dll!OpenTK.Platform.Windows.WinFactory.CreateGLContext({OpenTK.Graphics.GraphicsMode}, {OpenTK.Platform.Windows.WinWindowInfo}, null, true, 1, 0, Default)	C#
OpenTK.dll!OpenTK.Graphics.GraphicsContext.GraphicsContext({OpenTK.Graphics.GraphicsMode}, {OpenTK.Platform.Windows.WinWindowInfo}, 1, 0, Default)	C#
OpenTK.dll!OpenTK.Platform.Windows.WinGraphicsMode.GetModesARB({OpenTK.NativeWindow})	C#
[External Code]	
OpenTK.dll!OpenTK.Platform.Windows.WinGraphicsMode.WinGraphicsMode()	C#
OpenTK.dll!OpenTK.Platform.Windows.WinFactory.CreateGraphicsMode()	C#
OpenTK.dll!OpenTK.Graphics.GraphicsMode.GraphicsMode()	C#
[External Code]	
Game.exe!Game.MainWindow.MainWindow()	C#
Game.exe!Game.Program.Main()	C#

Specific point:

void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
	Debug.Write("Setting pixel format... ");
	if (!mode.Index.HasValue)
		throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
	if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
	PixelFormatDescriptor pfd = new PixelFormatDescriptor();
>>>>Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index.Value,
		API.PixelFormatDescriptorSize, ref pfd);
	if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd))
		throw new GraphicsContextException(String.Format(
			"Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error()));

I'm running Windows 7 32bit with a nVidia GT9400 graphics card btw.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


Status:open» need info

Are you running 1.0-stable or the 1.1 nightlies?

I've seen this issue before. Winapi offers two different versions of SetPixelFormat, one in gdi32.dll and one in opengl32.dll. Nvidia used to have a problem where using one was very slow (but other IHVs didn't show a difference).

It may be that DescribePixelFormat and wglDescribePixelFormat display a similar issue. Can you please try the following? Locate the definition for Functions.DescribePixelFormat and change the DllImport from "gdi32.dll"/"DescribePixelFormat" to "opengl32.dll"/"wglDescribePixelFormat". Does this fix the issue?