Skip to content

Commit 8410b19

Browse files
committed
disconnect compile time constants from dynamic robj computation
1 parent 52056c6 commit 8410b19

File tree

1 file changed

+60
-62
lines changed

1 file changed

+60
-62
lines changed

GLMakie/src/new-primitives.jl

+60-62
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,16 @@ function assemble_scatter_robj(attr, args, uniforms, input2glname)
239239
colornorm = args.scaled_colorrange[]
240240
marker_shape = args.sdf_marker_shape[]
241241
distancefield = marker_shape === Cint(DISTANCEFIELD) ? get_texture!(screen.glscreen, args.atlas[]) : nothing
242+
242243
data = Dict(
243244
:vertex => positions,
244245
:indices => length(positions),
245246
:preprojection => Makie.get_preprojection(camera, space, markerspace),
246247
:distancefield => distancefield,
247248
:px_per_unit => screen.px_per_unit, # technically not const?
248249
:ssao => false, # shader compilation const
250+
:transparency => attr[:transparency][],
251+
:overdraw => attr[:overdraw][],
249252
:shape => marker_shape,
250253
)
251254

@@ -333,7 +336,7 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Scatter)
333336

334337
uniforms = [
335338
:gl_markerspace, :quad_scale,
336-
:transparency, :fxaa, :visible,
339+
:fxaa, :visible,
337340
:model_f32c,
338341
:_lowclip, :_highclip, :nan_color,
339342
:gl_clip_planes, :gl_num_clip_planes, :depth_shift, :gl_indices
@@ -349,7 +352,7 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Scatter)
349352
:quad_scale,
350353
:quad_offset,
351354
:image,
352-
:transparency, :fxaa, :visible,
355+
:fxaa, :visible,
353356
:strokecolor, :strokewidth, :glowcolor, :glowwidth,
354357
:model_f32c, :rotation, :transform_marker,
355358
:_lowclip, :_highclip, :nan_color,
@@ -419,15 +422,10 @@ function assemble_meshscatter_robj(attr, args, uniforms, input2glname)
419422

420423
data = Dict{Symbol, Any}(
421424
# Compile time variable
425+
:transparency => attr[:transparency][],
422426
:overdraw => attr[:overdraw][],
427+
:shading => attr[:shading][],
423428
:ssao => attr[:ssao][],
424-
:shading => attr[:shading][]
425-
426-
# :color_map => nothing,
427-
# :color_norm => nothing,
428-
# :view_normalmatrix => Mat4f(I),
429-
# :image => nothing,
430-
# :matcap => nothing,
431429
)
432430

433431
if args.packed_uv_transform[] isa Vector{Vec2f}
@@ -482,9 +480,9 @@ function draw_atomic(screen::Screen, scene::Scene, plot::MeshScatter)
482480
uniforms = [
483481
:positions_transformed_f32c, :markersize, :rotation, :f32c_scale, :instances,
484482
:_lowclip, :_highclip, :nan_color, # :matcap,
485-
:transparency, :fxaa, :visible,
483+
:fxaa, :visible,
486484
:model_f32c, :gl_clip_planes, :gl_num_clip_planes, :depth_shift,
487-
:diffuse, :specular, :shininess, :backlight, :world_normalmatrix, :shading
485+
:diffuse, :specular, :shininess, :backlight, :world_normalmatrix,
488486
]
489487

490488
input2glname = Dict{Symbol, Symbol}(
@@ -530,12 +528,14 @@ function assemble_lines_robj(attr, args, uniforms, input2glname)
530528
linestyle = attr[:linestyle][]
531529
camera = args.scene[].camera
532530
data = Dict{Symbol, Any}(
533-
:ssao => false,
534531
:fast => isnothing(linestyle),
535532
# :fast == true removes pattern from the shader so we don't need
536533
# to worry about this
537534
:vertex => positions, # Needs to be set before draw_lines()
538-
:overdraw => attr[:overdraw][]
535+
:transparency => attr[:transparency][],
536+
:overdraw => attr[:overdraw][],
537+
:ssao => false,
538+
:debug => attr[:debug][],
539539
)
540540

541541
add_camera_attributes!(data, args.gl_screen[], camera, args.space[])
@@ -681,7 +681,6 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Lines)
681681
return (output,)
682682
end
683683

684-
685684
add_input!(attr, :debug, false)
686685

