示例#1
0
    def draw_sorted(sorted_by_color):  #russ 080320: factored out of finish().
        """
        Traverse color-sorted lists, invoking worker procedures.
        """
        objects_drawn = 0  # Keep track and return.
        glEnable(GL_LIGHTING)

        for color, funcs in sorted_by_color.iteritems():

            opacity = color[3]
            if opacity == -1:
                #piotr 080429: Opacity == -1 signals the "unshaded color".
                # Also, see my comment in "schedule".
                glDisable(GL_LIGHTING)  # Don't forget to re-enable it!
                glColor3fv(color[:3])
            else:
                apply_material(color)
                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:
                glEnable(GL_LIGHTING)

            continue
        return objects_drawn
示例#2
0
 def draw_after_highlighting(self, 
                             glpane, 
                             dispdef, 
                             pickCheckOnly = False):
     """
     For ESPImage class, this does all the drawing. (Does it after main
     drawing code is finished drawing.) This method ensures that the 
     ESP image jig gets selected even when you click inside the 
     rectangular box (i.e. not just along the edges of the box).
     """
     anythingDrawn = False
     if self.hidden:
         return anythingDrawn
     
     self.pickCheckOnly = pickCheckOnly        
     anythingDrawn = True
     glPushName(self.glname)
     try:
         self._draw(glpane, dispdef) #calls self._draw_jig()
     except:
         anythingDrawn = False
         msg = "ignoring exception when drawing Jig %r" % self
         print_compact_traceback(msg + ": ")
     glPopName()
     
     return anythingDrawn
示例#3
0
 def draw_after_highlighting(self, 
                             glpane, 
                             dispdef, 
                             pickCheckOnly = False):
     """
     For ESPImage class, this does all the drawing. (does it after main
     drawing code is finished drawing) . This method ensures that the 
     ESP image jig gets selected even when you click inside the 
     rectangular box (i.e. not just along the edgets of the box)
     @see: GraphicsMode.Draw_after_highlighting()
     @see: Node.draw_after_highlighting()
     @see:Plane.draw_after_highlighting()
     """
     anythingDrawn = False
     if self.hidden:
         return anythingDrawn
     
     self.pickCheckOnly = pickCheckOnly        
     try:
         anythingDrawn = True
         glPushName(self.glname)
         self._draw(glpane, dispdef) #calls self._draw_jig()
     except:
         anythingDrawn = False
         glPopName()
         print_compact_traceback("ignoring exception when drawing Jig %r: " % self)
     else:
         glPopName()
         
     return anythingDrawn
示例#4
0
    def draw_sorted(sorted_by_color):   #russ 080320: factored out of finish().
        """
        Traverse color-sorted lists, invoking worker procedures.
        """
        objects_drawn = 0               # Keep track and return.
        glEnable(GL_LIGHTING)

        for color, funcs in sorted_by_color.iteritems():

            opacity = color[3]
            if opacity == -1:
                #piotr 080429: Opacity == -1 signals the "unshaded color".
                # Also, see my comment in "schedule".
                glDisable(GL_LIGHTING) # Don't forget to re-enable it!
                glColor3fv(color[:3])
            else:
                apply_material(color)
                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:
                glEnable(GL_LIGHTING)

            continue
        return objects_drawn
