protected override void Initialize(GameContext <iOSWindow> gameContext) { gameForm = gameContext.Control.GameView; nativeWindow = new WindowHandle(AppContextType.iOS, gameForm, gameForm.Handle); gameForm.Load += gameForm_Load; gameForm.Unload += gameForm_Unload; gameForm.RenderFrame += gameForm_RenderFrame; // get the OpenGL ES version var contextAvailable = false; foreach (var version in OpenGLUtils.GetGLVersions(gameContext.RequestedGraphicsProfile)) { var contextRenderingApi = MajorVersionTOEAGLRenderingAPI(version); EAGLContext contextTest = null; try { contextTest = new EAGLContext(contextRenderingApi); // delete extra context if (contextTest != null) { contextTest.Dispose(); } gameForm.ContextRenderingApi = contextRenderingApi; contextAvailable = true; break; } catch (Exception) { // TODO: log message } } if (!contextAvailable) { throw new Exception("Graphics context could not be created."); } gameForm.LayerColorFormat = EAGLColorFormat.RGBA8; //gameForm.LayerRetainsBacking = false; currentOrientation = UIApplication.SharedApplication.StatusBarOrientation; }
protected override void CreateFrameBuffer() { int requestedDepth = 0; int requestedStencil = 0; ColorFormat requestedColorFormat = 32; switch (RequestedBackBufferFormat) { case PixelFormat.R8G8B8A8_UNorm: case PixelFormat.B8G8R8A8_UNorm: requestedColorFormat = 32; break; case PixelFormat.B8G8R8X8_UNorm: requestedColorFormat = 24; break; case PixelFormat.B5G6R5_UNorm: requestedColorFormat = new ColorFormat(5, 6, 5, 0); break; case PixelFormat.B5G5R5A1_UNorm: requestedColorFormat = new ColorFormat(5, 5, 5, 1); break; default: throw new NotSupportedException("RequestedBackBufferFormat"); } switch (RequestedDepthStencilFormat) { case PixelFormat.None: break; case PixelFormat.D16_UNorm: requestedDepth = 16; break; case PixelFormat.D24_UNorm_S8_UInt: requestedDepth = 24; requestedStencil = 8; break; case PixelFormat.D32_Float: requestedDepth = 32; break; case PixelFormat.D32_Float_S8X24_UInt: requestedDepth = 32; requestedStencil = 8; break; default: throw new NotSupportedException("RequestedDepthStencilFormat"); } // Some devices only allow D16_S8, let's try it as well // D24 and D32 are supported on OpenGL ES 3 devices var requestedDepthFallback = requestedDepth > 16 ? 16 : requestedDepth; foreach (var version in OpenGLUtils.GetGLVersions(RequestedGraphicsProfile)) { if (TryCreateFrameBuffer(MajorVersionToGLVersion(version), requestedColorFormat, requestedDepth, requestedStencil) || TryCreateFrameBuffer(MajorVersionToGLVersion(version), requestedColorFormat, requestedDepthFallback, requestedStencil)) { return; } } throw new Exception("Unable to create a graphics context on the device. Maybe you should lower the preferred GraphicsProfile."); }
internal override void Initialize(GameContext gameContext) { GameContext = gameContext; gameForm = gameContext.GameView; nativeWindow = new WindowHandle(AppContextType.iOS, gameForm); gameForm.Load += gameForm_Load; gameForm.Unload += gameForm_Unload; gameForm.RenderFrame += gameForm_RenderFrame; // get the OpenGL ES version var contextAvailable = false; foreach (var version in OpenGLUtils.GetGLVersions(gameContext.RequestedGraphicsProfile)) { var contextRenderingApi = MajorVersionTOEAGLRenderingAPI(version); EAGLContext contextTest = null; try { contextTest = new EAGLContext(contextRenderingApi); // delete extra context if (contextTest != null) { contextTest.Dispose(); } gameForm.ContextRenderingApi = contextRenderingApi; contextAvailable = true; } catch (Exception) { // TODO: log message } } if (!contextAvailable) { throw new Exception("Graphics context could not be created."); } gameForm.LayerColorFormat = MonoTouch.OpenGLES.EAGLColorFormat.RGBA8; //gameForm.LayerRetainsBacking = false; // Setup the initial size of the window var width = gameContext.RequestedWidth; if (width == 0) { width = (int)(gameForm.Size.Width * gameForm.ContentScaleFactor); } var height = gameContext.RequestedHeight; if (height == 0) { height = (int)(gameForm.Size.Height * gameForm.ContentScaleFactor); } gameForm.Size = new Size(width, height); //gameForm.Resize += OnClientSizeChanged; }