• Advertisement
Sign in to follow this  

Managing indices, strides, offsets in the engine.

This topic is 710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings.

 

The topic's name is a bit misleading - I didn't know how to best name it. I'll describe here what I'm doing.

 

I'm writing very simple engine for rendering 3d models (surprise!). I want to encapsulate 3d object data in separate class - Object3D. This class have vertex buffers, index buffer, shaders, input layout, rasterizer state. Later I want to draw it but this information that I have in object is not enough. For example, I'm using separate (non-interleaved) vertex buffers for every element and when I'm supplying them to IASetVertexBuffers I need to provide strides and offsets. Offsets are simple in my case - they are all zeroes. With strides I have to use correct numbers, like here:

vector<UINT> strides{ static_cast<UINT>(sizeof(XMFLOAT3)), static_cast<UINT>(sizeof(XMFLOAT3)), static_cast<UINT>(sizeof(uint32_t)) };

Right now I'm supplying manually this values together with all necessary data. But I don't want. I have vertex buffers, input layout but I can't grab this info from there.

 

The next question arises when I'm starting to draw. In DrawIndexed I have to provide number of indices. Again, I can't get this info from my index buffer and I'm supplying this data manually.

 

I hope it's clear what I wrote. Please if you have questions - ask and I'll refine my essay.

Share this post


Link to post
Share on other sites
Advertisement

There's multiple approaches, but in any case you'll have to track your data structure.

 

It might be fixed predefined set of vertex formats, and your data will store code of that format. Strides/offset derived from that code, and you track vertex/index count in buffers.

 

Or it might be flexible system, where each independent data stream tracks its format (data unit type/size, e.g. float4,float2,short4) and units count. More complex system will have Buffer as a collection of data streams, interleaving data for better cache utilization, and tracking each stream semantic id/name for automated shaders binding. "Object3D" will host a collection of Buffers (since indices goes separately from vertex data, and vertex might be composed of multiple data streams, updated with different frequency) and cached vertex declaration.

 

Note that you store app-level Buffer objects, not just D3D bare handles, so you always have data sizes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement