Removed unused WGL methods

WGL was autogenerated a few years ago but never touched after that.
Since we use a tiny fraction of all available methods, it makes sense to
remove the unused ones. This reduces dll size and improves startup
times.
This commit is contained in:
Stefanos A. 2013-11-28 23:22:35 +01:00
parent c53c0bc66f
commit 0a39143b3e
6 changed files with 157 additions and 978 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,52 +0,0 @@
namespace OpenTK.Platform.Windows
{
using System;
using System.Runtime.InteropServices;
#pragma warning disable 3019
#pragma warning disable 1591
partial class Wgl
{
internal static partial class Imports
{
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglCreateContext", ExactSpelling = true, SetLastError=true)]
internal extern static IntPtr CreateContext(IntPtr hDc);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglDeleteContext", ExactSpelling = true, SetLastError = true)]
internal extern static Boolean DeleteContext(IntPtr oldContext);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglGetCurrentContext", ExactSpelling = true, SetLastError=true)]
internal extern static IntPtr GetCurrentContext();
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglMakeCurrent", ExactSpelling = true, SetLastError=true)]
internal extern static Boolean MakeCurrent(IntPtr hDc, IntPtr newContext);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglCopyContext", ExactSpelling = true, SetLastError = true)]
internal extern static unsafe int ChoosePixelFormat(IntPtr hDc, PixelFormatDescriptor* pPfd);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglDescribePixelFormat", ExactSpelling = true, SetLastError = true)]
internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, UInt32 cjpfd, PixelFormatDescriptor* ppfd);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglGetCurrentDC", ExactSpelling = true, SetLastError = true)]
internal extern static IntPtr GetCurrentDC();
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglGetProcAddress", ExactSpelling = true, SetLastError = true)]
internal extern static IntPtr GetProcAddress(String lpszProc);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglGetPixelFormat", ExactSpelling = true, SetLastError = true)]
internal extern static int GetPixelFormat(IntPtr hdc);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglSetPixelFormat", ExactSpelling = true, SetLastError = true)]
internal extern static unsafe Boolean SetPixelFormat(IntPtr hdc, int ipfd, PixelFormatDescriptor* ppfd);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglSwapBuffers", ExactSpelling = true, SetLastError = true)]
internal extern static Boolean SwapBuffers(IntPtr hdc);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglShareLists", ExactSpelling = true, SetLastError = true)]
internal extern static Boolean ShareLists(IntPtr hrcSrvShare, IntPtr hrcSrvSource);
}
}
}

View file

