コード例 #1
0
ファイル: GraphicsContext.cs プロジェクト: yaram/OpenGL.Net
        public void TestConstructorRaw()
        {
            using (DeviceContext deviceContext = DeviceContext.Create()) {
                // Create a context manually
                IntPtr glContext = deviceContext.CreateContext(IntPtr.Zero);

                // Create a GraphicsContext on glContext
                GraphicsContext graphicsContext = null;

                try {
                    Assert.DoesNotThrow(delegate { graphicsContext = new GraphicsContext(deviceContext, glContext); });
                    TestConstructProperties(graphicsContext);

                    Assert.AreEqual(glContext, graphicsContext.Handle, "GL context handle different from original");
                    Assert.IsTrue(deviceContext.RefCount > 0, "DeviceContext is not referenced");
                } finally {
                    if (graphicsContext != null)
                    {
                        graphicsContext.Dispose();
                        TestDisposedProperties(graphicsContext);
                    }
                }

                Assert.IsTrue(deviceContext.RefCount == 0, "DeviceContext was not referenced");

                // Context won't be deleted by GraphicsContext in this case
                deviceContext.DeleteContext(glContext);
            }
        }
コード例 #2
0
		private static void RenderOsdPBuffer(DeviceContext deviceContext)
		{
			IntPtr glContext = IntPtr.Zero;
			uint framebuffer = 0;
			uint renderbuffer = 0;

			try {
				// Create context and make current on this thread
				if ((glContext = deviceContext.CreateContext(IntPtr.Zero)) == IntPtr.Zero)
					throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());	// XXX
				deviceContext.MakeCurrent(glContext);

				// Create framebuffer resources
				int w = Math.Min(800, 800);
				int h = Math.Min(600, 800);

				RenderOsd(w, h);
				SnapshotOsd(w, h);

			} finally {
				if (renderbuffer != 0)
					Gl.DeleteRenderbuffers(renderbuffer);
				if (framebuffer != 0)
					Gl.DeleteFramebuffers(framebuffer);
				if (glContext != IntPtr.Zero)
					deviceContext.DeleteContext(glContext);
			}
		}
コード例 #3
0
        private void TestGetCurrentContext_Core()
        {
            using (DeviceContext deviceContext = DeviceContext.Create()) {
                if (deviceContext.IsPixelFormatSet == false)
                {
                    deviceContext.ChoosePixelFormat(new DevicePixelFormat(24));
                }

                IntPtr currentContext = DeviceContext.GetCurrentContext();

                // Initially no current context
                Assert.AreEqual(IntPtr.Zero, currentContext);

                IntPtr glContext = deviceContext.CreateContext(IntPtr.Zero);
                try {
                    deviceContext.MakeCurrent(glContext);

                    // No the previously GL context is current on this thread
                    currentContext = DeviceContext.GetCurrentContext();
                    Assert.AreEqual(glContext, currentContext);

                    deviceContext.MakeCurrent(IntPtr.Zero);
                } finally {
                    deviceContext.DeleteContext(glContext);
                }
            }
        }
