コード例 #1
0
        public void TestReferenceCount()
        {
            // By default, runs without EGL
            Egl.IsRequired = false;

            using (DeviceContext deviceContext = DeviceContext.Create()) {
                Assert.AreEqual(0, deviceContext.RefCount);
                Assert.IsFalse(deviceContext.IsDisposed);

                deviceContext.IncRef();
                Assert.AreEqual(1, deviceContext.RefCount);
                Assert.IsFalse(deviceContext.IsDisposed);

                deviceContext.IncRef();
                Assert.AreEqual(2, deviceContext.RefCount);
                Assert.IsFalse(deviceContext.IsDisposed);

                deviceContext.DecRef();
                Assert.AreEqual(1, deviceContext.RefCount);
                Assert.IsFalse(deviceContext.IsDisposed);

                deviceContext.DecRef();
                Assert.AreEqual(0, deviceContext.RefCount);
                Assert.IsTrue(deviceContext.IsDisposed);
            }
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Gl.Initialize();

            try {
                // Gl.CurrentExtensions.FramebufferObject_ARB = false;		// Test P-Buffer
                // Egl.IsRequired = Egl.IsAvailable;						// Test EGL (not yet working)

                if (Gl.CurrentExtensions.FramebufferObject_ARB)
                {
                    using (DeviceContext deviceContext = DeviceContext.Create()) {
                        RenderOsdFramebuffer(deviceContext);
                    }
                }
                else
                {
                    // Fallback to old-school pbuffer
                    using (INativePBuffer nativeBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 800, 600)) {
                        using (DeviceContext deviceContext = DeviceContext.Create(nativeBuffer)) {
                            RenderOsdPBuffer(deviceContext);
                        }
                    }
                }
            } catch (Exception exception) {
                Console.WriteLine("Unexpected exception: {0}", exception.ToString());
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
		static void Main()
		{
			string envDebug = Environment.GetEnvironmentVariable("DEBUG");

			if (envDebug == "GL") {
				KhronosApi.RegisterApplicationLogDelegate(delegate (string format, object[] args) {
					Console.WriteLine(format, args);
				});
			}

			try {
				// Gl.CurrentExtensions.FramebufferObject_ARB = false;		// Test P-Buffer
				// Egl.IsRequired = Egl.IsAvailable;						// Test EGL (not yet working)

				if (Gl.CurrentExtensions.FramebufferObject_ARB) {
					using (DeviceContext deviceContext = DeviceContext.Create()) {
						RenderOsdFramebuffer(deviceContext);
					}
				} else {
					// Fallback to old-school pbuffer
					using (INativePBuffer nativeBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 800, 600)) {
						using (DeviceContext deviceContext = DeviceContext.Create(nativeBuffer)) {
							RenderOsdPBuffer(deviceContext);
						}
					}
				}
			} catch (Exception exception) {
				Console.WriteLine("Unexpected exception: {0}", exception.ToString());
			}
		}
コード例 #6
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);
        }
コード例 #7
0
        private void DeviceContext_Create1_Core()
        {
            DeviceContext deviceContext = null;

            // "Windowless" DeviceContext creation should be possible on every platform
            Assert.DoesNotThrow(() => deviceContext = DeviceContext.Create());
            Assert.IsNotNull(deviceContext);

            // Release resources
            deviceContext.Dispose();
        }
コード例 #8
0
ファイル: GraphicsContext.cs プロジェクト: yaram/OpenGL.Net
        public void TestConstructor()
        {
            using (DeviceContext deviceContext = DeviceContext.Create()) {
                GraphicsContext graphicsContext;

                using (graphicsContext = new GraphicsContext(deviceContext)) {
                    TestConstructProperties(graphicsContext);
                }
                TestDisposedProperties(graphicsContext);
            }
        }
コード例 #9
0
        private void TestAvailableAPIs_Core()
        {
            using (DeviceContext deviceContext = DeviceContext.Create()) {
                if (deviceContext.IsPixelFormatSet == false)
                {
                    deviceContext.ChoosePixelFormat(new DevicePixelFormat(24));
                }

                Assert.IsNotNull(deviceContext.AvailableAPIs);
                CollectionAssert.IsNotEmpty(deviceContext.AvailableAPIs);
            }
        }