示例#5
0
    def draw_after_highlighting(self, glpane, dispdef, pickCheckOnly=False):
        """
        For ESPImage class, this does all the drawing. (does it after main
        drawing code is finished drawing) . This method ensures that the 
        ESP image jig gets selected even when you click inside the 
        rectangular box (i.e. not just along the edgets of the box)
        @see: GraphicsMode.Draw_after_highlighting()
        @see: Node.draw_after_highlighting()
        @see:Plane.draw_after_highlighting()
        """
        anythingDrawn = False
        if self.hidden:
            return anythingDrawn

        self.pickCheckOnly = pickCheckOnly
        try:
            anythingDrawn = True
            glPushName(self.glname)
            self._draw(glpane, dispdef)  #calls self._draw_jig()
        except:
            anythingDrawn = False
            glPopName()
            print_compact_traceback(
                "ignoring exception when drawing Jig %r: " % self)
        else:
            glPopName()

        return anythingDrawn
 def draw(self, glpane, dispdef):
     if self.hidden:
         return
     try:
         glPushName(self.glname)
         self._draw(glpane, dispdef)
     except:
         glPopName()
         print_compact_traceback("ignoring exception when drawing Plane %r: " % self)
     else:
         glPopName()
 def draw(self, glpane, dispdef):
     if self.hidden:
         return
     try:
         glPushName(self.glname)
         self._draw(glpane, dispdef)
     except:
         glPopName()
         print_compact_traceback(
             "ignoring exception when drawing Plane %r: " % self)
     else:
         glPopName()
示例#8
0
    def schedule(color, func, params):  # staticmethod
        if ColorSorter.sorting:

            ColorSorter._add_to_sorter(color, func, params)

        else:

            ColorSorter._immediate += 1  # for benchmark/debug stats, mostly

            # 20060216 We know we can do this here because the stack is
            # only ever one element deep
            name = ColorSorter._gl_name_stack[-1]
            if name:
                glPushName(name)
            ## Don't check in immediate drawing, e.g. preDraw_glselect_dict.
            ## else:
            ##   print "bug_1: attempt to push non-glname", name

            #Apply appropriate opacity for the object if it is specified
            #in the 'color' param. (Also do necessary things such as
            #call glBlendFunc it. -- Ninad 20071009

            if len(color) == 4:
                opacity = color[3]
            else:
                opacity = 1.0

            if opacity >= 0.0 and opacity != 1.0:
                glDepthMask(GL_FALSE)
                glEnable(GL_BLEND)
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            elif opacity == -1:
                # piotr 080429: I replaced the " < 0" condition with " == -1"
                # The opacity flag is now used to signal either "unshaded
                # colors" (opacity == -1) or "multicolor object" (opacity == -2)
                glDisable(GL_LIGHTING)  # Don't forget to re-enable it!
                glColor3fv(color[:3])
                pass

            apply_material(color)
            func(params)  # Call the draw worker function.

            if opacity > 0.0 and opacity != 1.0:
                glDisable(GL_BLEND)
                glDepthMask(GL_TRUE)
            elif opacity == -1:
                # piotr 080429: See my comment above.
                glEnable(GL_LIGHTING)

            if name:
                glPopName()
        return
示例#9
0
    def schedule(color, func, params): # staticmethod
        if ColorSorter.sorting:

            ColorSorter._add_to_sorter(color, func, params)

        else:

            ColorSorter._immediate += 1 # for benchmark/debug stats, mostly

            # 20060216 We know we can do this here because the stack is
            # only ever one element deep
            name = ColorSorter._gl_name_stack[-1]
            if name:
                glPushName(name)
            ## Don't check in immediate drawing, e.g. preDraw_glselect_dict.
            ## else:
            ##   print "bug_1: attempt to push non-glname", name

            #Apply appropriate opacity for the object if it is specified
            #in the 'color' param. (Also do necessary things such as
            #call glBlendFunc it. -- Ninad 20071009

            if len(color) == 4:
                opacity = color[3]
            else:
                opacity = 1.0

            if opacity >= 0.0 and opacity != 1.0:
                glDepthMask(GL_FALSE)
                glEnable(GL_BLEND)
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            elif opacity == -1:
                # piotr 080429: I replaced the " < 0" condition with " == -1"
                # The opacity flag is now used to signal either "unshaded
                # colors" (opacity == -1) or "multicolor object" (opacity == -2)
                glDisable(GL_LIGHTING)          # Don't forget to re-enable it!
                glColor3fv(color[:3])
                pass

            apply_material(color)
            func(params)                # Call the draw worker function.

            if opacity > 0.0 and opacity != 1.0:
                glDisable(GL_BLEND)
                glDepthMask(GL_TRUE)
            elif opacity == -1:
                # piotr 080429: See my comment above.
                glEnable(GL_LIGHTING)

            if name:
                glPopName()
        return