687686
generate_clip_planes!(attr, :clip) # requires projectionview
@@ -712,7 +711,7 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Lines)
712711
:gl_indices, :gl_valid_vertex, :gl_total_length, :gl_last_length,
713712
:gl_pattern, :gl_pattern_length, :linecap, :gl_miter_limit, :joinstyle, :linewidth,
714713
:scene_origin, :px_per_unit,
715-
:transparency, :fxaa, :debug, :visible,
714+
:fxaa, :visible,
716715
:model_f32c,
717716
:_lowclip, :_highclip, :nan_color,
718717
:gl_clip_planes, :gl_num_clip_planes, :depth_shift
@@ -750,15 +749,14 @@ end
750749
################################################################################
751750

752751
function assemble_linesegments_robj(attr, args, uniforms, input2glname)
753-
positions = args[1][] # changes name, so we use positional
754752
linestyle = attr[:linestyle][]
755753
camera = args.scene[].camera
756754

757755
data = Dict{Symbol, Any}(
758-
:ssao => false,
759-
:vertex => positions, # TODO: can be automated
756+
:transparency => attr[:transparency][],
760757
:overdraw => attr[:overdraw][],
761-
:indices => length(positions)
758+
:debug => attr[:debug][],
759+
:ssao => false,
762760
)
763761
screen = args.gl_screen[]
764762
add_camera_attributes!(data, screen, camera, args.space[])
@@ -777,7 +775,7 @@ function assemble_linesegments_robj(attr, args, uniforms, input2glname)
777775
if isnothing(linestyle)
778776
data[:pattern] = nothing
779777
end
780-
return draw_linesegments(screen, positions, data) # TODO: extract positions
778+
return draw_linesegments(screen, data[:vertex], data) # TODO: extract positions
781779
end
782780

783781
function draw_atomic(screen::Screen, scene::Scene, plot::LineSegments)
@@ -800,16 +798,19 @@ function draw_atomic(screen::Screen, scene::Scene, plot::LineSegments)
800798
add_input!(attr, :projectionview, scene.camera.projectionview)
801799
generate_clip_planes!(attr)
802800

801+
register_computation!(attr, [:positions_transformed_f32c], [:indices]) do (positions,), changed, cached
802+
return (length(positions[]),)
803+
end
804+
803805
inputs = [
804-
:positions_transformed_f32c,
805806
:space, :scene, :gl_screen,
806807
:synched_color, :alpha_colormap, :scaled_colorrange
807808
]
808809
uniforms = [
810+
:positions_transformed_f32c, :indices,
809811
:gl_pattern, :gl_pattern_length, :linecap, :synched_linewidth,
810812
:scene_origin, :px_per_unit, :model_f32c,
811-
:transparency, :fxaa, :debug,
812-
:visible,
813+
:fxaa, :visible,
813814
:gl_clip_planes, :gl_num_clip_planes, :depth_shift
814815
]
815816

@@ -827,9 +828,6 @@ function draw_atomic(screen::Screen, scene::Scene, plot::LineSegments)
827828
robj = assemble_linesegments_robj(attr, args, uniforms, input2glname)
828829
else
829830
robj = output[1][]
830-
if changed[1]
831-
robj.vertexarray.indices = length(args[1][])
832-
end
833831
update_robjs!(robj, args, changed, input2glname)
834832
end
835833
screen.requires_update = true
@@ -845,20 +843,19 @@ end
845843
################################################################################
846844

847845
function assemble_image_robj(attr, args, uniforms, input2glname)
848-
positions = args[1][] # changes name, so we use positional
849846
screen = args.gl_screen[]
850847

851848
r = Rect2f(0,0,1,1)
852849

853850
data = Dict{Symbol, Any}(
854-
:vertices => positions,
855-
# Compile time variable
856-
:overdraw => attr[:overdraw][],
857-
# Constants
858-
:ssao => false,
859851
:faces => decompose(GLTriangleFace, r),
860852
:texturecoordinates => decompose_uv(r),
853+
854+
# Compile time variable/constants
861855
:picking_mode => "#define PICKING_INDEX_FROM_UV",
856+
:transparency => attr[:transparency][],
857+
:overdraw => attr[:overdraw][],
858+
:ssao => false,
862859
)
863860

864861
camera = args.scene[].camera
@@ -875,7 +872,7 @@ function assemble_image_robj(attr, args, uniforms, input2glname)
875872

