Esempio n. 1
0
        public override void Initialize()
        {
            if(_initialized)
                throw new InvalidOperationException("Context has already been initialized.");

            
            var builder = new ContextBuilder(_wgl);
            var tempContext = builder.BuildLegacyContext(_contextParameters);
            var finalContext = builder.BuildModernContext(_contextParameters, this, _sharedContext, tempContext);
            Handle = finalContext;
            _initialized = true;

            if (_contextParameters.SwapInterval != null)
            {
                using (Bind())
                {
                    SetSwapInterval((SwapInterval)_contextParameters.SwapInterval.Value);
                }
            }
        }
Esempio n. 2
0
        public void BuildModernContext_ValidArguments_ReturnsContextHandle()
        {
            // Arrange
            var wgl = Substitute.For<IWGL>();
            wgl.wglMakeCurrent(Arg.Any<IntPtr>(), Arg.Any<IntPtr>()).Returns(true);
            var lib = Substitute.For<ILibrary>();
            wglChoosePixelFormatARB choosePixelFormat = (hdc, list, fList, formats, piFormats, numFormats) => true;
            wglCreateContextAttribsARB createContextAttribs = (dc, context, list) => (IntPtr)1;
            lib.GetProcedure<wglChoosePixelFormatARB>("wglChoosePixelFormatARB").Returns(choosePixelFormat);
            lib.GetProcedure<wglCreateContextAttribsARB>("wglCreateContextAttribsARB").Returns(createContextAttribs);
            var builder = new ContextBuilder(wgl);

            // Act
            var result = builder.BuildModernContext(new ContextCreationParameters { Window = 1, Device = 1 }, lib, null, (IntPtr)1);

            // Assert
            Assert.That(result, Is.Not.EqualTo(IntPtr.Zero));
        }
Esempio n. 3
0
        public void BuildModernContext_CannotFindChoosePixelFormatARB_ThrowsMissingEntryPointException()
        {
            // Arrange
            var wgl = Substitute.For<IWGL>();
            wgl.wglMakeCurrent(Arg.Any<IntPtr>(), Arg.Any<IntPtr>()).Returns(true);
            var lib = Substitute.For<ILibrary>();
            lib.GetProcedure<wglChoosePixelFormatARB>("wglChoosePixelFormatARB").Returns((wglChoosePixelFormatARB)null);
            lib.GetProcedure<wglCreateContextAttribsARB>("wglCreateContextAttribsARB").Returns((wglCreateContextAttribsARB)null);
            var builder = new ContextBuilder(wgl);

            // Act
            TestDelegate build =
                () => builder.BuildModernContext(new ContextCreationParameters { Window = 1, Device = 1 }, lib, null, (IntPtr)1);

            // Assert
            Assert.That(build, Throws.TypeOf<MissingEntryPointException>());
        }
Esempio n. 4
0
        public void BuildModernContext_CreateContextAttribsReturnsNull_ThrowsContextCreationException()
        {
            // Arrange
            var wgl = Substitute.For<IWGL>();
            wgl.wglMakeCurrent(Arg.Any<IntPtr>(), Arg.Any<IntPtr>()).Returns(true);
            var lib = Substitute.For<ILibrary>();
            wglChoosePixelFormatARB choosePixelFormat = (hdc, list, fList, formats, piFormats, numFormats) => true;
            wglCreateContextAttribsARB createContextAttribs = (dc, context, list) => IntPtr.Zero;
            lib.GetProcedure<wglChoosePixelFormatARB>("wglChoosePixelFormatARB").Returns(choosePixelFormat);
            lib.GetProcedure<wglCreateContextAttribsARB>("wglCreateContextAttribsARB").Returns(createContextAttribs);
            var builder = new ContextBuilder(wgl);

            // Act
            TestDelegate build =
                () => builder.BuildModernContext(new ContextCreationParameters { Window = 1, Device = 1 }, lib, null, (IntPtr)1);

            // Assert
            Assert.That(build, Throws.TypeOf<ContextCreationException>());
        }
Esempio n. 5
0
        public void BuildModernContext_CannotBindLegacyContext_ThrowsContextCreationException()
        {
            // Arrange
            var wgl = Substitute.For<IWGL>();
            wgl.wglMakeCurrent(Arg.Any<IntPtr>(), Arg.Any<IntPtr>()).Returns(false);
            var lib = Substitute.For<ILibrary>();
            var builder = new ContextBuilder(wgl);

            // Act
            TestDelegate build =
                () => builder.BuildModernContext(new ContextCreationParameters {Window = 1, Device = 1}, lib, null, (IntPtr) 1);

            // Assert
            Assert.That(build, Throws.TypeOf<ContextCreationException>());
        }