2 ##########################################################################
4 # Copyright 2009 VMware, Inc.
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sub license, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice (including the
16 # next paragraph) shall be included in all copies or substantial portions
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 # IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 ##########################################################################
34 def make_image(surface
):
35 data
= surface
.get_tile_rgba8(0, 0, surface
.width
, surface
.height
)
38 outimage
= Image
.fromstring('RGBA', (surface
.width
, surface
.height
), data
, "raw", 'RGBA', 0, 1)
41 def save_image(filename
, surface
):
42 outimage
= make_image(surface
)
43 outimage
.save(filename
, "PNG")
46 ctx
= dev
.context_create()
53 # disabled blending/masking
55 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_ONE
56 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_ONE
57 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_ZERO
58 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
59 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
63 depth_stencil_alpha
= DepthStencilAlpha()
64 depth_stencil_alpha
.depth
.enabled
= 0
65 depth_stencil_alpha
.depth
.writemask
= 1
66 depth_stencil_alpha
.depth
.func
= PIPE_FUNC_LESS
67 ctx
.set_depth_stencil_alpha(depth_stencil_alpha
)
70 rasterizer
= Rasterizer()
71 rasterizer
.front_winding
= PIPE_WINDING_CW
72 rasterizer
.cull_mode
= PIPE_WINDING_NONE
73 rasterizer
.scissor
= 1
74 ctx
.set_rasterizer(rasterizer
)
79 scale
[0] = width
/ 2.0
80 scale
[1] = -height
/ 2.0
81 scale
[2] = (maxz
- minz
) / 2.0
83 viewport
.scale
= scale
84 translate
= FloatArray(4)
85 translate
[0] = width
/ 2.0
86 translate
[1] = height
/ 2.0
87 translate
[2] = (maxz
- minz
) / 2.0
89 viewport
.translate
= translate
90 ctx
.set_viewport(viewport
)
94 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
95 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
96 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
97 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
98 sampler
.min_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
99 sampler
.mag_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
100 sampler
.normalized_coords
= 1
101 ctx
.set_fragment_sampler(0, sampler
)
108 scissor
.maxy
= height
109 ctx
.set_scissor(scissor
)
116 cbuf
= dev
.resource_create(
117 PIPE_FORMAT_B8G8R8X8_UNORM
,
119 bind
=PIPE_BIND_RENDER_TARGET
,
126 ctx
.set_framebuffer(fb
)
127 rgba
= FloatArray(4);
132 ctx
.clear(PIPE_CLEAR_COLOR
, rgba
, 0.0, 0)
135 vs
= Shader(file('vert-' + name
+ '.sh', 'rt').read())
136 ctx
.set_vertex_shader(vs
)
141 DCL IN[0], COLOR, LINEAR
142 DCL OUT[0], COLOR, CONSTANT
146 ctx
.set_fragment_shader(fs
)
148 constbuf0
= dev
.buffer_create(64,
149 (PIPE_BUFFER_USAGE_CONSTANT |
150 PIPE_BUFFER_USAGE_GPU_READ |
151 PIPE_BUFFER_USAGE_CPU_WRITE
),
155 cbdata
+= struct
.pack('4f', 0.4, 0.0, 0.0, 1.0)
156 cbdata
+= struct
.pack('4f', 1.0, 1.0, 1.0, 1.0)
157 cbdata
+= struct
.pack('4f', 2.0, 2.0, 2.0, 2.0)
158 cbdata
+= struct
.pack('4f', 4.0, 8.0, 16.0, 32.0)
160 constbuf0
.write(cbdata
, 0)
162 ctx
.set_constant_buffer(PIPE_SHADER_VERTEX
,
166 constbuf1
= dev
.buffer_create(64,
167 (PIPE_BUFFER_USAGE_CONSTANT |
168 PIPE_BUFFER_USAGE_GPU_READ |
169 PIPE_BUFFER_USAGE_CPU_WRITE
),
173 cbdata
+= struct
.pack('4f', 0.1, 0.1, 0.1, 0.1)
174 cbdata
+= struct
.pack('4f', 0.25, 0.25, 0.25, 0.25)
175 cbdata
+= struct
.pack('4f', 0.5, 0.5, 0.5, 0.5)
176 cbdata
+= struct
.pack('4f', 0.75, 0.75, 0.75, 0.75)
178 constbuf1
.write(cbdata
, 0)
180 ctx
.set_constant_buffer(PIPE_SHADER_VERTEX
,
227 verts
= FloatArray(nverts
* nattrs
* 4)
229 for i
in range(0, nverts
):
230 verts
[i
* nattrs
* 4 + 0] = xy
[tri
[i
] * 2 + 0] # x
231 verts
[i
* nattrs
* 4 + 1] = xy
[tri
[i
] * 2 + 1] # y
232 verts
[i
* nattrs
* 4 + 2] = 0.5 # z
233 verts
[i
* nattrs
* 4 + 3] = 1.0 # w
234 verts
[i
* nattrs
* 4 + 4] = color
[(i
% 3) * 3 + 0] # r
235 verts
[i
* nattrs
* 4 + 5] = color
[(i
% 3) * 3 + 1] # g
236 verts
[i
* nattrs
* 4 + 6] = color
[(i
% 3) * 3 + 2] # b
237 verts
[i
* nattrs
* 4 + 7] = 1.0 # a
239 ctx
.draw_vertices(PIPE_PRIM_TRIANGLES
,
246 save_image('vert-' + name
+ '.png', cbuf
)
286 if __name__
== '__main__':