Example #1
0
def test_pyrex_opengl(test_type): # not tested since major refactoring
    try:
        print_compact_stack("selectMode Draw: " )###
        ### BUG: if import quux fails, we get into some sort of infinite
        ###   loop of Draw calls. [bruce 070917 comment]

        #self.w.win_update()
        ## sys.path.append("./experimental/pyrex-opengl") # no longer 
        ##needed here -- always done in drawer.py
        binPath = os.path.normpath(os.path.dirname(
            os.path.abspath(sys.argv[0])) + '/../bin')
        if binPath not in sys.path:
            sys.path.append(binPath)
        import quux
        if "experimental" in os.path.dirname(quux.__file__):
            print "WARNING: Using experimental version of quux module"
        # quux.test()
        quux.shapeRendererInit()
        quux.shapeRendererSetUseDynamicLOD(0)
        quux.shapeRendererStartDrawing()
        if test_type == 1:
            center = Numeric.array((Numeric.array((0, 0, 0), 'f'),
                                    Numeric.array((0, 0, 1), 'f'),
                                    Numeric.array((0, 1, 0), 'f'),
                                    Numeric.array((0, 1, 1), 'f'),
                                    Numeric.array((1, 0, 0), 'f'),
                                    Numeric.array((1, 0, 1), 'f'),
                                    Numeric.array((1, 1, 0), 'f'),
                                    Numeric.array((1, 1, 1), 'f')), 'f')
            radius = Numeric.array((0.2, 0.4, 0.6, 0.8,
                                    1.2, 1.4, 1.6, 1.8), 'f')
            color = Numeric.array((Numeric.array((0, 0, 0, 0.5), 'f'),
                                   Numeric.array((0, 0, 1, 0.5), 'f'),
                                   Numeric.array((0, 1, 0, 0.5), 'f'),
                                   Numeric.array((0, 1, 1, 0.5), 'f'),
                                   Numeric.array((1, 0, 0, 0.5), 'f'),
                                   Numeric.array((1, 0, 1, 0.5), 'f'),
                                   Numeric.array((1, 1, 0, 0.5), 'f'),
                                   Numeric.array((1, 1, 1, 0.5), 'f')), 'f')
            result = quux.shapeRendererDrawSpheres(8, center, radius, color)
        elif test_type == 2:
            # grantham - I'm pretty sure the actual compilation, init,
            # etc happens once
            from bearing_data import sphereCenters, sphereRadii
            from bearing_data import sphereColors, cylinderPos1
            from bearing_data import cylinderPos2, cylinderRadii
            from bearing_data import cylinderCapped, cylinderColors
            glPushMatrix()
            glTranslate(-0.001500, -0.000501, 151.873627)
            result = quux.shapeRendererDrawSpheres(1848, 
                                                   sphereCenters, 
                                                   sphereRadii, 
                                                   sphereColors)
            result = quux.shapeRendererDrawCylinders(5290, 
                                                     cylinderPos1,
                                                     cylinderPos2, 
                                                     cylinderRadii, 
                                                     cylinderCapped, 
                                                     cylinderColors)
            glPopMatrix()
        quux.shapeRendererFinishDrawing()

    except ImportError:
        env.history.message(redmsg(
            "Can't import Pyrex OpenGL or maybe bearing_data.py, rebuild it"))

    return
Example #2
0
def test_pyrex_opengl(test_type):  # not tested since major refactoring
    try:
        print_compact_stack("selectMode Draw: ")  ###
        ### BUG: if import quux fails, we get into some sort of infinite
        ###   loop of Draw calls. [bruce 070917 comment]

        #self.w.win_update()
        ## sys.path.append("./experimental/pyrex-opengl") # no longer
        ##needed here -- always done in drawer.py
        binPath = os.path.normpath(
            os.path.dirname(os.path.abspath(sys.argv[0])) + '/../bin')
        if binPath not in sys.path:
            sys.path.append(binPath)
        import quux
        if "experimental" in os.path.dirname(quux.__file__):
            print "WARNING: Using experimental version of quux module"
        # quux.test()
        quux.shapeRendererInit()
        quux.shapeRendererSetUseDynamicLOD(0)
        quux.shapeRendererStartDrawing()
        if test_type == 1:
            center = Numeric.array(
                (Numeric.array((0, 0, 0), 'f'), Numeric.array(
                    (0, 0, 1), 'f'), Numeric.array(
                        (0, 1, 0), 'f'), Numeric.array((0, 1, 1), 'f'),
                 Numeric.array((1, 0, 0), 'f'), Numeric.array(
                     (1, 0, 1), 'f'), Numeric.array(
                         (1, 1, 0), 'f'), Numeric.array((1, 1, 1), 'f')), 'f')
            radius = Numeric.array((0.2, 0.4, 0.6, 0.8, 1.2, 1.4, 1.6, 1.8),
                                   'f')
            color = Numeric.array(
                (Numeric.array(
                    (0, 0, 0, 0.5), 'f'), Numeric.array((0, 0, 1, 0.5), 'f'),
                 Numeric.array(
                     (0, 1, 0, 0.5), 'f'), Numeric.array((0, 1, 1, 0.5), 'f'),
                 Numeric.array(
                     (1, 0, 0, 0.5), 'f'), Numeric.array((1, 0, 1, 0.5), 'f'),
                 Numeric.array(
                     (1, 1, 0, 0.5), 'f'), Numeric.array(
                         (1, 1, 1, 0.5), 'f')), 'f')
            result = quux.shapeRendererDrawSpheres(8, center, radius, color)
        elif test_type == 2:
            # grantham - I'm pretty sure the actual compilation, init,
            # etc happens once
            from bearing_data import sphereCenters, sphereRadii
            from bearing_data import sphereColors, cylinderPos1
            from bearing_data import cylinderPos2, cylinderRadii
            from bearing_data import cylinderCapped, cylinderColors
            glPushMatrix()
            glTranslate(-0.001500, -0.000501, 151.873627)
            result = quux.shapeRendererDrawSpheres(1848, sphereCenters,
                                                   sphereRadii, sphereColors)
            result = quux.shapeRendererDrawCylinders(5290, cylinderPos1,
                                                     cylinderPos2,
                                                     cylinderRadii,
                                                     cylinderCapped,
                                                     cylinderColors)
            glPopMatrix()
        quux.shapeRendererFinishDrawing()

    except ImportError:
        env.history.message(
            redmsg(
                "Can't import Pyrex OpenGL or maybe bearing_data.py, rebuild it"
            ))

    return
