Let say I have couple of thousands moving objects in my scene and i want to use frustum-sphere test to cull invisible ones.
Then in my code i have something like this:
struct BoundingSphere
{
float x, y, z, radius;
};
struct ObjectsDetailPool
{
BoundingSphere bs[MAX_OBJECTS];
uint64_t visible[MAX_OBJECTS]; // 64 possible views
DrawableThing dt[MAX_OBJECTS]; // mesh data
};
struct Object
{
BoundingSphere* pbs;
uint64_t* pvisible;
DrawableThing* pdt;
};
vector<Object> vobjs;
... //here cull for all views
// draw
if(vobjs.empty())
return;
...//set shader...
for(auto& obj : vobjs)
{
if(obj.pvisible ...) // this is bad?
obj.draw();
}
...// repeat draw for each view
But lot of texts say this is bad because of branch mispredictions and what not, usually there is a lot of criticism but none of the solutions shown.
I dont understand how should i construct/manage this list then?
Should i partition the vector? So i swap-back invisible objects and store iterator where visible ends, but then again i have a branch because i need to check if it is visible.
Create a new vector and push_back only visible objects? But then again i have a branch because i need to check if it is visible.