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>()); }
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>()); }
private IntPtr CreateTempOpenGLContext(ContextCreationParameters parameters) { var builder = new ContextBuilder(_wgl); return builder.BuildLegacyContext(parameters); }
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); } } }
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)); }
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>()); }