-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#104] - 🔨 there is now the possibility to interface with shader vari…
…ables through the slot system and it required some addition to elsewhere 👷
- Loading branch information
1 parent
527b6e8
commit f386428
Showing
14 changed files
with
489 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
|
||
#include "wire_variable_bridge.h" | ||
|
||
using namespace motor::graphics ; | ||
|
||
//***************************************************************** | ||
wire_variable_bridge::wire_variable_bridge( void_t ) noexcept | ||
{ | ||
} | ||
|
||
//***************************************************************** | ||
wire_variable_bridge::wire_variable_bridge( motor::graphics::variable_set_mtr_safe_t ) noexcept | ||
{ | ||
} | ||
|
||
//***************************************************************** | ||
wire_variable_bridge::wire_variable_bridge( this_rref_t rhv ) noexcept : _vs( motor::move( rhv._vs ) ), | ||
_inputs( std::move( rhv._inputs ) ), _bindings( std::move( rhv._bindings ) ) | ||
{ | ||
} | ||
|
||
//***************************************************************** | ||
wire_variable_bridge::~wire_variable_bridge( void_t ) noexcept | ||
{ | ||
_inputs.clear() ; | ||
} | ||
|
||
//***************************************************************** | ||
void_t wire_variable_bridge::pull_data( void_t ) noexcept | ||
{ | ||
for( auto & b : _bindings ) | ||
{ | ||
b.pull_funk( b ) ; | ||
} | ||
} | ||
|
||
//***************************************************************** | ||
void_t wire_variable_bridge::update_bindings( void_t ) noexcept | ||
{ | ||
this_t::create_bindings() ; | ||
|
||
if( _vs == nullptr ) return ; | ||
|
||
// clear up every slot which is not in the shader | ||
// variable set. | ||
{ | ||
std::vector< motor::string_t > removeables ; | ||
|
||
_inputs.for_each_slot( [&] ( motor::string_in_t name, motor::wire::iinput_slot_ptr_t ) | ||
{ | ||
if ( !_vs->has_any_variable( name ) ) | ||
{ | ||
removeables.emplace_back( name ) ; | ||
} | ||
} ) ; | ||
|
||
for ( auto const & name : removeables ) | ||
{ | ||
_inputs.remove( name ) ; | ||
} | ||
} | ||
} | ||
|
||
//***************************************************************** | ||
void_t wire_variable_bridge::update_bindings( motor::graphics::variable_set_mtr_safe_t vs ) noexcept | ||
{ | ||
motor::release( motor::move( _vs ) ) ; | ||
_vs = motor::move( vs ) ; | ||
this_t::update_bindings() ; | ||
} | ||
|
||
//***************************************************************** | ||
motor::wire::inputs_ptr_t wire_variable_bridge::borrow_inputs( void_t ) noexcept | ||
{ | ||
return &_inputs ; | ||
} | ||
|
||
//***************************************************************** | ||
motor::wire::inputs_cptr_t wire_variable_bridge::borrow_inputs( void_t ) const noexcept | ||
{ | ||
return &_inputs ; | ||
} | ||
|
||
//***************************************************************** | ||
void_t wire_variable_bridge::create_bindings( void_t ) noexcept | ||
{ | ||
_bindings.clear() ; | ||
|
||
if( _vs == nullptr ) | ||
{ | ||
_inputs.clear() ; | ||
return ; | ||
} | ||
|
||
_vs->for_each_data_variable( [&]( motor::string_in_t name, motor::graphics::ivariable_ptr_t var ) | ||
{ | ||
if( this_t::make_binding< int_t >( name, var ) ) return ; | ||
if( this_t::make_binding< float_t >( name, var ) ) return ; | ||
if( this_t::make_binding< uint_t >( name, var ) ) return ; | ||
if( this_t::make_binding< motor::math::vec2f_t >( name, var ) ) return ; | ||
if( this_t::make_binding< motor::math::vec3f_t >( name, var ) ) return ; | ||
if( this_t::make_binding< motor::math::vec4f_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::vec2i_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::vec3i_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::vec4i_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::vec2ui_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::vec3ui_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::vec4ui_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::mat2f_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::mat3f_t >( name, var ) ) return ; | ||
if ( this_t::make_binding< motor::math::mat4f_t >( name, var ) ) return ; | ||
} ) ; | ||
|
||
_vs->for_each_texture_variable( [&] ( motor::string_in_t name, motor::graphics::data_variable<motor::string_t> * var ) | ||
{ | ||
if( this_t::make_binding< motor::string_t >( name, var ) ) return ; | ||
} ) ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#pragma once | ||
#include "../api.h" | ||
#include "../typedefs.h" | ||
|
||
#include "variable_set.hpp" | ||
|
||
#include <motor/wire/slot/sheet.hpp> | ||
|
||
namespace motor | ||
{ | ||
namespace graphics | ||
{ | ||
class MOTOR_GRAPHICS_API wire_variable_bridge | ||
{ | ||
motor_this_typedefs( wire_variable_bridge ) ; | ||
|
||
private: | ||
|
||
motor::graphics::variable_set_mtr_t _vs = nullptr ; | ||
motor::wire::inputs_t _inputs ; | ||
|
||
// will only hold borrowed pointers. | ||
// ref counted pointers are stored above. | ||
// binding in this case means: | ||
// shader var to slot binding | ||
struct variable_binding | ||
{ | ||
using pull_funk_t = std::function< void_t ( variable_binding & ) > ; | ||
motor::graphics::ivariable_ptr_t gvar ; | ||
motor::wire::iinput_slot_ptr_t slot ; | ||
pull_funk_t pull_funk ; | ||
}; | ||
|
||
motor::vector< variable_binding > _bindings ; | ||
|
||
public: | ||
|
||
wire_variable_bridge( void_t ) noexcept ; | ||
wire_variable_bridge( motor::graphics::variable_set_mtr_safe_t ) noexcept ; | ||
wire_variable_bridge( this_rref_t ) noexcept ; | ||
wire_variable_bridge( this_cref_t ) = delete ; | ||
~wire_variable_bridge( void_t ) noexcept ; | ||
|
||
public: // update interface | ||
|
||
// pull data from inputs slots to graphics variables | ||
void_t pull_data( void_t ) noexcept ; | ||
|
||
// redo graphics variables to inputs bindings | ||
void_t update_bindings( void_t ) noexcept ; | ||
|
||
// redo graphics variables to inputs bindings | ||
// by introducing a new variable set | ||
void_t update_bindings( motor::graphics::variable_set_mtr_safe_t ) noexcept ; | ||
|
||
public: // get/set | ||
|
||
motor::wire::inputs_ptr_t borrow_inputs( void_t ) noexcept ; | ||
motor::wire::inputs_cptr_t borrow_inputs( void_t ) const noexcept ; | ||
|
||
private: | ||
|
||
void_t create_bindings( void_t ) noexcept ; | ||
|
||
template< typename T > | ||
bool_t make_binding( motor::string_in_t name, motor::graphics::ivariable_ptr_t var ) noexcept | ||
{ | ||
using type_t = T ; | ||
|
||
auto [a, b] = motor::graphics::cast_data_variable< type_t >( var ) ; | ||
if ( a ) | ||
{ | ||
using slot_t = motor::wire::input_slot< type_t > ; | ||
using var_t = motor::graphics::data_variable< type_t > ; | ||
|
||
auto s = _inputs.get_or_add( name, motor::shared( slot_t( b->get() ) ) ) ; | ||
b->set( ((slot_t*)s.mtr())->get_value() ) ; | ||
|
||
_bindings.emplace_back( variable_binding | ||
{ | ||
var, motor::move( s ), | ||
[=] ( this_t::variable_binding & v ) | ||
{ | ||
auto * s_local = reinterpret_cast<slot_t *>( v.slot ) ; | ||
auto * v_local = reinterpret_cast<var_t *>( v.gvar ) ; | ||
|
||
v_local->set( s_local->get_value() ) ; | ||
} | ||
} ) ; | ||
return true ; | ||
} | ||
return false ; | ||
} | ||
}; | ||
motor_typedef( wire_variable_bridge ) ; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.