@ -1,3 +1,30 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2013 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion
namespace OpenTK.Platform.Windows
{
using System;
@ -10,64 +37,10 @@ namespace OpenTK.Platform.Windows
{
internal static partial class Delegates
{
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr CreateContext(IntPtr hDc);
internal static CreateContext wglCreateContext;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean DeleteContext(IntPtr oldContext);
internal static DeleteContext wglDeleteContext;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr GetCurrentContext();
internal static GetCurrentContext wglGetCurrentContext;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean MakeCurrent(IntPtr hDc, IntPtr newContext);
internal static MakeCurrent wglMakeCurrent;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean CopyContext(IntPtr hglrcSrc, IntPtr hglrcDst, UInt32 mask);
internal static CopyContext wglCopyContext;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate int ChoosePixelFormat(IntPtr hDc, PixelFormatDescriptor* pPfd);
internal unsafe static ChoosePixelFormat wglChoosePixelFormat;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate int DescribePixelFormat(IntPtr hdc, int ipfd, UInt32 cjpfd, PixelFormatDescriptor* ppfd);
internal unsafe static DescribePixelFormat wglDescribePixelFormat;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr GetCurrentDC();
internal static GetCurrentDC wglGetCurrentDC;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr GetDefaultProcAddress(String lpszProc);
internal static GetDefaultProcAddress wglGetDefaultProcAddress;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr GetProcAddress(String lpszProc);
internal static GetProcAddress wglGetProcAddress;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate int GetPixelFormat(IntPtr hdc);
internal static GetPixelFormat wglGetPixelFormat;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate Boolean SetPixelFormat(IntPtr hdc, int ipfd, PixelFormatDescriptor* ppfd);
internal unsafe static SetPixelFormat wglSetPixelFormat;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean SwapBuffers(IntPtr hdc);
internal static SwapBuffers wglSwapBuffers;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean ShareLists(IntPtr hrcSrvShare, IntPtr hrcSrvSource);
internal static ShareLists wglShareLists;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate IntPtr CreateContextAttribsARB(IntPtr hDC, IntPtr hShareContext, int* attribList);
internal unsafe static CreateContextAttribsARB wglCreateContextAttribsARB;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr CreateBufferRegionARB(IntPtr hDC, int iLayerPlane, UInt32 uType);
internal static CreateBufferRegionARB wglCreateBufferRegionARB;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate void DeleteBufferRegionARB(IntPtr hRegion);
internal static DeleteBufferRegionARB wglDeleteBufferRegionARB;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean SaveBufferRegionARB(IntPtr hRegion, int x, int y, int width, int height);
internal static SaveBufferRegionARB wglSaveBufferRegionARB;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean RestoreBufferRegionARB(IntPtr hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
internal static RestoreBufferRegionARB wglRestoreBufferRegionARB;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr GetExtensionsStringARB(IntPtr hdc);
internal static GetExtensionsStringARB wglGetExtensionsStringARB;
[System.Security.SuppressUnmanagedCodeSecurity()]
@ -110,51 +83,9 @@ namespace OpenTK.Platform.Windows
internal unsafe delegate Boolean SetPbufferAttribARB(IntPtr hPbuffer, int* piAttribList);
internal unsafe static SetPbufferAttribARB wglSetPbufferAttribARB;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate bool CreateDisplayColorTableEXT(UInt16 id);
internal static CreateDisplayColorTableEXT wglCreateDisplayColorTableEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate bool LoadDisplayColorTableEXT(UInt16* table, UInt32 length);
internal unsafe static LoadDisplayColorTableEXT wglLoadDisplayColorTableEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate bool BindDisplayColorTableEXT(UInt16 id);
internal static BindDisplayColorTableEXT wglBindDisplayColorTableEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate void DestroyDisplayColorTableEXT(UInt16 id);
internal static DestroyDisplayColorTableEXT wglDestroyDisplayColorTableEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr GetExtensionsStringEXT();
internal static GetExtensionsStringEXT wglGetExtensionsStringEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean MakeContextCurrentEXT(IntPtr hDrawDC, IntPtr hReadDC, IntPtr hglrc);
internal static MakeContextCurrentEXT wglMakeContextCurrentEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr GetCurrentReadDCEXT();
internal static GetCurrentReadDCEXT wglGetCurrentReadDCEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate IntPtr CreatePbufferEXT(IntPtr hDC, int iPixelFormat, int iWidth, int iHeight, int* piAttribList);
internal unsafe static CreatePbufferEXT wglCreatePbufferEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate IntPtr GetPbufferDCEXT(IntPtr hPbuffer);
internal static GetPbufferDCEXT wglGetPbufferDCEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate int ReleasePbufferDCEXT(IntPtr hPbuffer, IntPtr hDC);
internal static ReleasePbufferDCEXT wglReleasePbufferDCEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean DestroyPbufferEXT(IntPtr hPbuffer);
internal static DestroyPbufferEXT wglDestroyPbufferEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate Boolean QueryPbufferEXT(IntPtr hPbuffer, int iAttribute, [Out] int* piValue);
internal unsafe static QueryPbufferEXT wglQueryPbufferEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate Boolean GetPixelFormatAttribivEXT(IntPtr hdc, int iPixelFormat, int iLayerPlane, UInt32 nAttributes, [Out] int* piAttributes, [Out] int* piValues);
internal unsafe static GetPixelFormatAttribivEXT wglGetPixelFormatAttribivEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate Boolean GetPixelFormatAttribfvEXT(IntPtr hdc, int iPixelFormat, int iLayerPlane, UInt32 nAttributes, [Out] int* piAttributes, [Out] Single* pfValues);
internal unsafe static GetPixelFormatAttribfvEXT wglGetPixelFormatAttribfvEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal unsafe delegate Boolean ChoosePixelFormatEXT(IntPtr hdc, int* piAttribIList, Single* pfAttribFList, UInt32 nMaxFormats, [Out] int* piFormats, [Out] UInt32* nNumFormats);
internal unsafe static ChoosePixelFormatEXT wglChoosePixelFormatEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]
internal delegate Boolean SwapIntervalEXT(int interval);
internal static SwapIntervalEXT wglSwapIntervalEXT;
[System.Security.SuppressUnmanagedCodeSecurity()]

View file

@ -22,7 +22,6 @@ namespace OpenTK.Platform.Windows
assembly = Assembly.GetExecutingAssembly();
wglClass = assembly.GetType("OpenTK.Platform.Windows.Wgl");
delegatesClass = wglClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
importsClass = wglClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic);
//// Ensure core entry points are ready prior to accessing any method.
//// Resolves bug [#993]: "Possible bug in GraphicsContext.CreateDummyContext()"
@ -38,7 +37,6 @@ namespace OpenTK.Platform.Windows
private static Assembly assembly;
private static Type wglClass;
private static Type delegatesClass;
private static Type importsClass;
private static bool rebuildExtensionList = true;
@ -59,16 +57,7 @@ namespace OpenTK.Platform.Windows
/// </returns>
static Delegate LoadDelegate(string name, Type signature)
{
Delegate d;
string realName = name.StartsWith("wgl") ? name.Substring(3) : name;
if (importsClass.GetMethod(realName,
BindingFlags.NonPublic | BindingFlags.Static) != null)
d = GetExtensionDelegate(name, signature) ??
Delegate.CreateDelegate(signature, typeof(Imports), realName);
else
d = GetExtensionDelegate(name, signature);
Delegate d = GetExtensionDelegate(name, signature);
return d;
}
@ -87,7 +76,7 @@ namespace OpenTK.Platform.Windows
/// </returns>
private static Delegate GetExtensionDelegate(string name, Type signature)
{
IntPtr address = Imports.GetProcAddress(name);
IntPtr address = GetProcAddress(name);
if (address == IntPtr.Zero ||
address == new IntPtr(1) || // Workaround for buggy nvidia drivers which return

View file

@ -68,7 +68,7 @@ namespace OpenTK.Platform.Windows
SetGraphicsModePFD(selector, GraphicsMode.Default, window);
// Then, construct a temporary context and load all wgl extensions
ContextHandle temp_context = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
ContextHandle temp_context = new ContextHandle(Wgl.CreateContext(window.DeviceContext));
if (temp_context != ContextHandle.Zero)
{
// Make the context current.
@ -79,7 +79,7 @@ namespace OpenTK.Platform.Windows
// Sigh...
for (int retry = 0; retry < 5; retry++)
{
bool success = Wgl.Imports.MakeCurrent(window.DeviceContext, temp_context.Handle);
bool success = Wgl.MakeCurrent(window.DeviceContext, temp_context.Handle);
if (!success)
{
Debug.Print("wglMakeCurrent failed with error: {0}. Retrying", Marshal.GetLastWin32Error());
@ -94,8 +94,8 @@ namespace OpenTK.Platform.Windows
// Load wgl extensions and destroy temporary context
Wgl.LoadAll();
Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
Wgl.Imports.DeleteContext(temp_context.Handle);
Wgl.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
Wgl.DeleteContext(temp_context.Handle);
}
else
{
@ -168,9 +168,9 @@ namespace OpenTK.Platform.Windows
{
// Failed to create GL3-level context, fall back to GL2.
Debug.Write("Falling back to GL2... ");
Handle = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
Handle = new ContextHandle(Wgl.CreateContext(window.DeviceContext));
if (Handle == ContextHandle.Zero)
Handle = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
Handle = new ContextHandle(Wgl.CreateContext(window.DeviceContext));
if (Handle == ContextHandle.Zero)
throw new GraphicsContextException(
String.Format("Context creation failed. Wgl.CreateContext() error: {0}.",
@ -193,7 +193,7 @@ namespace OpenTK.Platform.Windows
{
Marshal.GetLastWin32Error();
Debug.Write(String.Format("Sharing state with context {0}: ", sharedContext));
bool result = Wgl.Imports.ShareLists((sharedContext as IGraphicsContextInternal).Context.Handle, Handle.Handle);
bool result = Wgl.ShareLists((sharedContext as IGraphicsContextInternal).Context.Handle, Handle.Handle);
Debug.WriteLine(result ? "success!" : "failed with win32 error " + Marshal.GetLastWin32Error());
}
}
@ -255,11 +255,11 @@ namespace OpenTK.Platform.Windows
if (wnd.Handle == IntPtr.Zero)
throw new ArgumentException("window", "Must point to a valid window.");
success = Wgl.Imports.MakeCurrent(wnd.DeviceContext, Handle.Handle);
success = Wgl.MakeCurrent(wnd.DeviceContext, Handle.Handle);
}
else
{
success = Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
success = Wgl.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
}
if (!success)
@ -274,7 +274,7 @@ namespace OpenTK.Platform.Windows
public override bool IsCurrent
{
get { return Wgl.Imports.GetCurrentContext() == Handle.Handle; }
get { return Wgl.GetCurrentContext() == Handle.Handle; }
}
#endregion
@ -338,7 +338,17 @@ namespace OpenTK.Platform.Windows
public override IntPtr GetAddress(string function_string)
{
IntPtr address = Wgl.Imports.GetProcAddress(function_string);
IntPtr address = Wgl.GetProcAddress(function_string);
if (!IsValid(address))
{
address = Functions.GetProcAddress(opengl32Handle, function_string);
}
return address;
}
public override IntPtr GetAddress(IntPtr function_string)
{
IntPtr address = Wgl.GetProcAddress(function_string);
if (!IsValid(address))
{
address = Functions.GetProcAddress(opengl32Handle, function_string);
@ -403,7 +413,7 @@ namespace OpenTK.Platform.Windows
{
get
{
return Wgl.Imports.GetCurrentDC();
return Wgl.GetCurrentDC();
}
}
@ -462,7 +472,7 @@ namespace OpenTK.Platform.Windows
try
{
// This will fail if the user calls Dispose() on thread X when the context is current on thread Y.
if (!Wgl.Imports.DeleteContext(Handle.Handle))
if (!Wgl.DeleteContext(Handle.Handle))
Debug.Print("Failed to destroy OpenGL context {0}. Error: {1}",
Handle.ToString(), Marshal.GetLastWin32Error());
}

View file

@ -109,15 +109,9 @@ namespace OpenTK.Platform.Windows
static int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor pfd)
{
unsafe
{
fixed (PixelFormatDescriptor* ppfd = &pfd)
{
// Note: DescribePixelFormat found in gdi32 is extremely slow
// on nvidia, for some reason.
return Wgl.Imports.DescribePixelFormat(hdc, ipfd, (uint)cjpfd, ppfd);
}
}
// Note: DescribePixelFormat found in gdi32 is extremely slow
// on nvidia, for some reason.
return Wgl.DescribePixelFormat(hdc, ipfd, (uint)cjpfd, out pfd);
}
#endregion