Improve efficiency when drawing 2D elements in d3d9

Source: Internet
Author: User

For example, to draw a rect, the general method is

Vertexbuffer-> lock ();

Fillrectvertex ();

Vertexbuffer-> unlock ();

Settexture ();

Drawprimitive ();

 

The validity rate of drawing multiple 2D elements is very low. The reason is that lock/unlock is called multiple times.

 

 

Improvement Method:

2d element Rendering

Use a unified memory buffer and Command record.

During painting, the vertex data is first filled into the buffer, and the Command record is filled, including the shader, vertex idx/size, and primitive type of the current element.

During actual painting, copy the buffer to the vertex buffer, and then execute the Command record (set shader, drawprimitive (idx, size )), here, we can merge adjacent similar commands (continuous commands with the same shader and primitive type, such as drawtext)

 

Here, the shader contains texture, texture blend (without PS), PS/Vs, and PS/Vs-related change scripts (such as making a game icon, mixed by two layers of texture, one layer Keeps rotating)

 

If necessary, you can also use the zcoordinate to mark the command order. Sort the command before execution (the translucent element is finally drawn). Reduce render state switching.

 

Three ways to draw 2D elements.

Draw all 3D elements first, and then clear Z before drawing 2D, then z can be buffered.

 

1. Use the potion_t vertex format to skip world/view changes. The vertex coordinates are pixel coordinates.

2. Use the world/view matrix of identity to disable illumination. The vertex coordinates are X [-], Y [-], the top and right are positive, and the origin is in the center of the screen/window. The advantage of this method is that the drawing is calculated in percentage and has nothing to do with the resolution.

3. Use vs to skip world/view changes. Similar effects to 2 can also be added with some simple animations.

For example, a rotating windmill directly changes the texture U/V

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.