Team Ai
Apppublic

OpenMotionLab/MotionGPT

sourceHugging Facemitupdated 1y agoView on Hugging Face
118likes
osmesa.py60 linesDownload Raw Back to platforms
1from .base import Platform2 3 4__all__ = ['OSMesaPlatform']5 6 7class OSMesaPlatform(Platform):8    """Renders into a software buffer using OSMesa. Requires special versions9    of OSMesa to be installed, plus PyOpenGL upgrade.10    """11 12    def __init__(self, viewport_width, viewport_height):13        super(OSMesaPlatform, self).__init__(viewport_width, viewport_height)14        self._context = None15        self._buffer = None16 17    def init_context(self):18        from OpenGL import arrays19        from OpenGL.osmesa import (20            OSMesaCreateContextAttribs, OSMESA_FORMAT,21            OSMESA_RGBA, OSMESA_PROFILE, OSMESA_CORE_PROFILE,22            OSMESA_CONTEXT_MAJOR_VERSION, OSMESA_CONTEXT_MINOR_VERSION,23            OSMESA_DEPTH_BITS24        )25 26        attrs = arrays.GLintArray.asArray([27            OSMESA_FORMAT, OSMESA_RGBA,28            OSMESA_DEPTH_BITS, 24,29            OSMESA_PROFILE, OSMESA_CORE_PROFILE,30            OSMESA_CONTEXT_MAJOR_VERSION, 3,31            OSMESA_CONTEXT_MINOR_VERSION, 3,32            033        ])34        self._context = OSMesaCreateContextAttribs(attrs, None)35        self._buffer = arrays.GLubyteArray.zeros(36            (self.viewport_height, self.viewport_width, 4)37        )38 39    def make_current(self):40        from OpenGL import GL as gl41        from OpenGL.osmesa import OSMesaMakeCurrent42        assert(OSMesaMakeCurrent(43            self._context, self._buffer, gl.GL_UNSIGNED_BYTE,44            self.viewport_width, self.viewport_height45        ))46 47    def make_uncurrent(self):48        """Make the OpenGL context uncurrent.49        """50        pass51 52    def delete_context(self):53        from OpenGL.osmesa import OSMesaDestroyContext54        OSMesaDestroyContext(self._context)55        self._context = None56        self._buffer = None57 58    def supports_framebuffers(self):59        return False60