Example #3
0
    def finish(draw_now = None): # staticmethod
        """
        Finish sorting -- objects recorded since "start" will be sorted;
        if draw_now is True, they'll also then be drawn.

        If there's no parent CSDL, we're in all-in-one-display-list mode,
        which is still a big speedup over plain immediate-mode drawing.
        In that case, draw_now must be True since it doesn't make sense
        to not draw (the drawing has already happened).
        """
        # TODO: refactor by moving some of this into methods in CSDL
        # (specifically, in ColorSorter._parent_csdl). [bruce 090224 comment]

        assert ColorSorter.sorting #bruce 090220, appears to be true from this code
        assert ColorSorter.glpane is not None #bruce 090220
        assert ColorSorter.glpane is not _the_fake_GLPane #bruce 090304

        if not ColorSorter._parent_csdl:
            #bruce 090220 revised, check _parent_csdl rather than sorting
            # (since sorting is always true); looks right but not fully analyzed
            assert draw_now, "finish(draw_now = False) makes no sense unless ColorSorter._parent_csdl"
            ### WARNING: DUPLICATE CODE with end of this method
            # (todo: split out some submethods to clean up)
            ColorSorter.sorting = False
            ColorSorter._unsuspend_if_needed()
            return                      # Plain immediate-mode, nothing to do.

        if draw_now is None:
            draw_now = False # not really needed
            print_compact_stack( "temporary warning: draw_now was not explicitly passed, using False: ") ####
            #### before release, leaving it out can mean False without a warning,
            # since by then it ought to be the "usual case". [bruce 090219]
            pass

        from utilities.debug_prefs import debug_pref, Choice_boolean_False
        debug_which_renderer = debug_pref(
            "debug print which renderer",
            Choice_boolean_False) #bruce 060314, imperfect but tolerable

        parent_csdl = ColorSorter._parent_csdl
        ColorSorter._parent_csdl = None
            # this must be done sometime before we return;
            # it can be done here, since nothing in this method after this
            # should use it directly or add primitives to it [bruce 090105]
        if ColorSorter.glpane.glprefs.use_c_renderer:
            # WARNING: this case has not been maintained for a long time
            # [bruce 090219 comment]
            quux.shapeRendererInit()
            if debug_which_renderer:
                #bruce 060314 uncommented/revised the next line; it might have
                # to come after shapeRendererInit (not sure); it definitely has
                # to come after a graphics context is created and initialized.
                # 20060314 grantham - yes, has to come after
                # quux.shapeRendererInit .
                enabled = quux.shapeRendererGetInteger(quux.IS_VBO_ENABLED)
                print ("using C renderer: VBO %s enabled" %
                       (('is NOT', 'is')[enabled]))
            quux.shapeRendererSetUseDynamicLOD(0)
            if ColorSorter.sphereLevel != -1:
                quux.shapeRendererSetStaticLODLevels(ColorSorter.sphereLevel, 1)
            quux.shapeRendererStartDrawing()
            ColorSorter._cur_shapelist.draw()
            quux.shapeRendererFinishDrawing()
            ColorSorter.sorting = False

            # So chunks can actually record their shapelist
            # at some point if they want to
            # ColorSorter._cur_shapelist.petrify()
            # return ColorSorter._cur_shapelist

        else:
            if debug_which_renderer:
                print "using Python renderer"

            if parent_csdl is None:
                # Either all in one display list, or immediate-mode drawing.
                ### REVIEW [bruce 090114]: are both possibilities still present,
                # now that several old options have been removed?
                ColorSorter._draw_sorted( ColorSorter.sorted_by_color)
                pass
            else: #russ 080225
                parent_csdl.finish( ColorSorter.sorted_by_color)
                    #bruce 090224 refactored this into parent_csdl
                pass

            ColorSorter.sorted_by_color = None
            pass

        ### WARNING: DUPLICATE CODE with another return statement in this method

        ColorSorter.sorting = False

        if draw_now:
            # Draw the newly-built display list, and any shader primitives as well.
            if parent_csdl is not None:
                parent_csdl.draw(
                    # Use either the normal-color display list or the selected one.
                    selected = parent_csdl.selected)

        ColorSorter._unsuspend_if_needed()
        return