コード例 #4
0
        public static void Init()
        {
            Gl.Initialize();

            pixelBuff = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 128, 128);
            devCtx    = DeviceContext.Create(pixelBuff);
            glCtx     = devCtx.CreateContext(IntPtr.Zero);

            devCtx.MakeCurrent(glCtx);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: koson/OpenGL.Net
        private static void RenderOsdFramebuffer(DeviceContext deviceContext)
        {
            IntPtr glContext    = IntPtr.Zero;
            uint   framebuffer  = 0;
            uint   renderbuffer = 0;

            try {
                // Create context and make current on this thread
                if ((glContext = deviceContext.CreateContext(IntPtr.Zero)) == IntPtr.Zero)
                {
                    throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());                         // XXX
                }
                deviceContext.MakeCurrent(glContext);

                // Create framebuffer resources
                int w = Math.Min(800, Gl.CurrentLimits.MaxRenderbufferSize);
                int h = Math.Min(600, Gl.CurrentLimits.MaxRenderbufferSize);

                renderbuffer = Gl.GenRenderbuffer();
                Gl.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderbuffer);
                Gl.RenderbufferStorage(RenderbufferTarget.Renderbuffer, InternalFormat.Rgb8, w, h);

                framebuffer = Gl.GenFramebuffer();
                Gl.BindFramebuffer(FramebufferTarget.ReadFramebuffer, framebuffer);
                Gl.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer);
                Gl.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, RenderbufferTarget.Renderbuffer, renderbuffer);

                FramebufferStatus framebufferStatus = Gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
                if (framebufferStatus != FramebufferStatus.FramebufferComplete)
                {
                    throw new InvalidOperationException("framebuffer not complete");
                }

                Gl.DrawBuffers(Gl.COLOR_ATTACHMENT0);

                RenderOsd(w, h);

                Gl.ReadBuffer(ReadBufferMode.ColorAttachment0);

                SnapshotOsd(w, h);
            } finally {
                if (renderbuffer != 0)
                {
                    Gl.DeleteRenderbuffers(renderbuffer);
                }
                if (framebuffer != 0)
                {
                    Gl.DeleteFramebuffers(framebuffer);
                }
                if (glContext != IntPtr.Zero)
                {
                    deviceContext.DeleteContext(glContext);
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: owenxuwei/OpenGL.Net
        static void Main()
        {
            try {
                string envDebug = Environment.GetEnvironmentVariable("DEBUG");
                if (envDebug == "GL")
                {
                    KhronosApi.Log += delegate(object sender, KhronosLogEventArgs e) {
                        Console.WriteLine(e.ToString());
                    };
                    KhronosApi.LogEnabled = true;
                }

                // RPi runs on EGL
                Egl.IsRequired = true;

                if (Egl.IsAvailable == false)
                {
                    throw new InvalidOperationException("EGL is not available. Aborting.");
                }

                using (VideoCoreWindow nativeWindow = new VideoCoreWindow()) {
                    using (DeviceContext eglContext = DeviceContext.Create(nativeWindow.Display, nativeWindow.Handle)) {
                        eglContext.ChoosePixelFormat(new DevicePixelFormat(32));

                        IntPtr glContext = eglContext.CreateContext(IntPtr.Zero);

                        eglContext.MakeCurrent(glContext);

                        Initialize();

                        Gl.Viewport(0, 0, 1920, 1080);
                        Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);

                        while (true)
                        {
                            Gl.Clear(ClearBufferMask.ColorBufferBit);
                            Draw();
                            eglContext.SwapBuffers();
                            break;
                        }

                        System.Threading.Thread.Sleep(10000);

                        Terminate();
                        eglContext.DeleteContext(glContext);
                    }
                }
            } catch (Exception exception) {
                Console.WriteLine(exception.ToString());
            }
        }
コード例 #7
0
        private void DeviceContext_CreateContext_DefaultAPI_Core(string api)
        {
            using (Device device = new Device())
            {
                DeviceContext deviceContext = device.Context;
                List <string> availableAPIs = new List <string>(deviceContext.AvailableAPIs);

                if (availableAPIs.Contains(api) == false)
                {
                    Assert.Inconclusive("underlying device is unable to support '" + api + "'");
                }

                if (deviceContext.IsPixelFormatSet == false)
                {
                    deviceContext.ChoosePixelFormat(new DevicePixelFormat(24));
                }

                IntPtr glContext = deviceContext.CreateContext(IntPtr.Zero);
                Assert.AreNotEqual(IntPtr.Zero, glContext);

                try {
                    if (deviceContext.MakeCurrent(glContext) == false)
                    {
                        Assert.Fail("unable to make current");
                    }

                    string         glVersionString = Gl.GetString(StringName.Version);
                    KhronosVersion glVersion       = KhronosVersion.Parse(glVersionString);

                    switch (api)
                    {
                    case KhronosVersion.ApiGlsc2:
                        // SC2 is a special case: based on ES2
                        Assert.AreEqual(KhronosVersion.ApiGles2, glVersion.Api);
                        break;

                    default:
                        Assert.AreEqual(api, glVersion.Api);
                        break;
                    }

                    deviceContext.MakeCurrent(IntPtr.Zero);
                } finally {
                    if (glContext != IntPtr.Zero)
                    {
                        deviceContext.DeleteContext(glContext);
                    }
                }
            }
        }
コード例 #8
0
        void InitOpenGL()
        {
            // Create OpenGL device context
            _deviceContext = DeviceContext.Create(IntPtr.Zero, _hWnd);

            // Choose pixel format
            _deviceContext.ChoosePixelFormat(new DevicePixelFormat(24));

            // Create OpenGL Context
            _ctx = _deviceContext.CreateContext(IntPtr.Zero);

            // Make context current
            _deviceContext.MakeCurrent(_ctx);
        }
コード例 #9
0
        private void TestUserCase1_Core()
        {
            using (DeviceContext deviceContext = DeviceContext.Create()) {
                if (deviceContext.IsPixelFormatSet == false)
                {
                    deviceContext.ChoosePixelFormat(new DevicePixelFormat(24));
                }

                IntPtr glContext = deviceContext.CreateContext(IntPtr.Zero);

                deviceContext.MakeCurrent(glContext);
                // Perform drawing...
                deviceContext.MakeCurrent(IntPtr.Zero);
                deviceContext.DeleteContext(glContext);
            }
        }
コード例 #10
0
		private static void RenderOsdFramebuffer(DeviceContext deviceContext)
		{
			IntPtr glContext = IntPtr.Zero;
			uint framebuffer = 0;
			uint renderbuffer = 0;

			try {
				// Create context and make current on this thread
				if ((glContext = deviceContext.CreateContext(IntPtr.Zero)) == IntPtr.Zero)
					throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());	// XXX
				deviceContext.MakeCurrent(glContext);

				// Create framebuffer resources
				int w = Math.Min(800, Gl.CurrentLimits.MaxRenderBufferSize);
				int h = Math.Min(600, Gl.CurrentLimits.MaxRenderBufferSize);

				renderbuffer = Gl.GenRenderbuffer();
				Gl.BindRenderbuffer(Gl.RENDERBUFFER, renderbuffer);
				Gl.RenderbufferStorage(Gl.RENDERBUFFER, Gl.RGB8, w, h);

				framebuffer = Gl.GenFramebuffer();
				Gl.BindFramebuffer(Gl.READ_FRAMEBUFFER, framebuffer);
				Gl.BindFramebuffer(Gl.FRAMEBUFFER, framebuffer);
				Gl.FramebufferRenderbuffer(Gl.FRAMEBUFFER, Gl.COLOR_ATTACHMENT0, Gl.RENDERBUFFER, renderbuffer);

				int framebufferStatus = Gl.CheckFramebufferStatus(Gl.FRAMEBUFFER);
				if (framebufferStatus != Gl.FRAMEBUFFER_COMPLETE)
					throw new InvalidOperationException("framebuffer not complete");

				Gl.DrawBuffers(Gl.COLOR_ATTACHMENT0);

				RenderOsd(w, h);

				Gl.ReadBuffer(ReadBufferMode.ColorAttachment0);

				SnapshotOsd(w, h);

			} finally {
				if (renderbuffer != 0)
					Gl.DeleteRenderbuffers(renderbuffer);
				if (framebuffer != 0)
					Gl.DeleteFramebuffers(framebuffer);
				if (glContext != IntPtr.Zero)
					deviceContext.DeleteContext(glContext);
			}
		}
