Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
97 views
in Technique[技术] by (71.8m points)

java - How to use function glMultiDrawElementsBaseVertex?

I'm currently trying to use function glMultiDrawElementsBaseVertex? in java with lwjgl and opengl but i have some questions.

first, i stored 2 meshes in one vbo then i want to draw them in one draw call.

so i did

int[] count = new int[] {this.modelManager.getElementCount().get(0), this.modelManager.getElementCount().get(1)};
int[] baseVertex  = new int[] {0, this.modelManager.getElementCount().get(1)};
glMultiDrawElementsBaseVertex(GL_TRIANGLES, count, GL_UNSIGNED_INT, this.modelManager.pointerBuffer, baseVertex);

but im not sure about parameters. "getElementCount" return the numbers of indices for a mesh. "baseVertex" if understand correctly it represent how many objects of each mesh i want to draw. And for pointerBuffer im realy no sure about how i construct it but it store all indices of the two meshes.

this.pointerBuffer = PointerBuffer.create(MemoryUtil.memAddress(indicesBuffer), indices.length);

And for PointerBuffer parameter, i read somewhere that pointerBuffer must be a pointer to array of array but i dont know how to do it. Following image is actually my result, one strangly combined of two mesh but i wanted to draw 100 objects of each mesh. enter image description here

Edit: i forget to say my code works with the following call but it draw only one type of mesh

glDrawElementsInstancedBaseVertex(GL_TRIANGLES, this.modelManager.getElementCount().get(1), GL_UNSIGNED_INT, 0, NB_MAX_OBJECTS, this.modelManager.getElementCount().get(0));
question from:https://stackoverflow.com/questions/65843968/how-to-use-function-glmultidrawelementsbasevertex

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

basevertex specifies a constant that should be added to each element of indices? when chosing elements from the enabled vertex arrays.
If the index of the mesh starts at 0, the basevertex for the 1st mesh must be 0. For the 2nd mesh it must be the number of indices of the 1st mesh:

int[] count = new int[] {
    this.modelManager.getElementCount().get(0), 
    this.modelManager.getElementCount().get(1)
};
int[] baseVertex  = new int[] {
    0,
    this.modelManager.getElementCount().get(0)
};

If you want to draw 1 mesh multiple times, you need to use instancing Instancing. Use glDrawElementsInstanced to draw multiple instances of a set of elements.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...