Example #4
0
    def finish(draw_now=None):  # staticmethod
        """
        Finish sorting -- objects recorded since "start" will be sorted;
        if draw_now is True, they'll also then be drawn.

        If there's no parent CSDL, we're in all-in-one-display-list mode,
        which is still a big speedup over plain immediate-mode drawing.
        In that case, draw_now must be True since it doesn't make sense
        to not draw (the drawing has already happened).
        """
        # TODO: refactor by moving some of this into methods in CSDL
        # (specifically, in ColorSorter._parent_csdl). [bruce 090224 comment]

        assert ColorSorter.sorting  #bruce 090220, appears to be true from this code
        assert ColorSorter.glpane is not None  #bruce 090220
        assert ColorSorter.glpane is not _the_fake_GLPane  #bruce 090304

        if not ColorSorter._parent_csdl:
            #bruce 090220 revised, check _parent_csdl rather than sorting
            # (since sorting is always true); looks right but not fully analyzed
            assert draw_now, "finish(draw_now = False) makes no sense unless ColorSorter._parent_csdl"
            ### WARNING: DUPLICATE CODE with end of this method
            # (todo: split out some submethods to clean up)
            ColorSorter.sorting = False
            ColorSorter._unsuspend_if_needed()
            return  # Plain immediate-mode, nothing to do.

        if draw_now is None:
            draw_now = False  # not really needed
            print_compact_stack(
                "temporary warning: draw_now was not explicitly passed, using False: "
            )  ####
            #### before release, leaving it out can mean False without a warning,
            # since by then it ought to be the "usual case". [bruce 090219]
            pass

        from utilities.debug_prefs import debug_pref, Choice_boolean_False
        debug_which_renderer = debug_pref(
            "debug print which renderer",
            Choice_boolean_False)  #bruce 060314, imperfect but tolerable

        parent_csdl = ColorSorter._parent_csdl
        ColorSorter._parent_csdl = None
        # this must be done sometime before we return;
        # it can be done here, since nothing in this method after this
        # should use it directly or add primitives to it [bruce 090105]
        if ColorSorter.glpane.glprefs.use_c_renderer:
            # WARNING: this case has not been maintained for a long time
            # [bruce 090219 comment]
            quux.shapeRendererInit()
            if debug_which_renderer:
                #bruce 060314 uncommented/revised the next line; it might have
                # to come after shapeRendererInit (not sure); it definitely has
                # to come after a graphics context is created and initialized.
                # 20060314 grantham - yes, has to come after
                # quux.shapeRendererInit .
                enabled = quux.shapeRendererGetInteger(quux.IS_VBO_ENABLED)
                print("using C renderer: VBO %s enabled" %
                      (('is NOT', 'is')[enabled]))
            quux.shapeRendererSetUseDynamicLOD(0)
            if ColorSorter.sphereLevel != -1:
                quux.shapeRendererSetStaticLODLevels(ColorSorter.sphereLevel,
                                                     1)
            quux.shapeRendererStartDrawing()
            ColorSorter._cur_shapelist.draw()
            quux.shapeRendererFinishDrawing()
            ColorSorter.sorting = False

            # So chunks can actually record their shapelist
            # at some point if they want to
            # ColorSorter._cur_shapelist.petrify()
            # return ColorSorter._cur_shapelist

        else:
            if debug_which_renderer:
                print "using Python renderer"

            if parent_csdl is None:
                # Either all in one display list, or immediate-mode drawing.
                ### REVIEW [bruce 090114]: are both possibilities still present,
                # now that several old options have been removed?
                ColorSorter._draw_sorted(ColorSorter.sorted_by_color)
                pass
            else:  #russ 080225
                parent_csdl.finish(ColorSorter.sorted_by_color)
                #bruce 090224 refactored this into parent_csdl
                pass

            ColorSorter.sorted_by_color = None
            pass

        ### WARNING: DUPLICATE CODE with another return statement in this method

        ColorSorter.sorting = False

        if draw_now:
            # Draw the newly-built display list, and any shader primitives as well.
            if parent_csdl is not None:
                parent_csdl.draw(
                    # Use either the normal-color display list or the selected one.
                    selected=parent_csdl.selected)

        ColorSorter._unsuspend_if_needed()
        return
