Panda3D

Loading...
Searching...
No Matches
glxGraphicsPipe.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 glxGraphicsPipe.cxx
10 * @author mike
11 * @date 1997-01-09
12 */
13
14#include "glxGraphicsPipe.h"
15#include "glxGraphicsWindow.h"
16#include "glxGraphicsBuffer.h"
17#include "glxGraphicsPixmap.h"
18#include "glxGraphicsStateGuardian.h"
19#include "posixGraphicsStateGuardian.h"
20#include "config_glxdisplay.h"
21#include "frameBufferProperties.h"
22
23 using std::string;
24
25 TypeHandle glxGraphicsPipe::_type_handle;
26
27/**
28 *
29 */
30glxGraphicsPipe::
31glxGraphicsPipe(const string &display) : x11GraphicsPipe(display) {
32 if (_display == None) {
33 // Some error must have occurred.
34 return;
35 }
36
37 string display_spec (XDisplayString(_display));
38
39 int errorBase, eventBase;
40 if (!glXQueryExtension(_display, &errorBase, &eventBase)) {
41 glxdisplay_cat.error()
42 << "OpenGL GLX extension not supported on display \"" << display_spec
43 << "\".\n";
44 return;
45 }
46}
47
48/**
49 * Returns the name of the rendering interface associated with this
50 * GraphicsPipe. This is used to present to the user to allow him/her to
51 * choose between several possible GraphicsPipes available on a particular
52 * platform, so the name should be meaningful and unique for a given platform.
53 */
54 string glxGraphicsPipe::
55 get_interface_name() const {
56 return "OpenGL";
57}
58
59/**
60 * This function is passed to the GraphicsPipeSelection object to allow the
61 * user to make a default glxGraphicsPipe.
62 */
63PT(GraphicsPipe) glxGraphicsPipe::
64pipe_constructor() {
65 return new glxGraphicsPipe;
66}
67
68/**
69 * Creates a new window on the pipe, if possible.
70 */
71PT(GraphicsOutput) glxGraphicsPipe::
72make_output(const string &name,
73 const FrameBufferProperties &fb_prop,
74 const WindowProperties &win_prop,
75 int flags,
76 GraphicsEngine *engine,
77 GraphicsStateGuardian *gsg,
78 GraphicsOutput *host,
79 int retry,
80 bool &precertify) {
81
82 if (!_is_valid) {
83 return nullptr;
84 }
85
86 // This may not be a GLX GSG; it might be a callback GSG.
87 PosixGraphicsStateGuardian *posixgsg = nullptr;
88 glxGraphicsStateGuardian *glxgsg = nullptr;
89 if (gsg != nullptr) {
90 DCAST_INTO_R(posixgsg, gsg, nullptr);
91 glxgsg = DCAST(glxGraphicsStateGuardian, posixgsg);
92 }
93
94 bool support_rtt;
95 support_rtt = false;
96 /*
97 Currently, no support for glxGraphicsBuffer render-to-texture.
98 if (glxgsg) {
99 support_rtt =
100 glxgsg -> get_supports_render_texture() &&
101 support_render_texture;
102 }
103 */
104
105 // First thing to try: a glxGraphicsWindow
106
107 if (retry == 0) {
108 if (gsg != nullptr && glxgsg == nullptr) {
109 // We can't use a non-GLX GSG.
110 return nullptr;
111 }
112 if (((flags&BF_require_parasite)!=0)||
113 ((flags&BF_refuse_window)!=0)||
114 ((flags&BF_resizeable)!=0)||
115 ((flags&BF_size_track_host)!=0)||
116 ((flags&BF_rtt_cumulative)!=0)||
117 ((flags&BF_can_bind_color)!=0)||
118 ((flags&BF_can_bind_every)!=0)||
119 ((flags&BF_can_bind_layered)!=0)) {
120 return nullptr;
121 }
122 return new glxGraphicsWindow(engine, this, name, fb_prop, win_prop,
123 flags, gsg, host);
124 }
125
126 // Second thing to try: a GLGraphicsBuffer
127
128 if (retry == 1) {
129 if (!gl_support_fbo || host == nullptr ||
130 (flags & (BF_require_parasite | BF_require_window)) != 0) {
131 return nullptr;
132 }
133 // Early failure - if we are sure that this buffer WONT meet specs, we can
134 // bail out early.
135 if ((flags & BF_fb_props_optional) == 0) {
136 if (fb_prop.get_indexed_color() ||
137 fb_prop.get_back_buffers() > 0 ||
138 fb_prop.get_accum_bits() > 0) {
139 return nullptr;
140 }
141 }
142 if (posixgsg != nullptr && posixgsg->is_valid() && !posixgsg->needs_reset()) {
143 if (!posixgsg->_supports_framebuffer_object ||
144 posixgsg->_glDrawBuffers == nullptr) {
145 return nullptr;
146 } else {
147 // Early success - if we are sure that this buffer WILL meet specs, we
148 // can precertify it.
149 precertify = true;
150 }
151 }
152 return new GLGraphicsBuffer(engine, this, name, fb_prop, win_prop,
153 flags, gsg, host);
154 }
155
156 // Third thing to try: a glxGraphicsBuffer
157 if (glxgsg == nullptr || glxgsg->_supports_fbconfig) {
158 if (retry == 2) {
159 if (!glx_support_pbuffer) {
160 return nullptr;
161 }
162
163 if (((flags&BF_require_parasite)!=0)||
164 ((flags&BF_require_window)!=0)||
165 ((flags&BF_resizeable)!=0)||
166 ((flags&BF_size_track_host)!=0)||
167 ((flags&BF_can_bind_layered)!=0)) {
168 return nullptr;
169 }
170
171 if (!support_rtt) {
172 if (((flags&BF_rtt_cumulative)!=0)||
173 ((flags&BF_can_bind_every)!=0)) {
174 // If we require Render-to-Texture, but can't be sure we support it,
175 // bail.
176 return nullptr;
177 }
178 }
179
180 return new glxGraphicsBuffer(engine, this, name, fb_prop, win_prop,
181 flags, gsg, host);
182 }
183 }
184
185 // Third thing to try: a glxGraphicsPixmap.
186 if (retry == 3) {
187 if (!glx_support_pixmap) {
188 return nullptr;
189 }
190
191 if (((flags&BF_require_parasite)!=0)||
192 ((flags&BF_require_window)!=0)||
193 ((flags&BF_resizeable)!=0)||
194 ((flags&BF_size_track_host)!=0)||
195 ((flags&BF_can_bind_layered)!=0)) {
196 return nullptr;
197 }
198
199 if (((flags&BF_rtt_cumulative)!=0)||
200 ((flags&BF_can_bind_every)!=0)) {
201 return nullptr;
202 }
203
204 return new glxGraphicsPixmap(engine, this, name, fb_prop, win_prop,
205 flags, gsg, host);
206 }
207
208 // Nothing else left to try.
209 return nullptr;
210}
211
212/**
213 * This is called when make_output() is used to create a
214 * CallbackGraphicsWindow. If the GraphicsPipe can construct a GSG that's not
215 * associated with any particular window object, do so now, assuming the
216 * correct graphics context has been set up externally.
217 */
218PT(GraphicsStateGuardian) glxGraphicsPipe::
219make_callback_gsg(GraphicsEngine *engine) {
220 // We create a PosixGraphicsStateGuardian instead of a
221 // glxGraphicsStateGuardian, because the externally-created context might
222 // not have anything to do with the glx interface.
223 return new PosixGraphicsStateGuardian(engine, this);
224}
FrameBufferProperties
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
Definition frameBufferProperties.h:26
GraphicsEngine
This class is the main interface to controlling the render process.
Definition graphicsEngine.h:53
GraphicsOutput
This is a base class for the various different classes that represent the result of a frame of render...
Definition graphicsOutput.h:63
GraphicsPipe
An object to create GraphicsOutputs that share a particular 3-D API.
Definition graphicsPipe.h:52
GraphicsStateGuardian
Encapsulates all the communication with a particular instance of a given rendering backend.
Definition graphicsStateGuardian.h:65
PosixGraphicsStateGuardian
This GSG is used only for CallbackGraphicsWindow (which might not be using the glx interfaces),...
Definition posixGraphicsStateGuardian.h:26
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
WindowProperties
A container for the various kinds of properties we might ask to have on a graphics window before we o...
Definition windowProperties.h:29
glxGraphicsBuffer
An offscreen buffer in the GLX environment.
Definition glxGraphicsBuffer.h:25
glxGraphicsPipe
This graphics pipe represents the interface for creating OpenGL graphics windows on an X-based (e....
Definition glxGraphicsPipe.h:76
glxGraphicsPipe::get_interface_name
virtual std::string get_interface_name() const
Returns the name of the rendering interface associated with this GraphicsPipe.
Definition glxGraphicsPipe.cxx:55
glxGraphicsPixmap
Another offscreen buffer in the GLX environment.
Definition glxGraphicsPixmap.h:28
glxGraphicsStateGuardian
A tiny specialization on GLGraphicsStateGuardian to add some glx-specific information.
Definition glxGraphicsStateGuardian.h:74
glxGraphicsWindow
An interface to the glx system for managing GL windows under X.
Definition glxGraphicsWindow.h:27
x11GraphicsPipe
This graphics pipe represents the interface for creating graphics windows on an X-based client.
Definition x11GraphicsPipe.h:96
config_glxdisplay.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
frameBufferProperties.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
glxGraphicsBuffer.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
glxGraphicsPipe.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
glxGraphicsPixmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
glxGraphicsStateGuardian.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
glxGraphicsWindow.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
posixGraphicsStateGuardian.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.