A text efficient drawing and display method based on 3D rendering engine
By processing multiple text drawings as a rectangle, using multiple texture images to map and optimize resource management, the inefficiency and fluency of large-scale text drawing in the 3D rendering engine is solved, and efficient display on mid- and low-end graphics cards is achieved.
Patent Information
- Application Number
- CN202111331915.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-11
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2041-11-11
AI Technical Summary
In the three-dimensional rendering engine, when traditional methods draw large batches of text, the number of rectangles is huge, resulting in delayed data updates, affecting fluency, and insufficient performance of mid- and low-end graphics cards, high-end graphics cards are too expensive, and they are not suitable for popularization.
Draw text drawings composed of multiple texts as a rectangle, create multiple texture pictures, map a set of text drawings for each picture, optimize resource allocation and recycling, dynamically adjust the texture image area, reduce the number of rectangles, and improve resource utilization.
It realizes efficient display of large batches of text on mid- and low-end graphics cards, improves rendering efficiency and fluency, reduces the number of rectangles, and improves the display effect.
Smart Images

Figure CN114049424B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer graphics processing and display, and in particular to a text efficient drawing and display method based on a three-dimensional rendering engine. Background Art
[0002] The rendering principle of text in 3D engines is actually a relatively mature technology, and the general process is basically the same, such as Figure 1 As shown: First, the font template, that is, the two-dimensional bitmap data of the text, is obtained from the font file, then the font template is converted into a texture image and loaded into the video memory, and finally rendered to the corresponding display position. This whole process can be seen in the patent application of Tencent Technology (Shenzhen) Co., Ltd. - "A Text Rendering Method and Device", and also in the patent application of Wuhan Guoyao Xintiandi Information Technology Co., Ltd. - "A Three-Dimensional Text Stroke Drawing Method", but the emphasis and details of each party are slightly different.
[0003] In a 3D rendering engine, the traditional approach to drawing text is to read each displayed character from a font file, format and store it in a large texture image, establish texture coordinates for each character, and use this texture image to create a Geometry object to draw all the characters. In the Geometry object, each character corresponds to a rectangle, and each rectangle is mapped to the character in the texture image. It can be found that for each displayed character, a corresponding rectangle must be drawn, that is, the number of displayed characters is equal to the number of rectangles. If the number of displayed characters is very large, the number of rectangles that need to be drawn will also be very large. In addition, the dynamic change of the character position requires the dynamic update of the huge amount of rectangle vertex data, which causes delays in data updates and affects the smoothness of text display.
[0004] In 3D rendering engines, text rendering consumes the most resources and has the lowest rendering efficiency compared to the rendering of geometric objects such as points, lines, and planes. In recent years, with the rapid development of graphics card hardware technology, the continuous upgrading of high-performance graphics cards has to some extent alleviated the basic hardware requirements for efficient 3D rendering engines. However, for users who pursue extreme performance or those who seek the best value for money, 3D rendering engines always struggle to achieve the expected performance results when using traditional methods to draw large quantities of text. In other words, with mid-range and low-end graphics cards, the picture is not smooth enough when rendering large quantities of text; while using high-end graphics cards is too expensive and not suitable for widespread application. Summary of the Invention
[0005] To address the above issues, the present invention proposes a method for efficiently drawing and displaying text based on a 3D rendering engine, provides an optimized text drawing method, and focuses on solving the following technical problems:
[0006] (1) Batch texturing is performed for the display and drawing of large quantities of text.
[0007] (2) Balance texture resource utilization and the number of drawn rectangles.
[0008] (3) Resource allocation and recycling issues in batch texturing.
[0009] The optimization scheme of the present invention enables high display efficiency when drawing large quantities of text on mid-to-low-end graphics cards. When the 3D rendering engine of the present invention renders large quantities of text, it can significantly reduce the number of text drawing rectangles, thereby achieving the purpose of optimizing efficiency.
[0010] The technical solution of the present invention is: a method for efficiently drawing and displaying text based on a three-dimensional rendering engine, comprising the following steps:
[0011] Step 1: Draw the entire text drawing composed of multiple characters as a rectangle, read all the characters in the entire text drawing from the font file in advance, and layout them according to the text drawing format, and then output them as a rectangular image;
[0012] Step 2: Create multiple texture images, where the size of the texture images is between half a screen and one screen size.
[0013] Step 3: Map each texture image to a set of text markings, wherein the set of text markings includes multiple entire text markings, each entire text marking corresponds to a rectangular image, and the multiple rectangular images are rearranged and arranged in the texture image; wherein the texture image is cut into multiple rows, and the rectangular images are arranged in the rows during the rearrangement.
[0014] Furthermore, in step 2, when each texture image begins to be created, the internal blank layout area is the size of the texture image, and then the entire text drawing is allocated to it, that is, the rectangular image corresponding to the entire text drawing is typeset into the texture image, and at the same time, the used and unused areas of the texture image are recorded. This process is repeated to allocate all text drawings until the texture image is used up, that is, the texture image has no usable area, or no area of suitable size is allocated to a new text drawing object. At this time, a new texture image can be created again to continue the allocation, and the above process is repeated until all drawn text drawing objects are allocated.
[0015] Furthermore, during the display process, the number of text marking objects also changes dynamically, including both newly added and deleted text markings. For newly added text markings, blank areas are searched in the existing texture image to layout its rectangular image. If no blank area is found, a new texture image is created. For deleted text markings, the texture image area it occupies is recycled and recorded in the blank area list of this texture image so that it can be allocated to other newly added text marking objects.
[0016] Furthermore, for the blank area of the entire texture image, it is divided into rows of rectangular areas to form a row rectangle list marked by row position and row height. The height of the rectangular area of each row in the list is determined by the first text drawing object assigned to this row, and is set to the height of the rectangular image of the text drawing object plus two pixels. The top one pixel height isolates the upper row, and the bottom one pixel height isolates the lower row. In addition to recording the row height, each row also needs to record the horizontal x value of the starting point that can be used for the current row.
[0017] Furthermore, a blank area list is maintained to store those recycled rectangular areas. In the recycled rectangular area list, two adjacent blank rectangular areas in the same row are merged into one blank rectangular area.
[0018] When allocating a texture image area to a text drawing object, you can first query whether there is a matching condition from the list of blank areas in the texture image. If not, query again from the list of row rectangles to see if there is a matching condition. If still not, you can finally create a new texture image to meet the requirements of the text drawing allocation.
[0019] Beneficial effects:
[0020] In existing 3D rendering engines, the original rendering method is optimal for small amounts of text. However, for large amounts of text, the rendering efficiency drops dramatically due to the large number of rendered rectangles. The method of the present invention strikes a balance between the number of rectangles drawn and the utilization of texture image resources, significantly improving the rendering efficiency of large amounts of text. The advantages of the present invention are reflected in the following aspects:
[0021] 1. Rendering efficiency has been greatly improved for large amounts of text and plotting data.
[0022] 2. For mid- and low-end graphics cards, the number of text and graphics that can be displayed has also been greatly improved while ensuring the smoothness of the picture. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 General process of text drawing;
[0024] Figure 2 The rendering engine handles text drawing;
[0025] Figure 3 Mapping multiple text plots to large texture images;
[0026] Figure 4 Multi-texture image mapping multiple sets of text plotting;
[0027] Figure 5 Resource management within texture images. DETAILED DESCRIPTION
[0028] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] The 3D rendering engine has already been optimized for drawing text. However, this optimization strategy is only adopted for drawing small or medium amounts of text. It is not the optimal solution for drawing large quantities of text. The present invention proposes a more targeted optimization method based on the original solution, which is significantly more efficient than the original solution when drawing large quantities of text.
[0030] The following first introduces the original solution of the 3D rendering engine.
[0031] The specific process of the 3D rendering engine for text drawing is as follows: the rendering engine takes each character used in the text drawing from the font file and typesets it into a large texture image. Then, each character in the text drawing generates a rectangular object, and the texture coordinates of each rectangular object are mapped to the corresponding character position in the texture image, thereby realizing text drawing. Figure 2 shown.
[0032] The above process clearly demonstrates the advantages of the rendering engine for text labeling: it maximizes texture image resource utilization and minimizes image memory usage. The more characters in a text label, the higher the probability of repeated characters. A character only needs to be included once in the texture image to be reused across multiple signs. Since the number of characters commonly used is typically limited, the texture image size (and memory usage) is ultimately limited.
[0033] However, this optimization process in the rendering engine also has its flaws. As you can see, each character in each text plot requires a rectangle object to be generated. If the plot contains a large number of characters and the plot itself is also large, you can imagine that the number of rectangle objects that need to be drawn will be very considerable, even massive. This will inevitably overload the rendering engine and affect the frame rate. This is the situation encountered when drawing massive text. Therefore, some improvements can be made to address this problem.
[0034] Since the number of rectangles drawn is too large, we can reduce the number of rectangles by drawing the entire text mark as a rectangle. This requires reading all the text in the text mark from the font file in advance, and formatting it according to the text mark format, and then outputting it into a rectangular image.
[0035] In theory, this output rectangular image can be used as a separate texture image to draw the corresponding text drawing object. However, if we do this, each text drawing corresponds to a separate texture image, that is, each text drawing is drawn using a Geometry object. Although there is a certain optimization effect, it cannot achieve the purpose of batch drawing.
[0036] According to an embodiment of the present invention, the correct approach should be to rearrange these rectangular images and output them to a larger texture image, and then map all text plots to this large texture, thus forming multiple text plots that are drawn using only one Geometry object, thereby achieving batch drawing of text plots, such as Figure 3 shown.
[0037] Even if all text and drawings are typeset into a large texture image, there is still an obvious problem. That is, the size of the texture image will become very large as the number of text and drawings increases, so large that the graphics card will have difficulty loading it. Therefore, further optimization is needed.
[0038] According to an embodiment of the present invention, considering that a large texture image cannot layout all text drawings, the present invention creates multiple texture images, and each texture image maps a group of text drawings. The size of all texture images can be fixed, and the size selection of the texture image needs to be set according to the situation, because if it is too small, not many text drawings can be layouted, and the optimization effect is not obvious; if it is too large, it affects the loading speed of the graphics card and also affects the display effect. Therefore, preferably, the size selection range of the texture image is generally about half the screen size to one screen size, because from common sense, the largest text drawing will definitely not exceed half the screen size, and the graphics card can also quickly load a picture of about the size of a screen. Figure 4 As shown, a picture size of 1024 in both length and width is selected.
[0039] There is one more issue that needs to be addressed, which is the resource allocation and recycling of texture images. Texture image resources have two meanings: one is the blank layout area within each texture image; the other is the total number of texture images.
[0040] When each texture image is created, the blank layout area inside is the size of the texture image. Then you can assign text to it, that is, layout the rectangular image corresponding to the text into the texture image, and record the used and unused areas of the texture image. Loop this process to allocate all text until the texture image is used up, that is, the texture image has no usable area, or no area of suitable size is allocated to the new text object. At this time, you can create a new texture image again to continue the allocation, and loop the above process until all the drawn text objects are allocated.
[0041] During the display process, the number of text drawing objects also changes dynamically, with both new text drawing and deleted text drawing. For new text drawing, we look for blank areas in the existing texture image to layout its rectangular image. If no blank area is found, a new texture image is created. For deleted text drawing, we reclaim the texture image area it occupies and record it in the blank area list of this texture image so that it can be allocated to other new text drawing objects.
[0042] The blank area of the entire texture image can be divided into rows of rectangular areas to form a row rectangle list marked by row position and row height. The height of the rectangular area of each row in the list is determined by the first text drawing object assigned to this row, which is generally the height of the rectangular image of this text drawing object plus two pixels (one pixel height at the top isolates the upper row, and one pixel height at the bottom isolates the lower row). In addition to recording the row height, each row also needs to record the starting point (horizontal x value) that can be used for the current row. In addition, a blank area list needs to be maintained to store those recycled rectangular areas. In the recycled rectangular area list, two adjacent blank rectangular areas in the same row can also be merged into one blank rectangular area, such as Figure 5 shown.
[0043] In this way, when we allocate a texture image area to a text drawing object, we can first query whether there is a matching condition from the list of blank areas in the texture image. If not, we can query again from the list of row rectangles to see if there is a matching condition. If still not, we can finally create a new texture image to meet the requirements of the text drawing allocation.
Claims
1. A method for efficiently drawing and displaying text based on a three-dimensional rendering engine, characterized in that: The steps include: Step 1: Draw the entire text drawing composed of multiple characters as a rectangle, read all the characters in the entire text drawing from the font file in advance, and layout them according to the text drawing format, and then output them as a rectangular image; Step 2: Create multiple texture images, where the size of the texture images is between half a screen and one screen size. Step 3: Map each texture image to a set of text plots, wherein the set of text plots includes multiple whole text plots, each whole text plot corresponds to a rectangular image, and the multiple rectangular images are rearranged and arranged in the texture image; wherein the texture image is cut into multiple rows, and the rectangular images are rearranged and arranged in the rows; In step 2, when each texture image is initially created, the internal blank layout area is the size of the texture image, and then the entire text drawing is allocated to it, that is, the rectangular image corresponding to the entire text drawing is typeset into the texture image, and the used and unused areas of the texture image are recorded at the same time. This process is repeated to allocate all text drawings until the texture image is used up, that is, there is no usable area of the texture image, or no area of suitable size is allocated to a new text drawing object. At this time, a new texture image is created again to continue the allocation, and the above process is repeated until all drawn text drawing objects are allocated; During the display process, the number of text drawing objects changes dynamically, with both new and deleted text drawing objects. For new text drawing objects, blank areas are searched for in the existing texture image to layout its rectangular image. If no blank area is found, a new texture image is created. For deleted text drawing objects, the texture image area occupied by it is recycled and recorded in the blank area list of this texture image so that it can be allocated to other new text drawing objects. For the blank area of the entire texture image, divide it into rows of rectangular areas, forming a row rectangle list marked by row position and row height. The height of the rectangular area of each row in the list is determined by the first text drawing object assigned to this row, and is set to the height of the rectangular image of the text drawing object plus two pixels. The top pixel height isolates the upper row, and the bottom pixel height isolates the lower row. In addition to recording the row height, each row also needs to record the horizontal x value of the starting point that can be used for the current row; Maintain a blank area list to store those recycled rectangular areas. In the recycled rectangular area list, two adjacent blank rectangular areas in the same row are merged into one blank rectangular area. When allocating a texture image area to a text drawing object, first query whether there is a matching area from the list of blank areas in the texture image. If not, query whether there is a matching area from the list of row rectangles. If still not, finally create a new texture image to meet the requirements of the text drawing allocation.
Citation Information
Patent Citations
Map drawing method and device
CN110956673A