/[libvob]/libvob/vob/fillet/light3d.py
ViewVC logotype

Diff of /libvob/vob/fillet/light3d.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21 by tjl, Mon Jun 30 07:22:38 2003 UTC revision 1.22 by jvk, Mon Jun 30 11:04:18 2003 UTC
# Line 134  commonkeys = [ Line 134  commonkeys = [
134              SlideLin("thick", 1, .1, "thickness", "T", "t"),              SlideLin("thick", 1, .1, "thickness", "T", "t"),
135              Toggle("drawEdge", 1, "Draw edge", "e"),              Toggle("drawEdge", 1, "Draw edge", "e"),
136              Toggle("drawInside", 1, "Draw inside", "i"),              Toggle("drawInside", 1, "Draw inside", "i"),
137              Toggle("depthColor", 0, "Color from depth", "d"),              Toggle("depthColor", 1, "Color from depth", "d"),
138              Toggle("lines", 0, "Toggle showing lines", "l"),              Toggle("lines", 0, "Toggle showing lines", "l"),
139              Toggle("ellipses", 1, "Toggle ellipses", "s"),              Toggle("ellipses", 1, "Toggle ellipses", "s"),
140              Toggle("stretched", 1, "Toggle stretched", "v"),              Toggle("stretched", 1, "Toggle stretched", "v"),
# Line 145  commonkeys = [ Line 145  commonkeys = [
145              SlideLin("seed", 42, 1, "seed number", "A", "a"),              SlideLin("seed", 42, 1, "seed number", "A", "a"),
146              SlideLin("size", 100, 10, "Node size", "K", "k"),              SlideLin("size", 100, 10, "Node size", "K", "k"),
147              SlideLin("dice", 20, 1, "Dice factor", "P", "p"),              SlideLin("dice", 20, 1, "Dice factor", "P", "p"),
148              Toggle("fillet3d", 0, "3D fillets", "3"),              Toggle("fillet3d", 1, "3D fillets", "3"),
149              Toggle("blend3d", 0, "3D fillets blend", "4"),              Toggle("blend3d", 0, "3D fillets blend", "4"),
150              SlideLin("linewidth", 2, 1, "line width", "B", "b"),              SlideLin("linewidth", 2, 1, "line width", "B", "b"),
151              Toggle("perspective", 0, "perspective", "F"),              Toggle("perspective", 0, "perspective", "F"),
152              Toggle("texture", 0, "texture", "x"),              Toggle("texture", 0, "texture", "x"),
153  ]  ]
154    
155    width = 0
156    height = 0
157    directDepthCopy = 0
158    
159    def initBuffers(w, h):
160        print "initBuffers(%s,%s)" % (w,h)
161        global width, height, depthTexture, tmpTexture, directDepthCopy
162        if width == w and height == h: return
163    
164        depthTexture = GL.createTexture()
165        tmpTexture = GL.createTexture()
166            
167        if not GL.hasExtension("GL_NV_texture_rectangle"): return
168    
169        width,height = w,h
170    
171        rect = 1
172        targ = "TEXTURE_RECTANGLE_NV"
173        if directDepthCopy:
174            depthTexture.loadNull2D("TEXTURE_RECTANGLE_NV", 0, "DEPTH_COMPONENT24",
175                                    width, height, 0, "DEPTH_COMPONENT",
176                                    "INT")
177        else:
178            depthTexture.loadNull2D("TEXTURE_RECTANGLE_NV", 0, "RGBA8",
179                                    width, height, 0, "BGRA",
180                                    "UNSIGNED_INT_8_8_8_8")
181    
182            tmpTexture.loadNull2D("TEXTURE_RECTANGLE_NV", 0, "RGB8",
183                                  width, height, 0, "RGB",
184                                  "INT")
185            
186        depthTexture.setTexParameter(targ, "TEXTURE_MIN_FILTER", "LINEAR")
187        depthTexture.setTexParameter(targ, "TEXTURE_MAG_FILTER", "LINEAR")
188    
189    
190    
191  def drawFillets(self, vs, pc):  def drawFillets(self, vs, pc):
192          vs.put(getDListNocoords("""          vs.put(getDListNocoords("""
# Line 215  def drawFillets(self, vs, pc): Line 250  def drawFillets(self, vs, pc):
250              PushMatrix              PushMatrix
251              """ % vp[0].getProgId()))              """ % vp[0].getProgId()))
252    
253                if not self.depthColor:
254                    vs.put(getDListNocoords("""
255                    Disable VERTEX_PROGRAM_ARB
256                    """))
257    
258              if self.texture:              if self.texture:
259                  vs.put(getDListNocoords("""                  vs.put(getDListNocoords("""
260                  BindTexture TEXTURE_2D %s                  BindTexture TEXTURE_2D %s
# Line 267  def drawFillets(self, vs, pc): Line 307  def drawFillets(self, vs, pc):
307              BindTexture TEXTURE_2D 0              BindTexture TEXTURE_2D 0
308              PopAttrib              PopAttrib
309          """))          """))
310    
311    
312            if self.fillet3d and self.drawEdge:
313                size = vs.getSize()
314                initBuffers(size.width, size.height)
315    
316                # Now, draw the edges
317                if directDepthCopy:
318                    vs.put(getDListNocoords("""
319                        BindTexture TEXTURE_RECTANGLE_NV %s
320                    """ % depthTexture.getTexId()))
321                    vs.put(GLRen.createCopyTexSubImage2D("TEXTURE_RECTANGLE_NV",
322                                                         0, 0, 0, width, height),
323                           0)
324    
325                else:
326                    vs.put(getDListNocoords("""
327                    PushAttrib ENABLE_BIT
328                    Disable ALPHA_TEST
329                    Disable DEPTH_TEST
330                    Disable TEXTURE_RECTANGLE_NV
331                    Disable TEXTURE_2D
332                    """))
333    
334                    # Copy the color buffer to a texture
335                    vs.put(getDListNocoords("""
336                        BindTexture TEXTURE_RECTANGLE_NV %s
337                        """ % tmpTexture.getTexId()))
338                    vs.put(GLRen.createCopyTexSubImage2D("TEXTURE_RECTANGLE_NV",
339                                                         0, 0, 0, width, height),
340                           0)
341    
342                    # Copy stencil&depth to color
343                    csdest = vs.translateCS(0,"copydest",0,height)
344                    vs.put(GLRen.createCopyPixels(width, height,
345                                                  "DEPTH_STENCIL_TO_BGRA_NV"),
346                           0,
347                           csdest,
348                           )
349    
350                    # Read the depth to a texture
351                    vs.put(getDListNocoords("""
352                        BindTexture TEXTURE_RECTANGLE_NV %s
353                        """ % depthTexture.getTexId()))
354                    vs.put(GLRen.createCopyTexSubImage2D("TEXTURE_RECTANGLE_NV",
355                                                         0, 0, 0, width, height),
356                           0)
357    
358                    # Copy the color back from the backup texture
359                    vs.put(getDListNocoords("""
360                        BindTexture TEXTURE_RECTANGLE_NV %s
361                        Enable TEXTURE_RECTANGLE_NV
362                        """ % tmpTexture.getTexId()))
363                    vs.put(getDList("""
364                        Color 1 1 1
365                        Begin QUAD_STRIP
366                        TexCoord 0 0
367                        Vertex 0 %(h)s
368                        
369                        TexCoord 0 %(h)s
370                        Vertex 0 0
371                        
372                        TexCoord %(w)s  0
373                        Vertex %(w)s %(h)s
374                        
375                        TexCoord %(w)s %(h)s
376                        Vertex %(w)s 0
377                        End
378                    """ % { "w" : width, "h" : height }), 0)
379                
380                    vs.put(getDListNocoords("""
381                        PopAttrib
382                    """))
383    
384                vs.put(getDListNocoords("""
385                    PushAttrib ENABLE_BIT
386                    Color 1 1 1
387                    BindProgram FRAGMENT_PROGRAM_NV %s
388                    Enable FRAGMENT_PROGRAM_NV
389                    Enable BLEND
390                    BindTexture TEXTURE_RECTANGLE_NV %s
391                """ % (edgefp.getProgId(),
392                       depthTexture.getTexId())))
393    
394                vs.put(quad(), vs.orthoCS(0, "nprEdgeQuad", -100, 0, 0,
395                                          width, height))
396    
397                vs.put(getDListNocoords("""
398                    BindTexture TEXTURE_RECTANGLE_NV 0
399                    PopAttrib
400                """))

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26