@kitware/vtk.js 24.0.3 → 24.1.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.
@@ -331,9 +331,10 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
331
331
  if (cabo.getElementCount()) {
332
332
  // are we drawing edges
333
333
  model.drawingEdges = drawSurfaceWithEdges && (i === model.primTypes.TrisEdges || i === model.primTypes.TriStripsEdges);
334
- publicAPI.updateShaders(model.primitives[i], ren, actor);
334
+ model.lastBoundBO = model.primitives[i];
335
+ model.primitives[i].updateShaders(ren, actor, publicAPI);
335
336
  var program = model.primitives[i].getProgram();
336
- var mode = publicAPI.getOpenGLMode(representation, i);
337
+ var mode = model.primitives[i].getOpenGLMode(representation);
337
338
  var normalMatrixUsed = program.isUniformUsed('normalMatrix');
338
339
  var mcvcMatrixUsed = program.isUniformUsed('MCVCMatrix');
339
340
 
@@ -413,6 +414,14 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
413
414
  return superClass.getNeedToRebuildBufferObjects(ren, actor);
414
415
  };
415
416
 
417
+ publicAPI.getNeedToRebuildShaders = function (cellBO, ren, actor) {
418
+ if (superClass.getNeedToRebuildShaders(cellBO, ren, actor) || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime()) {
419
+ return true;
420
+ }
421
+
422
+ return false;
423
+ };
424
+
416
425
  publicAPI.buildBufferObjects = function (ren, actor) {
417
426
  if (model.hardwareSupport) {
418
427
  // update the buffer objects if needed
@@ -2,7 +2,18 @@ import macro from '../../macros.js';
2
2
  import vtkCellArrayBufferObject from './CellArrayBufferObject.js';
3
3
  import vtkShaderProgram from './ShaderProgram.js';
4
4
  import vtkVertexArrayObject from './VertexArrayObject.js';
5
+ import { Representation } from '../Core/Property/Constants.js';
5
6
 
7
+ var primTypes = {
8
+ Start: 0,
9
+ Points: 0,
10
+ Lines: 1,
11
+ Tris: 2,
12
+ TriStrips: 3,
13
+ TrisEdges: 4,
14
+ TriStripsEdges: 5,
15
+ End: 6
16
+ }; // ----------------------------------------------------------------------------
6
17
  // vtkOpenGLHelper methods
7
18
  // ----------------------------------------------------------------------------
8
19
 
@@ -11,7 +22,8 @@ function vtkOpenGLHelper(publicAPI, model) {
11
22
  model.classHierarchy.push('vtkOpenGLHelper');
12
23
 
13
24
  publicAPI.setOpenGLRenderWindow = function (win) {
14
- model.program.setContext(win.getContext());
25
+ model.context = win.getContext();
26
+ model.program.setContext(model.context);
15
27
  model.VAO.setOpenGLRenderWindow(win);
16
28
  model.CABO.setOpenGLRenderWindow(win);
17
29
  };
@@ -21,12 +33,141 @@ function vtkOpenGLHelper(publicAPI, model) {
21
33
  model.CABO.releaseGraphicsResources();
22
34
  model.CABO.setElementCount(0);
23
35
  };
36
+
37
+ publicAPI.drawArrays = function (ren, actor, rep, oglMapper) {
38
+ // Are there any entries
39
+ if (model.CABO.getElementCount()) {
40
+ // are we drawing edges
41
+ var mode = publicAPI.getOpenGLMode(rep);
42
+ var wideLines = publicAPI.haveWideLines(ren, actor);
43
+ var gl = model.context;
44
+ var drawingLines = mode === gl.LINES;
45
+
46
+ if (drawingLines && wideLines) {
47
+ publicAPI.updateShaders(ren, actor, oglMapper);
48
+ gl.drawArraysInstanced(mode, 0, model.CABO.getElementCount(), 2 * Math.ceil(actor.getProperty().getLineWidth()));
49
+ } else {
50
+ gl.lineWidth(actor.getProperty().getLineWidth());
51
+ publicAPI.updateShaders(ren, actor, oglMapper);
52
+ gl.drawArrays(mode, 0, model.CABO.getElementCount()); // reset the line width
53
+
54
+ gl.lineWidth(1);
55
+ }
56
+
57
+ var stride = (mode === gl.POINTS ? 1 : 0) || (mode === gl.LINES ? 2 : 3);
58
+ return model.CABO.getElementCount() / stride;
59
+ }
60
+
61
+ return 0;
62
+ };
63
+
64
+ publicAPI.getOpenGLMode = function (rep) {
65
+ var type = model.primitiveType;
66
+
67
+ if (rep === Representation.POINTS || type === primTypes.Points) {
68
+ return model.context.POINTS;
69
+ }
70
+
71
+ if (rep === Representation.WIREFRAME || type === primTypes.Lines || type === primTypes.TrisEdges || type === primTypes.TriStripsEdges) {
72
+ return model.context.LINES;
73
+ }
74
+
75
+ return model.context.TRIANGLES;
76
+ };
77
+
78
+ publicAPI.haveWideLines = function (ren, actor) {
79
+ if (actor.getProperty().getLineWidth() > 1.0) {
80
+ // we have wide lines, but the OpenGL implementation may
81
+ // actually support them, check the range to see if we
82
+ // really need have to implement our own wide lines
83
+ if (model.CABO.getOpenGLRenderWindow()) {
84
+ if (model.CABO.getOpenGLRenderWindow().getHardwareMaximumLineWidth() >= actor.getProperty().getLineWidth()) {
85
+ return false;
86
+ }
87
+ }
88
+
89
+ return true;
90
+ }
91
+
92
+ return false;
93
+ };
94
+
95
+ publicAPI.getNeedToRebuildShaders = function (ren, actor, oglMapper) {
96
+ // has something changed that would require us to recreate the shader?
97
+ // candidates are
98
+ // property modified (representation interpolation and lighting)
99
+ // input modified
100
+ // mapper modified (lighting complexity)
101
+ if (oglMapper.getNeedToRebuildShaders(publicAPI, ren, actor) || publicAPI.getProgram() === 0 || publicAPI.getShaderSourceTime().getMTime() < oglMapper.getMTime() || publicAPI.getShaderSourceTime().getMTime() < actor.getMTime()) {
102
+ return true;
103
+ }
104
+
105
+ return false;
106
+ };
107
+
108
+ publicAPI.updateShaders = function (ren, actor, oglMapper) {
109
+ // has something changed that would require us to recreate the shader?
110
+ if (publicAPI.getNeedToRebuildShaders(ren, actor, oglMapper)) {
111
+ var shaders = {
112
+ Vertex: null,
113
+ Fragment: null,
114
+ Geometry: null
115
+ };
116
+ oglMapper.buildShaders(shaders, ren, actor); // compile and bind the program if needed
117
+
118
+ var newShader = model.CABO.getOpenGLRenderWindow().getShaderCache().readyShaderProgramArray(shaders.Vertex, shaders.Fragment, shaders.Geometry); // if the shader changed reinitialize the VAO
119
+
120
+ if (newShader !== publicAPI.getProgram()) {
121
+ publicAPI.setProgram(newShader); // reset the VAO as the shader has changed
122
+
123
+ publicAPI.getVAO().releaseGraphicsResources();
124
+ }
125
+
126
+ publicAPI.getShaderSourceTime().modified();
127
+ } else {
128
+ model.CABO.getOpenGLRenderWindow().getShaderCache().readyShaderProgram(publicAPI.getProgram());
129
+ }
130
+
131
+ publicAPI.getVAO().bind();
132
+ oglMapper.setMapperShaderParameters(publicAPI, ren, actor);
133
+ oglMapper.setPropertyShaderParameters(publicAPI, ren, actor);
134
+ oglMapper.setCameraShaderParameters(publicAPI, ren, actor);
135
+ oglMapper.setLightingShaderParameters(publicAPI, ren, actor);
136
+ oglMapper.invokeShaderCallbacks(publicAPI, ren, actor);
137
+ };
138
+
139
+ publicAPI.setMapperShaderParameters = function (ren, actor, size) {
140
+ if (publicAPI.haveWideLines(ren, actor)) {
141
+ publicAPI.getProgram().setUniform2f('viewportSize', size.usize, size.vsize);
142
+ var lineWidth = parseFloat(actor.getProperty().getLineWidth());
143
+ var halfLineWidth = lineWidth / 2.0;
144
+ publicAPI.getProgram().setUniformf('lineWidthStepSize', lineWidth / Math.ceil(lineWidth));
145
+ publicAPI.getProgram().setUniformf('halfLineWidth', halfLineWidth);
146
+ }
147
+ };
148
+
149
+ publicAPI.replaceShaderPositionVC = function (shaders, ren, actor) {
150
+ var VSSource = shaders.Vertex; // for lines, make sure we add the width code
151
+
152
+ if (publicAPI.getOpenGLMode(actor.getProperty().getRepresentation()) === model.context.LINES && publicAPI.haveWideLines(ren, actor)) {
153
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Dec', ['//VTK::PositionVC::Dec', 'uniform vec2 viewportSize;', 'uniform float lineWidthStepSize;', 'uniform float halfLineWidth;']).result;
154
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Impl', ['//VTK::PositionVC::Impl', ' if (halfLineWidth > 0.0)', ' {', ' float offset = float(gl_InstanceID / 2) * lineWidthStepSize - halfLineWidth;', ' vec4 tmpPos = gl_Position;', ' vec3 tmpPos2 = tmpPos.xyz / tmpPos.w;', ' tmpPos2.x = tmpPos2.x + 2.0 * mod(float(gl_InstanceID), 2.0) * offset / viewportSize[0];', ' tmpPos2.y = tmpPos2.y + 2.0 * mod(float(gl_InstanceID + 1), 2.0) * offset / viewportSize[1];', ' gl_Position = vec4(tmpPos2.xyz * tmpPos.w, tmpPos.w);', ' }']).result;
155
+ } // for points make sure to add in the point size
156
+
157
+
158
+ if (actor.getProperty().getRepresentation() === Representation.POINTS || model.primitiveType === primTypes.Points) {
159
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Impl', ['//VTK::PositionVC::Impl', " gl_PointSize = ".concat(actor.getProperty().getPointSize(), ".0;")], false).result;
160
+ }
161
+
162
+ shaders.Vertex = VSSource;
163
+ };
24
164
  } // ----------------------------------------------------------------------------
25
165
  // Object factory
26
166
  // ----------------------------------------------------------------------------
27
167
 
28
168
 
29
169
  var DEFAULT_VALUES = {
170
+ context: null,
30
171
  program: null,
31
172
  shaderSourceTime: null,
32
173
  VAO: null,
@@ -56,7 +197,8 @@ var newInstance = macro.newInstance(extend); // --------------------------------
56
197
 
57
198
  var vtkHelper = {
58
199
  newInstance: newInstance,
59
- extend: extend
200
+ extend: extend,
201
+ primTypes: primTypes
60
202
  };
61
203
 
62
- export { vtkHelper as default, extend, newInstance };
204
+ export { vtkHelper as default, extend, newInstance, primTypes };
@@ -15,16 +15,7 @@ import { registerOverride } from './ViewNodeFactory.js';
15
15
 
16
16
  /* eslint-disable no-lonely-if */
17
17
 
18
- var primTypes = {
19
- Start: 0,
20
- Points: 0,
21
- Lines: 1,
22
- Tris: 2,
23
- TriStrips: 3,
24
- TrisEdges: 4,
25
- TriStripsEdges: 5,
26
- End: 6
27
- };
18
+ var primTypes = vtkHelper.primTypes;
28
19
  var Representation = vtkProperty.Representation,
29
20
  Shading = vtkProperty.Shading;
30
21
  var ScalarMode = vtkMapper.ScalarMode;
@@ -326,7 +317,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
326
317
  FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Normal::Dec', ['uniform mat3 normalMatrix;', 'uniform samplerBuffer textureN;']).result;
327
318
  FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Normal::Impl', ['vec3 normalVCVSOutput = normalize(normalMatrix *', ' texelFetchBuffer(textureN, gl_PrimitiveID + PrimitiveIDOffset).xyz);', ' if (gl_FrontFacing == false) { normalVCVSOutput = -normalVCVSOutput; }']).result;
328
319
  } else {
329
- if (publicAPI.getOpenGLMode(actor.getProperty().getRepresentation(), model.lastBoundBO.getPrimitiveType()) === model.context.LINES) {
320
+ if (model.lastBoundBO.getOpenGLMode(actor.getProperty().getRepresentation()) === model.context.LINES) {
330
321
  // generate a normal for lines, it will be perpendicular to the line
331
322
  // and maximally aligned with the camera view direction
332
323
  // no clue if this is the best way to do this.
@@ -361,14 +352,11 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
361
352
  };
362
353
 
363
354
  publicAPI.replaceShaderPositionVC = function (shaders, ren, actor) {
355
+ // replace common shader code
356
+ model.lastBoundBO.replaceShaderPositionVC(shaders, ren, actor);
364
357
  var VSSource = shaders.Vertex;
365
358
  var GSSource = shaders.Geometry;
366
- var FSSource = shaders.Fragment; // for points make sure to add in the point size
367
-
368
- if (actor.getProperty().getRepresentation() === Representation.POINTS || model.lastBoundBO.getPrimitiveType() === primTypes.Points) {
369
- VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Impl', ['//VTK::PositionVC::Impl', " gl_PointSize = ".concat(actor.getProperty().getPointSize(), ".0;")], false).result;
370
- } // do we need the vertex in the shader in View Coordinates
371
-
359
+ var FSSource = shaders.Fragment; // do we need the vertex in the shader in View Coordinates
372
360
 
373
361
  var lastLightComplexity = model.lastBoundBO.getReferenceByName('lastLightComplexity');
374
362
 
@@ -556,7 +544,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
556
544
  var cellNormals = poly.getCellData().getNormals();
557
545
  var flat = actor.getProperty().getInterpolation() === Shading.FLAT;
558
546
  var representation = actor.getProperty().getRepresentation();
559
- var mode = publicAPI.getOpenGLMode(representation, primType); // 1) all surfaces need lighting
547
+ var mode = cellBO.getOpenGLMode(representation, primType); // 1) all surfaces need lighting
560
548
 
561
549
  if (mode === model.context.TRIANGLES) {
562
550
  needLighting = true; // 2) all cell normals without point normals need lighting
@@ -628,7 +616,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
628
616
  // light complexity changed
629
617
 
630
618
 
631
- if (model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getProgram() === 0 || cellBO.getShaderSourceTime().getMTime() < publicAPI.getMTime() || cellBO.getShaderSourceTime().getMTime() < actor.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime() || needRebuild) {
619
+ if (model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime() || needRebuild) {
632
620
  model.lastHaveSeenDepthRequest = model.haveSeenDepthRequest;
633
621
  return true;
634
622
  }
@@ -636,36 +624,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
636
624
  return false;
637
625
  };
638
626
 
639
- publicAPI.updateShaders = function (cellBO, ren, actor) {
640
- model.lastBoundBO = cellBO; // has something changed that would require us to recreate the shader?
641
-
642
- if (publicAPI.getNeedToRebuildShaders(cellBO, ren, actor)) {
643
- var shaders = {
644
- Vertex: null,
645
- Fragment: null,
646
- Geometry: null
647
- };
648
- publicAPI.buildShaders(shaders, ren, actor); // compile and bind the program if needed
649
-
650
- var newShader = model._openGLRenderWindow.getShaderCache().readyShaderProgramArray(shaders.Vertex, shaders.Fragment, shaders.Geometry); // if the shader changed reinitialize the VAO
651
-
652
-
653
- if (newShader !== cellBO.getProgram()) {
654
- cellBO.setProgram(newShader); // reset the VAO as the shader has changed
655
-
656
- cellBO.getVAO().releaseGraphicsResources();
657
- }
658
-
659
- cellBO.getShaderSourceTime().modified();
660
- } else {
661
- model._openGLRenderWindow.getShaderCache().readyShaderProgram(cellBO.getProgram());
662
- }
663
-
664
- cellBO.getVAO().bind();
665
- publicAPI.setMapperShaderParameters(cellBO, ren, actor);
666
- publicAPI.setPropertyShaderParameters(cellBO, ren, actor);
667
- publicAPI.setCameraShaderParameters(cellBO, ren, actor);
668
- publicAPI.setLightingShaderParameters(cellBO, ren, actor);
627
+ publicAPI.invokeShaderCallbacks = function (cellBO, ren, actor) {
669
628
  var listCallbacks = model.renderable.getViewSpecificProperties().ShadersCallbacks;
670
629
 
671
630
  if (listCallbacks) {
@@ -783,8 +742,10 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
783
742
  if (cellBO.getProgram().isUniformUsed('cfactor')) {
784
743
  cellBO.getProgram().setUniformf('cfactor', cp.factor);
785
744
  }
786
- }
745
+ } // handle wide lines
746
+
787
747
 
748
+ cellBO.setMapperShaderParameters(ren, actor, model.openGLRenderer.getTiledSizeAndOrigin());
788
749
  var selector = model.openGLRenderer.getSelector();
789
750
  cellBO.getProgram().setUniform3fArray('mapperIndex', selector ? selector.getPropColorValue() : [0.0, 0.0, 0.0]);
790
751
  cellBO.getProgram().setUniformi('picking', selector ? selector.getCurrentPass() + 1 : 0);
@@ -997,9 +958,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
997
958
 
998
959
  publicAPI.renderPieceDraw = function (ren, actor) {
999
960
  var representation = actor.getProperty().getRepresentation();
1000
- var gl = model.context;
1001
- var drawSurfaceWithEdges = actor.getProperty().getEdgeVisibility() && representation === Representation.SURFACE;
1002
- gl.lineWidth(actor.getProperty().getLineWidth()); // for every primitive type
961
+ var drawSurfaceWithEdges = actor.getProperty().getEdgeVisibility() && representation === Representation.SURFACE; // for every primitive type
1003
962
 
1004
963
  for (var i = primTypes.Start; i < primTypes.End; i++) {
1005
964
  // if there are entries
@@ -1008,32 +967,13 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
1008
967
  if (cabo.getElementCount()) {
1009
968
  // are we drawing edges
1010
969
  model.drawingEdges = drawSurfaceWithEdges && (i === primTypes.TrisEdges || i === primTypes.TriStripsEdges);
1011
- var mode = publicAPI.getOpenGLMode(representation, i);
1012
970
 
1013
971
  if (!model.drawingEdges || !model.renderDepth) {
1014
- publicAPI.updateShaders(model.primitives[i], ren, actor);
1015
- gl.drawArrays(mode, 0, cabo.getElementCount());
972
+ model.lastBoundBO = model.primitives[i];
973
+ model.primitiveIDOffset += model.primitives[i].drawArrays(ren, actor, representation, publicAPI);
1016
974
  }
1017
-
1018
- var stride = (mode === gl.POINTS ? 1 : 0) || (mode === gl.LINES ? 2 : 3);
1019
- model.primitiveIDOffset += cabo.getElementCount() / stride;
1020
975
  }
1021
- } // reset the line width
1022
-
1023
-
1024
- gl.lineWidth(1);
1025
- };
1026
-
1027
- publicAPI.getOpenGLMode = function (rep, type) {
1028
- if (rep === Representation.POINTS || type === primTypes.Points) {
1029
- return model.context.POINTS;
1030
976
  }
1031
-
1032
- if (rep === Representation.WIREFRAME || type === primTypes.Lines || type === primTypes.TrisEdges || type === primTypes.TriStripsEdges) {
1033
- return model.context.LINES;
1034
- }
1035
-
1036
- return model.context.TRIANGLES;
1037
977
  };
1038
978
 
1039
979
  publicAPI.renderPieceFinish = function (ren, actor) {
@@ -1299,10 +1239,9 @@ var newInstance = newInstance$1(extend, 'vtkOpenGLPolyDataMapper'); // ---------
1299
1239
 
1300
1240
  var vtkOpenGLPolyDataMapper$1 = {
1301
1241
  newInstance: newInstance,
1302
- extend: extend,
1303
- primTypes: primTypes
1242
+ extend: extend
1304
1243
  }; // Register ourself to OpenGL backend if imported
1305
1244
 
1306
1245
  registerOverride('vtkMapper', newInstance);
1307
1246
 
1308
- export { vtkOpenGLPolyDataMapper$1 as default, extend, newInstance, primTypes };
1247
+ export { vtkOpenGLPolyDataMapper$1 as default, extend, newInstance };
@@ -2,7 +2,6 @@ import { mat4 } from 'gl-matrix';
2
2
  import { newInstance as newInstance$1, setGet, obj, vtkErrorMacro as vtkErrorMacro$1 } from '../../macros.js';
3
3
  import vtkHelper from './Helper.js';
4
4
  import vtkMapper2D from '../Core/Mapper2D.js';
5
- import vtkOpenGLPolyDataMapper from './PolyDataMapper.js';
6
5
  import vtkPoints from '../../Common/Core/Points.js';
7
6
  import { v as vtkPolyData2DFS } from './glsl/vtkPolyData2DFS.glsl.js';
8
7
  import { v as vtkPolyData2DVS } from './glsl/vtkPolyData2DVS.glsl.js';
@@ -10,12 +9,11 @@ import vtkReplacementShaderMapper from './ReplacementShaderMapper.js';
10
9
  import vtkShaderProgram from './ShaderProgram.js';
11
10
  import vtkViewNode from '../SceneGraph/ViewNode.js';
12
11
  import { K as round } from '../../Common/Core/Math/index.js';
13
- import { Representation } from '../Core/Property/Constants.js';
14
12
  import { DisplayLocation } from '../Core/Property2D/Constants.js';
15
13
  import { registerOverride } from './ViewNodeFactory.js';
16
14
 
17
15
  // import { mat3, mat4, vec3 } from 'gl-matrix';
18
- var primTypes = vtkOpenGLPolyDataMapper.primTypes;
16
+ var primTypes = vtkHelper.primTypes;
19
17
  var ScalarMode = vtkMapper2D.ScalarMode;
20
18
  var vtkErrorMacro = vtkErrorMacro$1;
21
19
  var StartEvent = {
@@ -146,7 +144,7 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
146
144
  // property modified (representation interpolation and lighting)
147
145
  // input modified
148
146
  // light complexity changed
149
- if (cellBO.getProgram() === 0 || cellBO.getShaderSourceTime().getMTime() < publicAPI.getMTime() || cellBO.getShaderSourceTime().getMTime() < actor.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime()) {
147
+ if (cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime()) {
150
148
  return true;
151
149
  }
152
150
 
@@ -172,18 +170,6 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
172
170
  return false;
173
171
  };
174
172
 
175
- publicAPI.getOpenGLMode = function (rep, type) {
176
- if (rep === Representation.POINTS || type === primTypes.Points) {
177
- return model.context.POINTS;
178
- }
179
-
180
- if (rep === Representation.WIREFRAME || type === primTypes.Lines || type === primTypes.TrisEdges || type === primTypes.TriStripsEdges) {
181
- return model.context.LINES;
182
- }
183
-
184
- return model.context.TRIANGLES;
185
- };
186
-
187
173
  publicAPI.buildBufferObjects = function (ren, actor) {
188
174
  var poly = model.currentInput;
189
175
 
@@ -252,9 +238,7 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
252
238
 
253
239
  publicAPI.renderPieceDraw = function (ren, actor) {
254
240
  var representation = actor.getProperty().getRepresentation();
255
- var drawSurfaceWithEdges = false;
256
241
  var gl = model.context;
257
- gl.lineWidth(actor.getProperty().getLineWidth());
258
242
  gl.depthMask(true); // for every primitive type
259
243
 
260
244
  for (var i = primTypes.Start; i < primTypes.End; i++) {
@@ -262,27 +246,15 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
262
246
  var cabo = model.primitives[i].getCABO();
263
247
 
264
248
  if (cabo.getElementCount()) {
265
- // are we drawing edges
266
- model.drawingEdges = drawSurfaceWithEdges ;
267
- var mode = publicAPI.getOpenGLMode(representation, i);
268
-
269
- if (!model.drawingEdges || !model.renderDepth) {
270
- publicAPI.updateShaders(model.primitives[i], ren, actor);
271
- gl.drawArrays(mode, 0, cabo.getElementCount());
272
- }
273
-
274
- var stride = (mode === gl.POINTS ? 1 : 0) || (mode === gl.LINES ? 2 : 3);
275
- model.primitiveIDOffset += cabo.getElementCount() / stride;
249
+ model.lastBoundBO = model.primitives[i];
250
+ model.primitiveIDOffset += model.primitives[i].drawArrays(ren, actor, representation, publicAPI);
276
251
  }
277
- } // reset the line width
278
-
279
-
280
- gl.lineWidth(1);
252
+ }
281
253
  };
282
254
 
283
255
  publicAPI.renderPieceFinish = function (ren, actor) {
284
- if (model.LastBoundBO) {
285
- model.LastBoundBO.getVAO().release();
256
+ if (model.lastBoundBO) {
257
+ model.lastBoundBO.getVAO().release();
286
258
  }
287
259
  };
288
260
 
@@ -402,48 +374,11 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
402
374
  };
403
375
 
404
376
  publicAPI.replaceShaderPositionVC = function (shaders, ren, actor) {
405
- var VSSource = shaders.Vertex;
406
- var GSSource = shaders.Geometry;
407
- var FSSource = shaders.Fragment; // for points make sure to add in the point size
408
-
409
- if (actor.getProperty().getRepresentation() === Representation.POINTS || model.lastBoundBO.getPrimitiveType() === primTypes.Points) {
410
- VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Impl', ['//VTK::PositionVC::Impl', " gl_PointSize = ".concat(actor.getProperty().getPointSize(), ".0;")], false).result;
411
- }
412
-
413
- shaders.Vertex = VSSource;
414
- shaders.Geometry = GSSource;
415
- shaders.Fragment = FSSource;
377
+ // replace common shader code
378
+ model.lastBoundBO.replaceShaderPositionVC(shaders, ren, actor);
416
379
  };
417
380
 
418
- publicAPI.updateShaders = function (cellBO, ren, actor) {
419
- model.lastBoundBO = cellBO; // has something changed that would require us to recreate the shader?
420
-
421
- if (publicAPI.getNeedToRebuildShaders(cellBO, ren, actor)) {
422
- var shaders = {
423
- Vertex: null,
424
- Fragment: null,
425
- Geometry: null
426
- };
427
- publicAPI.buildShaders(shaders, ren, actor); // compile and bind the program if needed
428
-
429
- var newShader = model._openGLRenderWindow.getShaderCache().readyShaderProgramArray(shaders.Vertex, shaders.Fragment, shaders.Geometry); // if the shader changed reinitialize the VAO
430
-
431
-
432
- if (newShader !== cellBO.getProgram()) {
433
- cellBO.setProgram(newShader); // reset the VAO as the shader has changed
434
-
435
- cellBO.getVAO().releaseGraphicsResources();
436
- }
437
-
438
- cellBO.getShaderSourceTime().modified();
439
- } else {
440
- model._openGLRenderWindow.getShaderCache().readyShaderProgram(cellBO.getProgram());
441
- }
442
-
443
- cellBO.getVAO().bind();
444
- publicAPI.setMapperShaderParameters(cellBO, ren, actor);
445
- publicAPI.setPropertyShaderParameters(cellBO, ren, actor);
446
- publicAPI.setCameraShaderParameters(cellBO, ren, actor);
381
+ publicAPI.invokeShaderCallbacks = function (cellBO, ren, actor) {
447
382
  var listCallbacks = model.renderable.getViewSpecificProperties().ShadersCallbacks;
448
383
 
449
384
  if (listCallbacks) {
@@ -501,15 +436,7 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
501
436
  } // handle wide lines
502
437
 
503
438
 
504
- if (publicAPI.haveWideLines(ren, actor)) {
505
- var gl = model.context;
506
- var vp = gl.getParameter(gl.VIEWPORT);
507
- var lineWidth = [1, 1];
508
- lineWidth[0] = 2.0 * actor.getProperty().getLineWidth() / vp[2];
509
- lineWidth[1] = 2.0 * actor.getProperty().getLineWidth() / vp[3];
510
- cellBO.getProgram().setUniform2f('lineWidthNVC', lineWidth);
511
- }
512
-
439
+ cellBO.setMapperShaderParameters(ren, actor, model.openGLRenderer.getTiledSizeAndOrigin());
513
440
  var selector = model.openGLRenderer.getSelector();
514
441
  cellBO.getProgram().setUniform3fArray('mapperIndex', selector ? selector.getPropColorValue() : [0.0, 0.0, 0.0]);
515
442
  cellBO.getProgram().setUniformi('picking', selector ? selector.getCurrentPass() + 1 : 0);
@@ -529,6 +456,9 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
529
456
  }
530
457
  };
531
458
 
459
+ publicAPI.setLightingShaderParameters = function (cellBO, ren, actor) {// no-op
460
+ };
461
+
532
462
  function safeMatrixMultiply(matrixArray, matrixType, tmpMat) {
533
463
  matrixType.identity(tmpMat);
534
464
  return matrixArray.reduce(function (res, matrix, index) {
@@ -598,20 +528,6 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
598
528
  mat4.transpose(tmpMat4, tmpMat4);
599
529
  program.setUniformMatrix('WCVCMatrix', safeMatrixMultiply([tmpMat4, inverseShiftScaleMatrix], mat4, model.tmpMat4));
600
530
  };
601
-
602
- publicAPI.haveWideLines = function (ren, actor) {
603
- if (model.lastBoundBO === model.lines && actor.getProperty().getLineWidth() > 1.0) {
604
- // we have wide lines, but the OpenGL implementation may
605
- // actually support them, check the range to see if we
606
- // really need have to implement our own wide lines
607
- // vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(ren->GetVTKWindow());
608
- // return !(
609
- // renWin && renWin->GetMaximumHardwareLineWidth() >= actor->GetProperty()->GetLineWidth());
610
- return true;
611
- }
612
-
613
- return false;
614
- };
615
531
  } // ----------------------------------------------------------------------------
616
532
  // Object factory
617
533
  // ----------------------------------------------------------------------------
@@ -737,6 +737,12 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
737
737
  });
738
738
  };
739
739
 
740
+ publicAPI.getHardwareMaximumLineWidth = function () {
741
+ var gl = publicAPI.get3DContext();
742
+ var lineWidthRange = gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE);
743
+ return lineWidthRange[1];
744
+ };
745
+
740
746
  publicAPI.getGLInformations = function () {
741
747
  var gl = publicAPI.get3DContext();
742
748
  var glTextureFloat = gl.getExtension('OES_texture_float');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "24.0.3",
3
+ "version": "24.1.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",