Panda3D
eglGraphicsPipe.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file eglGraphicsPipe.cxx
10  * @author rdb
11  * @date 2009-05-21
12  */
13 
14 #include "eglGraphicsBuffer.h"
15 #include "eglGraphicsPipe.h"
16 #include "eglGraphicsPixmap.h"
17 #include "eglGraphicsWindow.h"
19 #include "config_egldisplay.h"
20 #include "frameBufferProperties.h"
21 
22 TypeHandle eglGraphicsPipe::_type_handle;
23 
24 /**
25  *
26  */
27 eglGraphicsPipe::
28 eglGraphicsPipe(const std::string &display) : x11GraphicsPipe(display) {
29  _egl_display = eglGetDisplay((NativeDisplayType) _display);
30  if (!eglInitialize(_egl_display, nullptr, nullptr)) {
31  egldisplay_cat.error()
32  << "Couldn't initialize the EGL display: "
33  << get_egl_error_string(eglGetError()) << "\n";
34  }
35 
36  if (!eglBindAPI(EGL_OPENGL_ES_API)) {
37  egldisplay_cat.error()
38  << "Couldn't bind EGL to the OpenGL ES API: "
39  << get_egl_error_string(eglGetError()) << "\n";
40  }
41 }
42 
43 /**
44  *
45  */
46 eglGraphicsPipe::
47 ~eglGraphicsPipe() {
48  if (_egl_display) {
49  if (!eglTerminate(_egl_display)) {
50  egldisplay_cat.error() << "Failed to terminate EGL display: "
51  << get_egl_error_string(eglGetError()) << "\n";
52  }
53  }
54 }
55 
56 /**
57  * Returns the name of the rendering interface associated with this
58  * GraphicsPipe. This is used to present to the user to allow him/her to
59  * choose between several possible GraphicsPipes available on a particular
60  * platform, so the name should be meaningful and unique for a given platform.
61  */
62 std::string eglGraphicsPipe::
64  return "OpenGL ES";
65 }
66 
67 /**
68  * This function is passed to the GraphicsPipeSelection object to allow the
69  * user to make a default eglGraphicsPipe.
70  */
71 PT(GraphicsPipe) eglGraphicsPipe::
72 pipe_constructor() {
73  return new eglGraphicsPipe;
74 }
75 
76 /**
77  * Creates a new window on the pipe, if possible.
78  */
79 PT(GraphicsOutput) eglGraphicsPipe::
80 make_output(const std::string &name,
81  const FrameBufferProperties &fb_prop,
82  const WindowProperties &win_prop,
83  int flags,
84  GraphicsEngine *engine,
86  GraphicsOutput *host,
87  int retry,
88  bool &precertify) {
89 
90  if (!_is_valid) {
91  return nullptr;
92  }
93 
94  eglGraphicsStateGuardian *eglgsg = 0;
95  if (gsg != 0) {
96  DCAST_INTO_R(eglgsg, gsg, nullptr);
97  }
98 
99  bool support_rtt;
100  support_rtt = false;
101  /*
102  Currently, no support for eglGraphicsBuffer render-to-texture.
103  if (eglgsg) {
104  support_rtt =
105  eglgsg -> get_supports_render_texture() &&
106  support_render_texture;
107  }
108  */
109 
110  // First thing to try: an eglGraphicsWindow
111 
112  if (retry == 0) {
113  if (((flags&BF_require_parasite)!=0)||
114  ((flags&BF_refuse_window)!=0)||
115  ((flags&BF_resizeable)!=0)||
116  ((flags&BF_size_track_host)!=0)||
117  ((flags&BF_rtt_cumulative)!=0)||
118  ((flags&BF_can_bind_color)!=0)||
119  ((flags&BF_can_bind_every)!=0)) {
120  return nullptr;
121  }
122  return new eglGraphicsWindow(engine, this, name, fb_prop, win_prop,
123  flags, gsg, host);
124  }
125 
126  // Second thing to try: a GLES(2)GraphicsBuffer
127  if (retry == 1) {
128  if ((host==0)||
129  // (!gl_support_fbo)||
130  ((flags&BF_require_parasite)!=0)||
131  ((flags&BF_require_window)!=0)) {
132  return nullptr;
133  }
134  // Early failure - if we are sure that this buffer WONT meet specs, we can
135  // bail out early.
136  if ((flags & BF_fb_props_optional)==0) {
137  if ((fb_prop.get_indexed_color() > 0)||
138  (fb_prop.get_back_buffers() > 0)||
139  (fb_prop.get_accum_bits() > 0)||
140  (fb_prop.get_multisamples() > 0)) {
141  return nullptr;
142  }
143  }
144  // Early success - if we are sure that this buffer WILL meet specs, we can
145  // precertify it.
146  if ((eglgsg != 0) &&
147  (eglgsg->is_valid()) &&
148  (!eglgsg->needs_reset()) &&
149  (eglgsg->_supports_framebuffer_object) &&
150  (eglgsg->_glDrawBuffers != 0)&&
151  (fb_prop.is_basic())) {
152  precertify = true;
153  }
154 #ifdef OPENGLES_2
155  return new GLES2GraphicsBuffer(engine, this, name, fb_prop, win_prop,
156  flags, gsg, host);
157 #else
158  return new GLESGraphicsBuffer(engine, this, name, fb_prop, win_prop,
159  flags, gsg, host);
160 #endif
161  }
162 
163  // Third thing to try: a eglGraphicsBuffer
164  if (retry == 2) {
165  if (((flags&BF_require_parasite)!=0)||
166  ((flags&BF_require_window)!=0)||
167  ((flags&BF_resizeable)!=0)||
168  ((flags&BF_size_track_host)!=0)) {
169  return nullptr;
170  }
171 
172  if (!support_rtt) {
173  if (((flags&BF_rtt_cumulative)!=0)||
174  ((flags&BF_can_bind_every)!=0)) {
175  // If we require Render-to-Texture, but can't be sure we support it,
176  // bail.
177  return nullptr;
178  }
179  }
180 
181  return new eglGraphicsBuffer(engine, this, name, fb_prop, win_prop,
182  flags, gsg, host);
183  }
184 
185  // Fourth thing to try: an eglGraphicsPixmap.
186  if (retry == 3) {
187  if (((flags&BF_require_parasite)!=0)||
188  ((flags&BF_require_window)!=0)||
189  ((flags&BF_resizeable)!=0)||
190  ((flags&BF_size_track_host)!=0)) {
191  return nullptr;
192  }
193 
194  if (((flags&BF_rtt_cumulative)!=0)||
195  ((flags&BF_can_bind_every)!=0)) {
196  return nullptr;
197  }
198 
199  return new eglGraphicsPixmap(engine, this, name, fb_prop, win_prop,
200  flags, gsg, host);
201  }
202 
203  // Nothing else left to try.
204  return nullptr;
205 }
bool is_basic() const
Returns true if the properties are extremely basic.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This graphics pipe represents the interface for creating graphics windows on an X-based client.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An interface to the egl system for managing GLES windows under X.
virtual std::string get_interface_name() const
Returns the name of the rendering interface associated with this GraphicsPipe.
This graphics pipe represents the interface for creating OpenGL ES graphics windows on an X-based (e....
A container for the various kinds of properties we might ask to have on a graphics window before we o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const std::string get_egl_error_string(int error)
Returns the given EGL error as string.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
Another offscreen buffer in the EGL environment.
This is a base class for the various different classes that represent the result of a frame of render...
An offscreen buffer in the EGL environment.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encapsulates all the communication with a particular instance of a given rendering backend.
A tiny specialization on GLESGraphicsStateGuardian to add some egl-specific information.
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
PT(GraphicsPipe) eglGraphicsPipe
This function is passed to the GraphicsPipeSelection object to allow the user to make a default eglGr...