micugl 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ export declare class WebGLManager {
21
21
  updateBuffer(programId: string, attributeName: string, data: Float32Array | Uint8Array | Uint16Array): void;
22
22
  registerUniformUpdater<T extends UniformType>(programId: string, uniformName: string, type: T, updateFn: UniformUpdateFn<T>): void;
23
23
  updateUniforms(programId: string, time: number): void;
24
- setSize(width: number, height: number, useDevicePixelRatio?: boolean): void;
24
+ setSize(width: number, height: number, dpr?: number): void;
25
25
  prepareRender(programId: string, options?: RenderOptions): void;
26
26
  fastRender(programId: string, time: number, clear?: boolean): void;
27
27
  setUniform<T extends UniformType>(programId: string, uniformName: string, value: UniformTypeMap[T], type: T): void;
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var b=(m,r,o)=>r in m?w(m,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):m[r]=o;var d=(m,r,o)=>b(m,typeof r!="symbol"?r+"":r,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./FBOManager.js");class v{constructor(r,o){d(this,"gl");d(this,"fboManager");d(this,"resources",new Map);d(this,"compileCache",new Map);d(this,"uniformUpdateFns",new Map);d(this,"extensions",new Map);const t={alpha:!1,depth:!1,stencil:!1,antialias:!1,powerPreference:"low-power",preserveDrawingBuffer:!1},e=r.getContext("webgl",{...t,...o});if(!e)throw new Error("WebGL not supported");this.gl=e,this.fboManager=new E.FBOManager(e),this.getExtension("OES_texture_float"),this.getExtension("OES_texture_float_linear"),this.getExtension("OES_vertex_array_object"),this.getExtension("ANGLE_instanced_arrays")}getExtension(r){if(this.extensions.has(r))return this.extensions.get(r);const o=this.gl.getExtension(r);return this.extensions.set(r,o),o}createProgram(r,o){const{vertexShader:t,fragmentShader:e,uniforms:s,attributes:i}=o,n=this.gl,h=this.getOrCompileShader("vertex:"+t,n.VERTEX_SHADER,t),l=this.getOrCompileShader("fragment:"+e,n.FRAGMENT_SHADER,e),f=n.createProgram();if(!f)throw new Error("Failed to create WebGL program");if(n.attachShader(f,h),n.attachShader(f,l),n.linkProgram(f),!n.getProgramParameter(f,n.LINK_STATUS)){const g=n.getProgramInfoLog(f);throw n.deleteProgram(f),new Error(`Could not link shader program: ${g}`)}const c={};for(const g of s)c[g.name]=n.getUniformLocation(f,g.name);const u={};if(i)for(const g of i)u[g.name]=n.getAttribLocation(f,g.name);const a={program:f,uniforms:c,attributes:u,buffers:{}};return this.resources.set(r,a),this.uniformUpdateFns.set(r,new Map),a}getOrCompileShader(r,o,t){if(this.compileCache.has(r)){const s=this.compileCache.get(r);if(s)return s}const e=this.compileShader(o,t);return this.compileCache.set(r,e),e}compileShader(r,o){const t=this.gl,e=t.createShader(r);if(!e)throw new Error("Failed to create shader");if(t.shaderSource(e,o),t.compileShader(e),!t.getShaderParameter(e,t.COMPILE_STATUS)){const s=t.getShaderInfoLog(e);throw t.deleteShader(e),new Error(`Shader compilation failed: ${s}`)}return e}createBuffer(r,o,t){const e=this.gl,s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);const i=e.createBuffer();if(!i)throw new Error("Failed to create buffer");return e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW),s.buffers[o]={buffer:i,data:t},i}updateBuffer(r,o,t){const e=this.gl,s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);const i=s.buffers[o];if(!i)throw new Error(`Buffer for attribute ${o} not found`);e.bindBuffer(e.ARRAY_BUFFER,i.buffer),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW),i.data=t}registerUniformUpdater(r,o,t,e){const s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);const i=this.uniformUpdateFns.get(r);if(!i)throw new Error(`Program uniforms for id ${r} not found`);const n=s.uniforms[o];if(n===null)return;const h=this.gl;let l;switch(t){case"int":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1i(n,a),a};break;case"float":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1f(n,a),a};break;case"sampler2D":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1i(n,a),a};break;case"vec2":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform2fv(n,a),a};break;case"vec3":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform3fv(n,a),a};break;case"vec4":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform4fv(n,a),a};break;case"mat2":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix2fv(n,!1,a),a};break;case"mat3":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix3fv(n,!1,a),a};break;case"mat4":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix4fv(n,!1,a),a};break;default:throw new Error(`Unsupported uniform type: ${t}`)}i.set(o,l)}updateUniforms(r,o){const t=this.uniformUpdateFns.get(r);if(!t)return;const e=this.gl.canvas,s=e.width,i=e.height;t.forEach(n=>{n(o,s,i)})}setSize(r,o,t=!0){const e=this.gl.canvas,s=t&&window.devicePixelRatio||1,i=Math.floor(r*s),n=Math.floor(o*s);(e.width!==i||e.height!==n)&&(e.width=i,e.height=n,e.style.width=`${r}px`,e.style.height=`${o}px`,this.gl.viewport(0,0,i,n))}prepareRender(r,o={}){const{clear:t=!0,clearColor:e=[0,0,0,1]}=o,s=this.gl,i=this.resources.get(r);if(!i)throw new Error(`Program with id ${r} not found`);s.useProgram(i.program),t&&(s.clearColor(...e),s.clear(s.COLOR_BUFFER_BIT))}fastRender(r,o,t=!0){const e=this.gl,s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);e.useProgram(s.program),t&&e.clear(e.COLOR_BUFFER_BIT),this.updateUniforms(r,o)}setUniform(r,o,t,e){const s=this.gl,i=this.resources.get(r);if(!i)throw new Error(`Program with id ${r} not found`);const n=i.uniforms[o];if(n!==null)switch(s.useProgram(i.program),e){case"float":s.uniform1f(n,t);break;case"vec2":s.uniform2fv(n,t);break;case"vec3":s.uniform3fv(n,t);break;case"vec4":s.uniform4fv(n,t);break;case"int":s.uniform1i(n,t);break;case"mat2":s.uniformMatrix2fv(n,!1,t);break;case"mat3":s.uniformMatrix3fv(n,!1,t);break;case"mat4":s.uniformMatrix4fv(n,!1,t);break;case"sampler2D":s.uniform1i(n,t);break;default:throw new Error(`Unsupported uniform type: ${e}`)}}setAttributeOnce(r,o,t){const e=this.gl,s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);const i=s.attributes[o];if(i===-1){console.warn(`Attribute ${o} not found or is unused`);return}const n=s.buffers[o];if(!n)throw new Error(`Buffer for attribute ${o} not found`);if(e.bindBuffer(e.ARRAY_BUFFER,n.buffer),e.enableVertexAttribArray(i),e.vertexAttribPointer(i,t.size,e[t.type],t.normalized,t.stride,t.offset),t.instanced){const h=this.getExtension("ANGLE_instanced_arrays");if(h!=null&&h.vertexAttribDivisorANGLE)h.vertexAttribDivisorANGLE(i,1);else if(e.vertexAttribDivisor)e.vertexAttribDivisor(i,1);else throw new Error("Instanced rendering not supported")}}drawArrays(r,o,t){this.gl.drawArrays(r,o,t)}drawElements(r,o,t,e){this.gl.drawElements(r,o,t,e)}destroy(r){const o=this.gl,t=this.resources.get(r);t&&(Object.values(t.buffers).forEach(({buffer:e})=>{o.deleteBuffer(e)}),o.deleteProgram(t.program),this.resources.delete(r),this.uniformUpdateFns.delete(r))}destroyAll(){for(const r of Array.from(this.resources.keys()))this.destroy(r);this.compileCache.clear(),this.fboManager.destroyAll()}get context(){return this.gl}get fbo(){return this.fboManager}}exports.WebGLManager=v;
1
+ "use strict";var w=Object.defineProperty;var b=(m,r,o)=>r in m?w(m,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):m[r]=o;var d=(m,r,o)=>b(m,typeof r!="symbol"?r+"":r,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./FBOManager.js");class v{constructor(r,o){d(this,"gl");d(this,"fboManager");d(this,"resources",new Map);d(this,"compileCache",new Map);d(this,"uniformUpdateFns",new Map);d(this,"extensions",new Map);const t={alpha:!1,depth:!1,stencil:!1,antialias:!1,powerPreference:"low-power",preserveDrawingBuffer:!1},e=r.getContext("webgl",{...t,...o});if(!e)throw new Error("WebGL not supported");this.gl=e,this.fboManager=new E.FBOManager(e),this.getExtension("OES_texture_float"),this.getExtension("OES_texture_float_linear"),this.getExtension("OES_vertex_array_object"),this.getExtension("ANGLE_instanced_arrays")}getExtension(r){if(this.extensions.has(r))return this.extensions.get(r);const o=this.gl.getExtension(r);return this.extensions.set(r,o),o}createProgram(r,o){const{vertexShader:t,fragmentShader:e,uniforms:s,attributes:i}=o,n=this.gl,h=this.getOrCompileShader("vertex:"+t,n.VERTEX_SHADER,t),l=this.getOrCompileShader("fragment:"+e,n.FRAGMENT_SHADER,e),f=n.createProgram();if(!f)throw new Error("Failed to create WebGL program");if(n.attachShader(f,h),n.attachShader(f,l),n.linkProgram(f),!n.getProgramParameter(f,n.LINK_STATUS)){const g=n.getProgramInfoLog(f);throw n.deleteProgram(f),new Error(`Could not link shader program: ${g}`)}const c={};for(const g of s)c[g.name]=n.getUniformLocation(f,g.name);const u={};if(i)for(const g of i)u[g.name]=n.getAttribLocation(f,g.name);const a={program:f,uniforms:c,attributes:u,buffers:{}};return this.resources.set(r,a),this.uniformUpdateFns.set(r,new Map),a}getOrCompileShader(r,o,t){if(this.compileCache.has(r)){const s=this.compileCache.get(r);if(s)return s}const e=this.compileShader(o,t);return this.compileCache.set(r,e),e}compileShader(r,o){const t=this.gl,e=t.createShader(r);if(!e)throw new Error("Failed to create shader");if(t.shaderSource(e,o),t.compileShader(e),!t.getShaderParameter(e,t.COMPILE_STATUS)){const s=t.getShaderInfoLog(e);throw t.deleteShader(e),new Error(`Shader compilation failed: ${s}`)}return e}createBuffer(r,o,t){const e=this.gl,s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);const i=e.createBuffer();if(!i)throw new Error("Failed to create buffer");return e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW),s.buffers[o]={buffer:i,data:t},i}updateBuffer(r,o,t){const e=this.gl,s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);const i=s.buffers[o];if(!i)throw new Error(`Buffer for attribute ${o} not found`);e.bindBuffer(e.ARRAY_BUFFER,i.buffer),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW),i.data=t}registerUniformUpdater(r,o,t,e){const s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);const i=this.uniformUpdateFns.get(r);if(!i)throw new Error(`Program uniforms for id ${r} not found`);const n=s.uniforms[o];if(n===null)return;const h=this.gl;let l;switch(t){case"int":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1i(n,a),a};break;case"float":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1f(n,a),a};break;case"sampler2D":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1i(n,a),a};break;case"vec2":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform2fv(n,a),a};break;case"vec3":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform3fv(n,a),a};break;case"vec4":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform4fv(n,a),a};break;case"mat2":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix2fv(n,!1,a),a};break;case"mat3":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix3fv(n,!1,a),a};break;case"mat4":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix4fv(n,!1,a),a};break;default:throw new Error(`Unsupported uniform type: ${t}`)}i.set(o,l)}updateUniforms(r,o){const t=this.uniformUpdateFns.get(r);if(!t)return;const e=this.gl.canvas,s=e.width,i=e.height;t.forEach(n=>{n(o,s,i)})}setSize(r,o,t=1){const e=this.gl.canvas,s=Math.floor(r*t),i=Math.floor(o*t);(e.width!==s||e.height!==i)&&(e.width=s,e.height=i,e.style.width=`${r}px`,e.style.height=`${o}px`,this.gl.viewport(0,0,s,i))}prepareRender(r,o={}){const{clear:t=!0,clearColor:e=[0,0,0,1]}=o,s=this.gl,i=this.resources.get(r);if(!i)throw new Error(`Program with id ${r} not found`);s.useProgram(i.program),t&&(s.clearColor(...e),s.clear(s.COLOR_BUFFER_BIT))}fastRender(r,o,t=!0){const e=this.gl,s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);e.useProgram(s.program),t&&e.clear(e.COLOR_BUFFER_BIT),this.updateUniforms(r,o)}setUniform(r,o,t,e){const s=this.gl,i=this.resources.get(r);if(!i)throw new Error(`Program with id ${r} not found`);const n=i.uniforms[o];if(n!==null)switch(s.useProgram(i.program),e){case"float":s.uniform1f(n,t);break;case"vec2":s.uniform2fv(n,t);break;case"vec3":s.uniform3fv(n,t);break;case"vec4":s.uniform4fv(n,t);break;case"int":s.uniform1i(n,t);break;case"mat2":s.uniformMatrix2fv(n,!1,t);break;case"mat3":s.uniformMatrix3fv(n,!1,t);break;case"mat4":s.uniformMatrix4fv(n,!1,t);break;case"sampler2D":s.uniform1i(n,t);break;default:throw new Error(`Unsupported uniform type: ${e}`)}}setAttributeOnce(r,o,t){const e=this.gl,s=this.resources.get(r);if(!s)throw new Error(`Program with id ${r} not found`);const i=s.attributes[o];if(i===-1){console.warn(`Attribute ${o} not found or is unused`);return}const n=s.buffers[o];if(!n)throw new Error(`Buffer for attribute ${o} not found`);if(e.bindBuffer(e.ARRAY_BUFFER,n.buffer),e.enableVertexAttribArray(i),e.vertexAttribPointer(i,t.size,e[t.type],t.normalized,t.stride,t.offset),t.instanced){const h=this.getExtension("ANGLE_instanced_arrays");if(h!=null&&h.vertexAttribDivisorANGLE)h.vertexAttribDivisorANGLE(i,1);else if(e.vertexAttribDivisor)e.vertexAttribDivisor(i,1);else throw new Error("Instanced rendering not supported")}}drawArrays(r,o,t){this.gl.drawArrays(r,o,t)}drawElements(r,o,t,e){this.gl.drawElements(r,o,t,e)}destroy(r){const o=this.gl,t=this.resources.get(r);t&&(Object.values(t.buffers).forEach(({buffer:e})=>{o.deleteBuffer(e)}),o.deleteProgram(t.program),this.resources.delete(r),this.uniformUpdateFns.delete(r))}destroyAll(){for(const r of Array.from(this.resources.keys()))this.destroy(r);this.compileCache.clear(),this.fboManager.destroyAll()}get context(){return this.gl}get fbo(){return this.fboManager}}exports.WebGLManager=v;
@@ -1,15 +1,15 @@
1
1
  var w = Object.defineProperty;
2
- var b = (m, e, o) => e in m ? w(m, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : m[e] = o;
3
- var d = (m, e, o) => b(m, typeof e != "symbol" ? e + "" : e, o);
2
+ var b = (d, e, o) => e in d ? w(d, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : d[e] = o;
3
+ var m = (d, e, o) => b(d, typeof e != "symbol" ? e + "" : e, o);
4
4
  import { FBOManager as E } from "./FBOManager.mjs";
5
5
  class A {
6
6
  constructor(e, o) {
7
- d(this, "gl");
8
- d(this, "fboManager");
9
- d(this, "resources", /* @__PURE__ */ new Map());
10
- d(this, "compileCache", /* @__PURE__ */ new Map());
11
- d(this, "uniformUpdateFns", /* @__PURE__ */ new Map());
12
- d(this, "extensions", /* @__PURE__ */ new Map());
7
+ m(this, "gl");
8
+ m(this, "fboManager");
9
+ m(this, "resources", /* @__PURE__ */ new Map());
10
+ m(this, "compileCache", /* @__PURE__ */ new Map());
11
+ m(this, "uniformUpdateFns", /* @__PURE__ */ new Map());
12
+ m(this, "extensions", /* @__PURE__ */ new Map());
13
13
  const t = {
14
14
  alpha: !1,
15
15
  depth: !1,
@@ -169,9 +169,9 @@ class A {
169
169
  n(o, s, i);
170
170
  });
171
171
  }
172
- setSize(e, o, t = !0) {
173
- const r = this.gl.canvas, s = t && window.devicePixelRatio || 1, i = Math.floor(e * s), n = Math.floor(o * s);
174
- (r.width !== i || r.height !== n) && (r.width = i, r.height = n, r.style.width = `${e}px`, r.style.height = `${o}px`, this.gl.viewport(0, 0, i, n));
172
+ setSize(e, o, t = 1) {
173
+ const r = this.gl.canvas, s = Math.floor(e * t), i = Math.floor(o * t);
174
+ (r.width !== s || r.height !== i) && (r.width = s, r.height = i, r.style.width = `${e}px`, r.style.height = `${o}px`, this.gl.viewport(0, 0, s, i));
175
175
  }
176
176
  prepareRender(e, o = {}) {
177
177
  const { clear: t = !0, clearColor: r = [0, 0, 0, 1] } = o, s = this.gl, i = this.resources.get(e);
@@ -5,6 +5,10 @@ export interface BaseShaderProps {
5
5
  programId: string;
6
6
  shaderConfig: ShaderProgramConfig;
7
7
  uniforms: Record<string, UniformParam>;
8
+ skipDefaultUniforms?: boolean;
9
+ width?: number;
10
+ height?: number;
11
+ pixelRatio?: number;
8
12
  className?: string;
9
13
  style?: CSSProperties;
10
14
  renderOptions?: {
@@ -12,4 +16,4 @@ export interface BaseShaderProps {
12
16
  clearColor?: [number, number, number, number];
13
17
  };
14
18
  }
15
- export declare const BaseShaderComponent: ({ programId, shaderConfig, uniforms, className, style, renderOptions }: BaseShaderProps) => import("react/jsx-runtime").JSX.Element;
19
+ export declare const BaseShaderComponent: ({ programId, shaderConfig, uniforms, skipDefaultUniforms, width, height, pixelRatio, className, style, renderOptions }: BaseShaderProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime");require("react");const m=require("../../hooks/useUniformUpdaters.js"),S=require("../engine/ShaderEngine.js"),l={clear:!0,clearColor:[0,0,0,1]},p=({programId:e,shaderConfig:t,uniforms:n,className:s="",style:o,renderOptions:a=l})=>{const u={[e]:t},i=m.useUniformUpdaters(e,n),c=(f,h,r)=>{r.drawArrays(r.TRIANGLE_STRIP,0,4)};return d.jsx(S.ShaderEngine,{programConfigs:u,renderCallback:c,uniformUpdaters:i,className:s,style:o,useFastPath:!0,renderOptions:a})};exports.BaseShaderComponent=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime");require("react");const p=require("../../hooks/useUniformUpdaters.js"),h=require("../engine/ShaderEngine.js"),C={clear:!0,clearColor:[0,0,0,1]},E=({programId:e,shaderConfig:s,uniforms:t,skipDefaultUniforms:n=!1,width:o,height:a,pixelRatio:u,className:i="",style:c,renderOptions:d=C})=>{const l={[e]:s},m=p.useUniformUpdaters(e,t,{skipDefaultUniforms:n}),S=(R,U,r)=>{r.drawArrays(r.TRIANGLE_STRIP,0,4)};return f.jsx(h.ShaderEngine,{programConfigs:l,renderCallback:S,uniformUpdaters:m,width:o,height:a,pixelRatio:u,className:i,style:c,useFastPath:!0,renderOptions:d})};exports.BaseShaderComponent=E;
@@ -1,34 +1,41 @@
1
- import { jsx as i } from "react/jsx-runtime";
1
+ import { jsx as u } from "react/jsx-runtime";
2
2
  import "react";
3
- import { useUniformUpdaters as p } from "../../hooks/useUniformUpdaters.mjs";
4
- import { ShaderEngine as u } from "../engine/ShaderEngine.mjs";
5
- const d = {
3
+ import { useUniformUpdaters as d } from "../../hooks/useUniformUpdaters.mjs";
4
+ import { ShaderEngine as C } from "../engine/ShaderEngine.mjs";
5
+ const E = {
6
6
  clear: !0,
7
7
  clearColor: [0, 0, 0, 1]
8
- }, h = ({
8
+ }, U = ({
9
9
  programId: r,
10
10
  shaderConfig: o,
11
11
  uniforms: t,
12
- className: s = "",
13
- style: a,
14
- renderOptions: n = d
12
+ skipDefaultUniforms: s = !1,
13
+ width: a,
14
+ height: n,
15
+ pixelRatio: m,
16
+ className: c = "",
17
+ style: i,
18
+ renderOptions: p = E
15
19
  }) => {
16
- const m = { [r]: o }, c = p(r, t);
17
- return /* @__PURE__ */ i(
18
- u,
20
+ const f = { [r]: o }, l = d(r, t, { skipDefaultUniforms: s });
21
+ return /* @__PURE__ */ u(
22
+ C,
19
23
  {
20
- programConfigs: m,
21
- renderCallback: (l, C, e) => {
24
+ programConfigs: f,
25
+ renderCallback: (S, _, e) => {
22
26
  e.drawArrays(e.TRIANGLE_STRIP, 0, 4);
23
27
  },
24
- uniformUpdaters: c,
25
- className: s,
26
- style: a,
28
+ uniformUpdaters: l,
29
+ width: a,
30
+ height: n,
31
+ pixelRatio: m,
32
+ className: c,
33
+ style: i,
27
34
  useFastPath: !0,
28
- renderOptions: n
35
+ renderOptions: p
29
36
  }
30
37
  );
31
38
  };
32
39
  export {
33
- h as BaseShaderComponent
40
+ U as BaseShaderComponent
34
41
  };
@@ -6,6 +6,8 @@ interface ShaderEngineProps {
6
6
  renderOptions?: RenderOptions;
7
7
  className?: string;
8
8
  style?: CSSProperties;
9
+ width?: number;
10
+ height?: number;
9
11
  uniformUpdaters?: Record<string, {
10
12
  name: string;
11
13
  type: UniformType;
@@ -13,6 +15,7 @@ interface ShaderEngineProps {
13
15
  }[]>;
14
16
  useFastPath?: boolean;
15
17
  useDevicePixelRatio?: boolean;
18
+ pixelRatio?: number;
16
19
  }
17
- export declare const ShaderEngine: ({ programConfigs, renderCallback, renderOptions, className, style, uniformUpdaters, useFastPath, useDevicePixelRatio }: ShaderEngineProps) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const ShaderEngine: ({ programConfigs, renderCallback, renderOptions, className, style, width, height, uniformUpdaters, useFastPath, useDevicePixelRatio, pixelRatio }: ShaderEngineProps) => import("react/jsx-runtime").JSX.Element;
18
21
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("react/jsx-runtime"),t=require("react"),F=require("../../../core/managers/WebGLManager.js"),b={},y="",I={},h={},U=({programConfigs:E,renderCallback:T,renderOptions:o=b,className:L=y,style:S=I,uniformUpdaters:p=h,useFastPath:R=!1,useDevicePixelRatio:w=!0})=>{const f=t.useRef(null),a=t.useRef(null),l=t.useRef(null),u=t.useRef(null),g=t.useRef(0),m=t.useRef(r=>{const e=a.current,n=l.current;if(!e||!n)return;const c=r-g.current,s=e.context;if(R)e.fastRender(n,c,o.clear),s.drawArrays(s.TRIANGLE_STRIP,0,4);else{const i=e.resources.get(n);if(!i)return;e.prepareRender(n,o),A(c,i,s)}u.current=requestAnimationFrame(m.current)}),A=t.useCallback((r,e,n)=>{T(r,e,n)},[T]);t.useEffect(()=>{m.current=r=>{const e=a.current,n=l.current;if(!e||!n)return;const c=r-g.current,s=e.context;if(R)e.fastRender(n,c,o.clear),s.drawArrays(s.TRIANGLE_STRIP,0,4);else{const i=e.resources.get(n);if(!i)return;e.prepareRender(n,o),A(c,i,s)}u.current=requestAnimationFrame(m.current)}},[o,R,A]);const d=t.useCallback(()=>{if(!f.current||!a.current)return;const r=window.innerWidth,e=window.innerHeight;a.current.setSize(r,e,w)},[w]);return t.useEffect(()=>{if(!f.current)return;const r=new F.WebGLManager(f.current);a.current=r,d();const[[e,n]]=Object.entries(E);return r.createProgram(e,n),r.createBuffer(e,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),r.setAttributeOnce(e,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0}),l.current=e,g.current=performance.now(),u.current=requestAnimationFrame(m.current),window.addEventListener("resize",d),()=>{window.removeEventListener("resize",d),u.current&&cancelAnimationFrame(u.current),r.destroyAll()}},[E,d]),t.useEffect(()=>{const r=a.current,e=l.current;if(!r||!e)return;const n=p[e];n&&n.forEach(c=>{r.registerUniformUpdater(e,c.name,c.type,c.updateFn)})},[p]),_.jsx("canvas",{ref:f,className:L,style:S})};exports.ShaderEngine=U;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),t=require("react"),I=require("../../../core/managers/WebGLManager.js"),v={},U="",q={},z={},N=({programConfigs:E,renderCallback:T,renderOptions:o=v,className:F=U,style:b=q,width:p,height:w,uniformUpdaters:L=z,useFastPath:R=!1,useDevicePixelRatio:S=!0,pixelRatio:_})=>{const f=t.useRef(null),a=t.useRef(null),l=t.useRef(null),u=t.useRef(null),g=t.useRef(0),d=t.useRef(n=>{const e=a.current,r=l.current;if(!e||!r)return;const c=n-g.current,s=e.context;if(R)e.fastRender(r,c,o.clear),s.drawArrays(s.TRIANGLE_STRIP,0,4);else{const i=e.resources.get(r);if(!i)return;e.prepareRender(r,o),A(c,i,s)}u.current=requestAnimationFrame(d.current)}),A=t.useCallback((n,e,r)=>{T(n,e,r)},[T]);t.useEffect(()=>{d.current=n=>{const e=a.current,r=l.current;if(!e||!r)return;const c=n-g.current,s=e.context;if(R)e.fastRender(r,c,o.clear),s.drawArrays(s.TRIANGLE_STRIP,0,4);else{const i=e.resources.get(r);if(!i)return;e.prepareRender(r,o),A(c,i,s)}u.current=requestAnimationFrame(d.current)}},[o,R,A]);const m=t.useCallback(()=>{if(!f.current||!a.current)return;const n=p??window.innerWidth,e=w??window.innerHeight,r=_??(S?window.devicePixelRatio:1);a.current.setSize(n,e,r)},[S,_,p,w]);return t.useEffect(()=>{if(!f.current)return;const n=new I.WebGLManager(f.current);a.current=n,m();const[[e,r]]=Object.entries(E);return n.createProgram(e,r),n.createBuffer(e,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),n.setAttributeOnce(e,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0}),l.current=e,g.current=performance.now(),u.current=requestAnimationFrame(d.current),window.addEventListener("resize",m),()=>{window.removeEventListener("resize",m),u.current&&cancelAnimationFrame(u.current),n.destroyAll()}},[E,m]),t.useEffect(()=>{const n=a.current,e=l.current;if(!n||!e)return;const r=L[e];r&&r.forEach(c=>{n.registerUniformUpdater(e,c.name,c.type,c.updateFn)})},[L]),y.jsx("canvas",{ref:f,className:F,style:b})};exports.ShaderEngine=N;
@@ -1,82 +1,85 @@
1
- import { jsx as I } from "react/jsx-runtime";
2
- import { useRef as s, useCallback as _, useEffect as g } from "react";
3
- import { WebGLManager as U } from "../../../core/managers/WebGLManager.mjs";
4
- const h = {}, y = "", z = {}, N = {}, q = ({
1
+ import { jsx as y } from "react/jsx-runtime";
2
+ import { useRef as s, useCallback as I, useEffect as g } from "react";
3
+ import { WebGLManager as z } from "../../../core/managers/WebGLManager.mjs";
4
+ const N = {}, b = "", D = {}, P = {}, M = ({
5
5
  programConfigs: E,
6
6
  renderCallback: T,
7
- renderOptions: a = h,
8
- className: F = y,
9
- style: S = z,
10
- uniformUpdaters: w = N,
7
+ renderOptions: a = N,
8
+ className: U = b,
9
+ style: v = D,
10
+ width: w,
11
+ height: L,
12
+ uniformUpdaters: _ = P,
11
13
  useFastPath: A = !1,
12
- useDevicePixelRatio: L = !0
14
+ useDevicePixelRatio: F = !0,
15
+ pixelRatio: S
13
16
  }) => {
14
- const f = s(null), o = s(null), m = s(null), i = s(null), R = s(0), l = s((r) => {
15
- const e = o.current, n = m.current;
16
- if (!e || !n) return;
17
- const t = r - R.current, c = e.context;
17
+ const f = s(null), o = s(null), m = s(null), i = s(null), R = s(0), d = s((n) => {
18
+ const e = o.current, r = m.current;
19
+ if (!e || !r) return;
20
+ const t = n - R.current, c = e.context;
18
21
  if (A)
19
- e.fastRender(n, t, a.clear), c.drawArrays(c.TRIANGLE_STRIP, 0, 4);
22
+ e.fastRender(r, t, a.clear), c.drawArrays(c.TRIANGLE_STRIP, 0, 4);
20
23
  else {
21
- const u = e.resources.get(n);
24
+ const u = e.resources.get(r);
22
25
  if (!u) return;
23
- e.prepareRender(n, a), p(t, u, c);
26
+ e.prepareRender(r, a), p(t, u, c);
24
27
  }
25
- i.current = requestAnimationFrame(l.current);
26
- }), p = _((r, e, n) => {
27
- T(r, e, n);
28
+ i.current = requestAnimationFrame(d.current);
29
+ }), p = I((n, e, r) => {
30
+ T(n, e, r);
28
31
  }, [T]);
29
32
  g(() => {
30
- l.current = (r) => {
31
- const e = o.current, n = m.current;
32
- if (!e || !n) return;
33
- const t = r - R.current, c = e.context;
33
+ d.current = (n) => {
34
+ const e = o.current, r = m.current;
35
+ if (!e || !r) return;
36
+ const t = n - R.current, c = e.context;
34
37
  if (A)
35
- e.fastRender(n, t, a.clear), c.drawArrays(c.TRIANGLE_STRIP, 0, 4);
38
+ e.fastRender(r, t, a.clear), c.drawArrays(c.TRIANGLE_STRIP, 0, 4);
36
39
  else {
37
- const u = e.resources.get(n);
40
+ const u = e.resources.get(r);
38
41
  if (!u) return;
39
- e.prepareRender(n, a), p(t, u, c);
42
+ e.prepareRender(r, a), p(t, u, c);
40
43
  }
41
- i.current = requestAnimationFrame(l.current);
44
+ i.current = requestAnimationFrame(d.current);
42
45
  };
43
46
  }, [a, A, p]);
44
- const d = _(() => {
47
+ const l = I(() => {
45
48
  if (!f.current || !o.current) return;
46
- const r = window.innerWidth, e = window.innerHeight;
47
- o.current.setSize(r, e, L);
48
- }, [L]);
49
+ const n = w ?? window.innerWidth, e = L ?? window.innerHeight, r = S ?? (F ? window.devicePixelRatio : 1);
50
+ o.current.setSize(n, e, r);
51
+ }, [F, S, w, L]);
49
52
  return g(() => {
50
53
  if (!f.current) return;
51
- const r = new U(f.current);
52
- o.current = r, d();
53
- const [[e, n]] = Object.entries(E);
54
- return r.createProgram(e, n), r.createBuffer(e, "a_position", new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1])), r.setAttributeOnce(e, "a_position", {
54
+ const n = new z(f.current);
55
+ o.current = n, l();
56
+ const [[e, r]] = Object.entries(E);
57
+ return n.createProgram(e, r), n.createBuffer(e, "a_position", new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1])), n.setAttributeOnce(e, "a_position", {
55
58
  name: "a_position",
56
59
  size: 2,
57
60
  type: "FLOAT",
58
61
  normalized: !1,
59
62
  stride: 0,
60
63
  offset: 0
61
- }), m.current = e, R.current = performance.now(), i.current = requestAnimationFrame(l.current), window.addEventListener("resize", d), () => {
62
- window.removeEventListener("resize", d), i.current && cancelAnimationFrame(i.current), r.destroyAll();
64
+ }), m.current = e, R.current = performance.now(), i.current = requestAnimationFrame(d.current), window.addEventListener("resize", l), () => {
65
+ window.removeEventListener("resize", l), i.current && cancelAnimationFrame(i.current), n.destroyAll();
63
66
  };
64
- }, [E, d]), g(() => {
65
- const r = o.current, e = m.current;
66
- if (!r || !e) return;
67
- const n = w[e];
68
- n && n.forEach((t) => {
69
- r.registerUniformUpdater(e, t.name, t.type, t.updateFn);
67
+ }, [E, l]), g(() => {
68
+ const n = o.current, e = m.current;
69
+ if (!n || !e) return;
70
+ const r = _[e];
71
+ r && r.forEach((t) => {
72
+ n.registerUniformUpdater(e, t.name, t.type, t.updateFn);
70
73
  });
71
- }, [w]), /* @__PURE__ */ I(
74
+ }, [_]), /* @__PURE__ */ y(
72
75
  "canvas",
73
76
  {
74
77
  ref: f,
75
- className: F,
76
- style: S
78
+ className: U,
79
+ style: v
77
80
  }
78
81
  );
79
82
  };
80
83
  export {
81
- q as ShaderEngine
84
+ M as ShaderEngine
82
85
  };
@@ -1,4 +1,6 @@
1
1
  import { UniformParam, UniformUpdaterDef } from '../../types';
2
- export declare const useUniformUpdaters: (programId: string, uniforms: Record<string, UniformParam>) => {
2
+ export declare const useUniformUpdaters: (programId: string, uniforms: Record<string, UniformParam>, options?: {
3
+ skipDefaultUniforms?: boolean;
4
+ }) => {
3
5
  [x: string]: UniformUpdaterDef<import('../../types').UniformType>[];
4
6
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),u=require("../lib/createUniformUpdater.js"),a=(t,r)=>n.useMemo(()=>{const s=u.createCommonUpdaters();return Object.entries(r).forEach(([e,o])=>{const c=e.startsWith("u_")?e:`u_${e}`;s.push(u.createUniformUpdater(c,o.type,o.value))}),{[t]:s}},[t,r]);exports.useUniformUpdaters=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),c=require("../lib/createUniformUpdater.js"),U=(u,t,e)=>n.useMemo(()=>{const a=(e==null?void 0:e.skipDefaultUniforms)??!1?[]:c.createCommonUpdaters().filter(r=>r.name==="u_time"&&!("u_time"in t)||r.name==="u_resolution"&&!("u_resolution"in t));return Object.entries(t).forEach(([r,s])=>{const i=r.startsWith("u_")?r:`u_${r}`;a.push(c.createUniformUpdater(i,s.type,s.value))}),{[u]:a}},[u,t,e==null?void 0:e.skipDefaultUniforms]);exports.useUniformUpdaters=U;
@@ -1,12 +1,14 @@
1
- import { useMemo as c } from "react";
2
- import { createCommonUpdaters as n, createUniformUpdater as p } from "../lib/createUniformUpdater.mjs";
3
- const a = (e, r) => c(() => {
4
- const o = n();
5
- return Object.entries(r).forEach(([t, s]) => {
6
- const u = t.startsWith("u_") ? t : `u_${t}`;
7
- o.push(p(u, s.type, s.value));
8
- }), { [e]: o };
9
- }, [e, r]);
1
+ import { useMemo as f } from "react";
2
+ import { createCommonUpdaters as c, createUniformUpdater as i } from "../lib/createUniformUpdater.mjs";
3
+ const n = (u, t, e) => f(() => {
4
+ const a = (e == null ? void 0 : e.skipDefaultUniforms) ?? !1 ? [] : c().filter(
5
+ (r) => r.name === "u_time" && !("u_time" in t) || r.name === "u_resolution" && !("u_resolution" in t)
6
+ );
7
+ return Object.entries(t).forEach(([r, m]) => {
8
+ const s = r.startsWith("u_") ? r : `u_${r}`;
9
+ a.push(i(s, m.type, m.value));
10
+ }), { [u]: a };
11
+ }, [u, t, e == null ? void 0 : e.skipDefaultUniforms]);
10
12
  export {
11
- a as useUniformUpdaters
13
+ n as useUniformUpdaters
12
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "micugl",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Micu gl - Small React shader library",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",