Page 1 of 1

Odd behaviour in v1::SubMesh when switching from D3D11 to GL

Posted: Tue Nov 17, 2015 7:13 pm
by aymar
For some reason, this code:

Code: Select all

		const Ogre::v1::VertexElement* vertexPositions = submesh->vertexData[0]->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
		Ogre::v1::HardwareVertexBufferSharedPtr vertexBuffer = submesh->vertexData[0]->vertexBufferBinding->getBuffer(vertexPositions->getSource());
		unsigned char* ogreVertices = static_cast<unsigned char*>(vertexBuffer->lock(Ogre::v1::HardwareBuffer::HBL_READ_ONLY));
		for (int i = 0; i < nVertices; ++i, ogreVertices += vertexBuffer->getVertexSize()) {
			float* vertex = NULL;
			vertexPositions->baseVertexPointerToElement(ogreVertices, &vertex);
			Vector3d vertexPosition = position + rotate(orientation, scale*Vector3d(vertex[0], vertex[1], vertex[2]));
			triangleMesh->vertices[offset + 3*i] = vertexPosition.getX();
			triangleMesh->vertices[offset + 3*i + 1] = vertexPosition.getY();
			triangleMesh->vertices[offset + 3*i + 2] = vertexPosition.getZ();
		}		
		vertexBuffer->unlock();
Returns good data when running my app with DirectX 11, but when I change it to OpenGL 3+, it returns NANs and odd data.

That's bizarre since I'm just exploring the mesh vertices, which shouldn't differ between rendersystems.

Am I doing that wrong? Is there any alternate way to retrieve those data?

Thanks in advance.

Re: Odd behaviour in v1::SubMesh when switching from D3D11 t

Posted: Tue Nov 17, 2015 10:55 pm
by dark_sylinc
Looks to me you're not loading the meshes with Ogre::v1::HardwareBuffer::HBU_STATIC, and loads instead with the default HBU_WRITE_ONLY.

In Debug mode it will assert for that.

As the name implies, HBU_WRITE_ONLY means reading is not really allowed (undefined behavior)

Edit: If you did load the mesh with HBU_STATIC (e.g. no assert triggering in debug mode), then update your graphics drivers.

Re: Odd behaviour in v1::SubMesh when switching from D3D11 t

Posted: Wed Nov 18, 2015 12:13 pm
by aymar
I'm not loading the mesh manually, instead, I'm using directly the createEntity method.

Should I be loading the meshes separately before calling createEntity.

Re: Odd behaviour in v1::SubMesh when switching from D3D11 t

Posted: Wed Nov 18, 2015 12:33 pm
by aymar
Nevermind, I managed to load the mesh before sending it to the createEntity using HBU_STATIC, and it worked!

Thanks dark_sylinc.