From 440e3fe24821615405a21a619ff338cac6c2c2f4 Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Fri, 8 Nov 2013 10:39:08 +0100 Subject: [PATCH 1/6] Load ES30 and OpenGL4 entry points --- OpenTK.sln | 115 +++++++++++------- .../Examples/OpenTK/Test/GameWindowStates.cs | 2 +- Source/OpenTK/Graphics/GraphicsContext.cs | 2 +- Source/OpenTK/Graphics/GraphicsMode.cs | 53 +------- .../OpenTK/Platform/DesktopGraphicsContext.cs | 2 + .../Platform/EmbeddedGraphicsContext.cs | 1 + 6 files changed, 82 insertions(+), 93 deletions(-) diff --git a/OpenTK.sln b/OpenTK.sln index 0c991156..9ab581b5 100644 --- a/OpenTK.sln +++ b/OpenTK.sln @@ -1,25 +1,52 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK", "Source\OpenTK\OpenTK.csproj", "{A37A7E14-0000-0000-0000-000000000000}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.Compatibility", "Source\Compatibility\OpenTK.Compatibility.csproj", "{62C0DB35-0000-0000-0000-000000000000}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.Examples", "Source\Examples\OpenTK.Examples.csproj", "{868E37B3-0000-0000-0000-000000000000}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.GLControl", "Source\GLControl\OpenTK.GLControl.csproj", "{A625BE88-0000-0000-0000-000000000000}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Installer.Nsis", "Installers\Nsis\Build.Installer.Nsis.csproj", "{ADC34399-7613-44D2-90B2-19250F06FE7A}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Docs", "Documentation\Build.Docs.csproj", "{650C6F3D-33B5-4216-9536-956AB42C0624}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generator.Bind", "Source\Bind\Generator.Bind.csproj", "{31D19132-0000-0000-0000-000000000000}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generator.Convert", "Source\Converter\Generator.Convert.csproj", "{5FDFF4B6-0000-0000-0000-000000000000}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.UpdateVersion", "Source\Build.UpdateVersion\Build.UpdateVersion.csproj", "{75DC22B1-113F-4A66-96B9-2FF8208C10E8}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Installer.Zip", "Installers\Zip\Build.Installer.Zip.csproj", "{ADC34399-7613-44D2-90B2-19250F06FE7B}" + ProjectSection(ProjectDependencies) = postProject + {75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -29,6 +56,45 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A37A7E14-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU + {A37A7E14-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU + {A37A7E14-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU + {A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU + {62C0DB35-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62C0DB35-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62C0DB35-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU + {62C0DB35-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU + {62C0DB35-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU + {62C0DB35-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62C0DB35-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU + {868E37B3-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {868E37B3-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU + {868E37B3-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU + {868E37B3-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU + {868E37B3-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU + {868E37B3-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU + {868E37B3-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU + {A625BE88-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A625BE88-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A625BE88-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU + {A625BE88-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU + {A625BE88-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU + {A625BE88-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A625BE88-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU + {ADC34399-7613-44D2-90B2-19250F06FE7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADC34399-7613-44D2-90B2-19250F06FE7A}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU + {ADC34399-7613-44D2-90B2-19250F06FE7A}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU + {ADC34399-7613-44D2-90B2-19250F06FE7A}.Nsis|Any CPU.Build.0 = Nsis|Any CPU + {ADC34399-7613-44D2-90B2-19250F06FE7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {650C6F3D-33B5-4216-9536-956AB42C0624}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {650C6F3D-33B5-4216-9536-956AB42C0624}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU + {650C6F3D-33B5-4216-9536-956AB42C0624}.Documentation|Any CPU.Build.0 = Documentation|Any CPU + {650C6F3D-33B5-4216-9536-956AB42C0624}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU + {650C6F3D-33B5-4216-9536-956AB42C0624}.Nsis|Any CPU.Build.0 = Nsis|Any CPU + {650C6F3D-33B5-4216-9536-956AB42C0624}.Release|Any CPU.ActiveCfg = Release|Any CPU {31D19132-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {31D19132-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU {31D19132-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU @@ -43,19 +109,6 @@ Global {5FDFF4B6-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU {5FDFF4B6-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU {5FDFF4B6-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {62C0DB35-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {62C0DB35-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {62C0DB35-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU - {62C0DB35-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU - {62C0DB35-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU - {62C0DB35-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {62C0DB35-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {650C6F3D-33B5-4216-9536-956AB42C0624}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {650C6F3D-33B5-4216-9536-956AB42C0624}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU - {650C6F3D-33B5-4216-9536-956AB42C0624}.Documentation|Any CPU.Build.0 = Documentation|Any CPU - {650C6F3D-33B5-4216-9536-956AB42C0624}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU - {650C6F3D-33B5-4216-9536-956AB42C0624}.Nsis|Any CPU.Build.0 = Nsis|Any CPU - {650C6F3D-33B5-4216-9536-956AB42C0624}.Release|Any CPU.ActiveCfg = Release|Any CPU {75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Debug|Any CPU.Build.0 = Debug|Any CPU {75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU @@ -64,42 +117,16 @@ Global {75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Nsis|Any CPU.Build.0 = Nsis|Any CPU {75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Release|Any CPU.ActiveCfg = Release|Any CPU {75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Release|Any CPU.Build.0 = Release|Any CPU - {868E37B3-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {868E37B3-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {868E37B3-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU - {868E37B3-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU - {868E37B3-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU - {868E37B3-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {868E37B3-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A37A7E14-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU - {A37A7E14-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU - {A37A7E14-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU - {A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {A625BE88-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A625BE88-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A625BE88-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU - {A625BE88-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU - {A625BE88-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU - {A625BE88-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A625BE88-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {ADC34399-7613-44D2-90B2-19250F06FE7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ADC34399-7613-44D2-90B2-19250F06FE7A}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU - {ADC34399-7613-44D2-90B2-19250F06FE7A}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU - {ADC34399-7613-44D2-90B2-19250F06FE7A}.Nsis|Any CPU.Build.0 = Nsis|Any CPU - {ADC34399-7613-44D2-90B2-19250F06FE7A}.Release|Any CPU.ActiveCfg = Release|Any CPU {ADC34399-7613-44D2-90B2-19250F06FE7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ADC34399-7613-44D2-90B2-19250F06FE7B}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU {ADC34399-7613-44D2-90B2-19250F06FE7B}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU {ADC34399-7613-44D2-90B2-19250F06FE7B}.Nsis|Any CPU.Build.0 = Nsis|Any CPU {ADC34399-7613-44D2-90B2-19250F06FE7B}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection - GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = Source\Examples\OpenTK.Examples.csproj - EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Source\Examples\OpenTK.Examples.csproj + EndGlobalSection EndGlobal diff --git a/Source/Examples/OpenTK/Test/GameWindowStates.cs b/Source/Examples/OpenTK/Test/GameWindowStates.cs index d5e0bf2d..eda29cce 100644 --- a/Source/Examples/OpenTK/Test/GameWindowStates.cs +++ b/Source/Examples/OpenTK/Test/GameWindowStates.cs @@ -30,7 +30,7 @@ namespace Examples.Tests public GameWindowStates() : base(800, 600, GraphicsMode.Default, "Test", GameWindowFlags.Default, - DisplayDevice.GetDisplay(DisplayIndex.Second), 3, 0, GraphicsContextFlags.Embedded) + DisplayDevice.GetDisplay(DisplayIndex.Second), 1, 0, GraphicsContextFlags.Embedded) { VSync = VSyncMode.On; Keyboard.KeyRepeat = true; diff --git a/Source/OpenTK/Graphics/GraphicsContext.cs b/Source/OpenTK/Graphics/GraphicsContext.cs index 38ad336e..c9c57432 100644 --- a/Source/OpenTK/Graphics/GraphicsContext.cs +++ b/Source/OpenTK/Graphics/GraphicsContext.cs @@ -2,7 +2,7 @@ // // The Open Toolkit Library License // -// Copyright (c) 2006 - 2010 the Open Toolkit library. +// 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 diff --git a/Source/OpenTK/Graphics/GraphicsMode.cs b/Source/OpenTK/Graphics/GraphicsMode.cs index 06b6d3f6..1ef4bd0a 100644 --- a/Source/OpenTK/Graphics/GraphicsMode.cs +++ b/Source/OpenTK/Graphics/GraphicsMode.cs @@ -25,19 +25,10 @@ namespace OpenTK.Graphics static IGraphicsMode implementation; static readonly object SyncRoot = new object(); - #region --- Constructors --- + #region Constructors - #region static GraphicsMode() - - static GraphicsMode() - { - lock (SyncRoot) - { - implementation = Platform.Factory.Default.CreateGraphicsMode(); - } - } - - #endregion + // Disable BeforeFieldInit + static GraphicsMode() { } #region internal GraphicsMode(GraphicsMode mode) @@ -180,7 +171,6 @@ namespace OpenTK.Graphics { get { - LazySelectGraphicsMode(); return index; } set { index = value; } @@ -197,7 +187,6 @@ namespace OpenTK.Graphics { get { - LazySelectGraphicsMode(); return color_format; } private set { color_format = value; } @@ -214,7 +203,6 @@ namespace OpenTK.Graphics { get { - LazySelectGraphicsMode(); return accumulator_format; } private set { accumulator_format = value; } @@ -232,7 +220,6 @@ namespace OpenTK.Graphics { get { - LazySelectGraphicsMode(); return depth; } private set { depth = value; } @@ -250,7 +237,6 @@ namespace OpenTK.Graphics { get { - LazySelectGraphicsMode(); return stencil; } private set { stencil = value; } @@ -267,7 +253,6 @@ namespace OpenTK.Graphics { get { - LazySelectGraphicsMode(); return samples; } private set { samples = value; } @@ -284,7 +269,6 @@ namespace OpenTK.Graphics { get { - LazySelectGraphicsMode(); return stereo; } private set { stereo = value; } @@ -302,7 +286,6 @@ namespace OpenTK.Graphics { get { - LazySelectGraphicsMode(); return buffers; } private set { buffers = value; } @@ -321,9 +304,9 @@ namespace OpenTK.Graphics { if (defaultMode == null) { - Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).", - 32, 24, 8, 0, 0, 2, false); - defaultMode = new GraphicsMode(32, 24, 8, 0, 0, 2, false); + Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}).", + 32, 24, 8); + defaultMode = new GraphicsMode(null, 32, 24, 8, 0, 0, 2, false); } return defaultMode; } @@ -334,30 +317,6 @@ namespace OpenTK.Graphics #endregion - #region --- Private Methods --- - - // Queries the implementation for the actual graphics mode if this hasn't been done already. - // This method allows for lazy evaluation of the actual GraphicsMode and should be called - // by all GraphicsMode properties. - void LazySelectGraphicsMode() - { - if (index == null) - { - GraphicsMode mode = implementation.SelectGraphicsMode(color_format, depth, stencil, samples, accumulator_format, buffers, stereo); - - Index = mode.Index; - ColorFormat = mode.ColorFormat; - Depth = mode.Depth; - Stencil = mode.Stencil; - Samples = mode.Samples; - AccumulatorFormat = mode.AccumulatorFormat; - Buffers = mode.Buffers; - Stereo = mode.Stereo; - } - } - - #endregion - #region --- Overrides --- /// Returns a System.String describing the current GraphicsFormat. diff --git a/Source/OpenTK/Platform/DesktopGraphicsContext.cs b/Source/OpenTK/Platform/DesktopGraphicsContext.cs index f7355b62..e636ec93 100644 --- a/Source/OpenTK/Platform/DesktopGraphicsContext.cs +++ b/Source/OpenTK/Platform/DesktopGraphicsContext.cs @@ -36,9 +36,11 @@ namespace OpenTK.Platform public override void LoadAll() { new OpenTK.Graphics.OpenGL.GL().LoadEntryPoints(); + new OpenTK.Graphics.OpenGL4.GL().LoadEntryPoints(); new OpenTK.Graphics.ES10.GL().LoadEntryPoints(); new OpenTK.Graphics.ES11.GL().LoadEntryPoints(); new OpenTK.Graphics.ES20.GL().LoadEntryPoints(); + new OpenTK.Graphics.ES30.GL().LoadEntryPoints(); } } } diff --git a/Source/OpenTK/Platform/EmbeddedGraphicsContext.cs b/Source/OpenTK/Platform/EmbeddedGraphicsContext.cs index 2ac37638..fb98bb8d 100644 --- a/Source/OpenTK/Platform/EmbeddedGraphicsContext.cs +++ b/Source/OpenTK/Platform/EmbeddedGraphicsContext.cs @@ -38,6 +38,7 @@ namespace OpenTK.Platform new OpenTK.Graphics.ES10.GL().LoadEntryPoints(); new OpenTK.Graphics.ES11.GL().LoadEntryPoints(); new OpenTK.Graphics.ES20.GL().LoadEntryPoints(); + new OpenTK.Graphics.ES30.GL().LoadEntryPoints(); } } } \ No newline at end of file From ec2c64ee15f2f1ec5a0fe11a63e60fb0fbf5a7c0 Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Fri, 8 Nov 2013 10:41:58 +0100 Subject: [PATCH 2/6] Remove static init of GetCurrentContext The static initializer of GetCurrentContext would always default to the desktop PlatformFactory, which caused problems when trying to run OpenGL ES code on the desktop. The initializer is now removed and GetCurrentContext is set in the context constructor, before creating any contexts. --- Source/OpenTK/Graphics/GraphicsContext.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/OpenTK/Graphics/GraphicsContext.cs b/Source/OpenTK/Graphics/GraphicsContext.cs index c9c57432..bcd9dc49 100644 --- a/Source/OpenTK/Graphics/GraphicsContext.cs +++ b/Source/OpenTK/Graphics/GraphicsContext.cs @@ -131,7 +131,6 @@ namespace OpenTK.Graphics case true: factory = Factory.Embedded; break; } - implementation = factory.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags); // Note: this approach does not allow us to mix native and EGL contexts in the same process. // This should not be a problem, as this use-case is not interesting for regular applications. // Note 2: some platforms may not support a direct way of getting the current context @@ -140,12 +139,10 @@ namespace OpenTK.Graphics // declaration). if (GetCurrentContext == null) { - GetCurrentContextDelegate temp = factory.CreateGetCurrentGraphicsContext(); - if (temp != null) - { - GetCurrentContext = temp; - } + GetCurrentContext = factory.CreateGetCurrentGraphicsContext(); } + + implementation = factory.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags); } available_contexts.Add((this as IGraphicsContextInternal).Context, new WeakReference(this)); @@ -321,8 +318,7 @@ namespace OpenTK.Graphics #region public static IGraphicsContext CurrentContext internal delegate ContextHandle GetCurrentContextDelegate(); - internal static GetCurrentContextDelegate GetCurrentContext = - Platform.Factory.Default.CreateGetCurrentGraphicsContext(); + internal static GetCurrentContextDelegate GetCurrentContext; /// /// Gets the GraphicsContext that is current in the calling thread. From 0f01a6d12898b3d77973988356e73ef4785cbbf6 Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Fri, 8 Nov 2013 10:42:48 +0100 Subject: [PATCH 3/6] Stronger check for ES support It is not enough to check for EGL, we also need to check that ContextProfileFlags.ES is set. --- Source/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs b/Source/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs index e7ea0a09..997e1610 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs @@ -125,7 +125,7 @@ namespace OpenTK.Platform.SDL2 int profile; SDL.GL.GetAttribute(ContextAttribute.CONTEXT_PROFILE_MASK, out profile); - if (egl != 0) + if (egl != 0 && (profile & (int)ContextProfileFlags.ES) != 0) { context_flags |= GraphicsContextFlags.Embedded; } From 95316829ecc9b83d3ecd1dc7e51e260210bc805c Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Fri, 8 Nov 2013 10:46:27 +0100 Subject: [PATCH 4/6] Updated WGL init sequence WinGraphicsMode no longer creates a temporary context in order to create the list of available modes. Instead, it requires to be passed an existing context in its constructor. WinGLContext now creates one temporary context in its static constructor and hands that to WinGraphicsMode. WinFactory no longer supports the CreateGraphicsMode API. This API will be removed in the future, because the link because contexts and modes cannot be separated in the general case. --- Source/OpenTK/Platform/Windows/WinFactory.cs | 2 +- .../OpenTK/Platform/Windows/WinGLContext.cs | 95 ++++++----- .../Platform/Windows/WinGraphicsMode.cs | 158 ++++++++---------- 3 files changed, 131 insertions(+), 124 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/WinFactory.cs b/Source/OpenTK/Platform/Windows/WinFactory.cs index f5ae318a..74f27038 100644 --- a/Source/OpenTK/Platform/Windows/WinFactory.cs +++ b/Source/OpenTK/Platform/Windows/WinFactory.cs @@ -89,7 +89,7 @@ namespace OpenTK.Platform.Windows public virtual IGraphicsMode CreateGraphicsMode() { - return new WinGraphicsMode(); + throw new NotSupportedException(); } public virtual OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver() diff --git a/Source/OpenTK/Platform/Windows/WinGLContext.cs b/Source/OpenTK/Platform/Windows/WinGLContext.cs index 0fc6fb82..c866e447 100644 --- a/Source/OpenTK/Platform/Windows/WinGLContext.cs +++ b/Source/OpenTK/Platform/Windows/WinGLContext.cs @@ -36,11 +36,43 @@ namespace OpenTK.Platform.Windows bool vsync_supported; + static readonly IGraphicsMode ModeSelector; + #region --- Contructors --- static WinGLContext() { - Init(); + // Dynamically load the OpenGL32.dll in order to use the extension loading capabilities of Wgl. + if (opengl32Handle == IntPtr.Zero) + { + opengl32Handle = Functions.LoadLibrary(opengl32Name); + if (opengl32Handle == IntPtr.Zero) + throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}", + opengl32Name, Marshal.GetLastWin32Error())); + Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", opengl32Handle)); + } + + // We need to create a temp context in order to load + // wgl extensions (e.g. for multisampling or GL3). + // We cannot rely on OpenTK.Platform.Wgl until we + // create the context and call Wgl.LoadAll(). + Debug.Print("Creating temporary context for wgl extensions."); + using (INativeWindow native = new NativeWindow()) + { + // Create temporary context and load WGL entry points + WinWindowInfo window = native.WindowInfo as WinWindowInfo; + ContextHandle temp_context = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext)); + Wgl.Imports.MakeCurrent(window.DeviceContext, temp_context.Handle); + Wgl.LoadAll(); + + // Query graphics modes + ModeSelector = new WinGraphicsMode(temp_context, window.DeviceContext); + + // Destroy temporary context + Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero); + Wgl.Imports.DeleteContext(temp_context.Handle); + wgl_loaded = true; + } } public WinGLContext(GraphicsMode format, WinWindowInfo window, IGraphicsContext sharedContext, @@ -56,11 +88,8 @@ namespace OpenTK.Platform.Windows if (window.Handle == IntPtr.Zero) throw new ArgumentException("window", "Must be a valid window."); - Mode = format; - Debug.Print("OpenGL will be bound to window:{0} on thread:{1}", window.Handle, System.Threading.Thread.CurrentThread.ManagedThreadId); - SetGraphicsModePFD(format, (WinWindowInfo)window); lock (LoadLock) { @@ -71,18 +100,11 @@ namespace OpenTK.Platform.Windows // side-effects (i.e. the old contexts can still be handled // using the new entry points.) // Sigh... - // if (!wgl_loaded) - { - // We need to create a temp context in order to load wgl extensions (e.g. for multisampling or GL3). - // We cannot rely on OpenTK.Platform.Wgl until we create the context and call Wgl.LoadAll(). - Debug.Print("Creating temporary context for wgl extensions."); - ContextHandle temp_context = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext)); - Wgl.Imports.MakeCurrent(window.DeviceContext, temp_context.Handle); - Wgl.LoadAll(); - Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero); - Wgl.Imports.DeleteContext(temp_context.Handle); - wgl_loaded = true; - } + //if (!wgl_loaded) + //{ + //} + + Mode = SetGraphicsModePFD(format, (WinWindowInfo)window); if (Wgl.Delegates.wglCreateContextAttribsARB != null) { @@ -281,22 +303,35 @@ namespace OpenTK.Platform.Windows #region SetGraphicsModePFD // Note: there is no relevant ARB function. - internal static void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window) + internal static GraphicsMode SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window) { Debug.Write("Setting pixel format... "); + if (window == null) + throw new ArgumentNullException("window", "Must point to a valid window."); if (!mode.Index.HasValue) - throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); - - if (window == null) throw new ArgumentNullException("window", "Must point to a valid window."); + { + mode = ModeSelector.SelectGraphicsMode( + mode.ColorFormat, mode.Depth, mode.Stencil, + mode.Samples, mode.AccumulatorFormat, + mode.Buffers, mode.Stereo); + } PixelFormatDescriptor pfd = new PixelFormatDescriptor(); - Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index.Value, + Functions.DescribePixelFormat( + window.DeviceContext, (int)mode.Index.Value, API.PixelFormatDescriptorSize, ref pfd); + Debug.WriteLine(mode.Index.ToString()); + 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())); + "Requested GraphicsMode not available. SetPixelFormat error: {0}", + Marshal.GetLastWin32Error())); + } + + return mode; } #endregion @@ -314,22 +349,6 @@ namespace OpenTK.Platform.Windows #endregion - static internal void Init() - { - lock (SyncRoot) - { - // Dynamically load the OpenGL32.dll in order to use the extension loading capabilities of Wgl. - if (opengl32Handle == IntPtr.Zero) - { - opengl32Handle = Functions.LoadLibrary(opengl32Name); - if (opengl32Handle == IntPtr.Zero) - throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}", - opengl32Name, Marshal.GetLastWin32Error())); - Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", opengl32Handle)); - } - } - } - #endregion #region Overrides diff --git a/Source/OpenTK/Platform/Windows/WinGraphicsMode.cs b/Source/OpenTK/Platform/Windows/WinGraphicsMode.cs index f679f82a..677e40d0 100644 --- a/Source/OpenTK/Platform/Windows/WinGraphicsMode.cs +++ b/Source/OpenTK/Platform/Windows/WinGraphicsMode.cs @@ -46,19 +46,16 @@ namespace OpenTK.Platform.Windows #region Constructors - public WinGraphicsMode() + public WinGraphicsMode(ContextHandle context, IntPtr device) { lock (SyncRoot) { - using (INativeWindow native = new NativeWindow()) - { - modes.AddRange(GetModesARB(native)); - if (modes.Count == 0) - modes.AddRange(GetModesPFD(native)); - if (modes.Count == 0) - throw new GraphicsModeException( - "No GraphicsMode available. This should never happen, please report a bug at http://www.opentk.com"); - } + modes.AddRange(GetModesARB(context, device)); + if (modes.Count == 0) + modes.AddRange(GetModesPFD(context, device)); + if (modes.Count == 0) + throw new GraphicsModeException( + "No GraphicsMode available. This should never happen, please report a bug at http://www.opentk.com"); modes.Sort(new GraphicsModeComparer()); } } @@ -127,11 +124,9 @@ namespace OpenTK.Platform.Windows #region GetModesPFD - IEnumerable GetModesPFD(INativeWindow native) + IEnumerable GetModesPFD(ContextHandle context, IntPtr device) { - WinWindowInfo window = native.WindowInfo as WinWindowInfo; - IntPtr deviceContext = ((WinWindowInfo)window).DeviceContext; - Debug.WriteLine(String.Format("Device context: {0}", deviceContext)); + Debug.WriteLine(String.Format("Device context: {0}", device)); Debug.WriteLine("Retrieving PFD pixel formats... "); PixelFormatDescriptor pfd = new PixelFormatDescriptor(); @@ -152,7 +147,7 @@ namespace OpenTK.Platform.Windows // Iterate through all accelerated formats first. Afterwards, iterate through non-accelerated formats. // This should fix issue #2224, which causes OpenTK to fail on VMs without hardware acceleration. int pixel = 0; - while (DescribePixelFormat(deviceContext, ++pixel, API.PixelFormatDescriptorSize, ref pfd) != 0) + while (DescribePixelFormat(device, ++pixel, API.PixelFormatDescriptorSize, ref pfd) != 0) { // Ignore non-accelerated formats. if (!generic_allowed && (pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0) @@ -176,90 +171,83 @@ namespace OpenTK.Platform.Windows #region GetModesARB - IEnumerable GetModesARB(INativeWindow native) + IEnumerable GetModesARB(ContextHandle context, IntPtr device) { - using (IGraphicsContext context = new GraphicsContext( - new GraphicsMode(new IntPtr(2), new ColorFormat(), 0, 0, 0, new ColorFormat(), 2, false), - (WinWindowInfo)native.WindowInfo, 1, 0, GraphicsContextFlags.Default)) + // See http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt + // for more details + Debug.Write("Retrieving ARB pixel formats.... "); + if (Wgl.Delegates.wglChoosePixelFormatARB == null || Wgl.Delegates.wglGetPixelFormatAttribivARB == null) { - WinWindowInfo window = (WinWindowInfo)native.WindowInfo; + Debug.WriteLine("failed."); + yield break; + } - // See http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt - // for more details - Debug.Write("Retrieving ARB pixel formats.... "); - if (Wgl.Delegates.wglChoosePixelFormatARB == null || Wgl.Delegates.wglGetPixelFormatAttribivARB == null) - { - Debug.WriteLine("failed."); - yield break; - } + int[] attribs = new int[] + { + (int)WGL_ARB_pixel_format.AccelerationArb, - 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.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_pixel_format.DepthBitsArb, + (int)WGL_ARB_pixel_format.StencilBitsArb, - (int)WGL_ARB_multisample.SampleBuffersArb, - (int)WGL_ARB_multisample.SamplesArb, + (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.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)WGL_ARB_pixel_format.DoubleBufferArb, + (int)WGL_ARB_pixel_format.StereoArb, + 0 + }; - int[] values = new int[attribs.Length]; + int[] values = new int[attribs.Length]; - int[] attribs_values = new int[] + 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(device, 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]]; + + if (Wgl.Arb.ChoosePixelFormat(device, attribs_values, null, pixel.Length, pixel, num_formats)) { - (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]]; - - if (Wgl.Arb.ChoosePixelFormat(window.DeviceContext, attribs_values, null, pixel.Length, pixel, num_formats)) + foreach (int p in pixel) { - foreach (int p in pixel) + // Find out what we really got as a format: + if (!Wgl.Arb.GetPixelFormatAttrib(device, p, 0, attribs.Length - 1, attribs, values)) { - // Find out what we really got as a format: - if (!Wgl.Arb.GetPixelFormatAttrib(window.DeviceContext, p, 0, attribs.Length - 1, attribs, values)) - { - Debug.Print("[Warning] Failed to detect attributes for PixelFormat:{0}.", p); - continue; - } - - GraphicsMode mode = new GraphicsMode(new IntPtr(p), - new ColorFormat(values[1], values[2], values[3], values[4]), - values[6], - values[7], - values[8] != 0 ? values[9] : 0, - new ColorFormat(values[10], values[11], values[12], values[13]), - values[15] == 1 ? 2 : 1, - values[16] == 1 ? true : false); - - yield return mode; + Debug.Print("[Warning] Failed to detect attributes for PixelFormat:{0}.", p); + continue; } + + GraphicsMode mode = new GraphicsMode(new IntPtr(p), + new ColorFormat(values[1], values[2], values[3], values[4]), + values[6], + values[7], + values[8] != 0 ? values[9] : 0, + new ColorFormat(values[10], values[11], values[12], values[13]), + values[15] == 1 ? 2 : 1, + values[16] == 1 ? true : false); + + yield return mode; } } } From b66912a8e1052effafbe2c6c8a752702e2d9db50 Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Sat, 9 Nov 2013 15:13:50 +0100 Subject: [PATCH 5/6] Potential fix for issue 3430 EnableCap.ColorArray is part of the client state and must be enabled with GL.EnableClientState, not GL.Enalbe. This is a potential fix for http://www.opentk.com/node/3430 "Picking example's problem" --- Source/Examples/OpenGL/1.x/Picking.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Examples/OpenGL/1.x/Picking.cs b/Source/Examples/OpenGL/1.x/Picking.cs index f9ccc2d6..d3b9a0c5 100644 --- a/Source/Examples/OpenGL/1.x/Picking.cs +++ b/Source/Examples/OpenGL/1.x/Picking.cs @@ -235,7 +235,7 @@ namespace Examples.Tutorial protected override void OnRenderFrame(FrameEventArgs e) { GL.Color3(Color.White); - GL.Enable(EnableCap.ColorArray); + GL.EnableClientState(EnableCap.ColorArray); #region Pass 1: Draw Object and pick Triangle GL.ClearColor(1f, 1f, 1f, 1f); // clears to uint.MaxValue @@ -261,7 +261,7 @@ namespace Examples.Tutorial #endregion Pass 1: Draw Object and pick Triangle GL.Color3(Color.White); - GL.Disable(EnableCap.ColorArray); + GL.DisableClientState(EnableCap.ColorArray); #region Pass 2: Draw Shape if (SelectedTriangle == uint.MaxValue) From da684d233e85617a19dd5754122c5156c1608437 Mon Sep 17 00:00:00 2001 From: parallels Date: Sat, 9 Nov 2013 17:13:24 +0100 Subject: [PATCH 6/6] Swallow DllNotFoundException in Sdl2 constructor --- Source/OpenTK/Platform/SDL2/Sdl2.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/Platform/SDL2/Sdl2.cs b/Source/OpenTK/Platform/SDL2/Sdl2.cs index 0dd1bbb6..0f62e52c 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2.cs @@ -47,7 +47,14 @@ namespace OpenTK.Platform.SDL2 static SDL() { - GetVersion(out Version); + try + { + GetVersion(out Version); + } + catch + { + // nom nom + } } #region Functions