diff --git a/graphics/shader/compilation_listener.h b/graphics/shader/compilation_listener.h index c24b51d..6bfba7a 100644 --- a/graphics/shader/compilation_listener.h +++ b/graphics/shader/compilation_listener.h @@ -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 ; @@ -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 @@ -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 ) ; diff --git a/graphics/variable/variable_set.hpp b/graphics/variable/variable_set.hpp index 6cdcf30..9c908dc 100644 --- a/graphics/variable/variable_set.hpp +++ b/graphics/variable/variable_set.hpp @@ -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(), "texture variable" ) ; + motor::graphics::texture_variable_t(), "texture variable" ) ; // before inserting, check if name and type match { @@ -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 ; @@ -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 @@ -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(), "array variable" ) ; + motor::graphics::array_variable_t(), "array variable" ) ; // before inserting, check if name and type match { @@ -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 ; @@ -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 @@ -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(), "array variable from streamout" ) ; + motor::graphics::streamout_variable_t(), "array variable from streamout" ) ; // before inserting, check if name and type match { @@ -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 ; @@ -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 ) > ; diff --git a/graphics/variable/variables.hpp b/graphics/variable/variables.hpp index 1fd6040..b9c55af 100644 --- a/graphics/variable/variables.hpp +++ b/graphics/variable/variables.hpp @@ -62,58 +62,205 @@ namespace motor } }; - template<> - class data_variable : 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{}(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{}(_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 diff --git a/platform/graphics/d3d/d3d11.cpp b/platform/graphics/d3d/d3d11.cpp index 5020366..9fead33 100644 --- a/platform/graphics/d3d/d3d11.cpp +++ b/platform/graphics/d3d/d3d11.cpp @@ -3150,7 +3150,7 @@ struct d3d11_backend::pimpl for( auto& t : shd.ps_textures ) { auto * dv = vs->texture_variable( t.name ) ; - motor::string_t const img_name = dv->get() ; + motor::string_t const img_name = dv->get().name() ; size_t i = 0 ; for( ; i < images.size(); ++i ) if( images[ i ].name == img_name ) break ; @@ -3186,7 +3186,7 @@ struct d3d11_backend::pimpl for( auto& t : the_buffer ) { // first try data_buffers... - motor::string_t const name = vs->array_variable( t.name )->get() ; + motor::string_t const name = vs->array_variable( t.name )->get().name() ; size_t const i = this_t::find_index_by_resource_name( name, arrays ) ; // ... if the stored variable name is found in the data_buffers array, it is used ... @@ -3201,7 +3201,7 @@ struct d3d11_backend::pimpl // ... otherwise we default to the streamout objects else { - motor::string_t const name2 = vs->array_variable_streamout( t.name )->get() ; + motor::string_t const name2 = vs->array_variable_streamout( t.name )->get().name() ; size_t const i2 = this_t::find_index_by_resource_name( name2, streamouts ) ; if( i2 < streamouts.size() ) diff --git a/platform/graphics/gl/gl4.cpp b/platform/graphics/gl/gl4.cpp index e445886..654a643 100644 --- a/platform/graphics/gl/gl4.cpp +++ b/platform/graphics/gl/gl4.cpp @@ -2731,14 +2731,14 @@ struct gl4_backend::pimpl auto const& tx_name = var->get() ; for( auto& cfg : _images ) { - if( cfg.name == tx_name ) break ; + if( tx_name == cfg.name ) break ; ++i ; } if( i >= _images.size() ) { motor::log::global_t::error( motor_log_fn( "Could not find image [" + - tx_name + "]" ) ) ; + tx_name.name() + "]" ) ) ; continue ; } @@ -2752,18 +2752,14 @@ struct gl4_backend::pimpl } else if( motor::ogl::uniform_is_buffer( uv.type ) ) { - auto* var = vs->array_variable( uv.name ) ; + motor::string_t tx_name ; - if( var == nullptr ) { - motor::log::global_t::error( motor_log_fn( "can not claim variable " + uv.name ) ) ; - continue ; - } - - if( var->get().empty() ) - var = vs->array_variable_streamout( uv.name ) ; + tx_name = vs->array_variable( uv.name )->get().name() ; - auto const & tx_name = var->get() ; + if ( tx_name.empty() ) + tx_name = vs->array_variable_streamout( uv.name )->get().name() ; + } // looking for data buffer auto handle_buffer_link = [&]( void_t )