public void Evaluate(int SpreadMax) { if (InputChanged() || FFirstRun) { FFirstRun = false; FPinOutOutput.SliceCount = SpreadMax; ColorFormat FColorFormat; ColorFormat FAccumulatorFormat; for (int i=0; i<SpreadMax; i++) { if (FPinInColorFormat[i] == null) FColorFormat = new ColorFormat(32); else FColorFormat = FPinInColorFormat[i]; if (FPinInAccumulatorFormat[i] == null) FAccumulatorFormat = new ColorFormat(0); else FAccumulatorFormat = FPinInAccumulatorFormat[i]; FPinOutOutput[i] = new GraphicsMode(FColorFormat, FPinInDepthBufferDepth[i], FPinInStencilBufferDepth[i], FPinInMSAA[i], FAccumulatorFormat, FPinInBuffers[i], FPinInStereo[i]); } } }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { IntPtr pixelformat; do { pixelformat = SelectPixelFormat( color, depth, stencil, samples, accum, buffers, stereo, true, Device); Agl.AglError err = Agl.GetError(); if (pixelformat == IntPtr.Zero || err == Agl.AglError.BadPixelFormat) { Debug.Print("Failed to create full screen pixel format."); Debug.Print("Trying again to create a non-fullscreen pixel format."); pixelformat = SelectPixelFormat( color, depth, stencil, samples, accum, buffers, stereo, false, IntPtr.Zero); } if (pixelformat == IntPtr.Zero) { if (!Utilities.RelaxGraphicsMode( ref color, ref depth, ref stencil, ref samples, ref accum, ref buffers, ref stereo)) { throw new GraphicsModeException("Requested GraphicsMode not available."); } } } while (pixelformat == IntPtr.Zero); return GetGraphicsModeFromPixelFormat(pixelformat); }
protected override void CreateFrameBuffer() { int requestedDepth = 0; int requestedStencil = 0; ColorFormat requestedColorFormat = 32; switch (RequestedBackBufferFormat) { case PixelFormat.R8G8B8A8_UNorm: case PixelFormat.B8G8R8A8_UNorm: requestedColorFormat = 32; break; case PixelFormat.B8G8R8X8_UNorm: requestedColorFormat = 24; break; case PixelFormat.B5G6R5_UNorm: requestedColorFormat = new ColorFormat(5, 6, 5, 0); break; case PixelFormat.B5G5R5A1_UNorm: requestedColorFormat = new ColorFormat(5, 5, 5, 1); break; default: throw new NotSupportedException("RequestedBackBufferFormat"); } switch (RequestedDepthStencilFormat) { case PixelFormat.None: break; case PixelFormat.D16_UNorm: requestedDepth = 16; break; case PixelFormat.D24_UNorm_S8_UInt: requestedDepth = 24; requestedStencil = 8; break; case PixelFormat.D32_Float: requestedDepth = 32; break; case PixelFormat.D32_Float_S8X24_UInt: requestedDepth = 32; requestedStencil = 8; break; default: throw new NotSupportedException("RequestedDepthStencilFormat"); } // Some devices only allow D16_S8, let's try it as well // D24 and D32 are supported on OpenGL ES 3 devices var requestedDepthFallback = requestedDepth > 16 ? 16 : requestedDepth; foreach (var version in OpenGLUtils.GetGLVersions(RequestedGraphicsProfile)) { if (TryCreateFrameBuffer(MajorVersionToGLVersion(version), requestedColorFormat, requestedDepth, requestedStencil) || TryCreateFrameBuffer(MajorVersionToGLVersion(version), requestedColorFormat, requestedDepthFallback, requestedStencil)) return; } throw new Exception("Unable to create a graphics context on the device. Maybe you should lower the preferred GraphicsProfile."); }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { GraphicsMode gfx; // The actual GraphicsMode that will be selected. IntPtr visual = IntPtr.Zero; IntPtr display = API.DefaultDisplay; do { // Try to select a visual using Glx.ChooseFBConfig and Glx.GetVisualFromFBConfig. // This is only supported on GLX 1.3 - if it fails, fall back to Glx.ChooseVisual. visual = SelectVisualUsingFBConfig(color, depth, stencil, samples, accum, buffers, stereo); if (visual == IntPtr.Zero) visual = SelectVisualUsingChooseVisual(color, depth, stencil, samples, accum, buffers, stereo); if (visual == IntPtr.Zero) { // Relax parameters and retry if (!Utilities.RelaxGraphicsMode(ref color, ref depth, ref stencil, ref samples, ref accum, ref buffers, ref stereo)) throw new GraphicsModeException("Requested GraphicsMode not available."); } } while (visual == IntPtr.Zero); XVisualInfo info = (XVisualInfo)Marshal.PtrToStructure(visual, typeof(XVisualInfo)); // See what we *really* got: int r, g, b, a; Glx.GetConfig(display, ref info, GLXAttribute.ALPHA_SIZE, out a); Glx.GetConfig(display, ref info, GLXAttribute.RED_SIZE, out r); Glx.GetConfig(display, ref info, GLXAttribute.GREEN_SIZE, out g); Glx.GetConfig(display, ref info, GLXAttribute.BLUE_SIZE, out b); int ar, ag, ab, aa; Glx.GetConfig(display, ref info, GLXAttribute.ACCUM_ALPHA_SIZE, out aa); Glx.GetConfig(display, ref info, GLXAttribute.ACCUM_RED_SIZE, out ar); Glx.GetConfig(display, ref info, GLXAttribute.ACCUM_GREEN_SIZE, out ag); Glx.GetConfig(display, ref info, GLXAttribute.ACCUM_BLUE_SIZE, out ab); Glx.GetConfig(display, ref info, GLXAttribute.DEPTH_SIZE, out depth); Glx.GetConfig(display, ref info, GLXAttribute.STENCIL_SIZE, out stencil); Glx.GetConfig(display, ref info, GLXAttribute.SAMPLES, out samples); Glx.GetConfig(display, ref info, GLXAttribute.DOUBLEBUFFER, out buffers); ++buffers; // the above lines returns 0 - false and 1 - true. int st; Glx.GetConfig(display, ref info, GLXAttribute.STEREO, out st); stereo = st != 0; gfx = new GraphicsMode(info.VisualID, new ColorFormat(r, g, b, a), depth, stencil, samples, new ColorFormat(ar, ag, ab, aa), buffers, stereo); using (new XLock(display)) { Functions.XFree(visual); } return gfx; }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { // According to the EGL specs, the ES flag should select ES 1.0 or higher, which // makes sense as a default. EglContext.cs checks return SelectGraphicsMode(color, depth, stencil, samples, accum, buffers, stereo, RenderableFlags.ES); }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { IntPtr pixelformat = SelectPixelFormat( color, depth, stencil, samples, accum, buffers, stereo, false, IntPtr.Zero); return GetGraphicsModeFromPixelFormat(pixelformat); }
public GraphicsMode SelectGraphicsMode (ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { //TODO: Implement // Actually, you know what, never mind. This will all work magically on anything from the last // decade anyway. return new GraphicsMode(IntPtr.Zero,color,depth,stencil,samples,accum,buffers,stereo); }
private IntPtr SelectPixelFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { List<int> list = new List<int>(); if (color.BitsPerPixel > 0) { if (!color.IsIndexed) list.Add(4); list.Add(8); list.Add(color.Red); list.Add(9); list.Add(color.Green); list.Add(10); list.Add(color.Blue); list.Add(11); list.Add(color.Alpha); } if (depth > 0) { list.Add(12); list.Add(depth); } if (buffers > 1) list.Add(5); if (stencil > 1) { list.Add(13); list.Add(stencil); } if (accum.BitsPerPixel > 0) { list.Add(17); list.Add(accum.Alpha); list.Add(16); list.Add(accum.Blue); list.Add(15); list.Add(accum.Green); list.Add(14); list.Add(accum.Red); } if (samples > 0) { list.Add(55); list.Add(1); list.Add(56); list.Add(samples); } if (stereo) list.Add(6); list.Add(0); list.Add(0); IntPtr num = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, list.ToArray()); if (num == IntPtr.Zero) throw new GraphicsModeException(string.Format("[Error] Failed to select GraphicsMode, error {0}.", (object) Agl.GetError())); else return num; }
GraphicsMode SelectGraphicsModePFD(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo) { using (Control native_window = new Control()) using (WinWindowInfo window = new WinWindowInfo(native_window.Handle, null)) { IntPtr deviceContext = ((WinWindowInfo)window).DeviceContext; Debug.WriteLine(String.Format("Device context: {0}", deviceContext)); Debug.Write("Selecting pixel format... "); PixelFormatDescriptor pixelFormat = new PixelFormatDescriptor(); pixelFormat.Size = API.PixelFormatDescriptorSize; pixelFormat.Version = API.PixelFormatDescriptorVersion; pixelFormat.Flags = PixelFormatDescriptorFlags.SUPPORT_OPENGL | PixelFormatDescriptorFlags.DRAW_TO_WINDOW; pixelFormat.ColorBits = (byte)(color.Red + color.Green + color.Blue); pixelFormat.PixelType = color.IsIndexed ? PixelType.INDEXED : PixelType.RGBA; pixelFormat.RedBits = (byte)color.Red; pixelFormat.GreenBits = (byte)color.Green; pixelFormat.BlueBits = (byte)color.Blue; pixelFormat.AlphaBits = (byte)color.Alpha; if (accum.BitsPerPixel > 0) { pixelFormat.AccumBits = (byte)(accum.Red + accum.Green + accum.Blue); pixelFormat.AccumRedBits = (byte)accum.Red; pixelFormat.AccumGreenBits = (byte)accum.Green; pixelFormat.AccumBlueBits = (byte)accum.Blue; pixelFormat.AccumAlphaBits = (byte)accum.Alpha; } pixelFormat.DepthBits = (byte)depth; pixelFormat.StencilBits = (byte)stencil; if (depth <= 0) pixelFormat.Flags |= PixelFormatDescriptorFlags.DEPTH_DONTCARE; if (stereo) pixelFormat.Flags |= PixelFormatDescriptorFlags.STEREO; if (buffers > 1) pixelFormat.Flags |= PixelFormatDescriptorFlags.DOUBLEBUFFER; int pixel = Functions.ChoosePixelFormat(deviceContext, ref pixelFormat); if (pixel == 0) throw new GraphicsModeException("The requested GraphicsMode is not available."); // Find out what we really got as a format: PixelFormatDescriptor pfd = new PixelFormatDescriptor(); pixelFormat.Size = API.PixelFormatDescriptorSize; pixelFormat.Version = API.PixelFormatDescriptorVersion; Functions.DescribePixelFormat(deviceContext, pixel, API.PixelFormatDescriptorSize, ref pfd); GraphicsMode fmt = new GraphicsMode((IntPtr)pixel, new ColorDepth(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits), pfd.DepthBits, pfd.StencilBits, 0, new ColorDepth(pfd.AccumBits), (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1, (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0); return fmt; } }
public GraphicsMode SelectGraphicsMode( ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { IntPtr[] configs = new IntPtr[1]; int[] attribList = new int[] { //Egl.SURFACE_TYPE, Egl.WINDOW_BIT, Egl.RED_SIZE, color.Red, Egl.GREEN_SIZE, color.Green, Egl.BLUE_SIZE, color.Blue, Egl.ALPHA_SIZE, color.Alpha, Egl.DEPTH_SIZE, depth > 0 ? depth : 0, Egl.STENCIL_SIZE, stencil > 0 ? stencil : 0, //Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0, Egl.SAMPLES, samples > 0 ? samples : 0, //------------ Egl.NONE, }; IntPtr display = window.Display; int num_configs; if (!Egl.GetConfigs(display, null, 0, out num_configs)) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode configurations, error {0}", Egl.GetError())); } if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs)) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError())); } // See what we really got IntPtr active_config = configs[0]; int r, g, b, a; Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r); Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g); Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b); Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a); int d, s; Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d); Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s); int sample_buffers; Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers); Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples); return new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false); }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { EGLConfig[] configs = new EGLConfig[1]; int[] attribList = new int[] { //Egl.SURFACE_TYPE, Egl.WINDOW_BIT, Egl.RED_SIZE, color.Red, Egl.GREEN_SIZE, color.Green, Egl.BLUE_SIZE, color.Blue, Egl.ALPHA_SIZE, color.Alpha, Egl.DEPTH_SIZE, depth > 0 ? depth : 0, Egl.STENCIL_SIZE, stencil > 0 ? stencil : 0, //Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0, Egl.SAMPLES, samples > 0 ? samples : 0, Egl.NONE, }; // Todo: what if we don't wish to use the default display? EGLDisplay display = Egl.GetDisplay(EGLNativeDisplayType.Default); int major, minor; if (!Egl.Initialize(display, out major, out minor)) throw new GraphicsModeException(String.Format("Failed to initialize display connection, error {0}", Egl.GetError())); int num_configs; if (!Egl.GetConfigs(display, null, 0, out num_configs)) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode configurations, error {0}", Egl.GetError())); } if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs)) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError())); } // See what we really got EGLConfig active_config = configs[0]; int r, g, b, a; Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r); Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g); Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b); Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a); int d, s; Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d); Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s); int sample_buffers; Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers); Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples); return new GraphicsMode(active_config.Handle.Value, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false); }
private IntPtr SelectVisualUsingChooseVisual(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { List<int> list = new List<int>(); if (color.BitsPerPixel > 0) { if (!color.IsIndexed) list.Add(4); list.Add(8); list.Add(color.Red); list.Add(9); list.Add(color.Green); list.Add(10); list.Add(color.Blue); list.Add(11); list.Add(color.Alpha); } if (depth > 0) { list.Add(12); list.Add(depth); } if (buffers > 1) list.Add(5); if (stencil > 1) { list.Add(13); list.Add(stencil); } if (accum.BitsPerPixel > 0) { list.Add(17); list.Add(accum.Alpha); list.Add(16); list.Add(accum.Blue); list.Add(15); list.Add(accum.Green); list.Add(14); list.Add(accum.Red); } if (samples > 0) { list.Add(100000); list.Add(1); list.Add(100001); list.Add(samples); } if (stereo) list.Add(6); list.Add(0); IntPtr defaultDisplay = API.DefaultDisplay; using (new XLock(defaultDisplay)) return Glx.ChooseVisual(defaultDisplay, Functions.XDefaultScreen(defaultDisplay), list.ToArray()); }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { GraphicsMode graphicsMode; do { graphicsMode = this.modes.Find((Predicate<GraphicsMode>) (current => this.ModeSelector(current, color, depth, stencil, samples, accum, buffers, stereo))); } while (graphicsMode == null && this.RelaxParameters(ref color, ref depth, ref stencil, ref samples, ref accum, ref buffers, ref stereo)); if (graphicsMode == null) graphicsMode = this.modes[0]; return graphicsMode; }
public void Evaluate(int SpreadMax) { if (FPinInBPP.IsChanged || FFirstRun) { FFirstRun = false; FPinOutOutput.SliceCount = SpreadMax; for (int i=0; i<SpreadMax; i++) { FPinOutOutput[i] = new ColorFormat(FPinInBPP[i]); } } }
public void Evaluate(int SpreadMax) { if (FPinInRed.IsChanged || FPinInGreen.IsChanged || FPinInBlue.IsChanged || FPinInAlpha.IsChanged || FFirstRun) { FFirstRun = false; FPinOutOutput.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { FPinOutOutput[i] = new ColorFormat(FPinInRed[i], FPinInGreen[i], FPinInBlue[i], FPinInAlpha[i]); } } }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, RenderableFlags renderable_flags) { IntPtr[] configs = new IntPtr[1]; int[] attrib_list = new int[17] { 12352, (int) renderable_flags, 12324, color.Red, 12323, color.Green, 12322, color.Blue, 12321, color.Alpha, 12325, depth > 0 ? depth : 0, 12326, stencil > 0 ? stencil : 0, 12337, samples > 0 ? samples : 0, 12344 }; IntPtr display = Egl.GetDisplay(IntPtr.Zero); int major; int minor; if (!Egl.Initialize(display, out major, out minor)) throw new GraphicsModeException(string.Format("Failed to initialize display connection, error {0}", (object) Egl.GetError())); int num_config; if (!Egl.ChooseConfig(display, attrib_list, configs, configs.Length, out num_config) || num_config == 0) throw new GraphicsModeException(string.Format("Failed to retrieve GraphicsMode, error {0}", (object) Egl.GetError())); IntPtr config = configs[0]; int red; Egl.GetConfigAttrib(display, config, 12324, out red); int green; Egl.GetConfigAttrib(display, config, 12323, out green); int blue; Egl.GetConfigAttrib(display, config, 12322, out blue); int alpha; Egl.GetConfigAttrib(display, config, 12321, out alpha); int depth1; Egl.GetConfigAttrib(display, config, 12325, out depth1); int stencil1; Egl.GetConfigAttrib(display, config, 12326, out stencil1); int num; Egl.GetConfigAttrib(display, config, 12337, out num); Egl.GetConfigAttrib(display, config, 12337, out samples); return new GraphicsMode(new IntPtr?(config), new ColorFormat(red, green, blue, alpha), depth1, stencil1, num > 0 ? samples : 0, (ColorFormat) 0, 2, false); }
internal GraphicsMode(IntPtr? index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { if (depth < 0) throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero."); if (stencil < 0) throw new ArgumentOutOfRangeException("stencil", "Must be greater than, or equal to zero."); if (buffers <= 0) throw new ArgumentOutOfRangeException("buffers", "Must be greater than zero."); if (samples < 0) throw new ArgumentOutOfRangeException("samples", "Must be greater than, or equal to zero."); this.Index = index; this.ColorFormat = color; this.Depth = depth; this.Stencil = stencil; this.Samples = samples; this.AccumulatorFormat = accum; this.Buffers = buffers; this.Stereo = stereo; }
bool RelaxParameters(ref ColorFormat color, ref int depth, ref int stencil, ref int samples, ref ColorFormat accum, ref int buffers, ref bool stereo) { if (stereo) { stereo = false; return true; } if (buffers != 2) { buffers = 2; return true; } if (accum != 0) { accum = 0; return true; } if (samples != 0) { samples = 0; return true; } if (depth < 16) { depth = 16; return true; } if (depth != 24) { depth = 24; return true; } if (stencil > 0 && stencil != 8) { stencil = 8; return true; } if (stencil == 8) { stencil = 0; return true; } if (color < 8) { color = 8; return true; } if (color < 16) { color = 16; return true; } if (color < 24) { color = 24; return true; } if (color < 32 || color > 32) { color = 32; return true; } return false; // We tried everything we could, no match found. }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { GraphicsMode mode = null; do { mode = modes.Find(delegate(GraphicsMode current) { return ModeSelector(current, color, depth, stencil, samples, accum, buffers, stereo); }); } while (mode == null && RelaxParameters( ref color, ref depth, ref stencil, ref samples, ref accum, ref buffers, ref stereo)); if (mode == null) mode = modes[0]; return mode; }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { GraphicsMode mode = new GraphicsMode(color, depth, stencil, samples,accum, buffers, stereo); GraphicsMode created_mode = ChoosePixelFormatARB(Device, mode); // If ChoosePixelFormatARB failed, iterate through all acceleration types in turn (ICD, MCD, None) // This should fix issue #2224, which causes OpenTK to fail on VMs without hardware acceleration. created_mode = created_mode ?? ChoosePixelFormatPFD(Device, mode, AccelerationType.ICD); created_mode = created_mode ?? ChoosePixelFormatPFD(Device, mode, AccelerationType.MCD); created_mode = created_mode ?? ChoosePixelFormatPFD(Device, mode, AccelerationType.None); if (created_mode == null) { throw new GraphicsModeException("The requested GraphicsMode is not supported"); } return created_mode; }
protected override void CreateFrameBuffer() { int requestedStencil = 0; ColorFormat requestedColorFormat = 32; switch (RequestedBackBufferFormat) { case PixelFormat.R8G8B8A8_UNorm: case PixelFormat.B8G8R8A8_UNorm: requestedColorFormat = 32; break; case PixelFormat.B8G8R8X8_UNorm: requestedColorFormat = 24; break; case PixelFormat.B5G6R5_UNorm: requestedColorFormat = new ColorFormat(5, 6, 5, 0); break; case PixelFormat.B5G5R5A1_UNorm: requestedColorFormat = new ColorFormat(5, 5, 5, 1); break; default: throw new NotSupportedException("RequestedBackBufferFormat"); } // Query first the maximum supported profile, as some devices are crashing if we try to instantiate a 3.0 on a device supporting only 2.0 var maximumVersion = GetMaximumSupportedProfile(); foreach (var profile in RequestedGraphicsProfile) { var version = OpenGLUtils.GetGLVersion(profile); if (version > maximumVersion) { continue; } ContextRenderingApi = version; GraphicsMode = new GraphicsMode(requestedColorFormat, 0, requestedStencil); base.CreateFrameBuffer(); return; } throw new Exception("Unable to create a graphics context on the device. Maybe you should lower the preferred GraphicsProfile."); }
public GraphicsMode SelectGraphicsMode(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo) { GraphicsMode mode = null; if (!creating) { try { creating = true; mode = SelectGraphicsModeARB(color, depth, stencil, samples, accum, buffers, stereo); } finally { creating = false; } } if (mode == null) mode = SelectGraphicsModePFD(color, depth, stencil, samples, accum, buffers, stereo); return mode; }
public static void Main() { Application.EnableVisualStyles(); modProgram.PlatformPathSeparator = System.IO.Path.DirectorySeparatorChar; modProgram.SetProgramSubDirs(); modSettings.CreateSettingOptions(); modControls.CreateControls(); clsResult resultToAdd = modSettings.Settings_Load(ref modSettings.InitializeSettings); InitializeResult.Add(resultToAdd); ColorFormat color = new ColorFormat(modSettings.InitializeSettings.MapViewBPP); OpenGL1 = new GLControl(new GraphicsMode(color, modSettings.InitializeSettings.MapViewDepth, 0)); color = new ColorFormat(modSettings.InitializeSettings.TextureViewBPP); OpenGL2 = new GLControl(new GraphicsMode(color, modSettings.InitializeSettings.TextureViewDepth, 0)); while ((OpenGL1.Context == null) | (OpenGL2.Context == null)) { } frmMainInstance = new frmMain(); try { modProgram.ProgramIcon = new Icon(MyProject.Application.Info.DirectoryPath + Conversions.ToString(modProgram.PlatformPathSeparator) + "flaME.ico"); } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; InitializeResult.WarningAdd("FlaME icon is missing: " + exception.Message); ProjectData.ClearProjectError(); } frmMainInstance.Icon = modProgram.ProgramIcon; frmGeneratorInstance.Icon = modProgram.ProgramIcon; InitializeDelay = new System.Windows.Forms.Timer(); InitializeDelay.Tick += new EventHandler(frmMainInstance.Initialize); InitializeDelay.Interval = 50; InitializeDelay.Enabled = true; while (!modProgram.ProgramInitializeFinished) { Thread.Sleep(50); Application.DoEvents(); } Application.Run(frmMainInstance); }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { IntPtr num1 = IntPtr.Zero; IntPtr defaultDisplay = API.DefaultDisplay; IntPtr num2 = this.SelectVisualUsingFBConfig(color, depth, stencil, samples, accum, buffers, stereo); if (num2 == IntPtr.Zero) num2 = this.SelectVisualUsingChooseVisual(color, depth, stencil, samples, accum, buffers, stereo); if (num2 == IntPtr.Zero) throw new GraphicsModeException("Requested GraphicsMode not available."); XVisualInfo vis = (XVisualInfo) Marshal.PtrToStructure(num2, typeof (XVisualInfo)); int alpha1; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.ALPHA_SIZE, out alpha1); int red1; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.RED_SIZE, out red1); int green1; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.GREEN_SIZE, out green1); int blue1; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.BLUE_SIZE, out blue1); int alpha2; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.ACCUM_ALPHA_SIZE, out alpha2); int red2; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.ACCUM_RED_SIZE, out red2); int green2; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.ACCUM_GREEN_SIZE, out green2); int blue2; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.ACCUM_BLUE_SIZE, out blue2); Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.DEPTH_SIZE, out depth); Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.STENCIL_SIZE, out stencil); Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.SAMPLES, out samples); Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.DOUBLEBUFFER, out buffers); ++buffers; int num3; Glx.GetConfig(defaultDisplay, ref vis, GLXAttribute.STEREO, out num3); stereo = num3 != 0; GraphicsMode graphicsMode = new GraphicsMode(new IntPtr?(vis.VisualID), new ColorFormat(red1, green1, blue1, alpha1), depth, stencil, samples, new ColorFormat(red2, green2, blue2, alpha2), buffers, stereo); using (new XLock(defaultDisplay)) Functions.XFree(num2); return graphicsMode; }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, out IntPtr pixelformat) { do { pixelformat = SelectPixelFormat( color, depth, stencil, samples, accum, buffers, stereo); if (pixelformat == IntPtr.Zero) { if (!RelaxGraphicsMode( ref color, ref depth, ref stencil, ref samples, ref accum, ref buffers, ref stereo)) { throw new GraphicsModeException("Requested GraphicsMode not available, error: " + Agl.GetError()); } } } while (pixelformat == IntPtr.Zero); return GetGraphicsModeFromPixelFormat(pixelformat); }
public GraphicsMode SelectGraphicsMode(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo) { GraphicsMode mode = null; if (!creating) { try { creating = true; mode = SelectGraphicsModeARB(color, depth, stencil, samples, accum, buffers, stereo); } finally { creating = false; } } if (mode == null) { mode = SelectGraphicsModePFD(color, depth, stencil, samples, accum, buffers, stereo); } return(mode); }
/// <summary> /// Creates an AndroidGraphicsMode instance with the required settings. /// Passing null to the display parameter for lazy initialization is recommended. /// </summary> /// <param name="display"> /// A <see cref="T:Javax.Microedition.Khronos.Egl.EGLDisplay" /> with the display to use for creating the /// <see cref="T:Javax.Microedition.Khronos.Egl.EGLConfig" /> that represents this graphics configuration in /// the OpenGL space. Pass null for lazy initialization. /// </param> /// <param name="version">Requested OpenGL version (1 or 2)</param> /// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="depth">The number of bits in the depth buffer.</param> /// <param name="stencil">The number of bits in the stencil buffer.</param> /// <param name="samples">The number of samples for FSAA.</param> /// <param name="stereo">Set to true for a GraphicsMode with stereographic capabilities.</param> /// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param> public AndroidGraphicsMode (EGLDisplay display, int version, ColorFormat color, int depth, int stencil, int samples, int buffers, bool stereo) { this.ColorFormat = color; this.Depth = depth; this.Stencil = stencil; this.Samples = samples; this.AccumulatorFormat = color; this.Buffers = buffers; this.Stereo = stereo; this.Version = version; }
/// <summary> /// Creates an AndroidGraphicsMode instance with the defined settings. /// Defaults to EGL 1.x. To use EGL 2.0, call the /// <see cref="M:OpenTK.Platform.Android.AndroidGraphicsMode(Javax.Microedition.Khronos.Egl.EGLDisplay,int,OpenTK.Graphics.GraphicsMode)" /> /// or /// <see cref="M:OpenTK.Platform.Android.AndroidGraphicsMode(Javax.Microedition.Khronos.Egl.EGLDisplay,int,OpenTK.Graphics.ColorFormat,int,int,int,int,bool)" /> /// constructors (pass null to the display parameter for lazy initialization) /// </summary> public AndroidGraphicsMode (ColorFormat color, int depth, int stencil, int samples, int buffers, bool stereo) : this (null, 1, color, depth, stencil, samples, buffers, stereo) { }
public GraphicsMode SelectGraphicsMode (ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { return new AndroidGraphicsMode (color, depth, stencil, samples, buffers, stereo); }
GraphicsMode SelectGraphicsModePFD(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo) { using (Control native_window = new Control()) using (WinWindowInfo window = new WinWindowInfo(native_window.Handle, null)) { IntPtr deviceContext = ((WinWindowInfo)window).DeviceContext; Debug.WriteLine(String.Format("Device context: {0}", deviceContext)); Debug.Write("Selecting pixel format... "); PixelFormatDescriptor pixelFormat = new PixelFormatDescriptor(); pixelFormat.Size = API.PixelFormatDescriptorSize; pixelFormat.Version = API.PixelFormatDescriptorVersion; pixelFormat.Flags = PixelFormatDescriptorFlags.SUPPORT_OPENGL | PixelFormatDescriptorFlags.DRAW_TO_WINDOW; pixelFormat.ColorBits = (byte)(color.Red + color.Green + color.Blue); pixelFormat.PixelType = color.IsIndexed ? PixelType.INDEXED : PixelType.RGBA; pixelFormat.RedBits = (byte)color.Red; pixelFormat.GreenBits = (byte)color.Green; pixelFormat.BlueBits = (byte)color.Blue; pixelFormat.AlphaBits = (byte)color.Alpha; if (accum.BitsPerPixel > 0) { pixelFormat.AccumBits = (byte)(accum.Red + accum.Green + accum.Blue); pixelFormat.AccumRedBits = (byte)accum.Red; pixelFormat.AccumGreenBits = (byte)accum.Green; pixelFormat.AccumBlueBits = (byte)accum.Blue; pixelFormat.AccumAlphaBits = (byte)accum.Alpha; } pixelFormat.DepthBits = (byte)depth; pixelFormat.StencilBits = (byte)stencil; if (depth <= 0) { pixelFormat.Flags |= PixelFormatDescriptorFlags.DEPTH_DONTCARE; } if (stereo) { pixelFormat.Flags |= PixelFormatDescriptorFlags.STEREO; } if (buffers > 1) { pixelFormat.Flags |= PixelFormatDescriptorFlags.DOUBLEBUFFER; } int pixel = Functions.ChoosePixelFormat(deviceContext, ref pixelFormat); if (pixel == 0) { throw new GraphicsModeException("The requested GraphicsMode is not available."); } // Find out what we really got as a format: PixelFormatDescriptor pfd = new PixelFormatDescriptor(); pixelFormat.Size = API.PixelFormatDescriptorSize; pixelFormat.Version = API.PixelFormatDescriptorVersion; Functions.DescribePixelFormat(deviceContext, pixel, API.PixelFormatDescriptorSize, ref pfd); GraphicsMode fmt = new GraphicsMode((IntPtr)pixel, new ColorDepth(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits), pfd.DepthBits, pfd.StencilBits, 0, new ColorDepth(pfd.AccumBits), (pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1, (pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0); return(fmt); } }
GraphicsMode SelectGraphicsModeARB(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo) { using (INativeWindow native_window = new NativeWindow()) using (IGraphicsContext context = new GraphicsContext(new GraphicsMode(new ColorFormat(), 0, 0, 0, new ColorFormat(), 2, false), native_window.WindowInfo, 1, 0, GraphicsContextFlags.Default)) { WinWindowInfo window = (WinWindowInfo)native_window.WindowInfo; Debug.Write("Selecting pixel format (ARB)... "); if (Wgl.Delegates.wglChoosePixelFormatARB == null || Wgl.Delegates.wglGetPixelFormatAttribivARB == null) { Debug.WriteLine("failed"); return(null); } int[] attribs = new int[] { (int)WGL_ARB_pixel_format.AccelerationArb, (int)WGL_ARB_pixel_format.AlphaBitsArb, (int)WGL_ARB_pixel_format.RedBitsArb, (int)WGL_ARB_pixel_format.GreenBitsArb, (int)WGL_ARB_pixel_format.BlueBitsArb, (int)WGL_ARB_pixel_format.ColorBitsArb, (int)WGL_ARB_pixel_format.DepthBitsArb, (int)WGL_ARB_pixel_format.StencilBitsArb, (int)WGL_ARB_multisample.SampleBuffersArb, (int)WGL_ARB_multisample.SamplesArb, (int)WGL_ARB_pixel_format.AccumAlphaBitsArb, (int)WGL_ARB_pixel_format.AccumRedBitsArb, (int)WGL_ARB_pixel_format.AccumGreenBitsArb, (int)WGL_ARB_pixel_format.AccumBlueBitsArb, (int)WGL_ARB_pixel_format.AccumBitsArb, (int)WGL_ARB_pixel_format.DoubleBufferArb, (int)WGL_ARB_pixel_format.StereoArb, 0 }; int[] values = new int[attribs.Length]; int[] attribs_values = new int[] { (int)WGL_ARB_pixel_format.AccelerationArb, (int)WGL_ARB_pixel_format.FullAccelerationArb, (int)WGL_ARB_pixel_format.RedBitsArb, color.Red, (int)WGL_ARB_pixel_format.GreenBitsArb, color.Green, (int)WGL_ARB_pixel_format.BlueBitsArb, color.Blue, (int)WGL_ARB_pixel_format.AlphaBitsArb, color.Alpha, (int)WGL_ARB_pixel_format.ColorBitsArb, color.BitsPerPixel, (int)WGL_ARB_pixel_format.DepthBitsArb, depth, (int)WGL_ARB_pixel_format.StencilBitsArb, stencil, (int)WGL_ARB_multisample.SampleBuffersArb, samples > 0 ? 1 : 0, (int)WGL_ARB_multisample.SamplesArb, samples, (int)WGL_ARB_pixel_format.AccumRedBitsArb, accum.Red, (int)WGL_ARB_pixel_format.AccumGreenBitsArb, accum.Green, (int)WGL_ARB_pixel_format.AccumBlueBitsArb, accum.Blue, (int)WGL_ARB_pixel_format.AccumAlphaBitsArb, accum.Alpha, (int)WGL_ARB_pixel_format.AccumBitsArb, accum.BitsPerPixel, (int)WGL_ARB_pixel_format.DoubleBufferArb, 1, (int)WGL_ARB_pixel_format.StereoArb, stereo ? 1 : 0, 0, 0 }; int[] pixel = new int[1], num_formats = new int[1]; Wgl.Arb.ChoosePixelFormat(window.DeviceContext, attribs_values, null, 1, pixel, num_formats); if (num_formats[0] == 0 || pixel[0] == 0) { // Try again without an accumulator. Many modern cards cannot accelerate multisampled formats with accumulator buffers. attribs_values[10 * 2 + 1] = attribs_values[11 * 2 + 1] = attribs_values[12 * 2 + 1] = attribs_values[13 * 2 + 1] = attribs_values[14 * 2 + 1] = 0; Wgl.Arb.ChoosePixelFormat(window.DeviceContext, attribs_values, null, 1, pixel, num_formats); } if (num_formats[0] == 0 || pixel[0] == 0) { Debug.WriteLine("failed"); return(null); } // Find out what we really got as a format: Wgl.Arb.GetPixelFormatAttrib(window.DeviceContext, pixel[0], 0, attribs.Length, attribs, values); GraphicsMode mode = new GraphicsMode(new IntPtr(pixel[0]), new ColorDepth(values[1], values[2], values[3], values[4]), values[6], values[7], values[8] != 0 ? values[9] : 0, new ColorDepth(values[10], values[11], values[12], values[13]), values[15] == 1 ? 2 : 1, values[16] == 1 ? true : false); Debug.WriteLine("success!"); return(mode); } }
internal IntPtr SelectPixelFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, bool fullscreen, IntPtr device) { List<int> attribs = new List<int>(); Debug.Print("Bits per pixel: {0}", color.BitsPerPixel); if (color.BitsPerPixel > 0) { if (!color.IsIndexed) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_RGBA); } attribs.Add((int)Agl.PixelFormatAttribute.AGL_RED_SIZE); attribs.Add(color.Red); attribs.Add((int)Agl.PixelFormatAttribute.AGL_GREEN_SIZE); attribs.Add(color.Green); attribs.Add((int)Agl.PixelFormatAttribute.AGL_BLUE_SIZE); attribs.Add(color.Blue); attribs.Add((int)Agl.PixelFormatAttribute.AGL_ALPHA_SIZE); attribs.Add(color.Alpha); } Debug.Print("Depth: {0}", depth); if (depth > 0) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_DEPTH_SIZE); attribs.Add(depth); } if (buffers > 1) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER); } if (stencil > 1) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_STENCIL_SIZE); attribs.Add(stencil); } if (accum.BitsPerPixel > 0) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE); attribs.Add(accum.Alpha); attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE); attribs.Add(accum.Blue); attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE); attribs.Add(accum.Green); attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE); attribs.Add(accum.Red); } if (samples > 0) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB); attribs.Add(1); attribs.Add((int)Agl.PixelFormatAttribute.AGL_SAMPLES_ARB); attribs.Add(samples); } if (stereo) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_STEREO); } if (fullscreen) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_FULLSCREEN); } attribs.Add(0); attribs.Add(0); IntPtr pixelformat = IntPtr.Zero; if (device != IntPtr.Zero) { pixelformat = Agl.aglChoosePixelFormat(ref device, 0, attribs.ToArray()); } else { pixelformat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray()); } return pixelformat; }
public GraphicsMode(ColorFormat color, int depth) : this(color, depth, GraphicsMode.Default.Stencil, GraphicsMode.Default.Samples, GraphicsMode.Default.AccumulatorFormat, GraphicsMode.Default.Buffers, GraphicsMode.Default.Stereo) { }
/// <summary> /// Create Graphcis Context /// </summary> /// <returns></returns> public bool CreateGraphicsContext() { // If this looks uninitialized... initialize. if (ColorBPP == 0) { ColorBPP = 32; if (DepthBPP == 0) DepthBPP = 16; } ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP); ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP); int buffers = 2; if (SingleBuffer) buffers--; GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo); #if MAC IntPtr windowHandle = gdk_quartz_window_get_nswindow(GdkWindow.Handle); // Problem: gdk_window_ensure_native() crashes when used more than once. // For now, just create a NSView in place and use that instead. // Needs some care updating when resizing, hiding, etc, but seems to work. // (I'd guess this is pretty much what gdk_window_ensure_native() does internally.) var customView = NativeClass.AllocateClass("CustomNSView" + uniqueId++, "NSView"); NativeClass.RegisterClass(customView); nsView = SendIntPtr(SendIntPtr(customView, sel_registerName("alloc")), sel_registerName("initWithFrame:"), new RectangleF(0, 0, 400, 400)); bool native = gdk_window_ensure_native(GdkWindow.Handle); if (!native) { throw new PlatformNotSupportedException("Could not create native view."); } nsView = gdk_quartz_window_get_nsview(GdkWindow.Handle); windowInfo = OpenTK.Platform.Utilities.CreateMacOSWindowInfo(windowHandle, nsView); UpdateNSView(); #elif LINUX IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle); int screen = Screen.Number; IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle); IntPtr rootWindow = gdk_x11_drawable_get_xid(RootWindow.Handle); IntPtr visualInfo; if (graphicsMode.Index.HasValue) { XVisualInfo info = new XVisualInfo(); info.VisualID = graphicsMode.Index.Value; int dummy; visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy); } else { visualInfo = GetVisualInfo(display); } windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo); XFree(visualInfo); #endif // GraphicsContext graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags); graphicsContext.MakeCurrent(windowInfo); if (GraphicsContext.ShareContexts) { Interlocked.Increment(ref graphicsContextCount); if (!sharedContextInitialized) { sharedContextInitialized = true; ((IGraphicsContextInternal)graphicsContext).LoadAll(); OnGraphicsContextInitialized(); } } else { ((IGraphicsContextInternal)graphicsContext).LoadAll(); OnGraphicsContextInitialized(); } this.OnInitialized(this, null); this.timerId = GLib.Timeout.Add(16, new GLib.TimeoutHandler(this.Render)); return false; }
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <param name="color">The ColorFormat of the color buffer.</param> public GraphicsMode(ColorFormat color) : this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo) { }
public GraphicsMode(IntPtr?index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { if (depth < 0) { throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero."); } if (stencil < 0) { throw new ArgumentOutOfRangeException("stencil", "Must be greater than, or equal to zero."); } if (buffers <= 0) { throw new ArgumentOutOfRangeException("buffers", "Must be greater than zero."); } if (samples < 0) { throw new ArgumentOutOfRangeException("samples", "Must be greater than, or equal to zero."); } this.Index = index; this.ColorFormat = color; this.Depth = depth; this.Stencil = stencil; this.Samples = samples; this.AccumulatorFormat = accum; this.Buffers = buffers; this.Stereo = stereo; }
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="depth">The number of bits in the depth buffer.</param> /// <param name="stencil">The number of bits in the stencil buffer.</param> /// <param name="samples">The number of samples for FSAA.</param> public GraphicsMode(ColorFormat color, int depth, int stencil, int samples) : this(color, depth, stencil, samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo) { }
GraphicsMode SelectGraphicsModeARB(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo) { using (INativeWindow native_window = new NativeWindow()) using (IGraphicsContext context = new GraphicsContext(new GraphicsMode(new ColorFormat(), 0, 0, 0, new ColorFormat(), 2, false), native_window.WindowInfo, 1, 0, GraphicsContextFlags.Default)) { WinWindowInfo window = (WinWindowInfo)native_window.WindowInfo; // See http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt // for more details Debug.Write("Selecting pixel format (ARB)... "); if (Wgl.Delegates.wglChoosePixelFormatARB == null || Wgl.Delegates.wglGetPixelFormatAttribivARB == null) { Debug.WriteLine("failed"); return(null); } int[] attribs = new int[] { (int)WGL_ARB_pixel_format.AccelerationArb, (int)WGL_ARB_pixel_format.RedBitsArb, (int)WGL_ARB_pixel_format.GreenBitsArb, (int)WGL_ARB_pixel_format.BlueBitsArb, (int)WGL_ARB_pixel_format.AlphaBitsArb, (int)WGL_ARB_pixel_format.ColorBitsArb, (int)WGL_ARB_pixel_format.DepthBitsArb, (int)WGL_ARB_pixel_format.StencilBitsArb, (int)WGL_ARB_multisample.SampleBuffersArb, (int)WGL_ARB_multisample.SamplesArb, (int)WGL_ARB_pixel_format.AccumRedBitsArb, (int)WGL_ARB_pixel_format.AccumGreenBitsArb, (int)WGL_ARB_pixel_format.AccumBlueBitsArb, (int)WGL_ARB_pixel_format.AccumAlphaBitsArb, (int)WGL_ARB_pixel_format.AccumBitsArb, (int)WGL_ARB_pixel_format.DoubleBufferArb, (int)WGL_ARB_pixel_format.StereoArb, 0 }; int[] values = new int[attribs.Length]; int[] attribs_values = new int[] { (int)WGL_ARB_pixel_format.AccelerationArb, (int)WGL_ARB_pixel_format.FullAccelerationArb, (int)WGL_ARB_pixel_format.DrawToWindowArb, 1, (int)WGL_ARB_pixel_format.RedBitsArb, color.Red, (int)WGL_ARB_pixel_format.GreenBitsArb, color.Green, (int)WGL_ARB_pixel_format.BlueBitsArb, color.Blue, (int)WGL_ARB_pixel_format.AlphaBitsArb, color.Alpha, (int)WGL_ARB_pixel_format.ColorBitsArb, color.BitsPerPixel - color.Alpha, // Should not contain alpha bpp (see spec) (int)WGL_ARB_pixel_format.DepthBitsArb, depth, (int)WGL_ARB_pixel_format.StencilBitsArb, stencil, (int)WGL_ARB_multisample.SampleBuffersArb, samples > 0 ? 1 : 0, (int)WGL_ARB_multisample.SamplesArb, samples, (int)WGL_ARB_pixel_format.AccumRedBitsArb, accum.Red, (int)WGL_ARB_pixel_format.AccumGreenBitsArb, accum.Green, (int)WGL_ARB_pixel_format.AccumBlueBitsArb, accum.Blue, (int)WGL_ARB_pixel_format.AccumAlphaBitsArb, accum.Alpha, (int)WGL_ARB_pixel_format.AccumBitsArb, accum.BitsPerPixel, // Spec doesn't mention wether alpha bpp should be included... (int)WGL_ARB_pixel_format.DoubleBufferArb, buffers > 1 ? 1 : 0, (int)WGL_ARB_pixel_format.StereoArb, stereo ? 1 : 0, 0, 0 }; int[] pixel = new int[1], num_formats = new int[1]; bool success = Wgl.Arb.ChoosePixelFormat(window.DeviceContext, attribs_values, null, 1, pixel, num_formats); if (!success || num_formats[0] == 0 || pixel[0] == 0) { // Try again without an accumulator. Many modern cards cannot accelerate multisampled formats with accumulator buffers. int index_of_accum = Array.IndexOf(attribs_values, (int)WGL_ARB_pixel_format.AccumRedBitsArb); attribs_values[index_of_accum + 1] = attribs_values[index_of_accum + 3] = attribs_values[index_of_accum + 5] = attribs_values[index_of_accum + 7] = attribs_values[index_of_accum + 9] = 0; Wgl.Arb.ChoosePixelFormat(window.DeviceContext, attribs_values, null, 1, pixel, num_formats); } if (!success || num_formats[0] == 0 || pixel[0] == 0) { Debug.WriteLine("failed (no suitable pixel format)."); return(null); } // Find out what we really got as a format: success = Wgl.Arb.GetPixelFormatAttrib(window.DeviceContext, pixel[0], 0, attribs.Length - 1, attribs, values); if (!success) { Debug.WriteLine("failed (pixel format attributes could not be determined)."); return(null); } GraphicsMode mode = new GraphicsMode(new IntPtr(pixel[0]), new ColorDepth(values[1], values[2], values[3], values[4]), values[6], values[7], values[8] != 0 ? values[9] : 0, new ColorDepth(values[10], values[11], values[12], values[13]), values[15] == 1 ? 2 : 1, values[16] == 1 ? true : false); Debug.WriteLine("success!"); return(mode); } }
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="depth">The number of bits in the depth buffer.</param> /// <param name="stencil">The number of bits in the stencil buffer.</param> /// <param name="samples">The number of samples for FSAA.</param> /// <param name="accum">The ColorFormat of the accumilliary buffer.</param> /// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param> public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers) : this(color, depth, stencil, samples, accum, buffers, Default.Stereo) { }
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="depth">The number of bits in the depth buffer.</param> /// <param name="stencil">The number of bits in the stencil buffer.</param> /// <param name="samples">The number of samples for FSAA.</param> /// <param name="accum">The ColorFormat of the accumilliary buffer.</param> /// <param name="stereo">Set to true for a GraphicsMode with stereographic capabilities.</param> /// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param> public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) : this(null, color, depth, stencil, samples, accum, buffers, stereo) { }