#if defined(_MSC_VER) #pragma warning( disable : 4786 ) #endif #include #include #include #include #include #include //#include using namespace osg; GeoSet::GeoSet() { // we will use the a default delete functor which // assumes that users have allocated arrays with new only // and that now sharing of attributes exists between GeoSet's. _adf = new AttributeDeleteFunctor; _coords = (Vec3 *)0; _normals = (Vec3 *)0; _colors = (Vec4 *)0; _tcoords = (Vec2 *)0; _iarray = (float *)0L; _iaformat = IA_OFF; _ogliaformat = 0; _numprims = 0; _primtype = NO_TYPE; _oglprimtype = 0xFFFF; _needprimlen = 0; _primLengths = (int *)0; _numcoords = 0; _normal_binding = BIND_OFF; _color_binding = BIND_OFF; _texture_binding = BIND_OFF; _fast_path = 1; // cout << endl << "Above allocated"<* ma = newMemoryAdapter::instance(); // mem_ptr coords(ma->allocate(100),ma); // cout << "Registered"<getPrimLengths(); delete [] gset->getCoords(); INDEX_ARRAY_DELETE(gset->getCoordIndices()) delete [] gset->getNormals(); INDEX_ARRAY_DELETE(gset->getNormalIndices()); delete [] gset->getColors(); INDEX_ARRAY_DELETE(gset->getColorIndices()); delete [] gset->getTextureCoords(); INDEX_ARRAY_DELETE(gset->getTextureIndices()) // can't delete a void* right now... interleaved arrays needs to be reimplemented with a proper pointer.. // delete [] gset->getInterleavedArray(); INDEX_ARRAY_DELETE(gset->getInterleavedIndices()); } #undef INDEX_ARRAY_DELETE GeoSet::~GeoSet() { // if attached call the adf do delete the memory. if (_adf.valid()) (*_adf)(this); } void GeoSet::setColorBinding( const BindingType binding ) { if( binding != BIND_DEFAULT && binding != BIND_OFF && binding != BIND_OVERALL && binding != BIND_PERPRIM && binding != BIND_PERVERTEX ) _color_binding = BIND_OFF; else _color_binding = binding; if( _color_binding == BIND_DEFAULT ) _color_binding = BIND_PERVERTEX; set_fast_path(); } void GeoSet::setNormalBinding( const BindingType binding ) { if( binding != BIND_DEFAULT && binding != BIND_OFF && binding != BIND_OVERALL && binding != BIND_PERPRIM && binding != BIND_PERVERTEX ) _normal_binding = BIND_OFF; else _normal_binding = binding; if( _normal_binding == BIND_DEFAULT ) _normal_binding = BIND_PERVERTEX; set_fast_path(); } void GeoSet::setTextureBinding( const BindingType binding ) { if( binding != BIND_DEFAULT && binding != BIND_OFF && binding != BIND_PERVERTEX ) _texture_binding = BIND_OFF; else _texture_binding = binding; if( _texture_binding == BIND_DEFAULT ) _texture_binding = BIND_PERVERTEX; set_fast_path(); } void GeoSet::drawImmediateMode(State&) { if( _coords == (Vec3 *)0 && _iaformat == IA_OFF ) return; // need to do this to get a valid _numcoords, _numindices & _primlength if( _numcoords == 0 ) computeNumVerts(); if( _fast_path ) draw_fast_path(); else draw_alternate_path(); } void GeoSet::computeNumVerts() const { int i; int numverts=0; int flat_shaded_offset=0; if (_primtype == FLAT_LINE_STRIP) flat_shaded_offset=_numprims; else if (_primtype == FLAT_TRIANGLE_STRIP) flat_shaded_offset=2*_numprims; else if (_primtype == FLAT_TRIANGLE_FAN) flat_shaded_offset=2*_numprims; switch( _primtype ) { case POINTS : _primlength = 1; numverts = _numprims * _primlength; break; case LINES : _primlength = 2; numverts = _numprims * _primlength; break; case TRIANGLES : _primlength = 3; numverts = _numprims * _primlength; break; case QUADS : _primlength = 4; numverts = _numprims * _primlength; break; case QUAD_STRIP : case FLAT_TRIANGLE_FAN : case TRIANGLE_FAN : case LINE_LOOP : case LINE_STRIP : case FLAT_LINE_STRIP : case TRIANGLE_STRIP : case FLAT_TRIANGLE_STRIP : case POLYGON : _primlength = 0; numverts = 0; for( i = 0; i < _numprims; i++ ) numverts += _primLengths[i]; break; default: notify(WARN) << "Not supported primitive "<<(int)_primtype<