From d594982dd226bcafa349928aca1c8cde50abbc6e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 22 Jan 2004 14:24:51 +0000 Subject: [PATCH] Added support for copying tex coord data directly from prpgGeometry. --- src/osgPlugins/txp/TXPParser.cpp | 21 +++++++++++++++------ src/osgPlugins/txp/trpage_geom.cpp | 8 ++++++++ src/osgPlugins/txp/trpage_geom.h | 7 +++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/osgPlugins/txp/TXPParser.cpp b/src/osgPlugins/txp/TXPParser.cpp index a3a8faec9..e59d276ad 100644 --- a/src/osgPlugins/txp/TXPParser.cpp +++ b/src/osgPlugins/txp/TXPParser.cpp @@ -123,7 +123,7 @@ void TXPParser::replaceTileLod(osg::Group* group) } } -bool TXPParser::StartChildren(void *in) +bool TXPParser::StartChildren(void * /*in*/) { bool pushParent = true; @@ -822,19 +822,23 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) osg::Geometry *geometry = 0L; // Get texture coordinates - trpgTexData td; + ; int num_tex; geom.GetNumTexCoordSets(num_tex); osg::Vec2Array** tex_coords = new osg::Vec2Array*[num_tex]; for (int texno = 0; texno < num_tex; texno++) { tex_coords[texno] = 0L; - if (geom.GetTexCoordSet(texno,&td)) + const trpgTexData* td = geom.GetTexCoordSet(texno); + if (td) { - tex_coords[texno] = new osg::Vec2Array(numVert); - for (int i=0 ;i < numVert; i++) + tex_coords[texno] = new osg::Vec2Array(numVert); + const float* sourcePtr = &(td->floatData[0]); + float* destinationPtr = (float*)&((*tex_coords[texno])[0]); + for (int i=0 ;i < numVert; ++i) { - (*(tex_coords[texno]))[i].set(td.floatData[2*i+0],td.floatData[2*i+1]); + *destinationPtr++ = *sourcePtr++; + *destinationPtr++ = *sourcePtr++; } } } @@ -1085,6 +1089,11 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) } + else + { + std::cout<<"Detected potential memory leak in TXPParerse.cpp"<= (int)texData.size()) return 0; + return &(texData[id]); +} + + bool trpgGeometry::GetNumEdgeFlag(int &n) const { if (!isValid()) return false; diff --git a/src/osgPlugins/txp/trpage_geom.h b/src/osgPlugins/txp/trpage_geom.h index c40269c50..37315e5c2 100644 --- a/src/osgPlugins/txp/trpage_geom.h +++ b/src/osgPlugins/txp/trpage_geom.h @@ -2114,6 +2114,13 @@ public: coordinate sets. */ bool GetTexCoordSet(int id,trpgTexData *) const; + + /* This method returns this trpgGeometry's texture coordinate set specified by the given + index. GetNumTexCoordSets determines the total number of texture + coordinate sets. + */ + const trpgTexData *GetTexCoordSet(int id) const; + /* Returns the number of edge flags in this geometry node. Edge flags are used on certain primitive types, but are rather rare. */