test_textureattrib.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. from panda3d import core
  2. # Some dummy textures we can use for our texture attributes.
  3. stage1 = core.TextureStage("stage1")
  4. stage2 = core.TextureStage("stage2")
  5. stage3 = core.TextureStage("stage3")
  6. tex1 = core.Texture("tex1")
  7. tex2 = core.Texture("tex2")
  8. tex3 = core.Texture("tex3")
  9. def test_textureattrib_compose_add():
  10. # Tests a case in which a child node adds another texture.
  11. tattr1 = core.TextureAttrib.make()
  12. tattr1 = tattr1.add_on_stage(stage1, tex1)
  13. tattr2 = core.TextureAttrib.make()
  14. tattr2 = tattr2.add_on_stage(stage2, tex2)
  15. tattr3 = tattr1.compose(tattr2)
  16. assert tattr3.get_num_on_stages() == 2
  17. assert stage1 in tattr3.on_stages
  18. assert stage2 in tattr3.on_stages
  19. def test_textureattrib_compose_subtract():
  20. # Tests a case in which a child node disables a texture.
  21. tattr1 = core.TextureAttrib.make()
  22. tattr1 = tattr1.add_on_stage(stage1, tex1)
  23. tattr1 = tattr1.add_on_stage(stage2, tex2)
  24. tattr2 = core.TextureAttrib.make()
  25. tattr2 = tattr2.add_off_stage(stage3)
  26. tattr2 = tattr2.add_off_stage(stage2)
  27. tattr3 = tattr1.compose(tattr2)
  28. assert tattr3.get_num_on_stages() == 1
  29. assert stage1 in tattr3.on_stages
  30. assert stage2 not in tattr3.on_stages
  31. assert stage3 not in tattr3.on_stages
  32. def test_textureattrib_compose_both():
  33. # Tests a case in which a child node both enables and disables a texture.
  34. tattr1 = core.TextureAttrib.make()
  35. tattr1 = tattr1.add_on_stage(stage1, tex1)
  36. tattr1 = tattr1.add_on_stage(stage2, tex2)
  37. tattr2 = core.TextureAttrib.make()
  38. tattr2 = tattr2.add_on_stage(stage3, tex3)
  39. tattr2 = tattr2.add_on_stage(stage1, tex1)
  40. tattr2 = tattr2.add_off_stage(stage2)
  41. tattr3 = tattr1.compose(tattr2)
  42. assert tattr3.get_num_on_stages() == 2
  43. assert stage1 in tattr3.on_stages
  44. assert stage2 not in tattr3.on_stages
  45. assert stage3 in tattr3.on_stages
  46. def test_textureattrib_compose_alloff():
  47. # Tests a case in which a child node disables all textures.
  48. tattr1 = core.TextureAttrib.make()
  49. tattr1 = tattr1.add_on_stage(stage1, tex1)
  50. tattr1 = tattr1.add_on_stage(stage2, tex2)
  51. assert tattr1.get_num_on_stages() == 2
  52. tattr2 = core.TextureAttrib.make_all_off()
  53. assert tattr2.has_all_off()
  54. tattr3 = tattr1.compose(tattr2)
  55. assert tattr3.get_num_on_stages() == 0
  56. assert tattr3.get_num_off_stages() == 0
  57. assert tattr3.has_all_off()
  58. def test_textureattrib_compare():
  59. tattr1 = core.TextureAttrib.make()
  60. tattr2 = core.TextureAttrib.make()
  61. assert tattr1.compare_to(tattr2) == 0
  62. # All-off should not compare equal to empty
  63. tattr2 = core.TextureAttrib.make_all_off()
  64. assert tattr1.compare_to(tattr2) != 0
  65. assert tattr2.compare_to(tattr1) != 0
  66. assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2)
  67. # Empty stage is not the same as a single off stage
  68. tattr1 = core.TextureAttrib.make()
  69. tattr2 = core.TextureAttrib.make()
  70. tattr2 = tattr2.add_off_stage(stage1)
  71. assert tattr1.compare_to(tattr2) != 0
  72. assert tattr2.compare_to(tattr1) != 0
  73. assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2)
  74. # All-off stage is not the same as a single off stage
  75. tattr1 = core.TextureAttrib.make_all_off()
  76. tattr2 = core.TextureAttrib.make()
  77. tattr2 = tattr2.add_off_stage(stage1)
  78. assert tattr1.compare_to(tattr2) != 0
  79. assert tattr2.compare_to(tattr1) != 0
  80. assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2)
  81. # Different off stages are non-equal
  82. tattr1 = core.TextureAttrib.make_all_off()
  83. tattr1 = tattr2.add_off_stage(stage1)
  84. tattr2 = core.TextureAttrib.make()
  85. tattr2 = tattr2.add_off_stage(stage2)
  86. assert tattr1.compare_to(tattr2) != 0
  87. assert tattr2.compare_to(tattr1) != 0
  88. assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2)
  89. # If both have a different texture, but same stage, they are not equal
  90. tattr1 = core.TextureAttrib.make()
  91. tattr1 = tattr1.add_on_stage(stage1, tex1)
  92. tattr2 = core.TextureAttrib.make()
  93. tattr2 = tattr2.add_on_stage(stage1, tex2)
  94. assert tattr1.compare_to(tattr2) != 0
  95. assert tattr2.compare_to(tattr1) != 0
  96. assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2)
  97. # If both have the same texture, but different stage, they are not equal
  98. tattr1 = core.TextureAttrib.make()
  99. tattr1 = tattr1.add_on_stage(stage1, tex1)
  100. tattr2 = core.TextureAttrib.make()
  101. tattr2 = tattr2.add_on_stage(stage2, tex2)
  102. assert tattr1.compare_to(tattr2) != 0
  103. assert tattr2.compare_to(tattr1) != 0
  104. assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2)
  105. # If both have the same texture and stage, they are equal
  106. tattr1 = core.TextureAttrib.make()
  107. tattr1 = tattr1.add_on_stage(stage1, tex1)
  108. tattr2 = core.TextureAttrib.make()
  109. tattr2 = tattr2.add_on_stage(stage1, tex1)
  110. assert tattr1.compare_to(tattr2) == 0
  111. assert tattr2.compare_to(tattr1) == 0
  112. # Adding an extra texture makes it unequal
  113. tattr2 = tattr2.add_on_stage(stage2, tex2)
  114. assert tattr1.compare_to(tattr2) != 0
  115. assert tattr2.compare_to(tattr1) != 0
  116. assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2)
  117. # Different textures altogether is of course unequal
  118. tattr1 = core.TextureAttrib.make()
  119. tattr1 = tattr1.add_on_stage(stage2, tex2)
  120. tattr2 = core.TextureAttrib.make()
  121. tattr2 = tattr2.add_on_stage(stage1, tex1)
  122. assert tattr1.compare_to(tattr2) != 0
  123. assert tattr2.compare_to(tattr1) != 0
  124. assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2)