Giter VIP home page Giter VIP logo

Comments (4)

john-chapman avatar john-chapman commented on June 8, 2024 1

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.

john-chapman avatar john-chapman commented on June 8, 2024 1

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.

john-chapman avatar john-chapman commented on June 8, 2024 1

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.

KenzieMac130 avatar KenzieMac130 commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.