Panda3D
 All Classes Functions Variables Enumerations
androidGraphicsPipe.cxx
1 // Filename: androidGraphicsPipe.cxx
2 // Created by: rdb (11Jan13)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 //#include "androidGraphicsBuffer.h"
16 #include "androidGraphicsPipe.h"
17 //#include "androidGraphicsPixmap.h"
18 #include "androidGraphicsWindow.h"
19 #include "androidGraphicsStateGuardian.h"
20 #include "config_androiddisplay.h"
21 #include "frameBufferProperties.h"
22 
23 TypeHandle AndroidGraphicsPipe::_type_handle;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: AndroidGraphicsPipe::Constructor
27 // Access: Public
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 AndroidGraphicsPipe::
31 AndroidGraphicsPipe() {
32  _is_valid = false;
33  _supported_types = OT_window | OT_buffer | OT_texture_buffer;
34  _egl_display = NULL;
35 
36  _display_width = 0;
37  _display_height = 0;
38 
39  _egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
40  if (!eglInitialize(_egl_display, NULL, NULL)) {
41  androiddisplay_cat.error()
42  << "Couldn't initialize the EGL display: "
43  << get_egl_error_string(eglGetError()) << "\n";
44  }
45 
46  if (!eglBindAPI(EGL_OPENGL_ES_API)) {
47  androiddisplay_cat.error()
48  << "Couldn't bind EGL to the OpenGL ES API: "
49  << get_egl_error_string(eglGetError()) << "\n";
50  }
51 
52  _is_valid = true;
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: AndroidGraphicsPipe::Destructor
57 // Access: Public, Virtual
58 // Description:
59 ////////////////////////////////////////////////////////////////////
60 AndroidGraphicsPipe::
61 ~AndroidGraphicsPipe() {
62  if (_egl_display) {
63  if (!eglTerminate(_egl_display)) {
64  androiddisplay_cat.error() << "Failed to terminate EGL display: "
65  << get_egl_error_string(eglGetError()) << "\n";
66  }
67  }
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: AndroidGraphicsPipe::get_interface_name
72 // Access: Published, Virtual
73 // Description: Returns the name of the rendering interface
74 // associated with this GraphicsPipe. This is used to
75 // present to the user to allow him/her to choose
76 // between several possible GraphicsPipes available on a
77 // particular platform, so the name should be meaningful
78 // and unique for a given platform.
79 ////////////////////////////////////////////////////////////////////
82  return "OpenGL ES";
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: AndroidGraphicsPipe::pipe_constructor
87 // Access: Public, Static
88 // Description: This function is passed to the GraphicsPipeSelection
89 // object to allow the user to make a default
90 // AndroidGraphicsPipe.
91 ////////////////////////////////////////////////////////////////////
93 pipe_constructor() {
94  return new AndroidGraphicsPipe;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: AndroidGraphicsPipe::get_preferred_window_thread
99 // Access: Public, Virtual
100 // Description: Returns an indication of the thread in which this
101 // GraphicsPipe requires its window processing to be
102 // performed: typically either the app thread (e.g. X)
103 // or the draw thread (Windows).
104 ////////////////////////////////////////////////////////////////////
105 GraphicsPipe::PreferredWindowThread
107  // Most of the Android NDK window functions can be
108  // called from any thread. Since we're creating the
109  // context at open_window time, let's choose "draw".
110  return PWT_app;
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: AndroidGraphicsPipe::make_output
115 // Access: Protected, Virtual
116 // Description: Creates a new window on the pipe, if possible.
117 ////////////////////////////////////////////////////////////////////
119 make_output(const string &name,
120  const FrameBufferProperties &fb_prop,
121  const WindowProperties &win_prop,
122  int flags,
123  GraphicsEngine *engine,
125  GraphicsOutput *host,
126  int retry,
127  bool &precertify) {
128 
129  if (!_is_valid) {
130  return NULL;
131  }
132 
133  AndroidGraphicsStateGuardian *androidgsg = 0;
134  if (gsg != 0) {
135  DCAST_INTO_R(androidgsg, gsg, NULL);
136  }
137 
138  // First thing to try: an eglGraphicsWindow
139 
140  if (retry == 0) {
141  if (((flags&BF_require_parasite)!=0)||
142  ((flags&BF_refuse_window)!=0)||
143  ((flags&BF_resizeable)!=0)||
144  ((flags&BF_size_track_host)!=0)||
145  ((flags&BF_rtt_cumulative)!=0)||
146  ((flags&BF_can_bind_color)!=0)||
147  ((flags&BF_can_bind_every)!=0)) {
148  return NULL;
149  }
150  return new AndroidGraphicsWindow(engine, this, name, fb_prop, win_prop,
151  flags, gsg, host);
152  }
153 
154  // Second thing to try: a GLES(2)GraphicsBuffer
155  /*if (retry == 1) {
156  if ((host==0)||
157  // (!gl_support_fbo)||
158  ((flags&BF_require_parasite)!=0)||
159  ((flags&BF_require_window)!=0)) {
160  return NULL;
161  }
162  // Early failure - if we are sure that this buffer WONT
163  // meet specs, we can bail out early.
164  if ((flags & BF_fb_props_optional)==0) {
165  if ((fb_prop.get_indexed_color() > 0)||
166  (fb_prop.get_back_buffers() > 0)||
167  (fb_prop.get_accum_bits() > 0)||
168  (fb_prop.get_multisamples() > 0)) {
169  return NULL;
170  }
171  }
172  // Early success - if we are sure that this buffer WILL
173  // meet specs, we can precertify it.
174  if ((eglgsg != 0) &&
175  (eglgsg->is_valid()) &&
176  (!eglgsg->needs_reset()) &&
177  (eglgsg->_supports_framebuffer_object) &&
178  (eglgsg->_glDrawBuffers != 0)&&
179  (fb_prop.is_basic())) {
180  precertify = true;
181  }
182 #ifdef OPENGLES_2
183  return new GLES2GraphicsBuffer(engine, this, name, fb_prop, win_prop,
184  flags, gsg, host);
185 #else
186  return new GLESGraphicsBuffer(engine, this, name, fb_prop, win_prop,
187  flags, gsg, host);
188 #endif
189  }
190 
191  // Third thing to try: a eglGraphicsBuffer
192  if (retry == 2) {
193  if (((flags&BF_require_parasite)!=0)||
194  ((flags&BF_require_window)!=0)||
195  ((flags&BF_resizeable)!=0)||
196  ((flags&BF_size_track_host)!=0)) {
197  return NULL;
198  }
199 
200  if (!support_rtt) {
201  if (((flags&BF_rtt_cumulative)!=0)||
202  ((flags&BF_can_bind_every)!=0)) {
203  // If we require Render-to-Texture, but can't be sure we
204  // support it, bail.
205  return NULL;
206  }
207  }
208 
209  return new eglGraphicsBuffer(engine, this, name, fb_prop, win_prop,
210  flags, gsg, host);
211  }
212 
213  // Fourth thing to try: an eglGraphicsPixmap.
214  if (retry == 3) {
215  if (((flags&BF_require_parasite)!=0)||
216  ((flags&BF_require_window)!=0)||
217  ((flags&BF_resizeable)!=0)||
218  ((flags&BF_size_track_host)!=0)) {
219  return NULL;
220  }
221 
222  if (((flags&BF_rtt_cumulative)!=0)||
223  ((flags&BF_can_bind_every)!=0)) {
224  return NULL;
225  }
226 
227  return new eglGraphicsPixmap(engine, this, name, fb_prop, win_prop,
228  flags, gsg, host);
229  }*/
230 
231  // Nothing else left to try.
232  return NULL;
233 }
This graphics pipe represents the interface for creating OpenGL ES graphics windows on an X-based (e...
virtual string get_interface_name() const
Returns the name of the rendering interface associated with this GraphicsPipe.
virtual PreferredWindowThread get_preferred_window_thread() const
Returns an indication of the thread in which this GraphicsPipe requires its window processing to be p...
An interface to manage Android windows and their appropriate EGL surfaces.
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
This is a base class for the various different classes that represent the result of a frame of render...
A tiny specialization on GLESGraphicsStateGuardian to add some egl-specific information.
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...