Ejemplo n.º 1
0
 public StageConfig(string name, int width, int height)
 {
     this.name    = name;
     this.width   = width;
     this.height  = height;
     this.terrain = new SurfaceConfig(width, height);
 }
Ejemplo n.º 2
0
						public SurfaceConfig(SurfaceConfig surfaceConfig) /* MethodBuilder.Create */ 
						{
						}
Ejemplo n.º 3
0
        protected void CreateGLContext()
        {
            lostglContext = false;

            egl = EGLContext.EGL.JavaCast <IEGL10>();

            eglDisplay = egl.EglGetDisplay(EGL10.EglDefaultDisplay);
            if (eglDisplay == EGL10.EglNoDisplay)
            {
                throw new Exception("Could not get EGL display" + GetErrorAsString());
            }

            int[] version = new int[2];
            if (!egl.EglInitialize(eglDisplay, version))
            {
                throw new Exception("Could not initialize EGL display" + GetErrorAsString());
            }

            int depth   = 0;
            int stencil = 0;

            switch (_game.graphicsDeviceManager.PreferredDepthStencilFormat)
            {
            case DepthFormat.Depth16:
                depth = 16;
                break;

            case DepthFormat.Depth24:
                depth = 24;
                break;

            case DepthFormat.Depth24Stencil8:
                depth   = 24;
                stencil = 8;
                break;

            case DepthFormat.None:
                break;
            }

            List <SurfaceConfig> configs = new List <SurfaceConfig>();

            if (depth > 0)
            {
                configs.Add(new SurfaceConfig()
                {
                    Red = 8, Green = 8, Blue = 8, Alpha = 8, Depth = depth, Stencil = stencil
                });
                configs.Add(new SurfaceConfig()
                {
                    Red = 5, Green = 6, Blue = 5, Depth = depth, Stencil = stencil
                });
                configs.Add(new SurfaceConfig()
                {
                    Depth = depth, Stencil = stencil
                });
                if (depth > 16)
                {
                    configs.Add(new SurfaceConfig()
                    {
                        Red = 8, Green = 8, Blue = 8, Alpha = 8, Depth = 16
                    });
                    configs.Add(new SurfaceConfig()
                    {
                        Red = 5, Green = 6, Blue = 5, Depth = 16
                    });
                    configs.Add(new SurfaceConfig()
                    {
                        Depth = 16
                    });
                }
                configs.Add(new SurfaceConfig()
                {
                    Red = 8, Green = 8, Blue = 8, Alpha = 8
                });
                configs.Add(new SurfaceConfig()
                {
                    Red = 5, Green = 6, Blue = 5
                });
            }
            else
            {
                configs.Add(new SurfaceConfig()
                {
                    Red = 8, Green = 8, Blue = 8, Alpha = 8
                });
                configs.Add(new SurfaceConfig()
                {
                    Red = 5, Green = 6, Blue = 5
                });
            }
            configs.Add(new SurfaceConfig()
            {
                Red = 4, Green = 4, Blue = 4
            });
            int[]       numConfigs = new int[1];
            EGLConfig[] results    = new EGLConfig[1];

            if (!egl.EglGetConfigs(eglDisplay, null, 0, numConfigs))
            {
                throw new Exception("Could not get config count. " + GetErrorAsString());
            }

            EGLConfig[] cfgs = new EGLConfig[numConfigs[0]];
            egl.EglGetConfigs(eglDisplay, cfgs, numConfigs[0], numConfigs);
            Log.Verbose("AndroidGameView", "Device Supports");
            foreach (var c in cfgs)
            {
                Log.Verbose("AndroidGameView", string.Format(" {0}", SurfaceConfig.FromEGLConfig(c, egl, eglDisplay)));
            }

            bool found = false;

            numConfigs[0] = 0;
            foreach (var config in configs)
            {
                Log.Verbose("AndroidGameView", string.Format("Checking Config : {0}", config));
                found = egl.EglChooseConfig(eglDisplay, config.ToConfigAttribs(), results, 1, numConfigs);
                Log.Verbose("AndroidGameView", "EglChooseConfig returned {0} and {1}", found, numConfigs[0]);
                if (!found || numConfigs[0] <= 0)
                {
                    Log.Verbose("AndroidGameView", "Config not supported");
                    continue;
                }
                Log.Verbose("AndroidGameView", string.Format("Selected Config : {0}", config));
                break;
            }

            if (!found || numConfigs[0] <= 0)
            {
                throw new Exception("No valid EGL configs found" + GetErrorAsString());
            }
            var createdVersion = new EW.Framework.GLESVersion();

            foreach (var v in EW.Framework.GLESVersion.GetSupportedGLESVersions())
            {
                Log.Verbose("AndroidGameView", "Creating GLES {0} Context", v);
                eglContext = egl.EglCreateContext(eglDisplay, results[0], EGL10.EglNoContext, v.GetAttributes());
                if (eglContext == null || eglContext == EGL10.EglNoContext)
                {
                    Log.Verbose("AndroidGameView", string.Format("GLES {0} Not Supported. {1}", v, GetErrorAsString()));
                    eglContext = EGL10.EglNoContext;
                    continue;
                }
                createdVersion = v;
                break;
            }
            if (eglContext == null || eglContext == EGL10.EglNoContext)
            {
                eglContext = null;
                throw new Exception("Could not create EGL context" + GetErrorAsString());
            }
            Log.Verbose("AndroidGameView", "Created GLES {0} Context", createdVersion);
            eglConfig          = results[0];
            glContextAvailable = true;
        }