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