Updating subset of vertex buffer

Started by
3 comments, last by tonemgub 9 years, 3 months ago

Hello,

In the past I've built a pretty simple OpenGL text rendering engine that uses the AngelCode BMFont library. I'm currently in the process of converting it to DirectX. As I'm doing my conversion, I'm looking for ways that I could improve my logic. I'm still very much a beginner, and was hoping to be pointed in the right direction to optimize my engine.

The application is a console emulator. It displays 101 characters by 36 characters, totalling to 3636 characters that can be displayed simultaneously. The amount of characters only changed when the user resizes the console app.

Right now, I'm just using a large vertex buffer, rendering it with DrawPrimitive on every paint. Sometimes, all of the vertices change, but it also happens that only a small subset of the vertices are updated as I might be only updating a few characters. For now, this does the job just fine, but I'm most likely going to be adding Direct2D support to this engine, so I'd like to minimize the work that I'm going to be doing with the bitmap font rendering part of the engine.

What should I do so that when I only need to update a couple characters, so I don't have to send the whole vertex back to the GPU?

Thoughts?

TL;DR - bitmap font rendering engine. currently using 1 vertex buffer. how to optimize for times where only a small part of the VB gets changed?

Advertisement

I don't know a lot of specifics about the AngelCode library. In my experience you can get better performance by staying with Direct3D rather than going to Direct2D. YMMV. If you stick to D3D, one thing you could do in D3D9 is to fill your vertex buffer with all possible geometry one time at initialization and then use a much smaller constant buffer for per-frame values that need to change. With the appropriate shaders you can use your constant buffer to enable/disable quads, translate them around the screen, color them, u/v animate them, scale them, rotate them, etc. You could also relink textures to each quad per-frame using a different API. All of this is done to avoid locking, modifying and unlocking all or part of the original VB you spoke of (which would be the simpler (e.g. less code to write) way of doing this).

https://www.opengl.org/sdk/docs/man/html/glBufferSubData.xhtml or https://www.opengl.org/sdk/docs/man2/xhtml/glMapBuffer.xml ?

The OP is trying to move to DirecX from OpenGL

You could also use render-to-texture to keep a view of your existing console buffer already rendered, then just render the modified characters on top of it. You'd only be sending the vertices for the modified characters this way. Or instead of rendering to a new texture, simply skip using Clear every frame, so that you just draw the changed characters on top of the old backbuffer. There are also some specific swap-chain creation flags you have to use so that the contents of the backbuffer are preserved from one frame to another. You'll have to experiment a bit to find the proper ones - I can't remember what they are exactly.

This topic is closed to new replies.

Advertisement