Skip to content

Commit b32bb8f

Browse files
committed
renamed dropdown ui control to select
the select option is now targeted in the user shader by a literal string value (preprocessed and converted to a uint)
1 parent 81527a8 commit b32bb8f

File tree

11 files changed

+364
-79
lines changed

11 files changed

+364
-79
lines changed

src/annotation/type_handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ if (ng_discardValue) {
629629
gl,
630630
shader,
631631
this.shaderControlState,
632-
parameters.parseResult.controls,
632+
parameters.parseResult,
633633
);
634634
gl.uniform3fv(shader.uniform("uSubspaceMatrix"), context.subspaceMatrix);
635635
gl.uniform1fv(shader.uniform("uModelClipBounds"), context.modelClipBounds);

src/layer/image/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ export class ImageUserLayer extends Base {
448448
this.manager.root.display.gl,
449449
shader,
450450
this.shaderControlState,
451-
shaderResult.parameters.parseResult.controls,
451+
shaderResult.parameters.parseResult,
452452
);
453453
},
454454
};

src/single_mesh/frontend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ export class SingleMeshLayer extends PerspectiveViewRenderLayer<ThreeDimensional
604604
gl,
605605
shader,
606606
this.displayState.shaderControlState,
607-
parameters.parseResult.controls,
607+
parameters.parseResult,
608608
);
609609

610610
const { pickIDs } = renderContext;

src/skeleton/frontend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ export class SkeletonLayer extends RefCounted {
584584
gl,
585585
edgeShader,
586586
shaderControlState,
587-
edgeShaderParameters.parseResult.controls,
587+
edgeShaderParameters.parseResult,
588588
);
589589
gl.uniform1f(edgeShader.uniform("uLineWidth"), lineWidth!);
590590

@@ -595,7 +595,7 @@ export class SkeletonLayer extends RefCounted {
595595
gl,
596596
nodeShader,
597597
shaderControlState,
598-
nodeShaderParameters.parseResult.controls,
598+
nodeShaderParameters.parseResult,
599599
);
600600

601601
const skeletons = source.chunks;

src/sliceview/volume/image_renderlayer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class ImageRenderLayer extends SliceViewVolumeRenderLayer<ShaderControlsB
143143
gl,
144144
shader,
145145
this.shaderControlState,
146-
parameters.parseResult.controls,
146+
parameters.parseResult,
147147
);
148148
}
149149

src/volume_rendering/volume_render_layer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ outputValue = vec4(1.0, 1.0, 1.0, 1.0);
908908
gl,
909909
shader,
910910
this.shaderControlState,
911-
shaderResult.parameters.parseResult.controls,
911+
shaderResult.parameters.parseResult,
912912
);
913913
this.bindDepthBufferTexture(renderContext, shader);
914914
chunkFormat.beginDrawing(gl, shader);
@@ -1078,7 +1078,7 @@ outputValue = vec4(1.0, 1.0, 1.0, 1.0);
10781078
gl,
10791079
shader,
10801080
this.shaderControlState,
1081-
shaderResult.parameters.parseResult.controls,
1081+
shaderResult.parameters.parseResult,
10821082
);
10831083
this.bindDepthBufferTexture(renderContext, shader);
10841084
this.setShaderUniforms(shader, shaderSetupUniforms);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google Inc.
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export type ShaderStringLiteralIdMap = Map<string, number>;
18+
19+
export interface ShaderSourcePreprocessingData {
20+
stringLiteralIds: ShaderStringLiteralIdMap;
21+
}
22+
23+
export interface ShaderStringPreprocessingResult {
24+
code: string;
25+
stringLiteralIds: ShaderStringLiteralIdMap;
26+
}
27+
28+
export function preprocessStrings(
29+
userShader: string,
30+
): ShaderStringPreprocessingResult {
31+
const stringLiteralIds = new Map<string, number>();
32+
const code = userShader.replace(/"(?:\\.|[^\\"])*"/g, (token) => {
33+
const value = JSON.parse(token) as string;
34+
let index = stringLiteralIds.get(value);
35+
if (index === undefined) {
36+
index = stringLiteralIds.size + 1;
37+
stringLiteralIds.set(value, index);
38+
}
39+
return `${index}u`;
40+
});
41+
return { code, stringLiteralIds };
42+
}

0 commit comments

Comments
 (0)