[2.1] Cannot get dynamic buffers to work

Problems building or running the engine, queries about how to use features etc.
Post Reply
mrmclovin
Goblin
Posts: 292
Joined: Sun May 11, 2008 9:27 pm
x 8

[2.1] Cannot get dynamic buffers to work

Post by mrmclovin » Sun Jul 14, 2019 12:09 pm

Ogre Version: 2.1 :?:
Operating System: macOs :?:
Render System: Metal :?:

I'm experimenting with Ogre's dynamic buffers but I have a problem that I'm unable to solve.

I'm creating a simple vertex buffer containing a square made up of two triangles (ie. 6 verts):

Code: Select all

VertexElement2Vec vertexElements;
  vertexElements.push_back(VertexElement2(VET_FLOAT3, VES_POSITION));
  ...
  vertexBuffer = vaoManager->createVertexBuffer(vertexElements, 6,
                                                  Ogre::BT_DYNAMIC_PERSISTENT,
                                                  initialVertices, false);
I assign a material and attach the Item which the buffer is associated with on a SceneNode and I can see the blue square on screen:

Image

The problem is that the buffer seems like it does not get updated during my map/unmap calls.
I try to set all verts to zeros just for debugging purposes:

Code: Select all

float *RESTRICT_ALIAS verts = reinterpret_cast<float * RESTRICT_ALIAS>(vertexBuffer->map(0, 6));

  const auto x = 0;
  const auto y = 1;
  const auto z = 2;
  int        j = 0;
  for (int i = 0; i < 2; ++i) {
    verts[x]                = 0;
    verts[y]                = 0;
    verts[z]                = 0;

    verts[3 + x] = 0;
    verts[3 + y] = 0;
    verts[3 + z] = 0;

    verts[6 + x] = 0;
    verts[6 + y] = 0;
    verts[6 + z] = 0;
    verts += 9;
  }

  vertexBuffer->unmap(Ogre::UO_KEEP_PERSISTENT);
But I can still see the blue triangle. Like my map call never affected the buffer. I can confirm the map/unmap are being called due to breakpoints. Given the rough/simplified code that I gave you, should I expect it work or am I misunderstanding how map/unmap works?
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4118
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 244
Contact:

Re: [2.1] Cannot get dynamic buffers to work

Post by dark_sylinc » Mon Jul 15, 2019 3:49 am

Everything you wrote appears correct at a simple glance, though the way you're zero-ing the buffer looks confusing and error-prone.

Perhaps the issue is somewhere else, like the wrong vertex buffer being assigned to the VertexArrayObject; or the wrong VertexArrayObject being assigned to the Renderable (hence the vertex buffer you're modifying is not actually the one that gets used).

If you post more code there may be something that could be spotted.

It may be a bug specific to Metal. If you're able to test your code on another platform (e.g. Windows or Linux) it may be worth it.

Compare your code against the one in DynamicGeometryGameState.cpp sample (which modifies dynamic vertex buffers every frame)

Cheers
Matias
0 x

mrmclovin
Goblin
Posts: 292
Joined: Sun May 11, 2008 9:27 pm
x 8

Re: [2.1] Cannot get dynamic buffers to work

Post by mrmclovin » Thu Jul 18, 2019 12:22 am

dark_sylinc wrote:
Mon Jul 15, 2019 3:49 am
Perhaps the issue is somewhere else, like the wrong vertex buffer being assigned to the VertexArrayObject; or the wrong VertexArrayObject being assigned to the Renderable (hence the vertex buffer you're modifying is not actually the one that gets used).
Indeed, it was probably an issue with referencing a duplicated buffer. I messed around for a bit and refactored my code so that I attached the buffers to a MeshPtr (using MeshManager::createMesh()), rather than doing a MovableObject/Renderable inherited class.

Anyway, thanks to your answer I was able to look at other places and eventually found the error. Thanks.
0 x

Post Reply