Example #5
0
    def Draw(self):
        if 1:
            # TODO: move this test code into a specific test mode just for it,
            # so it doesn't clutter up or slow down this general-use mode.
            #
            # wware 060124  Embed Pyrex/OpenGL unit tests into the cad code
            # grantham 060207:
            # Set to 1 to see a small array of eight spheres.
            # Set to 2 to see the Large-Bearing model, but this is most effective if
            #  the Large-Bearing has already been loaded normally into rotate mode
            #bruce 060209 set this from a debug_pref menu item, not a hardcoded flag
            TEST_PYREX_OPENGL = debug_pref("TEST_PYREX_OPENGL",
                                           Choice([0, 1, 2]))
            # uncomment this line to set it in the old way:
            ## TEST_PYREX_OPENGL = 1
        if TEST_PYREX_OPENGL:
            try:
                print_compact_stack("selectMode Draw: ")  ###
                ### BUG: if import quux fails, we get into some sort of infinite
                ###   loop of Draw calls. [bruce 070917 comment]

                #self.w.win_update()
                ## sys.path.append("./experimental/pyrex-opengl") # no longer
                ##needed here -- always done in drawer.py
                binPath = os.path.normpath(
                    os.path.dirname(os.path.abspath(sys.argv[0])) + '/../bin')
                if binPath not in sys.path:
                    sys.path.append(binPath)
                import quux
                if "experimental" in os.path.dirname(quux.__file__):
                    print "WARNING: Using experimental version of quux module"
                # quux.test()
                quux.shapeRendererInit()
                quux.shapeRendererSetUseDynamicLOD(0)
                quux.shapeRendererStartDrawing()
                if TEST_PYREX_OPENGL == 1:
                    center = Numeric.array(
                        (Numeric.array(
                            (0, 0, 0), 'f'), Numeric.array(
                                (0, 0, 1), 'f'), Numeric.array((0, 1, 0), 'f'),
                         Numeric.array(
                             (0, 1, 1), 'f'), Numeric.array((1, 0, 0), 'f'),
                         Numeric.array(
                             (1, 0, 1), 'f'), Numeric.array(
                                 (1, 1, 0), 'f'), Numeric.array(
                                     (1, 1, 1), 'f')), 'f')
                    radius = Numeric.array(
                        (0.2, 0.4, 0.6, 0.8, 1.2, 1.4, 1.6, 1.8), 'f')
                    color = Numeric.array((Numeric.array(
                        (0, 0, 0, 0.5), 'f'), Numeric.array(
                            (0, 0, 1, 0.5),
                            'f'), Numeric.array((0, 1, 0, 0.5), 'f'),
                                           Numeric.array((0, 1, 1, 0.5), 'f'),
                                           Numeric.array((1, 0, 0, 0.5), 'f'),
                                           Numeric.array((1, 0, 1, 0.5), 'f'),
                                           Numeric.array((1, 1, 0, 0.5), 'f'),
                                           Numeric.array((1, 1, 1, 0.5), 'f')),
                                          'f')
                    result = quux.shapeRendererDrawSpheres(
                        8, center, radius, color)
                elif TEST_PYREX_OPENGL == 2:
                    # grantham - I'm pretty sure the actual compilation, init,
                    # etc happens once
                    from bearing_data import sphereCenters, sphereRadii
                    from bearing_data import sphereColors, cylinderPos1
                    from bearing_data import cylinderPos2, cylinderRadii
                    from bearing_data import cylinderCapped, cylinderColors
                    glPushMatrix()
                    glTranslate(-0.001500, -0.000501, 151.873627)
                    result = quux.shapeRendererDrawSpheres(
                        1848, sphereCenters, sphereRadii, sphereColors)
                    result = quux.shapeRendererDrawCylinders(
                        5290, cylinderPos1, cylinderPos2, cylinderRadii,
                        cylinderCapped, cylinderColors)
                    glPopMatrix()
                quux.shapeRendererFinishDrawing()

            except ImportError:
                env.history.message(
                    redmsg(
                        "Can't import Pyrex OpenGL or maybe bearing_data.py, rebuild it"
                    ))
        else:
            if self.bc_in_use is not None:  #bruce 060414
                self.bc_in_use.draw(self.o, 'fake dispdef kluge')
            # bruce comment 040922: code is almost identical with modifyMode.Draw;
            # the difference (no check for self.o.assy existing) might be a bug
            # in this version, or might have no effect.
            commonGraphicsMode.Draw(self)
            #self.griddraw()
            if self.selCurve_List: self.draw_selection_curve()
            self.o.assy.draw(self.o)
    def Draw(self):
        if 1:
            # TODO: move this test code into a specific test mode just for it,
            # so it doesn't clutter up or slow down this general-use mode.
            #
            # wware 060124  Embed Pyrex/OpenGL unit tests into the cad code
            # grantham 060207:
            # Set to 1 to see a small array of eight spheres.
            # Set to 2 to see the Large-Bearing model, but this is most effective if
            #  the Large-Bearing has already been loaded normally into rotate mode
            #bruce 060209 set this from a debug_pref menu item, not a hardcoded flag
            TEST_PYREX_OPENGL = debug_pref("TEST_PYREX_OPENGL", Choice([0,1,2]))
            # uncomment this line to set it in the old way:
            ## TEST_PYREX_OPENGL = 1
        if TEST_PYREX_OPENGL:
            try:
                print_compact_stack("selectMode Draw: " )###
                ### BUG: if import quux fails, we get into some sort of infinite
                ###   loop of Draw calls. [bruce 070917 comment]

                #self.w.win_update()
                ## sys.path.append("./experimental/pyrex-opengl") # no longer 
                ##needed here -- always done in drawer.py
                binPath = os.path.normpath(os.path.dirname(
                    os.path.abspath(sys.argv[0])) + '/../bin')
                if binPath not in sys.path:
                    sys.path.append(binPath)
                import quux
                if "experimental" in os.path.dirname(quux.__file__):
                    print "WARNING: Using experimental version of quux module"
                # quux.test()
                quux.shapeRendererInit()
                quux.shapeRendererSetUseDynamicLOD(0)
                quux.shapeRendererStartDrawing()
                if TEST_PYREX_OPENGL == 1:
                    center = Numeric.array((Numeric.array((0, 0, 0), 'f'),
                                            Numeric.array((0, 0, 1), 'f'),
                                            Numeric.array((0, 1, 0), 'f'),
                                            Numeric.array((0, 1, 1), 'f'),
                                            Numeric.array((1, 0, 0), 'f'),
                                            Numeric.array((1, 0, 1), 'f'),
                                            Numeric.array((1, 1, 0), 'f'),
                                            Numeric.array((1, 1, 1), 'f')), 'f')
                    radius = Numeric.array((0.2, 0.4, 0.6, 0.8,
                                            1.2, 1.4, 1.6, 1.8), 'f')
                    color = Numeric.array((Numeric.array((0, 0, 0, 0.5), 'f'),
                                           Numeric.array((0, 0, 1, 0.5), 'f'),
                                           Numeric.array((0, 1, 0, 0.5), 'f'),
                                           Numeric.array((0, 1, 1, 0.5), 'f'),
                                           Numeric.array((1, 0, 0, 0.5), 'f'),
                                           Numeric.array((1, 0, 1, 0.5), 'f'),
                                           Numeric.array((1, 1, 0, 0.5), 'f'),
                                           Numeric.array((1, 1, 1, 0.5), 'f')), 'f')
                    result = quux.shapeRendererDrawSpheres(8, center, radius, color)
                elif TEST_PYREX_OPENGL == 2:
                    # grantham - I'm pretty sure the actual compilation, init,
                    # etc happens once
                    from bearing_data import sphereCenters, sphereRadii
                    from bearing_data import sphereColors, cylinderPos1
                    from bearing_data import cylinderPos2, cylinderRadii
                    from bearing_data import cylinderCapped, cylinderColors
                    glPushMatrix()
                    glTranslate(-0.001500, -0.000501, 151.873627)
                    result = quux.shapeRendererDrawSpheres(1848, 
                                                           sphereCenters, 
                                                           sphereRadii, 
                                                           sphereColors)
                    result = quux.shapeRendererDrawCylinders(5290, 
                                                             cylinderPos1,
                                                             cylinderPos2, 
                                                             cylinderRadii, 
                                                             cylinderCapped, 
                                                             cylinderColors)
                    glPopMatrix()
                quux.shapeRendererFinishDrawing()

            except ImportError:
                env.history.message(redmsg(
                    "Can't import Pyrex OpenGL or maybe bearing_data.py, rebuild it"))
        else:
            if self.bc_in_use is not None: #bruce 060414
                self.bc_in_use.draw(self.o, 'fake dispdef kluge')
            # bruce comment 040922: code is almost identical with modifyMode.Draw;
            # the difference (no check for self.o.assy existing) might be a bug
            # in this version, or might have no effect.
            commonGraphicsMode.Draw(self)   
            #self.griddraw()
            if self.selCurve_List: self.draw_selection_curve()
            self.o.assy.draw(self.o)
