1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
|
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Nicolas P. Rougier. All rights reserved.
# Distributed under the terms of the new BSD License.
# -----------------------------------------------------------------------------
import unittest
import numpy as np
from vispy.gloo import Texture1D, Texture2D, Texture3D, TextureAtlas
from vispy.testing import requires_pyopengl, run_tests_if_main, assert_raises
# here we test some things that will be true of all Texture types:
Texture = Texture2D
# ----------------------------------------------------------------- Texture ---
class TextureTest(unittest.TestCase):
# No data, no dtype : forbidden
# ---------------------------------
def test_init_none(self):
self.assertRaises(ValueError, Texture)
# Data only
# ---------------------------------
def test_init_data(self):
data = np.zeros((10, 10, 3), dtype=np.uint8)
T = Texture(data=data, interpolation='linear', wrapping='repeat')
assert T._shape == (10, 10, 3)
assert T._interpolation == ('linear', 'linear')
assert T._wrapping == ('repeat', 'repeat')
# Setting data and shape
# ---------------------------------
def test_init_dtype_shape(self):
T = Texture((10, 10))
assert T._shape == (10, 10, 1)
self.assertRaises(ValueError, Texture, shape=(10, 10),
data=np.zeros((10, 10), np.float32))
# Set data with store
# ---------------------------------
def test_setitem_all(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture(data=data)
T[...] = np.ones((10, 10, 1))
glir_cmd = T._glir.clear()[-1]
assert glir_cmd[0] == 'DATA'
assert np.allclose(glir_cmd[3], np.ones((10, 10, 1)))
# Set data without store
# ---------------------------------
def test_setitem_all_no_store(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture(data=data)
T[...] = np.ones((10, 10), np.uint8)
assert np.allclose(data, np.zeros((10, 10)))
# Set a single data
# ---------------------------------
def test_setitem_single(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture(data=data)
T[0, 0, 0] = 1
glir_cmd = T._glir.clear()[-1]
assert glir_cmd[0] == 'DATA'
assert np.allclose(glir_cmd[3], np.array([1]))
# We apparently support this
T[8:3, 3] = 1
# Set some data
# ---------------------------------
def test_setitem_partial(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture(data=data)
T[5:, 5:] = 1
glir_cmd = T._glir.clear()[-1]
assert glir_cmd[0] == 'DATA'
assert np.allclose(glir_cmd[3], np.ones((5, 5)))
# Set non contiguous data
# ---------------------------------
def test_setitem_wrong(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture(data=data)
# with self.assertRaises(ValueError):
# T[::2, ::2] = 1
s = slice(None, None, 2)
self.assertRaises(IndexError, T.__setitem__, (s, s), 1)
self.assertRaises(IndexError, T.__setitem__, (-100, 3), 1)
self.assertRaises(TypeError, T.__setitem__, ('foo', 'bar'), 1)
# Set properties
def test_set_texture_properties(self):
T = Texture((10, 10))
# Interpolation
T.interpolation = 'nearest'
assert T.interpolation == 'nearest'
T.interpolation = 'linear'
assert T.interpolation == 'linear'
T.interpolation = ['linear'] * 2
assert T.interpolation == 'linear'
T.interpolation = ['linear', 'nearest']
assert T.interpolation == ('linear', 'nearest')
# Wrong interpolation
iset = Texture.interpolation.fset
self.assertRaises(ValueError, iset, T, ['linear'] * 3)
self.assertRaises(ValueError, iset, T, True)
self.assertRaises(ValueError, iset, T, [])
self.assertRaises(ValueError, iset, T, 'linearios')
# Wrapping
T.wrapping = 'clamp_to_edge'
assert T.wrapping == 'clamp_to_edge'
T.wrapping = 'repeat'
assert T.wrapping == 'repeat'
T.wrapping = 'mirrored_repeat'
assert T.wrapping == 'mirrored_repeat'
T.wrapping = 'repeat', 'repeat'
assert T.wrapping == 'repeat'
T.wrapping = 'repeat', 'clamp_to_edge'
assert T.wrapping == ('repeat', 'clamp_to_edge')
# Wrong wrapping
wset = Texture.wrapping.fset
self.assertRaises(ValueError, wset, T, ['repeat'] * 3)
self.assertRaises(ValueError, wset, T, True)
self.assertRaises(ValueError, wset, T, [])
self.assertRaises(ValueError, wset, T, 'repeatos')
# --------------------------------------------------------------- Texture2D ---
class Texture2DTest(unittest.TestCase):
# Note: put many tests related to (re)sizing here, because Texture
# is not really aware of shape.
# Shape extension
# ---------------------------------
def test_init(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
assert 'Texture2D' in repr(T)
assert T._shape == (10, 10, 1)
assert T.glsl_type == ('uniform', 'sampler2D')
# Width & height
# ---------------------------------
def test_width_height(self):
data = np.zeros((10, 20), dtype=np.uint8)
T = Texture2D(data=data)
assert T.width == 20
assert T.height == 10
# Resize
# ---------------------------------
def test_resize(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
T.resize((5, 5))
assert T.shape == (5, 5, 1)
glir_cmd = T._glir.clear()[-1]
assert glir_cmd[0] == 'SIZE'
# Wong arg
self.assertRaises(ValueError, T.resize, (5, 5), 4)
# Resize with bad shape
# ---------------------------------
def test_resize_bad_shape(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
# with self.assertRaises(ValueError):
# T.resize((5, 5, 5))
self.assertRaises(ValueError, T.resize, (5,))
self.assertRaises(ValueError, T.resize, (5, 5, 5))
self.assertRaises(ValueError, T.resize, (5, 5, 5, 1))
# Resize not resizable
# ---------------------------------
def test_resize_unresizable(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data, resizable=False)
# with self.assertRaises(RuntimeError):
# T.resize((5, 5))
self.assertRaises(RuntimeError, T.resize, (5, 5))
# Set oversized data (-> resize)
# ---------------------------------
def test_set_oversized_data(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
T.set_data(np.ones((20, 20), np.uint8))
assert T.shape == (20, 20, 1)
glir_cmds = T._glir.clear()
assert glir_cmds[-2][0] == 'SIZE'
assert glir_cmds[-1][0] == 'DATA'
# Set undersized data
# ---------------------------------
def test_set_undersized_data(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
T.set_data(np.ones((5, 5), np.uint8))
assert T.shape == (5, 5, 1)
glir_cmds = T._glir.clear()
assert glir_cmds[-2][0] == 'SIZE'
assert glir_cmds[-1][0] == 'DATA'
# Set misplaced data
# ---------------------------------
def test_set_misplaced_data(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
# with self.assertRaises(ValueError):
# T.set_data(np.ones((5, 5)), offset=(8, 8))
self.assertRaises(ValueError, T.set_data,
np.ones((5, 5)), offset=(8, 8))
# Set misshaped data
# ---------------------------------
def test_set_misshaped_data_2D(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
# with self.assertRaises(ValueError):
# T.set_data(np.ones((10, 10)))
self.assertRaises(ValueError, T.set_data, np.ones((10,)))
self.assertRaises(ValueError, T.set_data, np.ones((5, 5, 5, 1)),)
# Set whole data (clear pending data)
# ---------------------------------
def test_set_whole_data(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
T.set_data(np.ones((10, 10), np.uint8))
assert T.shape == (10, 10, 1)
# Test set data with different shape
# ---------------------------------
def test_reset_data_shape(self):
shape1 = 10, 10
shape3 = 10, 10, 3
# Init data (explicit shape)
data = np.zeros((10, 10, 1), dtype=np.uint8)
T = Texture2D(data=data)
assert T.shape == (10, 10, 1)
assert T.format == 'luminance'
# Set data to rgb
T.set_data(np.zeros(shape3, np.uint8))
assert T.shape == (10, 10, 3)
assert T.format == 'rgb'
# Set data to grayscale
T.set_data(np.zeros(shape1, np.uint8))
assert T.shape == (10, 10, 1)
assert T.format == 'luminance'
# Set size to rgb
T.resize(shape3)
assert T.shape == (10, 10, 3)
assert T._format == 'rgb'
# Set size to grayscale
T.resize(shape1)
assert T.shape == (10, 10, 1)
assert T._format == 'luminance'
# Keep using old format
T.resize(shape1, 'alpha')
T.resize(shape1)
assert T._format == 'alpha'
# Use luminance as default
T.resize(shape3)
T.resize(shape1)
assert T._format == 'luminance'
# Too large
self.assertRaises(ValueError, T.resize, (5, 5, 5, 1))
# Cannot determine format
self.assertRaises(ValueError, T.resize, (5, 5, 5))
# Invalid format
self.assertRaises(ValueError, T.resize, shape3, 'foo')
self.assertRaises(ValueError, T.resize, shape3, 'alpha')
#self.assertRaises(ValueError, T.resize, shape3, 4)
# Test set data with different shape and type
# -------------------------------------------
def test_reset_data_type(self):
data = np.zeros((10, 10), dtype=np.uint8)
T = Texture2D(data=data)
data = np.zeros((10, 11), dtype=np.float32)
T.set_data(data)
data = np.zeros((12, 10), dtype=np.int32)
T.set_data(data)
self.assertRaises(ValueError, T.set_data, np.zeros([10, 10, 10, 1]))
# --------------------------------------------------------------- Texture1D ---
@requires_pyopengl()
def test_texture_1D():
# Note: put many tests related to (re)sizing here, because Texture
# is not really aware of shape.
# Shape extension
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
assert T._shape == (10, 1)
assert 'Texture1D' in repr(T)
assert T.glsl_type == ('uniform', 'sampler1D')
# Width
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
assert T.width == 10
# Resize
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
T.resize((5, ))
assert T.shape == (5, 1)
glir_cmd = T._glir.clear()[-1]
assert glir_cmd[0] == 'SIZE'
assert glir_cmd[2] == (5, 1)
# Resize with bad shape
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
# with self.assertRaises(ValueError):
# T.resize((5, 5, 5, 5))
assert_raises(ValueError, T.resize, (5, 5, 5, 5))
# Resize not resizable
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data, resizable=False)
# with self.assertRaises(RuntimeError):
# T.resize((5, 5, 5))
assert_raises(RuntimeError, T.resize, (5, ))
# Set oversized data (-> resize)
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
T.set_data(np.ones((20, ), np.uint8))
assert T.shape == (20, 1)
# Set undersized data
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
T.set_data(np.ones((5, ), np.uint8))
assert T.shape == (5, 1)
# Set misplaced data
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
# with self.assertRaises(ValueError):
# T.set_data(np.ones((5, 5, 5)), offset=(8, 8, 8))
assert_raises(ValueError, T.set_data,
np.ones((5, )), offset=(8, ))
# Set misshaped data
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
# with self.assertRaises(ValueError):
# T.set_data(np.ones((10, 10, 10)))
assert_raises(ValueError, T.set_data, np.ones((10, 10)))
# Set whole data (clear pending data)
# ---------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
T.set_data(np.ones((10, ), np.uint8))
assert T.shape == (10, 1)
glir_cmd = T._glir.clear()[-1]
assert glir_cmd[0] == 'DATA'
# Test set data with different shape
# ---------------------------------
shape1 = (10, )
shape3 = (10, 3)
# Init data (explicit shape)
data = np.zeros((10, 1), dtype=np.uint8)
T = Texture1D(data=data)
assert T.shape == (10, 1)
assert T._format == 'luminance'
# Set data to rgb
T.set_data(np.zeros(shape3, np.uint8))
assert T.shape == (10, 3)
assert T._format == 'rgb'
# Set data to grayscale
T.set_data(np.zeros(shape1, np.uint8))
assert T.shape == (10, 1)
assert T._format == 'luminance'
# Set size to rgb
T.resize(shape3)
assert T.shape == (10, 3)
assert T._format == 'rgb'
# Set size to grayscale
T.resize(shape1)
assert T.shape == (10, 1)
assert T._format == 'luminance'
# Test set data with different shape and type
# -------------------------------------------
data = np.zeros((10, ), dtype=np.uint8)
T = Texture1D(data=data)
data = np.zeros((10, ), dtype=np.float32)
T.set_data(data)
data = np.zeros((12, ), dtype=np.int32)
T.set_data(data)
# --------------------------------------------------------------- Texture3D ---
@requires_pyopengl()
def test_texture_3D():
# Note: put many tests related to (re)sizing here, because Texture
# is not really aware of shape.
# Shape extension
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
assert T._shape == (10, 10, 10, 1)
assert 'Texture3D' in repr(T)
assert T.glsl_type == ('uniform', 'sampler3D')
# Width & height
# ---------------------------------
data = np.zeros((10, 20, 30), dtype=np.uint8)
T = Texture3D(data=data)
assert T.width == 30
assert T.height == 20
assert T.depth == 10
# Resize
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
T.resize((5, 5, 5))
assert T.shape == (5, 5, 5, 1)
glir_cmd = T._glir.clear()[-1]
assert glir_cmd[0] == 'SIZE'
assert glir_cmd[2] == (5, 5, 5, 1)
# Resize with bad shape
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
# with self.assertRaises(ValueError):
# T.resize((5, 5, 5, 5))
assert_raises(ValueError, T.resize, (5, 5, 5, 5))
# Resize not resizable
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data, resizable=False)
# with self.assertRaises(RuntimeError):
# T.resize((5, 5, 5))
assert_raises(RuntimeError, T.resize, (5, 5, 5))
# Set oversized data (-> resize)
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
T.set_data(np.ones((20, 20, 20), np.uint8))
assert T.shape == (20, 20, 20, 1)
# Set undersized data
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
T.set_data(np.ones((5, 5, 5), np.uint8))
assert T.shape == (5, 5, 5, 1)
# Set misplaced data
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
# with self.assertRaises(ValueError):
# T.set_data(np.ones((5, 5, 5)), offset=(8, 8, 8))
assert_raises(ValueError, T.set_data,
np.ones((5, 5, 5)), offset=(8, 8, 8))
# Set misshaped data
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
# with self.assertRaises(ValueError):
# T.set_data(np.ones((10, 10, 10)))
assert_raises(ValueError, T.set_data, np.ones((10,)))
# Set whole data (clear pending data)
# ---------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
T.set_data(np.ones((10, 10, 10), np.uint8))
assert T.shape == (10, 10, 10, 1)
glir_cmd = T._glir.clear()[-1]
assert glir_cmd[0] == 'DATA'
# Test set data with different shape
# ---------------------------------
shape1 = 10, 10, 10
shape3 = 10, 10, 10, 3
# Init data (explicit shape)
data = np.zeros((10, 10, 10, 1), dtype=np.uint8)
T = Texture3D(data=data)
assert T.shape == (10, 10, 10, 1)
assert T._format == 'luminance'
# Set data to rgb
T.set_data(np.zeros(shape3, np.uint8))
assert T.shape == (10, 10, 10, 3)
assert T._format == 'rgb'
# Set data to grayscale
T.set_data(np.zeros(shape1, np.uint8))
assert T.shape == (10, 10, 10, 1)
assert T._format == 'luminance'
# Set size to rgb
T.resize(shape3)
assert T.shape == (10, 10, 10, 3)
assert T._format == 'rgb'
# Set size to grayscale
T.resize(shape1)
assert T.shape == (10, 10, 10, 1)
assert T._format == 'luminance'
# Test set data with different shape and type
# -------------------------------------------
data = np.zeros((10, 10, 10), dtype=np.uint8)
T = Texture3D(data=data)
data = np.zeros((10, 11, 11), dtype=np.float32)
T.set_data(data)
data = np.zeros((12, 12, 10), dtype=np.int32)
T.set_data(data)
class TextureAtlasTest(unittest.TestCase):
def test_init_atas(self):
T = TextureAtlas((100, 100))
assert T.shape == (128, 128, 3) # rounds to powers of 2
for i in [10, 20, 30, 40, 50, 60]:
reg = T.get_free_region(10, 10)
assert len(reg) == 4
reg = T.get_free_region(129, 129)
assert reg is None
# --------------------------------------------------------- Texture formats ---
def _test_texture_formats(Texture, baseshape, formats):
# valid channel count and format combinations
for channels in range(1, 5):
for format in [f for n, f in formats if n == channels]:
shape = baseshape + (channels,)
T = Texture(shape=shape, format=format)
assert 'Texture' in repr(T)
assert T._shape == shape
data = np.zeros(shape, dtype=np.uint8)
T = Texture(data=data, format=format)
assert 'Texture' in repr(T)
assert T._shape == shape
# invalid channel count and format combinations
for channels in range(1, 5):
for format in [f for n, f in formats + [(5, 'junk')] if n != channels]:
shape = baseshape + (channels,)
assert_raises(ValueError, Texture, shape=shape, format=format)
data = np.zeros(shape, dtype=np.uint8)
assert_raises(ValueError, Texture, data=data, format=format)
# --------------------------------------------------------- Texture formats ---
def _test_texture_basic_formats(Texture, baseshape):
_test_texture_formats(
Texture,
baseshape,
[
(1, 'alpha'),
(1, 'luminance'),
(2, 'luminance_alpha'),
(3, 'rgb'),
(4, 'rgba')
]
)
# ------------------------------------------------------- Texture1D formats ---
def test_texture_1D_formats():
_test_texture_basic_formats(Texture1D, (10, ))
# ------------------------------------------------------- Texture2D formats ---
def test_texture_2D_formats():
_test_texture_basic_formats(Texture2D, (10, 10))
# ------------------------------------------------------- Texture3D formats ---
def test_texture_3D_formats():
_test_texture_basic_formats(Texture3D, (10, 10, 10))
# -------------------------------------------------- Texture OpenGL formats ---
def _test_texture_opengl_formats(Texture, baseshape):
_test_texture_formats(
Texture,
baseshape,
[
(1, 'red'),
(2, 'rg'),
(3, 'rgb'),
(4, 'rgba')
]
)
# ------------------------------------------------ Texture1D OpenGL formats ---
@requires_pyopengl()
def test_texture_1D_opengl_formats():
_test_texture_opengl_formats(Texture1D, (10, ))
# ------------------------------------------------ Texture2D OpenGL formats ---
@requires_pyopengl()
def test_texture_2D_opengl_formats():
_test_texture_opengl_formats(Texture2D, (10, 10))
# ------------------------------------------------ Texture3D OpenGL formats ---
@requires_pyopengl()
def test_texture_3D_opengl_formats():
_test_texture_opengl_formats(Texture3D, (10, 10, 10))
# ------------------------------------------ Texture OpenGL internalformats ---
def _test_texture_internalformats(Texture, baseshape):
# Test format for concrete Texture class and baseshape + (numchannels,)
# Test internalformats valid with desktop OpenGL
formats = [
(1, 'red', ['red', 'r8', 'r16', 'r16f', 'r32f']),
(2, 'rg', ['rg', 'rg8', 'rg16', 'rg16f', 'rg32f']),
(3, 'rgb', ['rgb', 'rgb8', 'rgb16', 'rgb16f', 'rgb32f']),
(4, 'rgba', ['rgba', 'rgba8', 'rgba16', 'rgba16f', 'rgba32f'])
]
for channels in range(1, 5):
for fmt, ifmts in [(f, iL) for n, f, iL in formats if n == channels]:
shape = baseshape + (channels,)
data = np.zeros(shape, dtype=np.uint8)
for ifmt in ifmts:
T = Texture(shape=shape, format=fmt, internalformat=ifmt)
assert 'Texture' in repr(T)
assert T._shape == shape
T = Texture(data=data, format=fmt, internalformat=ifmt)
assert 'Texture' in repr(T)
assert T._shape == shape
for channels in range(1, 5):
for fmt, ifmts in [(f, iL) for n, f, iL in formats if n != channels]:
shape = baseshape + (channels,)
data = np.zeros(shape, dtype=np.uint8)
for ifmt in ifmts:
assert_raises(ValueError, Texture, shape=shape, format=fmt,
internalformat=ifmt)
assert_raises(ValueError, Texture, data=data, format=fmt,
internalformat=ifmt)
# ---------------------------------------- Texture2D OpenGL internalformats ---
@requires_pyopengl()
def test_texture_2D_internalformats():
_test_texture_internalformats(Texture2D, (10, 10))
# ---------------------------------------- Texture3D OpenGL internalformats ---
@requires_pyopengl()
def test_texture_3D_internalformats():
_test_texture_internalformats(Texture3D, (10, 10, 10))
run_tests_if_main()
|