00001 #region License
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #endregion
00027
00028 using System;
00029 using System.Collections.Generic;
00030 using System.Text;
00031 using OpenTK.Graphics;
00032
00033 namespace OpenTK.Platform.Egl
00034 {
00035 class EglGraphicsMode : IGraphicsMode
00036 {
00037 #region IGraphicsMode Members
00038
00039 public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
00040 {
00041 IntPtr[] configs = new IntPtr[1];
00042 int[] attribList = new int[]
00043 {
00044
00045
00046 Egl.RED_SIZE, color.Red,
00047 Egl.GREEN_SIZE, color.Green,
00048 Egl.BLUE_SIZE, color.Blue,
00049 Egl.ALPHA_SIZE, color.Alpha,
00050
00051 Egl.DEPTH_SIZE, depth > 0 ? depth : 0,
00052 Egl.STENCIL_SIZE, stencil > 0 ? stencil : 0,
00053
00054
00055 Egl.SAMPLES, samples > 0 ? samples : 0,
00056
00057 Egl.NONE,
00058 };
00059
00060
00061 IntPtr display = Egl.GetDisplay(IntPtr.Zero);
00062 int major, minor;
00063 if (!Egl.Initialize(display, out major, out minor))
00064 throw new GraphicsModeException(String.Format("Failed to initialize display connection, error {0}", Egl.GetError()));
00065
00066 int num_configs;
00067 if (!Egl.GetConfigs(display, null, 0, out num_configs))
00068 {
00069 throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode configurations, error {0}", Egl.GetError()));
00070 }
00071
00072 if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs))
00073 {
00074 throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError()));
00075 }
00076
00077
00078 IntPtr active_config = configs[0];
00079 int r, g, b, a;
00080 Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r);
00081 Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g);
00082 Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b);
00083 Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a);
00084 int d, s;
00085 Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d);
00086 Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s);
00087 int sample_buffers;
00088 Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers);
00089 Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples);
00090
00091 return new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false);
00092 }
00093
00094 #endregion
00095 }
00096 }