2 ##########################################################################
4 # Copyright 2009 VMware, Inc.
5 # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
8 # Permission is hereby granted, free of charge, to any person obtaining a
9 # copy of this software and associated documentation files (the
10 # "Software"), to deal in the Software without restriction, including
11 # without limitation the rights to use, copy, modify, merge, publish,
12 # distribute, sub license, and/or sell copies of the Software, and to
13 # permit persons to whom the Software is furnished to do so, subject to
14 # the following conditions:
16 # The above copyright notice and this permission notice (including the
17 # next paragraph) shall be included in all copies or substantial portions
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 # IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
24 # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 ##########################################################################
44 def minify(dims, level = 1):
45 return [max(dim>>level, 1) for dim in dims]
48 def tex_coords(texture, face, level, zslice):
56 if texture.target == PIPE_TEXTURE_2D:
57 return [[s, t, 0.0] for s, t in st]
58 elif texture.target == PIPE_TEXTURE_3D:
59 depth = texture.get_depth(level)
61 r = float(zslice)/float(depth - 1)
64 return [[s, t, r] for s, t in st]
65 elif texture.target == PIPE_TEXTURE_CUBE:
68 # See http://developer.nvidia.com/object/cube_map_ogl_tutorial.html
71 if face == PIPE_TEX_FACE_POS_X:
75 if face == PIPE_TEX_FACE_NEG_X:
79 if face == PIPE_TEX_FACE_POS_Y:
83 if face == PIPE_TEX_FACE_NEG_Y:
87 if face == PIPE_TEX_FACE_POS_Z:
91 if face == PIPE_TEX_FACE_NEG_Z:
95 result.append([rx, ry, rz])
99 return n & (n - 1) == 0
102 class TextureTest(TestCase):
124 last_level = self.last_level
129 tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
132 geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE
133 if not is_pot(width) or not is_pot(height) or not is_pot(depth):
134 geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO
136 if not dev.is_format_supported(format, target, tex_usage, geom_flags):
139 ctx = self.dev.context_create()
141 # disabled blending/masking
143 blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE
144 blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE
145 blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
146 blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
147 blend.colormask = PIPE_MASK_RGBA
150 # no-op depth/stencil/alpha
151 depth_stencil_alpha = DepthStencilAlpha()
152 ctx.set_depth_stencil_alpha(depth_stencil_alpha)
155 rasterizer = Rasterizer()
156 rasterizer.front_winding = PIPE_WINDING_CW
157 rasterizer.cull_mode = PIPE_WINDING_NONE
158 rasterizer.bypass_vs_clip_and_viewport = 1
159 ctx.set_rasterizer(rasterizer)
163 sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
164 sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
165 sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
166 sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST
167 sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
168 sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
169 sampler.normalized_coords = 1
171 sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1
172 ctx.set_sampler(0, sampler)
175 texture = dev.texture_create(
181 last_level = last_level,
182 tex_usage = tex_usage,
185 expected_rgba = FloatArray(height*width*4)
190 ).sample_rgba(expected_rgba)
192 ctx.set_sampler_texture(0, texture)
195 cbuf_tex = dev.texture_create(
196 PIPE_FORMAT_A8R8G8B8_UNORM,
199 tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET,
202 cbuf = cbuf_tex.get_surface()
208 ctx.set_framebuffer(fb)
209 rgba = FloatArray(4);
214 ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
220 DCL IN[0], POSITION, CONSTANT
221 DCL IN[1], GENERIC, CONSTANT
222 DCL OUT[0], POSITION, CONSTANT
223 DCL OUT[1], GENERIC, CONSTANT
229 ctx.set_vertex_shader(vs)
233 PIPE_TEXTURE_1D: "1D",
234 PIPE_TEXTURE_2D: "2D",
235 PIPE_TEXTURE_3D: "3D",
236 PIPE_TEXTURE_CUBE: "CUBE",
240 DCL IN[0], GENERIC[0], LINEAR
241 DCL OUT[0], COLOR, CONSTANT
242 DCL SAMP[0], CONSTANT
243 0:TEX OUT[0], IN[0], SAMP[0], %s
247 ctx.set_fragment_shader(fs)
251 verts = FloatArray(nverts * nattrs * 4)
255 w, h = minify((width, height), level)
264 tex = tex_coords(texture, face, level, zslice)
266 for i in range(0, 4):
268 verts[j + 0] = pos[i][0] # x
269 verts[j + 1] = pos[i][1] # y
270 verts[j + 2] = 0.0 # z
271 verts[j + 3] = 1.0 # w
272 verts[j + 4] = tex[i][0] # s
273 verts[j + 5] = tex[i][1] # r
274 verts[j + 6] = tex[i][2] # q
277 ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN,
284 cbuf = cbuf_tex.get_surface()
286 self.assert_rgba(cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
301 PIPE_FORMAT_A8R8G8B8_UNORM,
302 PIPE_FORMAT_X8R8G8B8_UNORM,
303 #PIPE_FORMAT_A8R8G8B8_SRGB,
304 PIPE_FORMAT_R5G6B5_UNORM,
305 PIPE_FORMAT_A1R5G5B5_UNORM,
306 PIPE_FORMAT_A4R4G4B4_UNORM,
307 #PIPE_FORMAT_Z32_UNORM,
308 #PIPE_FORMAT_Z24S8_UNORM,
309 #PIPE_FORMAT_Z24X8_UNORM,
310 #PIPE_FORMAT_Z16_UNORM,
311 #PIPE_FORMAT_S8_UNORM,
312 PIPE_FORMAT_A8_UNORM,
313 PIPE_FORMAT_L8_UNORM,
315 PIPE_FORMAT_DXT1_RGB,
316 #PIPE_FORMAT_DXT1_RGBA,
317 #PIPE_FORMAT_DXT3_RGBA,
318 #PIPE_FORMAT_DXT5_RGBA,
321 sizes = [64, 32, 16, 8, 4, 2, 1]
322 #sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
335 for target in targets:
336 for format in formats:
338 if target == PIPE_TEXTURE_3D:
343 if target != PIPE_TEXTURE_CUBE and face:
346 for last_level in range(levels):
347 for level in range(0, last_level + 1):
349 while zslice < depth >> level:
357 last_level = last_level,
363 zslice = (zslice + 1)*2 - 1
367 if __name__ == '__main__':