コード例 #11
0
        public Sender()
        {
            _sendPool =
                new DedicatedThreadPool(new DedicatedThreadPoolSettings(1, ThreadType.Background,
                                                                        "Send-Pool"));
            _sendPool.QueueUserWorkItem(() =>
            {
                // Initialize Static Core
                _deviceContext = DeviceContext.Create();
                _glContext     = _deviceContext.CreateContext(IntPtr.Zero);
                _deviceContext.MakeCurrent(_glContext);

                //_senderLocker = new object();

                // Initialize Core
                _sender = new SpoutSender();
                _sender.CreateSender(SenderName, _width, _height, 0);
            });
        }
コード例 #12
0
        private void TestUserCase3_Core()
        {
            if (DeviceContext.IsPBufferSupported == false)
            {
                Assert.Inconclusive("platform don't support P-Buffers");
            }

            using (INativePBuffer nativePBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 64, 64)) {
                using (DeviceContext deviceContext = DeviceContext.Create(nativePBuffer)) {
                    // The pixel format is already defined by INativePBuffer
                    Assert.IsTrue(deviceContext.IsPixelFormatSet);

                    IntPtr glContext = deviceContext.CreateContext(IntPtr.Zero);

                    deviceContext.MakeCurrent(glContext);
                    // Perform drawing...
                    deviceContext.MakeCurrent(IntPtr.Zero);
                    deviceContext.DeleteContext(glContext);
                }
            }
        }
