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('''
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
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()
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
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('''
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():