コード例 #10
0
 public Device(DevicePixelFormat pixelFormat)
 {
     if (DeviceContext.IsPBufferSupported)
     {
         _NativePBuffer = DeviceContext.CreatePBuffer(pixelFormat, 64, 64);
         Context        = DeviceContext.Create(_NativePBuffer);
     }
     else
     {
         Assert.Inconclusive("no UI backend available");
     }
 }
コード例 #11
0
ファイル: OpenGlTests.cs プロジェクト: brownard/MP2-Emulators
        public void TryCreateContext()
        {
            int major = 2;
            int minor = 1;

            Gl.Initialize();
            var deviceContext = DeviceContext.Create();

            GlContext glContext = GlContext.TryCreate(deviceContext, major, minor, SharpRetro.LibRetro.retro_hw_context_type.RETRO_HW_CONTEXT_OPENGL, false);

            Assert.NotNull(glContext);
            glContext.Dispose();
        }
コード例 #12
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());
            }
        }
コード例 #13
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);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: ihildebrandt/OpenGL.Net
        protected override void OnRealized()
        {
            // Base implementation
            base.OnRealized();

            IntPtr winHandle = GetWindowHandle();

            if (winHandle != IntPtr.Zero)
            {
                _DeviceContext = DeviceContext.Create(IntPtr.Zero, GetWindowHandle());
                _DeviceContext.ChoosePixelFormat(new DevicePixelFormat(24));

                _GraphicsContext = _DeviceContext.CreateContext(IntPtr.Zero);
            }
        }
コード例 #15
0
        private void TestCreateContext_DefaultAPI_Core(string api)
        {
            using (DeviceContext deviceContext = DeviceContext.Create()) {
                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);
                    }
                }
            }
        }
コード例 #16
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);
            }
        }
コード例 #17
0
        private void DeviceContext_Create3_Core()
        {
            if (DeviceContext.IsPBufferSupported == false)
            {
                Assert.Inconclusive("platform don't support P-Buffers");
            }

            DeviceContext deviceContext = null;

            using (INativePBuffer nativePBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 64, 64)) {
                Assert.DoesNotThrow(() => deviceContext = DeviceContext.Create(nativePBuffer));
                Assert.IsNotNull(nativePBuffer);

                // Release resources
                deviceContext.Dispose();
            }
        }
コード例 #18
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);
            });
        }
コード例 #19
0
        public bool SetHWRender(ref retro_hw_render_callback hwRenderCallback)
        {
            if (_deviceContext != null)
            {
                return(false);
            }

            _deviceContext = DeviceContext.Create();

            // Try and create an openGl context using the attributes specified in the callback
            _glContext = GlContext.TryCreate(_deviceContext, (int)hwRenderCallback.version_major, (int)hwRenderCallback.version_minor,
                                             (retro_hw_context_type)hwRenderCallback.context_type, hwRenderCallback.debug_context);

            // Creation might fail if the system doesn't
            // support the requested attributes
            if (_glContext == null)
            {
                return(false);
            }

            // ToDo: Some cores seem to need a separate shared context
            // but can't get it to work yet...
            if (_haveSharedContext)
            {
                _sharedGlContext = _glContext.CreateSharedContext();
            }

            // Render context that the libretro core will render to, contains a texture buffer and an optional depth/stencil buffer.
            _libretroContext = new LibretroRenderContext(hwRenderCallback.depth, hwRenderCallback.stencil, hwRenderCallback.bottom_left_origin);

            // Get the libretro core callbacks
            _contextResetDlgt = hwRenderCallback.context_reset != IntPtr.Zero ?
                                Marshal.GetDelegateForFunctionPointer <retro_hw_context_reset_t>(hwRenderCallback.context_reset) : null;

            _contextDestroyDlgt = hwRenderCallback.context_destroy != IntPtr.Zero ?
                                  Marshal.GetDelegateForFunctionPointer <retro_hw_context_reset_t>(hwRenderCallback.context_destroy) : null;

            // Pass the opengl callbacks back to the core
            hwRenderCallback.get_proc_address        = Marshal.GetFunctionPointerForDelegate(_getProcAddressDelegate);
            hwRenderCallback.get_current_framebuffer = Marshal.GetFunctionPointerForDelegate(_getCurrentFramebufferDlgt);

            return(true);
        }
