Panda3D

posixGraphicsStateGuardian.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 posixGraphicsStateGuardian.cxx
10 * @author drose
11 * @date 2012-01-14
12 */
13
14 #include "posixGraphicsStateGuardian.h"
15 #include "config_glxdisplay.h"
16 #include <dlfcn.h>
17
18 TypeHandle PosixGraphicsStateGuardian::_type_handle;
19
20 /**
21 *
22 */
23 PosixGraphicsStateGuardian::
24 PosixGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe) :
25 GLGraphicsStateGuardian(engine, pipe)
26 {
27 _libgl_handle = nullptr;
28 }
29
30 /**
31 *
32 */
33 PosixGraphicsStateGuardian::
34 ~PosixGraphicsStateGuardian() {
35 if (_libgl_handle != nullptr) {
36 dlclose(_libgl_handle);
37 }
38 }
39
40 /**
41 * Returns the pointer to the GL extension function with the indicated name.
42 * It is the responsibility of the caller to ensure that the required
43 * extension is defined in the OpenGL runtime prior to calling this; it is an
44 * error to call this for a function that is not defined.
45 */
46 void *PosixGraphicsStateGuardian::
47 do_get_extension_func(const char *name) {
48 nassertr(name != nullptr, nullptr);
49
50 if (glx_get_os_address) {
51 return get_system_func(name);
52 }
53
54 return nullptr;
55 }
56
57 /**
58 * Support for get_extension_func(), above, that uses system calls to find a
59 * GL or GLX function (in the absence of a working glxGetProcAddress()
60 * function to call).
61 */
62 void *PosixGraphicsStateGuardian::
63 get_system_func(const char *name) {
64 if (_libgl_handle == nullptr) {
65 // We open the current executable, rather than naming a particular
66 // library. Presumably libGL.so (or whatever the library should be
67 // called) is already available in the current executable address space,
68 // so this is more portable than insisting on a particular shared library
69 // name.
70 _libgl_handle = dlopen(nullptr, RTLD_LAZY);
71 nassertr(_libgl_handle != nullptr, nullptr);
72
73 // If that doesn't locate the symbol we expected, then fall back to
74 // loading the GL library by its usual name.
75 if (dlsym(_libgl_handle, name) == nullptr) {
76 dlclose(_libgl_handle);
77 glxdisplay_cat.warning()
78 << name << " not found in executable; looking in libGL.so instead.\n";
79 _libgl_handle = dlopen("libGL.so", RTLD_LAZY);
80 nassertr(_libgl_handle != nullptr, nullptr);
81 }
82 }
83
84 return dlsym(_libgl_handle, name);
85 }
GraphicsEngine
This class is the main interface to controlling the render process.
Definition: graphicsEngine.h:53
GraphicsPipe
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
config_glxdisplay.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
posixGraphicsStateGuardian.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.