Closed matthewturk closed 1 year ago
One thing I do need to keep an eye on is making sure that #version
is still the very first line.
OK, I fixed that up by moving around where we include the preprocessor definitions. I tested that it worked with this diff as well:
diff --git a/examples/amr_volume_rendering.py b/examples/amr_volume_rendering.py
index 17fd8ea..c0b1619 100644
--- a/examples/amr_volume_rendering.py
+++ b/examples/amr_volume_rendering.py
@@ -6,4 +6,5 @@ ds = yt.load_sample("IsolatedGalaxy")
rc = yt_idv.render_context(height=800, width=800, gui=True)
sg = rc.add_scene(ds, "density", no_ghost=True)
+sg.add_text("Hi there")
rc.run()
diff --git a/yt_idv/shader_objects.py b/yt_idv/shader_objects.py
index 5cb4cd1..bb5473e 100644
--- a/yt_idv/shader_objects.py
+++ b/yt_idv/shader_objects.py
@@ -367,6 +367,7 @@ class ShaderTrait(traitlets.TraitType):
"blend_func_separate" in shader_info
)
shader_info.setdefault("shader_name", value)
+ shader_info.setdefault("preprocessor_defs", [("USE_RED_OFF", "")])
shader = Shader(**shader_info)
return shader
except KeyError:
diff --git a/yt_idv/shaders/textoverlay.frag.glsl b/yt_idv/shaders/textoverlay.frag.glsl
index a6b98da..8657b5f 100644
--- a/yt_idv/shaders/textoverlay.frag.glsl
+++ b/yt_idv/shaders/textoverlay.frag.glsl
@@ -6,5 +6,9 @@ void main(){
float val = texture(fb_tex, UV).r;
gl_FragDepth = 0.0;
if(val == 0) discard;
+#ifdef USE_RED
+ color = vec4(1.0, 0, 0, 1.0);
+#else
color = vec4(val);
+#endif
}
and switching between USE_RED_OFF
and USE_RED
.
I can't remember why I didn't just merge this!
This should be enough to get the shader programs to accept preprocessor directives. It's not quite ready to go yet, because right now the shader objects themselves are created inside the shader program, and I'm not passing the full set of preprocessor directives down.
How it works right now is that
base_component.py
has the function_recompile_shader
. This deletes the shaders and sets_program1_invalid
and_program2_invalid
to True. The next time the call gets made toprogram1
, it is a property that calls:We'll need to include in this a set of parameters that are defined on the base component. I think this could be a property defined by each subclass that translates properties/traits into strings.