Comments (4)
Hi - thanks for clarifying the issue! I think I understand better now: all you really want is to know the total number of vertices that will be drawn before the callbacks happen, so that you can (re)allocate your vertex buffer up front.
Actually this is already possible but it's a sort of 'backdoor' in the API and looks hacky:
U32 totalVertices = 0;
totalVertices += GetContext().getPrimitiveCount(DrawPrimitive_Triangles) * 3;
totalVertices += GetContext().getPrimitiveCount(DrawPrimitive_Lines) * 2;
totalVertices += GetContext().getPrimitiveCount(DrawPrimitive_Points) * 1;
U32 allocationSize = totalVertices * sizeof(VertexData);
Of course, this information is only accurate at the time you call Draw()
- if you do any Im3d::
calls between allocating the buffer and calling Draw()
(or MergeContexts()
for a multi-context setup), your buffer will be the wrong size!
I'm thinking about ways to enforce this ordering constraint via the API. The best solution I can think of is to have the callback called only once, so that the app can consume all of the pending draw lists at once and have global info about the frame, e.g.:
void Im3d_Draw(const Im3d::DrawList _drawList[], int _drawListCount)
{
// loop over all the draw lists and count vertices
// (re)allocate resources
// issue draw calls
Right now I don't see any negative implications of doing it this way (I can still support the old-style callback) and it maintains the single point of contact between the app and the draw data (which I think simplifies things a lot).
Any additional thoughts or ideas are appreciated!
from im3d.
Ok, so having 'direct' access to the draw data is possible but will require a couple of changes to the API. Right now, calling Draw()
finalizes the draw data internally (really this just means doing the sorting), and then calls the app callback. So this finalization step would still need to happen, however I'd probably move it to an EndFrame()
function - after calling this the draw lists would be available until you call NewFrame()
again.
I think I'm happy with doing it this way, rather than adding a new type of callback. I'll therefore mark this issue as 'todo' and put it at the top of my list. Thanks again for your input!
from im3d.
The new API is now available in version v1.13. The examples have been updated to use the new API (draw callback is marked deprecated but I'll probably not remove it any time soon).
Thanks again for your valuable input!
from im3d.
Thank you very much for the response and recommendation on a workaround.
The callback with a list of commands seems like a much better way to approach it.
If I may bring in another library for an example for a moment, ImGui has made the render callback function obsolete (still available by default though) and instead recommends the user call a function GetDrawData() when they need access to draw lists from the library.
In the case where the users might want to distribute the draw call recording/buffer management payload between threads this method of direct access would be the best way to do it, only requiring the threads to all sync with the get list function. Instead of having to be invoked or wrangled by a callback.
from im3d.
Related Issues (20)
- Intersect(Ray, Capsule) HOT 1
- plane drawing issue in local mode HOT 1
- memory leak HOT 3
- Add IM3D_API macro for dll export HOT 2
- Detect NaNs
- wrong behavior when scale the model HOT 3
- Prevent gizmo flip while gizmo is in use
- Question: How to draw multiple shapes in different locations? HOT 2
- Depth testing for Triangle primitives HOT 4
- Custom include for im3d_config.h HOT 1
- Ids don't get reset if some control is still active and no subsequent Im3d::Gizmo call HOT 1
- Plug into existing application HOT 1
- im3d default Camera model does not suppot aspect ratio on height HOT 4
- is it possible to make this tools usable for qt? HOT 1
- Deal with transformed world coordinates. HOT 1
- C Bindings HOT 1
- Question: Weird plane orientation HOT 4
- OSX support HOT 4
- Default IM3D_MALLOC/IM3D_FREE macros should be defined in `im3d.h` HOT 6
- Consider to split `AppData::m_appData` into platform and renderer depended
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from im3d.