test_fbprops.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from panda3d.core import FrameBufferProperties
  2. def test_fbprops_copy_ctor():
  3. default = FrameBufferProperties.get_default()
  4. fbprops = FrameBufferProperties(default)
  5. assert fbprops == default
  6. def test_fbquality_depth():
  7. # We check common framebuffer depth configurations to make sure they
  8. # are rated predictably with respect to each other when requesting 1 bit.
  9. # In particular, we make sure that we don't get a 16-bit depth buffer if
  10. # the driver only gives extra depth in combination with a stencil buffer.
  11. req = FrameBufferProperties()
  12. req.depth_bits = 1
  13. #NB. we need to set rgb_color=True when testing the quality of framebuffer
  14. # properties, lest it return a quality of 0.
  15. fb_d16s8 = FrameBufferProperties()
  16. fb_d16s8.rgb_color = True
  17. fb_d16s8.depth_bits = 16
  18. fb_d16s8.stencil_bits = 8
  19. fb_d24s8 = FrameBufferProperties()
  20. fb_d24s8.rgb_color = True
  21. fb_d24s8.depth_bits = 24
  22. fb_d24s8.stencil_bits = 8
  23. fb_d32 = FrameBufferProperties()
  24. fb_d32.rgb_color = True
  25. fb_d32.depth_bits = 32
  26. fb_d32s8 = FrameBufferProperties()
  27. fb_d32s8.rgb_color = True
  28. fb_d32s8.depth_bits = 32
  29. fb_d32s8.stencil_bits = 8
  30. # 16-bit depth is terrible for most applications and should not be chosen.
  31. assert fb_d16s8.get_quality(req) < fb_d24s8.get_quality(req)
  32. assert fb_d16s8.get_quality(req) < fb_d32.get_quality(req)
  33. assert fb_d16s8.get_quality(req) < fb_d32s8.get_quality(req)
  34. # Getting extra depth should be better than getting an unwanted bitplane.
  35. assert fb_d32.get_quality(req) > fb_d16s8.get_quality(req)
  36. assert fb_d32.get_quality(req) > fb_d24s8.get_quality(req)
  37. # If we're getting stencil anyway, we'll prefer to maximize our depth.
  38. assert fb_d32s8.get_quality(req) > fb_d24s8.get_quality(req)
  39. # However, unnecessary stencil bits are still a waste.
  40. assert fb_d32s8.get_quality(req) < fb_d32.get_quality(req)
  41. def test_fbquality_rgba64():
  42. # Make sure that we don't get a 64-bit configuration if we request
  43. # an unspecific number of color bits. See:
  44. # https://www.panda3d.org/forums/viewtopic.php?t=20192
  45. # This issue occurs if we are requesting 1 bit, not if we are requesting
  46. # a specific amount. There are several ways to do that, so we want to
  47. # assert that none of them will yield a 64-bit color buffer.
  48. req_color0 = FrameBufferProperties()
  49. req_color0.color_bits = 0
  50. req_color1 = FrameBufferProperties()
  51. req_color1.color_bits = 1
  52. req_color0_alpha0 = FrameBufferProperties()
  53. req_color0_alpha0.color_bits = 0
  54. req_color0_alpha0.alpha_bits = 0
  55. req_color1_alpha1 = FrameBufferProperties()
  56. req_color1_alpha1.color_bits = 1
  57. req_color1_alpha1.alpha_bits = 1
  58. req_rgb0 = FrameBufferProperties()
  59. req_rgb0.set_rgba_bits(0, 0, 0, 0)
  60. req_rgb1 = FrameBufferProperties()
  61. req_rgb1.set_rgba_bits(1, 1, 1, 0)
  62. req_rgb0_alpha0 = FrameBufferProperties()
  63. req_rgb0_alpha0.set_rgba_bits(0, 0, 0, 0)
  64. req_rgb1_alpha1 = FrameBufferProperties()
  65. req_rgb1_alpha1.set_rgba_bits(1, 1, 1, 1)
  66. fb_rgba8 = FrameBufferProperties()
  67. fb_rgba8.rgb_color = True
  68. fb_rgba8.set_rgba_bits(8, 8, 8, 8)
  69. fb_rgba16 = FrameBufferProperties()
  70. fb_rgba16.rgb_color = True
  71. fb_rgba16.set_rgba_bits(16, 16, 16, 16)
  72. assert fb_rgba8.get_quality(req_color0) > fb_rgba16.get_quality(req_color0)
  73. assert fb_rgba8.get_quality(req_color1) > fb_rgba16.get_quality(req_color1)
  74. assert fb_rgba8.get_quality(req_color0_alpha0) > fb_rgba16.get_quality(req_color0_alpha0)
  75. assert fb_rgba8.get_quality(req_color1_alpha1) > fb_rgba16.get_quality(req_color1_alpha1)
  76. assert fb_rgba8.get_quality(req_rgb0) > fb_rgba16.get_quality(req_rgb0)
  77. assert fb_rgba8.get_quality(req_rgb1) > fb_rgba16.get_quality(req_rgb1)
  78. assert fb_rgba8.get_quality(req_rgb0_alpha0) > fb_rgba16.get_quality(req_rgb0_alpha0)
  79. assert fb_rgba8.get_quality(req_rgb1_alpha1) > fb_rgba16.get_quality(req_rgb1_alpha1)