Changeset 295
- Timestamp:
- 07/31/14 02:32:59 (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gfx/mesh_creator.hh
r294 r295 23 23 // TODO: this could generate normals too 24 24 void generate_tangents(); 25 void flip_normals(); 26 bool is_same_format( mesh_data* other ); 27 void merge( mesh_data* other ); 25 28 private: 26 29 mesh_raw_channel* merge_channels( mesh_raw_channel* a, mesh_raw_channel* b ); 30 mesh_raw_channel* append_channels( mesh_raw_channel* a, mesh_raw_channel* b, uint32 frame_count = 1 ); 27 31 28 32 mesh_data* m_data; … … 47 51 mesh_creator( mesh_data_pack* pack ) : m_pack( pack ) {} 48 52 // assumes that keys are equally spaced 49 void pre_transform_keys() { mesh_nodes_creator( m_pack->m_nodes ).pre_transform_keys(); } 53 void pre_transform_keys() 54 { 55 if ( m_pack->m_nodes ) 56 mesh_nodes_creator( m_pack->m_nodes ).pre_transform_keys(); 57 } 50 58 void generate_tangents() 51 59 { … … 57 65 void merge_keys() { mesh_nodes_creator( m_pack->m_nodes ).merge_keys(); } 58 66 // assumes that position and normal is vec3, tangent is vec4 67 void flip_normals() 68 { 69 for ( size_t m = 0; m < m_pack->m_count; ++m ) 70 mesh_data_creator( &(m_pack->m_meshes[m]) ).flip_normals(); 71 } 59 72 void transform( float scale, const mat3& r33 ) 60 73 { … … 64 77 mesh_nodes_creator( m_pack->m_nodes ).transform( scale, r33 ); 65 78 } 79 // assumes models have same format 80 // currently only data merge 81 bool merge( mesh_data_pack* other ) 82 { 83 for ( size_t m = 0; m < m_pack->m_count; ++m ) 84 { 85 if (!mesh_data_creator( &(m_pack->m_meshes[m]) ).is_same_format( &(other->m_meshes[m]) ) ) 86 return false; 87 } 88 for ( size_t m = 0; m < m_pack->m_count; ++m ) 89 { 90 mesh_data_creator(&(m_pack->m_meshes[m]) ).merge( &(other->m_meshes[m]) ); 91 } 92 return true; 93 } 66 94 private: 67 95 mesh_data_pack* m_pack; -
trunk/nv/gl/gl_context.hh
r245 r295 64 64 public: 65 65 native_gl_context( device* a_device, void* a_native_win_handle ); 66 void* get_native_handle() { return m_handle; } 66 67 ~native_gl_context(); 67 68 private: -
trunk/nv/gl/gl_window.hh
r245 r295 32 32 virtual context* get_context() { return m_context; } 33 33 virtual device* get_device() { return m_device; } 34 35 34 virtual void swap_buffers(); 36 35 virtual ~gl_window(); … … 41 40 string m_title; 42 41 void* m_handle; 42 void* m_hwnd; 43 43 bool m_adopted; 44 44 gl_context* m_context; -
trunk/nv/handle.hh
r287 r295 147 147 resize_indexes_to( h.index() ); 148 148 m_indexes[ h.index() ] = m_data.size(); 149 m_handles.push_back( h ); 149 150 m_data.emplace_back(); 150 151 return &(m_data.back()); … … 170 171 if ( dead_eindex != (sint32)m_data.size()-1 ) 171 172 { 172 m_data[ dead_eindex ] = m_data.back();173 m_handles[ dead_eindex ] = m_handles.back();174 m_indexes[ h.index() ] = m_indexes[ swap_handle.index() ];173 m_data[ dead_eindex ] = m_data.back(); 174 m_handles[ dead_eindex ] = swap_handle; 175 m_indexes[ swap_handle.index() ] = dead_eindex; 175 176 } 176 177 m_data.pop_back(); -
trunk/nv/interface/animated_mesh.hh
r288 r295 33 33 float get_end() const { return m_end; } 34 34 bool is_looping() const { return m_looping; } 35 void set_range( float a_start, float a_end ) 36 { 37 m_start = a_start; 38 m_end = a_end; 39 m_duration = m_end - m_start; 40 } 41 void set_frame_rate( uint32 rate ) 42 { 43 m_frame_rate = rate; 44 } 35 45 virtual ~animation_entry() {} 36 46 protected: -
trunk/nv/interface/mesh_data.hh
r294 r295 107 107 return nullptr; 108 108 } 109 110 const mesh_raw_channel* get_channel( slot s ) const 111 { 112 for ( auto ch : m_channels ) 113 { 114 for ( uint32 i = 0; i < ch->desc.count; ++i ) 115 if ( ch->desc.slots[i].vslot == s ) 116 { 117 return ch; 118 } 119 } 120 return nullptr; 121 } 122 123 int get_channel_index( slot s ) const 124 { 125 for ( uint32 c = 0; c < m_channels.size(); ++c ) 126 { 127 const mesh_raw_channel* ch = m_channels[c]; 128 for ( uint32 i = 0; i < ch->desc.count; ++i ) 129 if ( ch->desc.slots[i].vslot == s ) 130 { 131 return c; 132 } 133 } 134 return -1; 135 } 136 109 137 110 138 size_t get_count() const -
trunk/nv/interface/vertex.hh
r286 r295 261 261 } 262 262 263 bool operator==( const vertex_descriptor& rhs ) 263 bool operator!=( const vertex_descriptor& rhs ) const 264 { 265 return !( *this == rhs ); 266 } 267 268 bool operator==( const vertex_descriptor& rhs ) const 264 269 { 265 270 if ( size != rhs.size ) return false; -
trunk/nv/lib/detail/gl_types.inc
r244 r295 1 #ifndef NV_LIB_GL_TYPES_HH 2 #define NV_LIB_GL_TYPES_HH 3 1 4 typedef unsigned int GLenum; 2 5 typedef unsigned int GLbitfield; … … 21 24 22 25 /* OpenGL 1.1 non-deprecated defines */ 26 #define GL_NO_ERROR 0 23 27 #define GL_DEPTH_BUFFER_BIT 0x00000100 24 28 #define GL_STENCIL_BUFFER_BIT 0x00000400 … … 517 521 #define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 518 522 #define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 523 524 #endif // NV_LIB_GL_TYPES_HH -
trunk/nv/logger.hh
r256 r295 41 41 const char* timestamp() const; 42 42 /** 43 * Log level name (unpadded) 44 */ 45 const char* level_name( log_level level ) const; 46 /** 47 * Log level name (padded) 48 */ 49 const char* padded_level_name( log_level level ) const; 50 /** 43 51 * Enforcement of virtual destructor. 44 52 */ -
trunk/src/gfx/mesh_creator.cc
r294 r295 168 168 }; 169 169 170 void nv::mesh_data_creator::flip_normals() 171 { 172 int ch_n = m_data->get_channel_index( slot::NORMAL ); 173 size_t n_offset = 0; 174 if ( ch_n == -1 ) return; 175 mesh_raw_channel* channel = m_data->m_channels[ch_n]; 176 for ( uint32 i = 0; i < channel->desc.count; ++i ) 177 if ( channel->desc.slots[i].vslot == slot::NORMAL ) 178 { 179 n_offset = channel->desc.slots[i].offset; 180 } 181 182 for ( uint32 i = 0; i < channel->count; ++i ) 183 { 184 vec3& normal = *(vec3*)(channel->data + channel->desc.size * i + n_offset); 185 normal = -normal; 186 } 187 } 188 189 170 190 void nv::mesh_data_creator::generate_tangents() 171 191 { … … 339 359 return result; 340 360 } 361 362 nv::mesh_raw_channel* nv::mesh_data_creator::append_channels( mesh_raw_channel* a, mesh_raw_channel* b, uint32 frame_count ) 363 { 364 if ( a->desc != b->desc ) return nullptr; 365 if ( a->count % frame_count != 0 ) return nullptr; 366 if ( b->count % frame_count != 0 ) return nullptr; 367 size_t vtx_size = a->desc.size; 368 369 uint8* data = new uint8[ ( a->count + b->count ) * vtx_size ]; 370 371 372 if ( frame_count == 1 ) 373 { 374 size_t a_size = vtx_size * a->count; 375 std::copy_n( a->data, a_size, data ); 376 std::copy_n( b->data, vtx_size * b->count, data + a_size ); 377 } 378 else 379 { 380 size_t frame_size_a = ( a->count / frame_count ) * vtx_size; 381 size_t frame_size_b = ( b->count / frame_count ) * vtx_size; 382 size_t pos_a = 0; 383 size_t pos_b = 0; 384 size_t pos = 0; 385 for ( size_t i = 0; i < frame_count; ++i ) 386 { 387 std::copy_n( a->data + pos_a, frame_size_a, data + pos ); 388 std::copy_n( b->data + pos_b, frame_size_b, data + pos + frame_size_a ); pos_a += frame_size_a; 389 pos_b += frame_size_b; 390 pos += frame_size_a + frame_size_b; 391 } 392 } 393 394 mesh_raw_channel* result = new mesh_raw_channel; 395 result->count = a->count + b->count; 396 result->desc = a->desc; 397 result->data = data; 398 return result; 399 } 400 401 402 403 bool nv::mesh_data_creator::is_same_format( mesh_data* other ) 404 { 405 if ( m_data->get_channel_count() != other->get_channel_count() ) return false; 406 for ( uint32 c = 0; c < m_data->get_channel_count(); ++c ) 407 { 408 if ( m_data->get_channel(c)->desc != other->get_channel(c)->desc ) 409 return false; 410 } 411 return true; 412 } 413 414 void nv::mesh_data_creator::merge( mesh_data* other ) 415 { 416 if ( !is_same_format( other ) ) return; 417 int ch_pi = m_data->get_channel_index( slot::POSITION ); 418 int ch_ti = m_data->get_channel_index( slot::TEXCOORD ); 419 int och_pi = other->get_channel_index( slot::POSITION ); 420 int och_ti = other->get_channel_index( slot::TEXCOORD ); 421 if ( ch_pi == -1 || ch_ti == -1 ) return; 422 size_t size = m_data->m_channels[ ch_ti ]->count; 423 size_t osize = other->m_channels[ och_ti ]->count; 424 size_t count = m_data->m_channels[ ch_pi ]->count; 425 size_t ocount = other->m_channels[ och_pi ]->count; 426 if ( count % size != 0 || ocount % osize != 0 ) return; 427 if ( count / size != ocount / osize ) return; 428 429 for ( uint32 c = 0; c < m_data->get_channel_count(); ++c ) 430 { 431 mesh_raw_channel* old = m_data->m_channels[c]; 432 size_t frame_count = ( old->is_index() ? 1 : old->count / size ); 433 m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count ); 434 NV_ASSERT( m_data->m_channels[c], "Merge problem!" ); 435 if ( old->is_index() ) 436 { 437 switch ( old->desc.slots[0].etype ) 438 { 439 case USHORT : 440 { 441 NV_ASSERT( size + osize < uint16(-1), "Index out of range!" ); 442 uint16* indexes = (uint16*)m_data->m_channels[c]->data; 443 for ( uint16 i = (uint16)old->count; i < m_data->m_channels[c]->count; ++i ) 444 indexes[i] += (uint16)size; 445 446 } 447 break; 448 case UINT : 449 { 450 uint32* indexes = (uint32*)m_data->m_channels[c]->data; 451 for ( uint32 i = old->count; i < m_data->m_channels[c]->count; ++i ) 452 indexes[i] += size; 453 } 454 break; 455 default : NV_ASSERT( false, "Unsupported index type!" ); break; 456 } 457 m_data->m_index_channel = m_data->m_channels[c]; 458 } 459 delete old; 460 } 461 } -
trunk/src/gfx/skeletal_mesh.cc
r290 r295 225 225 skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)(a_anim); 226 226 anim->prepare( m_bone_data ); 227 update_animation( a_anim, uint32( anim->get_start() * 1000.f * anim->get_frame_rate() * 1000 ));227 update_animation( a_anim, 0 ); 228 228 } 229 229 } -
trunk/src/gl/gl_window.cc
r246 r295 206 206 207 207 gl_window::gl_window( device* dev, uint16 width, uint16 height, bool fullscreen ) 208 : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr ), m_ adopted( false )208 : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr ), m_hwnd( 0 ), m_adopted( false ) 209 209 { 210 210 // bpp = m_info->vfmt->BitsPerPixel; … … 298 298 void gl_window::swap_buffers() 299 299 { 300 if ( m_adopted ) return; // NOT SURE 300 if ( m_adopted ) 301 { 302 #if NV_PLATFORM == NV_WINDOWS 303 ::SwapBuffers( (HDC)m_hwnd ); 304 #else 305 NV_ASSERT( false, "Native GL context only working with SDL 2.0!" ); 306 #endif 307 308 } 301 309 #if NV_SDL_VERSION == NV_SDL_20 302 310 SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) ); … … 328 336 // m_height = (uint16)rect.bottom; 329 337 m_handle = window; 338 m_hwnd = ::GetDC( (HWND)handle ); 330 339 m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) ); 331 340 #else -
trunk/src/library.cc
r256 r295 120 120 } 121 121 m_handle = NULL; 122 NV_LOG( LOG_NOTICE, "library : '" + m_name + "' closed." );123 122 } 124 123 -
trunk/src/logger.cc
r204 r295 251 251 return buffer; 252 252 } 253 254 const char* nv::log_sink::level_name( log_level level ) const 255 { 256 return NV_LOG_LEVEL_NAME( level ); 257 } 258 259 const char* nv::log_sink::padded_level_name( log_level level ) const 260 { 261 return NV_LOG_LEVEL_NAME_PAD( level ); 262 }
Note: See TracChangeset
for help on using the changeset viewer.