876873
# Correct the name mapping
877874
input2glname[:scaled_color] = :image
878-
interp = args.interpolate[] ? :linear : :nearest
875+
interp = attr[:interpolate][] ? :linear : :nearest
879876
data[:image] = Texture(screen.glscreen, color; minfilter = interp)
880877

881878
# Transfer over uniforms
@@ -897,15 +894,15 @@ function draw_atomic_as_image(screen::Screen, scene::Scene, plot)
897894
generate_clip_planes!(attr)
898895

899896
inputs = [
900-
:positions_transformed_f32c,
901897
# Special
902898
:space, :scene, :gl_screen,
903899
# Needs explicit handling
904-
:alpha_colormap, :scaled_color, :scaled_colorrange, :interpolate,
900+
:alpha_colormap, :scaled_color, :scaled_colorrange,
905901
]
906902
uniforms = [
903+
:positions_transformed_f32c,
907904
:_lowclip, :_highclip, :nan_color,
908-
:transparency, :fxaa, :visible,
905+
:fxaa, :visible,
909906
:model_f32c,
910907
:gl_clip_planes, :gl_num_clip_planes, :depth_shift
911908
]
@@ -949,9 +946,9 @@ function assemble_heatmap_robj(attr, args, uniforms, input2glname)
949946
data = Dict{Symbol, Any}(
950947
:position_x => Texture(screen.glscreen, args[1][], minfilter = :nearest),
951948
:position_y => Texture(screen.glscreen, args[2][], minfilter = :nearest),
952-
# Compile time variable
949+
# Compile time variable, Constants
950+
:transparency => attr[:transparency][],
953951
:overdraw => attr[:overdraw][],
954-
# Constants
955952
:ssao => false,
956953
)
957954

@@ -969,7 +966,7 @@ function assemble_heatmap_robj(attr, args, uniforms, input2glname)
969966

970967
# Correct the name mapping
971968
input2glname[:scaled_color] = :intensity
972-
interp = args.interpolate[] ? :linear : :nearest
969+
interp = attr[:interpolate][] ? :linear : :nearest
973970
if color isa ShaderAbstractions.Sampler
974971
data[:intensity] = color
975972
else
@@ -1009,11 +1006,11 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Heatmap)
10091006
# Special
10101007
:space, :scene, :gl_screen,
10111008
# Needs explicit handling
1012-
:alpha_colormap, :scaled_color, :scaled_colorrange, :interpolate,
1009+
:alpha_colormap, :scaled_color, :scaled_colorrange
10131010
]
10141011
uniforms = [
10151012
:_lowclip, :_highclip, :nan_color,
1016-
:transparency, :fxaa, :visible,
1013+
:fxaa, :visible,
10171014
:model_f32c, :instances,
10181015
:gl_clip_planes, :gl_num_clip_planes, :depth_shift
10191016
]
@@ -1053,19 +1050,19 @@ function assemble_surface_robj(attr, args, uniforms, input2glname)
10531050
screen = args.gl_screen[]
10541051

10551052
data = Dict{Symbol, Any}(
1056-
# Compile time variable
1053+
# Compile time variable, Constants
1054+
:transparency => attr[:transparency][],
10571055
:overdraw => attr[:overdraw][],
1058-
# Constants
1056+
:shading => attr[:shading][],
10591057
:ssao => attr[:ssao][],
1060-
:shading => attr[:shading][]
10611058
)
10621059

10631060
colorname = add_mesh_color_attributes!(
10641061
screen, data,
10651062
args.scaled_color[],
10661063
args.alpha_colormap[],
10671064
args.scaled_colorrange[],
1068-
args.interpolate[]
1065+
attr[:interpolate][]
10691066
)
10701067
@assert colorname == :image
10711068

