mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 03:42:50 +08:00
Summary: EGLContext is a utility to render with OpenGL without an attached display (that is, without a monitor). DeviceContextManager allows us to avoid unnecessary context creations and releases. See docstrings for more info. Reviewed By: jcjohnson Differential Revision: D36562551 fbshipit-source-id: eb0d2a2f85555ee110e203d435a44ad243281d2c
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD-style license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
# If we can access EGL, import MeshRasterizerOpenGL.
|
|
def _can_import_egl_and_pycuda():
|
|
import os
|
|
import warnings
|
|
|
|
try:
|
|
os.environ["PYOPENGL_PLATFORM"] = "egl"
|
|
import OpenGL.EGL
|
|
except (AttributeError, ImportError, ModuleNotFoundError):
|
|
warnings.warn(
|
|
"Can't import EGL, not importing MeshRasterizerOpenGL. This might happen if"
|
|
" your Python application imported OpenGL with a non-EGL backend before"
|
|
" importing PyTorch3D, or if you don't have pyopengl installed as part"
|
|
" of your Python distribution."
|
|
)
|
|
return False
|
|
|
|
try:
|
|
import pycuda.gl
|
|
except (ImportError, ImportError, ModuleNotFoundError):
|
|
warnings.warn("Can't import pucuda.gl, not importing MeshRasterizerOpenGL.")
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
if _can_import_egl_and_pycuda():
|
|
from .opengl_utils import EGLContext, global_device_context_store
|
|
|
|
__all__ = [k for k in globals().keys() if not k.startswith("_")]
|