Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
RasterizerState.OpenGL.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL
4 using System;
5 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
6 using OpenTK.Graphics.ES30;
7 #else
8 using OpenTK.Graphics.OpenGL;
9 #endif
10 
11 namespace SiliconStudio.Paradox.Graphics
12 {
13  public partial class RasterizerState
14  {
15 #if !SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
16  private PolygonMode polygonMode;
17 #endif
18 
19  private RasterizerState(GraphicsDevice device, RasterizerStateDescription rasterizerStateDescription) : base(device)
20  {
21  Description = rasterizerStateDescription;
22 
23 #if !SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
24  polygonMode = Description.FillMode == FillMode.Solid ? PolygonMode.Fill : PolygonMode.Line;
25 #endif
26 
27  // TODO: DepthBiasClamp and various other properties are not fully supported yet
28  if (Description.DepthBiasClamp != 0.0f) throw new NotSupportedException();
29  }
30 
31  /// <inheritdoc/>
32  protected internal override bool OnRecreate()
33  {
34  base.OnRecreate();
35  return true;
36  }
37 
38  public void Apply()
39  {
40 #if !SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
41  GL.PolygonMode(MaterialFace.FrontAndBack, polygonMode);
42 #endif
43  GL.PolygonOffset(Description.DepthBias, Description.SlopeScaleDepthBias);
44 
45  if (Description.CullMode == CullMode.None)
46  GL.Disable(EnableCap.CullFace);
47  else
48  {
49  GL.Enable(EnableCap.CullFace);
50  GL.CullFace(GetCullMode(Description.CullMode));
51  }
52 
53 
54  if (Description.ScissorTestEnable)
55  GL.Enable(EnableCap.ScissorTest);
56  else
57  GL.Disable(EnableCap.ScissorTest);
58  }
59 
60  public static CullFaceMode GetCullMode(CullMode cullMode)
61  {
62  switch (cullMode)
63  {
64  case CullMode.Front:
65  return CullFaceMode.Front;
66  case CullMode.Back:
67  return CullFaceMode.Back;
68  case CullMode.None:
69  default:
70  return CullFaceMode.FrontAndBack;
71  }
72  }
73  }
74 }
75 #endif
CullMode
Indicates triangles facing a particular direction are not drawn.
Definition: CullMode.cs:14