From e0ec10d11c728e69f76d9dbbd616b7b34e35a605 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Wed, 23 Jan 2008 12:41:10 +0000 Subject: [PATCH] Addd public properties and documentation. --- Source/OpenTK/ColorMode.cs | 61 +++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/Source/OpenTK/ColorMode.cs b/Source/OpenTK/ColorMode.cs index 25c7da9b..e69715ed 100644 --- a/Source/OpenTK/ColorMode.cs +++ b/Source/OpenTK/ColorMode.cs @@ -10,12 +10,23 @@ using System.Globalization; namespace OpenTK { + /// Defines a color mode for OpenGL rendering. + /// + /// A ColorMode contains Red, Green, Blue and Alpha components that descibe + /// the allocated bits per pixel for the corresponding color. + /// public class ColorMode { - public byte Red, Green, Blue, Alpha; - public bool IsIndexed = false; - public int BitsPerPixel; - + byte red, green, blue, alpha; + bool isIndexed = false; + int bitsPerPixel; + + #region --- Constructors --- + + /// + /// Constructs a new ColorMode with the specified aggregate bits per pixel. + /// + /// The bits per pixel sum for the Red, Green, Blue and Alpha color channels. public ColorMode(int bpp) { Red = Green = Blue = Alpha = 0; @@ -37,16 +48,33 @@ namespace OpenTK Red = Green = Blue = 5; break; case 8: + Red = Green = 3; + Blue = 2; IsIndexed = true; break; case 4: + Red = Green = 2; + Blue = 1; + IsIndexed = true; + break; + case 1: IsIndexed = true; break; default: + Red = Blue = Alpha = (byte)(bpp / 4); + Green = (byte)((bpp / 4) + (bpp % 4)); break; } } + /// + /// Constructs a new ColorMode with the specified bits per pixel for + /// the Red, Green, Blue and Alpha color channels. + /// + /// Bits per pixel for the Red color channel. + /// Bits per pixel for the Green color channel. + /// Bits per pixel for the Blue color channel. + /// Bits per pixel for the Alpha color channel. public ColorMode(int red, int green, int blue, int alpha) { Red = (byte)red; @@ -54,8 +82,31 @@ namespace OpenTK Blue = (byte)blue; Alpha = (byte)alpha; BitsPerPixel = red + green + blue + alpha; + if (BitsPerPixel < 15) + IsIndexed = true; } + #endregion + + #region --- Public Methods --- + + /// Gets the bits per pixel for the Red channel. + public int Red { get { return red; } private set { red = (byte)value; } } + /// Gets the bits per pixel for the Green channel. + public int Green { get { return green; } private set { green = (byte)value; } } + /// Gets the bits per pixel for the Blue channel. + public int Blue { get { return blue; } private set { blue = (byte)value; } } + /// Gets the bits per pixel for the Alpha channel. + public int Alpha { get { return alpha; } private set { alpha = (byte)value; } } + /// Gets a System.Boolean indicating whether this ColorMode is indexed. + public bool IsIndexed { get { return isIndexed; } private set { isIndexed = value; } } + /// Gets the sum of Red, Green, Blue and Alpha bits per pixel. + public int BitsPerPixel { get { return bitsPerPixel; } private set { bitsPerPixel = value; } } + + #endregion + + #region --- Overrides --- + public override bool Equals(object obj) { return (obj is ColorMode) ? (this == (ColorMode)obj) : false; @@ -90,5 +141,7 @@ namespace OpenTK { return string.Format("{0} ({1})", BitsPerPixel, (IsIndexed ? " indexed" : Red.ToString() + Green.ToString() + Blue.ToString() + Alpha.ToString())); } + + #endregion } }