PageRenderTime 575ms CodeModel.GetById 151ms app.highlight 338ms RepoModel.GetById 74ms app.codeStats 1ms

/opengles/src/RasterizerState.h

http://ftk.googlecode.com/
C++ Header | 1245 lines | 956 code | 232 blank | 57 comment | 71 complexity | 496f7b6f1dcd8abb9359d4e8647b54ca MD5 | raw file
   1#ifndef EGL_RASTERIZER_STATE_H
   2#define EGL_RASTERIZER_STATE_H 1
   3
   4// ==========================================================================
   5//
   6// RasterizerState	Rasterizer State Class for 3D Rendering Library
   7//
   8//					The rasterizer state maintains all the state information
   9//					that is necessary to determine the details of the
  10//					next primitive to be scan-converted.
  11//
  12// --------------------------------------------------------------------------
  13//
  14// 10-10-2003		Hans-Martin Will	initial version
  15//
  16// --------------------------------------------------------------------------
  17//
  18// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
  19//
  20// Redistribution and use in source and binary forms, with or without
  21// modification, are permitted provided that the following conditions are
  22// met:
  23//
  24//	 *  Redistributions of source code must retain the above copyright
  25// 		notice, this list of conditions and the following disclaimer.
  26//   *	Redistributions in binary form must reproduce the above copyright
  27// 		notice, this list of conditions and the following disclaimer in the
  28// 		documentation and/or other materials provided with the distribution.
  29//
  30// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  34// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  35// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  36// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  37// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  38// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  39// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  40// THE POSSIBILITY OF SUCH DAMAGE.
  41//
  42// ==========================================================================
  43
  44
  45#include "OGLES.h"
  46#include "fixed.h"
  47#include "linalg.h"
  48#include "Color.h"
  49
  50
  51namespace EGL {
  52	class Rasterizer;
  53	class MultiTexture;
  54
  55	class RasterizerState {
  56
  57		friend class Rasterizer;
  58		friend class CodeGenerator;
  59
  60	public:
  61		enum Limits {
  62			LogMaxTextureSize = 12,
  63			MaxTextureSize = 1 << LogMaxTextureSize
  64		};
  65
  66		enum LogicOp {
  67			LogicOpInvalid = -1,
  68			LogicOpClear,
  69			LogicOpAnd,
  70			LogicOpAndReverse,
  71			LogicOpCopy,
  72			LogicOpAndInverted,
  73			LogicOpNoop,
  74			LogicOpXor,
  75			LogicOpOr,
  76			LogicOpNor,
  77			LogicOpEquiv,
  78			LogicOpInvert,
  79			LogicOpOrReverse,
  80			LogicOpCopyInverted,
  81			LogicOpOrInverted,
  82			LogicOpNand,
  83			LogicOpSet
  84		};
  85
  86		enum ComparisonFunc {
  87			CompFuncInvalid = -1,
  88			CompFuncNever,
  89			CompFuncLess,
  90			CompFuncEqual,
  91			CompFuncLEqual,
  92			CompFuncGreater,
  93			CompFuncNotEqual,
  94			CompFuncGEqual,
  95			CompFuncAlways
  96		};
  97
  98		enum BlendFuncDst {
  99			BlendFuncDstInvalid = -1,
 100			BlendFuncDstZero,
 101			BlendFuncDstOne,
 102			BlendFuncDstSrcColor,
 103			BlendFuncDstOneMinusSrcColor,
 104			BlendFuncDstSrcAlpha,
 105			BlendFuncDstOneMinusSrcAlpha,
 106			BlendFuncDstDstAlpha,
 107			BlendFuncDstOneMinusDstAlpha
 108		};
 109
 110		enum BlendFuncSrc {
 111			BlendFuncSrcInvalid = -1,
 112			BlendFuncSrcZero,
 113			BlendFuncSrcOne,
 114			BlendFuncSrcDstColor,
 115			BlendFuncSrcOneMinusDstColor,
 116			BlendFuncSrcSrcAlpha,
 117			BlendFuncSrcOneMinusSrcAlpha,
 118			BlendFuncSrcDstAlpha,
 119			BlendFuncSrcOneMinusDstAlpha,
 120			BlendFuncSrcSrcAlphaSaturate
 121		};
 122
 123		enum StencilOp {
 124			StencilOpInvalid = -1,
 125			StencilOpZero,
 126			StencilOpKeep,
 127			StencilOpReplace,
 128			StencilOpIncr,
 129			StencilOpDecr,
 130			StencilOpInvert
 131		};
 132
 133		enum ShadingModel {
 134			ShadeModelInvalid = -1,
 135			ShadeModelFlat,
 136			ShadeModelSmooth
 137		};
 138
 139		enum TextureMode {
 140			TextureModeInvalid = -1,
 141			TextureModeDecal,
 142			TextureModeReplace,
 143			TextureModeBlend,
 144			TextureModeAdd,
 145			TextureModeModulate,
 146			TextureModeCombine
 147		};
 148
 149		enum TextureModeCombineFunc {
 150			TextureModeCombineReplace,
 151			TextureModeCombineModulate,
 152			TextureModeCombineAdd,
 153			TextureModeCombineAddSigned,
 154			TextureModeCombineInterpolate,
 155			TextureModeCombineSubtract,
 156			TextureModeCombineDot3RGB,
 157			TextureModeCombineDot3RGBA
 158		};
 159
 160		enum TextureCombineSrc {
 161			TextureCombineSrcTexture,
 162			TextureCombineSrcConstant,
 163			TextureCombineSrcPrimaryColor,
 164			TextureCombineSrcPrevious
 165		};
 166
 167		enum TextureCombineOp {
 168			TextureCombineOpSrcColor,
 169			TextureCombineOpOneMinusSrcColor,
 170			TextureCombineOpSrcAlpha,
 171			TextureCombineOpOneMinusSrcAlpha
 172		};
 173
 174		enum WrappingMode {
 175			WrappingModeInvalid = -1,
 176			WrappingModeClampToEdge,
 177			WrappingModeRepeat
 178		};
 179
 180		enum FilterMode {
 181			FilterModeInvalid = -1,
 182			FilterModeNone,
 183			FilterModeNearest,
 184			FilterModeLinear
 185		};
 186
 187		enum TextureFormat {
 188			TextureFormatInvalid = -1,
 189			TextureFormatAlpha = 0,				// 8
 190			TextureFormatLuminance = 1,			// 8
 191			TextureFormatLuminanceAlpha = 2,	// 8-8
 192			TextureFormatRGB8 = 3,				// 8-8-8
 193			TextureFormatRGBA8 = 4,				// 8-8-8-8
 194			TextureFormatRGB565 = 5,			// 5-6-5
 195			TextureFormatRGBA4444 = 6,			// 4-4-4-4
 196			TextureFormatRGBA5551 = 7			// 5-5-5-1
 197		};
 198
 199	public:
 200		RasterizerState();
 201
 202		bool CompareCommon(const RasterizerState& other) const;
 203		bool ComparePoint(const RasterizerState& other) const;
 204		bool CompareLine(const RasterizerState& other) const;
 205		bool ComparePolygon(const RasterizerState& other) const;
 206
 207		typedef bool (RasterizerState::*CompareFunction)(const RasterizerState& other) const;
 208
 209		// ----------------------------------------------------------------------
 210		// Primitive rendering state
 211		// ----------------------------------------------------------------------
 212
 213		void SetTexEnvColor(size_t unit, const Color& color);
 214		Color GetTexEnvColor(size_t unit) const;
 215
 216		void SetTextureMode(size_t unit, TextureMode mode);
 217		TextureMode GetTextureMode(size_t unit) const;
 218
 219		void SetTextureCombineFuncRGB(size_t unit, TextureModeCombineFunc func);
 220		TextureModeCombineFunc GetTextureCombineFuncRGB(size_t unit) const;
 221
 222		void SetTextureCombineFuncAlpha(size_t unit, TextureModeCombineFunc func);
 223		TextureModeCombineFunc GetTextureCombineFuncAlpha(size_t unit) const;
 224
 225		void SetTextureCombineSrcRGB(size_t unit, size_t idx, TextureCombineSrc src);
 226		TextureCombineSrc GetTextureCombineSrcRGB(size_t unit, size_t idx) const;
 227
 228		void SetTextureCombineSrcAlpha(size_t unit, size_t idx, TextureCombineSrc src);
 229		TextureCombineSrc GetTextureCombineSrcAlpha(size_t unit, size_t idx) const;
 230
 231		void SetTextureCombineOpRGB(size_t unit, size_t idx, TextureCombineOp op);
 232		TextureCombineOp GetTextureCombineOpRGB(size_t unit, size_t idx) const;
 233
 234		void SetTextureCombineOpAlpha(size_t unit, size_t idx, TextureCombineOp op);
 235		TextureCombineOp GetTextureCombineOpAlpha(size_t unit, size_t idx) const;
 236
 237		void SetTextureScaleRGB(size_t unit, EGL_Fixed scale);
 238		EGL_Fixed GetTextureScaleRGB(size_t unit) const;
 239
 240		void SetTextureScaleAlpha(size_t unit, EGL_Fixed scale);
 241		EGL_Fixed GetTextureScaleAlpha(size_t unit) const;
 242
 243		void SetMinFilterMode(size_t unit, FilterMode mode);
 244		void SetMagFilterMode(size_t unit, FilterMode mode);
 245		void SetMipmapFilterMode(size_t unit, FilterMode mode);
 246		void SetWrappingModeS(size_t unit, WrappingMode mode);
 247		void SetWrappingModeT(size_t unit, WrappingMode mode);
 248
 249		FilterMode GetMinFilterMode(size_t unit) const			{ return m_Texture[unit].MinFilterMode; }
 250		FilterMode GetMagFilterMode(size_t unit) const			{ return m_Texture[unit].MagFilterMode; }
 251		FilterMode GetMipmapFilterMode(size_t unit) const		{ return m_Texture[unit].MipmapFilterMode; }
 252		WrappingMode GetWrappingModeS(size_t unit) const		{ return m_Texture[unit].WrappingModeS; }
 253		WrappingMode GetWrappingModeT(size_t unit) const		{ return m_Texture[unit].WrappingModeT; }
 254
 255		void SetInternalFormat(size_t unit, TextureFormat format);
 256
 257		void SetDepthRange(EGL_Fixed zNear, EGL_Fixed zFar);
 258
 259		void SetFogColor(const Color& color);
 260		Color GetFogColor() const;
 261		void EnableFog(bool enabled);
 262		bool IsEnabledFog() const;
 263
 264		void SetLineWidth(EGL_Fixed width);
 265		void SetLineSmoothEnabled(bool enabled);
 266		bool IsLineSmoothEnabled() const;
 267
 268		void SetLogicOp(LogicOp opcode);
 269		LogicOp GetLogicOp() const;
 270
 271		void SetShadeModel(ShadingModel mode);
 272		ShadingModel GetShadeModel() const;
 273
 274		void EnableTexture(size_t unit, bool enabled);
 275		bool IsEnabledTexture(size_t unit) const;
 276
 277		void SetPointSmoothEnabled(bool enabled);
 278		bool IsPointSmoothEnabled() const;
 279		void SetPointSpriteEnabled(bool enabled);
 280		bool IsPointSpriteEnabled() const;
 281		void SetPointCoordReplaceEnabled(size_t unit, bool enabled);
 282		bool IsPointCoordReplaceEnabled(size_t unit) const;
 283
 284		void EnablePolygonOffsetFill(bool enabled);
 285		bool IsEnabledPolygonOffsetFill() const;
 286		void SetPolygonOffset(EGL_Fixed factor, EGL_Fixed units);
 287		void SetSampleCoverage(EGL_Fixed value, bool invert);
 288		EGL_Fixed GetPolygonOffsetFactor() const;
 289		EGL_Fixed GetPolygonOffsetUnits() const;
 290		EGL_Fixed GetSampleCoverage() const;
 291		bool GetSampleCoverageInvert() const;
 292
 293		// ----------------------------------------------------------------------
 294		// Fragment rendering state
 295		// ----------------------------------------------------------------------
 296
 297		void SetAlphaFunc(ComparisonFunc func, EGL_Fixed ref);
 298		ComparisonFunc GetAlphaFunc() const;
 299		EGL_Fixed GetAlphaRef() const;
 300		void SetBlendFunc(BlendFuncSrc sfactor, BlendFuncDst dfactor);
 301		BlendFuncSrc GetBlendFuncSrc() const;
 302		BlendFuncDst GetBlendFuncDst() const;
 303		void SetColorMask(bool red, bool green, bool blue, bool alpha);
 304		Color GetColorMask() const;
 305
 306		void SetDepthFunc(ComparisonFunc func);
 307		ComparisonFunc GetDepthFunc() const;
 308		void SetDepthMask(bool flag);
 309		bool GetDepthMask() const;
 310
 311		void SetScissor(I32 x, I32 y, U32 width, U32 height);
 312
 313		void EnableAlphaTest(bool enabled);
 314		void EnableDepthTest(bool enabled);
 315		void EnableLogicOp(bool enabled);
 316		void EnableScissorTest(bool enabled);
 317		void EnableBlending(bool enabled);
 318		void EnableStencilTest(bool enabled);
 319
 320		bool IsEnabledAlphaTest() const;
 321		bool IsEnabledDepthTest() const;
 322		bool IsEnabledLogicOp() const;
 323		bool IsEnabledScissorTest() const;
 324		bool IsEnabledBlending() const;
 325		bool IsEnabledStencilTest() const;
 326
 327		void SetStencilFunc(ComparisonFunc func, I32 ref, U32 mask);
 328		ComparisonFunc GetStencilFunc() const;
 329		I32 GetStencilRef() const;
 330		I32 GetStencilComparisonMask() const;
 331		void SetStencilMask(U32 mask);
 332		U32 GetStencilMask() const;
 333
 334		void SetStencilOp(StencilOp fail, StencilOp zfail, StencilOp zpass);
 335		StencilOp GetStencilOpFail() const;
 336		StencilOp GetStencilOpFailZFail() const;
 337		StencilOp GetStencilOpFailZPass() const;
 338
 339	private:
 340		// ----------------------------------------------------------------------
 341		// Primitve specific rendering state
 342		// ----------------------------------------------------------------------
 343
 344		struct PointState {
 345			PointState() {
 346				SmoothEnabled = false;
 347				SpriteEnabled = false;
 348				CoordReplaceEnabled = false;
 349			}
 350
 351			PointState(const PointState& other) {
 352				SmoothEnabled = other.SmoothEnabled;
 353				SpriteEnabled = other.SpriteEnabled;
 354				CoordReplaceEnabled = other.CoordReplaceEnabled;
 355			}
 356
 357			PointState& operator=(const PointState& other) {
 358				SmoothEnabled = other.SmoothEnabled;
 359				SpriteEnabled = other.SpriteEnabled;
 360				CoordReplaceEnabled = other.CoordReplaceEnabled;
 361				return *this;
 362			}
 363
 364			bool operator==(const PointState& other) const {
 365				return	SmoothEnabled == other.SmoothEnabled &&
 366					SpriteEnabled == other.SpriteEnabled &&
 367					(!SpriteEnabled ||
 368					 CoordReplaceEnabled == other.CoordReplaceEnabled);
 369			}
 370
 371			bool				SmoothEnabled;
 372			bool				SpriteEnabled;
 373			bool				CoordReplaceEnabled;
 374		}
 375								m_Point;
 376
 377		struct LineState {
 378			LineState() {
 379				SmoothEnabled = false;
 380				Width = EGL_ONE;
 381			}
 382
 383			LineState(const LineState& other) {
 384				SmoothEnabled = other.SmoothEnabled;
 385				Width = other.Width;
 386			}
 387
 388			LineState& operator=(const LineState& other) {
 389				SmoothEnabled = other.SmoothEnabled;
 390				Width = other.Width;
 391				return *this;
 392			}
 393
 394			bool operator==(const LineState& other) const {
 395				return SmoothEnabled == other.SmoothEnabled &&
 396					Width == other.Width;
 397			}
 398
 399			bool				SmoothEnabled;
 400			EGL_Fixed			Width;	// current line width
 401		}
 402								m_Line;
 403
 404
 405		struct PolygonState {
 406			PolygonState() {
 407				OffsetFillEnabled = false;
 408				OffsetFactor = 0;
 409				OffsetUnits = 0;
 410			}
 411
 412			PolygonState(const PolygonState& other) {
 413				OffsetFillEnabled = other.OffsetFillEnabled;
 414				OffsetFactor = other.OffsetFactor;
 415				OffsetUnits = other.OffsetUnits;
 416			}
 417
 418			PolygonState& operator=(const PolygonState& other) {
 419				OffsetFillEnabled = other.OffsetFillEnabled;
 420				OffsetFactor = other.OffsetFactor;
 421				OffsetUnits = other.OffsetUnits;
 422				return *this;
 423			}
 424
 425			bool operator==(const PolygonState& other) const {
 426				return OffsetFillEnabled == other.OffsetFillEnabled &&
 427					(!OffsetFillEnabled ||
 428					 OffsetFactor == other.OffsetFactor &&
 429					 OffsetUnits == other.OffsetUnits);
 430			}
 431
 432			bool				OffsetFillEnabled;
 433			EGL_Fixed			OffsetFactor;
 434			EGL_Fixed			OffsetUnits;
 435		}
 436								m_Polygon;
 437
 438		// ----------------------------------------------------------------------
 439		// General rendering state
 440		// ----------------------------------------------------------------------
 441
 442		struct FogState {
 443			FogState() {
 444				Enabled = false;
 445				Color = EGL::Color(0, 0, 0, 0);
 446
 447			}
 448
 449			FogState(const FogState& other) {
 450				Enabled = other.Enabled;
 451				Color = other.Color;
 452			}
 453
 454			FogState& operator=(const FogState& other) {
 455				Enabled = other.Enabled;
 456				Color = other.Color;
 457				return *this;
 458			}
 459
 460			bool operator==(const FogState& other) const {
 461				return Enabled == other.Enabled &&
 462					(!Enabled || Color == other.Color);
 463			}
 464
 465			bool				Enabled;
 466            EGL::Color				Color;
 467		}
 468								m_Fog;
 469
 470		struct TextureState {
 471			TextureState() {
 472				Enabled = false;
 473				EnvColor = Color(0, 0, 0, 0);
 474				Mode = TextureModeModulate;
 475				MinFilterMode = FilterModeNearest;
 476				MagFilterMode = FilterModeNearest;
 477				MipmapFilterMode = FilterModeNone;
 478				WrappingModeS = WrappingModeRepeat;
 479				WrappingModeT = WrappingModeRepeat;
 480				InternalFormat = TextureFormatLuminance;				
 481				CombineFuncRGB = TextureModeCombineModulate; 
 482				CombineFuncAlpha = TextureModeCombineModulate;
 483
 484				CombineSrcRGB[0] = CombineSrcAlpha[0] = TextureCombineSrcTexture;
 485				CombineSrcRGB[1] = CombineSrcAlpha[1] = TextureCombineSrcPrevious;
 486				CombineSrcRGB[2] = CombineSrcAlpha[2] = TextureCombineSrcConstant;
 487
 488				CombineOpRGB[0] = CombineOpRGB[1] = TextureCombineOpSrcColor;
 489				CombineOpRGB[2] = CombineOpAlpha[0] =
 490				CombineOpAlpha[1] = CombineOpAlpha[2] = TextureCombineOpSrcAlpha;
 491
 492				ScaleRGB = ScaleAlpha = EGL_ONE;
 493			}
 494
 495			TextureState(const TextureState& other) {
 496				Enabled = other.Enabled;
 497				EnvColor = other.EnvColor;
 498				Mode = other.Mode;
 499				MinFilterMode = other.MinFilterMode;
 500				MagFilterMode = other.MagFilterMode;
 501				MipmapFilterMode = other.MipmapFilterMode;
 502				WrappingModeS = other.WrappingModeS;
 503				WrappingModeT = other.WrappingModeT;
 504				InternalFormat = other.InternalFormat;
 505				CombineFuncRGB = other.CombineFuncRGB;
 506				CombineFuncAlpha = other.CombineFuncAlpha;
 507
 508				for (int i = 0; i < 3; ++i) {
 509					CombineSrcRGB[i] = other.CombineSrcRGB[i];
 510					CombineSrcAlpha[i] = other.CombineSrcAlpha[i];
 511					CombineOpRGB[i] = other.CombineOpRGB[i];
 512					CombineOpAlpha[i] = other.CombineOpAlpha[i];
 513				}
 514
 515				ScaleRGB = other.ScaleRGB;
 516				ScaleAlpha = other.ScaleAlpha;
 517			}
 518
 519			TextureState& operator=(const TextureState& other) {
 520				Enabled = other.Enabled;
 521				EnvColor = other.EnvColor;
 522				Mode = other.Mode;
 523				MinFilterMode = other.MinFilterMode;
 524				MagFilterMode = other.MagFilterMode;
 525				MipmapFilterMode = other.MipmapFilterMode;
 526				WrappingModeS = other.WrappingModeS;
 527				WrappingModeT = other.WrappingModeT;
 528				InternalFormat = other.InternalFormat;
 529				CombineFuncRGB = other.CombineFuncRGB;
 530				CombineFuncAlpha = other.CombineFuncAlpha;
 531
 532				for (int i = 0; i < 3; ++i) {
 533					CombineSrcRGB[i] = other.CombineSrcRGB[i];
 534					CombineSrcAlpha[i] = other.CombineSrcAlpha[i];
 535					CombineOpRGB[i] = other.CombineOpRGB[i];
 536					CombineOpAlpha[i] = other.CombineOpAlpha[i];
 537				}
 538
 539				ScaleRGB = other.ScaleRGB;
 540				ScaleAlpha = other.ScaleAlpha;
 541
 542				return *this;
 543			}
 544
 545			bool operator==(const TextureState& other) const {
 546				if (!(Enabled == other.Enabled))
 547					return false;
 548				
 549				if (!Enabled)
 550					return true;
 551
 552				if (!(EnvColor == other.EnvColor) ||
 553					Mode != other.Mode ||
 554					MinFilterMode != other.MinFilterMode ||
 555					MagFilterMode != other.MagFilterMode ||
 556					MipmapFilterMode != other.MipmapFilterMode ||
 557					WrappingModeS != other.WrappingModeS ||
 558					WrappingModeT != other.WrappingModeT ||
 559					InternalFormat != other.InternalFormat)
 560					return false;
 561
 562				if (Mode == TextureModeCombine) {
 563
 564					if (CombineFuncRGB != other.CombineFuncRGB ||
 565						CombineFuncAlpha != other.CombineFuncAlpha ||
 566						ScaleRGB != other.ScaleRGB ||
 567						ScaleAlpha != other.ScaleAlpha)
 568						return false;
 569
 570					for (int i = 0; i < 3; ++i) {
 571						if (CombineSrcRGB[i] != other.CombineSrcRGB[i] ||
 572							CombineSrcAlpha[i] != other.CombineSrcAlpha[i] ||
 573							CombineOpRGB[i] != other.CombineOpRGB[i] ||
 574							CombineOpAlpha[i] != other.CombineOpAlpha[i])
 575							return false;
 576					}
 577				}
 578
 579				return true;
 580			}
 581
 582			bool					Enabled;
 583			Color					EnvColor;
 584			TextureMode				Mode;
 585			TextureModeCombineFunc	CombineFuncRGB, CombineFuncAlpha;
 586			TextureCombineSrc		CombineSrcRGB[3], CombineSrcAlpha[3];
 587			TextureCombineOp		CombineOpRGB[3], CombineOpAlpha[3];
 588			EGL_Fixed				ScaleRGB, ScaleAlpha;
 589			FilterMode				MinFilterMode;
 590			FilterMode				MagFilterMode;
 591			FilterMode				MipmapFilterMode;
 592			WrappingMode			WrappingModeS;
 593			WrappingMode			WrappingModeT;
 594			TextureFormat			InternalFormat;
 595		}
 596								m_Texture[EGL_NUM_TEXTURE_UNITS];
 597
 598		struct ScissorTestState {
 599			ScissorTestState() {
 600				Enabled = false;
 601				X = 0;
 602				Y = 0;
 603				Width = 1024;
 604				Height = 1024;
 605			}
 606
 607			ScissorTestState(const ScissorTestState& other) {
 608				Enabled = other.Enabled;
 609				X = other.X;
 610				Y = other.Y;
 611				Width = other.Width;
 612				Height = other.Height;
 613			}
 614
 615			ScissorTestState& operator=(const ScissorTestState& other) {
 616				Enabled = other.Enabled;
 617				X = other.X;
 618				Y = other.Y;
 619				Width = other.Width;
 620				Height = other.Height;
 621				return *this;
 622			}
 623
 624			bool operator==(const ScissorTestState& other) const {
 625				return Enabled == other.Enabled &&
 626					(!Enabled ||
 627					 X == other.X && Y == other.Y &&
 628					 Width == other.Width && Height == other.Height);
 629			}
 630
 631			bool				Enabled;
 632			I32					X, Y;
 633			U32					Width, Height;
 634		}
 635								m_ScissorTest;
 636
 637		struct MaskState {
 638			MaskState() {
 639				Red = true;
 640				Blue = true;
 641				Green = true;
 642				Alpha = true;
 643				Depth = true;
 644			}
 645
 646			MaskState(const MaskState& other) {
 647				Red = other.Red;
 648				Blue = other.Blue;
 649				Green = other.Green;
 650				Alpha = other.Alpha;
 651				Depth = other.Depth;
 652			}
 653
 654			MaskState& operator=(const MaskState& other) {
 655				Red = other.Red;
 656				Blue = other.Blue;
 657				Green = other.Green;
 658				Alpha = other.Alpha;
 659				Depth = other.Depth;
 660				return *this;
 661			}
 662
 663			bool operator==(const MaskState& other) const {
 664				return Red == other.Red &&
 665					Green == other.Green &&
 666					Blue == other.Blue &&
 667					Alpha == other.Alpha &&
 668					Depth == other.Depth;
 669			}
 670
 671			bool				Red;	// if true, write red channel
 672			bool				Green;	// if true, write green channel
 673			bool				Blue;	// if true, write blue channel
 674			bool				Alpha;	// if true, write alpha channel
 675			bool				Depth;	// if true, write depth buffer
 676		}
 677								m_Mask;
 678
 679		struct AlphaState {
 680			AlphaState() {
 681				Enabled = false;
 682				Func = CompFuncAlways;
 683				Reference = 0; 
 684			}
 685
 686			AlphaState(const AlphaState& other) {
 687				Enabled = other.Enabled;
 688				Func = other.Func;
 689				Reference = other.Reference; 
 690			}
 691
 692			AlphaState& operator=(const AlphaState& other) {
 693				Enabled = other.Enabled;
 694				Func = other.Func;
 695				Reference = other.Reference; 
 696				return *this;
 697			}
 698
 699			bool operator==(const AlphaState& other) const {
 700				return Enabled == other.Enabled &&
 701					(!Enabled ||
 702					 Func == other.Func &&
 703					 Reference == other.Reference);
 704			}
 705
 706			bool				Enabled;
 707			ComparisonFunc		Func;
 708			EGL_Fixed			Reference;
 709		}
 710								m_Alpha;
 711
 712		struct BlendState {
 713			BlendState() {
 714				Enabled = false;
 715				FuncSrc = BlendFuncSrcOne;
 716				FuncDst = BlendFuncDstZero;
 717			}
 718
 719			BlendState(const BlendState& other) {
 720				Enabled = other.Enabled;
 721				FuncSrc = other.FuncSrc;
 722				FuncDst = other.FuncDst;
 723			}
 724
 725			BlendState& operator=(const BlendState& other) {
 726				Enabled = other.Enabled;
 727				FuncSrc = other.FuncSrc;
 728				FuncDst = other.FuncDst;
 729				return *this;
 730			}
 731
 732			bool operator==(const BlendState& other) const {
 733				return Enabled == other.Enabled &&
 734					(!Enabled ||
 735					 FuncSrc == other.FuncSrc && FuncDst == other.FuncDst);
 736			}
 737
 738			bool				Enabled;
 739			BlendFuncSrc		FuncSrc;
 740			BlendFuncDst		FuncDst;
 741		}
 742								m_Blend;
 743
 744		struct DepthTestState {
 745			DepthTestState() {
 746				Enabled = false;
 747				Func = CompFuncLess;
 748			}
 749
 750			DepthTestState(const DepthTestState& other) {
 751				Enabled = other.Enabled;
 752				Func = other.Func;
 753			}
 754
 755			DepthTestState& operator=(const DepthTestState& other) {
 756				Enabled = other.Enabled;
 757				Func = other.Func;
 758				return *this;
 759			}
 760
 761			bool operator==(const DepthTestState& other) const {
 762				return Enabled == other.Enabled &&
 763					(!Enabled || Func == other.Func);
 764			}
 765
 766			bool				Enabled;
 767			ComparisonFunc		Func;
 768		}
 769								m_DepthTest;
 770
 771		struct LogicOpState {
 772			LogicOpState() {
 773				Enabled = false;
 774				Opcode = LogicOpCopy;
 775			}
 776
 777			LogicOpState(const LogicOpState& other) {
 778				Enabled = other.Enabled;
 779				Opcode = other.Opcode;
 780			}
 781
 782			LogicOpState& operator=(const LogicOpState& other) {
 783				Enabled = other.Enabled;
 784				Opcode = other.Opcode;
 785				return *this;
 786			}
 787
 788			bool operator==(const LogicOpState& other) const {
 789				return Enabled == other.Enabled &&
 790					(!Enabled || Opcode == other.Opcode);
 791			}
 792
 793			bool				Enabled;
 794			LogicOp				Opcode;
 795		}
 796								m_LogicOp;
 797
 798		struct StencilState {
 799			StencilState() {
 800				Enabled = false;
 801				Func = CompFuncAlways;
 802				Reference = 0;
 803				Mask = 0xFFFFFFFFu;
 804				ComparisonMask = 0xFFFFFFFFu;
 805				Fail = StencilOpKeep;
 806				ZFail = StencilOpKeep;
 807				ZPass = StencilOpKeep;
 808			}
 809
 810			StencilState(const StencilState& other) {
 811				Enabled = other.Enabled;
 812				Func = other.Func;
 813				Reference = other.Reference;
 814				ComparisonMask = other.ComparisonMask;
 815				Mask = other.Mask;
 816				Fail = other.Fail;
 817				ZFail = other.ZFail;
 818				ZPass = other.ZPass;
 819			}
 820
 821			StencilState& operator=(const StencilState& other) {
 822				Enabled = other.Enabled;
 823				Func = other.Func;
 824				Reference = other.Reference;
 825				Mask = other.Mask;
 826				ComparisonMask = other.ComparisonMask;
 827				Fail = other.Fail;
 828				ZFail = other.ZFail;
 829				ZPass = other.ZPass;
 830				return *this;
 831			}
 832
 833			bool operator==(const StencilState& other) const {
 834				return Enabled == other.Enabled &&
 835					(!Enabled ||
 836					 Func == other.Func &&
 837					 Reference == other.Reference &&
 838					 Mask == other.Mask &&
 839					 ComparisonMask == other.ComparisonMask &&
 840					 Fail == other.Fail &&
 841					 ZFail == other.ZFail &&
 842					 ZPass == other.ZPass);
 843			}
 844
 845			bool				Enabled;
 846			ComparisonFunc		Func;
 847			I32					Reference;
 848			U32					ComparisonMask;
 849			U32					Mask;
 850
 851			StencilOp			Fail, ZFail, ZPass;
 852		}
 853								m_Stencil;
 854
 855		ShadingModel			m_ShadingModel;
 856
 857		EGL_Fixed				m_SampleCoverage;
 858		bool					m_InvertSampleCoverage;
 859
 860	};
 861
 862
 863	// ----------------------------------------------------------------------
 864	// Inline member definitions
 865	// ----------------------------------------------------------------------
 866
 867
 868	inline void RasterizerState :: SetTexEnvColor(size_t unit, const Color& color) {
 869		m_Texture[unit].EnvColor = color;
 870	}
 871
 872	inline Color RasterizerState :: GetTexEnvColor(size_t unit) const {
 873		return m_Texture[unit].EnvColor;
 874	}
 875
 876	inline void RasterizerState :: SetTextureMode(size_t unit, TextureMode mode) {
 877		m_Texture[unit].Mode = mode;
 878	}
 879
 880	inline RasterizerState::TextureMode RasterizerState :: GetTextureMode(size_t unit) const {
 881		return m_Texture[unit].Mode;
 882	}
 883
 884	inline void RasterizerState :: SetMinFilterMode(size_t unit, FilterMode mode) {
 885		m_Texture[unit].MinFilterMode = mode;
 886	}
 887
 888	inline void RasterizerState :: SetMagFilterMode(size_t unit, FilterMode mode) {
 889		m_Texture[unit].MagFilterMode = mode;
 890	}
 891
 892	inline void RasterizerState :: SetMipmapFilterMode(size_t unit, FilterMode mode) {
 893		m_Texture[unit].MipmapFilterMode = mode;
 894	}
 895
 896	inline void RasterizerState :: SetWrappingModeS(size_t unit, WrappingMode mode) {
 897		m_Texture[unit].WrappingModeS = mode;
 898	}
 899
 900	inline void RasterizerState :: SetWrappingModeT(size_t unit, WrappingMode mode) {
 901		m_Texture[unit].WrappingModeT = mode;
 902	}
 903
 904	inline void RasterizerState :: SetInternalFormat(size_t unit, TextureFormat format) {
 905		m_Texture[unit].InternalFormat = format;
 906	}
 907
 908	inline void RasterizerState :: SetFogColor(const Color& color) {
 909		m_Fog.Color = color;
 910	}
 911
 912	inline void RasterizerState :: EnableFog(bool enabled) {
 913		m_Fog.Enabled = enabled;
 914	}
 915
 916	inline void RasterizerState :: SetLineWidth(EGL_Fixed width) {
 917		m_Line.Width = width;
 918	}
 919
 920	inline void RasterizerState :: SetLogicOp(LogicOp opcode) {
 921		m_LogicOp.Opcode = opcode;
 922	}
 923
 924	inline void RasterizerState :: SetShadeModel(ShadingModel mode) {
 925		m_ShadingModel = mode;
 926	}
 927
 928	inline RasterizerState::ShadingModel RasterizerState :: GetShadeModel() const {
 929		return m_ShadingModel;
 930	}
 931
 932	inline void RasterizerState :: EnableTexture(size_t unit, bool enabled) {
 933		m_Texture[unit].Enabled = enabled;
 934	}
 935
 936	inline void RasterizerState :: EnablePolygonOffsetFill(bool enabled) {
 937		m_Polygon.OffsetFillEnabled = enabled;
 938	}
 939
 940	inline bool RasterizerState :: IsEnabledPolygonOffsetFill() const {
 941		return m_Polygon.OffsetFillEnabled;
 942	}
 943
 944	inline void RasterizerState :: SetPolygonOffset(EGL_Fixed factor, EGL_Fixed units) {
 945		m_Polygon.OffsetFactor = factor;
 946		m_Polygon.OffsetUnits = units;
 947	}
 948
 949	inline void RasterizerState :: SetSampleCoverage(EGL_Fixed value, bool invert) {
 950		m_SampleCoverage = value;
 951		m_InvertSampleCoverage = invert;
 952	}
 953
 954	// ----------------------------------------------------------------------
 955	// Fragment rendering state
 956	// ----------------------------------------------------------------------
 957
 958	inline void RasterizerState :: SetAlphaFunc(ComparisonFunc func, EGL_Fixed ref) {
 959		m_Alpha.Func = func;
 960		m_Alpha.Reference = ref;
 961	}
 962
 963	inline void RasterizerState :: SetBlendFunc(BlendFuncSrc sfactor, BlendFuncDst dfactor) {
 964		m_Blend.FuncSrc = sfactor;
 965		m_Blend.FuncDst = dfactor;
 966	}
 967
 968	inline void RasterizerState :: SetColorMask(bool red, bool green, bool blue, bool alpha) {
 969		m_Mask.Alpha = alpha;
 970		m_Mask.Red = red;
 971		m_Mask.Green = green;
 972		m_Mask.Blue = blue;
 973	}
 974
 975	inline Color RasterizerState :: GetColorMask() const {
 976		return Color(m_Mask.Red		? 0xff : 0,
 977					 m_Mask.Green	? 0xff : 0,
 978					 m_Mask.Blue	? 0xff : 0,
 979					 m_Mask.Alpha	? 0xff : 0);
 980	}
 981
 982	inline bool RasterizerState :: GetDepthMask() const {
 983		return m_Mask.Depth;
 984	}
 985
 986	inline U32 RasterizerState :: GetStencilMask() const {
 987		return m_Stencil.Mask;
 988	}
 989
 990	inline void RasterizerState :: SetDepthFunc(ComparisonFunc func) {
 991		m_DepthTest.Func = func;
 992	}
 993
 994	inline void RasterizerState :: SetDepthMask(bool flag) {
 995		m_Mask.Depth = flag;
 996	}
 997
 998	inline void RasterizerState :: SetScissor(I32 x, I32 y, U32 width, U32 height) {
 999		m_ScissorTest.X = x;
1000		m_ScissorTest.Y = y;
1001		m_ScissorTest.Width = width;
1002		m_ScissorTest.Height = height;
1003	}
1004
1005	inline void RasterizerState :: EnableAlphaTest(bool enabled) {
1006		m_Alpha.Enabled = enabled;
1007	}
1008
1009	inline void RasterizerState :: EnableDepthTest(bool enabled) {
1010		m_DepthTest.Enabled = enabled;
1011	}
1012
1013	inline void RasterizerState :: EnableLogicOp(bool enabled) {
1014		m_LogicOp.Enabled = enabled;
1015	}
1016
1017	inline void RasterizerState :: EnableScissorTest(bool enabled) {
1018		m_ScissorTest.Enabled = enabled;
1019	}
1020
1021	inline void RasterizerState :: EnableBlending(bool enabled) {
1022		m_Blend.Enabled = enabled;
1023	}
1024
1025	inline void RasterizerState :: SetStencilFunc(ComparisonFunc func, I32 ref, U32 mask) {
1026		m_Stencil.Func = func;
1027		m_Stencil.Reference = ref;
1028		m_Stencil.ComparisonMask = mask;
1029	}
1030
1031	inline void RasterizerState :: SetStencilMask(U32 mask) {
1032		m_Stencil.Mask = mask;
1033	}
1034
1035	inline void RasterizerState :: SetStencilOp(StencilOp fail, StencilOp zfail, StencilOp zpass) {
1036		m_Stencil.Fail = fail;
1037		m_Stencil.ZFail = zfail;
1038		m_Stencil.ZPass = zpass;
1039	}
1040
1041	inline void RasterizerState :: EnableStencilTest(bool enabled) {
1042		m_Stencil.Enabled = enabled;
1043	}
1044
1045	inline void RasterizerState :: SetLineSmoothEnabled(bool enabled) {
1046		m_Line.SmoothEnabled = enabled;
1047	}
1048
1049	inline void RasterizerState :: SetPointSmoothEnabled(bool enabled) {
1050		m_Point.SmoothEnabled = enabled;
1051	}
1052
1053	inline void RasterizerState :: SetPointSpriteEnabled(bool enabled) {
1054		m_Point.SpriteEnabled = enabled;
1055	}
1056
1057	inline void RasterizerState :: SetPointCoordReplaceEnabled(size_t unit, bool enabled) {
1058		m_Point.CoordReplaceEnabled = enabled;
1059	}
1060
1061	inline bool RasterizerState :: IsPointCoordReplaceEnabled(size_t unit) const {
1062		return m_Point.CoordReplaceEnabled;
1063	}
1064
1065	inline bool RasterizerState :: IsEnabledFog() const {
1066		return m_Fog.Enabled;
1067	}
1068
1069	inline Color RasterizerState :: GetFogColor() const {
1070		return m_Fog.Color;
1071	}
1072
1073	inline EGL_Fixed RasterizerState :: GetPolygonOffsetFactor() const {
1074		return m_Polygon.OffsetFactor;
1075	}
1076
1077	inline EGL_Fixed RasterizerState :: GetPolygonOffsetUnits() const {
1078		return m_Polygon.OffsetUnits;
1079	}
1080
1081	inline EGL_Fixed RasterizerState :: GetSampleCoverage() const {
1082		return m_SampleCoverage;
1083	}
1084
1085	inline bool RasterizerState :: GetSampleCoverageInvert() const {
1086		return m_InvertSampleCoverage;
1087	}
1088
1089	inline bool RasterizerState :: IsPointSmoothEnabled() const {
1090		return m_Point.SmoothEnabled;
1091	}
1092
1093	inline bool RasterizerState :: IsLineSmoothEnabled() const {
1094		return m_Line.SmoothEnabled;
1095	}
1096
1097	inline bool RasterizerState :: IsEnabledAlphaTest() const {
1098		return m_Alpha.Enabled;
1099	}
1100
1101	inline bool RasterizerState :: IsEnabledDepthTest() const {
1102		return m_DepthTest.Enabled;
1103	}
1104
1105	inline bool RasterizerState :: IsEnabledLogicOp() const {
1106		return m_LogicOp.Enabled;
1107	}
1108
1109	inline bool RasterizerState :: IsEnabledScissorTest() const {
1110		return m_ScissorTest.Enabled;
1111	}
1112
1113	inline bool RasterizerState :: IsEnabledBlending() const {
1114		return m_Blend.Enabled;
1115	}
1116
1117	inline bool RasterizerState :: IsEnabledStencilTest() const {
1118		return m_Stencil.Enabled;
1119	}
1120
1121	inline bool RasterizerState :: IsEnabledTexture(size_t unit) const {
1122		return m_Texture[unit].Enabled;
1123	}
1124
1125	inline bool RasterizerState :: IsPointSpriteEnabled() const {
1126		return m_Point.SpriteEnabled;
1127	}
1128
1129	inline RasterizerState::LogicOp RasterizerState :: GetLogicOp() const {
1130		return m_LogicOp.Opcode;
1131	}
1132
1133	inline RasterizerState::ComparisonFunc RasterizerState :: GetAlphaFunc() const {
1134		return m_Alpha.Func;
1135	}
1136
1137	inline EGL_Fixed RasterizerState :: GetAlphaRef() const {
1138		return m_Alpha.Reference;
1139	}
1140
1141	inline RasterizerState::BlendFuncSrc RasterizerState :: GetBlendFuncSrc() const {
1142		return m_Blend.FuncSrc;
1143	}
1144
1145	inline RasterizerState::BlendFuncDst RasterizerState :: GetBlendFuncDst() const {
1146		return m_Blend.FuncDst;
1147	}
1148
1149	inline RasterizerState::ComparisonFunc RasterizerState :: GetDepthFunc() const {
1150		return m_DepthTest.Func;
1151	}
1152
1153	inline RasterizerState::ComparisonFunc RasterizerState :: GetStencilFunc() const {
1154		return m_Stencil.Func;
1155	}
1156
1157	inline I32 RasterizerState :: GetStencilRef() const {
1158		return m_Stencil.Reference;
1159	}
1160
1161	inline I32 RasterizerState :: GetStencilComparisonMask() const {
1162		return m_Stencil.ComparisonMask;
1163	}
1164
1165	inline RasterizerState::StencilOp RasterizerState :: GetStencilOpFail() const {
1166		return m_Stencil.Fail;
1167	}
1168
1169	inline RasterizerState::StencilOp RasterizerState :: GetStencilOpFailZFail() const {
1170		return m_Stencil.ZFail;
1171	}
1172
1173	inline RasterizerState::StencilOp RasterizerState :: GetStencilOpFailZPass() const {
1174		return m_Stencil.ZPass;
1175	}
1176
1177	inline void RasterizerState :: SetTextureCombineFuncRGB(size_t unit, TextureModeCombineFunc func) {
1178		m_Texture[unit].CombineFuncRGB = func;
1179	}
1180
1181	inline RasterizerState::TextureModeCombineFunc RasterizerState :: GetTextureCombineFuncRGB(size_t unit) const {
1182		return m_Texture[unit].CombineFuncRGB;
1183	}
1184
1185	inline void RasterizerState :: SetTextureCombineFuncAlpha(size_t unit, TextureModeCombineFunc func) {
1186		m_Texture[unit].CombineFuncAlpha = func;
1187	}
1188
1189	inline RasterizerState::TextureModeCombineFunc RasterizerState :: GetTextureCombineFuncAlpha(size_t unit) const {
1190		return m_Texture[unit].CombineFuncAlpha;
1191	}
1192
1193	inline void RasterizerState :: SetTextureCombineSrcRGB(size_t unit, size_t idx, TextureCombineSrc src) {
1194		m_Texture[unit].CombineSrcRGB[idx] = src;
1195	}
1196
1197	inline RasterizerState::TextureCombineSrc RasterizerState :: GetTextureCombineSrcRGB(size_t unit, size_t idx) const {
1198		return m_Texture[unit].CombineSrcRGB[idx];
1199	}
1200
1201	inline void RasterizerState :: SetTextureCombineSrcAlpha(size_t unit, size_t idx, TextureCombineSrc src) {
1202		m_Texture[unit].CombineSrcAlpha[idx] = src;
1203	}
1204
1205	inline RasterizerState::TextureCombineSrc RasterizerState :: GetTextureCombineSrcAlpha(size_t unit, size_t idx) const {
1206		return m_Texture[unit].CombineSrcAlpha[idx];
1207	}
1208
1209	inline void RasterizerState :: SetTextureCombineOpRGB(size_t unit, size_t idx, TextureCombineOp op) {
1210		m_Texture[unit].CombineOpRGB[idx] = op;
1211	}
1212
1213	inline RasterizerState::TextureCombineOp RasterizerState :: GetTextureCombineOpRGB(size_t unit, size_t idx) const {
1214		return m_Texture[unit].CombineOpRGB[idx];
1215	}
1216
1217	inline void RasterizerState :: SetTextureCombineOpAlpha(size_t unit, size_t idx, TextureCombineOp op) {
1218		m_Texture[unit].CombineOpAlpha[idx] = op;
1219	}
1220
1221	inline RasterizerState::TextureCombineOp RasterizerState :: GetTextureCombineOpAlpha(size_t unit, size_t idx) const {
1222		return m_Texture[unit].CombineOpAlpha[idx];
1223	}
1224
1225	inline void RasterizerState :: SetTextureScaleRGB(size_t unit, EGL_Fixed scale) {
1226		m_Texture[unit].ScaleRGB = scale;
1227	}
1228
1229	inline EGL_Fixed RasterizerState :: GetTextureScaleRGB(size_t unit) const {
1230		return m_Texture[unit].ScaleRGB;
1231	}
1232
1233	inline void RasterizerState :: SetTextureScaleAlpha(size_t unit, EGL_Fixed scale) {
1234		m_Texture[unit].ScaleAlpha = scale;
1235	}
1236
1237	inline EGL_Fixed RasterizerState :: GetTextureScaleAlpha(size_t unit) const {
1238		return m_Texture[unit].ScaleAlpha;
1239	}
1240
1241
1242}
1243
1244#endif //ndef EGL_RASTERIZER_STATE_H
1245