コード例 #20
0
ファイル: TestBase.cs プロジェクト: vipyami/OpenGL.Net
        public void FixtureSetUp()
        {
            try {
                // Support ES tests
                Egl.IsRequired = IsEsTest;

                // Create device context
                _DeviceContext = DeviceContext.Create();
                List <DevicePixelFormat> pixelFormats = _DeviceContext.PixelsFormats.Choose(new DevicePixelFormat(24));

                if (pixelFormats.Count == 0)
                {
                    throw new NotSupportedException("unable to find suitable pixel format");
                }
            } catch {
                // Release resources manually
                FixtureTearDown();
                throw;
            }
        }
コード例 #21
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);
                }
            }
        }
コード例 #22
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);
        }
コード例 #23
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);
                    }
                }
            }
        }
コード例 #24
0
ファイル: NativeWindow.cs プロジェクト: ipud2/OpenGL.Net-1
        /// <summary>
        /// Create the device context and set the pixel format.
        /// </summary>
        private void CreateDeviceContext(IntPtr displayHandle, IntPtr windowHandle, DevicePixelFormat controlReqFormat)
        {
            #region Support ES/SC API

            switch (_ProfileType)
            {
            case ProfileType.Embedded:
                DeviceContext.DefaultAPI = KhronosVersion.ApiGles2;
                break;

            case ProfileType.SecurityCritical2:
                DeviceContext.DefaultAPI = KhronosVersion.ApiGlsc2;
                break;
            }

            #endregion

            #region Create device context

            DeviceContext = DeviceContext.Create(displayHandle, windowHandle);
            DeviceContext.IncRef();

            #endregion

            #region Set pixel format

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

            if (matchingPixelFormats.Count == 0 && controlReqFormat.MultisampleBits > 0)
            {
                // Try to select the maximum multisample configuration
                int multisampleBits = 0;

                pixelFormats.ForEach(delegate(DevicePixelFormat item) { multisampleBits = Math.Max(multisampleBits, item.MultisampleBits); });

                controlReqFormat.MultisampleBits = multisampleBits;

                matchingPixelFormats = pixelFormats.Choose(controlReqFormat);
            }

            if (matchingPixelFormats.Count == 0 && controlReqFormat.DoubleBuffer)
            {
                // Try single buffered pixel formats
                controlReqFormat.DoubleBuffer = false;

                matchingPixelFormats = pixelFormats.Choose(controlReqFormat);
                if (matchingPixelFormats.Count == 0)
                {
                    throw new InvalidOperationException(
                              $"unable to find a suitable pixel format: {pixelFormats.GuessChooseError(controlReqFormat)}");
                }
            }
            else if (matchingPixelFormats.Count == 0)
            {
                throw new InvalidOperationException(
                          $"unable to find a suitable pixel format: {pixelFormats.GuessChooseError(controlReqFormat)}");
            }

            DeviceContext.SetPixelFormat(matchingPixelFormats[0]);

            #endregion

            #region Set V-Sync

            if (Gl.PlatformExtensions.SwapControl)
            {
                int swapInterval = SwapInterval;

                // Mask value in case it is not supported
                if (!Gl.PlatformExtensions.SwapControlTear && swapInterval == -1)
                {
                    swapInterval = 1;
                }

                DeviceContext.SwapInterval(swapInterval);
            }

            #endregion
        }
コード例 #25
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);
        }