コード例 #13
0
        public RCode CreateDevice(Dictionary <string, object> parameters, bool bFullScreen, bool bVSYNC)
        {
            IntPtr window  = IntPtr.Zero;
            IntPtr display = IntPtr.Zero;

            if (parameters.ContainsKey("windowPtr"))
            {
                window = (IntPtr)parameters["windowPtr"];
            }
            if (parameters.ContainsKey("displayPtr"))
            {
                display = (IntPtr)parameters["displayPtr"];
            }

            deviceContext = DeviceContext.Create(display, window);
            deviceContext.ChoosePixelFormat(new DevicePixelFormat()
            {
                DoubleBuffer = true
            });

            renderContext = deviceContext.CreateContext(IntPtr.Zero);

            if (renderContext == IntPtr.Zero)
            {
                return(RCode.FAIL);
            }
            if (!deviceContext.MakeCurrent(renderContext))
            {
                return(RCode.FAIL);
            }

            deviceContext.SwapInterval(0);

            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            Gl.Enable(EnableCap.Texture2d);

            return(RCode.OK);
        }
コード例 #14
0
        private void TestCreateContextAttrib_Core()
        {
            using (DeviceContext deviceContext = DeviceContext.Create()) {
                if (deviceContext.IsPixelFormatSet == false)
                {
                    deviceContext.ChoosePixelFormat(new DevicePixelFormat(24));
                }

                IntPtr glContext = IntPtr.Zero;

                Assert.DoesNotThrow(delegate() { glContext = deviceContext.CreateContext(IntPtr.Zero); });
                try {
                    Assert.AreNotEqual(IntPtr.Zero, glContext);
                    Assert.DoesNotThrow(delegate() { deviceContext.MakeCurrent(glContext); });

                    Assert.DoesNotThrow(delegate() { deviceContext.MakeCurrent(IntPtr.Zero); });
                } finally {
                    if (glContext != IntPtr.Zero)
                    {
                        deviceContext.DeleteContext(glContext);
                    }
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// This is called immediately after the surface is first created.
        /// </summary>
        /// <param name="holder">
        /// The SurfaceHolder whose surface is being created.
        /// </param>
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            Debug.WriteLine("Sparrow: SurfaceCreated");
            // Get actual native window handle
            _NativeWindowHandle = ANativeWindow_fromSurface(JNIEnv.Handle, holder.Surface.Handle);

            // Create device context
            _DeviceContext = DeviceContext.Create(IntPtr.Zero, _NativeWindowHandle);
            _DeviceContext.IncRef();

            // Set pixel format
            DevicePixelFormatCollection pixelFormats     = _DeviceContext.PixelsFormats;
            DevicePixelFormat           controlReqFormat = new DevicePixelFormat();

            controlReqFormat.RgbaUnsigned = true;
            controlReqFormat.RenderWindow = true;
            controlReqFormat.ColorBits    = 24;
            //controlReqFormat.DepthBits = (int)DepthBits;
            //controlReqFormat.StencilBits = (int)StencilBits;
            //controlReqFormat.MultisampleBits = (int)MultisampleBits;
            //controlReqFormat.DoubleBuffer = true;

            List <DevicePixelFormat> matchingPixelFormats = pixelFormats.Choose(controlReqFormat);

            if (matchingPixelFormats.Count == 0)
            {
                throw new InvalidOperationException("unable to find a suitable pixel format");
            }
            _DeviceContext.SetPixelFormat(matchingPixelFormats[0]);

            // Create OpenGL context using compatibility profile
            if ((_RenderContext = _DeviceContext.CreateContext(IntPtr.Zero)) == IntPtr.Zero)
            {
                throw new InvalidOperationException("unable to create render context");
            }
            // Make context current
            if (_DeviceContext.MakeCurrent(_RenderContext) == false)
            {
                throw new InvalidOperationException("unable to make context current");
            }

            Invalidate();

            if (_RenderTimer != null)
            {
                throw new InvalidOperationException("rendering already active");
            }

            if (SparrowSharp.Root == null)
            {
                SparrowSharp.NativeWindow = this;
                // TODO get viewport dimensions?
                SparrowSharp.Start((uint)Width, (uint)Height, (uint)Width, (uint)Height, _rootClass);
            }
            else
            {
                SparrowSharp.OnContextCreated();
            }

            _RenderTimerDueTime = (int)Math.Ceiling(1000.0f / 60.0f);
            _RenderTimer        = new Timer(RenderTimerCallback, null, _RenderTimerDueTime, Timeout.Infinite);
        }
コード例 #16
0
ファイル: NativeWindow.cs プロジェクト: ipud2/OpenGL.Net-1
        /// <summary>
        /// Create the NativeWindow context, eventually shared with others.
        /// </summary>
        protected void CreateDesktopContext()
        {
            if (GLContext != IntPtr.Zero)
            {
                throw new InvalidOperationException("context already created");
            }

            IntPtr sharingContext = IntPtr.Zero;
            bool   shareResources = false;

            if (shareResources)
            {
                List <IntPtr> sharingContextes;

                if (_SharingGroups.TryGetValue(ContextSharingGroup, out sharingContextes))
                {
                    sharingContext = sharingContextes.Count > 0 ? sharingContextes[0] : IntPtr.Zero;
                }
                else
                {
                    _SharingGroups.Add(ContextSharingGroup, new List <IntPtr>());
                }
            }

            if (Gl.PlatformExtensions.CreateContext_ARB)
            {
                List <int> attributes = new List <int>();
                uint       contextProfile = 0, contextFlags = 0;
                bool       debuggerAttached = Debugger.IsAttached;

                #region WGL_ARB_create_context|GLX_ARB_create_context

                // The default values for WGL_CONTEXT_MAJOR_VERSION_ARB and WGL_CONTEXT_MINOR_VERSION_ARB are 1 and 0 respectively. In this
                // case, implementations will typically return the most recent version of OpenGL they support which is backwards compatible with OpenGL 1.0
                // (e.g. 3.0, 3.1 + GL_ARB_compatibility, or 3.2 compatibility profile) [from WGL_ARB_create_context spec]
                Debug.Assert(Wgl.CONTEXT_MAJOR_VERSION_ARB == Glx.CONTEXT_MAJOR_VERSION_ARB);
                Debug.Assert(Wgl.CONTEXT_MINOR_VERSION_ARB == Glx.CONTEXT_MINOR_VERSION_ARB);
                if (ContextVersion != null)
                {
                    attributes.AddRange(new int[] {
                        Wgl.CONTEXT_MAJOR_VERSION_ARB, ContextVersion.Major,
                        Wgl.CONTEXT_MINOR_VERSION_ARB, ContextVersion.Minor
                    });
                }
                else
                {
                    // Note: this shouldn't be necessary since defaults are defined. However, on certains drivers this arguments are
                    // required for specifying CONTEXT_FLAGS_ARB and CONTEXT_PROFILE_MASK_ARB attributes:
                    // - Required by NVIDIA 266.72 on GeForce GT 540M on Windows 7 x64
                    attributes.AddRange(new int[] {
                        Wgl.CONTEXT_MAJOR_VERSION_ARB, 1,
                        Wgl.CONTEXT_MINOR_VERSION_ARB, 0
                    });
                }

                if (_DebugContextBit == AttributePermission.Enabled || debuggerAttached && _DebugContextBit == AttributePermission.EnabledInDebugger)
                {
                    Debug.Assert(Wgl.CONTEXT_DEBUG_BIT_ARB == Glx.CONTEXT_DEBUG_BIT_ARB);
                    contextFlags |= Wgl.CONTEXT_DEBUG_BIT_ARB;
                }

                if (_ForwardCompatibleContextBit == AttributePermission.Enabled || debuggerAttached && _ForwardCompatibleContextBit == AttributePermission.EnabledInDebugger)
                {
                    Debug.Assert(Wgl.CONTEXT_FORWARD_COMPATIBLE_BIT_ARB == Glx.CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
                    contextFlags |= Wgl.CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
                }

                #endregion

                #region WGL_ARB_create_context_profile|GLX_ARB_create_context_profile

                if (Gl.PlatformExtensions.CreateContextProfile_ARB)
                {
                    switch (_ProfileType)
                    {
                    case ProfileType.Core:
                        Debug.Assert(Wgl.CONTEXT_CORE_PROFILE_BIT_ARB == Glx.CONTEXT_CORE_PROFILE_BIT_ARB);
                        contextProfile |= Wgl.CONTEXT_CORE_PROFILE_BIT_ARB;
                        break;

                    case ProfileType.Compatibility:
                        Debug.Assert(Wgl.CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB == Glx.CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
                        contextProfile |= Wgl.CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
                        break;
                    }
                }

                #endregion

                #region WGL_ARB_create_context_robustness|GLX_ARB_create_context_robustness

                if (Gl.PlatformExtensions.CreateContextRobustness_ARB)
                {
                    if (_RobustContextBit == AttributePermission.Enabled || debuggerAttached && _RobustContextBit == AttributePermission.EnabledInDebugger)
                    {
                        Debug.Assert(Wgl.CONTEXT_ROBUST_ACCESS_BIT_ARB == Glx.CONTEXT_ROBUST_ACCESS_BIT_ARB);
                        contextFlags |= Wgl.CONTEXT_ROBUST_ACCESS_BIT_ARB;
                    }
                }

                #endregion

                Debug.Assert(Wgl.CONTEXT_FLAGS_ARB == Glx.CONTEXT_FLAGS_ARB);
                if (contextFlags != 0)
                {
                    attributes.AddRange(new int[] { Wgl.CONTEXT_FLAGS_ARB, unchecked ((int)contextFlags) });
                }

                Debug.Assert(Wgl.CONTEXT_PROFILE_MASK_ARB == Glx.CONTEXT_PROFILE_MASK_ARB);
                Debug.Assert(contextProfile == 0 || Gl.PlatformExtensions.CreateContextProfile_ARB);
                if (contextProfile != 0)
                {
                    attributes.AddRange(new int[] { Wgl.CONTEXT_PROFILE_MASK_ARB, unchecked ((int)contextProfile) });
                }

                attributes.Add(0);

                if ((GLContext = DeviceContext.CreateContextAttrib(sharingContext, attributes.ToArray())) == IntPtr.Zero)
                {
                    throw new InvalidOperationException($"unable to create render context ({Gl.GetError()})");
                }
            }
            else
            {
                // Create OpenGL context using compatibility profile
                if ((GLContext = DeviceContext.CreateContext(sharingContext)) == IntPtr.Zero)
                {
                    throw new InvalidOperationException("unable to create render context");
                }
            }

            // Allow other GlControl instances to reuse this GlControl context
            if (shareResources)
            {
                if (_SharingWindows.ContainsKey(ContextSharingGroup))
                {
                    throw new InvalidOperationException($"another GlControl has created sharing group {ContextSharingGroup}");
                }
                _SharingWindows.Add(ContextSharingGroup, this);
            }

            // Allow other GlControl instances to share resources with this context
            if (shareResources)
            {
                List <IntPtr> sharingContextes;

                // Get the list previously created
                _SharingGroups.TryGetValue(ContextSharingGroup, out sharingContextes);
                // ...and register this context among the others
                sharingContextes.Add(GLContext);
            }
        }
コード例 #17
0
ファイル: GlWidget.cs プロジェクト: pingyuan162/OpenGL.Net
        /// <summary>
        /// Create the GlWidget context.
        /// </summary>
        private void CreateContext()
        {
            if (_GraphicsContext != IntPtr.Zero)
            {
                throw new InvalidOperationException("context already created");
            }

            IntPtr sharingContext = IntPtr.Zero;

            if (Gl.PlatformExtensions.CreateContext_ARB)
            {
                List <int> attributes = new List <int>();
                uint       contextProfile = 0, contextFlags = 0;
                bool       debuggerAttached = Debugger.IsAttached;

                #region WGL_ARB_create_context|GLX_ARB_create_context

                #endregion

                #region WGL_ARB_create_context_profile|GLX_ARB_create_context_profile

                if (Gl.PlatformExtensions.CreateContextProfile_ARB)
                {
                }

                #endregion

                #region WGL_ARB_create_context_robustness|GLX_ARB_create_context_robustness

                if (Gl.PlatformExtensions.CreateContextRobustness_ARB)
                {
                }

                #endregion

                Debug.Assert(Wgl.CONTEXT_FLAGS_ARB == Glx.CONTEXT_FLAGS_ARB);
                if (contextFlags != 0)
                {
                    attributes.AddRange(new int[] { Wgl.CONTEXT_FLAGS_ARB, unchecked ((int)contextFlags) });
                }

                Debug.Assert(Wgl.CONTEXT_PROFILE_MASK_ARB == Glx.CONTEXT_PROFILE_MASK_ARB);
                Debug.Assert(contextProfile == 0 || Gl.PlatformExtensions.CreateContextProfile_ARB);
                if (contextProfile != 0)
                {
                    attributes.AddRange(new int[] { Wgl.CONTEXT_PROFILE_MASK_ARB, unchecked ((int)contextProfile) });
                }

                attributes.Add(0);

                if ((_GraphicsContext = _DeviceContext.CreateContextAttrib(sharingContext, attributes.ToArray())) == IntPtr.Zero)
                {
                    throw new InvalidOperationException(String.Format("unable to create render context ({0})", Gl.GetError()));
                }
            }
            else
            {
                // Create OpenGL context using compatibility profile
                if ((_GraphicsContext = _DeviceContext.CreateContext(sharingContext)) == IntPtr.Zero)
                {
                    throw new InvalidOperationException("unable to create render context");
                }
            }
        }