public PixelFormatException ( string message, ContextCreationParameters parameters, PixelFormatDescriptor descriptor ) : base(message, parameters) { Descriptor = descriptor; }
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 static IWGL CreateMockWgl() { var wgl = Substitute.For<IWGL>(); var pfd = new PixelFormatDescriptor(); wglChoosePixelFormatARB ch = (hdc, list, fList, formats, piFormats, numFormats) => true; wglCreateContextAttribsARB createContext = (dc, context, list) => new IntPtr(1); wgl.ChoosePixelFormat(Arg.Any<IntPtr>(), ref pfd).ReturnsForAnyArgs(1); wgl.SetPixelFormat(Arg.Any<IntPtr>(), Arg.Any<int>(), ref pfd).ReturnsForAnyArgs(true); wgl.wglCreateContext(Arg.Any<IntPtr>()).Returns(new IntPtr(1)); wgl.wglMakeCurrent(Arg.Any<IntPtr>(), Arg.Any<IntPtr>()).Returns(true); wgl.wglGetProcAddress("wglChoosePixelFormatARB").Returns(Marshal.GetFunctionPointerForDelegate(ch)); wgl.wglGetProcAddress("wglCreateContextAttribsARB").Returns(Marshal.GetFunctionPointerForDelegate(createContext)); return wgl; }
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>()); }
public IntPtr BuildLegacyContext(ContextCreationParameters parameters) { if(parameters.Device == 0) throw new ContextCreationException("No device specified.", parameters); if(parameters.Window == 0) throw new ContextCreationException("No window specified.", parameters); var desc = new PixelFormatDescriptor { Version = 1, StencilBits = 8, DepthBits = 24, ColorBits = 32, PixelType = PixelType.Rgba, Size = (ushort)System.Runtime.InteropServices.Marshal.SizeOf(typeof(PixelFormatDescriptor)), Flags = PixelFormatFlags.DoubleBuffer | PixelFormatFlags.DrawToWindows | PixelFormatFlags.SupportOpenGL, }; int pixelFormat = _wgl.ChoosePixelFormat((IntPtr)parameters.Device, ref desc); if (pixelFormat == 0) throw new PixelFormatException("Could not select an appropriate pixel format.", parameters, desc); if (!_wgl.SetPixelFormat((IntPtr)parameters.Device, pixelFormat, ref desc)) throw new PixelFormatException("Could not set pixel format for HDC.", parameters, desc); var glptr = _wgl.wglCreateContext((IntPtr)parameters.Device); if (glptr == IntPtr.Zero) throw new ContextCreationException("Unable to create OpenGL context.", parameters); return glptr; }
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)); }