21.7 C
New York
Monday, April 28, 2025

Move information effectively to the GPU akin to a group of objects


I’m beginning to work in a physics system, the place there are a number of objects on this planet which can be represented. The present method that I’m contemplating consists of pseudopopia in C, the place every object has information which can be used for illustration, and the info which can be No used to rendering.

Fast instance:

double Object_update(Object *this, double now) {
    double delta = now - this->last_update;
    this->place(0) += this->velocity(0);
    this->place(1) += this->velocity(1);
    this->place(2) += this->velocity(2);
    // Test for collisions and many others.
}
struct Class {
    size_t dimension;
    const struct Class *tremendous;
    double (*replace)(double);
} Object = {
    
};
struct Object {
    struct Class *class;
    double last_update;
    float place(3), rotation(3)(3), velocity(3), mass;
    // Others could be added later, e.g., bounding_box, angular_velocity, drive, torque, and many others.
};

So right here is the issue. If these objects have their place and rotation Embedded in them, so how may (and never the opposite properties) go the GPU to symbolize?

I’ve thought-about storing these particularly In a parallel matrix within the accessible reminiscence of GPU, however that will probably be sophisticated once I discover the previous drawback of sustaining stated contiguous matrix, that’s, eliminating gaps when objects are destroyed, and many others. And it turns into much more sophisticated once I add ‘subclasses’ with further information which can be related to illustration, resembling texture id or meshes, which implies that the weather are now not homogeneous.

How can I preserve the info accessible to GPU in my Object Along with the properties that don’t have to be accessible to GPU?

I may journey them within the rendering loop after which setVertexBytes to the place/rotation information of every object, however that will incur a drawing name per object, which isn’t environment friendly for numerous objects.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles