A texture-based triangle character representation and instantiation rendering method and system
By converting character outlines into ordered vertex sequences and encoding them into textures, the matching problem when scaling and rotating dot matrix character data in the prior art is solved, and efficient and correct drawing of glyph features is achieved.
Patent Information
- Application Number
- CN202210250365.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-15
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2042-03-15
AI Technical Summary
The prior art cannot fully match the device pixels when scaling and rotating dot matrix character data, resulting in unreasonable drawing of glyph features, resulting in problems such as glyph distortion and blurred display.
The texture-based triangle character representation and instantiation rendering method are adopted to ensure the consistency of character data storage form in the CPU and GPU by converting the character outline into an ordered vertex sequence and encoding it into a texture using the tree splitting method.
It effectively solves the matching problem when scaling and rotating the dot matrix data, ensures the correct drawing of glyph features, and avoids glyph distortion and blurred display.
Smart Images

Figure CN114627212B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of character drawing, and in particular to a texture-based triangle-band character representation and instantiation rendering method and system. Background Art
[0002] Text is an important symbol of human civilization, and supporting the visualization of text is a problem that computer graphics must face and solve. There are many types of text in human history, and fonts have different measurement and usage standards depending on the different needs of practicality and artistry. Therefore, it is a complex problem to effectively describe and render characters.
[0003] In the development of computer graphics, character visualization mainly includes the early classic bitmap font description and 2D block rendering method and the modern vector font description and dot matrix filling rendering method.
[0004] Modern vector fonts, such as TrueType fonts, use key points and mathematical curves to describe the outline of characters. When rendering, the key points are connected to generate the character outline, and the characters are drawn by filling the outline with dots. Due to the combination of B-spline curves and straight lines, this method can express the outline characteristics of characters very well. In addition, thanks to the mathematical description method, this method has vector characteristics and does not have scaling problems. However, when rendering, it is similar to common GPU drawing schemes and classic bitmap fonts. Its essence is to generate dot matrix data and use textures to achieve text rendering. This makes the character data lose its vector characteristics and return to pixel mode, so there are scaling and rotation problems. Specifically, in application scenarios such as map annotation symbol display, scaling and rotating dot matrix data may make it unable to fully match the device pixels, resulting in unreasonable drawing of glyph features, such as glyph distortion and blurred display.
[0005] Therefore, there is an urgent need in the art for a technical solution that can ensure that the demand for large-scale reuse of fonts is met while achieving efficient and correct drawing of characters. Summary of the invention
[0006] The purpose of the present invention is to provide a texture-based triangle-band character representation and instantiation rendering method and system, which always uses texture as the medium for transmitting data in hardware, ensuring the consistency of the storage form of character data in the CPU and GPU, and adopts a triangle-band character description and re-interpretation instantiation rendering method to effectively solve the problem in the prior art that when scaling and rotating dot matrix data, it cannot be completely matched with device pixels, resulting in unreasonable drawing of glyph features, resulting in problems such as glyph distortion and blurred display.
[0007] To achieve the above object, the present invention provides the following solutions:
[0008] A texture-based triangle character representation and instantiation rendering method, the method comprising:
[0009] Get the outline of the character to be drawn;
[0010] Convert the outline of each character into an ordered vertex sequence using triangle strips;
[0011] Encoding the ordered vertex sequence into a texture by using a tree splitting method, and recording a row index of each ordered vertex sequence in the texture;
[0012] transferring the texture and the row index to a video memory;
[0013] Writing a decoder according to the correspondence between the texture and the ordered vertex sequence;
[0014] Obtaining the texture of a specified character; the specified character is a character that needs to be displayed;
[0015] Decoding the texture of the designated character using the decoder to obtain an ordered vertex sequence;
[0016] The designated character is displayed according to the ordered sequence of vertices.
[0017] In some embodiments, obtaining the outline of the character to be drawn specifically includes:
[0018] Loading a font file, and generating all characters in the font file according to a specified font size;
[0019] Get the outline of each character.
[0020] In some embodiments, converting the outline of each character into an ordered vertex sequence using a triangle strip specifically includes:
[0021] Performing triangular-band-based surface subdivision on each part constituting the contour to obtain a plurality of triangular bands;
[0022] Connecting the beginning and the end of the plurality of triangle strips by using a degenerate triangle method to obtain a triangle strip representation of the contour, that is, a single triangle strip representing each contour;
[0023] Each vertex of the single triangle belt is organized into an ordered vertex sequence according to the inherent order of the triangle belt.
[0024] In some embodiments, after converting the outline of each character into a triangle strip primitive to obtain an ordered vertex sequence, the method further includes:
[0025] The coordinates of each vertex in the ordered vertex sequence are normalized.
[0026] In some embodiments, encoding the ordered vertex sequence into a texture using a tree splitting method and recording a row index of each ordered vertex sequence specifically includes:
[0027] Use the tree splitting method to encode each vertex coordinate into RGBA color information;
[0028] All vertices of a single character are stored in a specified row in a texture bitmap, and the row index of the specified row is recorded to obtain a texture and a row index.
[0029] In some embodiments, displaying the specified character according to the ordered vertex sequence specifically includes:
[0030] According to the ordered vertex sequence, the coordinate transformation and color scheme required for drawing are applied, and the triangle strip drawing method of the GPU is used to complete the character drawing.
[0031] The present invention also provides a texture-based triangle character representation and instantiation rendering system, the system comprising:
[0032] A contour acquisition unit, used to acquire the contour of the character to be drawn;
[0033] An ordered vertex sequence acquisition unit, used for converting the outline of each character into an ordered vertex sequence using a triangle strip;
[0034] An encoding unit, used for encoding the ordered vertex sequence into a texture by using a tree splitting method, and recording a row index of each ordered vertex sequence in the texture;
[0035] A transmission unit, used for transmitting the texture and the row index to a video memory;
[0036] A decoder writing unit, used for writing a decoder according to the correspondence between the texture and the ordered vertex sequence;
[0037] A designated character texture acquisition unit is used to acquire the texture of a designated character; the designated character is a character that needs to be displayed;
[0038] A decoding unit, configured to decode the texture of the designated character using the decoder to obtain an ordered vertex sequence;
[0039] A display unit is used to display the specified character according to the ordered vertex sequence.
[0040] In some embodiments, converting the outline of each character into an ordered vertex sequence using a triangle strip specifically includes:
[0041] Performing triangular-band-based surface subdivision on each part constituting the contour to obtain a plurality of triangular bands;
[0042] Connecting the beginning and the end of the plurality of triangle strips by using a degenerate triangle method to obtain a triangle strip representation of the contour, that is, a single triangle strip representing each contour;
[0043] Each vertex of the single triangle belt is organized into an ordered vertex sequence according to the inherent order of the triangle belt.
[0044] In some embodiments, encoding the ordered vertex sequence into a texture using a tree splitting method and recording a row index of each ordered vertex sequence specifically includes:
[0045] Use the tree splitting method to encode each vertex coordinate into RGBA color information;
[0046] All vertices of a single character are stored in a specified row in a texture bitmap, and the row index of the specified row is recorded to obtain a texture and a row index.
[0047] In some embodiments, displaying the specified character according to the ordered vertex sequence specifically includes:
[0048] According to the ordered vertex sequence, the coordinate transformation and color scheme required for drawing are applied, and the triangle strip drawing method of the GPU is used to complete the character drawing.
[0049] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0050] The present invention discloses a texture-based triangle-belt character representation and instantiation rendering method and system, comprising the following steps: first, converting the character outline into a corresponding ordered vertex array based on the triangle-belt basic graphic element. Then, using an encoder, the vertex coordinates are encoded into a texture. And then, the texture is transferred to a video memory, and then, the texture is decoded into coordinate data under standardized device coordinates by a decoder to complete the drawing of the character. It always uses texture as a medium for data transmission in hardware, ensuring the consistency of the storage form of character data in the CPU and GPU, and adopts a triangle-belt character description and re-interpretation instantiation rendering method, which effectively solves the problem in the prior art that the scaling and rotation of dot matrix data cannot be fully matched with the device pixels, resulting in unreasonable drawing of glyph features, and problems such as glyph distortion and blurred display. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0052] Figure 1A flow chart of a texture-based triangle character representation and instantiation rendering method provided in Embodiment 1 of the present invention.
[0053] Figure 2 An overall schematic diagram of the texture-based triangle character representation and instantiation rendering method provided in the first embodiment of the present invention.
[0054] Figure 3 A schematic diagram of the degenerate triangle method provided in Example 1 of the present invention.
[0055] Figure 4 This is a schematic diagram of the effect of drawing a character represented by a single triangle strip in wireframe mode provided in the first embodiment of the present invention.
[0056] Figure 5 A schematic diagram of designing an encoder using a tree splitting method provided in Embodiment 1 of the present invention.
[0057] Figure 6 This is a schematic diagram of the storage structure of the converted color data provided in the first embodiment of the present invention.
[0058] Figure 7 A schematic diagram of a texture sample after encoding provided in the first embodiment of the present invention.
[0059] Figure 8 A schematic diagram of data stored in a video memory provided in the first embodiment of the present invention.
[0060] Fig. 9 This is a schematic diagram of the effects of character drawing under different scaling and rotation conditions provided by the first embodiment of the present invention.
[0061] Fig.10 A block diagram of a texture-based triangle character representation and instantiation rendering system provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0062] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of 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.
[0063] The purpose of the present invention is to provide a texture-based triangle-band character representation and instantiation rendering method and system, which always uses texture as the medium for transmitting data in hardware, ensuring the consistency of the storage form of character data in the CPU and GPU, and adopts a triangle-band character description and re-interpretation instantiation rendering method to effectively solve the problem in the prior art that when scaling and rotating dot matrix data, it cannot be completely matched with device pixels, resulting in unreasonable drawing of glyph features, resulting in problems such as glyph distortion and blurred display.
[0064] Bitmap fonts were first proposed in the article "A Simple OpenGL-based API for Texture Mapped Text" (Mark Kilgard, 1997) to solve the problem that OpenGL does not have a native character rendering API. This method uses texture as a carrier, loads all characters into a bitmap in the form of texture, determines the character texture range to be sampled by specifying texture coordinates, and draws the extracted texture color onto a pre-set 2D block to achieve text rendering. Although bitmap fonts are simple to implement and have good performance because the text has been pre-described as a texture, due to its resolution-dependent characteristics, corresponding bitmap data must be generated for different scaling conditions, so the flexibility is limited. Later, in the article "Improved Alpha-Tested Magnification for Vector Textures and Special Effects." (GREEN, 2007), it was proposed to use the signed distance field (SDF) method to replace bitmap characters. Although this method is efficient, it still has aliasing problems when the resolution is very high.
[0065] Modern vector fonts, such as TrueType fonts, use key points and mathematical curves to describe the outline of characters. When rendering, the key points are connected to generate the character outline, and the characters are drawn by filling the outline with dots. Due to the combination of B-spline curves and straight lines, this method can express the outline characteristics of characters very well. In addition, thanks to the mathematical description method, this method has vector characteristics and does not have scaling problems. However, when rendering, it is similar to common GPU drawing schemes and classic bitmap fonts. Its essence is to generate dot matrix data and use textures to achieve text rendering. This makes the character data lose its vector characteristics and return to pixel mode, so there are scaling and rotation problems. Specifically, in application scenarios such as map annotation symbol display, scaling and rotating dot matrix data may make it unable to fully match the device pixels, resulting in unreasonable drawing of glyph features, such as glyph distortion and blurred display.
[0066] In order to correctly represent the glyph features in a wider range of application scenarios, the mismatch between data and device pixels should be avoided as much as possible. The ideal character drawing method is to keep the vector state of the data throughout the rendering process, but it is difficult to achieve a good balance between the relevant expression and rendering in terms of reuse and efficiency. Therefore, how to ensure that the demand for large-scale reuse of fonts is met while achieving efficient and correct drawing of characters is an urgent problem to be solved in the application process such as electronic maps.
[0067] The present invention discloses a texture-based triangle-band character representation and instantiation rendering method, comprising the following steps: first, converting a vector font into a corresponding ordered vertex array based on the triangle band as a basic graphic element. Then, using an encoder, the vertex coordinates are encoded into texels and saved as a texture. Secondly, in the character instantiation rendering process, the texture is transferred to the video memory, and the texel information is extracted by a sampler in the vertex shader, and the texel is decoded into coordinate data under standardized device coordinates by a decoder. Finally, the drawing of the character is completed. The present invention always uses texture as a medium for data transmission in hardware, ensuring the consistency of the storage form of character data in the CPU and GPU; and using the triangle-band character description and re-interpretation instantiation rendering method, it is possible to draw all the characters required for a single frame in a single drawing call. The method of the present invention allows large-scale reuse of fonts while achieving efficient and correct drawing of characters.
[0068] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0069] Embodiment 1:
[0070] like Figure 1 As shown, this embodiment provides a texture-based triangle character representation and instantiation rendering method, the method comprising:
[0071] S1. Obtain the outline of the character to be drawn.
[0072] First, a font file is loaded, the font size is specified according to the application scenario and application requirements, all characters in the font file are generated according to the specified font size, and then the outline of each character is obtained.
[0073] S2. Convert the outline of each character into an ordered vertex sequence using triangle strip primitives.
[0074] First, the parts constituting the contour are subdivided based on a triangular strip to obtain a plurality of triangular strips;
[0075] Connecting the beginning and the end of the plurality of triangle strips by using a degenerate triangle method to obtain a triangle strip representation of the contour, that is, a single triangle strip representing each contour;
[0076] Each vertex of the single triangle belt is organized into an ordered vertex sequence according to the inherent order of the triangle belt.
[0077] As an optional implementation, in step S1, the font size is measured in "points" in typesetting and printing, and the font size rules are consistent with the character printing typesetting rules. In step S1, the contour array is obtained by extracting the mathematical description of the character in the font file, calculating the contour expression under the specified font size, and naturally dividing the contour array with the number of elements greater than or equal to 1 by the number of contour lines, traversing the contour lines one by one, and completing the data filling of the contour array elements by using the line-to-point method; the triangle strip array is a method of storing the triangle strip vertex data in an array manner, each vertex of the triangle strip vertex sequence is an element of the array, and the vertex element is composed of two floating-point numbers to represent the spatial coordinates of the vertex (x, y); the degenerate triangle is a special triangle formed when the three vertices constituting the triangle are collinear, and the triangle has the feature of an area of 0, which can be used to avoid the graphics card from rendering the transition triangle connecting two triangle strips; the head and tail of the triangle strip refer to the first and last vertices of the ordered vertex sequence determined by the triangle strip primitive; the production method of using the degenerate triangle to connect each triangle strip primitive is to copy the last vertex of the previous triangle strip to be connected and copy the first vertex of the next triangle strip to be connected, and insert the two vertices between the two triangle strip vertex elements as a transition, that is, to achieve the connection of two independent triangle strips.
[0078] S3. Encode the ordered vertex sequence into a texture using a tree splitting method, and record a row index of each ordered vertex sequence in the texture.
[0079] Before encoding, the coordinates of each vertex in the ordered vertex sequence need to be standardized. Then, each vertex coordinate is encoded into RGBA color information using a tree splitting method; all vertices of a single character are stored in a specified row in a texture bitmap, and the row index of the specified row is recorded to obtain a texture and a row index.
[0080] As an optional implementation, the standardized (x, y) coordinate value range is the interval [0.0, 1.0]. After it is enlarged to a subset range of the data interval that can be represented by a single-byte texture color component (the enlarged coordinate value range is [0.0, 255.0]), the integer part becomes an unsigned integer that can be represented and stored by 1 byte; the decimal part of the enlarged (x, y) coordinate has a value range of the interval [0.0, 1.0]. After it is enlarged in the same way, the integer part also becomes an unsigned integer that can be represented and stored by 1 byte; the last color is filled pixel by pixel to the maximum width, and the degenerate triangle method is used to force the area of the new triangle generated by the triangle strip after the valid vertex to be 0, so as to cancel the influence of such invalid vertices on the drawing results.
[0081] S4. Transferring the texture and the row index to a video memory.
[0082] S5. Write a decoder according to the correspondence between the texture and the ordered vertex sequence.
[0083] The decoding process of the decoder is actually the inverse process of the above encoding. The corresponding decoder is written according to the encoding and storage process of the ordered vertex sequence in the texture.
[0084] As an optional implementation, an instantiation method sampler and decoder for character textures are designed in the GPU rendering process; if the texture needs to be parsed in the geometry shader, the texture row index of the character to be rendered can be passed into the shader as a vertex attribute, and the vertex attribute is set to change to the next value after each instantiation; the row coordinates of the character to be rendered in the texture are determined by the row index vertex attribute specified by the instantiation rendering, and the character texture column coordinates are determined by the vertex ID uniquely specified in a single instantiation process; the texture is sampled based on the row and column coordinates to obtain the corresponding vertex color value; when there is a font display requirement, the texture data file generated in step 2 is read by the CPU and transferred to the video memory, the sampler finds the texture color corresponding to the specified character vertex, and the decoder is designed to convert the texture color corresponding to the specified character into vertex coordinate data; the standardized x, y coordinates are calculated to complete the decoding of the vertex (x, y) coordinate value.
[0085] Furthermore, the sampler and decoder for the instantiation method of character texture in the GPU rendering process in step 3 can be completed in the vertex calculation or primitive assembly stage of the rendering pipeline. Specifically, the sampling and decoding of character texture can be implemented in the vertex shader or geometry shader. For the vertex shader, the texture color corresponding to each vertex is extracted by a single instantiation of the uniquely specified vertex ID and the instantiation vertex attribute row index; for the geometry shader, the texture can be directly read, decoded in sequence, and the triangle strip primitives can be constructed.
[0086] In addition, the row index vertex attribute specified by instanced rendering is updated once for each instantiation. The relevant attributes remain unchanged during a single instantiation, which ensures that the texture sampler allows different vertices to point to the same row in the texture within a single instantiation; the vertex ID uniquely specified by a single instantiation is a unique identifier for a single vertex data during a single instantiation, which ensures that the texture sampler allows different vertices to point to different columns in the texture within a single instantiation; if the texture color component representation interval is automatically represented in the value range [0.0,1.0] inside the graphics card, then the encoding and decoding processes are not completely inverse; standardizing the x or y coordinate means changing the coordinate value range from the interval [0.0,1.0] to [-1.0,1.0].
[0087] S6. Acquire the texture of a specified character; the specified character is a character that needs to be displayed.
[0088] After the texture is passed into the video memory in the character instanced rendering process, the vertex color information can be collected by instantiating the vertex attributes and vertex ID control samplers in the vertex shader.
[0089] S7. Decode the texture of the designated character using the decoder to obtain an ordered vertex sequence.
[0090] As an optional implementation, in this embodiment, a decoder is used to decode the color information into vertex data in standardized device coordinates. Finally, the vertex data after other calculations are assembled into triangle strip primitives and the final font is rendered.
[0091] S8. Display the designated character according to the ordered vertex sequence.
[0092] Firstly, according to the ordered vertex sequence, the coordinate transformation and color scheme required for drawing are applied, and the triangle strip drawing method of the GPU is used to complete the character drawing.
[0093] In general, see Figure 2 , Figure 2The figure is a schematic diagram of the overall method of the present invention. The method comprises the following steps: firstly, the font data is preprocessed, the font file of the specified font is loaded and the font size information is specified, the contour array of each character is calculated and extracted according to the font and the font size, the array is traversed and each element is subjected to the surface subdivision based on the triangle belt, and the triangle belt array is linked into a triangle belt by the degenerate triangle method, so as to describe the vector fonts such as TrueType as the triangle belt vertex coordinate data. Then, the triangle belt vertex data is texture encoded, the triangle belt vertex coordinates are standardized, and a single-precision floating-point array with a value range of [0.0, 1.0] is calculated, and the vertex (x, y) coordinates are encoded into RGBA color information by tree splitting, and all the vertices of a single character are stored in a specified row of the texture bitmap. If the number of vertices does not reach the maximum width, the remaining color is filled with the color of the last vertex, and when the number of encoded vertices reaches the maximum height of the texture, the texture file is saved. Secondly, in the character instantiation rendering process, the texture is transferred to the video memory, and the sampler is controlled by instantiating vertex attributes and vertex IDs in the vertex shader to collect vertex color information, and the decoder is used to decode the color information into vertex data in standardized device coordinates. Finally, the vertex data after other calculations are assembled into triangle strip primitives and the final font is rendered.
[0094] During the preprocessing process, the triangle strip primitive has better information compression capabilities than ordinary triangle primitives because of its feature of using n+2 vertices to represent n triangles. It can also reduce the amount of repeated vertex calculations when the vertex shader performs vertex calculations, thereby improving rendering efficiency. Considering the need to store characters by row in the texture in subsequent steps, a single character must be described by a triangle strip. However, since a single triangle strip is difficult to describe bifurcated or separated polygons, which are often seen in characters, especially Chinese characters, it is inevitable that multiple triangle strips will be constructed in the process of triangle strip-based surface subdivision. For this reason, it is necessary to effectively link the triangle strips in a single character. The triangle strip linking method in the present invention adopts the degenerate triangle method, such as Figure 3 As shown, for two independent triangle strips, the last vertex is copied at the end of the first strip and the first vertex is copied at the beginning of the second strip to construct four degenerate triangles with an area of 0, thereby achieving linking. Figure 4 The figure shows the effect of drawing characters represented by a single triangle strip in wireframe mode. The unnatural lines that appear in each character are the result of degenerate triangles connecting the triangle strips.
[0095] In order to facilitate the texture-based encoding and decoding of the character triangle data, the triangle vertex data must be standardized first, and the value range of the (x, y) coordinate value must be mapped to the interval [0.0, 1.0]. During the mapping process, several types of feature relationships must be paid attention to: (1) The proportional feature between the x-axis and the y-axis must be preserved to ensure that the vertices are correctly scaled in each axis direction; (2) The local coordinate features within the bounding box must be preserved to ensure that the relationship between the triangle vertex coordinates of a single character is correct; (3) The global coordinate features outside the bounding box must be preserved to ensure that the size and position relationships between the characters are correct.
[0096] The key to texture-based encoding and decoding of character triangle data is to use a relatively simple and fast method to achieve the conversion of 2 single-precision floating-point data and 4 single-byte color component data (i.e., RGBA). The present invention uses a tree-shaped splitting method to design the encoder, such as Figure 5 As shown, by enlarging the standardized coordinates (taking the x coordinate as an example in the figure) to the interval [0.0, 255.0], the integer part of the value is in the interval [0, 255], so that the integer part can be stored by 1 byte of color component data; the decimal part of the enlarged coordinate is in the interval [0.0, 1.0), and by enlarging it again, the decimal is in the interval [0.0, 255.0), and after taking its integer part, it can also be stored by 1 byte of color component data. The above process is the encoding process of converting coordinates to color components. The structure of the converted color data storage is shown in the figure below. Figure 6 As shown in the figure, I represents the integer part of the coordinate after enlargement, and D represents the decimal part of the coordinate after enlargement. Figure 7 shown.
[0097] The decoding process from texture color to vertex coordinates can be basically regarded as the inverse process of the encoding process. However, it is worth noting that in most scenarios where programmable rendering pipelines are used, color values will be automatically converted by the GPU into single-precision floating-point data in the range of [0.0, 1.0]. Therefore, the scaling operation from the interval [0.0, 255.0] to [0.0, 1.0] can be omitted during the decoding process. The implementation of the decoder can be further simplified as follows: (1) extract the value of the color component where the decimal is located and divide it by 255.0; (2) add the value of the color component where the integer is located; (3) map the value to the interval [-1.0, 1.0]. In this way, the standardized device coordinate data of the vertex can be obtained.
[0098] The encoding and decoding process based on the tree-shaped splitting method in the present invention is essentially to convert 32-bit single-precision floating-point data and 16-bit dual-color components to each other, and there will inevitably be problems with information accuracy during the conversion process. The dual-color components of this method can represent 65,536 uniquely determined coordinates. If the upper limit of the width of the coordinate value exceeds this value, the representation of the dual-color components will have the problem of precision loss. A feasible solution provided by the present invention is: using the tree-shaped splitting characteristics, the decimal part of the enlarged coordinate data that is discarded when it is enlarged again is reused, it is enlarged and the integer part is picked up, and then stored in a new color component, and so on until the accuracy meets the application requirements.
[0099] After the character data is encoded as a texture and transferred to the video memory, for performance considerations, the present invention hopes to draw all the characters required for a single frame in a single Draw Call. The present invention reinterprets the instantiation rendering function by combining the instantiation rendering feature and the characteristics of the GPU programmable rendering pipeline, and designs an efficient instantiation-based texture sampler to complete the function of batch drawing text in a single frame and a single Draw Call. Instanced rendering is designed to achieve batch rendering of a single model, and large-scale repeated rendering of the model is achieved by specifying model data and the number of repetitions. The present invention also adopts an instanced rendering method, but after reinterpretation, the direct specification of rendering data is changed to indirect specification of texture row index, and the number of repetitions is interpreted as the total number of characters drawn in this Draw Call.
[0100] To build an instance-based sampler, the data that must be passed into the video memory includes the character texture and the row index of the character to be drawn. The data is shown as follows Figure 8 As shown. The row index is used as an instantiation vertex attribute, and its content is updated after an instantiation process ends, so as to ensure that the vertex attribute remains unchanged during a single instantiation process, and always indicates the texture row number pointed to by the character drawn by this instantiation. In the single instantiation process of the programmable rendering pipeline, different vertices will be assigned unique ID identifiers by hardware, and their ordered increasing characteristics are completely consistent with the meaning of the column number of the texture color at the sequence expression level. Therefore, the vertex ID can be directly used to represent the column number corresponding to it in the texture. Based on the above content, the present invention represents the row number by instantiating the vertex attribute, and represents the column number by the vertex ID in a single instantiation, thereby realizing the mapping relationship between the vertex and the texture color coordinates. The row and column coordinate values are directly obtained by built-in variables and video memory without any additional calculations. Therefore, the constructed sampler will not produce possible performance losses when establishing the mapping relationship.
[0101] Fig. 9The effects of character drawing under different scaling and rotation conditions are given in the figure. The test window resolution is 800x600; a 120-point font is used as the test data source for drawing; (a), (c) characters are not rotated, (b), (d) characters are rotated 60°; (a), (b) character sizes are obtained by scaling 0.2 times based on the standardized device coordinates, (c), (d) character sizes are obtained by scaling 0.03 times based on the standardized device coordinates (the images are enlarged for clarity). It can be seen from the figure that when the characters are large, there is almost no difference in the rendering effect regardless of whether they are rotated or not. Even when the characters are scaled to a very small size, the overall font can still be displayed correctly after a 60° rotation. The jagged straight line phenomenon caused by tilt can be solved by setting a specific anti-aliasing algorithm according to the usage environment.
[0102] Compared with the prior art, this embodiment combines the performance advantages of texture carriers and the scaling advantages of vector font description methods, avoiding the problem that textures are not flexible enough during scaling and that vector font features cannot run through the entire process of the programmable rendering pipeline, and reducing the blurring and distortion of fonts caused by operations such as character rotation. The use of triangle strips to describe characters and the re-interpreted instantiation rendering method makes it possible to draw all the characters required for a single frame in a single drawing call, improving the efficiency and effect of character loading and drawing.
[0103] Embodiment 2:
[0104] like Fig.10 As shown, the present invention provides a texture-based triangle character representation and instantiation rendering system, the system comprising:
[0105] The outline obtaining unit M1 is used to obtain the outline of the character to be drawn;
[0106] An ordered vertex sequence acquisition unit M2, used to convert the outline of each character into an ordered vertex sequence using a triangle strip;
[0107] The encoding unit M3 is used to encode the ordered vertex sequence into a texture by using a tree splitting method, and record a row index of each ordered vertex sequence in the texture;
[0108] A transmission unit M4, used for transmitting the texture and the row index to a video memory;
[0109] A decoder writing unit M5, used for writing a decoder according to the correspondence between the texture and the ordered vertex sequence;
[0110] The designated character texture acquisition unit M6 is used to acquire the texture of the designated character; the designated character is a character that needs to be displayed;
[0111] A decoding unit M7, configured to decode the texture of the designated character using the decoder to obtain an ordered vertex sequence;
[0112] The display unit M8 is used to display the specified character according to the ordered vertex sequence.
[0113] The step of converting the outline of each character into an ordered vertex sequence using a triangle strip specifically includes:
[0114] Performing triangular-band-based surface subdivision on each part constituting the contour to obtain a plurality of triangular bands;
[0115] Connecting the beginning and the end of the plurality of triangle strips by using a degenerate triangle method to obtain a triangle strip representation of the contour, that is, a single triangle strip representing each contour;
[0116] Each vertex of the single triangle belt is organized into an ordered vertex sequence according to the inherent order of the triangle belt.
[0117] The method of encoding the ordered vertex sequence into a texture by using a tree splitting method and recording a row index of each ordered vertex sequence specifically includes:
[0118] Use the tree splitting method to encode each vertex coordinate into RGBA color information;
[0119] All vertices of a single character are stored in a specified row in a texture bitmap, and the row index of the specified row is recorded to obtain a texture and a row index.
[0120] The step of displaying the designated character according to the ordered vertex sequence specifically includes:
[0121] According to the ordered vertex sequence, the coordinate transformation and color scheme required for drawing are applied, and the triangle strip drawing method of the GPU is used to complete the character drawing.
[0122] Embodiment three:
[0123] This embodiment provides a texture-based triangle character representation and instantiation rendering method, comprising the following steps:
[0124] Step 1, load the outline description data of the character to be drawn, convert the outline expression of each character into one or more triangle bands equivalent to the character outline expression, link the triangle bands, and each character forms a separate single triangle band expression.
[0125] Step 2: For the triangle strip expression of the character formed in step 1, traverse each character triangle strip vertex, encode the (x, y) coordinates of each vertex into an equivalent texel, and sequentially compose a texel row sequence representing the triangle strip expression of the character. The texel row sequence corresponding to each character is sequentially composed into a texture image data, and the row index of the texture row sequence corresponding to each character in the texture image is recorded.
[0126] Step 3, transfer the texture data formed in step 2 to the video memory. Use the general GPU Shader language to write a character decoder and drawer for character texel expression. For each character to be drawn, the character decoder and drawer takes out the corresponding character texel sequence according to the texture row index corresponding to the character, decodes each texel and restores it to the corresponding triangle strip vertex coordinates, applies the coordinate transformation and color scheme required for drawing, and uses the GPU triangle strip drawing method to complete the character drawing.
[0127] The specific steps for constructing a single triangle belt in step 1 are:
[0128] Step 1.1, load the character outline description data, generate the font outline according to the specified font size, and extract the outline array.
[0129] Step 1.2, perform surface subdivision based on triangle strip primitives on each element in the contour array to obtain a triangle strip primitive array.
[0130] Step 1.3, using the degenerate triangle method to link the beginning and end of each triangle strip to obtain a single triangle strip data of the character.
[0131] The specific steps for encoding vertex (x, y) coordinates into texels in step 2 are:
[0132] Step 2.1, specify the maximum width and height of the character data texture, encode the vertex coordinate values into texels using mathematical methods, and store them in the texture in row order according to the vertex order, so as to realize the encoding of the vertex data.
[0133] The specific steps of the mathematical coding method in step 2.1 are:
[0134] Step 2.1.1, enlarge the value range of the x-coordinate or y-coordinate to a subset of the interval range that can be represented by a single texel component, and take the integer part and store it in an unfilled component;
[0135] Step 2.1.2, enlarge the value range of the remaining decimal part to a subset of the interval range that can be represented by a single texel component, and take its integer part and store it in an unfilled component;
[0136] Step 2.1.3, for rows where the number of texels is less than the maximum width, copy the last texel and fill it to the maximum width.
[0137] The specific steps to create an instantiation method sampler in step 3 are:
[0138] Step 3.1, pass the texture row index of the character to be rendered as a vertex attribute into the shader, and set the attribute to be updated once per instantiation;
[0139] Step 3.2, determine the texture row coordinates of the vertex by the row index vertex attribute, determine the texture column coordinates by the vertex ID uniquely specified in a single instantiation process, and construct a mapping relationship between the character vertex and the texel position;
[0140] Step 3.3, sample the texture based on the mapping relationship to obtain the texel corresponding to the vertex.
[0141] The specific steps to create a decoder in step 3 are:
[0142] Step 3.4, obtaining the texel component using a specified method according to the sampler characteristics;
[0143] Step 3.5, reducing the component value storing the decimal part of the vertex coordinate to the initial interval to obtain the decimal part of the coordinate;
[0144] Step 3.6, the component value storing the integer part of the vertex coordinates is added with the decimal part and reduced to the initial interval to calculate the standardized,coordinate value.
[0145] As some optional implementations:
[0146] In the step 1.1, the font size is measured in "points" in conventional typesetting, and the font size rules are consistent with those of conventional typesetting.
[0147] The degenerate triangle connecting the triangle strip primitives in step 1.3 is a triangle with an area of 0, and is made by sequentially copying the tail vertex of the previous triangle strip to be connected and the first vertex element of the next triangle strip, and then merging the two triangle strip vertex sets in the order of the previous triangle strip - the copied vertex element - the next triangle strip, to complete the connection of the two triangle strips.
[0148] In the step 2.2.3, the last texel is copied to fill the maximum width, and the degenerate triangle method is used to force the area of the new triangle generated after the triangle strip has valid vertices to be 0, so as to cancel the influence of such invalid vertices on the drawing results.
[0149] The row index vertex attribute specified by the instanced rendering in step 3.2 has the characteristic that the value remains unchanged within one instantiation, thereby ensuring that the texture sampler always points to a row of the texture in a single instantiation.
[0150] The vertex ID uniquely specified by a single instantiation in step 3.2 is a unique identifier for each vertex in a single instantiation process, and this identifier ensures that the texture sampler allows different vertices to point to different columns of the texture within a single instantiation.
[0151] The encoding of the remaining decimal part described in step 2.2.2 will discard the decimal and retain the integer part after enlargement. In this case, two single-byte texel components can store a maximum of 65536 different vertex coordinates. If there are application scenarios that exceed the description capability of this method, new components can be used to store the integer part after the discarded decimal part is enlarged, and so on until the needs are met.
[0152] Embodiment 4:
[0153] This embodiment provides a texture-based triangle character representation and instantiation rendering method, comprising the following steps:
[0154] Step 1, load the font file, specify the font size according to the application scenario and application requirements, generate all the characters in the file to obtain the corresponding contour array; perform surface subdivision on each contour array element according to the basic primitive for constructing graphics, namely the triangle strip, to obtain the triangle strip array; use the degenerate triangle method to connect the beginning and end of each triangle strip to form the triangle strip vector data of a single character;
[0155] Furthermore, in step 1, the font size is measured in "points" in typesetting and printing, and the font size rules are consistent with the character printing typesetting rules; the contour array in step 1 is obtained by extracting the mathematical description of the character in the font file, calculating the contour line expression under the specified font size, and naturally dividing the contour array with the number of elements greater than or equal to 1 by the number of contour lines, traversing each contour line, and using the line-to-point method to complete the data filling of the contour array elements; the triangle strip array is a method of storing the triangle strip vertex data in an array format, and each vertex in the triangle strip vertex sequence is an element of the array. The vertex element is composed of two floating-point numbers to represent the spatial coordinates of the vertex (x, y). Label; Degenerate triangle is a special triangle formed when the three vertices that constitute the triangle are collinear. This triangle has the feature of 0 area, which can be used to avoid the graphics card from rendering the transition triangle connecting two triangle strips; the head and tail of a triangle strip refer to the first and last vertices of the ordered vertex sequence determined by the triangle strip primitive; the method of using degenerate triangles to connect each triangle strip primitive is to copy the last vertex of the previous triangle strip to be connected and the first vertex of the next triangle strip to be connected, and insert the two vertices between the two triangle strip vertex elements as a transition, thereby realizing the connection of two independent triangle strips.
[0156] Step 2, traverse each vertex of the character triangle strip vector data, standardize the vertex coordinates to establish a standardized vertex array for a single character; specify the maximum width and height of the character data texture, traverse each vertex element in the standardized vertex array, disassemble it and store it in the texture color component; for the rows whose colors cannot be filled to the maximum width, fill the last color pixel by pixel to the maximum width; perform step 2 on the next triangle strip vector data, and so on until the number of characters is equal to the maximum height of the texture, or all characters have been stored, thereby encoding multiple characters and generating a texture data file.
[0157] Furthermore, the standardized (x, y) coordinate value range in step 2 is the interval [0.0, 1.0]. After it is enlarged to a subset range of the data interval that can be represented by a single-byte texture color component (the enlarged coordinate value range is [0.0, 255.0]), the integer part becomes an unsigned integer that can be represented and stored by 1 byte; the decimal part of the enlarged (x, y) coordinate has a value range of the interval [0.0, 1.0]. After it is enlarged in the same way, the integer part also becomes an unsigned integer that can be represented and stored by 1 byte; the last color is filled pixel by pixel to the maximum width, and the degenerate triangle method is used to force the area of the new triangle generated by the triangle strip after the valid vertex to be 0, so as to cancel the influence of such invalid vertices on the drawing results.
[0158] Step 3, design an instantiation method sampler and decoder for character texture in the GPU rendering process; if the texture needs to be parsed in the geometry shader, the texture row index of the character to be rendered can be passed into the shader as a vertex attribute, and the vertex attribute is set to change to the next value after each instantiation; the row coordinates of the character to be rendered in the texture are determined by the row index vertex attribute specified by the instantiation rendering, and the character texture column coordinates are determined by the vertex ID uniquely specified in a single instantiation process; the texture is sampled based on the row and column coordinates to obtain the corresponding vertex color value; when there is a font display requirement, the texture data file generated in step 2 is read by the CPU and transferred to the video memory, the sampler finds the texture color corresponding to the specified character vertex, and the decoder is designed to convert the texture color corresponding to the specified character into vertex coordinate data; calculate the standardized coordinates to complete the decoding of the vertex (x, y) coordinate value.
[0159] Furthermore, the sampler and decoder for the instantiation method of character texture in the GPU rendering process in step 3 can be completed in the vertex calculation or primitive assembly stage of the rendering pipeline. Specifically, the sampling and decoding of character texture can be implemented in the vertex shader or geometry shader. For the vertex shader, the texture color corresponding to each vertex is extracted by a single instantiation of the uniquely specified vertex ID and the instantiation vertex attribute row index; for the geometry shader, the texture can be directly read, decoded in sequence, and the triangle strip primitives can be constructed.
[0160] Furthermore, the row index vertex attribute specified by the instanced rendering in step 3 is updated once for each instantiation, and the relevant attributes remain unchanged during a single instantiation, ensuring that the texture sampler allows different vertices to point to the same row in the texture within a single instantiation; the vertex ID uniquely specified by a single instantiation is a unique identifier for a single vertex data during a single instantiation, which ensures that the texture sampler allows different vertices to point to different columns in the texture within a single instantiation; if the texture color component representation interval is automatically represented in the value range [0.0,1.0] inside the graphics card, then the encoding and decoding processes are not completely inverse; standardizing the x or y coordinate means changing the coordinate value range from the interval [0.0,1.0] to [-1.0,1.0].
[0161] Step 4: Assemble the vertices into a single triangle strip primitive according to the order of vertices decoded by the decoder, and rasterize and shade the triangle strip to achieve the final display effect.
[0162] Embodiment five:
[0163] Modern vector font description methods and dot-fill rendering methods, led by TrueType, cannot meet the need to use the vector characteristics of characters throughout the entire rendering process. The reason is that there is a very big difference in the storage form of character data in the CPU and GPU. This embodiment designs a special texture carrier, which serves as a medium for data transmission in hardware, ensuring the consistency of the data storage form of characters in the CPU and GPU. The use and storage of data is completed in the form of encoding and decoding, so there will be no change in the storage form.
[0164] Based on this texture carrier, this embodiment directly designs a CPU-texture color data encoder and a GPU-vertex coordinate data decoder, and also derives a triangle strip preprocessing of character data before encoding and an instantiated vertex and texture mapping sampler before decoding. After the above processing and calculation of the character data, large-scale reuse of characters is achieved while achieving efficient drawing of characters with vector characteristics throughout the rendering process.
[0165] The following is an embodiment of the present invention using OpenGL GLSL:
[0166] (1)CPU-texture color data encoder
[0167]
[0168] (2) Instantiate vertex and texture mapping samplers (sampler2DRect sampler)
[0169]
[0170] (3) Instantiate vertex and texture mapping samplers (sampler2D samplers)
[0171]
[0172]
[0173] (4) GPU-Vertex Coordinate Data Decoder
[0174]
[0175] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0176] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of the present invention. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A texture-based triangle character representation and instantiation rendering method, characterized in that: The method comprises: Get the outline of the character to be drawn; Convert the outline of each character into an ordered vertex sequence using triangle strips; Encoding the ordered vertex sequence into a texture by using a tree splitting method, and recording a row index of each ordered vertex sequence in the texture; transferring the texture and the row index to a video memory; Writing a decoder according to the correspondence between the texture and the ordered vertex sequence; Obtaining the texture of a specified character; the specified character is a character that needs to be displayed; Decoding the texture of the designated character using the decoder to obtain an ordered vertex sequence; Displaying the specified character according to the ordered vertex sequence; The step of obtaining the outline of the character to be drawn specifically includes: Loading a font file, and generating all characters in the font file according to a specified font size; Get the outline of each character; The process of converting the outline of each character into an ordered vertex sequence using a triangle strip specifically includes: Performing triangular-band-based surface subdivision on each part constituting the contour to obtain a plurality of triangular bands; Connecting the beginning and the end of the plurality of triangle strips by using a degenerate triangle method to obtain a triangle strip representation of the contour, that is, a single triangle strip representing each contour; Arrange each vertex of the single triangle belt into an ordered vertex sequence according to the inherent order of the triangle belt; The method of encoding the ordered vertex sequence into a texture by using a tree splitting method and recording a row index of each ordered vertex sequence specifically includes: Encoding each vertex coordinate of the ordered vertex sequence into RGBA color information using a tree splitting method; All vertices of a single character are stored in a specified row in a texture bitmap, and the row index of the specified row is recorded to obtain a texture and a row index; The step of displaying the designated character according to the ordered vertex sequence specifically includes: According to the ordered vertex sequence, the coordinate transformation and color scheme required for drawing are applied, and the triangle strip drawing method of the GPU is used to complete the character drawing.
2. The texture-based triangle character representation and instantiation rendering method according to claim 1, characterized in that: After converting the outline of each character into an ordered vertex sequence using a triangle strip, the method further includes: The coordinates of each vertex in the ordered vertex sequence are normalized.
3. A texture-based triangle character representation and instantiation rendering system, characterized in that: The system comprises: A contour acquisition unit, used to acquire the contour of the character to be drawn; The step of obtaining the outline of the character to be drawn specifically includes: Loading a font file, and generating all characters in the font file according to a specified font size; Get the outline of each character; An ordered vertex sequence acquisition unit, used for converting the outline of each character into an ordered vertex sequence using a triangle strip; The process of converting the outline of each character into an ordered vertex sequence using a triangle strip specifically includes: Performing triangular-band-based surface subdivision on each part constituting the contour to obtain a plurality of triangular bands; Connecting the beginning and the end of the plurality of triangle strips by using a degenerate triangle method to obtain a triangle strip representation of the contour, that is, a single triangle strip representing each contour; Arrange each vertex of the single triangle belt into an ordered vertex sequence according to the inherent order of the triangle belt; An encoding unit, used for encoding the ordered vertex sequence into a texture by using a tree splitting method, and recording a row index of each ordered vertex sequence in the texture; The method of encoding the ordered vertex sequence into a texture by using a tree splitting method and recording a row index of each ordered vertex sequence specifically includes: Encoding each vertex coordinate of the ordered vertex sequence into RGBA color information using a tree splitting method; All vertices of a single character are stored in a specified row in a texture bitmap, and the row index of the specified row is recorded to obtain a texture and a row index; A transmission unit, used for transmitting the texture and the row index to a video memory; A decoder writing unit, used for writing a decoder according to the correspondence between the texture and the ordered vertex sequence; A designated character texture acquisition unit is used to acquire the texture of a designated character; the designated character is a character that needs to be displayed; A decoding unit, used for decoding the texture of the specified character by using the decoder to obtain an ordered vertex sequence; A display unit, configured to display the specified character according to the ordered vertex sequence; The step of displaying the designated character according to the ordered vertex sequence specifically includes: According to the ordered vertex sequence, the coordinate transformation and color scheme required for drawing are applied, and the triangle strip drawing method of the GPU is used to complete the character drawing.
Citation Information
Patent Citations
Image processing apparatus, image processing method, and computer program
CN101689203A
Compression of a tessellated primitive index list in a tile rendering system
CN103415872A