@kitware/vtk.js 26.5.5 → 26.5.6

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.
@@ -725,6 +725,33 @@ function vtkOpenGLTexture(publicAPI, model) {
725
725
  } //----------------------------------------------------------------------------
726
726
 
727
727
 
728
+ function useTexStorage(dataType) {
729
+ if (model._openGLRenderWindow) {
730
+ if (model.resizable) {
731
+ // Cannot use texStorage if the texture is supposed to be resizable.
732
+ return false;
733
+ }
734
+
735
+ if (model._openGLRenderWindow.getWebgl2()) {
736
+ var webGLInfo = model._openGLRenderWindow.getGLInformations();
737
+
738
+ if (webGLInfo.RENDERER.value.match(/WebKit/gi) && navigator.platform.match(/Mac/gi) && model.oglNorm16Ext && (dataType === VtkDataTypes.UNSIGNED_SHORT || dataType === VtkDataTypes.SHORT)) {
739
+ // Cannot use texStorage with EXT_texture_norm16 textures on Mac M1 GPU.
740
+ // No errors reported but the texture is unusable.
741
+ return false;
742
+ } // Use texStorage for WebGL2
743
+
744
+
745
+ return true;
746
+ }
747
+
748
+ return false;
749
+ }
750
+
751
+ return false;
752
+ } //----------------------------------------------------------------------------
753
+
754
+
728
755
  publicAPI.create2DFromRaw = function (width, height, numComps, dataType, data) {
729
756
  var flip = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
730
757
  // Now determine the texture parameters using the arguments.
@@ -756,7 +783,7 @@ function vtkOpenGLTexture(publicAPI, model) {
756
783
  model.context.pixelStorei(model.context.UNPACK_FLIP_Y_WEBGL, flip);
757
784
  model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
758
785
 
759
- if (model._openGLRenderWindow.getWebgl2() && !model.resizable) {
786
+ if (useTexStorage(dataType)) {
760
787
  model.context.texStorage2D(model.target, 1, model.internalFormat, model.width, model.height);
761
788
 
762
789
  if (scaledData[0] != null) {
@@ -830,7 +857,7 @@ function vtkOpenGLTexture(publicAPI, model) {
830
857
 
831
858
  model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
832
859
 
833
- if (model._openGLRenderWindow.getWebgl2() && !model.resizable) {
860
+ if (useTexStorage(dataType)) {
834
861
  model.context.texStorage2D(model.target, 6, model.internalFormat, model.width, model.height);
835
862
  } // We get the 6 images
836
863
 
@@ -907,7 +934,7 @@ function vtkOpenGLTexture(publicAPI, model) {
907
934
 
908
935
  model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
909
936
 
910
- if (model._openGLRenderWindow.getWebgl2() && !model.resizable) {
937
+ if (useTexStorage(dataType)) {
911
938
  model.context.texStorage2D(model.target, 1, model.internalFormat, model.width, model.height);
912
939
 
913
940
  if (data != null) {
@@ -939,8 +966,6 @@ function vtkOpenGLTexture(publicAPI, model) {
939
966
 
940
967
  model.target = model.context.TEXTURE_2D;
941
968
  model.components = 4;
942
- model.width = image.width;
943
- model.height = image.height;
944
969
  model.depth = 1;
945
970
  model.numberOfDimensions = 2;
946
971
 
@@ -952,17 +977,19 @@ function vtkOpenGLTexture(publicAPI, model) {
952
977
 
953
978
  model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1); // Scale up the texture to the next highest power of two dimensions (if needed) and flip y.
954
979
 
955
- var needNearestPowerOfTwo = !isPowerOfTwo(image.width) || !isPowerOfTwo(image.height);
980
+ var needNearestPowerOfTwo = !model._openGLRenderWindow.getWebgl2() && (!isPowerOfTwo(image.width) || !isPowerOfTwo(image.height));
956
981
  var canvas = document.createElement('canvas');
957
982
  canvas.width = needNearestPowerOfTwo ? nearestPowerOfTwo(image.width) : image.width;
958
983
  canvas.height = needNearestPowerOfTwo ? nearestPowerOfTwo(image.height) : image.height;
984
+ model.width = canvas.width;
985
+ model.height = canvas.height;
959
986
  var ctx = canvas.getContext('2d');
960
987
  ctx.translate(0, canvas.height);
961
988
  ctx.scale(1, -1);
962
989
  ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
963
990
  var safeImage = canvas;
964
991
 
965
- if (model._openGLRenderWindow.getWebgl2() && !model.resizable) {
992
+ if (useTexStorage(VtkDataTypes.UNSIGNED_CHAR)) {
966
993
  model.context.texStorage2D(model.target, 1, model.internalFormat, model.width, model.height);
967
994
 
968
995
  if (safeImage != null) {
@@ -1097,7 +1124,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1097
1124
  // model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
1098
1125
  // openGLDataType
1099
1126
 
1100
- if (model._openGLRenderWindow.getWebgl2()) {
1127
+ if (useTexStorage(dataType)) {
1101
1128
  model.context.texStorage3D(model.target, 1, model.internalFormat, model.width, model.height, model.depth);
1102
1129
 
1103
1130
  if (scaledData[0] != null) {
@@ -1342,7 +1369,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1342
1369
 
1343
1370
  model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
1344
1371
 
1345
- if (model._openGLRenderWindow.getWebgl2() && !model.resizable) {
1372
+ if (useTexStorage(dataTypeToUse)) {
1346
1373
  model.context.texStorage2D(model.target, 1, model.internalFormat, model.width, model.height);
1347
1374
 
1348
1375
  if (newArray != null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "26.5.5",
3
+ "version": "26.5.6",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",