Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AndroidParadoxGameView.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_PLATFORM_ANDROID
4 using System;
5 using SiliconStudio.Paradox.Graphics;
6 using Android.Content;
7 using OpenTK.Graphics;
8 using OpenTK.Platform.Android;
9 
10 namespace SiliconStudio.Paradox.Games.Android
11 {
12  public class AndroidParadoxGameView : AndroidGameView
13  {
14  public EventHandler<EventArgs> OnPause;
15 
16  public AndroidParadoxGameView(Context context) : base(context)
17  {
18  RequestedBackBufferFormat = PixelFormat.R8G8B8A8_UNorm;
19  RequestedDepthStencilFormat = PixelFormat.D24_UNorm_S8_UInt;
20  }
21 
22  /// <summary>
23  /// Gets or sets the requested back buffer format.
24  /// </summary>
25  /// <value>
26  /// The requested back buffer format.
27  /// </value>
28  public PixelFormat RequestedBackBufferFormat { get; set; }
29 
30  /// <summary>
31  /// Gets or sets the requested depth stencil format.
32  /// </summary>
33  /// <value>
34  /// The requested depth stencil format.
35  /// </value>
36  public PixelFormat RequestedDepthStencilFormat { get; set; }
37 
38  public override void Pause()
39  {
40  base.Pause();
41 
42  var handler = OnPause;
43  if (handler != null)
44  handler(this, EventArgs.Empty);
45  }
46 
47  protected override void CreateFrameBuffer()
48  {
49  // Request OpenGL ES 2.0
50  ContextRenderingApi = GLVersion.ES2;
51 
52  int requestedDepth = 0;
53  int requestedStencil = 0;
54  ColorFormat requestedColorFormat = 32;
55 
56  switch (RequestedBackBufferFormat)
57  {
58  case PixelFormat.R8G8B8A8_UNorm:
59  case PixelFormat.B8G8R8A8_UNorm:
60  requestedColorFormat = 32;
61  break;
62  case PixelFormat.B8G8R8X8_UNorm:
63  requestedColorFormat = 24;
64  break;
65  case PixelFormat.B5G6R5_UNorm:
66  requestedColorFormat = new ColorFormat(5, 6, 5, 0);
67  break;
68  case PixelFormat.B5G5R5A1_UNorm:
69  requestedColorFormat = new ColorFormat(5, 5, 5, 1);
70  break;
71  default:
72  throw new NotSupportedException("RequestedBackBufferFormat");
73  }
74 
75  switch (RequestedDepthStencilFormat)
76  {
77  case PixelFormat.D16_UNorm:
78  requestedDepth = 16;
79  break;
80  case PixelFormat.D24_UNorm_S8_UInt:
81  requestedDepth = 24;
82  requestedStencil = 8;
83  break;
84  case PixelFormat.D32_Float:
85  requestedDepth = 32;
86  break;
87  case PixelFormat.D32_Float_S8X24_UInt:
88  requestedDepth = 32;
89  requestedStencil = 8;
90  break;
91  default:
92  throw new NotSupportedException("RequestedDepthStencilFormat");
93  }
94 
95  try
96  {
97  GraphicsMode = new GraphicsMode(requestedColorFormat, requestedDepth, requestedStencil);
98  base.CreateFrameBuffer();
99  return;
100  }
101  catch (Exception)
102  {
103  // TODO: PDX-364: Log some warning message: "Could not create appropriate graphics mode"
104  }
105 
106  // Some devices only allow D16_S8, let's try it as well
107  if (requestedDepth > 16)
108  requestedDepth = 16;
109 
110  GraphicsMode = new GraphicsMode(requestedColorFormat, requestedDepth, requestedStencil);
111  base.CreateFrameBuffer();
112  }
113  }
114 }
115 #endif
PixelFormat
Defines various types of pixel formats.
Definition: PixelFormat.cs:32