示例#10
0
 def draw(self):
     """ 
     Draw the direction arrow. (This method is called inside of the 
     parent object's drawing code.
     """
     try:
         glPushName(self.glname)
         if self.flipDirection:
             self._draw(flipDirection = self.flipDirection)    
         else:
             self._draw()
     except:
         glPopName()
         print_compact_traceback("ignoring exception when drawing handle %r: " % self)
     else:
         glPopName()        
     pass
示例#11
0
 def draw(self):
     """ 
     Draw the direction arrow. (This method is called inside of the 
     parent object's drawing code.
     """
     try:
         glPushName(self.glname)
         if self.flipDirection:
             self._draw(flipDirection = self.flipDirection)    
         else:
             self._draw()
     except:
         glPopName()
         print_compact_traceback("ignoring exception when drawing handle %r: " % self)
     else:
         glPopName()        
     pass
示例#12
0
 def draw(self, hCenter=None):
     """
     Public method to draw the resize handle. 
     @param hCenter: The center of the handle. If None, use the handle's 
                     I{center} property.
     @type  hCenter: L{V} or None
     @see: :{self._draw} which is called inside this method.
     """
     try:
         glPushName(self.glname)
         if hCenter:
             self._draw(hCenter)
         else:
             self._draw()
     except:
         glPopName()
         print_compact_traceback("ignoring exception when drawing handle %r: " % self)
     else:
         glPopName()
示例#13
0
 def draw(self, hCenter=None):
     """
     Public method to draw the resize handle. 
     @param hCenter: The center of the handle. If None, use the handle's 
                     I{center} property.
     @type  hCenter: L{V} or None
     @see: :{self._draw} which is called inside this method.
     """
     try:
         glPushName(self.glname)
         if hCenter:
             self._draw(hCenter)
         else:
             self._draw()
     except:
         glPopName()
         print_compact_traceback(
             "ignoring exception when drawing handle %r: " % self)
     else:
         glPopName()
示例#14
0
    def _draw_sorted(sorted_by_color):   #russ 080320: factored out of finish().
        """
        Traverse color-sorted lists, invoking worker procedures.
        """
        ### REVIEW: still needed? does this have some duplicated code with
        # parent_csdl.finish? If so, has this been maintained as that's been
        # modified? [bruce 090224 questions]

        glEnable(GL_LIGHTING)

        for color, funcs in sorted_by_color.iteritems():

            opacity = color[3]
            if opacity == -1:
                #piotr 080429: Opacity == -1 signals the "unshaded color".
                # Also, see my comment in "schedule".
                glDisable(GL_LIGHTING) # reenabled below
                glColor3fv(color[:3])
            else:
                apply_material(color)
                pass

            for func, params, name in funcs:
                if name:
                    glPushName(name)
                else:
                    pass ## print "bug_4: attempt to push non-glname", name
                func(params)            # Call the draw worker function.
                if name:
                    glPopName()
                    pass
                continue

            if opacity == -1:
                glEnable(GL_LIGHTING)

            continue
        return
