private void DrawView()
		{
			// TODO: RB_LogComment( "---------- RB_STD_DrawView ----------\n" );

			_depthFunction = MaterialStates.DepthFunctionEqual;

			DrawSurface[] surfaces = _viewDef.DrawSurfaces.ToArray();
			int surfaceCount = surfaces.Length;

			// clear the z buffer, set the projection matrix, etc
			BeginDrawingView();

			// decide how much overbrighting we are going to do
			// TODO: RB_DetermineLightScale();

			// fill the depth buffer and clear color buffer to black except on
			// subviews
			FillDepthBuffer(surfaces);

			// main light renderer
			/*switch( tr.backEndRenderer ) {
			case BE_ARB:
				RB_ARB_DrawInteractions();
				break;
			case BE_ARB2:
				RB_ARB2_DrawInteractions();
				break;
			case BE_NV20:
				RB_NV20_DrawInteractions();
				break;
			case BE_NV10:
				RB_NV10_DrawInteractions();
				break;
			case BE_R200:
				RB_R200_DrawInteractions();
				break;
			}*/

			// disable stencil shadow test			
			//Gl.glStencilFunc(Gl.GL_ALWAYS, 128, 255);

			// uplight the entire screen to crutch up not having better blending range
			// TODO: RB_STD_LightScale();

			// now draw any non-light dependent shading passes
			int processed = DrawMaterialPasses(surfaces);

			// fob and blend lights
			// TODO: RB_STD_FogAllLights();

			// now draw any post-processing effects using _currentRender
			if(processed < surfaceCount)
			{
				idConsole.Warning("TODO: RB_STD_DrawShaderPasses( drawSurfs+processed, numDrawSurfs-processed );");
			}

			/*RB_RenderDebugTools( drawSurfs, numDrawSurfs );*/
		}
		/// <summary>
		/// This routine is responsible for setting the most commonly changed state.
		/// </summary>
		/// <param name="state"></param>
		private void SetState(MaterialStates state)
		{
			MaterialStates diff;
			int srcFactor;
			int dstFactor;

			BlendState blendState = new BlendState();

			if((idE.CvarSystem.GetBool("r_useStateCaching") == false) || (_state.ForceState == true))
			{
				// make sure everything is set all the time, so we
				// can see if our delta checking is screwing up
				diff = MaterialStates.Invalid;
				_state.ForceState = false;
			}
			else
			{
				diff = state ^ _state.StateBits;

				if(diff == 0)
				{
					return;
				}
			}

			//
			// check depthFunc bits
			//
			if((diff & (MaterialStates.DepthFunctionEqual | MaterialStates.DepthFunctionLess | MaterialStates.DepthFunctionAlways)) != 0)
			{
				if((state & MaterialStates.DepthFunctionEqual) == MaterialStates.DepthFunctionEqual)
				{
					//idConsole.Warning("TODO: DepthFuncEqual");
					//  TODO: Gl.glDepthFunc(Gl.GL_EQUAL);
				}
				else if((state & MaterialStates.DepthFunctionAlways) == MaterialStates.DepthFunctionAlways)
				{
					//idConsole.Warning("TODO: DepthFuncAlways");
					// TODO: Gl.glDepthFunc(Gl.GL_ALWAYS);
				}
				else
				{
					//idConsole.Warning("TODO: DepthFuncLEqual");
					// TODO: Gl.glDepthFunc(Gl.GL_LEQUAL);
				}
			}

			//
			// check blend bits
			//
			if((diff & (MaterialStates.SourceBlendBits | MaterialStates.DestinationBlendBits)) != 0)
			{
				switch(state & MaterialStates.SourceBlendBits)
				{
					case MaterialStates.SourceBlendZero:
						blendState.AlphaSourceBlend = Blend.Zero;
						blendState.ColorSourceBlend = Blend.Zero;
						break;
					case MaterialStates.SourceBlendOne:
						blendState.AlphaSourceBlend = Blend.One;
						blendState.ColorSourceBlend = Blend.One;
						break;
					case MaterialStates.SourceBlendDestinationColor:
						blendState.AlphaSourceBlend = Blend.DestinationColor;
						blendState.ColorSourceBlend = Blend.DestinationColor;
						break;
					case MaterialStates.SourceBlendOneMinusDestinationColor:
						blendState.AlphaSourceBlend = Blend.InverseDestinationColor;
						blendState.ColorSourceBlend = Blend.InverseDestinationColor;
						break;
					case MaterialStates.SourceBlendSourceAlpha:
						blendState.AlphaSourceBlend = Blend.SourceAlpha;
						blendState.ColorSourceBlend = Blend.SourceAlpha;
						break;
					case MaterialStates.SourceBlendOneMinusSourceAlpha:
						blendState.AlphaSourceBlend = Blend.InverseSourceAlpha;
						blendState.ColorSourceBlend = Blend.InverseSourceAlpha;
						break;
					case MaterialStates.SourceBlendDestinationAlpha:
						blendState.AlphaSourceBlend = Blend.DestinationAlpha;
						blendState.ColorSourceBlend = Blend.DestinationAlpha;
						break;
					case MaterialStates.SourceBlendOneMinusDestinationAlpha:
						blendState.AlphaSourceBlend = Blend.InverseDestinationAlpha;
						blendState.ColorSourceBlend = Blend.InverseDestinationAlpha;
						break;
					case MaterialStates.SourceBlendAlphaSaturate:
						blendState.AlphaSourceBlend = Blend.SourceAlphaSaturation;
						blendState.ColorSourceBlend = Blend.SourceAlphaSaturation;
						break;
					default:
						idConsole.Error("GL_State: invalid source blend state bits");
						break;
				}

				switch(state & MaterialStates.DestinationBlendBits)
				{
					case MaterialStates.DestinationBlendZero:
						blendState.AlphaDestinationBlend = Blend.Zero;
						blendState.ColorDestinationBlend = Blend.Zero;
						break;
					case MaterialStates.DestinationBlendOne:
						blendState.AlphaDestinationBlend = Blend.One;
						blendState.ColorDestinationBlend = Blend.One;
						break;
					case MaterialStates.DestinationBlendSourceColor:
						blendState.AlphaDestinationBlend = Blend.SourceColor;
						blendState.ColorDestinationBlend = Blend.SourceColor;
						break;
					case MaterialStates.DestinationBlendOneMinusSourceColor:
						blendState.AlphaDestinationBlend = Blend.InverseSourceColor;
						blendState.ColorDestinationBlend = Blend.InverseSourceColor;
						break;
					case MaterialStates.DestinationBlendSourceAlpha:
						blendState.AlphaDestinationBlend = Blend.SourceAlpha;
						blendState.ColorDestinationBlend = Blend.SourceAlpha;
						break;
					case MaterialStates.DestinationBlendOneMinusSourceAlpha:
						blendState.AlphaDestinationBlend = Blend.InverseSourceAlpha;
						blendState.ColorDestinationBlend = Blend.InverseSourceAlpha;
						break;
					case MaterialStates.DestinationBlendDestinationAlpha:
						blendState.AlphaDestinationBlend = Blend.DestinationAlpha;
						blendState.ColorDestinationBlend = Blend.DestinationAlpha;
						break;
					case MaterialStates.DestinationBlendOneMinusDestinationAlpha:
						blendState.AlphaDestinationBlend = Blend.InverseDestinationAlpha;
						blendState.ColorDestinationBlend = Blend.InverseDestinationAlpha;
						break;
					default:
						idConsole.Error("GL_State: invalid dst blend state bits");
						break;
				}
			}

			//
			// check depthmask
			//
			if((diff & MaterialStates.DepthMask) == MaterialStates.DepthMask)
			{
				//idConsole.Warning("TODO: depthmask");
				if((state & MaterialStates.DepthMask) == MaterialStates.DepthMask)
				{
					// TODO: Gl.glDepthMask(Gl.GL_FALSE);
				}
				else
				{
					// TODO: Gl.glDepthMask(Gl.GL_TRUE);
				}
			}

			//
			// check colormask
			//
			if((diff & (MaterialStates.RedMask | MaterialStates.GreenMask | MaterialStates.BlueMask | MaterialStates.AlphaMask)) != 0)
			{
				ColorWriteChannels colorChannels = ColorWriteChannels.None;

				if((diff & MaterialStates.RedMask) == 0)
				{
					colorChannels |= ColorWriteChannels.Red;
				}

				if((diff & MaterialStates.GreenMask) == 0)
				{
					colorChannels |= ColorWriteChannels.Green;
				}

				if((diff & MaterialStates.BlueMask) == 0)
				{
					colorChannels |= ColorWriteChannels.Blue;
				}

				if((diff & MaterialStates.AlphaMask) == 0)
				{
					colorChannels |= ColorWriteChannels.Alpha;
				}

				blendState.ColorWriteChannels = colorChannels;
			}

			//
			// fill/line mode
			//
			if((diff & MaterialStates.PolygonModeLine) == MaterialStates.PolygonModeLine)
			{
				if((state & MaterialStates.PolygonModeLine) == MaterialStates.PolygonModeLine)
				{
					// TODO: Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE);					
				}
				else
				{
					// TODO: Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL);
				}
			}

			//
			// alpha test
			//
			if((diff & MaterialStates.AlphaTestBits) == MaterialStates.AlphaTestBits)
			{
				switch(state & MaterialStates.AlphaTestBits)
				{
					case 0:

						//_graphicsDevice.BlendState = BlendState.Opaque;
						break;

					case MaterialStates.AlphaTestEqual255:
						idConsole.Warning("TODO: glEnable ALPHA255");
						//Gl.glEnable(Gl.GL_ALPHA_TEST);
						//Gl.glAlphaFunc(Gl.GL_EQUAL, 1.0f);
						break;

					case MaterialStates.AlphaTestLessThan128:
						idConsole.Warning("TODO: glEnable ALPHA128");
						//Gl.glEnable(Gl.GL_ALPHA_TEST);
						//Gl.glAlphaFunc(Gl.GL_LESS, 0.5f);
						break;

					case MaterialStates.AlphaTestGreaterOrEqual128:
						idConsole.Warning("TODO: glEnable LEALPHA128");
						//Gl.glEnable(Gl.GL_ALPHA_TEST);
						//Gl.glAlphaFunc(Gl.GL_GEQUAL, 0.5f);
						break;

					default:
						break;
				}
			}

			_graphicsDevice.BlendState = blendState;

			_state.StateBits = state;
		}