Graphical interface rendering method, device, electronic device and storage medium
By rendering the pictures and characters in the graphical interface data into textures respectively, and performing sampling and fusion processing, the problem of low rendering efficiency of the graphical interface is solved, achieving higher CPU load reduction and display frame rate improvement.
Patent Information
- Application Number
- CN202110575616.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-26
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2041-05-26
AI Technical Summary
In the existing technology, during the rendering process of the graphical interface, as the number of Draw Call operations increases, the CPU load increases, resulting in low rendering efficiency and reduced display frame rate, and there is a lack of effective solutions.
The pictures and characters in the graphical interface data are rendered into broken image textures and character textures respectively, and through sampling and fusion processing, Draw Call operations are reduced and the possibility of batch processing is improved.
Reduce CPU load, improve the rendering efficiency and display frame rate of the graphical interface, and reduce Draw Call operations during the rendering process.
Smart Images

Figure CN113409411B
Abstract
Description
Technical Field
[0001] The present application relates to Internet technology, and in particular to a method, device, electronic device and computer-readable storage medium for rendering a graphical interface. Background Art
[0002] With the rapid development of the Internet, the transmission speed has greatly increased, the user experience has become more important, and the front-end page logic has become more and more complex. When the user terminal presents the corresponding graphical interface, the central processing unit (CPU) and the graphics processing unit (GPU) need to work together. For example, the CPU calls the graphics programming interface to command the GPU to render the graphical interface (i.e., Draw Call operation).
[0003] Nowadays, the graphical interfaces displayed by user terminals are becoming more and more complex, and they contain more and more pictures and texts, which requires a large number of Draw Call operations in the rendering process. Before each Draw Call operation, the CPU needs to do a lot of preparation, such as detecting the rendering status, submitting the data required for rendering, submitting the status required for rendering, etc. With the increase of Draw Call operations, the CPU's additional overhead will increase, increasing the CPU load, resulting in lower rendering efficiency of the graphical interface, and then reducing the display frame rate of the user terminal. In this regard, there is no effective solution in the relevant technology. Summary of the invention
[0004] Embodiments of the present application provide a method, device, electronic device, and computer-readable storage medium for rendering a graphical interface, which can improve the rendering efficiency of the graphical interface.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] The present application provides a method for rendering a graphical interface, including:
[0007] Rendering a plurality of images in the graphical interface data into a fragmented image texture, and rendering a plurality of characters in the graphical interface data into a character texture;
[0008] The fragmented image texture and the character texture are sampled respectively to obtain the fragmented image texture color value and the character texture color value corresponding to each pixel point in the graphical interface;
[0009] According to the vertex information of the broken image texture and the character texture, the broken image texture color value and the character texture color value corresponding to each pixel are fused to obtain a fused color value of each pixel;
[0010] The graphical interface is formed by rendering according to the fused color value of each pixel.
[0011] The present application provides a graphical interface rendering device, including:
[0012] A texture rendering module, used to render multiple images in the graphical interface data into a fragmented image texture, and render multiple characters in the graphical interface data into a character texture;
[0013] A sampling module, used for sampling the fragmented image texture and the character texture respectively, and obtaining the fragmented image texture color value and the character texture color value corresponding to each pixel point in the graphical interface;
[0014] A fusion module, for fusing the color value of the broken image texture and the color value of the character texture corresponding to each pixel point according to the vertex information of the broken image texture and the character texture, to obtain a fused color value of each pixel point;
[0015] The interface rendering module is used to render and form the graphic interface according to the fused color value of each pixel.
[0016] In the above scheme, the texture rendering module is also used to remove the transparent area of each image in the graphical interface data; the following processing is performed for each image from which the transparent area is removed: the image is cut into multiple broken images along a first reference direction, and the multiple broken images are rendered into the broken image texture in sequence along a second reference direction; wherein the first reference direction and the second reference direction are perpendicular to each other.
[0017] In the above scheme, when the image is a rectangle, the first reference direction and the second reference direction correspond to two adjacent edges in the image; the texture rendering module is also used to cut the image into multiple pieces of the same height at equal intervals along the first reference direction, and render the multiple pieces into the piece texture in sequence along the second reference direction.
[0018] In the above scheme, the texture rendering module is also used to stitch multiple pictures in the graphical interface data to obtain a stitched picture; determine the distance between the two farthest vertices in the stitched picture; when the distance between the two farthest vertices in the stitched picture is greater than the distance between the two farthest vertices in the fragmented texture, determine to perform an operation of removing the transparent area of each picture in the graphical interface data.
[0019] In the above scheme, the texture rendering module is also used to extract a character file from the graphical interface data, wherein the character file includes the multiple characters; parse the character file to obtain a plurality of dot matrix characters corresponding to the multiple characters one by one; divide the character texture into a plurality of character areas, wherein the number of the plurality of character areas is greater than or equal to the number of the plurality of dot matrix characters; render the plurality of dot matrix characters into the plurality of character areas in sequence, wherein each of the character areas includes at most one of the dot matrix characters.
[0020] In the above scheme, the sampling module is also used to perform the following processing for each pixel point in the graphical interface: through a texture sampling function, sampling processing is performed at the position corresponding to the pixel point in the fragmented image texture to obtain the fragmented image texture coordinates of the pixel point; through a texture sampling function, sampling processing is performed at the position corresponding to the pixel point in the character texture to obtain the character texture coordinates of the pixel point; the fragmented image texture color value corresponding to the pixel point is determined according to the fragmented image texture coordinates of the pixel point; the character texture color value corresponding to the pixel point is determined according to the character texture coordinates of the pixel point; wherein the area of the fragmented image texture is the same as the area of the character texture.
[0021] In the above scheme, the sampling module is also used to convert the fragment texture coordinates of the pixel point into a fragment array index, and use the fragment texture color value corresponding to the fragment array index as the fragment texture color value of the pixel point; convert the character texture coordinates of the pixel point into a character array index, and use the character texture color value corresponding to the character array index as the character texture color value of the pixel point.
[0022] In the above scheme, the fusion module is also used to perform the following processing for each pixel: determine the first weight corresponding to the pixel according to the vertex information of the fragmented image texture, and determine the second weight corresponding to the pixel according to the vertex information of the character texture; based on the first weight and the second weight, perform weighted sum processing on the fragmented image texture color value corresponding to the pixel and the character texture color value corresponding to the pixel to obtain the fused color value of the pixel.
[0023] In the above scheme, the fusion module is also used to determine the vertex information of the target fragment corresponding to the pixel point in the fragment texture, and determine the texture coordinates in the vertex information of the target fragment; determine the target component in the texture coordinates as the first weight corresponding to the pixel point; determine the vertex information of the target character corresponding to the pixel point in the character texture, and determine the texture coordinates in the vertex information of the target character; determine the target component in the texture coordinates as the second weight corresponding to the pixel.
[0024] In the above scheme, the texture rendering module is also used to perform the following processing on each fragment in the fragment texture: determine the area in the fragment for rendering in the graphical interface, and divide the area into multiple sub-areas with specific shapes; determine the vertex information for rendering each of the sub-areas; combine the vertex information corresponding to the multiple sub-areas to obtain the vertex information for rendering the fragment.
[0025] In the above scheme, the texture rendering module is also used to select multiple broken pictures from the broken picture texture for splicing processing to obtain a spliced group picture; determine the center position of the spliced group picture, and determine the area in the spliced group picture for rendering in the graphical interface; draw a fan-shaped area with the center position as the vertex, wherein the fan-shaped area includes the area in the spliced group picture for rendering in the graphical interface; perform the following processing for each of the broken pictures in the spliced group picture: determine the radius of the fan-shaped area and the intersection between the broken pictures, and use the vertex information of the intersection as the vertex information for rendering the broken pictures.
[0026] In the above scheme, the texture rendering module is also used to determine the area of each image in the graphical interface data, and render the images whose area is greater than the area threshold into the background texture; the sampling module is also used to sample the background texture to obtain the background texture color value corresponding to each pixel in the graphical interface; the fusion module is also used to fuse the broken image texture color value, the character texture color value and the background texture color value corresponding to each pixel according to the vertex information of the broken image texture, the character texture and the background texture to obtain the fused color value of each pixel.
[0027] An embodiment of the present application provides an electronic device, including:
[0028] A memory for storing computer executable instructions;
[0029] The processor is used to implement the rendering method of the graphical interface provided in the embodiment of the present application when executing the computer executable instructions stored in the memory.
[0030] An embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions for implementing a method for rendering a graphical interface provided in an embodiment of the present application when executed by a processor.
[0031] The embodiments of the present application have the following beneficial effects:
[0032] The images and characters in the graphical interface data are rendered into different textures respectively, and the sampled fragment texture color value and character texture color value of each pixel are fused according to the vertex information of the fragment texture and the character texture, and rendered to form a graphical interface. This can increase the possibility of batch processing during the rendering process, reduce the Draw Call operations during the rendering process, thereby reducing the CPU load, improving the rendering efficiency of the graphical interface, and further increasing the display frame rate of the user terminal. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1A , Figure 1B and Figure 1C It is a schematic diagram of the principle of a rendering method of a graphical interface provided by the related art;
[0034] Figure 2 is a schematic diagram of the architecture of a rendering system 100 for a graphical interface provided in an embodiment of the present application;
[0035] Figure 3 is a schematic diagram of the structure of the terminal 400 provided in an embodiment of the present application;
[0036] Figure 4 It is a flowchart of a method for rendering a graphical interface provided in an embodiment of the present application;
[0037] Figure 5 It is a flowchart of a method for rendering a graphical interface provided in an embodiment of the present application;
[0038] Fig. 6A and Figure 6B It is a schematic diagram of an application scenario of the method for rendering a graphical interface provided in an embodiment of the present application;
[0039] Figure 7 It is a schematic diagram of the principle of the method for rendering a graphical interface provided in an embodiment of the present application;
[0040] Figure 8 It is a schematic diagram of an application scenario of the method for rendering a graphical interface provided in an embodiment of the present application;
[0041] Fig. 9 It is a flowchart of a method for rendering a graphical interface provided in an embodiment of the present application;
[0042] Fig. 10A This is a schematic diagram of the principle of rectangular cropping of fragmented images provided in an embodiment of the present application;
[0043] Fig. 10B It is a schematic diagram of the principle of performing fan-shaped cropping on a fragmented image provided by an embodiment of the present application;
[0044] Fig.11It is a schematic diagram of an application scenario of the method for rendering a graphical interface provided in an embodiment of the present application;
[0045] Fig.12 It is a schematic diagram of the principle of the method for rendering a graphical interface provided in an embodiment of the present application;
[0046] Fig.13A and Fig. 13B It is a schematic diagram of the principle of the rendering method of the graphical interface provided in the embodiment of the present application. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0048] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0049] In the following description, the terms "first / second" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first / second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0051] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0052] 1) Draw Call operation: refers to the process in which the CPU prepares the elements to be drawn (such as pictures or characters (including text, punctuation, letters, etc.)) and calls the graphics programming interface. Specifically, it refers to the operation in which the CPU calls the graphics programming interface, such as DirectX or OpenGL, to instruct the GPU to render.
[0053] 2) Atlas: When multiple textures are combined into a combined texture, the combined texture is called an atlas.
[0054] 3) Shader: used to implement image rendering, including vertex shader and pixel shader. Among them, the vertex shader is mainly responsible for the calculation of the geometric relationship of vertices, and the pixel shader is mainly responsible for the calculation of the color of the source. For example, when you need to present a triangle on the graphical interface, you must first draw the vertices, because the mesh is composed of vertices. At this time, the vertex shader must be used. Specifically, the vertex information is given to the vertex shader to display the vertex information. The second is to fill the color between the areas composed of these vertices. At this time, the pixel shader is used to fill the corresponding color.
[0055] There are two main solutions for rendering graphical interfaces in related technologies, namely static atlas method and dynamic atlas method. Figure 1A , Figure 1B and Figure 1C , Figure 1A , Figure 1B and Figure 1C This is a schematic diagram of the principle of the graphical interface rendering method provided by the related technology. Figure 1A , Figure 1B and Figure 1C Detailed description.
[0056] The static atlas method is to pre-arrange the atlas content offline so that as few atlases as possible are used in the graphical interface. This is the mainstream method of current graphical interface development. For details, see Figure 1A First of all, when designing a graphical interface, the reusability of elements should be considered. For example, some borders, buttons, etc. should be used as shared resources and placed in 1 to 3 large atlases, called reuse atlases; then other non-reusable elements should be divided according to functional modules, and each module uses 1 to 2 atlases, called functional atlases; finally, for some graphical interfaces that use both functional atlases and reuse atlases, if there are many "empty spaces" left in the functional atlas, the elements in the reuse atlas can be taken out separately and merged into the functional atlas, so as to achieve performance improvement through a certain degree of redundancy.
[0057] The static atlas method has the following disadvantages: (1) The atlas allocation rules need to be reasonably planned during development. The later content adjustment will have a great impact on the early planning. In extreme cases, the atlas needs to be reallocated. (2) It takes up a lot of memory because multiple atlases need to be loaded at the same time, and there will be a large number of resources in the atlas that are not needed at the time. (3) It is impossible to realize atlas batching, for example, Figure 1CIn the figure, each color represents an atlas. In figure (a), the number of Draw Call operations is 4. In figure (b), a black atlas is added after the right side, which makes it impossible to batch the images together, causing the number of Draw Call operations to increase from 4 to 9. In figure (c), a black atlas is added after both the left and right sides, so the number of Draw Call operations increases from 4 to 5. (4) It is impossible to batch text and images together. When there are a large number of text and images interspersed, the number of Draw Call operations will become very high.
[0058] The dynamic atlas method is to unify the textures (or pictures) used in various places into one texture online to achieve the effect of reducing the atlas. Figure 1B , Figure 1B This is a diagram of placing 500 images in one texture.
[0059] The dynamic atlas method has the following disadvantages: (1) The image sizes vary greatly, resulting in a low dynamic atlas fill rate. (2) When the interface is updated, it is difficult to find a suitable image to replace the space left by temporarily unused images. (3) Two or more dynamic atlases are required. (4) It is impossible to batch text and images together. When there are a large number of text and images interspersed, the number of Draw Call operations will become very high.
[0060] In view of the above technical problems, an embodiment of the present application provides a method for rendering a graphical interface, which can improve the rendering efficiency of the graphical interface. The following describes an exemplary application of the method for rendering a graphical interface provided by an embodiment of the present application. The method for rendering a graphical interface provided by an embodiment of the present application can be implemented by various electronic devices, for example, it can be implemented by a terminal alone, or it can be implemented by a terminal and a server in collaboration.
[0061] Next, the embodiment of the present application is described by taking the collaborative implementation of the terminal and the server as an example, see Figure 2 , Figure 2 1 is a schematic diagram of the architecture of a graphical interface rendering system 100 provided in an embodiment of the present application. The graphical interface rendering system 100 includes: a server 200, a network 300, and a terminal 400, which will be described separately.
[0062] In some embodiments, the server 200 is used to send graphical interface data to the terminal 400. The network 300 is used as a medium for communication between the server 200 and the viewer terminal 400, and can be a wide area network or a local area network, or a combination of the two. The terminal 400 is used to receive the graphical interface data sent by the server 200, and render the graphical interface according to multiple pictures and multiple characters in the graphical interface data. Specifically, multiple pictures in the graphical interface data are rendered into a fragmented texture, and multiple characters in the graphical interface data are rendered into a character texture; the fragmented texture and the character texture are sampled and processed respectively, and the fragmented texture color value and the character texture color value corresponding to each pixel in the graphical interface are obtained; according to the vertex information of the fragmented texture and the character texture, the fragmented texture color value and the character texture color value corresponding to each pixel are fused and processed to obtain the fused color value of each pixel; according to the fused color value of each pixel, the graphical interface is rendered.
[0063] As an example, the graphical interface rendering method provided in the embodiment of the present application can also be implemented by the terminal 400 alone. In this way, the terminal 400 does not need to receive the graphical interface data sent by the server 200, and can directly implement the rendering of the graphical interface based on the graphical interface data stored locally in the terminal 400.
[0064] In some embodiments, it can be applied to the scene of game interface rendering. Terminal 400 can run online games or stand-alone games. When terminal 400 runs online games, it can be implemented collaboratively by terminal 400 and server 200. When terminal 400 runs stand-alone games, it can be implemented alone by terminal 400.
[0065] Taking the collaborative implementation of terminal 400 and server 200 as an example, terminal 400 receives game interface data sent by server 200, and renders multiple game images in the game interface data into a fragment texture, and renders multiple characters in the game interface data into a character texture; the fragment texture and the character texture are sampled and processed respectively to obtain the fragment texture color value and the character texture color value corresponding to each pixel in the game interface; according to the vertex information of the fragment texture and the character texture, the fragment texture color value and the character texture color value corresponding to each pixel are fused to obtain the fused color value of each pixel; according to the fused color value of each pixel, the game interface is rendered.
[0066] The game interface is usually composed of many scattered pictures and characters, and there will be a large number of Draw Call operations. Before the terminal 400 performs a Draw Call operation each time, the CPU of the terminal 400 needs to perform a lot of preparation work. When there are too many Draw Call operations, the CPU of the terminal 400 needs to increase a lot of extra overhead for preparation work, and the excessive load on the CPU itself will cause the game frame rate to drop. At the same time, since the characters and pictures in the game interface may overlap with each other, there will be problems such as increased Draw Call operations and batch interruptions (i.e., inability to batch process). In this regard, the embodiments of the present application can increase the possibility of batch processing during the rendering process, reduce the Draw Call operations during the rendering process, thereby reducing the load on the CPU, improving the rendering efficiency of the game interface, and then improving the game frame rate.
[0067] The embodiments of the present application can be implemented with the help of cloud technology. Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and network in a wide area network or a local area network to achieve data calculation, storage, processing, and sharing.
[0068] Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, and application technology based on the cloud computing business model. It can form a resource pool that can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing and storage resources.
[0069] As an example, server 200 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, as well as big data and artificial intelligence platforms.
[0070] Next, explain Figure 2 The structure of the terminal 400 in FIG. Figure 3 , Figure 3 is a schematic diagram of the structure of the terminal 400 provided in an embodiment of the present application, Figure 3 The terminal 400 shown includes: at least one processor 410, a memory 450, at least one network interface 420 and a user interface 430. The various components in the terminal 400 are coupled together via a bus system 440. It is understood that the bus system 440 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 440 is not shown in FIG. Figure 3 Various buses are labeled as bus system 440 .
[0071] Processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0072] The user interface 430 includes one or more output devices 431 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0073] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.
[0074] The memory 450 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.
[0075] In some embodiments, memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.
[0076] The operating system 451 includes system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic businesses and process hardware-based tasks.
[0077] The network communication module 452 is used to reach other electronic devices via one or more (wired or wireless) network interfaces 420. Exemplary network interfaces 420 include: Bluetooth, Wireless LAN (WiFi), and Universal Serial Bus (USB).
[0078] The presentation module 453 is used to enable presentation of information (eg, a user interface for operating peripheral devices and displaying content and information) via one or more output devices 431 (eg, a display screen, a speaker, etc.) associated with the user interface 430 .
[0079] The input processing module 454 is used to detect one or more user inputs or interactions from one of the one or more input devices 432 and translate the detected inputs or interactions.
[0080] In some embodiments, the rendering device of the graphical interface provided in the embodiments of the present application can be implemented in a software manner. Figure 3 A rendering device 455 of a graphical interface stored in a memory 450 is shown, which may be software in the form of a program or a plug-in, and includes the following software modules: a texture rendering module 4551, a sampling module 4552, a fusion module 4553, and an interface rendering module 4554. These modules are logical, and thus may be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.
[0081] Below, by Figure 2 The terminal 400 in the embodiment of the present application independently executes the rendering method of the graphical interface provided by the embodiment of the present application as an example. Figure 4 , Figure 4 is a flowchart of a method for rendering a graphical interface provided in an embodiment of the present application, which will be combined with Figure 4 The steps shown are explained.
[0082] In step S101 , a plurality of images in the graphical interface data are rendered into a fragment texture, and a plurality of characters in the graphical interface data are rendered into a character texture.
[0083] In some embodiments, a CPU in the processor 410 of the terminal 400 renders multiple images in the graphical interface data into a fragment texture, and renders multiple characters in the graphical interface data into a character texture.
[0084] In some embodiments, rendering multiple images in the graphical interface data into a fragmented image texture may include: removing the transparent area of each image in the graphical interface data; performing the following processing for each image without the transparent area: cutting the image into multiple fragments along a first reference direction, and rendering the multiple fragments into the fragmented image texture in sequence along a second reference direction; wherein the first reference direction and the second reference direction are perpendicular to each other.
[0085] As an example, when the picture is a rectangle, the first reference direction and the second reference direction correspond to being parallel to two adjacent edges in the picture; cutting the picture into multiple broken pictures along the first reference direction, and rendering the multiple broken pictures in sequence into the broken picture texture along the second reference direction may include: cutting the picture into multiple broken pictures of the same height at equal intervals along the first reference direction, and rendering the multiple broken pictures in sequence into the broken picture texture along the second reference direction.
[0086] For example, see Fig.13A , Fig.13A is a schematic diagram of the principle of the method for rendering a graphical interface provided in an embodiment of the present application, Fig.13A In the example, the first reference direction is parallel to the a side of the rectangular image 131, and the second reference direction is parallel to the b side of the rectangular image 131. The rectangular image 131 is cut into four pieces 132 of the same height (or width) at equal intervals along the first reference direction, and the four pieces 132 are sequentially rendered from top to bottom along the second reference direction into the piece texture 133. Of course, the four pieces 132 can also be sequentially rendered from bottom to top along the second reference direction into the piece texture 133. Fig.13A It only shows that the four fragments 132 are sequentially rendered into the fragment texture 133 from top to bottom along the second reference direction, and so on.
[0087] For example, see Fig. 13B , Fig. 13B is a schematic diagram of the principle of the method for rendering a graphical interface provided in an embodiment of the present application, Fig. 13B In the example, the first reference direction is parallel to the b side of the rectangular image 131, and the second reference direction is parallel to the a side of the rectangular image 131. The rectangular image 131 is cut into four pieces 132 of the same height (or width) at equal intervals along the first reference direction, and the four pieces 132 are sequentially rendered from left to right along the second reference direction into the piece texture 133. Of course, the four pieces 132 can also be sequentially rendered from right to left along the second reference direction into the piece texture 133. Fig. 13B It only shows that the four fragments 132 are sequentially rendered into the fragment texture 133 from left to right along the second reference direction, and so on.
[0088] The related technology usually renders the entire image into a texture, which has a relatively simple structure and is easy to process. However, it is difficult to effectively utilize space when combining multiple images into a large fragmented image texture (such as a dynamic atlas method), resulting in low resource utilization. The embodiment of the present application unifies the height of the fragmented images and renders them into the fragmented image texture in sequence. Compared with the dynamic atlas method, it can not only more fully fill and utilize the space of the fragmented image texture and save the number of fragmented image textures, but also improve the success rate of image replacement when the graphical interface is updated. And the embodiment of the present application renders all images into a fragmented image texture, which can not only avoid the waste of resources required for image allocation and planning for multiple fragmented image textures, but also reduce the number of times the fragmented image texture is loaded, saving the terminal's occupied memory, thereby improving the success rate of batch processing.
[0089] As an example, before removing the transparent area of each picture in the graphical interface data, the method may also include: stitching multiple pictures in the graphical interface data to obtain a stitched picture; determining the distance between the two farthest vertices in the stitched picture; when the distance between the two farthest vertices in the stitched picture is greater than the distance between the two farthest vertices in the fragmented texture, determining that an operation of removing the transparent area of each picture in the graphical interface data will be performed.
[0090] For example, stitching multiple images in the graphical interface data may be stitching the multiple images along the boundary line of each image to obtain a stitched image. When the fragment texture is a rectangle, the distance between the two farthest vertices in the fragment texture is the length of the diagonal of the rectangle. When the distance between the two farthest vertices in the stitched image is greater than the distance between the two farthest vertices in the fragment texture, it indicates that all images cannot be rendered into one fragment texture. At this time, considering that the transparent area of the image does not need to be rendered during the rendering process of the graphical interface, the filling space in the fragment texture can be saved by removing the transparent area of the image, thereby improving the rendering efficiency of the graphical interface.
[0091] As an example, before removing the transparent area of each picture in the graphical interface data, the following may also be included: determining the area of the fragmented image texture; determining the area of each picture in the graphical interface data, and adding up the area of each picture to obtain the total image area; when the area of the fragmented image texture is smaller than the total image area, determining to perform an operation of removing the transparent area of each picture in the graphical interface data.
[0092] For example, when the area of the fragmented texture is smaller than the total image area, it means that even if all images are spliced according to the principle of minimum splicing area, all images cannot be rendered into one fragmented texture. At this time, the transparent area of the image can be removed to save the filling space in the fragmented texture, thereby improving the rendering efficiency of the graphical interface. Compared with the above-mentioned operation of determining whether to remove the transparent area of the image based on the distance between the two farthest vertices in the fragmented texture, the embodiment of the present application has a simpler calculation process and can save computing resources.
[0093] In some embodiments, after rendering multiple images in the graphical interface data into a fragmented image texture, the following processing may be performed for each fragmented image in the fragmented image texture: determining an area in the fragmented image for rendering in the graphical interface, and dividing the area into multiple sub-areas having specific shapes (such as triangles, rectangles, etc.); determining vertex information for rendering each sub-area; and combining vertex information corresponding to multiple sub-areas to obtain vertex information for rendering the fragmented image.
[0094] As an example, vertex information includes at least one of the following: vertex position, texture coordinates (or UV coordinates). The vertex position is used to define the position of the fragment image to be rendered in the graphical interface, and the UV coordinates are used to define the position of each point on the fragment image, which can determine the position of the surface texture map.
[0095] As an example, Fig. 10A In the figure, on the left, a rectangular mask is used to partially block the fragmented image, so that only the partially unblocked fragmented image is displayed in the rendered graphics interface; on the right, the display position (i.e., the above-mentioned vertex information) of each triangle in the fragmented image (i.e., the above-mentioned sub-area) in the rendered graphics interface is accurately calculated through rectangular clipping, and the vertex information corresponding to multiple triangles is combined to obtain the vertex information used to render the fragmented image.
[0096] In some embodiments, after rendering multiple images in the graphical interface data into a fragmented image texture, the process may include: selecting multiple fragmented images in the fragmented image texture for splicing processing to obtain a spliced group image; determining the center position of the spliced group image, and determining the area in the spliced group image for rendering in the graphical interface; drawing a fan-shaped area with the center position as the vertex, wherein the fan-shaped area includes the area in the spliced group image for rendering in the graphical interface; performing the following processing on each fragmented image in the spliced group image: determining the radius of the fan-shaped area and the intersection between the fragmented images, and using the vertex information of the intersection as the vertex information for rendering the fragmented images.
[0097] As an example, Fig. 10BIn the figure, on the left, a fan-shaped mask is used to merge and display a graphic composed of multiple fragments (i.e., the above-mentioned spliced group image); on the right, the intersection between the two radii of the fan and the spliced group image is accurately calculated through fan clipping, and the vertex information of the intersection is used as the vertex information for rendering the fragments.
[0098] The embodiments of the present application provide a variety of clipping methods to determine the vertex information of the fragmented images, which can improve the accuracy of calculating the vertex information of the fragmented images, not only ensure the correct display of the image, but also reduce unnecessary masks, avoid interrupting batch processing, and reduce the number of Draw Call operations.
[0099] In some embodiments, rendering multiple characters in graphical interface data into a character texture may include: extracting a character file from the graphical interface data, wherein the character file includes multiple characters; parsing the character file to obtain multiple dot matrix characters corresponding one-to-one to the multiple characters; dividing the character texture into multiple character areas, wherein the number of the multiple character areas is greater than or equal to the number of the multiple dot matrix characters; rendering the multiple dot matrix characters into multiple character areas in sequence, wherein each character area includes at most one dot matrix character.
[0100] As an example, dot matrix characters are a method for displaying character information, in which each character (such as text, letters, numbers, punctuation marks, etc.) is represented by a set of two-dimensional pixel information, and the area where the character stroke passes through is stored as 1, otherwise it is stored as 0. The processing and display speed of dot matrix characters is relatively fast, and dot matrix characters are usually represented in hexadecimal.
[0101] As an example, Fig.12 In the example, the character texture is divided into Fig.12 The multiple small blocks 121 (equivalent to the above-mentioned character area) shown render multiple dot matrix characters in sequence into the multiple small blocks 121, wherein each small block 121 includes at most one dot matrix character.
[0102] Taking 10 dot matrix characters as an example, the character texture can be divided into 4×4=16 character areas, so that all dot matrix characters can be rendered into the character texture, and each character area includes at most one dot matrix character, so that 4 unfilled character areas can be left. The character texture can also be divided into 2×5=10 character areas, so that all dot matrix characters can be rendered into the character texture, excluding unfilled character areas.
[0103] The embodiment of the present application divides the character texture into multiple character areas, and then fills the divided character areas. Compared with directly filling characters without dividing the character areas, the embodiment of the present application can improve the filling rate and calculation efficiency of the character texture.
[0104] In step S102, the fragmented image texture and the character texture are sampled respectively to obtain the fragmented image texture color value and the character texture color value corresponding to each pixel point in the graphical interface.
[0105] In some embodiments, the CPU in the processor 410 of the terminal 400 calls the shader of the GPU in the processor 410 to sample and process the fragment texture and the character texture respectively, and obtains the fragment texture color value and the character texture color value corresponding to each pixel in the graphical interface.
[0106] In some embodiments, the following processing is performed for each pixel in the graphical interface: sampling is performed at the position corresponding to the pixel in the fragment texture through a texture sampling function to obtain the fragment texture coordinates of the pixel; sampling is performed at the position corresponding to the pixel in the character texture through a texture sampling function to obtain the character texture coordinates of the pixel; the fragment texture color value corresponding to the pixel is determined based on the fragment texture coordinates of the pixel; and the character texture color value corresponding to the pixel is determined based on the character texture coordinates of the pixel.
[0107] As an example, the area of the broken image texture and the area of the character texture can be the same, and the area of the broken image texture and the area of the character texture can always remain unchanged during the rendering process of the graphical interface. There are many reasons for interrupting the batch during the interface rendering process, and the reason of texture memory change accounts for a high proportion. In the embodiment of the present application, the area of the broken image texture and the character texture is the same and fixed, that is, the memory of the broken image texture and the character texture is fixed, which can avoid the problem of batch failure due to changes in texture memory, thereby improving the success rate of batching.
[0108] As an example, determining the fragment texture color value corresponding to a pixel point according to the fragment texture coordinates of the pixel point may include: converting the fragment texture coordinates of the pixel point into a fragment array index, and using the fragment texture color value corresponding to the fragment array index as the fragment texture color value of the pixel point.
[0109] For example, there is a one-to-one correspondence between the fragment array index and the fragment texture color value, and there is a mapping relationship, so the fragment texture color value corresponding to the fragment array index can be determined by looking up the mapping relationship.
[0110] As an example, determining the character texture color value corresponding to a pixel point according to the character texture coordinates of the pixel point may include: converting the character texture coordinates of the pixel point into a character array index, and using the character texture color value corresponding to the character array index as the character texture color value of the pixel point.
[0111] For example, there is a one-to-one correspondence between the character array index and the character texture color value, and there is a mapping relationship, so the character texture color value corresponding to the character array index can be determined by looking up the mapping relationship.
[0112] The embodiment of the present application samples and processes the fragmented image texture and the character texture respectively, and obtains the fragmented image texture color value and the character texture color value corresponding to each pixel point in the graphical interface. The character rendering and image rendering in the graphical interface can be batch processed, thereby reducing the number of Draw Call operations and improving rendering efficiency.
[0113] In step S103, the color value of the fragment texture and the color value of the character texture corresponding to each pixel are fused according to the vertex information of the fragment texture and the character texture to obtain a fused color value of each pixel.
[0114] In some embodiments, the CPU in the processor 410 of the terminal 400 calls the shader of the GPU in the processor 410 to fuse the fragment texture color value and the character texture color value corresponding to each pixel point according to the vertex information of the fragment texture and the character texture to obtain the fused color value of each pixel point.
[0115] In some embodiments, see Figure 5 , Figure 5 is a flowchart of a method for rendering a graphical interface provided in an embodiment of the present application, based on Figure 4 Step S103 may include steps S1031 to S1033. It should be noted that steps S1031 to S1033 are operations performed on each pixel in the graphical interface.
[0116] In step S1031, a first weight of a corresponding pixel point is determined according to vertex information of the fragment texture.
[0117] In some embodiments, vertex information of a target fragment corresponding to a pixel point is determined in the fragment texture, and texture coordinates in the vertex information of the target fragment are determined; and a target component in the texture coordinates is determined as a first weight corresponding to the pixel point.
[0118] As an example, the texture coordinates include multiple types, such as abscissa components (or x components) and ordinate components (or y components). The target component in the texture coordinates in the vertex information of the target fragment can be the abscissa component or the ordinate component in the texture coordinates.
[0119] In step S1032, a second weight of a corresponding pixel point is determined according to vertex information of the character texture.
[0120] In some embodiments, vertex information of a target character corresponding to a pixel point is determined in the character texture, and texture coordinates in the vertex information of the target character are determined; and a target component in the texture coordinates is determined as a second weight corresponding to the pixel point.
[0121] As an example, the target component in the texture coordinates in the vertex information of the target character can be the horizontal coordinate component or the vertical coordinate component in the texture coordinates. Specifically, when the target component in the texture coordinates in the vertex information of the target fragment is the horizontal coordinate component in the texture coordinates, the target component in the texture coordinates in the vertex information of the target character is the horizontal coordinate component in the texture coordinates; when the target component in the texture coordinates in the vertex information of the target fragment is the vertical coordinate component in the texture coordinates, the target component in the texture coordinates in the vertex information of the target character is the vertical coordinate component in the texture coordinates, thereby ensuring the uniformity of determining the color value of the pixel point and improving the accuracy of the rendering of the graphical interface.
[0122] In step S1033, weighted sum processing is performed on the fragment texture color value corresponding to the pixel point and the character texture color value corresponding to the pixel point according to the first weight and the second weight to obtain a fused color value of the pixel point.
[0123] In some embodiments, the first weight and the color value of the fragment texture corresponding to the pixel point are multiplied to obtain a first product result; the second weight and the character texture color value corresponding to the pixel point are multiplied to obtain a second product result; the first product result and the second product result are added to obtain a fused color value of the pixel point.
[0124] In step S104, a graphical interface is rendered according to the fused color value of each pixel.
[0125] In some embodiments, the GPU in the processor 410 of the terminal 400 sends the fused color value of each pixel in the graphical interface to the output device 431 (eg, a display screen) to render the graphical interface in the output device 431 .
[0126] In some embodiments, before step S101, the method may further include: determining the area of each image in the graphical interface data, and rendering images with an area greater than an area threshold into the background texture; thus, before step S103, the method may include: sampling the background texture to obtain a background texture color value corresponding to each pixel in the graphical interface; step S103 may include: fusing the fragment texture color value, character texture color value and background texture color value corresponding to each pixel according to vertex information of the fragment texture, character texture and background texture to obtain a fused color value for each pixel.
[0127] As an example, the area threshold may be a default value, or a value set by a user, a terminal, or a server.
[0128] As an example, sampling the background texture to obtain the background texture color value corresponding to each pixel in the graphical interface may include: performing the following processing on each pixel in the graphical interface: sampling the position corresponding to the pixel in the background texture through a texture sampling function to obtain the background texture coordinates of the pixel; determining the background texture color value corresponding to the pixel based on the background texture coordinates of the pixel.
[0129] For example, determining the background texture color value corresponding to the pixel point according to the background texture coordinates of the pixel point may include: converting the background texture coordinates of the pixel point into a background array index, and using the background texture color value corresponding to the background array index as the background texture color value of the pixel point.
[0130] For example, there is a one-to-one correspondence between the background array index and the background texture color value, and there is a mapping relationship, so the background texture color value corresponding to the background array index can be determined by looking up the mapping relationship.
[0131] As an example, according to the vertex information of the fragment texture, character texture and background texture, the fragment texture color value, character texture color value and background texture color value corresponding to each pixel are fused to obtain the fused color value of each pixel, which may include: performing the following processing for each pixel: determining a first weight corresponding to the pixel according to the vertex information of the fragment texture, determining a second weight corresponding to the pixel according to the vertex information of the character texture, and determining a third weight corresponding to the pixel according to the vertex information of the background texture; performing weighted summation processing on the fragment texture color value corresponding to the pixel, the character texture color value corresponding to the pixel and the background texture color value corresponding to the pixel according to the first weight, the second weight and the third weight to obtain the fused color value of the pixel.
[0132] For example, the process of determining the first weight and the second weight is the same as the above embodiment and will not be described in detail. Determining the third weight of the corresponding pixel point based on the vertex information of the background texture may include: determining the vertex information of the target background corresponding to the pixel point in the background texture, and determining the texture coordinates in the vertex information of the target background; determining the target component in the texture coordinates as the third weight of the corresponding pixel point.
[0133] For example, according to the first weight, the second weight and the third weight, the weighted summation processing is performed on the broken image texture color value corresponding to the pixel point, the character texture color value corresponding to the pixel point and the background texture color value corresponding to the pixel point to obtain the fused color value of the pixel point, which may include: multiplying the first weight and the broken image texture color value corresponding to the pixel point to obtain a first product result; multiplying the second weight and the character texture color value corresponding to the pixel point to obtain a second product result; multiplying the third weight and the background texture color value corresponding to the pixel point to obtain a third product result; adding the first product result, the second product result and the third product result to obtain the fused color value of the pixel point.
[0134] As an example, the target component in the texture coordinates in the vertex information of the target background can be the horizontal coordinate component or the vertical coordinate component in the texture coordinates. Specifically, when the target component in the texture coordinates in the vertex information of the target fragment and the target component in the texture coordinates in the vertex information of the target character are the horizontal coordinate components in the texture coordinates, the target component in the texture coordinates in the vertex information of the target background is the horizontal coordinate component in the texture coordinates; when the target component in the texture coordinates in the vertex information of the target fragment and the target component in the texture coordinates in the vertex information of the target character are the vertical coordinate components in the texture coordinates, the target component in the texture coordinates in the vertex information of the target background is the vertical coordinate component in the texture coordinates, thereby ensuring the uniformity of determining the color value of the pixel point and improving the accuracy of rendering the graphical interface.
[0135] For example, Fig.11 In the process of separating the large-area image (or large image) used in the background from the fragmented texture, the fragmented texture can be prevented from being filled up too early.
[0136] The embodiment of the present application saves some large-area images used in the background separately as background textures, which can avoid the situation where the fragmented image texture is too early loaded due to the large-area images and the remaining fragmented images need to be allocated to the second fragmented image texture, thereby increasing the Draw Call operations.
[0137] Below, the rendering method of the graphical interface provided in the embodiment of the present application is explained by taking the rendering of the game interface as an example.
[0138] The embodiment of the present application can achieve batch processing and improve operating efficiency by rendering all images and characters used in the current game interface into their respective textures (that is, rendering all currently used images into fragment textures, and rendering all currently used characters into character textures). In extreme cases, the number of DrawCall operations of the static interface can reach 1.
[0139] In some embodiments, first, all images used in a graphical interface (hereinafter referred to as the interface) are processed offline into a Smash format, that is, each image is cut into multiple fragments of equal pixel height; then, the multiple fragments are dynamically assembled into a 2048×2048 (for example, RGBA32 format) fragment texture by utilizing the characteristic that images displayed on the same screen will not exceed the resolution of the terminal (for example, a mobile phone, a tablet computer, etc.); then, the characters used in the interface are rendered onto an independent 2048×2048 (R8 format) character texture; finally, through the flag bit on the vertex information, the Shader performs sampling on each pixel of the interface on two textures (i.e., the fragment texture and the character texture) during calculation, and performs weighted synthesis to output the rendered interface.
[0140] As an example, the flag bit on the vertex information borrows the x variable in the UV2 coordinate, where the value of the x variable is 0 or 1 (i.e., weight). The shader samples the two textures separately through the flag bit on the vertex information, and the process of weighted synthesis and outputting the rendering interface can be: the shader samples from the fragment texture and the character texture for each pixel of the interface at the same time, obtains the fragment texture color value and the character texture color value of each pixel, and then performs weighted synthesis and output of the fragment texture color value and the character texture color value through the x variable in the flag bit on the vertex information to obtain the rendered interface. In this way, since the speed of weighted calculation in the shader is faster than the speed of branch calculation, the rendering efficiency can be improved.
[0141] As an example, the memory of the broken image texture occupies 2048×2048×32 bits (RGBA32 format) = 16MB, the memory of the character texture occupies 2048×2048×8 bits (R8 format) = 4MB, and the memory of the interface texture (including the broken image texture and the character texture) is fixed at 16M+4M=20M. There are many reasons for interrupting the batch during the interface rendering process, mainly the rendering state, among which the reason of the change of the map memory accounts for a high proportion. In the embodiment of the present application, the memory of the broken image texture and the character texture is fixed, which can avoid the problem of batch failure due to the change of texture memory, thereby improving the success rate of batching.
[0142] For example, see Fig. 6A and Figure 6B , Fig. 6A and Figure 6B It is a schematic diagram of an application scenario of the method for rendering a graphical interface provided in an embodiment of the present application. Fig. 6A In FIG. 6 , “Batches” in area 601 indicates how many Draw Call operations are there per frame, and “Tris” indicates that 848 triangles are used in the frame and can be drawn in one Draw Call operation. Figure 6BBy rendering the image and the character together, the number of Draw Call operations 602 can be reduced from 21 to 15. The embodiment of the present application can save at least 50% of the memory and reduce at least 50% of the Draw Call operations.
[0143] Combine the following Figure 7 The specific implementation of the graphical interface rendering method provided in the embodiment of the present application is described. Figure 7 It is a schematic diagram of the principle of the rendering method of the graphical interface provided in the embodiment of the present application.
[0144] (1) Image processing
[0145] In some embodiments, the original images of different widths and heights are uniformly processed into multiple fragments of 32 pixels in height, and the redundant fully transparent areas are removed. The multiple fragments are stored in RGBA32 format in a custom format, wherein the quality of the user interface (UI) is poor if it is compressed and stored. Each X (i.e., the width of the fragment) × 32 fragment is losslessly compressed in the WebP format, and the relative compression rate is relatively high. At runtime, after reading the data file (i.e., the fragment) from the disk, the fragment is dynamically copied to a 2048×2048 fragment texture. Since the height of the fragment is unified, compared with the conventional dynamic atlas method, it can more fully fill and utilize the space of the fragment texture, and the success rate of replacement is also greatly improved.
[0146] As an example, after filling multiple fragments into a fragment texture, the vertex positions, UV coordinates, etc. of the fragments can be accurately calculated, and the multiple fragments can be pieced together into a triangle strip according to the vertex positions and UV coordinates, so as to display the image at the correct position on the interface.
[0147] For example, see Figure 8 , Figure 8 It is a schematic diagram of an application scenario of the method for rendering a graphical interface provided in an embodiment of the present application. Figure 8 In the figure, a complete picture 801 is composed of multiple rectangles (actually triangles) tightly stitched together, and the fragments of each rectangle are scattered in the fragment texture. The fragment texture 802 will be gradually filled from bottom to top during operation, and new fragments will be replaced in invalid areas. In related technologies, the entire picture is usually displayed, and the display area is a rectangle. This structure is relatively simple and easy to process. However, it is difficult to effectively use the space when combining multiple pictures into a large fragment texture, and there will be more fully transparent pixels, resulting in low resource utilization.
[0148] As an example, see Fig. 9 , Fig. 9 It is a flowchart of a method for rendering a graphical interface provided in an embodiment of the present application. Fig. 9When displaying a picture, first read the custom format file from the disk (step S901), then obtain multiple fragments (step S902), then apply for space from the dynamic atlas (step S903), and then fill the fragments into the dynamic atlas in turn (step S904), and finally calculate the vertex positions of the fragments and the UV coordinates in the atlas, and display them correctly (step S905).
[0149] In some embodiments, when calculating the vertex positions of the broken images, support for cropping methods can be added to the broken images, which can not only improve the accuracy of calculating the vertex positions of the broken images and ensure the correct display of the images, but also reduce unnecessary masks (because each additional mask adds at least 3 Draw Call operations) to avoid interrupting the batch.
[0150] As an example, see Fig. 10A , Fig. 10A It is a schematic diagram of the principle of rectangular cropping of fragments of an image provided in an embodiment of the present application. Fig. 10A In the figure, on the left, a Mask (rectangle) is used to partially block the fragmented image, allowing only part of the fragmented image to be displayed; on the right, the display position of the triangle in the fragmented image is accurately calculated through rectangular clipping to facilitate subsequent rendering of the fragmented image.
[0151] As an example, see Fig. 10B , Fig. 10B It is a schematic diagram of the principle of fan-shaped cropping of fragments of an image provided in an embodiment of the present application. Fig. 10B In the figure, on the left, a Mask (fan) is used to merge and display a graphic composed of multiple fragments (i.e., the above-mentioned spliced group image); on the right, the display position of the triangle is accurately calculated through fan clipping (i.e., the intersection of the two sides of the fan and the fragment band is found) to facilitate subsequent rendering of the fragments.
[0152] In some embodiments, some large-area images used in the background are saved separately as atlases (i.e., the above-mentioned background textures) to avoid the fragment texture being filled up too early due to the large image and the need to allocate the remaining fragments to the second fragment texture, which will increase the Draw Call operations. See Fig.11 , Fig.11 is a schematic diagram of an application scenario of a method for rendering a graphical interface provided in an embodiment of the present application, Fig.11 Separating large images from broken textures can prevent the broken textures from being filled up too early.
[0153] If one broken image texture cannot hold all broken images, at least two broken image textures are required. For example, one broken image texture is A and the other broken image texture is B. Then, when drawing, a display order of ABA BAB may appear. Since different broken image textures are difficult to batch together, the number of Draw Call operations will be greatly increased. Therefore, the embodiment of the present application places all broken images in one broken image texture to reduce the number of Draw Call operations.
[0154] (2) Word processing
[0155] In some embodiments, since the original engine will render different characters to different textures, for example, if two characters are used in the game, there will be two character textures, so the engine needs to be modified. Specifically, a 2048×2048 character texture is used to render all characters for unified management. Fig.12 , Fig.12 is a schematic diagram of the principle of the method for rendering a graphical interface provided in an embodiment of the present application, Fig.12 The image contains nearly 4,000 characters and uses an optimized filling algorithm, so that the time required to update the entire image is less than 0.5 seconds, and it can be completed in the loading process. The above-mentioned optimized filling algorithm refers to dividing the character texture into Fig.12 The multiple small blocks 121 (equivalent to the above-mentioned character area) shown take into account both filling rate and computing efficiency. Compared with related technologies (such as MaxRects algorithm), better and more stable computing efficiency is achieved, while the filling rate of the whole image is maintained at about 80%.
[0156] (3) Picture and text display together
[0157] Through the extra flag bit on the vertex information, the shader samples two textures (i.e., the fragment texture and the character texture) during calculation, and weights and synthesizes the output color, so that the rendering effect of the picture remains unchanged. The embodiment of the present application will slightly increase the computing load on the GPU, but since most of the time in the game is consumed by the CPU, the burden on the CPU can be reduced by reducing the Draw Call operation, which can greatly improve the rendering efficiency of the picture, thereby increasing the frame rate of the game, reducing heat, and improving the user experience.
[0158] Combine the following Figure 3 The present invention illustrates an exemplary structure of a rendering device for a graphical interface provided in an embodiment of the present application implemented as a software module.
[0159] In some embodiments, Figure 3As shown, the software modules in the rendering device 455 of the graphical interface stored in the memory 450 may include: a texture rendering module 4551, which is used to render multiple images in the graphical interface data into a fragmented image texture, and to render multiple characters in the graphical interface data into a character texture; a sampling module 4552, which is used to sample the fragmented image texture and the character texture respectively, and obtain the fragmented image texture color value and the character texture color value corresponding to each pixel in the graphical interface; a fusion module 4553, which is used to fuse the fragmented image texture color value and the character texture color value corresponding to each pixel according to the vertex information of the fragmented image texture and the character texture, and obtain the fused color value of each pixel; an interface rendering module 4554, which is used to render a graphical interface according to the fused color value of each pixel.
[0160] In the above scheme, the texture rendering module 4551 is also used to remove the transparent area of each picture in the graphical interface data; the following processing is performed for each picture from which the transparent area is removed: the picture is cut into multiple pieces along a first reference direction, and the multiple pieces are rendered into the piece texture in sequence along a second reference direction; wherein the first reference direction and the second reference direction are perpendicular to each other.
[0161] In the above scheme, when the image is a rectangle, the first reference direction and the second reference direction correspond to two adjacent edges in the image; the texture rendering module 4551 is also used to cut the image into multiple pieces of the same height at equal intervals along the first reference direction, and render the multiple pieces into the piece texture in sequence along the second reference direction.
[0162] In the above scheme, the texture rendering module 4551 is also used to stitch multiple pictures in the graphical interface data to obtain a stitched picture; determine the distance between the two farthest vertices in the stitched picture; when the distance between the two farthest vertices in the stitched picture is greater than the distance between the two farthest vertices in the fragmented texture, determine to perform an operation of removing the transparent area of each picture in the graphical interface data.
[0163] In the above scheme, the texture rendering module 4551 is also used to extract a character file from the graphical interface data, wherein the character file includes multiple characters; parse the character file to obtain multiple dot matrix characters corresponding to the multiple characters; divide the character texture into multiple character areas, wherein the number of the multiple character areas is greater than or equal to the number of the multiple dot matrix characters; render the multiple dot matrix characters into multiple character areas in sequence, wherein each character area includes at most one dot matrix character.
[0164] In the above scheme, the sampling module 4552 is also used to perform the following processing on each pixel point in the graphical interface: through the texture sampling function, sampling processing is performed at the position corresponding to the pixel point in the fragment texture to obtain the fragment texture coordinates of the pixel point; through the texture sampling function, sampling processing is performed at the position corresponding to the pixel point in the character texture to obtain the character texture coordinates of the pixel point; the fragment texture color value corresponding to the pixel point is determined according to the fragment texture coordinates of the pixel point; the character texture color value corresponding to the pixel point is determined according to the character texture coordinates of the pixel point; wherein the area of the fragment texture is the same as the area of the character texture.
[0165] In the above scheme, the sampling module 4552 is also used to convert the fragment texture coordinates of the pixel point into the fragment array index, and use the fragment texture color value corresponding to the fragment array index as the fragment texture color value of the pixel point; convert the character texture coordinates of the pixel point into the character array index, and use the character texture color value corresponding to the character array index as the character texture color value of the pixel point.
[0166] In the above scheme, the fusion module 4553 is also used to perform the following processing for each pixel: determine the first weight of the corresponding pixel according to the vertex information of the fragment texture, and determine the second weight of the corresponding pixel according to the vertex information of the character texture; according to the first weight and the second weight, perform weighted summation processing on the fragment texture color value corresponding to the pixel and the character texture color value corresponding to the pixel to obtain the fused color value of the pixel.
[0167] In the above scheme, the fusion module 4553 is also used to determine the vertex information of the target fragment corresponding to the pixel point in the fragment texture, and determine the texture coordinates in the vertex information of the target fragment; determine the target component in the texture coordinates as the first weight of the corresponding pixel point; determine the vertex information of the target character corresponding to the pixel point in the character texture, and determine the texture coordinates in the vertex information of the target character; determine the target component in the texture coordinates as the second weight of the corresponding pixel point.
[0168] In the above scheme, the texture rendering module 4551 is also used to perform the following processing on each fragment in the fragment texture: determine the area in the fragment for rendering in the graphical interface, and divide the area into multiple sub-areas with specific shapes; determine the vertex information for rendering each sub-area; combine the vertex information corresponding to multiple sub-areas to obtain the vertex information for rendering the fragment.
[0169] In the above scheme, the texture rendering module 4551 is also used to select multiple broken pictures in the broken picture texture for splicing processing to obtain a spliced group picture; determine the center position of the spliced group picture, and determine the area in the spliced group picture used for rendering in the graphical interface; draw a fan-shaped area with the center position as the vertex, wherein the fan-shaped area includes the area in the spliced group picture used for rendering in the graphical interface; perform the following processing for each broken picture in the spliced group picture: determine the radius of the fan-shaped area and the intersection between the broken pictures, and use the vertex information of the intersection as the vertex information for rendering the broken pictures.
[0170] In the above scheme, the texture rendering module 4551 is also used to determine the area of each image in the graphical interface data, and render the images with an area greater than the area threshold into the background texture; the sampling module 4552 is also used to sample the background texture to obtain the background texture color value corresponding to each pixel in the graphical interface; the fusion module 4553 is also used to fuse the fragment texture color value, character texture color value and background texture color value corresponding to each pixel according to the vertex information of the fragment texture, character texture and background texture to obtain the fused color value of each pixel.
[0171] Taking the electronic device as a computer device as an example, the embodiment of the present application provides a computer program product or a computer program, which includes a computer instruction, and the computer instruction is stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the rendering method of the graphical interface described in the embodiment of the present application.
[0172] The embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, the processor will be caused to execute the graphical interface rendering method provided by the embodiment of the present application, for example, Figure 4 and Figure 5 The graphical interface rendering method shown is for various computing devices including computers including intelligent terminals and servers.
[0173] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EP ROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or it may be various devices including one or any combination of the above memories.
[0174] In some embodiments, computer executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0175] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file storing other programs or data, such as in one or more scripts in a hypertext markup language document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0176] By way of example, computer executable instructions may be deployed to be executed on one computing device or on multiple computing devices located at one site or on multiple computing devices distributed across multiple sites and interconnected by a communication network.
[0177] To summarize, the embodiment of the present application renders the images and characters in the graphical interface data into different textures respectively, and according to the vertex information of the fragmented image texture and the character texture, fuses the fragmented image texture color value and the character texture color value of each pixel point sampled to render a graphical interface. This can improve the possibility of batch processing during the rendering process, reduce the Draw Call operations during the rendering process, thereby reducing the CPU load, improving the rendering efficiency of the graphical interface, and further improving the display frame rate of the user terminal.
[0178] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. A method for rendering a graphical interface, characterized in that: The method comprises: Rendering a plurality of images in the graphical interface data into a fragmented image texture, and rendering a plurality of characters in the graphical interface data into a character texture; The fragmented image texture and the character texture are sampled respectively to obtain the fragmented image texture color value and the character texture color value corresponding to each pixel point in the graphical interface; For each pixel point, determine a first weight and a second weight of the pixel point according to vertex information of the fragmented image texture and the character texture, respectively, wherein the first weight is a target component of texture coordinates in vertex information of a target fragmented image, the target fragmented image corresponds to the pixel point in the fragmented image texture, and the second weight is a target component of texture coordinates in vertex information of a target character, the target character corresponds to the pixel point in the character texture; According to the first weight and the second weight, weighted summing processing is performed on the fragment texture color value corresponding to the pixel point and the character texture color value corresponding to the pixel point to obtain a fused color value of the pixel point; The graphical interface is formed by rendering according to the fused color value of each pixel.
2. The method according to claim 1, characterized in that The rendering of the plurality of images in the graphical interface data into the fragmented image texture comprises: Removing the transparent area of each picture in the graphical interface data; The following processing is performed for each of the pictures after removing the transparent area: Cutting the image into a plurality of fragments along a first reference direction, and rendering the plurality of fragments into the fragment texture in sequence along a second reference direction; The first reference direction and the second reference direction are perpendicular to each other.
3. The method according to claim 2, characterized in that Before removing the transparent area of each picture in the graphical interface data, the method further includes: Splicing multiple images in the graphical interface data to obtain a spliced image; Determine the distance between two vertices that are farthest apart in the stitched image; When the distance between the two farthest vertices in the spliced image is greater than the distance between the two farthest vertices in the fragmented image texture, it is determined that an operation of removing the transparent area of each image in the graphical interface data will be performed.
4. The method according to claim 2, characterized in that: When the image is a rectangle, the first reference direction and the second reference direction are parallel to two adjacent sides of the image; The step of cutting the image into a plurality of fragments along a first reference direction, and sequentially rendering the plurality of fragments into the fragment texture along a second reference direction, comprises: The image is cut into a plurality of pieces with the same height at equal intervals along the first reference direction, and the plurality of pieces are sequentially rendered into the piece texture along the second reference direction.
5. The method according to claim 1, characterized in that The rendering of the plurality of characters in the graphical interface data into the character texture comprises: Extracting a character file from the graphical interface data, wherein the character file includes the plurality of characters; Parsing the character file to obtain a plurality of dot matrix characters corresponding to the plurality of characters; Dividing the character texture into a plurality of character regions, wherein the number of the plurality of character regions is greater than or equal to the number of the plurality of dot matrix characters; The plurality of dot matrix characters are sequentially rendered into the plurality of character regions, wherein each of the character regions includes at most one dot matrix character.
6. The method according to claim 1, characterized in that The sampling process is performed on the fragmented image texture and the character texture respectively to obtain the fragmented image texture color value and the character texture color value corresponding to each pixel point in the graphical interface, including: The following processing is performed for each pixel in the graphical interface: By using a texture sampling function, sampling is performed on the position corresponding to the pixel point in the fragment texture to obtain the fragment texture coordinates of the pixel point; By using a texture sampling function, sampling is performed at a position corresponding to the pixel point in the character texture to obtain a character texture coordinate of the pixel point; Determine the color value of the fragmented image texture corresponding to the pixel point according to the fragmented image texture coordinates of the pixel point; Determine the character texture color value corresponding to the pixel point according to the character texture coordinates of the pixel point; The area of the fragment texture is the same as the area of the character texture.
7. The method according to claim 6, characterized in that The determining the fragment texture color value corresponding to the pixel point according to the fragment texture coordinates of the pixel point includes: The fragment texture coordinates of the pixel point are converted into fragment array subscripts, and the fragment texture color value corresponding to the fragment array subscript is used as the fragment texture color value of the pixel point; The determining the character texture color value corresponding to the pixel point according to the character texture coordinates of the pixel point includes: The character texture coordinates of the pixel point are converted into a character array subscript, and the character texture color value corresponding to the character array subscript is used as the character texture color value of the pixel point.
8. The method according to claim 1, characterized in that After rendering the plurality of images in the graphical interface data into the fragment texture, the method further comprises: The following process is performed for each fragment in the fragment texture: Determine an area in the fragmented image for rendering in the graphical interface, and divide the area into a plurality of sub-areas having specific shapes, wherein the specific shape is a triangle or a rectangle; Determining vertex information for rendering each of the sub-regions; The vertex information corresponding to the plurality of sub-regions is combined to obtain vertex information for rendering the fragmented image.
9. The method according to claim 1, characterized in that: After rendering the plurality of images in the graphical interface data into the fragment texture, the method further comprises: Selecting a plurality of fragmented images from the fragmented image texture for splicing to obtain a spliced group image; Determine the center position of the spliced group of images, and determine the area of the spliced group of images for rendering in the graphical interface; Drawing a fan-shaped area with the center position as a vertex, wherein the fan-shaped area includes an area in the spliced group image used for rendering in the graphical interface; For each of the fragments in the spliced group image, The following processing is performed: determining the intersection between the radius of the fan-shaped area and the fragment image, and using the vertex information of the intersection as the vertex information for rendering the fragment image.
10. The method according to claim 1, characterized in that Before rendering the plurality of images in the graphical interface data into the fragment texture, the method further comprises: Determine the area of each picture in the graphical interface data, and render the pictures whose areas are greater than an area threshold into a background texture; Before fusing the color value of the broken image texture and the color value of the character texture corresponding to each pixel point according to the vertex information of the broken image texture and the character texture to obtain the fused color value of each pixel point, the method further includes: Sampling the background texture to obtain a background texture color value corresponding to each pixel in the graphic interface; According to the vertex information of the broken image texture and the character texture, the broken image texture color value and the character texture color value corresponding to each pixel are fused to obtain the fused color value of each pixel, including: According to the vertex information of the fragment texture, the character texture and the background texture, the fragment texture color value, the character texture color value and the background texture color value corresponding to each pixel are fused to obtain the fused color value of each pixel.
11. A graphical interface rendering device, characterized in that: The device comprises: A texture rendering module, used to render multiple images in the graphical interface data into a fragmented image texture, and render multiple characters in the graphical interface data into a character texture; A sampling module, used for sampling the fragmented image texture and the character texture respectively, and obtaining the fragmented image texture color value and the character texture color value corresponding to each pixel point in the graphical interface; A fusion module is used to determine, for each pixel point, a first weight and a second weight of the pixel point according to vertex information of the fragmented image texture and the character texture, respectively, wherein the first weight is a target component of texture coordinates in vertex information of a target fragmented image, the target fragmented image corresponds to the pixel point in the fragmented image texture, and the second weight is a target component of texture coordinates in vertex information of a target character, the target character corresponds to the pixel point in the character texture; and according to the first weight and the second weight, weighted summing processing is performed on a color value of the fragmented image texture corresponding to the pixel point and a color value of the character texture corresponding to the pixel point to obtain a fused color value of the pixel point; The interface rendering module is used to render and form the graphic interface according to the fused color value of each pixel.
12. An electronic device, characterized in that: include: A memory for storing computer executable instructions; A processor, configured to implement the method for rendering a graphical interface as described in any one of claims 1 to 10 when executing computer executable instructions stored in the memory.
13. A computer-readable storage medium, characterized in that: Computer executable instructions are stored, and when the computer executable instructions are executed, they are used to implement the rendering method of the graphical interface according to any one of claims 1 to 10.
14. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the method for rendering a graphical interface according to any one of claims 1 to 10 is implemented.