示例#15
0
    def _draw_sorted(sorted_by_color):  #russ 080320: factored out of finish().
        """
        Traverse color-sorted lists, invoking worker procedures.
        """
        ### REVIEW: still needed? does this have some duplicated code with
        # parent_csdl.finish? If so, has this been maintained as that's been
        # modified? [bruce 090224 questions]

        glEnable(GL_LIGHTING)

        for color, funcs in sorted_by_color.iteritems():

            opacity = color[3]
            if opacity == -1:
                #piotr 080429: Opacity == -1 signals the "unshaded color".
                # Also, see my comment in "schedule".
                glDisable(GL_LIGHTING)  # reenabled below
                glColor3fv(color[:3])
            else:
                apply_material(color)
                pass

            for func, params, name in funcs:
                if name:
                    glPushName(name)
                else:
                    pass  ## print "bug_4: attempt to push non-glname", name
                func(params)  # Call the draw worker function.
                if name:
                    glPopName()
                    pass
                continue

            if opacity == -1:
                glEnable(GL_LIGHTING)

            continue
        return
示例#16
0
 def pop_saved_names(self):
     for glname in self.saved_glnames:  # wrong order, but only the total number matters
         glPopName()
示例#17
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
示例#18
0
    def finish(self, sorted_by_color):  #bruce 090224 split this out of caller
        """
        Finish collecting new primitives for use in self, and store them all
        in self, ready to be drawn in various ways.

        [meant to be called only by ColorSorter.start, for now]
        """
        ##        self._reset()
        ##            # (note: this deallocates any existing display lists)

        if self.transformControl and (self.spheres or self.cylinders):
            self.updateTransform()
            # needed to do the transform for the first time,
            # even if it didn't change. Review: refactor to
            # whereever we first compile these down? That
            # might be a different place in self.draw vs.
            # draw from DrawingSet.

        selColor = env.prefs[selectionColor_prefs_key]

        # Note: if sorted_by_color is empty, current code still builds all
        # toplevel display lists, though they are noops. This may be needed
        # by some client code which uses those dls directly. Client code
        # wanting to know if it needs to draw our dls should test
        # self.has_nonempty_DLs(), which tests self._per_color_dls,
        # or self.has_nonshader_drawing(), which reports on that or any
        # other kind of nonshader (immediate mode opengl) drawing we might
        # have. [bruce 090225/090312 comment]

        # First build the lower level per-color sublists of primitives.

        for color, funcs in sorted_by_color.iteritems():
            sublists = [glGenLists(1), 0]

            # Remember the display list ID for this color.
            self._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:
                if name:
                    glPushName(name)
                else:
                    pass  ## print "bug_2: attempt to push non-glname", name
                func(params)  # Call the draw worker function.
                if name:
                    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:
                    if name:
                        glPushName(name)
                    else:
                        pass  ## print "bug_3: attempt to push non-glname", 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_junk, 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_junk = params
                        drawtriangle_strip_worker(
                            (pos_array, normal_array, None))
                    if name:
                        glPopName()
                        pass
                    continue
                glEndList()

            continue

        # Now the upper-level lists call all of the per-color sublists.
        #### REVIEW: these are created even when empty. Is that necessary?
        # [bruce 090224 Q]

        # One with colors.
        color_dl = self.color_dl = glGenLists(1)
        glNewList(color_dl, GL_COMPILE)

        for color, dls in self._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 = self.nocolor_dl = glGenLists(1)
        glNewList(nocolor_dl, GL_COMPILE)
        for color, dls in self._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 = self.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()
        pass
