@@ -40,7 +40,7 @@ export abstract class NfgComponent {
4040
4141 public async init ( ) : Promise < typeof this > {
4242 await this . _init ( ) ;
43- this . _updateUniforms ( ) ;
43+ this . updateUniforms ( ) ;
4444 this . _updatePipeline ( ) ;
4545 return this ;
4646 }
@@ -52,6 +52,27 @@ export abstract class NfgComponent {
5252 pass . draw ( this . _vertices . length / this . _vertexLength , this . _duplicate ) ;
5353 }
5454
55+ public updateUniforms ( ) : void {
56+ const uniformArray = new Float32Array ( [
57+ 0 ,
58+ 0 ,
59+ 0 ,
60+ 1 ,
61+ 1 ,
62+ 1 ,
63+ this . _core . initContext . canvas . width ,
64+ this . _core . initContext . canvas . height ,
65+ ] ) ;
66+ console . log ( this . _core . initContext . canvas . width , this . _core . initContext . canvas . height ) ;
67+ if ( ! this . _uniformBuffer )
68+ this . _uniformBuffer = this . _core . device . createBuffer ( {
69+ label : "View Uniforms" ,
70+ size : uniformArray . byteLength ,
71+ usage : GPUBufferUsage . UNIFORM | GPUBufferUsage . COPY_DST ,
72+ } ) ;
73+ this . _core . device . queue . writeBuffer ( this . _uniformBuffer , 0 , uniformArray ) ;
74+ }
75+
5576 protected abstract _init ( ) : Promise < void > ;
5677
5778 protected _setVertices ( raw : number [ ] ) : void {
@@ -96,25 +117,6 @@ export abstract class NfgComponent {
96117 this . _updateBindGroup ( ) ;
97118 }
98119
99- protected _updateUniforms ( ) : void {
100- const uniformArray = new Float32Array ( [
101- 0 ,
102- 0 ,
103- 0 ,
104- 1 ,
105- 1 ,
106- 1 ,
107- this . _core . initContext . canvas . width ,
108- this . _core . initContext . canvas . height ,
109- ] ) ;
110- this . _uniformBuffer = this . _core . device . createBuffer ( {
111- label : "View Uniforms" ,
112- size : uniformArray . byteLength ,
113- usage : GPUBufferUsage . UNIFORM | GPUBufferUsage . COPY_DST , // Une uniform est une valeur constante pour le gpu
114- } ) ;
115- this . _core . device . queue . writeBuffer ( this . _uniformBuffer , 0 , uniformArray ) ;
116- }
117-
118120 protected _updateBindGroup ( ) : void {
119121 this . _bindGroup = this . _core . device . createBindGroup ( {
120122 label : `${ this . _label } renderer bind group` ,
0 commit comments