2
0
David Rose 17 жил өмнө
parent
commit
a5972c42fc

+ 27 - 8
direct/src/showutil/TexMemWatcher.py

@@ -45,10 +45,26 @@ class TexMemWatcher(DirectObject):
         fbprops = FrameBufferProperties.getDefault()
         fbprops = FrameBufferProperties.getDefault()
         flags = GraphicsPipe.BFFbPropsOptional | GraphicsPipe.BFRequireWindow
         flags = GraphicsPipe.BFFbPropsOptional | GraphicsPipe.BFRequireWindow
 
 
-        self.win = base.graphicsEngine.makeOutput(base.pipe, name, 0, fbprops,
+        self.pipe = None
+
+        # We should use a tinydisplay pipe, so we don't compete for the
+        # graphics memory.
+        moduleName = base.config.GetString('tex-mem-pipe', 'tinydisplay')
+        if moduleName:
+            self.pipe = base.makeModulePipe(moduleName)
+
+        # If the requested pipe fails for some reason, I guess we'll
+        # use the regular pipe.
+        if not self.pipe:
+            self.pipe = base.pipe
+        
+        self.win = base.graphicsEngine.makeOutput(self.pipe, name, 0, fbprops,
                                                   props, flags)
                                                   props, flags)
         assert self.win
         assert self.win
 
 
+        # We should render at the end of the frame.
+        self.win.setSort(10000)
+
         # Set our GSG to a texture memory limit of 0.  This will force
         # Set our GSG to a texture memory limit of 0.  This will force
         # it to unload any textures as soon as they are offscreen, so
         # it to unload any textures as soon as they are offscreen, so
         # that our GSG's texture memory utilization will match that of
         # that our GSG's texture memory utilization will match that of
@@ -224,7 +240,7 @@ class TexMemWatcher(DirectObject):
                     texRecords.append(tr)
                     texRecords.append(tr)
                 else:
                 else:
                     tr.setActive(active)
                     tr.setActive(active)
-                    if tr.size != size:
+                    if tr.size != size or not tr.placements:
                         # The size has changed; reapply it.
                         # The size has changed; reapply it.
                         tr.setSize(size)
                         tr.setSize(size)
                         self.unplaceTexture(tr)
                         self.unplaceTexture(tr)
@@ -234,10 +250,11 @@ class TexMemWatcher(DirectObject):
                     # This texture is no longer resident; need to remove it.
                     # This texture is no longer resident; need to remove it.
                     self.unplaceTexture(tr)
                     self.unplaceTexture(tr)
 
 
-        # Now go through and make sure we unplace any textures that we
-        # didn't visit at all this pass.
-        for tr in neverVisited.values():
+        # Now go through and make sure we unplace (and remove!) any
+        # textures that we didn't visit at all this pass.
+        for tex, tr in neverVisited.items():
             self.unplaceTexture(tr)
             self.unplaceTexture(tr)
+            del self.texRecords[tex]
 
 
         self.totalSize = totalSize
         self.totalSize = totalSize
         if totalSize > self.limit and self.dynamicLimit:
         if totalSize > self.limit and self.dynamicLimit:
@@ -479,7 +496,7 @@ class TexMemWatcher(DirectObject):
                     tpw0 = overlap.p[0] - x
                     tpw0 = overlap.p[0] - x
                     if tpw0 <= 0.0:
                     if tpw0 <= 0.0:
                         break
                         break
-                    if tpw0 == tpw:
+                    if x + tpw0 == x + tpw:
                         tpw0 *= 0.999  # imprecision hack
                         tpw0 *= 0.999  # imprecision hack
                     tpw = tpw0
                     tpw = tpw0
                     tph = area / tpw
                     tph = area / tpw
@@ -572,14 +589,16 @@ class TexMemWatcher(DirectObject):
 
 
                     if tpw0 * tph > tpw * tph0:
                     if tpw0 * tph > tpw * tph0:
                         # Shortening width results in larger.
                         # Shortening width results in larger.
-                        if tpw == tpw0:
+                        if x + tpw == x + tpw0:
                             tpw0 *= 0.999  # imprecision hack
                             tpw0 *= 0.999  # imprecision hack
                         tpw = tpw0
                         tpw = tpw0
                     else:
                     else:
                         # Shortening height results in larger.
                         # Shortening height results in larger.
-                        if tph == tph0:
+                        if y + tph == y + tph0:
                             tph0 *= 0.999  # imprecision hack
                             tph0 *= 0.999  # imprecision hack
                         tph = tph0
                         tph = tph0
+                    print "x = %s, y = %s, tpw = %s, tph = %s" % (
+                        x, y, tpw, tph)
                 
                 
                 assert nextX > x
                 assert nextX > x
                 x = nextX
                 x = nextX