Esempio n. 1
0
        public void BuildLegacyContext_NullWindow_Fails_WithContextCreationException()
        {
            // Arrange
            var wgl = Substitute.For<IWGL>();
            var createParameters = new ContextCreationParameters { Device = 1 };
            var contextBuilder = new ContextBuilder(wgl);

            // Act
            TestDelegate test = () => contextBuilder.BuildLegacyContext(createParameters);

            // Assert
            Assert.That(test, Throws.TypeOf<ContextCreationException>());
        }
Esempio n. 2
0
        public void BuildLegacyContext_CannotChoosePixelFormat_ThrowsPixelFormatException()
        {
            // Arrange
            var wgl = Substitute.For<IWGL>();
            var desc = new PixelFormatDescriptor();
            wgl.ChoosePixelFormat(Arg.Any<IntPtr>(), ref desc).ReturnsForAnyArgs(0);
            var builder = new ContextBuilder(wgl);

            // Act
            TestDelegate build = () => builder.BuildLegacyContext(new ContextCreationParameters {Window = 1, Device = 1});

            // Assert
            Assert.That(build, Throws.TypeOf<PixelFormatException>());
        }
Esempio n. 3
0
 private IntPtr CreateTempOpenGLContext(ContextCreationParameters parameters)
 {
     var builder = new ContextBuilder(_wgl);
     return builder.BuildLegacyContext(parameters);
 }
Esempio n. 4
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. 5
0
        public void BuildLegacyContext_ValidWindowAndHdc_ReturnsContextHandle()
        {
            // Arrange
            var wgl = Substitute.For<IWGL>();
            var desc = new PixelFormatDescriptor();
            wgl.ChoosePixelFormat(Arg.Any<IntPtr>(), ref desc).ReturnsForAnyArgs(1);
            wgl.SetPixelFormat(Arg.Any<IntPtr>(), Arg.Any<int>(), ref desc).ReturnsForAnyArgs(true);
            wgl.wglCreateContext(Arg.Any<IntPtr>()).Returns((IntPtr)1);
            var builder = new ContextBuilder(wgl);

            // Act
            var result = builder.BuildLegacyContext(new ContextCreationParameters { Window = 1, Device = 1 });

            // Assert
            Assert.That(result, Is.EqualTo((IntPtr)1));
        }
Esempio n. 6
0
        public void BuildLegacyContext_CreateContextReturnsNull_ThrowsContextCreationException()
        {
            // Arrange
            var wgl = Substitute.For<IWGL>();
            var desc = new PixelFormatDescriptor();
            wgl.ChoosePixelFormat(Arg.Any<IntPtr>(), ref desc).ReturnsForAnyArgs(1);
            wgl.SetPixelFormat(Arg.Any<IntPtr>(), Arg.Any<int>(), ref desc).ReturnsForAnyArgs(true);
            wgl.wglCreateContext(Arg.Any<IntPtr>()).Returns(IntPtr.Zero);
            var builder = new ContextBuilder(wgl);

            // Act
            TestDelegate build = () => builder.BuildLegacyContext(new ContextCreationParameters { Window = 1, Device = 1 });

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