@@ -1102,12 +1099,12 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Surface)
11021099
# Special
11031100
:space, :scene, :gl_screen,
11041101
# Needs explicit handling
1105-
:alpha_colormap, :scaled_color, :scaled_colorrange, :interpolate,
1102+
:alpha_colormap, :scaled_color, :scaled_colorrange
11061103
]
11071104
uniforms = [
11081105
:x_transformed_f32c, :y_transformed_f32c, :z_converted,
11091106
:_lowclip, :_highclip, :nan_color,
1110-
:transparency, :fxaa, :visible,
1107+
:fxaa, :visible,
11111108
:model_f32c, :instances,
11121109
:gl_clip_planes, :gl_num_clip_planes, :depth_shift,
11131110
:diffuse, :specular, :shininess, :backlight, :world_normalmatrix,
@@ -1195,11 +1192,11 @@ function assemble_mesh_robj(attr, args, uniforms, input2glname)
11951192
camera = args.scene[].camera
11961193

11971194
data = Dict{Symbol, Any}(
1198-
# Compile time variable
1195+
# Compile time variable, Constants
1196+
:transparency => attr[:transparency][],
11991197
:overdraw => attr[:overdraw][],
1200-
# Constants
1198+
:shading => attr[:shading][],
12011199
:ssao => attr[:ssao][],
1202-
:shading => attr[:shading][]
12031200
)
12041201

12051202
add_camera_attributes!(data, screen, camera, args.space[])
@@ -1209,7 +1206,7 @@ function assemble_mesh_robj(attr, args, uniforms, input2glname)
12091206
args.scaled_color[],
12101207
args.alpha_colormap[],
12111208
args.scaled_colorrange[],
1212-
args.interpolate[]
1209+
attr[:interpolate][]
12131210
)
12141211

12151212
add_light_attributes!(args.scene[], data, attr)
@@ -1238,12 +1235,12 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Mesh)
12381235
# Special
12391236
:space, :scene, :gl_screen,
12401237
# Needs explicit handling
1241-
:alpha_colormap, :scaled_color, :scaled_colorrange, :interpolate,
1238+
:alpha_colormap, :scaled_color, :scaled_colorrange,
12421239
]
12431240
uniforms = [
12441241
:positions_transformed_f32c, :faces, :normals, :texturecoordinates,
12451242
:_lowclip, :_highclip, :nan_color,
1246-
:transparency, :fxaa, :visible,
1243+
:fxaa, :visible,
12471244
:model_f32c, :gl_clip_planes, :gl_num_clip_planes, :depth_shift,
12481245
:diffuse, :specular, :shininess, :backlight, :world_normalmatrix
12491246
]
@@ -1288,11 +1285,11 @@ function assemble_voxel_robj(attr, args, uniforms, input2glname)
12881285
data = Dict{Symbol, Any}(
12891286
:voxel_id => voxel_id,
12901287
:uv_transform => isnothing(uvt) ? nothing : Texture(screen.glscreen, uvt, minfilter = :nearest),
1291-
# Compile time variable
1288+
# Compile time variable, Constants
1289+
:transparency => attr[:transparency][],
12921290
:overdraw => attr[:overdraw][],
1293-
# Constants
1291+
:shading => attr[:shading][],
12941292
:ssao => attr[:ssao][],
1295-
:shading => attr[:shading][]
12961293
)
12971294

12981295
add_camera_attributes!(data, screen, camera, args.space[])
@@ -1349,7 +1346,7 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Voxels)
13491346
uniforms = [
13501347
:instances, :colormap,
13511348
:diffuse, :specular, :shininess, :backlight, :world_normalmatrix,
1352-
:transparency, :fxaa, :visible,
1349+
:fxaa, :visible,
13531350
:voxel_model, :gl_clip_planes, :gl_num_clip_planes, :depth_shift,
13541351
:gap
13551352
]
@@ -1393,11 +1390,12 @@ function assemble_volume_robj(attr, args, uniforms, input2glname)
13931390
volume_data = Texture(screen.glscreen, args.volume[], minfilter = interp)
13941391

13951392
data = Dict{Symbol, Any}(
1396-
# Compile time variable
1393+
# Compile time variable, Constants
1394+
:transparency => attr[:transparency][],
13971395
:overdraw => attr[:overdraw][],
1398-
# Constants
1396+
:shading => attr[:shading][],
13991397
:ssao => attr[:ssao][],
1400-
:shading => attr[:shading][]
1398+
:enable_depth => attr[:enable_depth][],
14011399
)
14021400

14031401
camera = args.scene[].camera
@@ -1439,9 +1437,9 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Volume)
14391437
:alpha_colormap, :scaled_colorrange
14401438
]
14411439
uniforms = [
1442-
:volume, :modelinv, :algorithm, :absorption, :isovalue, :isorange, :enable_depth,
1440+
:volume, :modelinv, :algorithm, :absorption, :isovalue, :isorange,
14431441
:diffuse, :specular, :shininess, :backlight, :world_normalmatrix,
1444-
:transparency, :fxaa, :visible,
1442+
:fxaa, :visible,
14451443
:volume_model, :gl_clip_planes, :gl_num_clip_planes, :depth_shift,
14461444
]
14471445

0 commit comments

Comments
 (0)