示例#19
0
 def pop_name(self):
     glPopName()
    def finish(self, sorted_by_color):  # bruce 090224 split this out of caller
        """
        Finish collecting new primitives for use in self, and store them all
        in self, ready to be drawn in various ways.

        [meant to be called only by ColorSorter.start, for now]
        """
        ##        self._reset()
        ##            # (note: this deallocates any existing display lists)

        if self.transformControl and (self.spheres or self.cylinders):
            self.updateTransform()
            # needed to do the transform for the first time,
            # even if it didn't change. Review: refactor to
            # whereever we first compile these down? That
            # might be a different place in self.draw vs.
            # draw from DrawingSet.

        selColor = env.prefs[selectionColor_prefs_key]

        # Note: if sorted_by_color is empty, current code still builds all
        # toplevel display lists, though they are noops. This may be needed
        # by some client code which uses those dls directly. Client code
        # wanting to know if it needs to draw our dls should test
        # self.has_nonempty_DLs(), which tests self._per_color_dls,
        # or self.has_nonshader_drawing(), which reports on that or any
        # other kind of nonshader (immediate mode opengl) drawing we might
        # have. [bruce 090225/090312 comment]

        # First build the lower level per-color sublists of primitives.

        for color, funcs in sorted_by_color.iteritems():
            sublists = [glGenLists(1), 0]

            # Remember the display list ID for this color.
            self._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:
                if name:
                    glPushName(name)
                else:
                    pass  ## print "bug_2: attempt to push non-glname", name
                func(params)  # Call the draw worker function.
                if name:
                    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:
                    if name:
                        glPushName(name)
                    else:
                        pass  ## print "bug_3: attempt to push non-glname", 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_junk, 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_junk = params
                        drawtriangle_strip_worker((pos_array, normal_array, None))
                    if name:
                        glPopName()
                        pass
                    continue
                glEndList()

            continue

        # Now the upper-level lists call all of the per-color sublists.
        #### REVIEW: these are created even when empty. Is that necessary?
        # [bruce 090224 Q]

        # One with colors.
        color_dl = self.color_dl = glGenLists(1)
        glNewList(color_dl, GL_COMPILE)

        for color, dls in self._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 = self.nocolor_dl = glGenLists(1)
        glNewList(nocolor_dl, GL_COMPILE)
        for color, dls in self._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 = self.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()
        pass
示例#21
0
 def pop_saved_names(self):
     for glname in self.saved_glnames: # wrong order, but only the total number matters
         glPopName()
示例#22
0
 def draw_after_highlighting(self,  glpane, dispdef, pickCheckOnly = False):
     """
     Things to draw after highlighting. Subclasses should override this 
     method. This API method ensures that , when user clicks on the filled
     area of a plane, the plane gets selected. 
             
     @param pickCheckOnly: This flag in conjunction with this API method
             allows selection of the plane when you click inside the plane 
              (i.e. not along the highlighted plane borders) . 
              (Note flag copied over from the old implementation 
              before 2008-06-20)
     @type pickCheckOnly: boolean
     
     @return: A boolean flag 'anythingDrawn' that tells whether this method
              drew something. 
     @rtype: boolean
     
     @see: GraphicsMode.Draw_after_highlighting()
     @see: Node.draw_after_highlighting() which is overridden here   
     """      
     #This implementation fixes bug 2900
     anythingDrawn = False
     
     if self.hidden:
         return False
     
     self.pickCheckOnly = pickCheckOnly
     
     try:
         anythingDrawn = True
         
         glPushName(self.glname)
         glPushMatrix()
         glTranslatef( self.center[0], self.center[1], self.center[2])
         q = self.quat
         glRotatef( q.angle * ONE_RADIAN, 
                    q.x,
                    q.y,
                    q.z)   
    
         if dot(self.getaxis(), glpane.lineOfSight) < 0:
             fill_color = brown #backside
         else:
             fill_color = self.fill_color
          
         # Urmi-20080613: display grid lines on the plane
 
         if env.prefs[PlanePM_showGrid_prefs_key]:
             drawGPGridForPlane(self.glpane, self.gridColor, self.gridLineType, 
                                self.width, self.height, 
                                self.gridXSpacing, self.gridYSpacing,
                                self.quat.unrot(self.glpane.up), 
                                self.quat.unrot(self.glpane.right), 
                                env.prefs[PlanePM_showGridLabels_prefs_key], 
                                self.originLocation, 
                                self.displayLabelStyle)
             
         textureReady = False
 
         if self.display_image and \
            self.tex_image:
             textureReady = True
             glBindTexture(GL_TEXTURE_2D, self.tex_image)
             fill_color = [1.0,1.0,1.0]
             
         if self.display_heightfield:
             if self.heightfield and \
                self.image:
                 if not self.heightfield_use_texture:
                     textureReady = False
                 drawHeightfield(fill_color, 
                           self.width, 
                           self.height, 
                           textureReady,
                           self.opacity, 
                           SOLID=True, 
                           pickCheckOnly=self.pickCheckOnly,
                           hf=self.heightfield)
         else:
             drawPlane(fill_color, 
                       self.width, 
                       self.height, 
                       textureReady,
                       self.opacity, 
                       SOLID=True, 
                       pickCheckOnly=self.pickCheckOnly,
                       tex_coords=self.tex_coords)
  
         glPopMatrix()
         
     except:
         anythingDrawn = False
         glPopName()
         print_compact_traceback(
             "ignoring exception when drawing Plane %r: " % self)
     else:
         glPopName()
     
     return anythingDrawn
