python: Cleanup.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Tue, 15 Jul 2008 08:57:48 +0000 (17:57 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Tue, 15 Jul 2008 08:58:48 +0000 (17:58 +0900)
src/gallium/state_trackers/python/samples/tri.py
src/gallium/state_trackers/python/tests/base.py
src/gallium/state_trackers/python/tests/texture.py

index e5044a02458bc9708faaf27e3b7d98fadbf50bb1..366592292980946ebbf1b80276f42d7965a66f87 100644 (file)
@@ -143,24 +143,16 @@ def test(dev):
     cbuf = dev.texture_create(PIPE_FORMAT_X8R8G8B8_UNORM, 
                               width, height,
                               usage=PIPE_TEXTURE_USAGE_DISPLAY_TARGET)
-    zbuf = dev.texture_create(PIPE_FORMAT_X8Z24_UNORM, 
-                              width, height,
-                              usage=PIPE_TEXTURE_USAGE_DEPTH_STENCIL)
     _cbuf = cbuf.get_surface(usage = PIPE_BUFFER_USAGE_GPU_READ|PIPE_BUFFER_USAGE_GPU_WRITE)
-    _zsbuf = zbuf.get_surface(usage = PIPE_BUFFER_USAGE_GPU_READ|PIPE_BUFFER_USAGE_GPU_WRITE)
     fb = Framebuffer()
     fb.width = width
     fb.height = height
     fb.num_cbufs = 1
     fb.set_cbuf(0, _cbuf)
-    fb.set_zsbuf(_zsbuf)
     ctx.set_framebuffer(fb)
     _cbuf.clear_value = 0x00000000
-    _zsbuf.clear_value = 0x00ffffff
     ctx.surface_clear(_cbuf, _cbuf.clear_value)
-    ctx.surface_clear(_zsbuf, _zsbuf.clear_value)
     del _cbuf
-    del _zsbuf
     
     # vertex shader
     vs = Shader('''
index 185a59996e67db0e866ed6a3711bca1dd47ffe53..d5d6114a45db7c7008a09b2c6ea7c61d83b0729f 100644 (file)
@@ -37,28 +37,25 @@ for name, value in globals().items():
         formats[value] = name
 
 
-def make_image(surface):
-    pixels = FloatArray(surface.height*surface.width*4)
-    surface.get_tile_rgba(0, 0, surface.width, surface.height, pixels)
-
+def make_image(width, height, rgba):
     import Image
     outimage = Image.new(
         mode='RGB',
-        size=(surface.width, surface.height),
+        size=(width, height),
         color=(0,0,0))
     outpixels = outimage.load()
-    for y in range(0, surface.height):
-        for x in range(0, surface.width):
-            offset = (y*surface.width + x)*4
-            r, g, b, a = [int(pixels[offset + ch]*255) for ch in range(4)]
+    for y in range(0, height):
+        for x in range(0, width):
+            offset = (y*width + x)*4
+            r, g, b, a = [int(rgba[offset + ch]*255) for ch in range(4)]
             outpixels[x, y] = r, g, b
     return outimage
 
-def save_image(filename, surface):
-    outimage = make_image(surface)
+def save_image(width, height, rgba, filename):
+    outimage = make_image(width, height, rgba)
     outimage.save(filename, "PNG")
 
-def show_image(*surfaces):
+def show_image(width, height, **rgbas):
     import Tkinter as tk
     from PIL import Image, ImageTk
 
@@ -67,15 +64,17 @@ def show_image(*surfaces):
     x = 64
     y = 64
     
-    for i in range(len(surfaces)):
-        surface = surfaces[i]
-        outimage = make_image(surface)
+    labels = rgbas.keys()
+    labels.sort() 
+    for i in range(len(labels)):
+        label = labels[i]
+        outimage = make_image(width, height, rgbas[label])
         
         if i:
             window = tk.Toplevel(root)
         else:
             window = root    
-        window.title('Image %u' % (i+1))
+        window.title(label)
         image1 = ImageTk.PhotoImage(outimage)
         w = image1.width()
         h = image1.height()
index 84ceebb169413565c67436b43a6f66bd187fc463..6a5ffb38b958a6729202b749bad1f0557e2481f5 100644 (file)
@@ -61,8 +61,8 @@ class TextureTest(Test):
     def run(self):
         dev = self.dev
         
-        format = PIPE_FORMAT_A8R8G8B8_UNORM
-        #format = PIPE_FORMAT_DXT1_RGB
+        #format = PIPE_FORMAT_A8R8G8B8_UNORM
+        format = PIPE_FORMAT_DXT1_RGB
         
         if not dev.is_format_supported(format, PIPE_TEXTURE):
             pass
@@ -130,20 +130,21 @@ class TextureTest(Test):
         
         expected_rgba = generate_data(texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE))
         
+        #  framebuffer 
         cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, 
                                       width, 
                                       height,
                                       usage = PIPE_TEXTURE_USAGE_RENDER_TARGET)
 
-        #  drawing dest 
         cbuf = cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_GPU_WRITE|PIPE_BUFFER_USAGE_GPU_READ)
         fb = Framebuffer()
         fb.width = width
         fb.height = height
         fb.num_cbufs = 1
         fb.set_cbuf(0, cbuf)
-        ctx.surface_clear(cbuf, 0x00000000)
         ctx.set_framebuffer(fb)
+        ctx.surface_clear(cbuf, 0x00000000)
+        del fb
     
         # vertex shader
         vs = Shader('''
@@ -220,14 +221,15 @@ class TextureTest(Test):
     
         ctx.flush()
 
+        del ctx
+        
         rgba = FloatArray(height*width*4)
 
         cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ).get_tile_rgba(x, y, w, h, rgba)
 
         compare_rgba(width, height, rgba, expected_rgba)
         
-        show_image(texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ), 
-                   cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ))
+        show_image(width, height, Result=rgba, Expected=expected_rgba)
 
 
 def main():