Back to index

nux  3.0.0
MeshData.cpp
Go to the documentation of this file.
00001 #include "GLResource.h"
00002 #include "MeshData.h"
00003 
00004 
00005 namespace nux
00006 {
00007   MeshData::MeshData()
00008   {
00009     _num_index = 0;
00010     _index_size = 0;
00011     _num_element = 0;
00012     _vertex_data = 0;
00013     _index_data = 0;
00014   }
00015 
00016   MeshData::~MeshData()
00017   {
00018     NUX_SAFE_DELETE_ARRAY(_vertex_data);
00019     NUX_SAFE_DELETE_ARRAY(_index_data);
00020   }
00021 
00022   bool MeshData::Allocate(int num_mesh_primitive, NuxMeshPrimitiveType primitive_type, int num_element, int element_size)
00023   {
00024     NUX_RETURN_VALUE_IF_FALSE(num_element > 0, false);
00025     NUX_RETURN_VALUE_IF_FALSE(element_size > 0, false);
00026 
00027     NUX_SAFE_DELETE_ARRAY(_vertex_data);
00028     NUX_SAFE_DELETE_ARRAY(_index_data);
00029 
00030     _num_element = num_element;
00031     _element_size = element_size;
00032 
00033     _mesh_primitive_type = primitive_type;
00034     switch(primitive_type)
00035     {
00036     case NUX_MESH_TRIANGLE:
00037       _num_index = num_mesh_primitive * 3;
00038       break;
00039 
00040     case NUX_MESH_TRIANGLE_STRIP:
00041     case NUX_MESH_TRIANGLE_FAN:
00042       _num_index = num_mesh_primitive + 2;
00043       break;
00044 
00045     case NUX_MESH_LINE:
00046         _num_index = num_mesh_primitive * 2;
00047       break;
00048 
00049     case NUX_MESH_LINE_STRIP:
00050     case NUX_MESH_LINE_LOOP:
00051       _num_index = num_mesh_primitive + 1;
00052       break;
00053 
00054     case NUX_MESH_QUAD:
00055       _num_index = num_mesh_primitive * 4;
00056       break;
00057 
00058     case NUX_MESH_QUAD_STRIP:
00059       _num_index = num_mesh_primitive + 2;
00060       break;
00061 
00062     case NUX_MESH_POINT:
00063       _num_index = num_mesh_primitive;
00064       break;
00065     }
00066     _index_size = 4;
00067 
00068     _vertex_data = new unsigned char[num_element * element_size];
00069     _index_data = new unsigned char[_num_index * _index_size];
00070 
00071     return true;
00072   }
00073 
00074 }