Skip to content

Commit

Permalink
[#104] - differentiate between various shader variable types
Browse files Browse the repository at this point in the history
  • Loading branch information
aconstlink committed Nov 7, 2024
1 parent 490756c commit 16dee5d
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 66 deletions.
27 changes: 16 additions & 11 deletions graphics/shader/compilation_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace motor
mutable motor::concurrent::mrsw_t _mtx ;

size_t _has_changed = 0 ;
size_t _compilation = 0 ;

bool_t _successful = false ;


motor::graphics::shader_bindings_t _bindings ;

Expand All @@ -27,8 +29,12 @@ namespace motor
{
motor::concurrent::mrsw_t::writer_lock_t lk( _mtx ) ;
++_has_changed ;
_compilation = compilation_sucessful ? _compilation+1 : _compilation ;
if( compilation_sucessful ) _bindings = bindings ;
_successful = compilation_sucessful ;

if( compilation_sucessful )
{
_bindings = bindings ;
}
}

bool_t has_changed( void_t ) const noexcept
Expand All @@ -37,30 +43,29 @@ namespace motor
return _has_changed != 0 ;
}

// @note only valid until reset.
bool_t is_compilation_successful( void_t ) const noexcept
{
motor::concurrent::mrsw_t::reader_lock_t lk( _mtx ) ;
return _has_changed == _compilation ;
return _successful ;
}

// reset and return if compilation was successful
bool_t get_if_successful( motor::graphics::shader_bindings_out_t sb ) noexcept
{
motor::concurrent::mrsw_t::reader_lock_t lk( _mtx ) ;
bool_t const ret = _has_changed == _compilation ;
if ( ret ) sb = _bindings ;
return ret ;
if ( _successful ) sb = _bindings ;
return _successful ;
}

// reset and return if compilation was successful
bool_t reset_and_successful( motor::graphics::shader_bindings_out_t sb ) noexcept
{
motor::concurrent::mrsw_t::writer_lock_t lk( _mtx ) ;
bool_t const ret = _has_changed == _compilation ;
_has_changed = 0 ;
_compilation = 0 ;
if( ret ) sb = std::move( _bindings ) ;
return ret ;
_successful = false ;
if( _successful ) sb = std::move( _bindings ) ;
return _successful ;
}
};
motor_typedef( compilation_listener ) ;
Expand Down
26 changes: 12 additions & 14 deletions graphics/variable/variable_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,10 @@ namespace motor
return false ;
}

motor::graphics::data_variable< motor::string_t > * texture_variable(
motor::string_in_t name ) noexcept
motor::graphics::texture_variable_t * texture_variable( motor::string_in_t name ) noexcept
{
motor::graphics::ivariable_ptr_t var = motor::memory::global_t::alloc(
motor::graphics::data_variable<motor::string_t>(), "texture variable" ) ;
motor::graphics::texture_variable_t(), "texture variable" ) ;

// before inserting, check if name and type match
{
Expand All @@ -194,7 +193,7 @@ namespace motor
{
motor::memory::global_t::dealloc( var ) ;

return static_cast< motor::graphics::data_variable< motor::string_t >* >( iter->var ) ;
return static_cast< motor::graphics::texture_variable_t* >( iter->var ) ;
}

this_t::texture_data_t d ;
Expand All @@ -204,7 +203,7 @@ namespace motor
_textures.emplace_back( d ) ;
}

return static_cast< motor::graphics::data_variable< motor::string_t >* >( var ) ;
return static_cast< motor::graphics::texture_variable_t* >( var ) ;
}

bool_t has_texture_variable( motor::string_in_t name ) const noexcept
Expand All @@ -216,11 +215,10 @@ namespace motor
return false ;
}

motor::graphics::data_variable< motor::string_t > * array_variable(
motor::string_in_t name ) noexcept
motor::graphics::array_variable_t * array_variable( motor::string_in_t name ) noexcept
{
motor::graphics::ivariable_ptr_t var = motor::memory::global_t::alloc(
motor::graphics::data_variable<motor::string_t>(), "array variable" ) ;
motor::graphics::array_variable_t(), "array variable" ) ;

