fix windows

This commit is contained in:
emmaus 2020-09-10 22:23:27 +00:00
parent fafd730d29
commit 79133f4812
6 changed files with 35 additions and 11 deletions

View file

@ -155,6 +155,7 @@ namespace OpenTK
public void ClearCurrent() public void ClearCurrent()
{ {
Gdk.GLContext.ClearCurrent();
GraphicsContext.MakeCurrent(null); GraphicsContext.MakeCurrent(null);
} }
@ -169,7 +170,7 @@ namespace OpenTK
{ {
try try
{ {
GraphicsContext.MakeCurrent(WindowInfo); MakeCurrent();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -259,7 +260,7 @@ namespace OpenTK
if (!_initialized) if (!_initialized)
Initialize(); Initialize();
else if (!IsRenderHandler) else if (!IsRenderHandler)
GraphicsContext.MakeCurrent(WindowInfo); MakeCurrent();
return true; return true;
} }
@ -277,6 +278,8 @@ namespace OpenTK
private void Initialize() private void Initialize()
{ {
Toolkit.Init();
_initialized = true; _initialized = true;
Gdk.GLContext.ClearCurrent(); Gdk.GLContext.ClearCurrent();
@ -302,7 +305,7 @@ namespace OpenTK
buffers--; buffers--;
} }
GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo); GraphicsMode graphicsMode = GraphicsMode.Default;//new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
this.Window.EnsureNative(); this.Window.EnsureNative();
@ -322,7 +325,7 @@ namespace OpenTK
// GraphicsContext // GraphicsContext
GraphicsContext = new GraphicsContext(graphicsMode, WindowInfo, GLVersionMajor, GLVersionMinor, GraphicsContextFlags); GraphicsContext = new GraphicsContext(graphicsMode, WindowInfo, GLVersionMajor, GLVersionMinor, GraphicsContextFlags);
GraphicsContext.MakeCurrent(WindowInfo); MakeCurrent();
if (OpenTK.Graphics.GraphicsContext.ShareContexts) if (OpenTK.Graphics.GraphicsContext.ShareContexts)
{ {
@ -345,6 +348,11 @@ namespace OpenTK
var swap = GraphicsContext.SwapInterval; var swap = GraphicsContext.SwapInterval;
GTKBindingHelper.InitializeGlBindings();
ClearCurrent();
MakeCurrent();
OnInitialized(); OnInitialized();
} }

View file

@ -47,12 +47,23 @@ namespace OpenTK
{ {
if (CurrentPlatform == OSPlatform.Windows) if (CurrentPlatform == OSPlatform.Windows)
{ {
IntPtr library = OpenTK.Platform.Windows.Functions.LoadLibrary(WglLibrary); var ptr = OpenTK.Platform.Windows.Wgl.GetAddress(procName);
return OpenTK.Platform.Windows.Functions.GetProcAddress(library, procName);
/* var addr = GetProcAddressWgl(procName);
if (addr == null || addr == IntPtr.Zero)
{
var library = UnsafeNativeMethods.LoadLibrary(WglLibrary);
addr = UnsafeNativeMethods.GetProcAddress(library, procName);
}
return addr;*/
return ptr;
} }
else if (CurrentPlatform == OSPlatform.Linux) else if (CurrentPlatform == OSPlatform.Linux)
{ {
return OpenTK.Platform.X11.Glx.GetProcAddress(procName); return GetProcAddressGlx(procName);
} }
else if(CurrentPlatform == OSPlatform.OSX) else if(CurrentPlatform == OSPlatform.OSX)
{ {

View file

@ -15,7 +15,7 @@ namespace OpenTK.Platform.Windows
private static IntPtr[] EntryPoints; private static IntPtr[] EntryPoints;
private static string[] EntryPointNames; private static string[] EntryPointNames;
internal const string Library = "OPENGL32.DLL"; internal const string Library = "opengl32.dll";
private readonly static Dictionary<string, bool> extensions = private readonly static Dictionary<string, bool> extensions =
new Dictionary<string, bool>(); new Dictionary<string, bool>();

View file

@ -396,7 +396,9 @@ namespace OpenTK.Platform.Windows
Debug.WriteLine(mode.Index.ToString()); Debug.WriteLine(mode.Index.ToString());
if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd)) var index = Functions.ChoosePixelFormat(window.DeviceContext, ref pfd);
if (!Functions.SetPixelFormat(window.DeviceContext, index, ref pfd))
{ {
throw new GraphicsContextException(String.Format( throw new GraphicsContextException(String.Format(
"Requested GraphicsMode not available. SetPixelFormat error: {0}", "Requested GraphicsMode not available. SetPixelFormat error: {0}",

View file

@ -12,7 +12,7 @@
<ReleaseVersion>1.1</ReleaseVersion> <ReleaseVersion>1.1</ReleaseVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GtkSharp" Version="3.22.25.56" /> <PackageReference Include="GtkSharp" Version="3.22.25.56" />

View file

@ -143,7 +143,8 @@ namespace GLWidgetTestGTK3
Samples = 4, Samples = 4,
GLVersionMajor = 3, GLVersionMajor = 3,
GLVersionMinor = 3, GLVersionMinor = 3,
GraphicsContextFlags = GraphicsContextFlags.Default GraphicsContextFlags = GraphicsContextFlags.ForwardCompatible | GraphicsContextFlags.Debug,
IsRenderHandler = true
}; };
this.MainGLWidget.Events |= this.MainGLWidget.Events |=
@ -351,6 +352,8 @@ namespace GLWidgetTestGTK3
GLInit = true; GLInit = true;
//GLib.Idle.Add(OnIdleProcessMain); //GLib.Idle.Add(OnIdleProcessMain);
MainGLWidget.ClearCurrent();
System.Threading.Thread thread = new System.Threading.Thread(Start); System.Threading.Thread thread = new System.Threading.Thread(Start);
thread.Start(); thread.Start();
} }