PageRenderTime 1206ms CodeModel.GetById 181ms app.highlight 832ms RepoModel.GetById 182ms app.codeStats 0ms

/opengles/src/Context.cpp

http://ftk.googlecode.com/
C++ | 1339 lines | 977 code | 298 blank | 64 comment | 78 complexity | 252f6380eda9bdc1e49d67a518fcf459 MD5 | raw file
   1// ==========================================================================
   2//
   3// context.cpp	Rendering Context Class for 3D Rendering Library
   4//
   5// --------------------------------------------------------------------------
   6//
   7// 08-07-2003	Hans-Martin Will	initial version
   8//
   9// --------------------------------------------------------------------------
  10//
  11// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
  12// 
  13// Redistribution and use in source and binary forms, with or without 
  14// modification, are permitted provided that the following conditions are 
  15// met:
  16// 
  17//	 *  Redistributions of source code must retain the above copyright
  18// 		notice, this list of conditions and the following disclaimer. 
  19//   *	Redistributions in binary form must reproduce the above copyright
  20// 		notice, this list of conditions and the following disclaimer in the 
  21// 		documentation and/or other materials provided with the distribution. 
  22// 
  23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
  25// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
  26// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
  27// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
  28// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  29// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
  31// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  32// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
  33// THE POSSIBILITY OF SUCH DAMAGE.
  34//
  35// ==========================================================================
  36
  37
  38#include "stdafx.h"
  39#include "Context.h"
  40#include "Surface.h"
  41#include "Rasterizer.h"
  42#include "Utils.h"
  43
  44
  45using namespace EGL;
  46
  47
  48// --------------------------------------------------------------------------
  49// Constructor and destructor
  50// --------------------------------------------------------------------------
  51
  52
  53Context :: Context(const Config & config) 
  54	:
  55	m_Config(config),
  56	m_DrawSurface(0),
  57	m_ReadSurface(0),
  58	m_LastError(GL_NO_ERROR),
  59
  60	// transformation matrices
  61	m_ModelViewMatrixStack(16),
  62	m_CurrentMatrixStack(&m_ModelViewMatrixStack),
  63	m_MatrixMode(GL_MODELVIEW),
  64	m_Scissor(0, 0, config.GetConfigAttrib(EGL_WIDTH), config.GetConfigAttrib(EGL_HEIGHT)),
  65	m_Viewport(0, 0, config.GetConfigAttrib(EGL_WIDTH), config.GetConfigAttrib(EGL_HEIGHT)),
  66	m_CurrentPaletteMatrix(0),
  67
  68	// server flags
  69	m_ClipPlaneEnabled(0),
  70	m_LightingEnabled(false),
  71	m_TwoSidedLightning(false),
  72	m_LightEnabled(0),				// no light on
  73	m_CullFaceEnabled(false),
  74	m_DitherEnabled(false),
  75	m_ReverseFaceOrientation(false),
  76	m_CullMode(CullModeBack),
  77	m_ColorMaterialEnabled(false),
  78	m_NormalizeEnabled(false),
  79	m_RescaleNormalEnabled(false),
  80	m_PolygonOffsetFillEnabled(false),
  81	m_MultiSampleEnabled(false),
  82	m_SampleAlphaToCoverageEnabled(false),
  83	m_SampleAlphaToOneEnabled(false),
  84	m_SampleCoverageEnabled(false),
  85	m_ScissorTestEnabled(false),
  86	m_MatrixPaletteEnabled(false),
  87	m_MatrixModePaletteEnabled(false),
  88	m_ActiveTexture(0),
  89	m_ClientActiveTexture(0),
  90
  91	// point parameters
  92	m_PointSize(EGL_ONE),
  93	m_PointSizeMin(EGL_ONE),
  94	m_PointSizeMax(EGL_ONE),		// what is the correct value?
  95	m_PointFadeThresholdSize(EGL_ONE),
  96	m_PointSizeAttenuate(false),
  97
  98	// fog parameters for setup phase
  99	m_FogMode(FogModeExp),
 100	m_FogStart(0),
 101	m_FogEnd(EGL_ONE),
 102	m_FogGradient(EGL_ONE),
 103	m_FogGradientShift(0),
 104	m_FogDensity(EGL_ONE),
 105
 106	// client flags
 107	m_VertexArrayEnabled(false),
 108	m_NormalArrayEnabled(false),
 109	m_ColorArrayEnabled(false),
 110	m_PointSizeArrayEnabled(false),
 111
 112	// buffers
 113	m_CurrentArrayBuffer(0),
 114	m_CurrentElementArrayBuffer(0),
 115
 116	// general context state
 117	m_Current(false),
 118	m_Disposed(false),
 119	m_ViewportInitialized(false),
 120	m_DefaultNormal(0, 0, EGL_ONE),
 121	m_DefaultRGBA(EGL_ONE, EGL_ONE, EGL_ONE, EGL_ONE),
 122
 123	// pixel store state
 124	m_PixelStorePackAlignment(4),
 125	m_PixelStoreUnpackAlignment(4),
 126
 127	// SGIS_generate_mipmap extension
 128	m_GenerateMipmaps(false),
 129
 130	// hints
 131	m_PerspectiveCorrectionHint(GL_DONT_CARE),
 132	m_PointSmoothHint(GL_DONT_CARE),
 133	m_LineSmoothHint(GL_DONT_CARE),
 134	m_FogHint(GL_DONT_CARE),
 135	m_GenerateMipmapHint(GL_DONT_CARE)
 136{
 137	DepthRangex(VIEWPORT_NEAR, VIEWPORT_FAR);
 138	ClearDepthx(EGL_ONE);
 139	ClearStencil(0);
 140
 141	m_Rasterizer = new Rasterizer(GetRasterizerState());	
 142	m_Buffers.Allocate();			// default buffer
 143
 144	m_LightModelAmbient.r = m_LightModelAmbient.g = m_LightModelAmbient.b = F(0.2f);
 145	m_LightModelAmbient.a = F(1.0);
 146
 147	m_Lights[0].SetDiffuseColor(FractionalColor(F(1.0), F(1.0), F(1.0), F(1.0)));
 148	m_Lights[0].SetSpecularColor(FractionalColor(F(1.0), F(1.0), F(1.0), F(1.0)));
 149
 150	m_PointDistanceAttenuation[0] = EGL_ONE;
 151	m_PointDistanceAttenuation[1] = 0;
 152	m_PointDistanceAttenuation[2] = 0;
 153
 154	size_t defaultTexture = m_Textures.Allocate();
 155
 156	for (size_t unit = 0; unit < EGL_NUM_TEXTURE_UNITS; ++unit) {
 157		m_TexCoordArrayEnabled[unit] = false;
 158		m_Rasterizer->SetTexture(unit, m_Textures.GetObject(defaultTexture));
 159	}
 160
 161	memset(&m_ClipPlanes, 0, sizeof(m_ClipPlanes));
 162}
 163
 164
 165Context :: ~Context() {
 166
 167	if (m_DrawSurface != 0) {
 168		m_DrawSurface->SetCurrentContext(0);
 169	}
 170
 171	if (m_ReadSurface != 0 && m_ReadSurface != m_DrawSurface) {
 172		m_ReadSurface->SetCurrentContext(0);
 173	}
 174
 175	m_ReadSurface = m_DrawSurface = 0;
 176
 177	if (m_Rasterizer != 0) {
 178
 179		delete m_Rasterizer;
 180		m_Rasterizer = 0;
 181	}
 182}
 183
 184
 185void Context :: SetReadSurface(EGL::Surface * surface) {
 186	if (m_ReadSurface != 0 && m_ReadSurface != m_DrawSurface && m_ReadSurface != surface) {
 187		m_ReadSurface->SetCurrentContext(0);
 188	}
 189
 190	m_ReadSurface = surface;
 191	m_ReadSurface->SetCurrentContext(this);
 192}
 193
 194
 195void Context :: SetDrawSurface(EGL::Surface * surface) {
 196	if (m_DrawSurface != 0 && m_ReadSurface != m_DrawSurface && m_DrawSurface != surface) {
 197		m_DrawSurface->SetCurrentContext(0);
 198	}
 199
 200	if (surface != 0 && !m_ViewportInitialized) {
 201		U16 width = surface->GetWidth();
 202		U16 height = surface->GetHeight();
 203
 204		Viewport(0, 0, width, height);
 205		Scissor(0, 0, width, height);
 206		m_ViewportInitialized = true;
 207	}
 208
 209	m_DrawSurface = surface;
 210	m_DrawSurface->SetCurrentContext(this);
 211	m_Rasterizer->SetSurface(surface);
 212
 213	UpdateScissorTest();
 214}
 215
 216
 217void Context :: Dispose() {
 218	if (m_Current) {
 219		m_Disposed = true;
 220	} else {
 221		delete this;
 222	}
 223}
 224
 225void Context :: SetCurrent(bool current) {
 226	m_Current = current;
 227
 228	if (!m_Current && m_Disposed) {
 229		delete this;
 230	}
 231}
 232
 233// --------------------------------------------------------------------------
 234// Error handling
 235// --------------------------------------------------------------------------
 236
 237
 238GLenum Context :: GetError(void) { 
 239	GLenum result = m_LastError;
 240	m_LastError = GL_NO_ERROR;
 241	return result;
 242}
 243
 244
 245void Context :: RecordError(GLenum error) {
 246	if (error != GL_NO_ERROR && m_LastError == GL_NO_ERROR) {
 247		m_LastError = error;
 248	}
 249}
 250
 251
 252// --------------------------------------------------------------------------
 253// Clearing
 254// --------------------------------------------------------------------------
 255
 256
 257void Context :: Clear(GLbitfield mask) { 
 258
 259	if (m_DrawSurface == 0) {
 260		return;
 261	}
 262
 263	if ((mask & (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != mask) {
 264		RecordError(GL_INVALID_VALUE);
 265		return;
 266	}
 267
 268	if (m_ScissorTestEnabled) {
 269		if (mask & GL_COLOR_BUFFER_BIT) {
 270			// is clamping [min, max] or [min, max)
 271			m_DrawSurface->ClearColorBuffer(m_ColorClearValue, 
 272				m_RasterizerState.GetColorMask(), m_Scissor);
 273		}
 274
 275		if (mask & GL_DEPTH_BUFFER_BIT) {
 276			// actually need to transform depth to correct value
 277			EGL_Fixed clearValue = EGL_MAP_0_1(m_DepthClearValue);
 278			m_DrawSurface->ClearDepthBuffer(clearValue, m_RasterizerState.GetDepthMask(), m_Scissor);
 279		}
 280
 281		if (mask & GL_STENCIL_BUFFER_BIT) {
 282			m_DrawSurface->ClearStencilBuffer(m_StencilClearValue, m_RasterizerState.GetStencilMask(), m_Scissor);
 283		}
 284	} else {
 285		if (mask & GL_COLOR_BUFFER_BIT) {
 286			// is clamping [min, max] or [min, max)
 287			m_DrawSurface->ClearColorBuffer(m_ColorClearValue, m_RasterizerState.GetColorMask());
 288		}
 289
 290		if (mask & GL_DEPTH_BUFFER_BIT) {
 291			// actually need to transform depth to correct value
 292			EGL_Fixed clearValue = EGL_MAP_0_1(m_DepthClearValue);
 293			m_DrawSurface->ClearDepthBuffer(clearValue, m_RasterizerState.GetDepthMask());
 294		}
 295
 296		if (mask & GL_STENCIL_BUFFER_BIT) {
 297			m_DrawSurface->ClearStencilBuffer(m_StencilClearValue, m_RasterizerState.GetStencilMask());
 298		}
 299	}
 300}
 301
 302
 303void Context :: ClearColorx(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) { 
 304	m_ColorClearValue = FractionalColor(red, green, blue, alpha);
 305}
 306
 307
 308void Context :: ClearDepthx(GLclampx depth) { 
 309	m_DepthClearValue = EGL_CLAMP(depth, 0, EGL_ONE);
 310}
 311
 312
 313void Context :: ClearStencil(GLint s) { 
 314	m_StencilClearValue = s;
 315}
 316
 317
 318// --------------------------------------------------------------------------
 319//
 320// --------------------------------------------------------------------------
 321
 322
 323void Context :: Toggle(GLenum cap, bool value) { 
 324	switch (cap) {
 325	case GL_LIGHTING:
 326		m_LightingEnabled = value;
 327		break;
 328
 329	case GL_FOG:
 330		GetRasterizerState()->EnableFog(value);
 331		break;
 332
 333	case GL_TEXTURE_2D:
 334		GetRasterizerState()->EnableTexture(m_ActiveTexture, value);
 335		break;
 336
 337	case GL_CULL_FACE:
 338		m_CullFaceEnabled = value;
 339		break;
 340
 341	case GL_ALPHA_TEST:
 342		GetRasterizerState()->EnableAlphaTest(value);
 343		break;
 344
 345	case GL_BLEND:
 346		GetRasterizerState()->EnableBlending(value);
 347		break;
 348
 349	case GL_COLOR_LOGIC_OP:
 350		GetRasterizerState()->EnableLogicOp(value);
 351		break;
 352
 353	case GL_DITHER:
 354		m_DitherEnabled = value;
 355		break;
 356
 357	case GL_STENCIL_TEST:
 358		GetRasterizerState()->EnableStencilTest(value);
 359		break;
 360
 361	case GL_DEPTH_TEST:
 362		GetRasterizerState()->EnableDepthTest(value);
 363		break;
 364
 365	case GL_LIGHT0:
 366	case GL_LIGHT1:
 367	case GL_LIGHT2:
 368	case GL_LIGHT3:
 369	case GL_LIGHT4:
 370	case GL_LIGHT5:
 371	case GL_LIGHT6:
 372	case GL_LIGHT7:
 373		{
 374			int mask = 1 << (cap - GL_LIGHT0);
 375
 376			if (value) {
 377				m_LightEnabled |= mask;
 378			} else {
 379				m_LightEnabled &= ~mask;
 380			}
 381		}
 382		break;
 383
 384	case GL_POINT_SMOOTH:
 385		GetRasterizerState()->SetPointSmoothEnabled(value);
 386		break;
 387
 388	case GL_POINT_SPRITE_OES:
 389		GetRasterizerState()->SetPointSpriteEnabled(value);
 390		break;
 391
 392	case GL_LINE_SMOOTH:
 393		GetRasterizerState()->SetLineSmoothEnabled(value);
 394		break;
 395
 396	case GL_SCISSOR_TEST:
 397		m_ScissorTestEnabled = value;
 398		UpdateScissorTest();
 399		break;
 400
 401	case GL_COLOR_MATERIAL:
 402		m_ColorMaterialEnabled = value;
 403		break;
 404
 405	case GL_NORMALIZE:
 406		m_NormalizeEnabled = value;
 407		break;
 408
 409	case GL_CLIP_PLANE0:
 410	case GL_CLIP_PLANE1:
 411	case GL_CLIP_PLANE2:
 412	case GL_CLIP_PLANE3:
 413	case GL_CLIP_PLANE4:
 414	case GL_CLIP_PLANE5:
 415		{
 416			size_t plane = cap - GL_CLIP_PLANE0;
 417			U32 mask = ~(1u << plane);
 418			U32 bit = value ? (1u << plane) : 0;
 419
 420			m_ClipPlaneEnabled = (m_ClipPlaneEnabled & mask) | bit;
 421		}
 422
 423		break;
 424
 425	case GL_RESCALE_NORMAL:
 426		m_RescaleNormalEnabled = value;
 427		UpdateInverseModelViewMatrix();
 428		break;
 429
 430	case GL_POLYGON_OFFSET_FILL:
 431		GetRasterizerState()->EnablePolygonOffsetFill(value);
 432		break;
 433
 434	case GL_MULTISAMPLE:
 435		m_MultiSampleEnabled = value;
 436		break;
 437
 438	case GL_SAMPLE_ALPHA_TO_COVERAGE:
 439		m_SampleAlphaToCoverageEnabled = value;
 440		break;
 441
 442	case GL_SAMPLE_ALPHA_TO_ONE:
 443		m_SampleAlphaToOneEnabled = value;
 444		break;
 445
 446	case GL_SAMPLE_COVERAGE:
 447		m_SampleCoverageEnabled = value;
 448		break;
 449
 450	case GL_MATRIX_PALETTE_OES:
 451		m_MatrixPaletteEnabled = value;
 452		break;
 453
 454	default:
 455		RecordError(GL_INVALID_ENUM);
 456		return;
 457	}
 458}
 459
 460void Context :: Disable(GLenum cap) { 
 461	Toggle(cap, false);
 462}
 463
 464void Context :: Enable(GLenum cap) { 
 465	Toggle(cap, true);
 466}
 467
 468void Context :: Hint(GLenum target, GLenum mode) { 
 469
 470	if (mode != GL_DONT_CARE && mode != GL_FASTEST && mode != GL_NICEST) {
 471		RecordError(GL_INVALID_ENUM);
 472		return;
 473	}
 474
 475	switch (target) {
 476	case GL_FOG_HINT:
 477		m_FogHint = mode;
 478		break;
 479
 480	case GL_LINE_SMOOTH_HINT:
 481		m_LineSmoothHint = mode;
 482		break;
 483
 484	case GL_PERSPECTIVE_CORRECTION_HINT:
 485		m_PerspectiveCorrectionHint = mode;
 486		break;
 487
 488	case GL_POINT_SMOOTH_HINT:
 489		m_PointSmoothHint = mode;
 490		break;
 491
 492	case GL_GENERATE_MIPMAP_HINT:
 493		m_GenerateMipmapHint = mode;
 494		break;
 495
 496	default:
 497		RecordError(GL_INVALID_ENUM);
 498		return;
 499	}
 500}
 501
 502namespace {
 503    static const GLenum formats[] = {
 504		GL_PALETTE4_RGB8_OES,
 505		GL_PALETTE4_RGBA8_OES,
 506		GL_PALETTE4_R5_G6_B5_OES,
 507		GL_PALETTE4_RGBA4_OES,
 508		GL_PALETTE4_RGB5_A1_OES,
 509		GL_PALETTE8_RGB8_OES,
 510		GL_PALETTE8_RGBA8_OES,
 511		GL_PALETTE8_R5_G6_B5_OES,
 512		GL_PALETTE8_RGBA4_OES,
 513		GL_PALETTE8_RGB5_A1_OES
 514    };
 515
 516	void CopyRect(const Rect & rect, GLint * params) {
 517		params[0] = rect.x;
 518		params[1] = rect.y;
 519		params[2] = rect.width;
 520		params[3] = rect.height;
 521	}
 522
 523	GLenum EnumFromComparisonFunc(RasterizerState::ComparisonFunc func) {
 524		switch (func) {
 525			case RasterizerState::CompFuncNever:	return GL_NEVER;
 526			case RasterizerState::CompFuncLess:		return GL_LESS;
 527			case RasterizerState::CompFuncLEqual:	return GL_LEQUAL;
 528			case RasterizerState::CompFuncGreater:	return GL_GREATER;
 529			case RasterizerState::CompFuncGEqual:	return GL_GEQUAL;
 530			case RasterizerState::CompFuncEqual:	return GL_EQUAL;
 531			case RasterizerState::CompFuncNotEqual:	return GL_NOTEQUAL;
 532			case RasterizerState::CompFuncAlways:	return GL_ALWAYS;
 533			default:								return 0;
 534		}
 535	}
 536
 537	GLenum EnumFromStencilOp(RasterizerState::StencilOp op) {
 538		switch (op) {
 539		case RasterizerState::StencilOpKeep:	return GL_KEEP;
 540		case RasterizerState::StencilOpZero:	return GL_ZERO;
 541		case RasterizerState::StencilOpReplace:	return GL_REPLACE;
 542		case RasterizerState::StencilOpIncr:	return GL_INCR;
 543		case RasterizerState::StencilOpDecr:	return GL_DECR;
 544		case RasterizerState::StencilOpInvert:	return GL_INVERT;
 545		default:								return 0;
 546		}
 547	}
 548
 549	GLenum EnumFromLogicOp(RasterizerState::LogicOp op) {
 550		switch (op) {
 551		case RasterizerState::LogicOpClear:			return GL_CLEAR;
 552		case RasterizerState::LogicOpAnd:			return GL_AND;
 553		case RasterizerState::LogicOpAndReverse:	return GL_AND_REVERSE;
 554		case RasterizerState::LogicOpCopy:			return GL_COPY;
 555		case RasterizerState::LogicOpAndInverted:	return GL_AND_INVERTED;
 556		case RasterizerState::LogicOpNoop:			return GL_NOOP;
 557		case RasterizerState::LogicOpXor:			return GL_XOR;
 558		case RasterizerState::LogicOpOr:			return GL_OR;
 559		case RasterizerState::LogicOpNor:			return GL_NOR;
 560		case RasterizerState::LogicOpEquiv:			return GL_EQUIV;
 561		case RasterizerState::LogicOpInvert:		return GL_INVERT;
 562		case RasterizerState::LogicOpOrReverse:		return GL_OR_REVERSE;
 563		case RasterizerState::LogicOpCopyInverted:	return GL_COPY_INVERTED;
 564		case RasterizerState::LogicOpOrInverted:	return GL_OR_INVERTED;
 565		case RasterizerState::LogicOpNand:			return GL_NAND;
 566		case RasterizerState::LogicOpSet:			return GL_SET;
 567		default:									return 0;
 568		}
 569	}
 570
 571	GLenum EnumFromBlendFuncSrc(RasterizerState::BlendFuncSrc sfactor) {
 572		switch (sfactor) {
 573		case RasterizerState::BlendFuncSrcZero:				return GL_ZERO;
 574		case RasterizerState::BlendFuncSrcOne:				return GL_ONE;
 575		case RasterizerState::BlendFuncSrcDstColor:			return GL_DST_COLOR;
 576		case RasterizerState::BlendFuncSrcOneMinusDstColor:	return GL_ONE_MINUS_DST_COLOR;
 577		case RasterizerState::BlendFuncSrcSrcAlpha:			return GL_SRC_ALPHA;
 578		case RasterizerState::BlendFuncSrcOneMinusSrcAlpha:	return GL_ONE_MINUS_SRC_ALPHA;
 579		case RasterizerState::BlendFuncSrcDstAlpha:			return GL_DST_ALPHA;
 580		case RasterizerState::BlendFuncSrcOneMinusDstAlpha:	return GL_ONE_MINUS_DST_ALPHA;
 581		case RasterizerState::BlendFuncSrcSrcAlphaSaturate:	return GL_SRC_ALPHA_SATURATE;
 582		default:											return 0;
 583		}
 584	}
 585
 586	GLenum EnumFromBlendFuncDst(RasterizerState::BlendFuncDst dfactor) {
 587		switch (dfactor) {
 588		case RasterizerState::BlendFuncDstZero:				return GL_ZERO;
 589		case RasterizerState::BlendFuncDstSrcColor:			return GL_SRC_COLOR;
 590		case RasterizerState::BlendFuncDstOneMinusSrcColor:	return GL_ONE_MINUS_SRC_COLOR;
 591		case RasterizerState::BlendFuncDstSrcAlpha:			return GL_SRC_ALPHA;
 592		case RasterizerState::BlendFuncDstOneMinusSrcAlpha:	return GL_ONE_MINUS_SRC_ALPHA;
 593		case RasterizerState::BlendFuncDstDstAlpha:			return GL_DST_ALPHA;
 594		case RasterizerState::BlendFuncDstOneMinusDstAlpha:	return GL_ONE_MINUS_DST_ALPHA;
 595		case RasterizerState::BlendFuncDstOne:				return GL_ONE;
 596		default:											return 0;
 597		}
 598	}
 599}
 600
 601
 602void Context :: GetIntegerv(GLenum pname, GLint *params) { 
 603	switch (pname) {
 604	/* 1.0 stuff */
 605	case GL_SMOOTH_LINE_WIDTH_RANGE:
 606	case GL_SMOOTH_POINT_SIZE_RANGE:
 607	case GL_ALIASED_POINT_SIZE_RANGE:
 608	case GL_ALIASED_LINE_WIDTH_RANGE:
 609		params[0] = params[1] = 1;
 610		return;
 611
 612	case GL_ALPHA_BITS:
 613		params[0] = m_Config.GetConfigAttrib(EGL_ALPHA_SIZE);
 614		break;
 615
 616	case GL_BLUE_BITS:
 617		params[0] = m_Config.GetConfigAttrib(EGL_BLUE_SIZE);
 618		break;
 619
 620	case GL_DEPTH_BITS:
 621		params[0] = m_Config.GetConfigAttrib(EGL_DEPTH_SIZE);
 622		break;
 623
 624	case GL_GREEN_BITS:
 625		params[0] = m_Config.GetConfigAttrib(EGL_GREEN_SIZE);
 626		break;
 627
 628	case GL_RED_BITS:
 629		params[0] = m_Config.GetConfigAttrib(EGL_RED_SIZE);
 630		break;
 631
 632	case GL_STENCIL_BITS:
 633		params[0] = m_Config.GetConfigAttrib(EGL_STENCIL_SIZE);
 634		break;
 635
 636	case GL_SUBPIXEL_BITS:
 637		params[0] = m_Config.GetConfigAttrib(EGL_SAMPLES);
 638		break;
 639
 640	case GL_COMPRESSED_TEXTURE_FORMATS:
 641		{
 642			size_t numFormats = sizeof(formats) / sizeof(formats[0]);
 643
 644			for (size_t index = 0; index < numFormats; ++index) 
 645				params[index] = formats[index];
 646		}
 647
 648		break;
 649
 650	case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
 651		params[0] = sizeof(formats) / sizeof(formats[0]);
 652		break;
 653
 654	case GL_MAX_ELEMENTS_INDICES:
 655	case GL_MAX_ELEMENTS_VERTICES:
 656		params[0] = INT_MAX;
 657		break;
 658
 659	case GL_MAX_LIGHTS:
 660		params[0] = EGL_NUMBER_LIGHTS;
 661		break;
 662
 663	case GL_MAX_CLIP_PLANES:
 664		params[0] = NUM_CLIP_PLANES;
 665		break;
 666
 667	case GL_MAX_MODELVIEW_STACK_DEPTH:
 668		params[0] = m_ModelViewMatrixStack.GetStackSize();
 669		break;
 670
 671	case GL_MODELVIEW_STACK_DEPTH:
 672		params[0] = m_ModelViewMatrixStack.GetCurrentStackSize();
 673		break;
 674
 675	case GL_MAX_PROJECTION_STACK_DEPTH:
 676		params[0] = m_ProjectionMatrixStack.GetStackSize();
 677		break;
 678
 679	case GL_PROJECTION_STACK_DEPTH:
 680		params[0] = m_ProjectionMatrixStack.GetCurrentStackSize();
 681		break;
 682
 683	case GL_MAX_TEXTURE_STACK_DEPTH:
 684		params[0] = m_TextureMatrixStack[m_ActiveTexture].GetStackSize();
 685		break;
 686
 687	case GL_TEXTURE_STACK_DEPTH:
 688		params[0] = m_TextureMatrixStack[m_ActiveTexture].GetCurrentStackSize();
 689		break;
 690
 691	case GL_MAX_TEXTURE_SIZE:
 692		params[0] = RasterizerState::MaxTextureSize;
 693		break;
 694
 695	case GL_MAX_TEXTURE_UNITS:
 696		params[0] = EGL_NUM_TEXTURE_UNITS;
 697		break;
 698
 699	case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
 700		params[0] = GL_UNSIGNED_SHORT_5_6_5;
 701		break;
 702
 703	case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
 704		params[0] = GL_RGB;
 705		break;
 706
 707	case GL_MAX_VIEWPORT_DIMS:
 708		params[0] = m_Config.m_Width;
 709		params[1] = m_Config.m_Height;
 710		break;
 711
 712	case GL_MAX_PALETTE_MATRICES_OES:
 713	case GL_MAX_VERTEX_UNITS_OES:
 714		params[0] = MATRIX_PALETTE_SIZE;
 715		break;
 716
 717//		params[0] = EGL_NUM_TEXTURE_UNITS;
 718//		break;
 719
 720	case GL_VERTEX_ARRAY_SIZE:
 721		params[0] = m_VertexArray.size;
 722		break;
 723
 724	case GL_VERTEX_ARRAY_STRIDE:
 725		params[0] = m_VertexArray.stride;
 726		break;
 727
 728	case GL_VERTEX_ARRAY_TYPE:
 729		params[0] = m_VertexArray.type;
 730		break;
 731
 732	case GL_NORMAL_ARRAY_STRIDE:
 733		params[0] = m_NormalArray.stride;
 734		break;
 735
 736	case GL_NORMAL_ARRAY_TYPE:
 737		params[0] = m_NormalArray.type;
 738		break;
 739
 740	case GL_COLOR_ARRAY_SIZE:
 741		params[0] = m_ColorArray.size;
 742		break;
 743
 744	case GL_COLOR_ARRAY_STRIDE:
 745		params[0] = m_ColorArray.stride;
 746		break;
 747
 748	case GL_COLOR_ARRAY_TYPE:
 749		params[0] = m_ColorArray.type;
 750		break;
 751
 752	case GL_TEXTURE_COORD_ARRAY_SIZE:
 753		params[0] = m_TexCoordArray[m_ClientActiveTexture].size;
 754		break;
 755
 756	case GL_TEXTURE_COORD_ARRAY_STRIDE:
 757		params[0] = m_TexCoordArray[m_ClientActiveTexture].stride;
 758		break;
 759
 760	case GL_TEXTURE_COORD_ARRAY_TYPE:
 761		params[0] = m_TexCoordArray[m_ClientActiveTexture].type;
 762		break;
 763
 764	case GL_MATRIX_INDEX_ARRAY_SIZE_OES:
 765		params[0] = m_MatrixIndexArray.size;
 766		break;
 767
 768	case GL_MATRIX_INDEX_ARRAY_TYPE_OES:
 769		params[0] = m_MatrixIndexArray.type;
 770		break;
 771
 772	case GL_MATRIX_INDEX_ARRAY_STRIDE_OES:
 773		params[0] = m_MatrixIndexArray.stride;
 774		break;
 775
 776	case GL_WEIGHT_ARRAY_SIZE_OES:
 777		params[0] = m_WeightArray.size;
 778		break;
 779
 780	case GL_WEIGHT_ARRAY_TYPE_OES:
 781		params[0] = m_WeightArray.type;
 782		break;
 783
 784	case GL_WEIGHT_ARRAY_STRIDE_OES:
 785		params[0] = m_WeightArray.stride;
 786		break;
 787
 788	case GL_POINT_SIZE_ARRAY_TYPE_OES:
 789		params[0] = m_PointSizeArray.type;
 790		break;
 791
 792	case GL_POINT_SIZE_ARRAY_STRIDE_OES:
 793		params[0] = m_PointSizeArray.stride;
 794		break;
 795
 796	case GL_VERTEX_ARRAY_BUFFER_BINDING:
 797		params[0] = m_VertexArray.boundBuffer;
 798		break;
 799
 800	case GL_NORMAL_ARRAY_BUFFER_BINDING:
 801		params[0] = m_NormalArray.boundBuffer;
 802		break;
 803
 804	case GL_COLOR_ARRAY_BUFFER_BINDING:
 805		params[0] = m_ColorArray.boundBuffer;
 806		break;
 807
 808	case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
 809		params[0] = m_TexCoordArray[m_ClientActiveTexture].boundBuffer;
 810		break;
 811
 812	case GL_ELEMENT_ARRAY_BUFFER_BINDING:
 813		params[0] = m_CurrentElementArrayBuffer;
 814		break;
 815
 816	case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
 817		params[0] = m_PointSizeArray.boundBuffer;
 818		break;
 819
 820	case GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES:
 821		params[0] = m_MatrixIndexArray.boundBuffer;
 822		break;
 823
 824	case GL_WEIGHT_ARRAY_BUFFER_BINDING_OES:
 825		params[0] = m_WeightArray.boundBuffer;
 826		break;
 827
 828	case GL_ARRAY_BUFFER_BINDING:
 829		params[0] = m_CurrentArrayBuffer;
 830		break;
 831
 832	case GL_UNPACK_ALIGNMENT:
 833		params[0] = m_PixelStoreUnpackAlignment;
 834		break;
 835
 836	case GL_PACK_ALIGNMENT:
 837		params[0] = m_PixelStorePackAlignment;
 838		break;
 839
 840	case GL_STENCIL_CLEAR_VALUE:
 841		params[0] = m_StencilClearValue;
 842		break;
 843
 844	case GL_DEPTH_CLEAR_VALUE:
 845		params[0] = EGL_Mul(0x7fffffff, m_DepthClearValue);
 846		break;
 847
 848	case GL_SCISSOR_BOX:
 849		CopyRect(m_Scissor, params);
 850		break;
 851
 852	case GL_SAMPLE_BUFFERS:
 853		params[0] = m_Config.m_SampleBuffers;
 854		break;
 855
 856	case GL_SAMPLES:
 857		params[0] = m_Config.m_Samples;
 858		break;
 859
 860	case GL_VIEWPORT:
 861		CopyRect(m_Viewport, params);
 862		break;
 863
 864	case GL_STENCIL_WRITEMASK:
 865		params[0] = m_RasterizerState.GetStencilMask();
 866		break;
 867
 868	case GL_STENCIL_VALUE_MASK:
 869		params[0] = m_RasterizerState.GetStencilComparisonMask();
 870		break;
 871
 872	case GL_STENCIL_REF:
 873		params[0] = m_RasterizerState.GetStencilRef();
 874		break;
 875
 876	case GL_ALPHA_TEST_REF:
 877		params[0] = EGL_Mul(0x7fffffff, m_RasterizerState.GetAlphaRef());
 878		break;
 879
 880	case GL_ALPHA_TEST_FUNC:
 881		params[0] = EnumFromComparisonFunc(m_RasterizerState.GetAlphaFunc());
 882		break;
 883
 884	case GL_STENCIL_FUNC:
 885		params[0] = EnumFromComparisonFunc(m_RasterizerState.GetStencilFunc());
 886		break;
 887
 888	case GL_STENCIL_FAIL:
 889		params[0] = EnumFromStencilOp(m_RasterizerState.GetStencilOpFail());
 890		break;
 891
 892	case GL_STENCIL_PASS_DEPTH_FAIL:
 893		params[0] = EnumFromStencilOp(m_RasterizerState.GetStencilOpFailZFail());
 894		break;
 895
 896	case GL_STENCIL_PASS_DEPTH_PASS:
 897		params[0] = EnumFromStencilOp(m_RasterizerState.GetStencilOpFailZPass());
 898		break;
 899
 900	case GL_DEPTH_FUNC:
 901		params[0] = EnumFromComparisonFunc(m_RasterizerState.GetDepthFunc());
 902		break;
 903
 904	case GL_LOGIC_OP_MODE:
 905		params[0] = EnumFromLogicOp(m_RasterizerState.GetLogicOp());
 906		break;
 907
 908	case GL_BLEND_SRC:
 909		params[0] = EnumFromBlendFuncSrc(m_RasterizerState.GetBlendFuncSrc());
 910		break;
 911
 912	case GL_BLEND_DST:
 913		params[0] = EnumFromBlendFuncDst(m_RasterizerState.GetBlendFuncDst());
 914		break;
 915
 916	case GL_FOG_MODE:
 917		{
 918			switch (m_FogMode) {
 919			case FogLinear:		params[0] = GL_LINEAR;	break;
 920			case FogModeExp:	params[0] = GL_EXP;		break;
 921			case FogModeExp2:	params[0] = GL_EXP2;	break;
 922			}
 923		}
 924
 925		break;
 926
 927	case GL_SHADE_MODEL:
 928		{
 929			switch (m_RasterizerState.GetShadeModel()) {
 930			case RasterizerState::ShadeModelFlat:	params[0] = GL_FLAT;
 931			case RasterizerState::ShadeModelSmooth:	params[0] = GL_SMOOTH;
 932			}
 933		}
 934
 935		break;
 936
 937	case GL_CULL_FACE_MODE:
 938		{
 939			switch (m_CullMode) {
 940			case CullModeFront:			params[0] = GL_FRONT;			break;
 941			case CullModeBack:			params[0] = GL_BACK;			break;
 942			case CullModeBackAndFront:	params[0] = GL_FRONT_AND_BACK;	break;
 943			}
 944		}
 945
 946		break;
 947
 948	case GL_FRONT_FACE:
 949		params[0] = m_ReverseFaceOrientation ? GL_CW : GL_CCW;
 950		break;
 951
 952	case GL_MATRIX_MODE:
 953		params[0] = m_MatrixMode;
 954		break;
 955
 956	case GL_ACTIVE_TEXTURE:
 957		params[0] = GL_TEXTURE0 + m_ActiveTexture;
 958		break;
 959
 960	case GL_CLIENT_ACTIVE_TEXTURE:
 961		params[0] = GL_TEXTURE0 + m_ClientActiveTexture;
 962		break;
 963
 964	case GL_TEXTURE_BINDING_2D:
 965		{
 966			size_t index = m_Textures.GetIndex(m_Rasterizer->GetTexture(m_ActiveTexture));
 967
 968			if (index == ~0) {
 969				params[0] = 0;
 970			} else {
 971				params[0] = index;
 972			}
 973		}
 974
 975		break;
 976
 977	case GL_COORD_REPLACE_OES:
 978		params[0] = m_RasterizerState.IsPointCoordReplaceEnabled(m_ActiveTexture);
 979		break;
 980
 981	case GL_CURRENT_COLOR:
 982		{
 983			params[0] = EGL_Mul(0x7fffffff, m_DefaultRGBA.r);
 984			params[1] = EGL_Mul(0x7fffffff, m_DefaultRGBA.g);
 985			params[2] = EGL_Mul(0x7fffffff, m_DefaultRGBA.b);
 986			params[3] = EGL_Mul(0x7fffffff, m_DefaultRGBA.a);
 987		}
 988
 989		break;
 990
 991	case GL_PERSPECTIVE_CORRECTION_HINT:
 992		params[0] = m_PerspectiveCorrectionHint;
 993		break;
 994
 995	case GL_POINT_SMOOTH_HINT:
 996		params[0] = m_PointSmoothHint;
 997		break;
 998
 999	case GL_LINE_SMOOTH_HINT:
1000		params[0] = m_LineSmoothHint;
1001		break;
1002
1003	case GL_FOG_HINT:
1004		params[0] = m_FogHint;
1005		break;
1006
1007	case GL_GENERATE_MIPMAP_HINT:
1008		params[0] = m_GenerateMipmapHint;
1009		break;
1010
1011	default:
1012		RecordError(GL_INVALID_ENUM);
1013	}
1014}
1015
1016
1017const GLubyte * Context :: GetString(GLenum name) { 
1018
1019	switch (name) {
1020	case GL_VENDOR:
1021		return (GLubyte *) EGL_CONFIG_VENDOR;
1022
1023	case GL_VERSION:
1024		return (GLubyte *) EGL_CONFIG_VERSION;
1025
1026	case GL_RENDERER:
1027		return (GLubyte *) EGL_CONFIG_RENDERER;
1028
1029	case GL_EXTENSIONS:
1030		return (GLubyte *) EGL_CONFIG_EXTENSIONS;
1031
1032	default:
1033		RecordError(GL_INVALID_ENUM);
1034		return 0;
1035	}
1036}
1037
1038void Context :: Finish(void) { }
1039void Context :: Flush(void) { }
1040
1041
1042void Context :: GetBooleanv(GLenum pname, GLboolean *params) {
1043	switch (pname) {
1044	case GL_LIGHT_MODEL_TWO_SIDE:
1045		params[0] = m_TwoSidedLightning;
1046		break;
1047
1048	case GL_COLOR_WRITEMASK:
1049		{
1050			Color mask = m_RasterizerState.GetColorMask();
1051			params[0] = mask.R() != 0;
1052			params[1] = mask.G() != 0;
1053			params[2] = mask.B() != 0;
1054			params[3] = mask.A() != 0;
1055		}
1056		break;
1057
1058	case GL_DEPTH_WRITEMASK:
1059		params[0] = m_RasterizerState.GetDepthMask();
1060		break;
1061
1062	case GL_SAMPLE_COVERAGE_INVERT:
1063		params[0] = m_RasterizerState.GetSampleCoverageInvert();
1064		break;
1065
1066	default:
1067		RecordError(GL_INVALID_ENUM);
1068		return;
1069	}
1070}
1071
1072
1073bool Context :: GetFixedv(GLenum pname, GLfixed *params) {
1074	switch (pname) {
1075	case GL_CURRENT_COLOR:
1076		CopyColor(m_DefaultRGBA, params);
1077		break;
1078
1079	case GL_CURRENT_TEXTURE_COORDS:
1080		CopyVector(m_DefaultTextureCoords[m_ActiveTexture], params);
1081		break;
1082
1083	case GL_CURRENT_NORMAL:
1084		params[0] = m_DefaultNormal.x();
1085		params[1] = m_DefaultNormal.y();
1086		params[2] = m_DefaultNormal.z();
1087		break;
1088
1089	case GL_MODELVIEW_MATRIX:
1090		CopyMatrix(m_ModelViewMatrixStack.CurrentMatrix(), params);
1091		break;
1092
1093	case GL_PROJECTION_MATRIX:
1094		CopyMatrix(m_ProjectionMatrixStack.CurrentMatrix(), params);
1095		break;
1096
1097	case GL_TEXTURE_MATRIX:
1098		CopyMatrix(m_TextureMatrixStack[m_ActiveTexture].CurrentMatrix(), params);
1099		break;
1100
1101	case GL_FOG_COLOR:
1102		CopyColor(m_RasterizerState.GetFogColor(), params);
1103		break;
1104
1105	case GL_FOG_DENSITY:
1106		params[0] = m_FogDensity;
1107		break;
1108
1109	case GL_FOG_START:
1110		params[0] = m_FogStart;
1111		break;
1112
1113	case GL_FOG_END:
1114		params[0] = m_FogEnd;
1115		break;
1116
1117	case GL_LIGHT_MODEL_AMBIENT:
1118		CopyColor(m_LightModelAmbient, params);
1119		break;
1120
1121	case GL_COLOR_CLEAR_VALUE:
1122		CopyColor(m_ColorClearValue, params);
1123		break;
1124
1125	case GL_ALIASED_LINE_WIDTH_RANGE:
1126	case GL_ALIASED_POINT_SIZE_RANGE:
1127	case GL_SMOOTH_LINE_WIDTH_RANGE:
1128	case GL_SMOOTH_POINT_SIZE_RANGE:
1129		params[0] = params[1] = EGL_ONE;
1130		break;
1131
1132	case GL_POLYGON_OFFSET_UNITS:
1133		params[0] = m_RasterizerState.GetPolygonOffsetUnits();
1134		break;
1135
1136	case GL_POLYGON_OFFSET_FACTOR:
1137		params[0] = m_RasterizerState.GetPolygonOffsetFactor();
1138		break;
1139
1140	case GL_SAMPLE_COVERAGE_VALUE:
1141		params[0] = m_RasterizerState.GetSampleCoverage();
1142		break;
1143
1144	case GL_POINT_SIZE_MIN:
1145		params[0] = m_PointSizeMin;
1146		break;
1147
1148	case GL_POINT_SIZE_MAX:
1149		params[0] = m_PointSizeMax;
1150		break;
1151
1152	case GL_POINT_FADE_THRESHOLD_SIZE:
1153		params[0] = m_PointFadeThresholdSize;
1154		break;
1155
1156	case GL_POINT_DISTANCE_ATTENUATION:
1157		params[0] = m_PointDistanceAttenuation[0];
1158		params[1] = m_PointDistanceAttenuation[1];
1159		params[2] = m_PointDistanceAttenuation[2];
1160		break;
1161
1162	case GL_DEPTH_RANGE:
1163		params[0] = m_DepthRangeNear;
1164		params[1] = m_DepthRangeFar;
1165		break;
1166
1167	case GL_POINT_SIZE:
1168	case GL_LINE_WIDTH:
1169		params[0] = EGL_ONE;
1170		break;
1171
1172	default:
1173		RecordError(GL_INVALID_ENUM);
1174		return false;
1175	}
1176
1177	return true;
1178}
1179
1180void Context :: GetPointerv(GLenum pname, void **params) {
1181	switch (pname) {
1182	case GL_VERTEX_ARRAY_POINTER:
1183		params[0] = const_cast<void *>(m_VertexArray.pointer);
1184		break;
1185
1186	case GL_NORMAL_ARRAY_POINTER:
1187		params[0] = const_cast<void *>(m_NormalArray.pointer);
1188		break;
1189
1190	case GL_COLOR_ARRAY_POINTER:
1191		params[0] = const_cast<void *>(m_ColorArray.pointer);
1192		break;
1193
1194	case GL_TEXTURE_COORD_ARRAY_POINTER:
1195		params[0] = const_cast<void *>(m_TexCoordArray[m_ClientActiveTexture].pointer);
1196		break;
1197
1198	case GL_MATRIX_INDEX_ARRAY_POINTER_OES:
1199		params[0] = const_cast<void *>(m_MatrixIndexArray.pointer);
1200		break;
1201
1202	case GL_WEIGHT_ARRAY_POINTER_OES:
1203		params[0] = const_cast<void *>(m_WeightArray.pointer);
1204		break;
1205
1206	case GL_POINT_SIZE_ARRAY_POINTER_OES:
1207		params[0] = const_cast<void *>(m_PointSizeArray.pointer);
1208		break;
1209
1210
1211	default:
1212		RecordError(GL_INVALID_ENUM);
1213		break;
1214	}
1215}
1216
1217GLboolean Context :: IsEnabled(GLenum cap) {
1218	switch (cap) {
1219	case GL_VERTEX_ARRAY:
1220		return m_VertexArrayEnabled;
1221
1222	case GL_NORMAL_ARRAY:
1223		return m_NormalArrayEnabled;
1224
1225	case GL_COLOR_ARRAY:
1226		return m_ColorArrayEnabled;
1227
1228	case GL_TEXTURE_COORD_ARRAY:
1229		return m_TexCoordArrayEnabled[m_ClientActiveTexture];
1230
1231	case GL_MATRIX_INDEX_ARRAY_OES:
1232		return m_MatrixIndexArrayEnabled;
1233
1234	case GL_WEIGHT_ARRAY_OES:
1235		return m_WeightArrayEnabled;
1236
1237	case GL_POINT_SIZE_ARRAY_OES:
1238		return m_PointSizeArrayEnabled;
1239
1240	case GL_NORMALIZE:
1241		return m_NormalizeEnabled;
1242
1243	case GL_RESCALE_NORMAL:
1244		return m_RescaleNormalEnabled;
1245
1246	case GL_LIGHT0:
1247	case GL_LIGHT1:
1248	case GL_LIGHT2:
1249	case GL_LIGHT3:
1250	case GL_LIGHT4:
1251	case GL_LIGHT5:
1252	case GL_LIGHT6:
1253	case GL_LIGHT7:
1254		{
1255			int mask = 1 << (cap - GL_LIGHT0);
1256			return (m_LightEnabled & mask) != 0;
1257		}
1258
1259	case GL_CLIP_PLANE0:
1260	case GL_CLIP_PLANE1:
1261	case GL_CLIP_PLANE2:
1262	case GL_CLIP_PLANE3:
1263	case GL_CLIP_PLANE4:
1264	case GL_CLIP_PLANE5:
1265		{
1266			U32 bit = 1u << (cap - GL_CLIP_PLANE0);
1267			return (m_ClipPlaneEnabled & bit) != 0;
1268		}
1269
1270		break;
1271
1272	case GL_FOG:
1273		return m_RasterizerState.IsEnabledFog();
1274
1275	case GL_LIGHTING:
1276		return m_LightingEnabled;
1277
1278	case GL_COLOR_MATERIAL:
1279		return m_ColorMaterialEnabled;
1280
1281	case GL_POINT_SMOOTH:
1282		return m_RasterizerState.IsPointSmoothEnabled();
1283
1284	case GL_LINE_SMOOTH:
1285		return m_RasterizerState.IsLineSmoothEnabled();
1286
1287	case GL_CULL_FACE:
1288		return m_CullFaceEnabled;
1289
1290	case GL_POLYGON_OFFSET_FILL:
1291		return m_RasterizerState.IsEnabledPolygonOffsetFill();
1292
1293	case GL_SCISSOR_TEST:
1294		return m_ScissorTestEnabled;
1295
1296	case GL_ALPHA_TEST:
1297		return m_RasterizerState.IsEnabledAlphaTest();
1298
1299	case GL_STENCIL_TEST:
1300		return m_RasterizerState.IsEnabledStencilTest();
1301
1302	case GL_DEPTH_TEST:
1303		return m_RasterizerState.IsEnabledDepthTest();
1304
1305	case GL_BLEND:
1306		return m_RasterizerState.IsEnabledBlending();
1307
1308	case GL_COLOR_LOGIC_OP:
1309		return m_RasterizerState.IsEnabledLogicOp();
1310
1311	case GL_TEXTURE_2D:
1312		return m_RasterizerState.IsEnabledTexture(m_ActiveTexture);
1313
1314	case GL_MATRIX_PALETTE_OES:
1315		return m_MatrixPaletteEnabled;
1316
1317	case GL_POINT_SPRITE_OES:
1318		return m_RasterizerState.IsPointSpriteEnabled();
1319
1320	case GL_MULTISAMPLE:
1321		return m_MultiSampleEnabled;
1322
1323	case GL_SAMPLE_ALPHA_TO_COVERAGE:
1324		return m_SampleAlphaToCoverageEnabled;
1325
1326	case GL_SAMPLE_ALPHA_TO_ONE:
1327		return m_SampleAlphaToOneEnabled;
1328
1329	case GL_SAMPLE_COVERAGE:
1330		return m_SampleCoverageEnabled;
1331
1332	case GL_DITHER:
1333		return m_DitherEnabled;
1334
1335	default:
1336		RecordError(GL_INVALID_ENUM);
1337		return false;
1338	}
1339}