@@ -208,6 +208,50 @@ it('WebGLStateTracker#intercept gl calls', async () => {
208208 void 0 ;
209209} ) ;
210210
211+ it ( 'WebGLStateTracker#tracks buffer bindings by target' , async ( ) => {
212+ const device = await devicePromise ;
213+ const { gl} = device ;
214+ const state = WebGLStateTracker . get ( gl ) ;
215+
216+ resetGLParameters ( gl ) ;
217+
218+ const bindingParameters = [
219+ [ gl . ARRAY_BUFFER , gl . ARRAY_BUFFER_BINDING ] ,
220+ [ gl . COPY_READ_BUFFER , gl . COPY_READ_BUFFER_BINDING ] ,
221+ [ gl . COPY_WRITE_BUFFER , gl . COPY_WRITE_BUFFER_BINDING ] ,
222+ [ gl . PIXEL_PACK_BUFFER , gl . PIXEL_PACK_BUFFER_BINDING ] ,
223+ [ gl . PIXEL_UNPACK_BUFFER , gl . PIXEL_UNPACK_BUFFER_BINDING ]
224+ ] ;
225+ const buffers = bindingParameters . map ( ( ) => gl . createBuffer ( ) ) ;
226+
227+ device . pushState ( ) ;
228+ for ( const [ index , [ target , bindingParameter ] ] of bindingParameters . entries ( ) ) {
229+ gl . bindBuffer ( target , buffers [ index ] ) ;
230+ expect ( state . cache [ bindingParameter ] , `binding of target ${ target } is tracked` ) . toBe (
231+ buffers [ index ]
232+ ) ;
233+ }
234+ for ( const [ index , [ , bindingParameter ] ] of bindingParameters . entries ( ) ) {
235+ expect ( gl . getParameter ( bindingParameter ) , `binding ${ bindingParameter } is current` ) . toBe (
236+ buffers [ index ]
237+ ) ;
238+ }
239+
240+ const uniformBuffer = gl . createBuffer ( ) ;
241+ gl . bindBuffer ( gl . UNIFORM_BUFFER , uniformBuffer ) ;
242+ expect ( state . cache [ gl . UNIFORM_BUFFER_BINDING ] , 'uniform buffer binding is not tracked' ) . toBe (
243+ undefined
244+ ) ;
245+ gl . bindBuffer ( gl . UNIFORM_BUFFER , null ) ;
246+ device . popState ( ) ;
247+
248+ for ( const [ , bindingParameter ] of bindingParameters ) {
249+ expect ( gl . getParameter ( bindingParameter ) , `binding ${ bindingParameter } is restored` ) . toBe ( null ) ;
250+ }
251+
252+ for ( const buffer of [ ...buffers , uniformBuffer ] ) gl . deleteBuffer ( buffer ) ;
253+ } ) ;
254+
211255it ( 'WebGLStateTracker#not cached parameters' , async ( ) => {
212256 const device = await devicePromise ;
213257 const { gl} = device ;
0 commit comments