1- from panda3d .core import Texture , PNMImage
1+ from panda3d .core import Texture , PNMImage , LColor
22from array import array
3+ import math
34
45
56def image_from_stored_pixel (component_type , format , data ):
@@ -15,6 +16,20 @@ def image_from_stored_pixel(component_type, format, data):
1516 return img
1617
1718
19+ def peek_tex_with_clear_color (component_type , format , clear_color ):
20+ """ Creates a 1-pixel texture with the given settings and clear color,
21+ then peeks the value at this pixel and returns it. """
22+
23+ tex = Texture ("" )
24+ tex .setup_1d_texture (1 , component_type , format )
25+ tex .set_clear_color (clear_color )
26+ tex .make_ram_image ()
27+
28+ col = LColor ()
29+ tex .peek ().fetch_pixel (col , 0 , 0 )
30+ return col
31+
32+
1833def test_texture_store_unsigned_byte ():
1934 data = array ('B' , (2 , 1 , 0 , 0xff ))
2035 img = image_from_stored_pixel (Texture .T_unsigned_byte , Texture .F_rgba , data )
@@ -88,3 +103,34 @@ def test_texture_store_srgb_alpha():
88103 assert img .maxval == 0xff
89104 col = img .get_xel_a (0 , 0 )
90105 assert col .almost_equal ((0.5 , 0.5 , 0.5 , 188 / 255.0 ), 1 / 255.0 )
106+
107+
108+ def test_texture_clear_unsigned_byte ():
109+ col = peek_tex_with_clear_color (Texture .T_float , Texture .F_rgba , (0 , 1 / 255.0 , 254 / 255.0 , 255.0 ))
110+ assert col == LColor (0 , 1 / 255.0 , 254 / 255.0 , 255.0 )
111+
112+
113+ def test_texture_clear_float ():
114+ col = peek_tex_with_clear_color (Texture .T_float , Texture .F_rgba , (0 , 0.25 , - 0.5 , 2 ))
115+ assert col == LColor (0 , 0.25 , - 0.5 , 2 )
116+
117+
118+ def test_texture_clear_half ():
119+ col = peek_tex_with_clear_color (Texture .T_half_float , Texture .F_rgba , (0 , 0.25 , - 0.5 , 2 ))
120+ assert col == LColor (0 , 0.25 , - 0.5 , 2 )
121+
122+ # Test edge cases
123+ inf = float ('inf' )
124+ nan = float ('nan' )
125+ col = peek_tex_with_clear_color (Texture .T_half_float , Texture .F_rgba , (65504 , 65536 , inf , nan ))
126+ assert col .x == 65504
127+ assert col .y == inf
128+ assert col .z == inf
129+ assert math .isnan (col .w )
130+
131+ # Negative edge case
132+ col = peek_tex_with_clear_color (Texture .T_half_float , Texture .F_rgba , (- 65504 , - 65536 , - inf , - nan ))
133+ assert col .x == - 65504
134+ assert col .y == - inf
135+ assert col .z == - inf
136+ assert math .isnan (col .w )
0 commit comments