jfcameron / gdk-graphics

3D Rendering using OpenGLES 2.0/WebGL1.0. Platforms: Linux, Windows, Mac, x86 64bit, arm64, wasm
MIT License
1 stars 1 forks source link

camera: add draw cull visitor #40

Open jfcameron opened 3 years ago

jfcameron commented 3 years ago

drawing as little as possible is a good idea. I dont want this graphics project to depend on a 3d collision library just to provide culling options. its a different problem. plus there are valid reasons a user would want simpler culling rules. a visitor would allow the user to make their own decisions, they could even pull in a collision library themselves.

jfcameron commented 3 years ago

first idea that comes to mind is the standard function pointer + user pointer pattern. before doing that though try to think of more cppy way to do it. it would be nice to avoid a void* but basically, camera would gain a set_cull_visitor and entity would gain a set_cull_user_pointer. overall i feel like this would be out of place in this otherwise very safety oriented project

jfcameron commented 3 years ago

opportunity to use std::any?

entity std::any m_cull_data

camera std::function<void(std::any pCullData)> m_cull_functor

jfcameron commented 3 years ago

Dont add setters, the functor should be provided at construction time. I want to keep things as immutable as possible after construction, its easier to think about and provides opportunity to optimize.

Look into the cost of checking if an any has value and if an any has the expected type. if its expensive then this should be memoized when an entity is added to a scene. e.g: if the entity being added has cull_data then place it in a unordered_map<typeid, unordered_set<shared_ptr>> m_CullEntities, then cameras with cull functors could check that structure instead. but again look into time complexity first