Example #7
0
    def finish():
        """
        Finish sorting - objects recorded since "start" will
        be sorted and invoked now.
        """
        from utilities.debug_prefs import debug_pref, Choice_boolean_False
        debug_which_renderer = debug_pref(
            "debug print which renderer",
            Choice_boolean_False)  #bruce 060314, imperfect but tolerable

        parent_csdl = ColorSorter.parent_csdl
        if drawing_globals.use_c_renderer:
            quux.shapeRendererInit()
            if debug_which_renderer:
                #bruce 060314 uncommented/revised the next line; it might have
                # to come after shapeRendererInit (not sure); it definitely has
                # to come after a graphics context is created and initialized.
                # 20060314 grantham - yes, has to come after
                # quux.shapeRendererInit .
                enabled = quux.shapeRendererGetInteger(quux.IS_VBO_ENABLED)
                print("using C renderer: VBO %s enabled" %
                      (('is NOT', 'is')[enabled]))
            quux.shapeRendererSetUseDynamicLOD(0)
            if ColorSorter.sphereLevel != -1:
                quux.shapeRendererSetStaticLODLevels(ColorSorter.sphereLevel,
                                                     1)
            quux.shapeRendererStartDrawing()
            ColorSorter._cur_shapelist.draw()
            quux.shapeRendererFinishDrawing()
            ColorSorter.sorting = False

            # So chunks can actually record their shapelist
            # at some point if they want to
            # ColorSorter._cur_shapelist.petrify()
            # return ColorSorter._cur_shapelist

        else:
            if debug_which_renderer:
                print(
                    "using Python renderer: use_color_sorted_dls %s enabled" %
                    (drawing_globals.use_color_sorted_dls and 'IS'
                     or 'is NOT'))
                print(
                    "using Python renderer: use_color_sorted_vbos %s enabled" %
                    (drawing_globals.use_color_sorted_vbos and 'IS'
                     or 'is NOT'))
            color_groups = len(ColorSorter.sorted_by_color)
            objects_drawn = 0

            if (not (drawing_globals.allow_color_sorting
                     and drawing_globals.use_color_sorted_dls)
                    or (ColorSortedDisplayList.cache_ColorSorter
                        and drawing_globals.allow_color_sorting
                        and drawing_globals.use_color_sorted_vbos)
                    #russ 080225 Added, 080320 VBO experiment.
                    or parent_csdl is None):

                # Either all in one display list, or immediate-mode drawing.
                objects_drawn += ColorSorter.draw_sorted(
                    ColorSorter.sorted_by_color)

                #russ 080225: Moved glEndList here for displist re-org.
                if parent_csdl is not None:
                    #russ 080320: Experiment with VBO drawing from cached
                    #ColorSorter lists.
                    if (ColorSortedDisplayList.cache_ColorSorter
                            and drawing_globals.allow_color_sorting
                            and drawing_globals.use_color_sorted_vbos):
                        # Remember the ColorSorter lists for use as a
                        # pseudo-display-list.
                        parent_csdl.sorted_by_color = \
                                   ColorSorter.sorted_by_color
                    else:
                        # Terminate a single display list, created when color
                        # sorting is turned off.  Started in ColorSorter.start .
                        glEndList()
                    pass
                pass

            else:  #russ 080225

                parent_csdl.reset()
                selColor = env.prefs[selectionColor_prefs_key]

                # First build the lower level per-color sublists of primitives.
                for color, funcs in ColorSorter.sorted_by_color.iteritems():
                    sublists = [glGenLists(1), 0]

                    # Remember the display list ID for this color.
                    parent_csdl.per_color_dls.append([color, sublists])

                    glNewList(sublists[0], GL_COMPILE)
                    opacity = color[3]

                    if opacity == -1:
                        #russ 080306: "Unshaded colors" for lines are signaled
                        # by an opacity of -1 (4th component of the color.)
                        glDisable(GL_LIGHTING)  # Don't forget to re-enable it!
                        pass

                    for func, params, name in funcs:
                        objects_drawn += 1
                        if name != 0:
                            glPushName(name)
                        func(params)
                        if name != 0:
                            glPopName()
                            pass
                        continue

                    if opacity == -1:
                        # Enable lighting after drawing "unshaded" objects.
                        glEnable(GL_LIGHTING)
                        pass
                    glEndList()

                    if opacity == -2:
                        # piotr 080419: Special case for drawpolycone_multicolor
                        # create another display list that ignores
                        # the contents of color_array.
                        # Remember the display list ID for this color.

                        sublists[1] = glGenLists(1)

                        glNewList(sublists[1], GL_COMPILE)

                        for func, params, name in funcs:
                            objects_drawn += 1
                            if name != 0:
                                glPushName(name)
                            if func == drawpolycone_multicolor_worker:
                                # Just to be sure, check if the func
                                # is drawpolycone_multicolor_worker
                                # and call drawpolycone_worker instead.
                                # I think in the future we can figure out
                                # a more general way of handling the
                                # GL_COLOR_MATERIAL objects. piotr 080420
                                pos_array, color_array, rad_array = params
                                drawpolycone_worker((pos_array, rad_array))
                            elif func == drawtriangle_strip_worker:
                                # piotr 080710: Multi-color modification
                                # for triangle_strip primitive (used by
                                # reduced protein style).
                                pos_array, normal_array, color_array = params
                                drawtriangle_strip_worker(
                                    (pos_array, normal_array, None))
                            if name != 0:
                                glPopName()
                                pass
                            continue
                        glEndList()

                    continue

                # Now the upper-level lists call all of the per-color sublists.
                # One with colors.
                color_dl = parent_csdl.color_dl = glGenLists(1)
                glNewList(color_dl, GL_COMPILE)

                for color, dls in parent_csdl.per_color_dls:

                    opacity = color[3]
                    if opacity < 0:
                        #russ 080306: "Unshaded colors" for lines are signaled
                        # by a negative alpha.
                        glColor3fv(color[:3])
                        # piotr 080417: for opacity == -2, i.e. if
                        # GL_COLOR_MATERIAL is enabled, the color is going
                        # to be ignored, anyway, so it is not necessary
                        # to be tested here
                    else:
                        apply_material(color)

                    glCallList(dls[0])

                    continue
                glEndList()

                # A second one without any colors.
                nocolor_dl = parent_csdl.nocolor_dl = glGenLists(1)
                glNewList(nocolor_dl, GL_COMPILE)
                for color, dls in parent_csdl.per_color_dls:
                    opacity = color[3]

                    if opacity == -2 \
                       and dls[1] > 0:
                        # piotr 080420: If GL_COLOR_MATERIAL is enabled,
                        # use a regular, single color dl rather than the
                        # multicolor one. Btw, dls[1] == 0 should never
                        # happen.
                        glCallList(dls[1])
                    else:
                        glCallList(dls[0])

                glEndList()

                # A third DL implements the selected appearance.
                selected_dl = parent_csdl.selected_dl = glGenLists(1)
                glNewList(selected_dl, GL_COMPILE)
                # russ 080530: Support for patterned selection drawing modes.
                patterned = isPatternedDrawing(select=True)
                if patterned:
                    # Patterned drawing needs the colored dl drawn first.
                    glCallList(color_dl)
                    startPatternedDrawing(select=True)
                    pass
                # Draw solid color (unpatterned) or an overlay pattern, in the
                # selection color.
                apply_material(selColor)
                glCallList(nocolor_dl)
                if patterned:
                    # Reset from patterning drawing mode.
                    endPatternedDrawing(select=True)
                glEndList()

                # Use either the normal-color display list or the selected one.
                parent_csdl.selectDl()

                # Draw the newly-built display list.
                parent_csdl.draw_dl()
                pass

            ColorSorter.sorted_by_color = None
            pass
        ColorSorter.sorting = False
        return
