Skip to content

Commit

Permalink
RF: Add keyword arguments to module: shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
WassCodeur committed Jul 10, 2024
1 parent 1f34348 commit 49f17c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
26 changes: 17 additions & 9 deletions fury/shaders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os

from fury import enable_warnings
from fury.decorators import warn_on_args_to_kwargs
from fury.deprecator import deprecate_with_version
from fury.io import load_text
from fury.lib import (
Expand Down Expand Up @@ -168,9 +169,11 @@ def load(filename):
return shader_file.read()


@warn_on_args_to_kwargs()
def shader_to_actor(
actor,
shader_type,
*,
impl_code="",
decl_code="",
block="valuepass",
Expand Down Expand Up @@ -279,7 +282,8 @@ def replace_shader_in_actor(actor, shader_type, code):
getattr(sp, function)(code)


def add_shader_callback(actor, callback, priority=0.0):
@warn_on_args_to_kwargs()
def add_shader_callback(actor, callback, *, priority=0.0):
"""Add a shader callback to the actor.
Parameters
Expand Down Expand Up @@ -328,20 +332,21 @@ def callbackMean(_caller, _event, calldata=None):
test_values.append(500)
fs.add_shader_callback(
actor, callbackHigh, 999)
actor, callbackHigh, priority=999)
fs.add_shader_callback(
actor, callbackLow, 0)
actor, callbackLow, priority=0)
id_mean = fs.add_shader_callback(
actor, callbackMean, 500)
actor, callbackMean, priority=500)
showm.start()
# test_values = [999, 500, 0, 999, 500, 0, ...]
"""

# @warn_on_args_to_kwargs()
@calldata_type(VTK_OBJECT)
def cbk(caller, event, calldata=None):
callback(caller, event, calldata)
callback(caller, event, calldata=calldata)

if not isinstance(priority, (float, int)):
raise TypeError(
Expand All @@ -355,7 +360,8 @@ def cbk(caller, event, calldata=None):
return id_observer


def shader_apply_effects(window, actor, effects, priority=0):
@warn_on_args_to_kwargs()
def shader_apply_effects(window, actor, effects, *, priority=0):
"""This applies a specific opengl state (effect) or a list of effects just
before the actor's shader is executed.
Expand All @@ -381,21 +387,23 @@ def shader_apply_effects(window, actor, effects, priority=0):
if not isinstance(effects, list):
effects = [effects]

def callback(_caller, _event, calldata=None, effects=None, window=None):
@warn_on_args_to_kwargs()
def callback(_caller, _event, *, calldata=None, effects=None, window=None):
program = calldata
glState = window.GetState()
if program is not None:
for func in effects:
func(glState)

id_observer = add_shader_callback(
actor, partial(callback, effects=effects, window=window), priority
actor, partial(callback, effects=effects, window=window), priority=priority
)

return id_observer


def attribute_to_actor(actor, arr, attr_name, deep=True):
@warn_on_args_to_kwargs()
def attribute_to_actor(actor, arr, attr_name, *, deep=True):
"""Link a numpy array with vertex attribute.
Parameters
Expand Down
8 changes: 4 additions & 4 deletions fury/shaders/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def callbackLow(_caller, _event, calldata=None):
if program is not None:
test_values.append(0)

id_observer = add_shader_callback(cone_actor, callbackLow, 0)
id_observer = add_shader_callback(cone_actor, callbackLow, priority=0)

with pytest.raises(Exception): # noqa: B017
add_shader_callback(cone_actor, callbackLow, priority="str")
Expand All @@ -258,10 +258,10 @@ def callbackMean(_caller, _event, calldata=None):
if program is not None:
test_values.append(500)

add_shader_callback(cone_actor, callbackHigh, 999)
add_shader_callback(cone_actor, callbackLow, 0)
add_shader_callback(cone_actor, callbackHigh, priority=999)
add_shader_callback(cone_actor, callbackLow, priority=0)

id_mean = add_shader_callback(cone_actor, callbackMean, 500)
id_mean = add_shader_callback(cone_actor, callbackMean, priority=500)

# check the priority of each call
window.snapshot(scene, size=(200, 200))
Expand Down

0 comments on commit 49f17c1

Please sign in to comment.