// before inserting, check if name and type match
{
Expand All @@ -236,7 +234,7 @@ namespace motor
{
motor::memory::global_t::dealloc( var ) ;

return static_cast< motor::graphics::data_variable< motor::string_t >* >( iter->var ) ;
return static_cast< motor::graphics::array_variable_t* >( iter->var ) ;
}

this_t::array_data_t d ;
Expand All @@ -246,7 +244,7 @@ namespace motor
_arrays.emplace_back( d ) ;
}

return static_cast< motor::graphics::data_variable< motor::string_t >* >( var ) ;
return static_cast< motor::graphics::array_variable_t* >( var ) ;
}

bool_t has_array_variable( motor::string_in_t name ) const noexcept
Expand All @@ -259,11 +257,11 @@ namespace motor
}

// allows to connect a streamout object with a data buffer in the shader
motor::graphics::data_variable< motor::string_t > * array_variable_streamout(
motor::graphics::streamout_variable_t * array_variable_streamout(
motor::string_in_t name ) noexcept
{
motor::graphics::ivariable_ptr_t var = motor::memory::global_t::alloc(
motor::graphics::data_variable<motor::string_t>(), "array variable from streamout" ) ;
motor::graphics::streamout_variable_t(), "array variable from streamout" ) ;

// before inserting, check if name and type match
{
Expand All @@ -279,7 +277,7 @@ namespace motor
{
motor::memory::global_t::dealloc( var ) ;

return static_cast< motor::graphics::data_variable< motor::string_t >* >( iter->var ) ;
return static_cast< motor::graphics::streamout_variable_t* >( iter->var ) ;
}

this_t::streamout_data_t d ;
Expand All @@ -289,7 +287,7 @@ namespace motor
_streamouts.emplace_back( d ) ;
}

return static_cast< motor::graphics::data_variable< motor::string_t >* >( var ) ;
return static_cast< motor::graphics::streamout_variable_t* >( var ) ;
}

using for_each_data_var_funk_t = std::function< void_t ( motor::string_in_t, motor::graphics::ivariable_ptr_t ) > ;
Expand Down
201 changes: 174 additions & 27 deletions graphics/variable/variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,58 +62,205 @@ namespace motor
}
};

template<>
class data_variable<motor::string_t> : public ivariable
//***************************************************
class texture_variable_data
{
motor_this_typedefs( data_variable< motor::string_t > ) ;
motor_typedefs( motor::string_t, value ) ;
motor_this_typedefs( texture_variable_data ) ;

private:

motor::string_t _value ;
//size_t _hash = 0 ;
motor::string_t _name ;

public: // ctor

texture_variable_data( void_t ) noexcept {}
texture_variable_data( char_cptr_t name ) noexcept : _name( name ) {}
texture_variable_data( motor::string_cref_t name ) noexcept : _name( name ) {}
texture_variable_data( motor::string_rref_t name ) noexcept : _name( std::move( name ) ) {}
texture_variable_data( this_cref_t rhv ) noexcept : _name( rhv._name ) {}
texture_variable_data( this_rref_t rhv ) noexcept : _name( std::move(rhv._name) ) {}
~texture_variable_data( void_t ) noexcept {}

public: // operator =

this_ref_t operator = ( motor::string_cref_t name ) noexcept
{
_name = name ;
return *this ;
}

this_ref_t operator = ( motor::string_rref_t name ) noexcept
{
_name = std::move( name ) ;
return *this ;
}

this_ref_t operator = ( this_cref_t rhv ) noexcept
{
_name = rhv._name ;
return *this ;
}

this_ref_t operator = ( this_rref_t rhv ) noexcept
{
_name = std::move( rhv._name ) ;
return *this ;
}

public: // operator ==

bool_t operator == ( motor::string_cref_t name ) const noexcept
{
return _name == name ;
}

bool_t operator == ( this_cref_t rhv ) const noexcept
{
return _name == rhv._name ;
}

public:

data_variable( void_t ) noexcept
{}
motor::string_cref_t name( void_t ) const noexcept
{
return _name ;
}

};
using texture_variable_t = data_variable< texture_variable_data > ;

