Exemplo 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>());
        }
Exemplo 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>());
        }
Exemplo n.º 3
0
 private IntPtr CreateTempOpenGLContext(ContextCreationParameters parameters)
 {
     var builder = new ContextBuilder(_wgl);
     return builder.BuildLegacyContext(parameters);
 }
Exemplo 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);
                }
            }
        }
Exemplo 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));
        }
Exemplo 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>());
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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>());
        }
Exemplo n.º 9
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>());
        }
Exemplo n.º 10
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>());
        }