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

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
aymar
Greenskin
Posts: 145
Joined: Fri Jun 12, 2015 6:53 pm
Location: Florianopolis, Brazil
x 17

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

Post 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.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

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

Post 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.
aymar
Greenskin
Posts: 145
Joined: Fri Jun 12, 2015 6:53 pm
Location: Florianopolis, Brazil
x 17

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

Post 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.
aymar
Greenskin
Posts: 145
Joined: Fri Jun 12, 2015 6:53 pm
Location: Florianopolis, Brazil
x 17

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

Post by aymar »

Nevermind, I managed to load the mesh before sending it to the createEntity using HBU_STATIC, and it worked!

Thanks dark_sylinc.
Post Reply