Texture rendering method and device, equipment and program product
By acquiring the vertex data of small texture images and rendering with index information, the efficiency problem of texture rendering on devices with low computing performance in the prior art is solved, and efficient texture rendering on devices with low performance is achieved.
Patent Information
- Application Number
- CN202510017573.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-06
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2045-01-06
AI Technical Summary
Existing texture rendering technology is difficult to efficiently render large amounts of textures on devices with low computing performance, especially multi-target rendering, which requires high equipment performance and cannot be applied on equipment such as on-board instruments.
By obtaining the vertex data of the small texture image, inputting it into the shader using the index information, calling the shader to render each small texture image based on the index information, realizing the simultaneous rendering of multiple small texture images, reducing the requirements for device computing performance.
It improves the efficiency of texture rendering, can efficiently render large amounts of textures on devices with low computing performance, reduces the requirements for device performance, and improves rendering efficiency.
Smart Images

Figure CN119919556A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of rendering technology, and in particular to a texture rendering method, device, equipment and program product. Background Art
[0002] With the development of technology, texture rendering technology is increasingly used in people's lives. For example, texture rendering technology is implemented on devices such as vehicle-mounted instruments, car computers, and smart home devices to provide users with richer and more refined images. However, there are currently two main rendering methods for texture rendering, including immediate rendering and multi-target rendering. Immediate rendering refers to rendering each texture one by one. This rendering method is efficient when the number of textures is small, but when rendering a large number of textures, frequent calls to the rendering function will reduce the rendering efficiency. Multi-target rendering can generate rendering results for multiple textures through a single call to the rendering function. However, multi-target rendering has high performance requirements for the device and cannot be applied to devices with low computing performance, such as vehicle-mounted instruments. Summary of the invention
[0003] Based on the above-mentioned defects and shortcomings of the prior art, the present application proposes a texture rendering method, device, equipment and program product, which can improve the rendering efficiency of texture rendering on devices with low computing performance.
[0004] According to the first aspect of the present application, a texture rendering method is provided, comprising: obtaining vertex data of N small texture images, wherein N is a positive integer, and the vertex data includes index information corresponding to each of the small texture images; inputting the vertex data of the N small texture images into a shader; calling the shader to render each of the small texture images based on the index information.
[0005] According to the texture rendering method provided in the first aspect of the present application, the obtaining of vertex data of N small texture images includes: creating a data list based on the number M of texture units in a rendering device, wherein M is a positive integer greater than or equal to N, and the data list is used to store vertex data of at most M small texture images; storing the vertex data of the N small texture images in the data list; and inputting the vertex data of the N small texture images into a shader includes: inputting the data list into the shader.
[0006] According to the texture rendering method provided in the first aspect of the present application, the shader includes a vertex shader and a fragment shader; calling the shader to render each of the small texture images based on the index information includes: calling the vertex shader, receiving the vertex data, and transferring the vertex data to the fragment shader; calling the fragment shader to render each of the small texture images based on the index information.
[0007] According to the texture rendering method provided in the first aspect of the present application, the index information received by the vertex shader includes index data of floating-point type; before calling the shader to render each of the small texture images based on the index information, it also includes: converting the index information from the floating-point type to an integer type through the fragment shader.
[0008] According to the texture rendering method provided in the first aspect of the present application, the acquisition of vertex data of N small texture images includes: based on the first texture identifier of the large texture image, loading the large texture image into the graphics memory, wherein the large texture image includes P small texture images, the second texture identifier of each of the small texture images in the large texture image is the same as the first texture identifier, and P is an integer greater than or equal to N; traversing the small texture images in the large texture image, determining N small texture images, and obtaining the vertex data of the N small texture images.
[0009] According to the texture rendering method provided in the first aspect of the present application, after calling the shader and rendering each of the small texture images respectively based on the index information, it also includes: determining whether the small texture images in the large texture image are completely traversed, and if not, re-determining N unrendered small texture images in the large texture image, and obtaining the vertex data of the re-determined N small texture images until the small texture images in the large texture image are completely traversed.
[0010] According to the texture rendering method provided in the first aspect of the present application, the vertex data includes custom texture coordinates; the custom texture coordinates include the index information.
[0011] According to the second aspect of the present application, a texture rendering device is provided, comprising: an acquisition module for acquiring vertex data of N small texture images, wherein N is a positive integer, and the vertex data includes index information corresponding to each of the small texture images; an input module for inputting the vertex data of the N small texture images into a shader; and a rendering module for calling the shader to render each of the small texture images based on the index information.
[0012] According to a third aspect of the present application, an electronic device is provided, comprising: a memory and a processor; the memory is connected to the processor and is used to store programs; the processor is used to implement the texture rendering method as described in the first aspect by running the program in the memory.
[0013] According to a fourth aspect of the present application, a computer program product is provided, comprising computer program instructions; when the computer program instructions are executed by a processor, the processor is enabled to execute the texture rendering method as described in the first aspect.
[0014] In the present application, vertex data of N small texture images are obtained, where N is a positive integer, and the vertex data includes index information corresponding to each small texture image; the vertex data of the N small texture images are input into the shader; the shader is called to render each small texture image based on the index information. In view of the excessive pressure on computing performance caused by repeatedly switching texture identifiers in ordinary multi-target rendering, the above process realizes simultaneous rendering of multiple small texture images through index information, reducing the requirements for computing performance of the device; and through the index information in the vertex data, N small texture images can be rendered simultaneously by calling the shader once, thereby improving rendering efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0016] Figure 1 A flowchart of a texture rendering method provided in an embodiment of the present application;
[0017] Figure 2 A schematic diagram of a flow chart of a rendering cycle based on a large texture image provided in an embodiment of the present application;
[0018] Figure 3 A block diagram of a texture rendering device provided in an embodiment of the present application;
[0019] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0021] Exemplary Methods
[0022] In view of the problems existing in the prior art, the present application provides a texture rendering method, which is implemented by software, and the software implementing the method runs on a device with data processing functions, such as an on-board processor, a remote server, a smart mobile device, etc. Optionally, the software corresponding to the method runs on a graphics processing unit (GPU) in an embedded device.
[0023] In one embodiment, if Figure 1 As shown, the process steps of the texture rendering method include:
[0024] Step 101 : obtaining vertex data of N small texture images, wherein N is a positive integer, and the vertex data includes index information corresponding to each small texture image.
[0025] In this embodiment, texture rendering refers to the process of mapping a two-dimensional image to the surface of a three-dimensional model in computer graphics. The texture rendering process includes steps such as vertex data preparation, vertex shader processing, rasterization, fragment shader processing, and frame buffer writing. Small texture images refer to image data that are processed as basic units in the texture rendering process. In a texture rendering process, it is usually necessary to render multiple small texture images separately to obtain the final rendering result.
[0026] In this embodiment, N small texture images are rendered at the same time. In order to ensure that the rendering logic of each small texture image is correct, corresponding index information is configured for each small texture image, so that when the N small texture images are rendered, the texture data corresponding to each small texture image can be correctly obtained. Index information refers to a data structure used to quickly find and access data, which can significantly improve the speed and efficiency of data retrieval. Vertex data is a very important component in computer graphics and three-dimensional modeling. It describes the geometric structure of the three-dimensional model, such as the position, normal, color, etc. of the vertex. The vertex data includes the screen coordinates (also known as xy coordinates) of the vertices contained in each small texture image in the screen, and the texture coordinates (also known as UV coordinates) of the vertices contained in each small texture image in the large texture image, wherein the large texture image includes multiple small texture images, and the index information is customized to be added to the vertex data of each small texture image. Optionally, the index information is information based on a numerical format.
[0027] In one embodiment, the vertex data includes custom texture coordinates; the custom texture coordinates include index information.
[0028] In this embodiment, the texture rendering process is completed by the GPU, and the vertex shader configured in the GPU is responsible for receiving vertex data and passing the vertex data to the fragment shader. In the vertex data passed from the vertex shader to the fragment shader, the texture coordinates of the small texture image based on the large texture image are the same before and after the transfer, and in order to ensure the consistency of the index information before and after the transfer, the original texture coordinates are transformed, and the index information is customized to the texture coordinates to generate customized texture coordinates. The customized texture coordinates include the original texture coordinates and the index information.
[0029] Step 102: input vertex data of N small texture images into a shader.
[0030] In this embodiment, vertex data carrying index information is input into a shader required for texture rendering, thereby ensuring that the index information plays a role in the texture rendering process and that the rendering logic of N small texture images is correct.
[0031] Step 103, calling the shader to render each small texture image based on the index information.
[0032] In this embodiment, when rendering N small texture images, it is necessary to call the shader configured in the GPU. When calling the shader, in addition to processing data such as texture identifier (ID), screen coordinates, and texture coordinates, it is also necessary to process index information to ensure that when rendering each small texture image, the corresponding texture data is correctly called to avoid data mixing between different small texture images; and when N small texture images are rendered at the same time, the shader is called, the rendering function is called once, and each small texture image is rendered at the same time based on the index information. The rendering process of N small texture images only needs to call the rendering function once, avoiding the calculation pressure caused by repeatedly calling the rendering function, thereby improving the rendering efficiency of N small texture images, while reducing the performance requirements of the device running this method.
[0033] In one embodiment, obtaining vertex data of N small texture images includes: creating a data list based on the number M of texture units in a rendering device, wherein M is a positive integer greater than or equal to N, and the data list is used to store vertex data of at most M small texture images; storing the vertex data of the N small texture images in the data list. Inputting the vertex data of the N small texture images into a shader includes: inputting the data list into the shader.
[0034] In this embodiment, the device on which the method is run includes multiple texture units, which are logical resource managers for binding and processing texture data. Each texture unit can bind a small texture image during texture rendering to manage and apply the texture data of the bound small texture image. Texture data (TextureData) is image data that describes the surface details of an object and may include information such as color, brightness, transparency, and normal.
[0035] In this embodiment, for the device on which the method is run, especially when the device is an embedded device, the number of texture units is limited, and therefore, the number of small texture images that can be managed simultaneously is also limited. Therefore, the number of small texture images that can be processed at one time can be managed by creating a data list. The data list can store the vertex data of up to M small texture images, so the vertex data corresponding to the N small texture images can be stored in the data list at one time, and then the vertex data of the N small texture images can be input into the shader through the data list, and the rendering process of the N small texture images can be completed by calling the rendering function once. Optionally, index information is pre-set, and the index information corresponds to the texture unit one by one. The index information corresponding to the M texture units can be assigned to the N small texture images, and the index information assigned to any two small texture images is different. When a batch of N small texture images is rendered, the index information corresponding to the M texture units can be reallocated to the next batch of N small texture images waiting to be rendered.
[0036] In this embodiment, the number of texture units configured by the device can be obtained by calling the function glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxNums) to obtain the maximum number of texture units supported by the device, that is, the number M is determined.
[0037] In one embodiment, the shader includes a vertex shader and a fragment shader. Calling the shader to render each small texture image based on the index information includes: calling the vertex shader to receive vertex data and transmitting the vertex data to the fragment shader; calling the fragment shader to render each small texture image based on the index information.
[0038] In this embodiment, the shaders used in the texture rendering process include vertex shaders and fragment shaders. The vertex shader is used to process vertex data, including position transformation, lighting calculation, etc., and transmit vertex data to the fragment shader, especially the texture coordinates of each vertex to the fragment shader. The fragment shader samples the corresponding pixel value from the texture data according to the texture coordinates transmitted by the vertex, and calculates the final color output based on factors such as lighting and material properties.
[0039] In this embodiment, the index information is added to the vertex data to ensure that the index information can be passed from the vertex shader to the fragment shader. Optionally, the texture coordinates passed from the vertex shader to the fragment shader are the same, so the index information is added to the original texture coordinates to form custom texture coordinates. In order to ensure that the vertex shader can receive vertex data containing index information, the vertex shader is customized in advance. Exemplarily, the program corresponding to the customized vertex shader is as follows:
[0040] Attribute vec2 vertexPosition;
[0041] attribute vec3 vertexUV;
[0042] varying vec3 UV;
[0043] void main()
[0044] {
[0045] gl_Position=vec4(vertexPosition.xy,0.0,1.0);
[0046] UV = vertexUV;
[0047] }
[0048] Among them, in the vertex shader, the received two-dimensional data vertexPosition is defined, which represents the screen coordinates based on the screen when the small texture image is rendered; the received three-dimensional data vertexUV is defined, and the first two digits of the three-dimensional data vertexUV represent the texture coordinates of the small texture image based on the large texture image, and the third digit represents the index information v; the three-dimensional data UV is consistent with the received vertexUV and is used to pass it to the fragment shader; in the main function main, gl_Position is the four-dimensional built-in variable of the vertex shader, the first three digits represent the xyz coordinates in the spatial coordinate system, the xy coordinates are the received screen coordinates vertexPosition, the z coordinate is defined as 0.0, and the fourth digit represents the homogeneous coordinate w, which is generally 1.0.
[0049] By customizing the vertex shader, it is possible to ensure that the vertex shader accurately receives index information and passes the index information to the fragment shader.
[0050] In one embodiment, the index information received by the vertex shader includes floating point index data. Before calling the shader to render each small texture image based on the index information, the method further includes: converting the index information from floating point type to integer type through a fragment shader.
[0051] In this embodiment, based on the actual operation situation, the data input to the vertex shader is usually of floating point type. When the fragment shader calls the index information to query the texture data of the corresponding small texture image, it is more convenient to process the data based on the integer type. Therefore, the index information can be converted from floating point type to integer type through the fragment shader.
[0052] In this embodiment, in order to ensure that the fragment shader accurately receives the index information and performs data type conversion on the index information, the fragment shader is customized in advance. Exemplarily, the program corresponding to the customized fragment shader is as follows:
[0053] The fragment shader program is as follows:
[0054] varying vec3 UV;
[0055] uniform sampler2D renderTexture[M];
[0056] void main()
[0057] {
[0058] int idx = int(UV.v–0.5);
[0059] gl_FragColor=texture2D(renderTexture[idx],UV.uv);
[0060] }
[0061] Among them, the fragment shader receives the three-dimensional data UV (that is, the custom texture coordinates) passed in from the vertex shader, as well as the second texture identifier of the small texture image of n sampler2D variables. Sampler2D is a special data type specifically used to represent two-dimensional textures. M is determined by the maximum number of texture units supported by the device. In the main function main, first obtain the index information idx after type conversion based on the passed in vertex data. Since the vertex data input to the vertex shader is of float type, and the data type of the index information required by the fragment shader is of int type, type conversion is required. The conversion formula is:
[0062] idx = int(UV.v–0.5)
[0063] Wherein, UV.v represents the index information of float type, int represents the rounding process, and idx represents the index information of int type. Based on the above formula, for example, when v is equal to (float)3.0, the corresponding idx is (int)2.
[0064] gl_FragColor is a built-in variable of the fragment shader, which is used to store the final color of the fragment (or pixel). The final color of the fragment is the result of the built-in function texture2D, which reads the color value of the corresponding position from the texture data pointed to by renderTexture[idx] according to the texture coordinate UV.uv.
[0065] By customizing the vertex shader, it is possible to ensure that the fragment shader accurately receives the index information and uses the index information correctly.
[0066] In one embodiment, vertex data of N small texture images are obtained, including: based on the first texture identifier of the large texture image, loading the large texture image into the graphics memory, wherein the large texture image includes P small texture images, the second texture identifier of each small texture image in the large texture image is the same as the first texture identifier, and P is an integer greater than or equal to N; traversing the small texture images in the large texture image, determining N small texture images, and obtaining vertex data of the N small texture images.
[0067] In this embodiment, in the actual operation process, when rendering multiple small texture images, if a large number of small texture images are loaded into the graphics memory during initialization, frequent reading and releasing of texture images will cause the loading process to take a long time, and frequent switching of texture identifiers during rendering will also reduce rendering efficiency. Therefore, multiple small texture images can be preprocessed, P small texture images can be synthesized into a large texture image, and the second texture identifier of each small texture image in the large texture image can be updated to the first texture identifier of the large texture image, that is, the second texture identifier of each small texture image in the large texture image is the same.
[0068] In this embodiment, after synthesizing the large texture image, based on the limitation of the texture unit, N small texture images are determined from the large texture image, and the processing is performed based on the vertex data of the N small texture images and the index information in the vertex data. During initialization, the large texture image is loaded into the graphics memory, and the pre-processing loading of the P small texture images is completed, and there is no need to frequently switch the texture identifier, which improves the initialization loading efficiency. In addition, the second texture identifiers of the N small texture images processed at the same time are the same. Therefore, when rendering the N small texture images based on the index information at the same time, there is no need to frequently switch the texture identifier, which improves the rendering efficiency of the texture rendering.
[0069] In this embodiment, if in a rendering project, two different first large texture images and second large texture images are generated according to actual needs, the first texture identifiers of the first large texture image and the second large texture image are different, the second texture identifier of the first small texture image in the first large texture image is the same as the first texture identifier of the first large texture image, and the second texture identifier of the second small texture image in the second large texture image is the same as the first texture identifier of the second large texture image.
[0070] In one embodiment, after calling the shader and rendering each small texture image based on the index information, it also includes: determining whether the small texture images in the large texture image are completely traversed, and if not, re-determining N unrendered small texture images in the large texture image, and obtaining vertex data of the re-determined N small texture images until the small texture images in the large texture image are completely traversed.
[0071] In this embodiment, the number of small texture images contained in the large texture image is determined according to the project situation. Therefore, the number of small texture images contained in the large texture image may be much larger than the number of texture units configured in the device. Based on the above, the small texture images in the large texture image can be traversed to achieve automatic loop rendering of the small texture images in the large texture image, thereby completing the rendering of the large texture image.
[0072] In a specific embodiment, Figure 2As shown, the process of rendering a small texture image in a large texture image includes:
[0073] Step 201, create a data list capable of storing M groups of vertex data, and a counting variable count, where count is assigned an initial value of 1;
[0074] Step 202, traverse the small texture objects in the large texture image, store the vertex data of the next small texture object into the data list, and pass the index information v in the custom texture coordinates into the renderTexture array of the fragment shader;
[0075] Based on the above embodiment, the fragment shader performs data type conversion on the index information v to obtain the index information idx. The conversion relationship is as follows:
[0076] int idx = int((UV.v–0.5);
[0077] Step 203, determine whether the current count count is equal to M, if not, execute step 204, if yes, execute step 205;
[0078] Step 204, count+1, execute step 202;
[0079] Step 205, passing the data list into the shader, clearing the data list, calling a rendering function once, rendering each small texture image stored in the data list, and resetting count=0;
[0080] Step 206, determining whether the traversal of the small texture images in the large texture image is complete, if not, executing step 202, if yes, executing step 207;
[0081] Step 207: If the data list is not empty, call the rendering function once to render each small texture image stored in the data list, and end the rendering loop for the large texture image.
[0082] In a specific embodiment, multiple small texture images are merged and preprocessed. Specifically, 144 small texture images are pre-made, and the small texture images are PNG image textures with a resolution of 160*90. The 144 small texture images are synthesized into a large image texture through the open source software Freetexture packer, and a json file is generated at the same time, which records the texture coordinates of each small image texture in the large image texture. Optionally, the large image texture packing method selects OptimalPacker and the inner margin selects 1, so that the small textures in the large texture image are arranged more closely and the resolution of the large image texture is minimized. Optionally, the resolution of the large image texture is 894*868.
[0083] In this embodiment, the maximum number of texture units supported by the device is obtained, and the shader code and rendering loop logic are modified accordingly. Specifically, by calling the function glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&maxNums), the maximum number of texture units supported by the current device, that is, the value of maxNums, is obtained. The device in this embodiment is an embedded device, and the value of maxNums of the embedded device is 16. Then the data list stores texture data of up to 16 small texture units. The array size of the sampler2D variable is defined as 16 in the fragment shader, so that there are 16 texture units to choose from when calling the rendering function once. Optionally, the rendering function is glDraw*, which is a general term for a series of functions used to draw geometric primitives.
[0084] In this embodiment, the rendering loop logic adopts a loop for large texture images. Figure 2 In the rendering loop shown, 144 small texture images can be divided into 9 batches. Each batch loads the vertex arrays and texture data of 16 small texture images into the shader. The 16 small texture images call the rendering function once to complete the rendering. The above operation is repeated until the rendering of 144 small texture images is completed, which is equivalent to reducing the number of calls to the rendering function from 144 times to 9 times.
[0085] In this embodiment, the large image texture is initialized and loaded. Specifically, in the initialization stage of the program, the large image texture will be read into the graphics memory, and the corresponding first texture identifier will be generated. Then, the custom texture coordinates of each small image texture in the large image texture will be obtained from the json file generated above, and the corresponding vertex data will be calculated based on the custom texture coordinates. In addition to the screen coordinates of the small texture based on the screen, and the texture coordinates of the small texture image in the large texture image, the vertex data also needs to include index information of 1-16, so that the vertex data of the small texture image in the fragment shader can correspond to the small texture image one by one during rendering. The second texture identifier of the small texture image is the same as the first texture identifier of the large texture image. In this embodiment, only one large texture image is generated, so the second texture identifiers of all small texture images are the same as the first texture identifier of the large texture image. Finally, 144 small texture images with vertex data and second texture identifiers are obtained.
[0086] In this embodiment, a rendering loop is started to implement multi-texture rendering. Specifically, the 144 small texture images generated above are traversed and loop rendering is adopted. Since the second texture identifiers of all small texture images use the first texture identifier of the large texture image, when a single frame of the large texture image is rendered, only 9 rendering functions are called.
[0087] In one embodiment, different rendering methods are used to perform rendering experiments on 144 small texture images.
[0088] Experimental Group 1
[0089] No merging operation of small texture images is performed, and 144 small texture images are loaded separately during initialization; and no index information is added, and the rendering function is called 144 times to complete the rendering of the 144 small texture images.
[0090] Experimental Group 2
[0091] The 144 small texture images are merged into a large texture image, and the large texture image is loaded during initialization; however, no index information is added to the small texture images, and the rendering function is called 144 times to complete the rendering of the 144 small texture images.
[0092] Experimental Group 3
[0093] The 144 small texture images are merged into a large texture image, and the large texture images are loaded separately during initialization; and index information is added to the small texture images, and the rendering function is called 9 times to complete the rendering of the 144 small texture images.
[0094] The solutions provided by the above three experimental groups were tested for rendering on the same embedded hardware, and the embedded device includes 16 texture units. Experimental group one, experimental group two and experimental group three were used for initialization, and the time consumption was 62ms, 25ms and 25ms respectively; experimental group one, experimental group two and experimental group three were used to complete the rendering of 144 small texture images, and the corresponding average frame rates were 3081fps, 3207fps and 3675fps respectively. This shows that the texture rendering method provided by the present application can reduce the initialization time by about 60% and increase the frame rate by about 20%.
[0095] In the present application, vertex data of N small texture images are obtained, where N is a positive integer, and the vertex data includes index information corresponding to each small texture image; the vertex data of the N small texture images are input into the shader; the shader is called to render each small texture image based on the index information. In view of the excessive pressure on computing performance caused by repeatedly switching texture identifiers in ordinary multi-target rendering, the above process realizes simultaneous rendering of multiple small texture images through index information, reducing the requirements for computing performance of the device; and through the index information in the vertex data, N small texture images can be rendered simultaneously by calling the shader once, thereby improving rendering efficiency.
[0096] Furthermore, the small texture images to be rendered are first synthesized into a large texture image, which can improve the rendering efficiency to a certain extent. And according to the maximum number of texture units supported by the device, the maximum number of sampler2D variables is defined in the fragment shader, and the index information of each small texture image configuration is received in the vertex shader; in the loop rendering, the index information is added to the vertex data, so that the vertex data corresponds to the small texture image one by one during drawing. In a rendering cycle, when the number of small texture images bound to each texture unit reaches the maximum number defined in the fragment shader, the rendering function is called once, which can reduce the calls of the rendering function exponentially and improve the rendering efficiency. Since the number of calls to the rendering function is reduced, the pressure on the computing performance of the device can be reduced, so that when the solution provided by the application is applied to devices with poor computing performance such as embedded devices, it can still maintain a high rendering efficiency.
[0097] Exemplary Devices
[0098] Accordingly, the present application also provides a texture rendering device, such as Figure 3 As shown, the device may include:
[0099] An acquisition module 301 is used to acquire vertex data of N small texture images, where N is a positive integer, and the vertex data includes index information corresponding to each small texture image;
[0100] An input module 302, used for inputting vertex data of N small texture images into a shader;
[0101] The rendering module 303 is used to call the shader to render each small texture image based on the index information.
[0102] In one embodiment, the acquisition module 301 is used to create a data list based on the number M of texture units in the rendering device, where M is a positive integer greater than or equal to N, and the data list is used to store vertex data of up to M small texture images; store the vertex data of the N small texture images in the data list; input the vertex data of the N small texture images into the shader, including: inputting the data list into the shader.
[0103] In one embodiment, the shader includes a vertex shader and a fragment shader;
[0104] The rendering module 303 is used to call the vertex shader, receive vertex data, and transmit the vertex data to the fragment shader; call the fragment shader to render each small texture image based on the index information.
[0105] In one embodiment, the index information received by the vertex shader includes index data of floating point type;
[0106] The rendering module 303 is further used to call the shader, and before rendering each small texture image based on the index information, convert the index information from a floating point type to an integer type through the fragment shader.
[0107] In one embodiment, the acquisition module 301 is used to load a large texture image into a graphics memory based on the first texture identifier of the large texture image, wherein the large texture image includes P small texture images, the second texture identifier of each small texture image in the large texture image is the same as the first texture identifier, and P is an integer greater than or equal to N; traverse the small texture images in the large texture image, determine N small texture images, and obtain vertex data of the N small texture images.
[0108] In one embodiment, the rendering module 303 is also used to call the shader, and after rendering each small texture image based on the index information, determine whether the small texture images in the large texture image are completely traversed. If not, re-determine N unrendered small texture images in the large texture image, and obtain vertex data of the re-determined N small texture images until the small texture images in the large texture image are completely traversed.
[0109] In one embodiment, the vertex data includes custom texture coordinates; the custom texture coordinates include index information.
[0110] The texture rendering device provided in this embodiment belongs to the same application concept as the texture rendering method provided in the above embodiments of this application, and can execute the texture rendering method provided in any of the above embodiments of this application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not fully described in this embodiment, please refer to the specific processing content of the texture rendering method provided in the above embodiments of this application, and will not be repeated here.
[0111] Exemplary Electronic Devices
[0112] The present application also provides an electronic device, such as Figure 4 As shown, the electronic device includes: a memory 400 and a processor 401 .
[0113] The memory 400 is connected to the processor 401 and is used to store programs.
[0114] The processor 401 is used to implement the texture rendering method in the above embodiment by running the program stored in the memory 400 .
[0115] Specifically, the electronic device may further include: a communication interface 402 , an input device 403 , an output device 404 and a bus 405 .
[0116] The processor 401, the memory 400, the communication interface 402, the input device 403 and the output device 404 are connected to each other via a bus.
[0117] Bus 405 may include a pathway for transferring information between various components of the computer system.
[0118] Processor 401 may be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the scheme of the present invention. It may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0119] The processor 401 may include a main processor, and may also include a baseband chip, a modem, etc.
[0120] The memory 400 stores a program for executing the technical solution of the present invention, and may also store an operating system and other key services. Specifically, the program may include a program code, and the program code includes a computer operation instruction. More specifically, the memory 400 may include a read-only memory (ROM), other types of static storage devices that can store static information and instructions, a random access memory (RAM), other types of dynamic storage devices that can store information and instructions, a disk storage, a flash, and the like.
[0121] The input device 403 may include a device for receiving data and information input by a user, such as a keyboard, a mouse, a camera, a scanner, a light pen, a voice input device, a touch screen, a pedometer, or a gravity sensor.
[0122] Output device 404 may include a device that allows information to be output to a user, such as a display screen, a printer, a speaker, etc.
[0123] The communication interface 402 may include any transceiver or the like to communicate with other devices or communication networks, such as Ethernet, a radio access network (RAN), a wireless local area network (WLAN), etc.
[0124] The processor 401 executes the program stored in the memory 400 and calls other devices, which can be used to implement each step of the texture rendering method provided in the above embodiment of the present application.
[0125] Exemplary computer program products and storage media
[0126] In addition to the above-mentioned method and device, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps in the texture rendering method described in the embodiment of the present application.
[0127] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0128] In addition, the embodiment of the present application may also be a storage medium on which a computer program is stored, and the computer program is executed by a processor to execute the steps of the texture rendering method described in the embodiment of the present application.
[0129] For the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0130] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0131] The steps in the methods of each embodiment of the present application can be adjusted in order, combined and deleted according to actual needs, and the technical features recorded in each embodiment can be replaced or combined.
[0132] The modules and sub-modules in the devices and terminals provided in the embodiments of the present application can be merged, divided and deleted according to actual needs.
[0133] In the several embodiments provided in the present application, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or submodules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple submodules or modules can be combined or integrated into another module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0134] The modules or submodules described as separate components may or may not be physically separated, and the components of the modules or submodules may or may not be physical modules or submodules, that is, they may be located in one place, or they may be distributed on multiple network modules or submodules. Some or all of the modules or submodules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0135] In addition, each functional module or submodule in each embodiment of the present application may be integrated into one processing module, or each module or submodule may exist physically separately, or two or more modules or submodules may be integrated into one module. The above-mentioned integrated modules or submodules may be implemented in the form of hardware or in the form of software functional modules or submodules.
[0136] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0137] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly by hardware, software units executed by a processor, or a combination of the two. The software units may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0138] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0139] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A texture rendering method, characterized in that: include: Obtain vertex data of N small texture images, where N is a positive integer, and the vertex data includes index information corresponding to each of the small texture images; Inputting vertex data of the N small texture images into a shader; The shader is called to render each of the small texture images based on the index information.
2. The texture rendering method according to claim 1, characterized in that: The step of obtaining vertex data of N small texture images includes: Based on the number M of texture units in the rendering device, create a data list, where M is a positive integer greater than or equal to N, and the data list is used to store vertex data of at most M small texture images; Storing the vertex data of the N small texture images into the data list; The step of inputting the vertex data of the N small texture images into a shader comprises: The data list is input into the shader.
3. The texture rendering method according to claim 1, characterized in that: The shader includes a vertex shader and a fragment shader; The calling of the shader to render each of the small texture images based on the index information includes: Calling the vertex shader, receiving the vertex data, and transmitting the vertex data to the fragment shader; The fragment shader is called to render each of the small texture images based on the index information.
4. The texture rendering method according to claim 3, characterized in that: The index information received by the vertex shader includes index data of floating point type; Before calling the shader to render each of the small texture images based on the index information, the method further includes: The index information is converted from the floating point type to an integer type by the fragment shader.
5. The texture rendering method according to claim 1, characterized in that: The step of obtaining vertex data of N small texture images includes: Based on the first texture identifier of the large texture image, the large texture image is loaded into the graphics memory, wherein the large texture image includes P small texture images, the second texture identifier of each small texture image in the large texture image is the same as the first texture identifier, and P is an integer greater than or equal to N; The small texture images in the large texture image are traversed to determine N small texture images, and the vertex data of the N small texture images are obtained.
6. The texture rendering method according to claim 5, characterized in that: After calling the shader and rendering each of the small texture images based on the index information, the method further includes: Determine whether the small texture images in the large texture image are completely traversed; if not, re-determine N unrendered small texture images in the large texture image, and obtain the vertex data of the re-determined N small texture images until the small texture images in the large texture image are completely traversed.
7. The texture rendering method according to any one of claims 1 to 6, characterized in that: The vertex data includes custom texture coordinates; The custom texture coordinates include the index information.
8. A texture rendering device, characterized in that: include: An acquisition module, used to acquire vertex data of N small texture images, wherein N is a positive integer, and the vertex data includes index information corresponding to each of the small texture images; An input module, used for inputting vertex data of the N small texture images into a shader; A rendering module is used to call the shader and render each of the small texture images based on the index information.
9. An electronic device, characterized in that: include: Memory and processor; The memory is connected to the processor and is used to store programs; The processor is used to implement the texture rendering method according to any one of claims 1 to 7 by running the program in the memory.
10. A computer program product, characterized in that includes computer program instructions; When the computer program instructions are executed by a processor, the processor is caused to perform the texture rendering method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image rendering method and device, and storage medium
CN108961382A
Image rendering method and device
CN110544291A
VR-based video rendering method and device, electronic equipment and storage medium
CN111754614A
Method for rendering visualization of virtual reality (VR) glasses and related equipment
CN114928767A
GPU-based inverse distance interpolation rendering method and device, medium and equipment
CN115937385A