VBO and shaders confusion, what's their connection?
- by Jeffrey
Considering OpenGL 2.1 VBOs and 1.20 GLSL shaders:
When creating an entity like "Zombie", is it good to initialize just the VBO buffer with the data once and do N glDrawArrays() calls per each N zombies? Is there a more efficient way? (With a single call we cannot pass different uniforms to the shader to calculate an offset, see point 3)
When dealing with logical object (player, tree, cube etc), should I always use the same shader or should I customize (or be able to customize) the shaders per each object?
Considering an entity class, should I create and define the shader at object initialization?
When having a movable object such as a human, is there any more powerful way to deal with its coordinates than to initialize its VBO object at 0,0 and define an uniform offset to pass to the shader to calculate its real position?
Could you make an example of the Data Oriented Design on creating a generic zombie class? Is the following good?
Zombielist class:
class ZombieList {
GLuint vbo; // generic zombie vertex model
std::vector<color>; // object default color
std::vector<texture>; // objects textures
std::vector<vector3D>; // objects positions
public:
unsigned int create(); // return object id
void move(unsigned int objId, vector3D offset);
void rotate(unsigned int objId, float angle);
void setColor(unsigned int objId, color c);
void setPosition(unsigned int objId, color c);
void setTexture(unsigned int, unsigned int);
...
void update(Player*); // move towards player, attack if near
}
Example:
Player p;
Zombielist zl;
unsigned int first = zl.create();
zl.setPosition(first, vector3D(50, 50));
zl.setTexture(first, texture("zombie1.png"));
...
while (running) { // main loop
...
zl.update(&p);
zl.draw(); // draw every zombie
}