Changeset 292
- Timestamp:
- 07/26/14 04:25:23 (11 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/nmd_loader.hh
r291 r292 91 91 }; 92 92 93 // HACK : TEMPORARY - will go to it's own file, probably nmd_io 94 void nmd_dump( const nv::mesh_data_pack* model, stream& stream_out ); 95 93 96 } 94 97 -
trunk/nv/gl/gl_device.hh
r245 r292 28 28 virtual vertex_array* create_vertex_array(); 29 29 virtual image_data* create_image_data( const std::string& filename ); // temporary 30 virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr );30 virtual texture2d* create_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ); 31 31 virtual uint32 get_ticks(); 32 32 virtual void delay( uint32 ms ); -
trunk/nv/gl/gl_enum.hh
r233 r292 33 33 unsigned int stencil_operation_to_enum( stencil_test_face::operation type ); 34 34 unsigned int buffer_hint_to_enum( buffer_hint hint ); 35 unsigned int image_format_to_enum( image_format format );35 unsigned int image_format_to_enum( pixel_format format ); 36 36 unsigned int sampler_filter_to_enum( sampler::filter filter ); 37 37 unsigned int sampler_wrap_to_enum( sampler::wrap wrap ); -
trunk/nv/gl/gl_texture2d.hh
r121 r292 22 22 { 23 23 public: 24 gl_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr );24 gl_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ); 25 25 virtual void assign( void* data ); 26 26 virtual void bind( size_t slot = 0 ); -
trunk/nv/interface/device.hh
r287 r292 35 35 virtual vertex_array* create_vertex_array() = 0; 36 36 virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary 37 virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ) = 0;37 virtual texture2d* create_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ) = 0; 38 38 virtual uint32 get_ticks() = 0; 39 39 virtual void delay( uint32 ms ) = 0; 40 41 texture2d* create_texture2d( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) 42 { 43 return create_texture2d( size, aformat.format, aformat.type, asampler, data ); 44 } 45 virtual texture2d* create_texture2d( image_data* data, sampler asampler ) 46 { 47 return create_texture2d( data->get_size(), data->get_format(), asampler, (void*)data->get_data() ); 48 } 40 49 41 50 template < typename VTX, slot SLOT > -
trunk/nv/interface/image_data.hh
r121 r292 20 20 namespace nv 21 21 { 22 enum pixel_format 23 { 24 RGB, 25 RGBA 26 }; 27 28 struct image_format 29 { 30 pixel_format format; 31 datatype type; 32 33 image_format( pixel_format f = RGB, datatype d = UBYTE ) 34 : format( f ), type( d ) {} 35 }; 36 22 37 class image_data 23 38 { 24 39 public: 25 image_data( ivec2 size, size_t depth, const uint8 * data ) 26 : m_size( size ), m_depth( depth ), m_data( nullptr ) 27 { 28 std::size_t bsize = static_cast<std::size_t>(m_size.x * m_size.y) * m_depth; 40 image_data( image_format format, ivec2 size, const uint8 * data ) 41 : m_format( format ), m_size( size ), m_data( nullptr ) { initialize( data ); } 42 uint8* release_data() { uint8* r = m_data; m_data = nullptr; return r; } 43 const uint8 * get_data() const { return m_data; } 44 const ivec2 get_size() const { return m_size; } 45 // TODO : better depth check (template?) 46 size_t get_depth() const { return m_format.format == RGB ? 3 : 4; } 47 image_format get_format() const { return m_format; } 48 ~image_data() { if (m_data) delete[] m_data; } 49 private: 50 void initialize( const uint8* data ) 51 { 52 std::size_t bsize = static_cast<std::size_t>(m_size.x * m_size.y) * get_depth(); 29 53 m_data = new uint8[ bsize ]; 30 54 std::copy( data, data + bsize, m_data ); 31 55 } 32 uint8* release_data() { uint8* r = m_data; m_data = nullptr; return r; } 33 const uint8 * get_data() const { return m_data; } 34 const ivec2 get_size() const { return m_size; } 35 size_t get_depth() const { return m_depth; } 36 ~image_data() { if (m_data) delete[] m_data; } 37 private: 56 57 image_format m_format; 38 58 ivec2 m_size; //!< Defines the size of the image as a vector 39 size_t m_depth; //!< Defines the depth of the image40 59 uint8* m_data; //!< Holder for data 41 60 }; -
trunk/nv/interface/texture2d.hh
r214 r292 15 15 #include <nv/common.hh> 16 16 #include <nv/math.hh> 17 #include <nv/interface/image_data.hh> 17 18 18 19 namespace nv … … 50 51 }; 51 52 52 enum image_format53 {54 RGB,55 RGBA56 };57 58 53 class texture2d 59 54 { 60 55 public: 61 62 texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler ) : 63 m_size( size ), m_format( aformat ), m_datatype( adatatype ), m_sampler( asampler ) {} 56 texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler ) : 57 m_size( size ), m_format( aformat, adatatype ), m_sampler( asampler ) {} 64 58 virtual void assign( void* data ) = 0; 65 59 virtual void bind( size_t slot = 0 ) = 0; … … 70 64 int get_height() const { return m_size.y; } 71 65 image_format get_format() const { return m_format; } 72 datatype get_datatype() const { return m_datatype; } 66 image_format get_pixel_format() const { return m_format.format; } 67 datatype get_type() const { return m_format.type; } 73 68 const sampler& get_sampler() const { return m_sampler; } 74 69 virtual ~texture2d() {} … … 76 71 ivec2 m_size; 77 72 image_format m_format; 78 datatype m_datatype;79 73 sampler m_sampler; 80 74 }; -
trunk/src/formats/assimp_loader.cc
r291 r292 63 63 bool nv::assimp_loader::load( stream& source ) 64 64 { 65 load_assimp_library(); 65 66 if ( m_scene != nullptr ) aiReleaseImport( (const aiScene*)m_scene ); 66 67 m_scene = nullptr; 67 68 m_mesh_count = 0; 68 load_assimp_library();69 69 NV_LOG( nv::LOG_NOTICE, "AssImp loading file..." ); 70 70 int size = (int)source.size(); -
trunk/src/formats/nmd_loader.cc
r291 r292 157 157 } 158 158 159 // ---------------------------------------------------------------- 160 // nmd format dump 161 // HACK : TEMPORARY - will go to it's own file, probably nmd_io 162 static void nmd_dump_mesh( const mesh_data* mesh, stream& stream_out ) 163 { 164 const std::vector< mesh_raw_channel* >& data = mesh->get_raw_channels(); 165 166 uint32 size = sizeof( nmd_element_header ); 167 for ( auto chan : data ) 168 { 169 size += sizeof( nmd_element_header ) + sizeof( nmd_stream_header ); 170 size += chan->size(); 171 } 172 173 nmd_element_header eheader; 174 eheader.type = nmd_type::MESH; 175 eheader.name = 0; 176 eheader.children = (uint16)data.size(); 177 eheader.size = size; 178 stream_out.write( &eheader, sizeof( eheader ), 1 ); 179 180 for ( auto chan : data ) 181 { 182 nmd_element_header cheader; 183 eheader.name = 0; 184 cheader.type = nmd_type::STREAM; 185 cheader.children = 0; 186 cheader.size = chan->size() + sizeof( nmd_stream_header ); 187 stream_out.write( &cheader, sizeof( cheader ), 1 ); 188 189 nmd_stream_header sheader; 190 sheader.format = chan->desc; 191 sheader.count = chan->count; 192 stream_out.write( &sheader, sizeof( sheader ), 1 ); 193 stream_out.write( chan->data, chan->desc.size, chan->count ); 194 } 195 } 196 197 static void nmd_dump_nodes_data( const mesh_nodes_data* nodes, stream& stream_out, string_table_creator* strings ) 198 { 199 uint32 total = sizeof( nmd_animation_header ); 200 for ( uint32 i = 0; i < nodes->get_count(); ++i ) 201 { 202 const mesh_node_data* node = nodes->get_node(i); 203 total += sizeof( nmd_element_header ) + sizeof( nmd_node_header ); 204 if ( node->data ) 205 for ( uint32 c = 0; c < node->data->get_channel_count(); ++c ) 206 { 207 total += sizeof( nmd_element_header ) + sizeof( nmd_key_channel_header ); 208 total += node->data->get_channel(c)->size(); 209 } 210 } 211 212 nmd_element_header header; 213 header.name = 0; 214 header.type = nmd_type::ANIMATION; 215 header.children = (uint16)nodes->get_count(); 216 header.size = total; 217 stream_out.write( &header, sizeof( header ), 1 ); 218 219 nmd_animation_header aheader; 220 aheader.frame_rate = nodes->get_frame_rate(); 221 aheader.duration = nodes->get_duration(); 222 aheader.flat = nodes->is_flat(); 223 stream_out.write( &aheader, sizeof( aheader ), 1 ); 224 225 for ( uint32 i = 0; i < nodes->get_count(); ++i ) 226 { 227 const mesh_node_data* node = nodes->get_node(i); 228 uint32 chan_size = 0; 229 uint32 chan_count = ( node->data ? node->data->get_channel_count() : 0 ); 230 for ( uint32 c = 0; c < chan_count; ++c ) 231 { 232 chan_size += sizeof( nmd_element_header ) + sizeof( nv::nmd_key_channel_header ); 233 chan_size += node->data->get_channel(c)->size(); 234 } 235 236 nmd_element_header eheader; 237 eheader.type = nmd_type::NODE; 238 eheader.name = strings->insert( node->name ); 239 eheader.children = (uint16)chan_count; 240 eheader.size = sizeof( nmd_node_header ) + chan_size; 241 stream_out.write( &eheader, sizeof( eheader ), 1 ); 242 243 nmd_node_header nheader; 244 nheader.parent_id = (uint16)node->parent_id; 245 nheader.transform = node->transform; 246 stream_out.write( &nheader, sizeof( nheader ), 1 ); 247 248 for ( uint32 c = 0; c < chan_count; ++c ) 249 { 250 const key_raw_channel* channel = node->data->get_channel(c); 251 252 eheader.type = nmd_type::KEY_CHANNEL; 253 eheader.children = 0; 254 eheader.size = sizeof( nmd_key_channel_header ) + channel->size(); 255 stream_out.write( &eheader, sizeof( eheader ), 1 ); 256 257 nmd_key_channel_header cheader; 258 cheader.format = channel->desc; 259 cheader.count = channel->count; 260 stream_out.write( &cheader, sizeof( cheader ), 1 ); 261 stream_out.write( channel->data, channel->desc.size, channel->count ); 262 } 263 } 264 } 265 266 void nv::nmd_dump( const mesh_data_pack* model, stream& stream_out ) 267 { 268 string_table_creator strings; 269 { 270 nmd_header header; 271 header.id = four_cc<'n','m','f','1'>::value; 272 header.elements = 1; // +1 string array 273 header.elements += model->get_count(); 274 if ( model->get_nodes() && model->get_nodes()->get_count() > 0 ) 275 header.elements += 1;// +1 bone array 276 header.version = 1; 277 stream_out.write( &header, sizeof( header ), 1 ); 278 } 279 280 for ( uint32 i = 0; i < model->get_count(); ++i ) 281 { 282 const mesh_data* mesh = model->get_mesh(i); 283 nmd_dump_mesh( mesh, stream_out ); 284 } 285 286 if ( model->get_nodes() && model->get_nodes()->get_count() > 0 ) 287 { 288 nmd_dump_nodes_data( model->get_nodes(), stream_out, &strings ); 289 } 290 291 nmd_element_header sheader; 292 sheader.type = nv::nmd_type::STRING_TABLE; 293 sheader.name = 0; 294 sheader.size = strings.dump_size(); 295 sheader.children = 0; 296 stream_out.write( &sheader, sizeof( sheader ), 1 ); 297 strings.dump( &stream_out ); 298 } -
trunk/src/gl/gl_device.cc
r245 r292 81 81 return nullptr; 82 82 } 83 image_data* data = new image_data( glm::ivec2( image->w, image->h ), image->format->BytesPerPixel, (nv::uint8*)image->pixels ); 83 // TODO: BGR vs RGB, single channel 84 assert( image->format->BytesPerPixel > 2 ); 85 image_format format(image->format->BytesPerPixel == 3 ? RGB : RGBA, UBYTE ); 86 image_data* data = new image_data( format, glm::ivec2( image->w, image->h ), (nv::uint8*)image->pixels ); 84 87 return data; 85 88 } 86 89 87 texture2d* gl_device::create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )90 texture2d* gl_device::create_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ ) 88 91 { 89 92 return new gl_texture2d( size, aformat, adatatype, asampler, data ); -
trunk/src/gl/gl_enum.cc
r237 r292 147 147 } 148 148 149 unsigned int nv::image_format_to_enum( image_format format )149 unsigned int nv::image_format_to_enum( pixel_format format ) 150 150 { 151 151 switch( format ) -
trunk/src/gl/gl_texture2d.cc
r204 r292 10 10 using namespace nv; 11 11 12 nv::gl_texture2d::gl_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )12 nv::gl_texture2d::gl_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ ) 13 13 : texture2d( size, aformat, adatatype, asampler ), m_name() 14 14 { … … 38 38 { 39 39 glBindTexture( GL_TEXTURE_2D, m_name.get_value() ); 40 glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(m_format ), m_size.x, m_size.y, 0, nv::image_format_to_enum(m_format), nv::datatype_to_gl_enum(m_datatype), data );40 glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(m_format.format), m_size.x, m_size.y, 0, nv::image_format_to_enum(m_format.format), nv::datatype_to_gl_enum(m_format.type), data ); 41 41 glBindTexture( GL_TEXTURE_2D, 0 ); 42 42 }
Note: See TracChangeset
for help on using the changeset viewer.