@@ -716,6 +716,42 @@ visualSuite("WebGPU", function () {
716716 } ) ;
717717 } ) ;
718718
719+ visualSuite ( "Buffer Alignment" , function ( ) {
720+ visualTest (
721+ "buildGeometry with non-4-byte-aligned index buffer size" ,
722+ async function ( p5 , screenshot ) {
723+ await p5 . createCanvas ( 50 , 50 , p5 . WEBGPU ) ;
724+
725+ p5 . randomSeed ( 1 ) ;
726+ p5 . colorMode ( p5 . HSB , 360 , 100 , 100 ) ;
727+
728+ // Create a geometry that will result in a non-4-byte-aligned buffer size
729+ // We want to create an odd number of triangles that results in
730+ // indices.length * indexType.BYTES_PER_ELEMENT not being divisible by 4
731+ const geom = p5 . buildGeometry ( ( ) => {
732+ p5 . noStroke ( ) ;
733+ // Create 1323 triangles (3969 indices total)
734+ // With Uint16 indices (2 bytes each): 3969 * 2 = 7938 bytes
735+ // 7938 is not divisible by 4, we want to ensure the renderer
736+ // pads this to keep bytes aligned
737+ for ( let i = 0 ; i < 1323 ; i ++ ) {
738+ p5 . fill ( p5 . random ( 360 ) , 80 , 90 ) ;
739+ p5 . triangle (
740+ p5 . random ( - 25 , 25 ) , p5 . random ( - 25 , 25 ) ,
741+ p5 . random ( - 25 , 25 ) , p5 . random ( - 25 , 25 ) ,
742+ p5 . random ( - 25 , 25 ) , p5 . random ( - 25 , 25 )
743+ ) ;
744+ }
745+ } ) ;
746+
747+ p5 . background ( 20 ) ;
748+ p5 . model ( geom ) ;
749+
750+ await screenshot ( ) ;
751+ }
752+ ) ;
753+ } ) ;
754+
719755 visualSuite ( "Image Based Lighting" , function ( ) {
720756 const shinesses = [ 50 , 150 ] ;
721757 for ( const shininess of shinesses ) {
0 commit comments