//***************************************************
class array_variable_data
{
motor_this_typedefs( array_variable_data ) ;

private:

data_variable( this_cref_t rhv ) noexcept
motor::string_t _name ;

public: // ctor

array_variable_data( void_t ) noexcept {}
array_variable_data( char_cptr_t name ) noexcept : _name( name ) {}
array_variable_data( motor::string_cref_t name ) noexcept : _name( name ) {}
array_variable_data( motor::string_rref_t name ) noexcept : _name( std::move( name ) ) {}
array_variable_data( this_cref_t rhv ) noexcept : _name( rhv._name ) {}
array_variable_data( this_rref_t rhv ) noexcept : _name( std::move( rhv._name ) ) {}
~array_variable_data( void_t ) noexcept {}

public: // operator =

this_ref_t operator = ( motor::string_cref_t name ) noexcept
{
_value = rhv._value ;
//_hash = rhv._hash ;
_name = name ;
return *this ;
}

data_variable( this_rref_t rhv ) noexcept
this_ref_t operator = ( motor::string_rref_t name ) noexcept
{
_value = std::move( rhv._value ) ;
//_hash = rhv._hash ;
_name = std::move( name ) ;
return *this ;
}

virtual ~data_variable( void_t ) noexcept {}
this_ref_t operator = ( this_cref_t rhv ) noexcept
{
_name = rhv._name ;
return *this ;
}

this_ref_t operator = ( this_rref_t rhv ) noexcept
{
_name = std::move( rhv._name ) ;
return *this ;
}

public: // operator ==

bool_t operator == ( motor::string_cref_t name ) const noexcept
{
return _name == name ;
}

bool_t operator == ( this_cref_t rhv ) const noexcept
{
return _name == rhv._name ;
}

public:

void_t set( value_cref_t v ) noexcept
{
_value = v ;
//_hash = std::hash<motor::string_t>{}(v) ;
motor::string_cref_t name( void_t ) const noexcept
{
return _name ;
}

void_t set( value_rref_t v ) noexcept
{
_value = std::move( v ) ;
//_hash = std::hash<motor::string_t>{}(_value) ;
};
using array_variable_t = data_variable< array_variable_data > ;

//***************************************************
class streamout_variable_data
{
motor_this_typedefs( streamout_variable_data ) ;

private:

motor::string_t _name ;

public: // ctor

streamout_variable_data( void_t ) noexcept {}
streamout_variable_data( char_cptr_t name ) noexcept : _name( name ) {}
streamout_variable_data( motor::string_cref_t name ) noexcept : _name( name ) {}
streamout_variable_data( motor::string_rref_t name ) noexcept : _name( std::move( name ) ) {}
streamout_variable_data( this_cref_t rhv ) noexcept : _name( rhv._name ) {}
streamout_variable_data( this_rref_t rhv ) noexcept : _name( std::move( rhv._name ) ) {}
~streamout_variable_data( void_t ) noexcept {}

public: // operator =

this_ref_t operator = ( motor::string_cref_t name ) noexcept
{
_name = name ;
return *this ;
}

value_cref_t get( void_t ) const noexcept { return _value ; }
//size_t hash( void_t ) const noexcept { return _hash ; }
this_ref_t operator = ( motor::string_rref_t name ) noexcept
{
_name = std::move( name ) ;
return *this ;
}

virtual void_cptr_t data_ptr( void_t ) const noexcept override
this_ref_t operator = ( this_cref_t rhv ) noexcept
{
_name = rhv._name ;
return *this ;
}

this_ref_t operator = ( this_rref_t rhv ) noexcept
{
_name = std::move( rhv._name ) ;
return *this ;
}

public: // operator ==

bool_t operator == ( motor::string_cref_t name ) const noexcept
{
return _name == name ;
}

bool_t operator == ( this_cref_t rhv ) const noexcept
{
return _name == rhv._name ;
}

public:

motor::string_cref_t name( void_t ) const noexcept
{
return nullptr ;
return _name ;
}
};
using streamout_variable_t = data_variable< streamout_variable_data > ;

template< typename T >
std::pair< bool_t, motor::graphics::data_variable< T > * > cast_data_variable( motor::graphics::ivariable_ptr_t in_var ) noexcept
Expand Down
Loading

0 comments on commit 16dee5d

Please sign in to comment.