Example #8
0
    def finish():
        """
        Finish sorting - objects recorded since "start" will
        be sorted and invoked now.
        """
        from utilities.debug_prefs import debug_pref, Choice_boolean_False
        debug_which_renderer = debug_pref(
            "debug print which renderer",
            Choice_boolean_False) #bruce 060314, imperfect but tolerable

        parent_csdl = ColorSorter.parent_csdl
        if drawing_globals.use_c_renderer:
            quux.shapeRendererInit()
            if debug_which_renderer:
                #bruce 060314 uncommented/revised the next line; it might have
                # to come after shapeRendererInit (not sure); it definitely has
                # to come after a graphics context is created and initialized.
                # 20060314 grantham - yes, has to come after
                # quux.shapeRendererInit .
                enabled = quux.shapeRendererGetInteger(quux.IS_VBO_ENABLED)
                print ("using C renderer: VBO %s enabled" %
                       (('is NOT', 'is')[enabled]))
            quux.shapeRendererSetUseDynamicLOD(0)
            if ColorSorter.sphereLevel != -1:
                quux.shapeRendererSetStaticLODLevels(ColorSorter.sphereLevel, 1)
            quux.shapeRendererStartDrawing()
            ColorSorter._cur_shapelist.draw()
            quux.shapeRendererFinishDrawing()
            ColorSorter.sorting = False

            # So chunks can actually record their shapelist
            # at some point if they want to
            # ColorSorter._cur_shapelist.petrify()
            # return ColorSorter._cur_shapelist      

        else:
            if debug_which_renderer:
                print ("using Python renderer: use_color_sorted_dls %s enabled"
                       % (drawing_globals.use_color_sorted_dls and 'IS'
                          or 'is NOT'))
                print ("using Python renderer: use_color_sorted_vbos %s enabled"
                       % (drawing_globals.use_color_sorted_vbos and 'IS'
                          or 'is NOT'))
            color_groups = len(ColorSorter.sorted_by_color)
            objects_drawn = 0

            if (not (drawing_globals.allow_color_sorting and
                     drawing_globals.use_color_sorted_dls)
                or (ColorSortedDisplayList.cache_ColorSorter and
                    drawing_globals.allow_color_sorting and
                    drawing_globals.use_color_sorted_vbos)
                #russ 080225 Added, 080320 VBO experiment.
                or parent_csdl is None):

                # Either all in one display list, or immediate-mode drawing.
                objects_drawn += ColorSorter.draw_sorted(
                    ColorSorter.sorted_by_color)

                #russ 080225: Moved glEndList here for displist re-org.
                if parent_csdl is not None:
                    #russ 080320: Experiment with VBO drawing from cached
                    #ColorSorter lists.
                    if (ColorSortedDisplayList.cache_ColorSorter and
                        drawing_globals.allow_color_sorting and
                        drawing_globals.use_color_sorted_vbos):
                        # Remember the ColorSorter lists for use as a
                        # pseudo-display-list.
                        parent_csdl.sorted_by_color = \
                                   ColorSorter.sorted_by_color
                    else:
                        # Terminate a single display list, created when color
                        # sorting is turned off.  Started in ColorSorter.start .
                        glEndList()
                    pass
                pass

            else: #russ 080225

                parent_csdl.reset()
                selColor = env.prefs[selectionColor_prefs_key]

                # First build the lower level per-color sublists of primitives.
                for color, funcs in ColorSorter.sorted_by_color.iteritems():
                    sublists = [glGenLists(1), 0]

                    # Remember the display list ID for this color.
                    parent_csdl.per_color_dls.append([color, sublists])

                    glNewList(sublists[0], GL_COMPILE)
                    opacity = color[3]

                    if opacity == -1:
                        #russ 080306: "Unshaded colors" for lines are signaled
                        # by an opacity of -1 (4th component of the color.)
                        glDisable(GL_LIGHTING) # Don't forget to re-enable it!
                        pass

                    for func, params, name in funcs:
                        objects_drawn += 1
                        if name != 0:
                            glPushName(name)
                        func(params)
                        if name != 0:
                            glPopName()
                            pass
                        continue

                    if opacity == -1:
                        # Enable lighting after drawing "unshaded" objects.
                        glEnable(GL_LIGHTING)
                        pass
                    glEndList()

                    if opacity == -2:
                        # piotr 080419: Special case for drawpolycone_multicolor
                        # create another display list that ignores
                        # the contents of color_array.
                        # Remember the display list ID for this color.

                        sublists[1] = glGenLists(1)

                        glNewList(sublists[1], GL_COMPILE)

                        for func, params, name in funcs:
                            objects_drawn += 1
                            if name != 0:
                                glPushName(name)
                            if func == drawpolycone_multicolor_worker:
                                # Just to be sure, check if the func
                                # is drawpolycone_multicolor_worker
                                # and call drawpolycone_worker instead.
                                # I think in the future we can figure out 
                                # a more general way of handling the 
                                # GL_COLOR_MATERIAL objects. piotr 080420
                                pos_array, color_array, rad_array = params
                                drawpolycone_worker((pos_array, rad_array))
                            elif func == drawtriangle_strip_worker:
                                # piotr 080710: Multi-color modification
                                # for triangle_strip primitive (used by 
                                # reduced protein style).
                                pos_array, normal_array, color_array = params
                                drawtriangle_strip_worker((pos_array, 
                                                           normal_array,
                                                           None))
                            if name != 0:
                                glPopName()
                                pass
                            continue
                        glEndList()

                    continue

                # Now the upper-level lists call all of the per-color sublists.
                # One with colors.
                color_dl = parent_csdl.color_dl = glGenLists(1)
                glNewList(color_dl, GL_COMPILE)

                for color, dls in parent_csdl.per_color_dls:

                    opacity = color[3]
                    if opacity < 0:
                        #russ 080306: "Unshaded colors" for lines are signaled
                        # by a negative alpha.
                        glColor3fv(color[:3])
                        # piotr 080417: for opacity == -2, i.e. if
                        # GL_COLOR_MATERIAL is enabled, the color is going 
                        # to be ignored, anyway, so it is not necessary
                        # to be tested here
                    else:
                        apply_material(color)

                    glCallList(dls[0])

                    continue
                glEndList()

                # A second one without any colors.
                nocolor_dl = parent_csdl.nocolor_dl = glGenLists(1)
                glNewList(nocolor_dl, GL_COMPILE)
                for color, dls in parent_csdl.per_color_dls:                    
                    opacity = color[3]

                    if opacity == -2 \
                       and dls[1] > 0:
                        # piotr 080420: If GL_COLOR_MATERIAL is enabled,
                        # use a regular, single color dl rather than the
                        # multicolor one. Btw, dls[1] == 0 should never 
                        # happen.
                        glCallList(dls[1])
                    else:
                        glCallList(dls[0])

                glEndList()

                # A third DL implements the selected appearance.
                selected_dl = parent_csdl.selected_dl = glGenLists(1)
                glNewList(selected_dl, GL_COMPILE)
                # russ 080530: Support for patterned selection drawing modes.
                patterned = isPatternedDrawing(select = True)
                if patterned:
                    # Patterned drawing needs the colored dl drawn first.
                    glCallList(color_dl)
                    startPatternedDrawing(select = True)
                    pass
                # Draw solid color (unpatterned) or an overlay pattern, in the
                # selection color.
                apply_material(selColor)
                glCallList(nocolor_dl)
                if patterned:
                    # Reset from patterning drawing mode.
                    endPatternedDrawing(select = True)
                glEndList()

                # Use either the normal-color display list or the selected one.
                parent_csdl.selectDl()

                # Draw the newly-built display list.
                parent_csdl.draw_dl()
                pass

            ColorSorter.sorted_by_color = None
            pass
        ColorSorter.sorting = False
        return