示例#23
0
 def pop_name(self):
     glPopName()
示例#24
0
    def draw_after_highlighting(self, glpane, dispdef, pickCheckOnly=False):
        """
        Things to draw after highlighting. Subclasses can override this 
        method. This API method ensures that, when user clicks on the filled
        area of a plane, the plane gets selected. 
                
        @param pickCheckOnly: This flag in conjunction with this API method
                allows selection of the plane when you click inside the plane 
                 (i.e. not along the highlighted plane borders) . 
                 (Note: flag copied over from the old implementation 
                 before 2008-06-20)
        @type pickCheckOnly: boolean
        
        @return: A boolean flag 'anythingDrawn' that tells whether this method
                 drew something. 
        @rtype: boolean
        
        @see: Node.draw_after_highlighting() which is overridden here   
        """
        #This implementation fixes bug 2900
        anythingDrawn = False

        if self.hidden:
            return anythingDrawn

        self.pickCheckOnly = pickCheckOnly

        try:
            anythingDrawn = True

            glPushName(self.glname)
            glPushMatrix()
            glTranslatef(self.center[0], self.center[1], self.center[2])
            q = self.quat
            glRotatef(q.angle * ONE_RADIAN, q.x, q.y, q.z)

            if dot(self.getaxis(), glpane.lineOfSight) < 0:
                fill_color = brown  #backside
            else:
                fill_color = self.fill_color

            # Urmi-20080613: display grid lines on the plane

            if env.prefs[PlanePM_showGrid_prefs_key]:
                drawGPGridForPlane(self.glpane, self.gridColor,
                                   self.gridLineType, self.width, self.height,
                                   self.gridXSpacing, self.gridYSpacing,
                                   self.quat.unrot(self.glpane.up),
                                   self.quat.unrot(self.glpane.right),
                                   env.prefs[PlanePM_showGridLabels_prefs_key],
                                   self.originLocation, self.displayLabelStyle)

            textureReady = False

            if self.display_image and \
               self.tex_image:
                textureReady = True
                glBindTexture(GL_TEXTURE_2D, self.tex_image)
                fill_color = [1.0, 1.0, 1.0]

            if self.display_heightfield:
                if self.heightfield and \
                   self.image:
                    if not self.heightfield_use_texture:
                        textureReady = False
                    drawHeightfield(fill_color,
                                    self.width,
                                    self.height,
                                    textureReady,
                                    self.opacity,
                                    SOLID=True,
                                    pickCheckOnly=self.pickCheckOnly,
                                    hf=self.heightfield)
            else:
                drawPlane(fill_color,
                          self.width,
                          self.height,
                          textureReady,
                          self.opacity,
                          SOLID=True,
                          pickCheckOnly=self.pickCheckOnly,
                          tex_coords=self.tex_coords)

            glPopMatrix()

        except:
            anythingDrawn = False
            glPopName()
            print_compact_traceback(
                "ignoring exception when drawing Plane %r: " % self)
        else:
            glPopName()

        return anythingDrawn
示例#25
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