1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use std::any::Any;
use std::collections::HashMap;

use interface::i_renderobj;

use implement::render::renderdevice_gl;

pub trait IComponent: 'static {
    fn as_any( & self ) -> & Any;
}

pub struct ComponentRenderBuffer {
    pub _data_dict: HashMap< i_renderobj::BuffDataType, Vec<f32> >,
    // pub _render_prim_type: i_renderobj::RenderObjType,
}

impl IComponent for ComponentRenderBuffer {
    fn as_any( & self ) -> & Any {
        self
    }
}

impl ComponentRenderBuffer {
    /// # this dumps the data to render device
    pub fn flush_into_render_device( & self, rd: & mut i_renderobj::RenderDevice ) -> Result< (), & 'static str > {
        println!("flushing into render device" );
        rd.store_buff_data( & self._data_dict )?;
        Ok( () )
    }
}

pub struct ComponentRenderUniform {
    /// # stores the uniforms values
    pub _data_dict_vf: HashMap< String, Vec<f32> >,
    pub _data_dict_mat4f: HashMap< String, Vec<f32> >,
    pub _data_dict_mat3f: HashMap< String, Vec<f32> >,
    /// # this maps an id to multiple uniforms
    pub _data_uniform_group: HashMap< u64, Vec< String > >,
}

impl Default for ComponentRenderUniform {
    fn default() -> ComponentRenderUniform {
        ComponentRenderUniform {
            _data_dict_vf: HashMap::new(),
            _data_dict_mat4f: HashMap::new(),
            _data_dict_mat3f: HashMap::new(),
            _data_uniform_group: HashMap::new(),
        }
    }
}

impl IComponent for ComponentRenderUniform {
    fn as_any( & self ) -> & Any {
        self
    }
}

impl ComponentRenderUniform {
    /// # this dumps the data to uniform manager
    pub fn flush_into_uniform_collection( & self, shader_program: i64, uc: & mut renderdevice_gl::RenderUniformCollection ) -> Result< (), & 'static str > {
        println!("flushing into uniform collection" );
        for ( ref k, ref v ) in self._data_dict_vf.iter() {
            uc.set_uniform_f( shader_program as _, (*k).as_str(), renderdevice_gl::UniformType::VEC, &v[..] );
        }
        for ( ref k, ref v ) in self._data_dict_mat4f.iter() {
            uc.set_uniform_f( shader_program as _, (*k).as_str(), renderdevice_gl::UniformType::MAT4, &v[..] );
        }
        for ( ref k, ref v ) in self._data_dict_mat3f.iter() {
            uc.set_uniform_f( shader_program as _, (*k).as_str(), renderdevice_gl::UniformType::MAT3, &v[..] );
        }
        
        for ( ref k, ref v ) in self._data_uniform_group.iter() {
            println!("uniform group: {}, length: {}.", **k, (**v).len() );
            uc.set_group( shader_program as _, **k, (**v).clone() ).is_ok();            
        }

        Ok( () )
    }
}

/// # command for resetting draw group content
#[derive(Clone)]
pub struct ComponentDrawGroupClear {
    pub _group_id: usize,
}

impl IComponent for ComponentDrawGroupClear {
    fn as_any( & self ) -> & Any {
        self
    }
}

#[derive(Clone)]
pub struct ComponentDrawGroupDependentObjects {
    pub _group_id: usize,
    pub _obj_ids: Vec< usize >,
}

impl IComponent for ComponentDrawGroupDependentObjects {
    fn as_any( & self ) -> & Any {
        self
    }
}

#[derive(Clone)]
pub struct ComponentDrawGroupBind {
    pub _group_id: usize,
}

impl IComponent for ComponentDrawGroupBind {
    fn as_any( & self ) -> & Any {
        self
    }
}

#[derive(Clone)]
pub struct ComponentDrawGroupDependentUniforms {
    pub _group_id: usize,
    pub _uniform_ids: Vec< u64 >,
}

impl IComponent for ComponentDrawGroupDependentUniforms {
    fn as_any( & self ) -> & Any {
        self
    }
}

#[derive(Clone)]
pub struct ComponentDrawGroupDispatch {
    pub _group_id: usize,
}

impl IComponent for ComponentDrawGroupDispatch {
    fn as_any( & self ) -> & Any {
        self
    }
}