@lightningjs/renderer 2.1.2 → 2.3.0
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.
- package/README.md +1 -4
- package/dist/exports/core-api.d.ts +74 -0
- package/dist/exports/core-api.js +96 -0
- package/dist/exports/core-api.js.map +1 -0
- package/dist/exports/index.d.ts +1 -0
- package/dist/exports/index.js +1 -0
- package/dist/exports/index.js.map +1 -1
- package/dist/exports/main-api.d.ts +30 -0
- package/dist/exports/main-api.js +45 -0
- package/dist/exports/main-api.js.map +1 -0
- package/dist/src/common/IAnimationController.d.ts +1 -1
- package/dist/src/core/CoreExtension.d.ts +12 -0
- package/dist/src/core/CoreExtension.js +29 -0
- package/dist/src/core/CoreExtension.js.map +1 -0
- package/dist/src/core/CoreNode.d.ts +1 -1
- package/dist/src/core/CoreNode.js +45 -46
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreShaderManager.js +1 -0
- package/dist/src/core/CoreShaderManager.js.map +1 -1
- package/dist/src/core/Stage.d.ts +1 -0
- package/dist/src/core/Stage.js +2 -1
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/animations/CoreAnimationController.js +3 -2
- package/dist/src/core/animations/CoreAnimationController.js.map +1 -1
- package/dist/src/core/lib/WebGlContextWrapper.d.ts +144 -2
- package/dist/src/core/lib/WebGlContextWrapper.js +211 -20
- package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
- package/dist/src/core/renderers/CoreRenderer.d.ts +1 -0
- package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +4 -3
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreShader.d.ts +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreShader.js +8 -18
- package/dist/src/core/renderers/webgl/WebGlCoreShader.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +1 -1
- package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.d.ts +2 -1
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +55 -2
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +1 -1
- package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/SdfShader.js +6 -6
- package/dist/src/core/renderers/webgl/shaders/SdfShader.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.d.ts +2 -0
- package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/TextRenderer.js +12 -9
- package/dist/src/core/text-rendering/renderers/TextRenderer.js.map +1 -1
- package/dist/src/core/utils.d.ts +1 -1
- package/dist/src/main-api/ICoreDriver.d.ts +24 -0
- package/dist/src/main-api/ICoreDriver.js +20 -0
- package/dist/src/main-api/ICoreDriver.js.map +1 -0
- package/dist/src/main-api/Inspector.js +9 -0
- package/dist/src/main-api/Inspector.js.map +1 -1
- package/dist/src/main-api/Renderer.d.ts +10 -0
- package/dist/src/main-api/Renderer.js +2 -0
- package/dist/src/main-api/Renderer.js.map +1 -1
- package/dist/src/main-api/RendererMain.d.ts +378 -0
- package/dist/src/main-api/RendererMain.js +367 -0
- package/dist/src/main-api/RendererMain.js.map +1 -0
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.d.ts +9 -0
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js +38 -0
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js.map +1 -0
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.d.ts +56 -0
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js +101 -0
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js.map +1 -0
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.d.ts +32 -0
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js +28 -0
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js.map +1 -0
- package/dist/src/render-drivers/main/MainCoreDriver.d.ts +21 -0
- package/dist/src/render-drivers/main/MainCoreDriver.js +115 -0
- package/dist/src/render-drivers/main/MainCoreDriver.js.map +1 -0
- package/dist/src/render-drivers/main/MainOnlyNode.d.ts +101 -0
- package/dist/src/render-drivers/main/MainOnlyNode.js +425 -0
- package/dist/src/render-drivers/main/MainOnlyNode.js.map +1 -0
- package/dist/src/render-drivers/main/MainOnlyTextNode.d.ts +47 -0
- package/dist/src/render-drivers/main/MainOnlyTextNode.js +204 -0
- package/dist/src/render-drivers/main/MainOnlyTextNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/NodeStruct.d.ts +93 -0
- package/dist/src/render-drivers/threadx/NodeStruct.js +290 -0
- package/dist/src/render-drivers/threadx/NodeStruct.js.map +1 -0
- package/dist/src/render-drivers/threadx/SharedNode.d.ts +40 -0
- package/dist/src/render-drivers/threadx/SharedNode.js +61 -0
- package/dist/src/render-drivers/threadx/SharedNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/TextNodeStruct.d.ts +44 -0
- package/dist/src/render-drivers/threadx/TextNodeStruct.js +203 -0
- package/dist/src/render-drivers/threadx/TextNodeStruct.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +25 -0
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +232 -0
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.d.ts +24 -0
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js +113 -0
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXMainNode.d.ts +46 -0
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js +160 -0
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.d.ts +28 -0
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js +55 -0
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +70 -0
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js +32 -0
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +1 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.d.ts +19 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js +184 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.d.ts +27 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js +109 -0
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js.map +1 -0
- package/dist/src/render-drivers/threadx/worker/renderer.d.ts +1 -0
- package/dist/src/render-drivers/threadx/worker/renderer.js +147 -0
- package/dist/src/render-drivers/threadx/worker/renderer.js.map +1 -0
- package/dist/src/render-drivers/utils.d.ts +12 -0
- package/dist/src/render-drivers/utils.js +74 -0
- package/dist/src/render-drivers/utils.js.map +1 -0
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +2 -2
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/exports/index.ts +1 -0
- package/package.json +1 -1
- package/src/common/IAnimationController.ts +5 -1
- package/src/core/CoreNode.ts +57 -55
- package/src/core/CoreShaderManager.ts +1 -0
- package/src/core/Stage.ts +3 -0
- package/src/core/animations/CoreAnimationController.ts +3 -2
- package/src/core/lib/WebGlContextWrapper.ts +288 -26
- package/src/core/renderers/CoreRenderer.ts +1 -0
- package/src/core/renderers/webgl/WebGlCoreRenderer.ts +8 -3
- package/src/core/renderers/webgl/WebGlCoreShader.ts +21 -28
- package/src/core/renderers/webgl/shaders/DefaultShaderBatched.ts +1 -1
- package/src/core/renderers/webgl/shaders/DynamicShader.ts +75 -3
- package/src/core/renderers/webgl/shaders/RoundedRectangle.ts +4 -1
- package/src/core/renderers/webgl/shaders/SdfShader.ts +21 -6
- package/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts +3 -0
- package/src/core/text-rendering/renderers/TextRenderer.ts +18 -18
- package/src/main-api/Inspector.ts +12 -0
- package/src/main-api/Renderer.ts +13 -0
- package/src/utils.ts +2 -1
|
@@ -45,10 +45,6 @@ export class WebGlContextWrapper {
|
|
|
45
45
|
private boundArrayBuffer: WebGLBuffer | null;
|
|
46
46
|
private boundElementArrayBuffer: WebGLBuffer | null;
|
|
47
47
|
private curProgram: WebGLProgram | null;
|
|
48
|
-
private programUniforms: WeakMap<
|
|
49
|
-
WebGLProgram,
|
|
50
|
-
Map<WebGLUniformLocation, any[]>
|
|
51
|
-
> = new WeakMap();
|
|
52
48
|
//#endregion Cached WebGL State
|
|
53
49
|
|
|
54
50
|
//#region Canvas
|
|
@@ -708,22 +704,279 @@ export class WebGlContextWrapper {
|
|
|
708
704
|
this.curProgram = program;
|
|
709
705
|
}
|
|
710
706
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
707
|
+
/**
|
|
708
|
+
* Sets the value of a single float uniform variable.
|
|
709
|
+
*
|
|
710
|
+
* @param location - The location of the uniform variable.
|
|
711
|
+
* @param v0 - The value to set.
|
|
712
|
+
*/
|
|
713
|
+
uniform1f(location: WebGLUniformLocation | null, v0: number) {
|
|
714
|
+
const { gl } = this;
|
|
715
|
+
gl.uniform1f(location, v0);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Sets the value of a float array uniform variable.
|
|
720
|
+
*
|
|
721
|
+
* @param location - The location of the uniform variable.
|
|
722
|
+
* @param value - The array of values to set.
|
|
723
|
+
*/
|
|
724
|
+
uniform1fv(
|
|
725
|
+
location: WebGLUniformLocation | null,
|
|
726
|
+
value: Float32Array | number[],
|
|
715
727
|
) {
|
|
716
|
-
const { gl
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
728
|
+
const { gl } = this;
|
|
729
|
+
gl.uniform1fv(location, value);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Sets the value of a single integer uniform variable.
|
|
734
|
+
*
|
|
735
|
+
* @param location - The location of the uniform variable.
|
|
736
|
+
* @param v0 - The value to set.
|
|
737
|
+
*/
|
|
738
|
+
uniform1i(location: WebGLUniformLocation | null, v0: number) {
|
|
739
|
+
const { gl } = this;
|
|
740
|
+
gl.uniform1i(location, v0);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Sets the value of an integer array uniform variable.
|
|
745
|
+
*
|
|
746
|
+
* @param location - The location of the uniform variable.
|
|
747
|
+
* @param value - The array of values to set.
|
|
748
|
+
*/
|
|
749
|
+
uniform1iv(
|
|
750
|
+
location: WebGLUniformLocation | null,
|
|
751
|
+
value: Int32Array | number[],
|
|
752
|
+
) {
|
|
753
|
+
const { gl } = this;
|
|
754
|
+
gl.uniform1iv(location, value);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Sets the value of a vec2 uniform variable.
|
|
759
|
+
*
|
|
760
|
+
* @param location - The location of the uniform variable.
|
|
761
|
+
* @param v0 - The first component of the vector.
|
|
762
|
+
* @param v1 - The second component of the vector.
|
|
763
|
+
*/
|
|
764
|
+
uniform2f(location: WebGLUniformLocation | null, v0: number, v1: number) {
|
|
765
|
+
const { gl } = this;
|
|
766
|
+
gl.uniform2f(location, v0, v1);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Sets the value of a vec2 array uniform variable.
|
|
771
|
+
*
|
|
772
|
+
* @param location - The location of the uniform variable.
|
|
773
|
+
* @param value - The array of vec2 values to set.
|
|
774
|
+
*/
|
|
775
|
+
uniform2fv(
|
|
776
|
+
location: WebGLUniformLocation | null,
|
|
777
|
+
value: Float32Array | number[],
|
|
778
|
+
) {
|
|
779
|
+
const { gl } = this;
|
|
780
|
+
gl.uniform2fv(location, value);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Sets the value of a ivec2 uniform variable.
|
|
785
|
+
*
|
|
786
|
+
* @param location - The location of the uniform variable.
|
|
787
|
+
* @param v0 - The first component of the vector.
|
|
788
|
+
* @param v1 - The second component of the vector.
|
|
789
|
+
*/
|
|
790
|
+
uniform2i(location: WebGLUniformLocation | null, v0: number, v1: number) {
|
|
791
|
+
const { gl } = this;
|
|
792
|
+
gl.uniform2i(location, v0, v1);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Sets the value of an ivec2 array uniform variable.
|
|
797
|
+
*
|
|
798
|
+
* @param location - The location of the uniform variable.
|
|
799
|
+
* @param value - The array of ivec2 values to set.
|
|
800
|
+
*/
|
|
801
|
+
uniform2iv(
|
|
802
|
+
location: WebGLUniformLocation | null,
|
|
803
|
+
value: Int32Array | number[],
|
|
804
|
+
) {
|
|
805
|
+
const { gl } = this;
|
|
806
|
+
gl.uniform2iv(location, value);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Sets the value of a vec3 uniform variable.
|
|
811
|
+
*
|
|
812
|
+
* @param location - The location of the uniform variable.
|
|
813
|
+
* @param v0 - The first component of the vector.
|
|
814
|
+
* @param v1 - The second component of the vector.
|
|
815
|
+
* @param v2 - The third component of the vector.
|
|
816
|
+
*/
|
|
817
|
+
uniform3f(
|
|
818
|
+
location: WebGLUniformLocation | null,
|
|
819
|
+
v0: number,
|
|
820
|
+
v1: number,
|
|
821
|
+
v2: number,
|
|
822
|
+
) {
|
|
823
|
+
const { gl } = this;
|
|
824
|
+
gl.uniform3f(location, v0, v1, v2);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Sets the value of a vec3 array uniform variable.
|
|
829
|
+
*
|
|
830
|
+
* @param location - The location of the uniform variable.
|
|
831
|
+
* @param value - The array of vec3 values to set.
|
|
832
|
+
*/
|
|
833
|
+
uniform3fv(
|
|
834
|
+
location: WebGLUniformLocation | null,
|
|
835
|
+
value: Float32Array | number[],
|
|
836
|
+
) {
|
|
837
|
+
const { gl } = this;
|
|
838
|
+
gl.uniform3fv(location, value);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Sets the value of a ivec3 uniform variable.
|
|
843
|
+
*
|
|
844
|
+
* @param location - The location of the uniform variable.
|
|
845
|
+
* @param v0 - The first component of the vector.
|
|
846
|
+
* @param v1 - The second component of the vector.
|
|
847
|
+
* @param v2 - The third component of the vector.
|
|
848
|
+
*/
|
|
849
|
+
uniform3i(
|
|
850
|
+
location: WebGLUniformLocation | null,
|
|
851
|
+
v0: number,
|
|
852
|
+
v1: number,
|
|
853
|
+
v2: number,
|
|
854
|
+
) {
|
|
855
|
+
const { gl } = this;
|
|
856
|
+
gl.uniform3i(location, v0, v1, v2);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Sets the value of an ivec3 array uniform variable.
|
|
861
|
+
*
|
|
862
|
+
* @param location - The location of the uniform variable.
|
|
863
|
+
* @param value - The array of ivec3 values to set.
|
|
864
|
+
*/
|
|
865
|
+
uniform3iv(
|
|
866
|
+
location: WebGLUniformLocation | null,
|
|
867
|
+
value: Int32Array | number[],
|
|
868
|
+
) {
|
|
869
|
+
const { gl } = this;
|
|
870
|
+
gl.uniform3iv(location, value);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Sets the value of a vec4 uniform variable.
|
|
875
|
+
*
|
|
876
|
+
* @param location - The location of the uniform variable.
|
|
877
|
+
* @param v0 - The first component of the vector.
|
|
878
|
+
* @param v1 - The second component of the vector.
|
|
879
|
+
* @param v2 - The third component of the vector.
|
|
880
|
+
* @param v3 - The fourth component of the vector.
|
|
881
|
+
*/
|
|
882
|
+
uniform4f(
|
|
883
|
+
location: WebGLUniformLocation | null,
|
|
884
|
+
v0: number,
|
|
885
|
+
v1: number,
|
|
886
|
+
v2: number,
|
|
887
|
+
v3: number,
|
|
888
|
+
) {
|
|
889
|
+
const { gl } = this;
|
|
890
|
+
gl.uniform4f(location, v0, v1, v2, v3);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Sets the value of a vec4 array uniform variable.
|
|
895
|
+
*
|
|
896
|
+
* @param location - The location of the uniform variable.
|
|
897
|
+
* @param value - The array of vec4 values to set.
|
|
898
|
+
*/
|
|
899
|
+
uniform4fv(
|
|
900
|
+
location: WebGLUniformLocation | null,
|
|
901
|
+
value: Float32Array | number[],
|
|
902
|
+
) {
|
|
903
|
+
const { gl } = this;
|
|
904
|
+
gl.uniform4fv(location, value);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Sets the value of a ivec4 uniform variable.
|
|
909
|
+
*
|
|
910
|
+
* @param location - The location of the uniform variable.
|
|
911
|
+
* @param v0 - The first component of the vector.
|
|
912
|
+
* @param v1 - The second component of the vector.
|
|
913
|
+
* @param v2 - The third component of the vector.
|
|
914
|
+
* @param v3 - The fourth component of the vector.
|
|
915
|
+
*/
|
|
916
|
+
uniform4i(
|
|
917
|
+
location: WebGLUniformLocation | null,
|
|
918
|
+
v0: number,
|
|
919
|
+
v1: number,
|
|
920
|
+
v2: number,
|
|
921
|
+
v3: number,
|
|
922
|
+
) {
|
|
923
|
+
const { gl } = this;
|
|
924
|
+
gl.uniform4i(location, v0, v1, v2, v3);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* Sets the value of an ivec4 array uniform variable.
|
|
929
|
+
*
|
|
930
|
+
* @param location - The location of the uniform variable.
|
|
931
|
+
* @param value - The array of ivec4 values to set.
|
|
932
|
+
*/
|
|
933
|
+
uniform4iv(
|
|
934
|
+
location: WebGLUniformLocation | null,
|
|
935
|
+
value: Int32Array | number[],
|
|
936
|
+
) {
|
|
937
|
+
const { gl } = this;
|
|
938
|
+
gl.uniform4iv(location, value);
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Sets the value of a mat2 uniform variable.
|
|
943
|
+
*
|
|
944
|
+
* @param location - The location of the uniform variable.
|
|
945
|
+
* @param transpose - Whether to transpose the matrix.
|
|
946
|
+
* @param value - The array of mat2 values to set.
|
|
947
|
+
*/
|
|
948
|
+
uniformMatrix2fv(
|
|
949
|
+
location: WebGLUniformLocation | null,
|
|
950
|
+
value: Float32Array | number[],
|
|
951
|
+
) {
|
|
952
|
+
const { gl } = this;
|
|
953
|
+
gl.uniformMatrix2fv(location, false, value);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Sets the value of a mat2 uniform variable.
|
|
958
|
+
* @param location - The location of the uniform variable.
|
|
959
|
+
* @param value - The array of mat2 values to set.
|
|
960
|
+
*/
|
|
961
|
+
uniformMatrix3fv(
|
|
962
|
+
location: WebGLUniformLocation | null,
|
|
963
|
+
value: Float32Array | number[],
|
|
964
|
+
) {
|
|
965
|
+
const { gl } = this;
|
|
966
|
+
gl.uniformMatrix3fv(location, false, value);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Sets the value of a mat4 uniform variable.
|
|
971
|
+
* @param location - The location of the uniform variable.
|
|
972
|
+
* @param value - The array of mat4 values to set.
|
|
973
|
+
*/
|
|
974
|
+
uniformMatrix4fv(
|
|
975
|
+
location: WebGLUniformLocation | null,
|
|
976
|
+
value: Float32Array | number[],
|
|
977
|
+
) {
|
|
978
|
+
const { gl } = this;
|
|
979
|
+
gl.uniformMatrix4fv(location, false, value);
|
|
727
980
|
}
|
|
728
981
|
|
|
729
982
|
/**
|
|
@@ -1031,12 +1284,21 @@ export function compareArrays<T>(a: T[], b: T[]): boolean {
|
|
|
1031
1284
|
if (a.length !== b.length) {
|
|
1032
1285
|
return false;
|
|
1033
1286
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1287
|
+
|
|
1288
|
+
let result = false;
|
|
1289
|
+
for (let i = 0; i < a.length; i++) {
|
|
1290
|
+
if (Array.isArray(a[i]) || a[i] instanceof Float32Array) {
|
|
1291
|
+
result = false;
|
|
1292
|
+
break;
|
|
1040
1293
|
}
|
|
1041
|
-
|
|
1294
|
+
|
|
1295
|
+
if (a[i] !== b[i]) {
|
|
1296
|
+
result = false;
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
result = true;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
return result;
|
|
1042
1304
|
}
|
|
@@ -121,7 +121,11 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
121
121
|
this.stage.requestRender();
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
const gl = createWebGLContext(
|
|
124
|
+
const gl = createWebGLContext(
|
|
125
|
+
canvas,
|
|
126
|
+
options.forceWebGL2,
|
|
127
|
+
options.contextSpy,
|
|
128
|
+
);
|
|
125
129
|
const glw = (this.glw = new WebGlContextWrapper(gl));
|
|
126
130
|
|
|
127
131
|
const color = getNormalizedRgbaComponents(clearColor);
|
|
@@ -619,12 +623,13 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
619
623
|
console.log('renderOps', this.renderOps.length);
|
|
620
624
|
}
|
|
621
625
|
|
|
622
|
-
this.renderOps.
|
|
626
|
+
for (let i = 0, length = this.renderOps.length; i < length; i++) {
|
|
627
|
+
const renderOp = this.renderOps[i] as WebGlCoreRenderOp;
|
|
623
628
|
if (doLog) {
|
|
624
629
|
console.log('Quads per operation', renderOp.numQuads);
|
|
625
630
|
}
|
|
626
631
|
renderOp.draw();
|
|
627
|
-
}
|
|
632
|
+
}
|
|
628
633
|
this.quadBufferUsage = this.curBufferIdx * arr.BYTES_PER_ELEMENT;
|
|
629
634
|
}
|
|
630
635
|
|
|
@@ -152,16 +152,6 @@ export abstract class WebGlCoreShader extends CoreShader {
|
|
|
152
152
|
}
|
|
153
153
|
this.program = program;
|
|
154
154
|
|
|
155
|
-
if (webGl2) {
|
|
156
|
-
const vao = glw.createVertexArray();
|
|
157
|
-
if (!vao) {
|
|
158
|
-
throw new Error();
|
|
159
|
-
}
|
|
160
|
-
this.vao = vao;
|
|
161
|
-
|
|
162
|
-
glw.bindVertexArray(this.vao);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
155
|
this.attributeLocations = {} as Record<string, number>;
|
|
166
156
|
this.attributeBuffers = {} as Record<string, number>;
|
|
167
157
|
this.attributeNames = [];
|
|
@@ -274,18 +264,23 @@ export abstract class WebGlCoreShader extends CoreShader {
|
|
|
274
264
|
const { width, height } = renderOp.framebufferDimensions || {};
|
|
275
265
|
// Force pixel ratio to 1.0 for render textures since they are always 1:1
|
|
276
266
|
// the final render texture will be rendered to the screen with the correct pixel ratio
|
|
277
|
-
this.
|
|
267
|
+
glw.uniform1f(this.getUniformLocation('u_pixelRatio'), 1.0);
|
|
278
268
|
|
|
279
269
|
// Set resolution to the framebuffer dimensions
|
|
280
|
-
|
|
281
|
-
'u_resolution',
|
|
282
|
-
|
|
270
|
+
glw.uniform2f(
|
|
271
|
+
this.getUniformLocation('u_resolution'),
|
|
272
|
+
width ?? 0,
|
|
273
|
+
height ?? 0,
|
|
283
274
|
);
|
|
284
275
|
} else {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
276
|
+
glw.uniform1f(
|
|
277
|
+
this.getUniformLocation('u_pixelRatio'),
|
|
278
|
+
renderOp.options.pixelRatio,
|
|
279
|
+
);
|
|
280
|
+
glw.uniform2f(
|
|
281
|
+
this.getUniformLocation('u_resolution'),
|
|
282
|
+
glw.canvas.width,
|
|
283
|
+
glw.canvas.height,
|
|
289
284
|
);
|
|
290
285
|
}
|
|
291
286
|
|
|
@@ -297,26 +292,25 @@ export abstract class WebGlCoreShader extends CoreShader {
|
|
|
297
292
|
if (!dimensions) {
|
|
298
293
|
dimensions = renderOp.dimensions;
|
|
299
294
|
}
|
|
300
|
-
|
|
295
|
+
glw.uniform2f(
|
|
296
|
+
this.getUniformLocation('u_dimensions'),
|
|
297
|
+
dimensions.width,
|
|
298
|
+
dimensions.height,
|
|
299
|
+
);
|
|
301
300
|
}
|
|
302
301
|
if (hasOwn(props, '$alpha')) {
|
|
303
302
|
let alpha = props.$alpha as number | null;
|
|
304
303
|
if (!alpha) {
|
|
305
304
|
alpha = renderOp.alpha;
|
|
306
305
|
}
|
|
307
|
-
this.
|
|
306
|
+
glw.uniform1f(this.getUniformLocation('u_alpha'), alpha);
|
|
308
307
|
}
|
|
309
308
|
this.bindProps(props);
|
|
310
309
|
}
|
|
311
310
|
}
|
|
312
311
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
this.glw.setUniform(
|
|
316
|
-
this.uniformTypes[name]!,
|
|
317
|
-
this.uniformLocations[name]!,
|
|
318
|
-
...(value as any),
|
|
319
|
-
);
|
|
312
|
+
getUniformLocation(name: string): WebGLUniformLocation | null {
|
|
313
|
+
return this.uniformLocations[name] || null;
|
|
320
314
|
}
|
|
321
315
|
|
|
322
316
|
bindBufferCollection(buffer: BufferCollection) {
|
|
@@ -346,7 +340,6 @@ export abstract class WebGlCoreShader extends CoreShader {
|
|
|
346
340
|
}
|
|
347
341
|
|
|
348
342
|
override attach(): void {
|
|
349
|
-
this.glw.useProgram(this.program);
|
|
350
343
|
this.glw.useProgram(this.program);
|
|
351
344
|
if (this.glw.isWebGl2() && this.vao) {
|
|
352
345
|
this.glw.bindVertexArray(this.vao);
|
|
@@ -57,7 +57,7 @@ export class DefaultShaderBatched extends WebGlCoreShader {
|
|
|
57
57
|
glw.bindTexture(t.ctxTexture);
|
|
58
58
|
});
|
|
59
59
|
const samplers = Array.from(Array(texture.length).keys());
|
|
60
|
-
this.
|
|
60
|
+
this.glw.uniform1iv(this.getUniformLocation('u_textures[0]'), samplers);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
static override shaderSources: ShaderProgramSources = {
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
type DimensionsShaderProp,
|
|
23
23
|
type AlphaShaderProp,
|
|
24
24
|
} from '../WebGlCoreShader.js';
|
|
25
|
-
import type
|
|
25
|
+
import { type UniformInfo } from '../internal/ShaderUtils.js';
|
|
26
26
|
import type { WebGlCoreCtxTexture } from '../WebGlCoreCtxTexture.js';
|
|
27
27
|
import {
|
|
28
28
|
ShaderEffect,
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
} from './effects/ShaderEffect.js';
|
|
34
34
|
import type { EffectMap } from '../../../CoreShaderManager.js';
|
|
35
35
|
import { assertTruthy } from '../../../../utils.js';
|
|
36
|
+
import type { UniformMethodMap } from '../../../lib/WebGlContextWrapper.js';
|
|
36
37
|
|
|
37
38
|
export interface DynamicShaderProps
|
|
38
39
|
extends DimensionsShaderProp,
|
|
@@ -74,6 +75,7 @@ const getResolvedEffect = (
|
|
|
74
75
|
const result: ShaderEffectValueMap = {
|
|
75
76
|
value: defaultPropValues[key] as ShaderEffectUniform['value'],
|
|
76
77
|
programValue: undefined,
|
|
78
|
+
method: uniform.method,
|
|
77
79
|
updateOnBind: uniform.updateOnBind || false,
|
|
78
80
|
hasValidator: uniform.validator !== undefined,
|
|
79
81
|
hasProgramValueUpdater: uniform.updateProgramValue !== undefined,
|
|
@@ -142,13 +144,82 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
142
144
|
glw.bindTexture(textures[0]!.ctxTexture);
|
|
143
145
|
}
|
|
144
146
|
|
|
147
|
+
bindUniformMethods(props: DynamicShaderProps): void {
|
|
148
|
+
const glw = this.glw;
|
|
149
|
+
const effects = props.effects;
|
|
150
|
+
const effectsL = effects!.length;
|
|
151
|
+
for (let i = 0; i < effectsL; i++) {
|
|
152
|
+
const uniformInfo = this.effects[i]!.uniformInfo;
|
|
153
|
+
const effect = effects![i]! as Record<string, any>;
|
|
154
|
+
const propKeys = Object.keys(effect.props);
|
|
155
|
+
const propsLength = propKeys.length;
|
|
156
|
+
for (let j = 0; j < propsLength; j++) {
|
|
157
|
+
const key = propKeys[j]!;
|
|
158
|
+
const method = effect.props[key].method as keyof UniformMethodMap;
|
|
159
|
+
const location = this.getUniformLocation(uniformInfo[key]!.name);
|
|
160
|
+
|
|
161
|
+
if (
|
|
162
|
+
method === 'uniform2fv' ||
|
|
163
|
+
method === 'uniform2iv' ||
|
|
164
|
+
//uniform === 'uniform3fv ' || <--- check why this isnt recognized
|
|
165
|
+
method === 'uniform3iv' ||
|
|
166
|
+
method === 'uniform4fv' ||
|
|
167
|
+
method === 'uniform4iv' ||
|
|
168
|
+
method === 'uniformMatrix2fv' ||
|
|
169
|
+
method === 'uniformMatrix3fv' ||
|
|
170
|
+
method === 'uniformMatrix4fv' ||
|
|
171
|
+
method === 'uniform1f' ||
|
|
172
|
+
method === 'uniform1fv' ||
|
|
173
|
+
method === 'uniform1i' ||
|
|
174
|
+
method === 'uniform1iv'
|
|
175
|
+
) {
|
|
176
|
+
effect.props[key].setUniformValue = function () {
|
|
177
|
+
glw[method](location, this.programValue);
|
|
178
|
+
};
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (method === 'uniform2f' || method === 'uniform2i') {
|
|
183
|
+
effect.props[key].setUniformValue = function () {
|
|
184
|
+
glw[method](location, this.programValue[0]!, this.programValue[1]!);
|
|
185
|
+
};
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (method === 'uniform3f' || method === 'uniform3i') {
|
|
190
|
+
effect.props[key].setUniformValue = function () {
|
|
191
|
+
glw[method](
|
|
192
|
+
location,
|
|
193
|
+
this.programValue[0]!,
|
|
194
|
+
this.programValue[1]!,
|
|
195
|
+
this.programValue[2]!,
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (method === 'uniform4f' || method === 'uniform4i') {
|
|
202
|
+
effect.props[key].setUniformValue = function () {
|
|
203
|
+
glw[method](
|
|
204
|
+
location,
|
|
205
|
+
this.programValue[0]!,
|
|
206
|
+
this.programValue[1]!,
|
|
207
|
+
this.programValue[2]!,
|
|
208
|
+
this.programValue[3]!,
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
145
217
|
protected override bindProps(props: Required<DynamicShaderProps>): void {
|
|
146
218
|
const effects = props.effects;
|
|
147
219
|
const effectsL = effects.length;
|
|
148
220
|
let i = 0;
|
|
149
221
|
for (; i < effectsL; i++) {
|
|
150
222
|
const effect = effects[i]! as Record<string, any>;
|
|
151
|
-
const uniformInfo = this.effects[i]!.uniformInfo;
|
|
152
223
|
const propKeys = Object.keys(effect.props);
|
|
153
224
|
const propsLength = propKeys.length;
|
|
154
225
|
let j = 0;
|
|
@@ -162,7 +233,8 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
162
233
|
]?.uniforms[key];
|
|
163
234
|
uniform?.updateProgramValue!(effect.props[key], props);
|
|
164
235
|
}
|
|
165
|
-
|
|
236
|
+
|
|
237
|
+
prop.setUniformValue();
|
|
166
238
|
}
|
|
167
239
|
}
|
|
168
240
|
}
|
|
@@ -80,7 +80,10 @@ export class RoundedRectangle extends WebGlCoreShader {
|
|
|
80
80
|
const radiusFactor =
|
|
81
81
|
Math.min(props.$dimensions.width, props.$dimensions.height) /
|
|
82
82
|
(2.0 * props.radius);
|
|
83
|
-
this.
|
|
83
|
+
this.glw.uniform1f(
|
|
84
|
+
this.getUniformLocation('u_radius'),
|
|
85
|
+
props.radius * Math.min(radiusFactor, 1),
|
|
86
|
+
);
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
override canBatchShaderProps(
|
|
@@ -89,18 +89,33 @@ export class SdfShader extends WebGlCoreShader {
|
|
|
89
89
|
const resolvedProps = SdfShader.resolveDefaults(props);
|
|
90
90
|
for (const key in resolvedProps) {
|
|
91
91
|
if (key === 'transform') {
|
|
92
|
-
this.
|
|
92
|
+
this.glw.uniformMatrix3fv(
|
|
93
|
+
this.getUniformLocation('u_transform'),
|
|
94
|
+
resolvedProps[key],
|
|
95
|
+
);
|
|
93
96
|
} else if (key === 'scrollY') {
|
|
94
|
-
this.
|
|
97
|
+
this.glw.uniform1f(
|
|
98
|
+
this.getUniformLocation('u_scrollY'),
|
|
99
|
+
resolvedProps[key],
|
|
100
|
+
);
|
|
95
101
|
} else if (key === 'color') {
|
|
96
102
|
const components = getNormalizedRgbaComponents(resolvedProps.color);
|
|
97
|
-
this.
|
|
103
|
+
this.glw.uniform4fv(this.getUniformLocation('u_color'), components);
|
|
98
104
|
} else if (key === 'size') {
|
|
99
|
-
this.
|
|
105
|
+
this.glw.uniform1f(
|
|
106
|
+
this.getUniformLocation('u_size'),
|
|
107
|
+
resolvedProps[key],
|
|
108
|
+
);
|
|
100
109
|
} else if (key === 'distanceRange') {
|
|
101
|
-
this.
|
|
110
|
+
this.glw.uniform1f(
|
|
111
|
+
this.getUniformLocation('u_distanceRange'),
|
|
112
|
+
resolvedProps[key],
|
|
113
|
+
);
|
|
102
114
|
} else if (key === 'debug') {
|
|
103
|
-
this.
|
|
115
|
+
this.glw.uniform1i(
|
|
116
|
+
this.getUniformLocation('u_debug'),
|
|
117
|
+
resolvedProps[key] ? 1 : 0,
|
|
118
|
+
);
|
|
104
119
|
}
|
|
105
120
|
}
|
|
106
121
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EffectMap } from '../../../../CoreShaderManager.js';
|
|
2
2
|
import type { ExtractProps } from '../../../../CoreTextureManager.js';
|
|
3
|
+
import type { WebGlContextWrapper } from '../../../../lib/WebGlContextWrapper.js';
|
|
3
4
|
import type {
|
|
4
5
|
AlphaShaderProp,
|
|
5
6
|
DimensionsShaderProp,
|
|
@@ -89,6 +90,8 @@ export interface ShaderEffectValueMap
|
|
|
89
90
|
AlphaShaderProp {
|
|
90
91
|
value: ShaderEffectUniform['value'];
|
|
91
92
|
programValue: number | Float32Array | undefined;
|
|
93
|
+
method: keyof UniformMethodMap;
|
|
94
|
+
setUniformValue?: () => void | null;
|
|
92
95
|
hasValidator: boolean;
|
|
93
96
|
hasProgramValueUpdater: boolean;
|
|
94
97
|
updateOnBind: boolean;
|