@@ -119,7 +119,8 @@ suite('p5.RendererGL', function() {
119
119
120
120
// It should be red
121
121
assert . deepEqual ( myp5 . get ( 5 , 5 ) , [ 255 , 0 , 0 , 255 ] ) ;
122
- } )
122
+ } ) ;
123
+
123
124
test ( 'textures remain bound after each draw call' , function ( ) {
124
125
myp5 . createCanvas ( 20 , 10 , myp5 . WEBGL ) ;
125
126
myp5 . background ( 255 ) ;
@@ -132,7 +133,7 @@ suite('p5.RendererGL', function() {
132
133
inputs.color = texture(myTex, inputs.texCoord);
133
134
return inputs;
134
135
}`
135
- } )
136
+ } ) ;
136
137
137
138
// Make a red texture
138
139
const tex = myp5 . createFramebuffer ( ) ;
@@ -154,7 +155,33 @@ suite('p5.RendererGL', function() {
154
155
// Both rectangles should be red
155
156
assert . deepEqual ( myp5 . get ( 5 , 5 ) , [ 255 , 0 , 0 , 255 ] ) ;
156
157
assert . deepEqual ( myp5 . get ( 15 , 5 ) , [ 255 , 0 , 0 , 255 ] ) ;
157
- } )
158
+ } ) ;
159
+
160
+ test ( 'texture() does not remain bound' , function ( ) {
161
+ myp5 . createCanvas ( 20 , 10 , myp5 . WEBGL ) ;
162
+ myp5 . background ( 255 ) ;
163
+
164
+ const myShader = myp5 . baseMaterialShader ( ) . modify ( { } ) ;
165
+
166
+ // Make a red texture
167
+ const tex = myp5 . createFramebuffer ( ) ;
168
+ tex . draw ( ( ) => myp5 . background ( 'red' ) ) ;
169
+
170
+ myp5 . shader ( myShader ) ;
171
+ const uSampler = myShader . samplers . find ( ( s ) => s . name === 'uSampler' ) ;
172
+
173
+ myp5 . push ( ) ;
174
+ myp5 . texture ( tex ) ;
175
+ myp5 . circle ( 0 , 0 , 20 ) ;
176
+ expect ( uSampler . texture . isFramebufferTexture ) . toBeTruthy ( ) ;
177
+ myp5 . pop ( ) ;
178
+
179
+ myp5 . push ( ) ;
180
+ // Texture should be unbound now
181
+ myp5 . circle ( 0 , 0 , 20 ) ;
182
+ expect ( uSampler . texture . isFramebufferTexture ) . toBeFalsy ( ) ;
183
+ myp5 . pop ( ) ;
184
+ } ) ;
158
185
} ) ;
159
186
160
187
suite ( 'default stroke shader' , function ( ) {
@@ -2711,48 +2738,48 @@ suite('p5.RendererGL', function() {
2711
2738
myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
2712
2739
const gl = myp5 . _renderer . GL ;
2713
2740
const isEnabled = gl . isEnabled ( gl . STENCIL_TEST ) ;
2714
-
2741
+
2715
2742
assert . equal ( isEnabled , false ) ;
2716
2743
assert . equal ( myp5 . _renderer . _userEnabledStencil , false ) ;
2717
2744
}
2718
2745
) ;
2719
-
2746
+
2720
2747
test ( 'Tracks when user manually enables stencil test' ,
2721
2748
function ( ) {
2722
2749
myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
2723
2750
const gl = myp5 . _renderer . GL ;
2724
-
2751
+
2725
2752
gl . enable ( gl . STENCIL_TEST ) ;
2726
2753
assert . equal ( myp5 . _renderer . _userEnabledStencil , true ) ;
2727
2754
assert . equal ( gl . isEnabled ( gl . STENCIL_TEST ) , true ) ;
2728
2755
}
2729
2756
) ;
2730
-
2757
+
2731
2758
test ( 'Tracks when user manually disables stencil test' ,
2732
2759
function ( ) {
2733
2760
myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
2734
2761
const gl = myp5 . _renderer . GL ;
2735
2762
2736
2763
gl . enable ( gl . STENCIL_TEST ) ;
2737
2764
gl . disable ( gl . STENCIL_TEST ) ;
2738
-
2765
+
2739
2766
assert . equal ( myp5 . _renderer . _userEnabledStencil , false ) ;
2740
2767
assert . equal ( gl . isEnabled ( gl . STENCIL_TEST ) , false ) ;
2741
2768
}
2742
2769
) ;
2743
-
2770
+
2744
2771
test ( 'Maintains stencil test state across draw cycles when user enabled' ,
2745
2772
function ( ) {
2746
2773
let drawCalled = false ;
2747
2774
2748
2775
myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
2749
2776
const originalDraw = myp5 . draw ;
2750
-
2777
+
2751
2778
myp5 . draw = function ( ) {
2752
2779
drawCalled = true ;
2753
2780
if ( originalDraw ) originalDraw . call ( myp5 ) ;
2754
2781
} ;
2755
-
2782
+
2756
2783
const gl = myp5 . _renderer . GL ;
2757
2784
gl . enable ( gl . STENCIL_TEST ) ;
2758
2785
assert . equal ( gl . isEnabled ( gl . STENCIL_TEST ) , true )
@@ -2764,7 +2791,7 @@ suite('p5.RendererGL', function() {
2764
2791
myp5 . draw = originalDraw ;
2765
2792
}
2766
2793
) ;
2767
-
2794
+
2768
2795
test ( 'Internal clip operations preserve user stencil test setting' ,
2769
2796
function ( ) {
2770
2797
myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
@@ -2783,7 +2810,7 @@ suite('p5.RendererGL', function() {
2783
2810
assert . equal ( gl . isEnabled ( gl . STENCIL_TEST ) , true ) ;
2784
2811
}
2785
2812
) ;
2786
-
2813
+
2787
2814
test ( 'Internal clip operations do not enable stencil test for future draw cycles' ,
2788
2815
function ( ) {
2789
2816
myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
0 commit comments