00001 #region --- License ---
00002
00003
00004
00005
00006
00007 #endregion
00008
00009 using System;
00010 using System.Collections.Generic;
00011 using System.Text;
00012 using System.Diagnostics;
00013
00014 namespace OpenTK.Graphics
00015 {
00017 public class GraphicsMode
00018 {
00019 ColorFormat color_format, accumulator_format;
00020 int depth, stencil, buffers, samples;
00021 bool stereo;
00022 IntPtr? index = null;
00023
00024 static GraphicsMode defaultMode;
00025 static IGraphicsMode implementation;
00026 static readonly object SyncRoot = new object();
00027
00028 #region --- Constructors ---
00029
00030 #region static GraphicsMode()
00031
00032 static GraphicsMode()
00033 {
00034 lock (SyncRoot)
00035 {
00036 implementation = Platform.Factory.Default.CreateGraphicsMode();
00037 }
00038 }
00039
00040 #endregion
00041
00042 #region internal GraphicsMode(GraphicsMode mode)
00043
00044 internal GraphicsMode(GraphicsMode mode)
00045 : this(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo) { }
00046
00047 #endregion
00048
00049 #region internal GraphicsMode(IntPtr? index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
00050
00051 internal GraphicsMode(IntPtr? index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum,
00052 int buffers, bool stereo)
00053 {
00054 if (depth < 0) throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero.");
00055 if (stencil < 0) throw new ArgumentOutOfRangeException("stencil", "Must be greater than, or equal to zero.");
00056 if (buffers <= 0) throw new ArgumentOutOfRangeException("buffers", "Must be greater than zero.");
00057 if (samples < 0) throw new ArgumentOutOfRangeException("samples", "Must be greater than, or equal to zero.");
00058
00059 this.Index = index;
00060 this.ColorFormat = color;
00061 this.Depth = depth;
00062 this.Stencil = stencil;
00063 this.Samples = samples;
00064 this.AccumulatorFormat = accum;
00065 this.Buffers = buffers;
00066 this.Stereo = stereo;
00067 }
00068
00069 #endregion
00070
00071 #region public GraphicsMode()
00072
00074 public GraphicsMode()
00075 : this(Default)
00076 { }
00077
00078 #endregion
00079
00080 #region public GraphicsMode(ColorFormat color)
00081
00084 public GraphicsMode(ColorFormat color)
00085 : this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
00086 { }
00087
00088 #endregion
00089
00090 #region public GraphicsMode(ColorFormat color, int depth)
00091
00095 public GraphicsMode(ColorFormat color, int depth)
00096 : this(color, depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
00097 { }
00098
00099 #endregion
00100
00101 #region public GraphicsMode(ColorFormat color, int depth, int stencil)
00102
00107 public GraphicsMode(ColorFormat color, int depth, int stencil)
00108 : this(color, depth, stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
00109 { }
00110
00111 #endregion
00112
00113 #region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
00114
00120 public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
00121 : this(color, depth, stencil, samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
00122 { }
00123
00124 #endregion
00125
00126 #region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
00127
00134 public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
00135 : this(color, depth, stencil, samples, accum, Default.Buffers, Default.Stereo)
00136 { }
00137
00138 #endregion
00139
00140 #region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
00141
00149 public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
00150 : this(color, depth, stencil, samples, accum, buffers, Default.Stereo)
00151 { }
00152
00153 #endregion
00154
00155 #region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
00156
00165 public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
00166 : this(null, color, depth, stencil, samples, accum, buffers, stereo) { }
00167
00168 #endregion
00169
00170 #endregion
00171
00172 #region --- Public Methods ---
00173
00174 #region public IntPtr Index
00175
00179 public IntPtr? Index
00180 {
00181 get
00182 {
00183 if (index == null)
00184 {
00185 GraphicsMode mode;
00186 mode = implementation.SelectGraphicsMode(ColorFormat, Depth, Stencil, Samples, AccumulatorFormat, Buffers, Stereo);
00187
00188 Index = mode.Index;
00189 ColorFormat = mode.ColorFormat;
00190 Depth = mode.Depth;
00191 Stencil = mode.Stencil;
00192 Samples = mode.Samples;
00193 AccumulatorFormat = mode.AccumulatorFormat;
00194 Buffers = mode.Buffers;
00195 Stereo = mode.Stereo;
00196 }
00197
00198 return index;
00199 }
00200 set { index = value; }
00201 }
00202
00203 #endregion
00204
00205 #region public int ColorFormat
00206
00210 public ColorFormat ColorFormat
00211 {
00212 get { return color_format; }
00213 private set { color_format = value; }
00214 }
00215
00216 #endregion
00217
00218 #region public int AccumulatorFormat
00219
00223 public ColorFormat AccumulatorFormat
00224 {
00225 get { return accumulator_format; }
00226 private set { accumulator_format = value; }
00227 }
00228
00229 #endregion
00230
00231 #region public int Depth
00232
00237 public int Depth
00238 {
00239 get { return depth; }
00240 private set { depth = value; }
00241 }
00242
00243 #endregion
00244
00245 #region public int Stencil
00246
00251 public int Stencil
00252 {
00253 get { return stencil; }
00254 private set { stencil = value; }
00255 }
00256
00257 #endregion
00258
00259 #region public int Samples
00260
00264 public int Samples
00265 {
00266 get { return samples; }
00267 private set { samples = value; }
00268 }
00269
00270 #endregion
00271
00272 #region public bool Stereo
00273
00277 public bool Stereo
00278 {
00279 get { return this.stereo; }
00280 private set { this.stereo = value; }
00281 }
00282
00283 #endregion
00284
00285 #region public int Buffers
00286
00291 public int Buffers
00292 {
00293 get { return this.buffers; }
00294 private set { this.buffers = value; }
00295 }
00296
00297 #endregion
00298
00299 #region public static GraphicsFormat Default
00300
00302 public static GraphicsMode Default
00303 {
00304 get
00305 {
00306 lock (SyncRoot)
00307 {
00308 if (defaultMode == null)
00309 {
00310 Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).", DisplayDevice.Default.BitsPerPixel,
00311 16, 0, 0, 0, 2, false);
00312 defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false);
00313 }
00314 return defaultMode;
00315 }
00316 }
00317 }
00318
00319 #endregion
00320
00321 #endregion
00322
00323 #region --- Overrides ---
00324
00327 public override string ToString()
00328 {
00329 return String.Format("Index: {0}, Color: {1}, Depth: {2}, Stencil: {3}, Samples: {4}, Accum: {5}, Buffers: {6}, Stereo: {7}",
00330 Index, ColorFormat, Depth, Stencil, Samples, AccumulatorFormat, Buffers, Stereo);
00331 }
00332
00333 #endregion
00334 }
00335 }