コード例 #26
0
ファイル: GlWidget.cs プロジェクト: pingyuan162/OpenGL.Net
        /// <summary>
        /// Create the device context and set the pixel format.
        /// </summary>
        private void CreateDeviceContext(DevicePixelFormat controlReqFormat)
        {
            #region Create device context

            _DeviceContext = DeviceContext.Create(GetDisplay(), GetWindowHandle());
            _DeviceContext.IncRef();

            #endregion

            #region Set pixel format

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

            if ((matchingPixelFormats.Count == 0) && controlReqFormat.MultisampleBits > 0)
            {
                // Try to select the maximum multisample configuration
                int multisampleBits = 0;

                pixelFormats.ForEach(delegate(DevicePixelFormat item) { multisampleBits = Math.Max(multisampleBits, item.MultisampleBits); });

                controlReqFormat.MultisampleBits = multisampleBits;

                matchingPixelFormats = pixelFormats.Choose(controlReqFormat);
            }

            if ((matchingPixelFormats.Count == 0) && controlReqFormat.DoubleBuffer)
            {
                // Try single buffered pixel formats
                controlReqFormat.DoubleBuffer = false;

                matchingPixelFormats = pixelFormats.Choose(controlReqFormat);
                if (matchingPixelFormats.Count == 0)
                {
                    throw new InvalidOperationException(String.Format("unable to find a suitable pixel format: {0}", pixelFormats.GuessChooseError(controlReqFormat)));
                }
            }
            else if (matchingPixelFormats.Count == 0)
            {
                throw new InvalidOperationException(String.Format("unable to find a suitable pixel format: {0}", pixelFormats.GuessChooseError(controlReqFormat)));
            }

            _DeviceContext.SetPixelFormat(matchingPixelFormats[0]);

            #endregion

            #region Set V-Sync

            if (Gl.PlatformExtensions.SwapControl)
            {
                int swapInterval = SwapInterval;

                // Mask value in case it is not supported
                if (!Gl.PlatformExtensions.SwapControlTear && swapInterval == -1)
                {
                    swapInterval = 1;
                }

                _DeviceContext.SwapInterval(swapInterval);
            }

            #endregion
        }
コード例 #27
0
        public OpenGLDevice(Win32Window window)
        {
            DeviceContext.DefaultAPI = Khronos.KhronosVersion.ApiGl;

            InitializeCache();

            this.deviceContext = DeviceContext.Create(IntPtr.Zero, window.handle);
            this.deviceContext.IncRef();

            Debug.LogFormat("OpenGL API: {0}", this.deviceContext.CurrentAPI);

            List <DevicePixelFormat> pixelFormats = this.deviceContext.PixelsFormats.Choose(
                new DevicePixelFormat
            {
                RgbaUnsigned    = true,
                RenderWindow    = true,
                ColorBits       = 32,
                DepthBits       = 24,
                StencilBits     = 8,
                MultisampleBits = 0,
                DoubleBuffer    = false,
            }
                );

            this.deviceContext.SetPixelFormat(pixelFormats[0]);

            if (Gl.PlatformExtensions.SwapControl)
            {
                int swapInterval = 1;

                // Mask value in case it is not supported
                if (!Gl.PlatformExtensions.SwapControlTear && swapInterval == -1)
                {
                    swapInterval = 1;
                }

                this.deviceContext.SwapInterval(swapInterval);
            }

            if (this.glContext != IntPtr.Zero)
            {
                throw new InvalidOperationException("context already created");
            }

            if ((this.glContext = this.deviceContext.CreateContext(IntPtr.Zero)) == IntPtr.Zero)
            {
                throw new InvalidOperationException("unable to create render context");
            }

            this.MakeCurrent();
            Gl.ClearColor(0.192157f, 0.301961f, 0.474510f, 1.0f);
            Gl.DepthFunc(DepthFunction.Lequal);

            Gl.Light(LightName.Light0, LightParameter.Position, new float[] { 1.0f, 1.0f, 1.0f, 0.0f });
            Gl.Enable(EnableCap.Light0);

            Gl.Enable(EnableCap.Texture2d);
            Gl.Enable(EnableCap.TextureCoordArray);
            Gl.ShadeModel(ShadingModel.Smooth);
            Gl.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
        }
コード例 #28
0
ファイル: TestBase.cs プロジェクト: yaram/OpenGL.Net
 public void FixtureSetUp()
 {
     _DeviceContext = DeviceContext.Create();
     _Context       = new GraphicsContext(_DeviceContext);
 }