Jump to content

[Render] [Tessellator] Efficiently drawing lines


uranophane

Recommended Posts

In my mod, I have to render many 3d wireframe boxes. There are often thousands of wireframe cubes that need to be rendered, and my existing algorithm doesn't perform well enough (~3-5 FPS on an i7-7700 + GTX 1060).

The code I currently use has the following flow (pseudocode):

startGlState(); // this initializes the GlStateManager
for (pos in coordinates){
	glLineWidth(width); // width varies
	drawBox(pos, color); // both vary
}
endGlState(); // this restores the GlStateManager

drawBox(pos, color){
	getTessellator(); // this instatiates a tessellator
	startBufferBuilding(); // this instantiates a BufferBuilder
	buffer.pos(pos.offset).color(color).endVertex();
    {...}
	tessellator.draw();
}

As it is currently, I must call tesslator.draw() for every coordinate because the thickness of the lines vary. So I tried a new method:

startGlState(); // this initializes the GlStateManager
getTessellator(); // this instatiates a tessellator
startBufferBuilding(); // this instantiates a BufferBuilder
for (pos in coordinates){
	bufferBox(pos, color); // both vary
}
tessellator.draw();
endGlState(); // this restores the GlStateManager

bufferBox(pos, color){
	buffer.pos(pos.offset).color(color).endVertex(); // add the edges of pos to the buffer
    {...}
}

This way, tesselator.draw() only gets called once per set of coordinates. However, line width remains static.

The second way was faster than the first, but not significantly (only a speedup of 2x when the # of calls was reduced by a factor of a few thousand). The result was still unplayable. With this, I came to the conclusion that the vertex buffer was the slowest part.

 

My question is: is there a faster way of drawing simple 3D lines? If so, how should I approach it?

By directly making openGL calls, perhaps?

The wireframe boxes must experience depth clipping along with the rest of the world.

Link to comment
Share on other sites

2 hours ago, uranophane said:

By directly making openGL calls, perhaps?

It's prohibited due to performance, so...

 

Why do you need thousands of wireframe cubes in the first place? I guess that's the part where many optimizations can take in place.

Also it's better not to update thousands of vertices every frame. Store them in a VBO and only update it when it's needed. (AFAIK this is also done with chunk rendering. There should be tools for that)

Don't call draw many times, it should be one main source of lag. Speedup of 2x is really a BIG improvement, actually. Instead, varying width lines can be done better with quads. Just play with some trigs and coordinates to find the orientation.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.