From 6a37909ee7085ac17d9c2a3ce5fb3cc215d0eea3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 17 Feb 2017 07:13:56 +0100 Subject: [PATCH] Revert "Fix race conditions caused by Array <-> GLBufferObject interactions (Bug #3580)" This reverts commit 115e563a7ab82ffb7679d0427f6952fff95e8b23. --- components/nif/data.cpp | 37 ++++++------------------ components/nifbullet/bulletnifloader.cpp | 7 +++-- components/nifosg/nifloader.cpp | 16 ++++------ 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 082b5aa63..1de7d0966 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -40,45 +40,32 @@ void ShapeData::read(NIFStream *nif) { int verts = nif->getUShort(); - // Assign a VBO right off the bat to avoid race conditions later, in case two threads load this data into a Geometry at the same time - osg::ref_ptr vbo = new osg::VertexBufferObject; - - if(nif->getInt() && verts) - { - vertices = new osg::Vec3Array; + vertices = new osg::Vec3Array; + if(nif->getInt()) nif->getVector3s(vertices, verts); - vertices->setVertexBufferObject(vbo); - } - if(nif->getInt() && verts) - { - normals = new osg::Vec3Array(osg::Array::BIND_PER_VERTEX); + normals = new osg::Vec3Array(osg::Array::BIND_PER_VERTEX); + if(nif->getInt()) nif->getVector3s(normals, verts); - normals->setVertexBufferObject(vbo); - } center = nif->getVector3(); radius = nif->getFloat(); - if(nif->getInt() && verts) - { - colors = new osg::Vec4Array(osg::Array::BIND_PER_VERTEX); + colors = new osg::Vec4Array(osg::Array::BIND_PER_VERTEX); + if(nif->getInt()) nif->getVector4s(colors, verts); - colors->setVertexBufferObject(vbo); - } // Only the first 6 bits are used as a count. I think the rest are // flags of some sort. int uvs = nif->getUShort(); uvs &= 0x3f; - if(nif->getInt() && verts) + if(nif->getInt()) { uvlist.resize(uvs); for(int i = 0;i < uvs;i++) { osg::Vec2Array* list = uvlist[i] = new osg::Vec2Array(osg::Array::BIND_PER_VERTEX); - list->setVertexBufferObject(vbo); nif->getVector2s(list, verts); // flip the texture coordinates to convert them to the OpenGL convention of bottom-left image origin @@ -99,14 +86,8 @@ void NiTriShapeData::read(NIFStream *nif) // We have three times as many vertices as triangles, so this // is always equal to tris*3. int cnt = nif->getInt(); - if (cnt) - { - triangles = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); - nif->getUShorts(triangles, cnt); - - // Assign an EBO right off the bat to avoid race conditions later, in case two threads load this data into a Geometry at the same time - triangles->setElementBufferObject(new osg::ElementBufferObject); - } + triangles = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); + nif->getUShorts(triangles, cnt); // Read the match list, which lists the vertices that are equal to // vertices. We don't actually need need this for anything, so diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index 6a369931a..9ac544c42 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -268,9 +268,7 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, if (shape->data.empty()) return; - - const Nif::NiTriShapeData *data = shape->data.getPtr(); - if (!data->triangles || !data->vertices) + if (shape->data->triangles->empty()) return; if (isAnimated) @@ -280,6 +278,8 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, btTriangleMesh* childMesh = new btTriangleMesh(); + const Nif::NiTriShapeData *data = shape->data.getPtr(); + childMesh->preallocateVertices(data->vertices->size()); childMesh->preallocateIndices(data->triangles->size()); @@ -320,6 +320,7 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, mStaticMesh = new btTriangleMesh(false); // Static shape, just transform all vertices into position + const Nif::NiTriShapeData *data = shape->data.getPtr(); const osg::Vec3Array& vertices = *data->vertices; const osg::DrawElementsUShort& triangles = *data->triangles; diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index a247c62a4..db3f190e4 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -898,10 +898,6 @@ namespace NifOsg osg::BoundingBox box; - osg::Vec3Array* verts = particledata->vertices; - if (!verts) - return; - int i=0; for (std::vector::const_iterator it = partctrl->particles.begin(); iactiveCount && it != partctrl->particles.end(); ++it, ++i) @@ -916,11 +912,11 @@ namespace NifOsg // Note this position and velocity is not correct for a particle system with absolute reference frame, // which can not be done in this loader since we are not attached to the scene yet. Will be fixed up post-load in the SceneManager. created->setVelocity(particle.velocity); - const osg::Vec3f& position = verts->at(particle.vertex); + const osg::Vec3f& position = particledata->vertices->at(particle.vertex); created->setPosition(position); osg::Vec4f partcolor (1.f,1.f,1.f,1.f); - if (particledata->colors.valid() && particle.vertex < int(particledata->colors->size())) + if (particle.vertex < int(particledata->colors->size())) partcolor = particledata->colors->at(particle.vertex); float size = particledata->sizes.at(particle.vertex) * partctrl->size; @@ -1082,7 +1078,7 @@ namespace NifOsg geometry->setVertexArray(data->vertices); - if (data->normals) + if (!data->normals->empty()) geometry->setNormalArray(data->normals); int textureStage = 0; @@ -1100,10 +1096,10 @@ namespace NifOsg geometry->setTexCoordArray(textureStage, data->uvlist[uvSet]); } - if (data->colors) + if (!data->colors->empty()) geometry->setColorArray(data->colors); - if (data->triangles) + if (!data->triangles->empty()) geometry->addPrimitiveSet(data->triangles); // osg::Material properties are handled here for two reasons: @@ -1112,7 +1108,7 @@ namespace NifOsg // above the actual renderable would be tedious. std::vector drawableProps; collectDrawableProperties(triShape, drawableProps); - applyDrawableProperties(parentNode, drawableProps, composite, data->colors.valid(), animflags, false); + applyDrawableProperties(parentNode, drawableProps, composite, !data->colors->empty(), animflags, false); } void handleTriShape(const Nif::NiTriShape* triShape, osg::Group* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector& boundTextures, int animflags)