1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics.ES20;
using OpenTK.Graphics.ES11;
using GL11 = OpenTK.Graphics.ES11.GL;
using GL20 = OpenTK.Graphics.ES20.GL;
using All11 = OpenTK.Graphics.ES11.All;
using All20 = OpenTK.Graphics.ES20.All;
namespace Microsoft.Xna.Framework.Graphics
{
public static class GLStateManager
{
private static GLStateEnabled _textureCoordArray;
private static GLStateEnabled _textures2D;
private static GLStateEnabled _vertextArray;
private static GLStateEnabled _colorArray;
private static GLStateEnabled _normalArray;
private static GLStateEnabled _depthTest;
private static All11 _blendFuncSource;
private static All11 _blendFuncDest;
private static All11 _cull = All11.Ccw; // default
public static void TextureCoordArray(bool enable)
{
if (enable && (_textureCoordArray != GLStateEnabled.True))
GL11.EnableClientState(All11.TextureCoordArray);
else
GL11.DisableClientState(All11.TextureCoordArray);
}
public static void VertexArray(bool enable)
{
if (enable && (_vertextArray != GLStateEnabled.True))
GL11.EnableClientState(All11.VertexArray);
else
GL11.DisableClientState(All11.VertexArray);
}
public static void ColorArray(bool enable)
{
if (enable && (_colorArray != GLStateEnabled.True))
GL11.EnableClientState(All11.ColorArray);
else
GL11.DisableClientState(All11.ColorArray);
}
public static void NormalArray(bool enable)
{
if (enable && (_normalArray != GLStateEnabled.True))
GL11.EnableClientState(All11.NormalArray);
else
GL11.DisableClientState(All11.NormalArray);
}
public static void Textures2D(bool enable)
{
if (enable && (_textures2D != GLStateEnabled.True))
GL11.Enable(All11.Texture2D);
else
GL11.Disable(All11.Texture2D);
}
public static void DepthTest(bool enable)
{
if (enable && (_depthTest != GLStateEnabled.True))
GL11.Enable(All11.DepthTest);
else
GL11.Disable(All11.DepthTest);
}
public static void Blend(bool enable)
{
GL11.Enable(All11.Blend);
}
public static void Viewport(Rectangle viewport)
{
GL11.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
}
public static void Projection(Matrix projection)
{
GL11.MatrixMode(All11.Projection);
GL11.LoadMatrix(ref projection.M11);
//GL11.Ortho(0, _device.DisplayMode.Width, _device.DisplayMode.Height, 0, -1, 1);
}
public static void WorldView(Matrix world, Matrix view)
{
GL11.MatrixMode(All11.Modelview);
GL11.LoadMatrix(ref view.M11);
GL11.MultMatrix(ref world.M11);
//GL11.Ortho(0, _device.DisplayMode.Width, _device.DisplayMode.Height, 0, -1, 1);
}
public static void Cull(All11 cullMode)
{
if (_cull != cullMode)
{
_cull = cullMode;
GL11.Enable(_cull);
}
}
public static void BlendFunc(All11 source, All11 dest)
{
if (source != _blendFuncSource && dest != _blendFuncDest)
{
source = _blendFuncSource;
dest = _blendFuncDest;
GL11.BlendFunc(source, dest);
}
}
}
public enum GLStateEnabled
{
False,
True,
NotSet
}
}
|