Graphic primitive clipping method, device, equipment, storage medium and computer program product
By dynamically updating the cropping parameters, we decide whether to continue cropping based on the positional relationship between the element and the cropping surface, solving the problem of unnecessary cropping after the element shape changes, and improving the efficiency of element cropping.
Patent Information
- Application Number
- CN202411342370.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2044-09-24
AI Technical Summary
During the element cropping process, the change in the element shape makes the parts that no longer need to be cropped are still processed, resulting in waste of time and power consumption.
By obtaining the primitive and its corresponding cropping surface, dynamically update the cropping parameters based on the positional relationship between the cropping surface and the primitive, and end the cropping without continuing to crop.
It avoids invalid element cropping, reduces the time and power consumption required for cropping, and improves the efficiency of element cropping.
Smart Images

Figure CN119151953B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer image processing technology, and in particular, to a primitive clipping method, apparatus, device, storage medium, and computer program product. Background Art
[0002] In a Graphics Processing Unit (GPU), invisible or unnecessary parts during the image rendering process can be removed by means of primitive clipping, so as to improve the rendering efficiency and reduce unnecessary calculations. In related technologies, a specific clipping plane for clipping a primitive is determined according to the primitive clipping mask of the primitive, so as to clip the primitive according to the specific clipping plane. During the primitive clipping process, the shape of the primitive may change, so that the primitive no longer needs to be clipped for some specific clipping planes. If the initial clipping mask is still used to clip the primitive for each specific clipping plane, it may cause waste of time and power required for primitive clipping. Summary of the Invention
[0003] In view of this, embodiments of this application provide a primitive clipping method, apparatus, device, storage medium, and computer program product, which improve the efficiency of primitive clipping.
[0004] The technical solution of the embodiments of this application is implemented as follows:
[0005] In a first aspect, an embodiment of this application provides a primitive clipping method, including: obtaining a primitive and at least one clipping plane corresponding to the primitive; during the clipping process corresponding to each clipping plane executed in a preset order, determining a clipping parameter based on the positional relationship between the at least one clipping plane and the current primitive; the current primitive is the primitive or the result after the primitive has been clipped at least once; in the case where the clipping parameter indicates that there is no clipping plane that needs to clip the current primitive, determining the current primitive as the clipped primitive.
[0006] In a second aspect, an embodiment of this application further provides a primitive clipping apparatus, including: a data acquisition module, configured to obtain a primitive and at least one clipping plane corresponding to the primitive; a parameter determination module, configured to determine a clipping parameter based on the positional relationship between the at least one clipping plane and the current primitive during the clipping process corresponding to each clipping plane executed in a preset order; the current primitive is the primitive or the result after the primitive has been clipped at least once; a result determination module, configured to determine the current primitive as the clipped primitive in the case where the clipping parameter indicates that there is no clipping plane that needs to clip the current primitive.
[0007] In a third aspect, an embodiment of this application further provides a computer device, including a memory and a processor, where the memory stores a computer program, and the processor implements the primitive clipping method of any one of the above when executing the computer program.
[0008] Fourthly, an embodiment of the present application further provides a storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the graphic primitive clipping method of any one of the above is implemented.
[0009] Fifthly, an embodiment of the present application further provides a computer program product, including a computer program, and when the computer program is executed by a processor, the graphic primitive clipping cache allocation method of any one of the above is implemented.
[0010] In summary, in the graphic primitive clipping method provided by the embodiment of the present application, at least one clipping plane corresponding to the graphic primitive is obtained; during the clipping process corresponding to each clipping plane executed in a preset order, clipping parameters are determined based on the positional relationship between at least one clipping plane and the current graphic primitive; when the clipping parameters indicate that there is no clipping plane that needs to clip the current graphic primitive, the current graphic primitive is determined as the clipped graphic primitive. In the process of clipping the current graphic primitive in the embodiment of the present application, the clipping parameters are updated based on the current graphic primitive updated after clipping, and when the updated clipping parameters indicate that no further clipping is required, the clipping is ended, avoiding invalid graphic primitive clipping, reducing the time and power consumption required for graphic primitive clipping, and improving the efficiency of graphic primitive clipping. Description of the Drawings
[0011] The drawings here are incorporated into the specification and constitute a part of this specification. These drawings are for embodiments in line with the present application and are used together with the specification to illustrate the technical solutions of the present application.
[0012] Figure 1 Schematic diagram of the system architecture for the graphic primitive clipping method provided by the embodiment of the present application;
[0013] Figure 2 Schematic diagram of the implementation process of a graphic primitive clipping method provided by the embodiment of the present application Figure 1 ;
[0014] Figure 3 Schematic diagram of the scenario of a graphic primitive and a clipping plane provided by the embodiment of the present application;
[0015] Figure 4 Schematic diagram of the implementation process of a graphic primitive clipping method provided by the embodiment of the present application Figure 2 ;
[0016] Figure 5 Another schematic diagram of the scenario of a graphic primitive and a clipping plane provided by the embodiment of the present application;
[0017] Figure 6 Schematic diagram of the implementation process of a graphic primitive clipping method provided by the embodiment of the present application Figure 3 ;
[0018] Figure 7Schematic diagram of a vertex clipping mask for a vertex provided by an embodiment of the present application;
[0019] Figure 8 Schematic implementation process of a primitive clipping method provided by an embodiment of the present application Figure 4 ;
[0020] Figure 9 Schematic implementation process of a primitive clipping method provided by an embodiment of the present application Figure 5 ;
[0021] Figure 10 Schematic diagram of a count value of a clipping plane provided by an embodiment of the present application;
[0022] Figure 11 Schematic diagram of another count value of a clipping plane provided by an embodiment of the present application;
[0023] Figure 12 Schematic implementation process of a primitive clipping method provided by an embodiment of the present application Figure 6 ;
[0024] Figure 13 Schematic diagram of a primitive clipping device provided by an embodiment of the present application;
[0025] Figure 14 Schematic diagram of a hardware entity of a computer device provided by an embodiment of the present application. Detailed implementation manners
[0026] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application.
[0027] It should be understood that the "embodiments of the present application" or "the foregoing embodiments" mentioned throughout the specification mean that specific features, structures, or characteristics related to the embodiments are included in at least one embodiment of the present application. Therefore, the appearances of "in the embodiments of the present application" or "in the foregoing embodiments" throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In various embodiments of the present application, the sequence numbers of the above processes do not mean the order of execution is prior or subsequent, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application. The serial numbers of the embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.
[0028] In addition, the accompanying drawings are only schematic illustrations of the embodiments of the present application and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus repeated descriptions thereof will be omitted. Some of the block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices. The terms used in the present application are only for the purpose of describing specific embodiments and are not intended to limit the present disclosure. The singular forms "a", "the" and "said" used in the present application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0029] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "when" or "while" or "in response to determining".
[0030] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which this application belongs. The terms used herein are only for the purpose of describing this application and are not intended to limit this application.
[0031] In the related art, in a GPU, a specific clipping plane for clipping a primitive is determined according to the primitive clipping mask of the primitive, so as to clip the primitive according to the specific clipping plane. During the process of primitive clipping, due to the change of the primitive shape, the primitive may no longer need to be clipped for some specific clipping planes. If the initial clipping mask is still used to clip the primitive for each specific clipping plane, it may cause waste of time and power consumption required for primitive clipping.
[0032] Based on the above problems, an embodiment of the present application proposes a primitive clipping method. During the process of clipping the current primitive, the clipping parameters are updated based on the current primitive updated after clipping, and the clipping is ended when the updated clipping parameters indicate that no further clipping is required, avoiding invalid primitive clipping, reducing the time and power consumption required for primitive clipping, and improving the efficiency of primitive clipping.
[0033] Figure 1The system architecture diagram of the primitive clipping method provided by the embodiment of the present application. As Figure 1 shown, the system architecture 100 includes a primitive assembly module 101, a clipping module 102, and a vertex buffer 103. Among them, the primitive assembly module 101 is used to generate vertex coordinates, primitive information, and guard band parameters. Among them, the primitive information includes the vertex coordinates that make up the primitive. The primitive assembly module 101 is further used to eliminate the primitives that do not need to be clipped, that is, each vertex is outside each clipping plane of at least one clipping plane, and to eliminate the primitives whose vertices are all within the protection area determined by the guard band parameters and within each clipping plane of at least one clipping plane, and send the vertex coordinates of the primitives with some vertices within the protection area to the clipping module 102. The clipping module 102 is used to clip the primitive according to the received primitive information. The vertex buffer 103 is used to cache the clipping result obtained by clipping the primitive.
[0034] The clipping module 102 includes a clipping parameter generation unit 1021, a clipping decision unit 1022, and a clipping execution unit 1023. Among them, the clipping parameter generation unit 1021 is used to generate the clipping parameters required in the process of clipping the primitive according to the position relationship between the primitive and the clipping window, and update the clipping parameters according to the clipped primitive; the clipping decision unit 1022 is used to determine the current clipping plane for clipping the current primitive according to the current clipping parameters; the clipping execution unit 1023 can use the current clipping plane to clip the current primitive, and send the clipping result to the vertex buffer 103. The clipping execution unit 1023 can also send the clipping result to the clipping parameter generation unit 1021, so that the clipping parameter generation unit 1021 updates the clipping parameters according to the position relationship between the new vertex and the clipping window.
[0035] Figure 2 The implementation process schematic diagram of a primitive clipping method provided by the embodiment of the present application Figure 1 As Figure 2 shown, the primitive clipping method at least includes steps S201 to S203.
[0036] Step S201, obtain a primitive and at least one clipping plane corresponding to the primitive.
[0037] Here, a primitive is a basic element that constitutes a three-dimensional image, such as a point, a line, a triangle, etc. In some embodiments, primitive information can also be obtained. The primitive information may include the position and orientation of the primitive in space, such as the coordinates of the vertices of the primitive, the normal vector, etc.; the primitive information may also include the attribute information of the primitive, such as the color, transparency, texture coordinates, etc. of the primitive. The above attributes determine the appearance of the primitive during rendering. Here, at least one clipping plane corresponding to the primitive is a clipping plane used to clip the primitive. During the process of obtaining the clipping plane, relevant information of the clipping plane can be obtained. For example, it may include the plane equation of the clipping plane, which is a mathematical equation defining the position and orientation of the clipping plane. The clipping plane usually consists of four parameterized coordinate axes (u, v, w, t) and a distance value, which are used to determine the position and orientation of the clipping plane; it may also include the clipping boundary of the clipping plane, which is used to define the boundary range of the clipping plane to limit the rendering range. It can be understood that the clipping plane information corresponding to each primitive can be the same or different.
[0038] In some embodiments, the clipping plane provided by this application may include the clipping plane corresponding to the viewing frustum, or may also include a user-defined clipping plane. Generally speaking, the clipping plane corresponding to the viewing frustum may include 4 different clipping planes: top, bottom, left, and right.
[0039] In the above step S201, by obtaining the primitive and at least one clipping plane corresponding to the primitive, the clipping process for the primitive can be completed in subsequent steps to obtain the clipped primitive.
[0040] Step S202, during the process of performing the clipping process corresponding to each of the at least one clipping plane in a preset order, determine the clipping parameters based on the positional relationship between the at least one clipping plane and the current primitive; the current primitive is the primitive or the result after the primitive has been clipped at least once.
[0041] In some embodiments, it can be determined whether the clipping plane in at least one clipping plane needs to clip the primitive in a preset order.
[0042] Among them, the preset order is the arrangement order of the clipping planes in at least one clipping plane. Taking the at least one clipping plane including a top clipping plane, a bottom clipping plane, a left clipping plane, and a right clipping plane as an example, the preset order may be the arrangement order of the top clipping plane, the bottom clipping plane, the right clipping plane, and the left clipping plane, or may also be other arrangement orders determined according to experience. It can be understood that during the process of clipping a primitive by at least one clipping plane, the preset order remains unchanged.
[0043] In the above process of performing the clipping process corresponding to each of the said clip planes in the preset order, taking the clipping process of the current clip plane in the at least one clip plane as an example, the current clip plane is the clip plane used in the current round of the clipping process. Taking the preset order as the arrangement order of the upper clip plane, the lower clip plane, the right clip plane, and the left clip plane as an example, the current clip plane used in the first round of the clipping process is the upper clip plane, and the current clip plane used in the second round of the clipping process is the lower clip plane. It can be understood that in different rounds of the clipping process, the current clip plane should correspond to different clip planes in the at least one clip plane.
[0044] In the above step S202, the current clip plane is determined from at least one clip plane in the preset order, so as to perform clipping corresponding to only one current clip plane in one round of the clipping process in the subsequent steps, rather than directly traversing each clip plane in the at least one clip plane to clip the primitive through all clip planes in one round of the clipping process, which not only improves the accuracy of primitive clipping, but also reduces the situation of ineffective clipping.
[0045] In some embodiments, during the process of using the current clip plane to clip the current primitive, the vertices and shape of the current primitive may change due to the clipping, resulting in a change in the positional relationship between the current primitive and the at least one clip plane. Before using the current clip plane to clip the current primitive, new clipping parameters can be determined according to the positional relationship between the changed current primitive and the at least one clip plane, so as to determine whether the changed current primitive needs to be clipped according to the new clipping parameters.
[0046] Here, the current primitive is the primitive to be clipped in the current round of the clipping process, corresponding to the current clip plane. That is to say, the current primitive is the said primitive (unclipped primitive) or the result after the said primitive has been clipped at least once. It should be noted that the result after the said primitive has been clipped at least once refers to the primitive after at least one round of the clipping process, and the above unclipped primitive refers to the primitive that has not undergone any round of the clipping process, that is, the original primitive.
[0047] Exemplarily, in the first round of the clipping process, the current primitive can be an unclipped primitive, and the corresponding current clip plane can be the first clip plane, and the first clip plane will be used to clip the unclipped primitive; in the second round of the clipping process, the current primitive can be the primitive obtained after being clipped by the first clip plane, and the corresponding current clip plane can be the second clip plane, and the second clip plane will be used to clip the primitive obtained after being clipped by the first clip plane. It can be understood that in different rounds of the clipping process, the shape of the current primitive may be different.
[0048] Among them, the clipping parameter characterizes whether there is a clipping plane in at least one clipping plane that needs to clip the current primitive. In the related art, if there are N clipping planes, N rounds of clipping processes are required. In this application, the clipping parameter is updated according to the current primitive updated during the clipping process to determine whether there is a clipping plane that needs to clip the current primitive according to the updated clipping parameter. In the case of N clipping planes, if during the (N - 1)-th round of the clipping process, the clipping parameter indicates that there is no clipping plane that needs to clip the current primitive, then there is no need to continue clipping the current primitive, and only (N - 1) rounds of clipping processes are required.
[0049] In some embodiments, a counter can be set for each clipping plane according to the number of clipping planes in at least one clipping plane. The clipping parameter can be the count value in the counter corresponding to each clipping plane. Among them, the count value can be represented by a first value and a second value, or can be represented by a specific value.
[0050] Exemplarily, taking the count value represented by a first value and a second value as an example, it can be represented by the first value that there are no vertices outside the corresponding clipping plane. When the count value is the first value, the clipping plane corresponding to this count value does not need to clip the current primitive; it can be represented by the second value that there are vertices outside the corresponding clipping plane. When the count value is the second value, the clipping plane corresponding to this count value needs to clip the current primitive.
[0051] In some embodiments, the first value can be the binary digit 0, and the second value can be the binary digit 1. Taking the count value represented by the binary digits 0 and 1 as an example, it can be represented by the binary digit 0 that there are no vertices outside the corresponding clipping plane. When the count value is 0, the clipping plane corresponding to this count value does not need to clip the current primitive; it can be represented by the binary digit 1 that there are vertices outside the corresponding clipping plane. When the count value is 1, the clipping plane corresponding to this count value needs to clip the current primitive.
[0052] Exemplarily, taking the count value represented by a specific value as an example, when the count value is 0, the number of vertices outside the clipping plane corresponding to this count value is 0, and this clipping plane does not need to clip the current primitive; when the count value is not 0, for example, when the count value is 2, the number of vertices outside the clipping plane corresponding to this count value is 2, and this clipping plane needs to clip the current primitive.
[0053] In some embodiments, the clipping parameter may be a primitive clipping mask composed of a first parameter and a second parameter. A primitive clipping mask bit may be set for each clipping plane according to the number of clipping planes in at least one clipping plane. The primitive clipping mask is composed of the primitive clipping mask bits, and it can be determined whether the current primitive is outside each clipping plane according to the primitive clipping mask bits. The primitive clipping mask bit may be the first parameter or the second parameter. When the current primitive is within a clipping plane, the primitive clipping mask bit corresponding to this clipping plane is the first parameter, indicating that the clipping plane corresponding to this primitive clipping mask bit does not need to clip the current primitive; when the current primitive is outside a clipping plane, the primitive clipping mask bit corresponding to this clipping plane is the second parameter, indicating that the clipping plane corresponding to this primitive clipping mask bit needs to clip the current primitive.
[0054] In some embodiments, the vertex clipping masks corresponding to the vertices in the current primitive may be determined first, and then the bitwise OR operation is performed according to the vertex clipping masks corresponding to the vertices to determine the primitive clipping mask.
[0055] In some embodiments, when a vertex is within a clipping plane, the vertex clipping mask bit corresponding to this clipping plane is the first parameter; when a vertex is outside a clipping plane, the vertex clipping mask bit corresponding to this clipping plane is the second parameter.
[0056] In some embodiments, the first parameter may be the binary digit 0, and the second parameter may be the binary digit 1. When a vertex is within a clipping plane, the vertex clipping mask bit corresponding to this clipping plane is the binary digit 0; when a vertex is outside a clipping plane, the vertex clipping mask bit corresponding to this clipping plane is the binary digit 1.
[0057] Taking the number of clipping planes in at least one clipping plane being 4 as an example, the corresponding vertex clipping mask should be composed of 4 vertex clipping mask bits corresponding to 4 clipping planes. For example, the vertex clipping mask of vertex A in primitive ABC is 0b0000 (0b is the prefix for binary representation, indicating that the following is a binary digit), the vertex clipping mask of vertex B is 0b0101, and the vertex clipping mask of vertex C is 0b0010. The bitwise OR of the vertex clipping masks of vertex A, vertex B, and vertex C gives the primitive clipping mask of primitive ABC as 0b0111.
[0058] In the process of determining the clipping parameter, it is necessary to determine whether each vertex in the current primitive is within or outside each clipping plane in at least one clipping plane. For example, the distance between each vertex and each clipping plane can be determined by the coordinates of the vertices in the current primitive and the plane coefficients of each clipping plane in at least one clipping plane, and it can be determined whether each vertex is within or outside each clipping plane according to the distance between each vertex and each clipping plane.
[0059] As Figure 3 shown Figure 3 in, the triangle ABC in represents the primitive to be cropped, and 301, 302, 303, and 304 are the four cropping planes corresponding to the primitive to be cropped respectively. Here, taking 301 as the upper cropping plane, 302 as the lower cropping plane, 303 as the right cropping plane, and 304 as the left cropping plane as an example for illustration.
[0060] Taking the determination of the cropping parameters of the primitive ABC with respect to the lower cropping plane as an example, the coordinates of vertex A, the coordinates of vertex B, the coordinates of vertex C, and the plane coefficients of the lower cropping plane can be determined. The distances from vertex A, vertex B, and vertex C to the lower cropping plane are determined by taking the dot product of the coordinates of vertex A, vertex B, and vertex C respectively with the plane coefficients of the lower cropping plane, so as to determine whether vertex A, vertex B, and vertex C are inside or outside the lower cropping plane according to the distances from vertex A, vertex B, and vertex C to the lower cropping plane.
[0061] Taking the normal vector of the lower cropping plane as (a, b, c) and the coordinates of a certain point on the lower cropping plane as (x0, y0, z0) as an example, the plane coefficients of the lower cropping plane can be determined by formula (1) and formula (2):
[0062] a(x - x0) + b(y - y0) + c(z - z0) = 0 (1);
[0063] where, (x0, y0, z0) represents the coordinates of a certain point on the lower cropping plane, (a, b, c) represents the normal vector of the lower cropping plane, and x, y, z represent the unknowns in the equation.
[0064] By arranging formula (1), formula (2) can be obtained:
[0065] ax + by + cz + d = 0 (2);
[0066] where, (a, b, c) represents the normal vector of the lower cropping plane, x, y, z represent the unknowns in the equation, d represents the constant in the equation, and (a, b, c, d) is the plane coefficient of the lower cropping plane.
[0067] Taking the coordinates of vertex A as (x A , y A , z A ) as an example, the distance from vertex A to the lower cropping plane can be determined by formula (3):
[0068]
[0069] where, D0 represents the distance from vertex A to the lower cropping plane, (a, b, c, d) represents the plane coefficient of the lower cropping plane, (x A , y A , zA ) represents the coordinates of vertex A.
[0070] After determining the distance between vertex A and the lower clipping plane, it is possible to determine whether vertex A is within or outside the lower clipping plane based on the distance between vertex A and the lower clipping plane. When the distance between vertex A and the lower clipping plane is positive, vertex A is within the lower clipping plane; when the distance between vertex A and the lower clipping plane is negative, vertex A is outside the lower clipping plane. The positional relationship between other vertices and other clipping planes can be determined according to the calculation methods in formulas (1) to (3), so as to determine the clipping parameters based on the positional relationship between each vertex and each clipping plane.
[0071] In step S202 above, during each round of clipping, before the start of clipping, new clipping parameters are determined based on the positional relationship between at least one clipping plane and the updated current primitive, so as to judge whether clipping is required according to the new clipping parameters. This reduces the situation of invalid clipping and improves the efficiency of primitive clipping.
[0072] Step S203: When the clipping parameters indicate that there is no clipping plane that needs to clip the current primitive, the current primitive is determined as the clipped primitive.
[0073] In some embodiments, it is possible to determine whether there is a clipping plane that needs to clip the current primitive through the clipping parameters. When there is no clipping plane that needs to clip the current primitive, the clipping of the current primitive is completed. Here, the clipped primitive is the primitive obtained after clipping the primitive according to at least one clipping plane.
[0074] Taking the clipping parameter as the count value corresponding to each clipping plane in at least one clipping plane as an example, when the count value corresponding to each clipping plane is 0, the number of vertices existing outside each clipping plane is 0, and there is no clipping plane that needs to clip the current primitive, then the clipping ends, and the current primitive is determined as the primitive obtained after clipping the primitive according to at least one clipping plane.
[0075] Taking the clipping parameter as the primitive clipping mask as an example, when all the primitive clipping mask bits in the primitive clipping mask corresponding to the current primitive are 0, the current primitive is within each clipping plane, and there is no clipping plane that needs to clip the current primitive, then the clipping ends, and the current primitive is determined as the primitive obtained after clipping the primitive according to at least one clipping plane.
[0076] In some embodiments, when the clipping parameters indicate that there is a planned clipping plane that needs to clip the current primitive, the planned clipping plane is used to clip the current primitive.
[0077] Here, the planned cutting plane is the cutting plane that needs to cut the current primitive. It can be understood that the planned cutting plane may be the current cutting plane used in the current round of cutting process, or the cutting plane used in the next round or subsequent rounds of cutting process.
[0078] Taking the cutting parameter as the count value corresponding to each cutting plane in at least one cutting plane as an example, in the case where there is a planned cutting plane with a count value greater than 0, the number of vertices existing outside the planned cutting plane is the number greater than 0, and the planned cutting plane needs to cut the current primitive, then the current primitive is cut using the planned cutting plane.
[0079] Taking the cutting parameter as the primitive cutting mask as an example, in the case where there is a primitive cutting mask bit with a value of 1 in the primitive cutting mask corresponding to the current primitive, the current primitive is located outside the planned cutting plane corresponding to the primitive cutting mask, and the planned cutting plane needs to cut the current primitive, then the current primitive is cut using the planned cutting plane.
[0080] In some embodiments, after determining that there is a cutting plane that needs to cut the current primitive according to the cutting parameter, the cutting of the primitive can be implemented according to the coordinates of each vertex and the plane coefficients of the cutting plane.
[0081] Such as Figure 3 As shown, taking the current primitive as primitive ABC and the planned cutting plane as the lower cutting plane as an example, in the case where the cutting parameter indicates that there is a lower cutting plane that needs to cut primitive ABC, primitive ABC is cut by the lower cutting plane.
[0082] Exemplarily, after determining the plane coefficients of the lower cutting plane, the distance between vertex A located inside the lower cutting plane and the lower cutting plane, and the distance between vertex B located outside the lower cutting plane and the lower cutting plane according to formulas (1) to (3), the interpolation coefficient can be determined according to the distance between vertex A and the lower cutting plane and the distance between vertex B and the lower cutting plane, and primitive ABC is cut according to the interpolation coefficient. Such as Figure 3 As shown, in the case where vertex A is located inside the lower cutting plane, the distance from vertex A to the lower cutting plane can be represented by a positive number; in the case where vertex B is located outside the lower cutting plane, the distance from vertex B to the lower cutting plane can be represented by a negative number, and the interpolation coefficient can be determined by formula (4):
[0083]
[0084] Wherein, f represents the interpolation coefficient, D1 represents the distance between vertex B and the lower cutting plane, and D0 represents the distance between vertex A and the lower cutting plane.
[0085] In some embodiments, the coordinates of the new vertex D obtained by clipping the graphic primitive ABC against the lower clipping plane can be determined by formula (5):
[0086] C D = C A * f + C B *(1 - f) (5);
[0087] Wherein, C D represents the coordinates of vertex D, C A represents the coordinates of vertex A, f represents the interpolation coefficient, and C B represents the coordinates of vertex B.
[0088] Through formula (4) and formula (5), the position of the new vertex D interpolated between vertex A and vertex B during the clipping of the graphic primitive ABC against the lower clipping plane can be determined. Replace the position of vertex B outside the lower clipping plane with the new vertex D, and determine the position of the new vertex E according to the calculation methods of formulas (1) to (5), so as to determine the positions of the vertices in the polygon ADEC obtained after clipping the graphic primitive ABC against the lower clipping plane. Replace the graphic primitive ABC with the polygon ADEC to complete the clipping of the lower clipping plane against the graphic primitive ABC.
[0089] After using the planned clipping plane to clip the current graphic primitive, the clipping parameters corresponding to the target graphic primitive can be determined according to the position relationship between the target graphic primitive obtained after clipping and each clipping plane in at least one clipping plane, so as to determine whether there is a clipping plane that needs to clip the target graphic primitive according to the clipping parameters. In the case where there is no clipping plane that needs to clip the target graphic primitive, end the clipping and use the target graphic primitive as the clipped graphic primitive; in the case where there is a clipping plane that needs to clip the target graphic primitive, clip the target graphic primitive according to the clipping parameters, and determine new clipping parameters after clipping, so as to make a new round of judgment on the updated graphic primitive according to the new clipping parameters.
[0090] In the process of clipping the current graphic primitive in the embodiments of the present application, the clipping parameters are updated based on the currently updated graphic primitive after clipping, and the clipping is ended when the updated clipping parameters indicate that no further clipping is required, avoiding invalid graphic primitive clipping, reducing the time and power consumption required for graphic primitive clipping, and improving the efficiency of graphic primitive clipping.
[0091] Figure 4 This is a schematic implementation process of a graphic primitive clipping method provided by the embodiments of the present application Figure 2 . As Figure 4 shown, based on Figure 2 , Figure 2 step S202 in can be updated to step S401 to step S402, and step S203 can be updated to step S403.
[0092] Step S401: Determine the vertex clipping masks of the vertices in the current primitive based on the positional relationship between the at least one clipping plane and the vertices in the current primitive.
[0093] In some embodiments, when clipping a current primitive according to a clipping window, the vertex clipping masks can be determined based on the positional relationship between the clipping window and the vertices in the current primitive, so as to determine the primitive clipping mask corresponding to the current primitive according to the vertex clipping masks, and determine whether the current primitive is within the clipping window according to the primitive clipping mask, thereby determining whether the current primitive needs to be further clipped for the clipping window.
[0094] Here, the at least one clipping plane corresponding to the primitive is the clipping plane used to clip the primitive. The current primitive is the primitive to be clipped in the current round of clipping. In the case of the first round of clipping of the current primitive, the current primitive can be an unclipped primitive; in the case of the second round of clipping of the current primitive, the current primitive can be the primitive obtained after the first round of clipping. It can be understood that in different rounds of clipping, the shape of the current primitive may be different.
[0095] Wherein, in a round of clipping, the vertex clipping mask of a vertex of the current primitive indicates whether the vertex is outside each of the at least one clipping plane.
[0096] In some embodiments, the vertex clipping masks can be determined through steps S4011 to S4012.
[0097] Step S4011: Determine the vertex clipping mask bits corresponding to each of the clipping planes according to the positional relationship between each of the clipping planes and the vertex; the vertex clipping mask bits indicate whether the vertex is outside the clipping plane.
[0098] In some embodiments, the vertex clipping masks can include multiple vertex clipping mask bits. The number of vertex clipping mask bits can be determined according to the number of clipping planes in the at least one clipping plane. For example, if there are 4 clipping planes in the at least one clipping plane, the corresponding number of vertex clipping mask bits is 4. Each vertex clipping mask bit corresponds to a clipping plane respectively, and can indicate whether the vertex is outside the corresponding clipping plane.
[0099] Here, the counting sub-value can include a first parameter and a second value. The first value can be used to indicate that the vertex is within the corresponding clipping plane, and the second value can be used to indicate that the vertex is outside the corresponding clipping plane.
[0100] In some embodiments, the vertex clipping mask bit can be a first parameter or a second parameter. When a vertex is within a clipping plane, the vertex clipping mask bit corresponding to the clipping plane is the first parameter, indicating that the vertex is within the clipping plane; when a vertex is within a clipping plane, the vertex clipping mask bit corresponding to the clipping plane is the second parameter, indicating that the vertex is outside the clipping plane. Herein, the first parameter and the second parameter can be boolean values, numbers, etc.
[0101] In some embodiments, the first parameter and the second parameter can be binary digits 0 and 1. When a vertex is within a clipping plane, the vertex clipping mask bit corresponding to the clipping plane is the binary digit 0, indicating that the vertex is within the clipping plane; when a vertex is within a clipping plane, the vertex clipping mask bit corresponding to the clipping plane is the binary digit 1, indicating that the vertex is outside the clipping plane.
[0102] In some embodiments, the positional relationship between each vertex and each clipping plane can be determined according to the coordinates of each vertex and the plane coefficients of each clipping plane. For example, the distance from each vertex to each clipping plane can be determined by the calculation methods in formulas (1) to (3). When the distance from a vertex to a clipping plane is a positive number, the vertex is within the clipping plane; when the distance from a vertex to a clipping plane is a negative number, the vertex is outside the clipping plane.
[0103] In some embodiments, when a vertex is a new vertex and the new vertex meets a preset requirement, the vertex clipping mask bit of the clipping plane corresponding to the new vertex is set to a third parameter indicating that the new vertex is within the clipping plane. Herein, the new vertex is a vertex obtained by clipping a primitive based on a historical clipping plane in a previous clipping process.
[0104] In some embodiments, the current primitive in the current clipping process may have a different shape from the current primitive in the previous clipping process. The vertices in the current primitive in the current clipping process that are different from the current primitive in the previous clipping process can be used as new vertices.
[0105] As Figure 3 shown, in the clipping process of the second round, the corresponding current primitive is primitive ABC. The lower clipping plane can be used to clip primitive ABC to obtain primitive ADEC. In the clipping process of the third round, the corresponding current primitive is primitive ADEC, and the vertices different from primitive ABC in the previous clipping process are vertex D and vertex E. Then, the new vertices in the corresponding current primitive ADEC in the clipping process of the third round are vertex D and vertex E.
[0106] In some embodiments, taking the vertex clipping mask bit being binary digit 0 or 1 as an example, the third parameter can be the binary digit 0 indicating that the new vertex is within the clipping plane.
[0107] In some embodiments, the preset requirement may be that the clipping plane corresponding to the new vertex is the historical clipping plane. Here, the historical clipping plane is the clipping plane used in the previous clipping process before the current primitive is clipped in this round. It can be understood that when the clipping plane corresponding to the new vertex is the historical clipping plane, the new vertex is generated after clipping the primitive through the corresponding clipping plane. Therefore, the new vertex is not outside the corresponding clipping plane, and the vertex clipping mask bit of the clipping plane corresponding to the new vertex can be set to 0.
[0108] As Figure 3 shown, taking the new vertex as vertex E as an example, the lower clipping plane is the historical clipping plane used in the previous clipping process. Vertex E is obtained by clipping the primitive ABC with the lower clipping plane in the previous clipping process. Therefore, vertex E is not outside the lower clipping plane, and the vertex clipping mask bit of vertex E corresponding to the lower clipping plane can be set to 0.
[0109] In some embodiments, if the clipping planes corresponding to multiple vertex clipping mask bits in vertex E are all the clipping planes used in the previous clipping or before the previous clipping, then these multiple vertex clipping mask bits are all set to 0. As Figure 3 shown, taking the new vertex as vertex E as an example, the lower clipping plane is the clipping plane used in the previous clipping, and the upper clipping plane is the clipping plane used before the previous clipping. Vertex E is obtained by clipping the primitive ABC with the lower clipping plane in the previous clipping process. The vertex clipping mask bits of vertex E corresponding to the lower clipping plane used in the previous clipping process and the upper clipping plane used before the previous clipping are both set to 0.
[0110] In some embodiments, the preset requirement may be that the vertex clipping mask bit of the edge vertex of the primitive edge corresponding to the new vertex is set to a third parameter; wherein, the primitive edge is the edge in the primitive before clipping the primitive based on the historical clipping plane.
[0111] Taking the generation of a new vertex based on the historical clipping plane in the previous clipping process as an example, the primitive edge is the edge in the primitive before the previous clipping process. The primitive edge corresponding to the new vertex is the primitive edge where the new vertex is located. The edge vertex is other vertices on the primitive edge corresponding to the new vertex except the new vertex. It can be understood that when the vertex clipping mask bits of all edge vertices on the primitive edge for a clipping plane are all 0, all edge vertices on the primitive edge are located within the clipping plane. Therefore, the new vertex generated on the primitive edge should also be located within the clipping plane, and the vertex clipping mask bit of the new vertex corresponding to the clipping plane can be set to 0. As Figure 3As shown, taking the new vertex as vertex D for example, vertex D was generated based on the lower clipping plane in the previous clipping process. The primitive edge is the edge in primitive ABC before clipping through the lower clipping plane. The primitive edge corresponding to vertex D is edge AB, and the edge vertices on edge AB include vertex A and vertex B. Given that the vertex clipping mask bits corresponding to vertex A and vertex B with respect to the right clipping plane are both 0, vertex A and vertex B are both within the right clipping plane. Therefore, edge AB is also within the right clipping plane, and vertex D on edge AB should also be within the right clipping plane, and the vertex clipping mask bit corresponding to vertex D with respect to the right clipping plane is set to 0.
[0112] In some embodiments, taking the current clipping as the i-th round of clipping for example, there may be relatively long primitive edges in the historical primitives used in the clipping process of the round before the round before last (the (i - 3)-th round). If the new vertex is located on such a historical primitive edge, and the vertex clipping mask bits of the vertices at both ends of the historical primitive edge with respect to the lower clipping plane are not both 0, inferring that the vertex clipping mask bit of the new vertex with respect to the lower clipping plane is not 0 according to the above method may result in incorrect results.
[0113] In the clipping process of the round before last (the (i - 2)-th round), the historical primitive was clipped through the lower clipping plane, and all vertices in the obtained primitive are within the lower clipping plane, and the vertex clipping mask bits with respect to the lower clipping plane are all 0, such that the new vertices generated through other clipping planes in the clipping process of the previous round (the (i - 1)-th round) or after the previous round are all within the lower clipping plane, and the vertex clipping mask bits with respect to the lower clipping plane are all 0. Therefore, by determining the vertex clipping mask bits of the vertices on the primitive edges in the primitive before the previous clipping process according to the above method to infer the new vertex, it can be inferred that the vertex clipping mask bit of the new vertex with respect to the lower clipping plane is 0, and the result is correct.
[0114] Exemplarily, Figure 5 Another schematic diagram of the scene of the primitive and the clipping plane provided by the embodiment of the present application. Figure 5 The triangle A1B1C1 in it represents the primitive to be clipped, and 501, 502, 503, and 504 are respectively the four clipping planes corresponding to the primitive to be clipped. Hereinafter, taking 501 as the upper clipping plane, 502 as the lower clipping plane, 503 as the right clipping plane, and 504 as the left clipping plane as an example for illustration.
[0115] As Figure 5 shown, in the case of about to perform the first round of clipping, the current primitive is primitive A1B1C1, and the three vertices of primitive A1B1C1 are vertex A1, vertex B1, and vertex C1 respectively. In the first round of clipping process, primitive A1B1C1 is clipped through the lower clipping plane to obtain primitive A1D1E1C1, and in the second round of clipping process, primitive A1D1E1C1 is clipped through the right clipping plane to obtain primitive F1D1G1.
[0116] Take the third-round clipping process as the current clipping process. Before performing the current clipping process, it is necessary to determine the vertex clipping mask bits of vertex F1, vertex D1, and vertex G1 respectively. The primitive A1B1C1 is the historical primitive. If, according to the above method, the vertex clipping mask bit of the new vertex F1 for the lower clipping plane is judged through the edge A1B1 in the primitive A1B1C1, the vertex clipping mask bit of vertex A1 for the lower clipping plane is 0, and the vertex clipping mask bit of vertex B1 for the lower clipping plane is 1, then the vertex clipping mask bit of the new vertex F1 for the lower clipping plane is not 0, which is not the correct result.
[0117] If the vertex clipping mask bit of the new vertex F1 for the lower clipping plane is judged through the edge A1D1 in the primitive A1D1E1C1 before the previous round (the second round) of clipping process, the vertex clipping mask bit of vertex A1 for the lower clipping plane is 0, and the vertex clipping mask bit of vertex D1 for the lower clipping plane is 1, then the vertex clipping mask bit of the new vertex F1 for the lower clipping plane is 0, which is the correct result.
[0118] Therefore, when determining the vertex clipping mask bit of a new vertex for a certain clipping plane through the above method, the primitive edge should be the edge in the primitive before the previous round of clipping process.
[0119] In some embodiments, when the vertex is a new vertex and the new vertex does not meet the preset requirements, based on the distance from the new vertex to the clipping plane corresponding to the new vertex, determine the vertex clipping mask bit corresponding to the clipping plane.
[0120] In the above embodiments, when the new vertex meets the preset requirements, directly determine the vertex clipping mask bit of the clipping plane corresponding to the new vertex, which improves the determination efficiency of the vertex clipping mask, and thus improves the efficiency of primitive clipping.
[0121] As Figure 3 shown, taking the new vertex as vertex D, when it is necessary to determine the vertex clipping mask bit of vertex D corresponding to the left clipping plane, the left clipping plane is not the clipping plane used in the previous round of clipping process or before the previous round of clipping process. The vertex clipping mask bits of the vertices on the edge AB corresponding to vertex D for the left clipping plane are not all 0, and the above preset requirements cannot be met. Therefore, it is necessary to determine the distance from vertex D to the left clipping plane according to formulas (1) to (3), and then determine the vertex clipping mask bit of vertex D corresponding to the left clipping plane according to the distance from vertex D to the left clipping plane.
[0122] Step S4012: Determine the vertex clipping mask of the vertex according to the vertex clipping mask bit corresponding to each clipping plane.
[0123] In some embodiments, after determining the vertex clipping mask bits corresponding to each vertex of each clipping plane, the vertex clipping mask bits can be arranged in a preset order to obtain the vertex clipping mask.
[0124] As Figure 3 shown, after respectively determining the vertex clipping mask bits corresponding to vertex A, vertex B, and vertex C for the upper clipping plane, lower clipping plane, right clipping plane, and left clipping plane, the vertex clipping mask bits of the vertices can be arranged from the highest bit to the lowest bit in the order of the upper clipping plane, lower clipping plane, right clipping plane, and left clipping plane. The vertex clipping mask of vertex A is obtained as 0b0000, the vertex clipping mask of vertex B is 0b0101, and the vertex clipping mask of vertex C is 0b0010. In some embodiments, the clipping planes corresponding to the vertex clipping mask bits in the vertex clipping mask can also be in other permutation orders, and the present application does not limit this.
[0125] Step S402: Determine the primitive clipping mask according to the vertex clipping masks of the vertices in the current primitive.
[0126] In some embodiments, after determining the vertex clipping masks of the vertices in the current primitive, the primitive clipping mask of the current primitive can be determined according to the vertex clipping masks, so as to determine whether the current primitive is within each clipping plane according to the primitive clipping mask, thereby determining whether the current primitive needs to be clipped for each clipping plane.
[0127] In some embodiments, the primitive clipping mask can be determined through steps S4021 to S4022.
[0128] Step S4021: Determine the primitive clipping mask bit corresponding to each clipping plane according to the vertex clipping mask bit corresponding to each clipping plane.
[0129] In some embodiments, when only one vertex is included in the current primitive, the primitive clipping mask bit corresponding to each clipping plane of the current primitive is the same as the vertex clipping mask bit corresponding to each clipping plane of the vertex. When multiple vertices are included in the current primitive, the primitive clipping mask bit corresponding to each clipping plane of the current primitive can be determined according to the vertex clipping mask bits corresponding to the multiple vertices for each clipping plane.
[0130] In some embodiments, in the case where there is a vertex clipping mask bit indicating that the vertex is outside the clipping plane, the primitive clipping mask bit is set to a first parameter indicating that the clipping plane needs to clip the current primitive; in the case where there is no vertex clipping mask bit indicating that the vertex is outside the clipping plane, the primitive clipping mask bit is set to a second parameter indicating that the clipping plane does not need to clip the current primitive.
[0131] Taking the primitive clipping mask bit as a binary digit 0 or 1 as an example, the first parameter is the binary digit 1 indicating that the clipping plane needs to clip the current primitive, and the second parameter is the binary digit 0 indicating that the clipping plane does not need to clip the current primitive.
[0132] As Figure 3 shown, the primitive ABC includes vertex A, vertex B, and vertex C. Taking the determination of the primitive clipping mask bit of the primitive ABC corresponding to the lower clipping plane as an example, the vertex clipping mask bit of vertex A corresponding to the lower clipping plane is 0, indicating that vertex A is within the lower clipping plane; the vertex clipping mask bit of vertex B corresponding to the lower clipping plane is 1, indicating that vertex B is outside the lower clipping plane; the vertex clipping mask bit of vertex C corresponding to the lower clipping plane is 0, indicating that vertex C is within the lower clipping plane; among them, there is a vertex clipping mask bit indicating that vertex B is outside the lower clipping plane. Therefore, the primitive clipping mask bit of the primitive ABC corresponding to the lower clipping plane is the binary digit 1 indicating that the lower clipping plane needs to clip the primitive ABC.
[0133] Taking the determination of the primitive clipping mask bit of the primitive ABC corresponding to the upper clipping plane as an example, the vertex clipping mask bit of vertex A corresponding to the upper clipping plane is 0, indicating that vertex A is within the upper clipping plane; the vertex clipping mask bit of vertex B corresponding to the upper clipping plane is 0, indicating that vertex B is within the upper clipping plane; the vertex clipping mask bit of vertex C corresponding to the upper clipping plane is 0, indicating that vertex C is within the upper clipping plane; among them, there is no vertex clipping mask bit indicating that the vertex is outside the upper clipping plane. Therefore, the primitive clipping mask bit of the primitive ABC corresponding to the upper clipping plane is the binary digit 0 indicating that the upper clipping plane does not need to clip the primitive ABC.
[0134] Step S4022: Determine the primitive clipping mask according to the primitive clipping mask bits corresponding to each of the clipping planes.
[0135] In some embodiments, after determining the primitive clipping mask bits of the primitive corresponding to each clipping plane, the primitive clipping mask bits can be arranged in a preset order to obtain the primitive clipping mask.
[0136] As Figure 3 shown, after respectively determining the primitive clipping mask bits of the primitive ABC corresponding to the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane, the primitive clipping mask bits can be arranged from the highest bit to the lowest bit in the order of the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane. The primitive clipping mask of the primitive ABC is obtained as 0b0111. In some embodiments, the clipping planes corresponding to the primitive clipping mask bits in the primitive clipping mask can also be in other arrangement orders, which are not limited in this application.
[0137] In the above embodiments, in the process of each round of clipping, a new primitive clipping mask is determined based on the positional relationship between at least one clipping plane and the updated current primitive, so as to judge whether clipping is required according to the new primitive clipping mask. The situation of invalid clipping is reduced, and the efficiency of primitive clipping is improved.
[0138] Step S403, when each bit of the primitive clipping mask indicates that the corresponding clipping plane does not need to clip the current primitive, determine the current primitive as the clipped primitive.
[0139] Here, the clipped primitive is the primitive obtained after clipping the primitive according to at least one clipping plane. In some embodiments, the clipping parameter includes a primitive clipping mask; the primitive clipping mask includes the primitive clipping mask bits corresponding to each clipping plane. When all the primitive clipping mask bits in the primitive clipping mask corresponding to the current primitive are 0, the current primitive is within each clipping plane. Therefore, there is no clipping plane that needs to clip the current primitive, and the clipping ends, and the current primitive is determined as the primitive obtained after clipping the primitive according to at least one clipping plane.
[0140] In the process of clipping the current primitive in the above embodiments, the primitive clipping mask is updated based on the updated current primitive after clipping, and the clipping ends when the continuously updated primitive clipping mask indicates that no clipping is required, avoiding invalid primitive clipping, reducing the time and power consumption required for primitive clipping, and improving the efficiency of primitive clipping.
[0141] Figure 6 The implementation process schematic of a primitive clipping method provided by an embodiment of the present application Figure 3 . As Figure 6 shown, based on Figure 2 , Figure 2 step S202 in Figure 2 can be updated to step S601,
[0142] Step S601, determine the count value of each clipping plane based on the positional relationship between each clipping plane in the at least one clipping plane and each vertex in the current primitive; the count value indicates whether there is a vertex outside the clipping plane.
[0143] In some embodiments, a counter can be set for each clipping plane according to the number of clipping planes in the at least one clipping plane, and each counter is used to record the count value of the corresponding clipping plane. Among them, the count value can be represented by binary digits 0 and 1, or can be represented by specific values.
[0144] In some embodiments, the distances from each vertex to each clipping plane can be determined by the calculation methods in formulas (1) to (3). When the distance from a vertex to a clipping plane is positive, the vertex is located within the clipping plane; when the distance from a vertex to a clipping plane is negative, the vertex is located outside the clipping plane. After determining the positional relationship between each vertex and each clipping plane, the number of vertices existing outside each clipping plane can be determined based on the positional relationship between each vertex and each clipping plane, thereby determining the count value corresponding to each clipping plane.
[0145] Taking the count value represented by binary digits 0 and 1 as an example, the binary digit 0 can be used to represent that there are no vertices outside the corresponding clipping plane, and the binary digit 1 can be used to represent that there are vertices outside the corresponding clipping plane.
[0146] Taking the count value represented by specific numerical values as an example, when the count value is 0, the number of vertices existing outside the clipping plane corresponding to this count value is 0, that is, there are no vertices outside the clipping plane corresponding to this count value; when the count value is not 0, for example, when the count value is 2, the number of vertices existing outside the clipping plane corresponding to this count value is 2, that is, there are two vertices outside the clipping plane corresponding to this count value.
[0147] In some embodiments, the count values of each clipping plane can be determined through steps S6011 to S6012.
[0148] Step S6011: Determine the counting sub - value corresponding to each vertex according to the positional relationship between each vertex and the clipping plane; the counting sub - value represents whether the vertex is located outside or inside the clipping plane.
[0149] Taking the counting sub - value as binary digits 0 or 1 as an example, the binary digit 0 can be used to represent that the vertex is located within the corresponding clipping plane, and the binary digit 1 can be used to represent that the vertex is located outside the corresponding clipping plane.
[0150] As Figure 3 shown, taking the example of respectively determining the counting sub - values of the upper clipping plane, lower clipping plane, right clipping plane, and left clipping plane corresponding to vertex B, vertex B is located within the upper clipping plane, and the counting sub - value of the upper clipping plane corresponding to vertex B is 0; vertex B is located outside the lower clipping plane, and the counting sub - value of the lower clipping plane corresponding to vertex B is 1; vertex B is located within the right clipping plane, and the counting sub - value of the right clipping plane corresponding to vertex B is 0; vertex B is located outside the left clipping plane, and the counting sub - value of the left clipping plane corresponding to vertex B is 1.
[0151] Step S6012: Determine the count value of the clipping plane according to the counting sub - values corresponding to each vertex.
[0152] In some embodiments, after determining the count sub-values corresponding to each vertex for a clipping plane, the count value of the clipping plane can be determined based on each count sub-value.
[0153] Taking the count value represented by binary digits 0 and 1 as an example, when there is a count sub-value indicating that a vertex is outside the clipping plane among the count sub-values corresponding to a clipping plane, the count value of the clipping plane is set to 1; when there is no count sub-value indicating that a vertex is outside the clipping plane among the count sub-values corresponding to a clipping plane, the count value of the clipping plane is set to 0.
[0154] As Figure 3 shown, the count sub-values corresponding to vertex A, vertex B, and vertex C of the lower clipping plane are 0, 1, and 0 respectively. Among them, there is a count sub-value 1 indicating that vertex B is outside the lower clipping plane. Therefore, the count value of the lower clipping plane for the primitive ABC is set to 1, indicating that there is a vertex outside the lower clipping plane.
[0155] Taking the count value represented by specific numerical values as an example, the count sub-values corresponding to a clipping plane can be added to determine the count value of the clipping plane.
[0156] As Figure 3 shown, the count sub-values corresponding to vertex A, vertex D, vertex E, and vertex C of the right clipping plane for the primitive ADEC are 0, 0, 1, and 1 respectively. After adding the count sub-values corresponding to the right clipping plane, the count value of the right clipping plane for the primitive ADEC is 2, indicating that there are two vertices outside the right clipping plane.
[0157] In the above embodiments, during each round of clipping, based on the positional relationship between at least one clipping plane and the updated current primitive, a new count value is determined to judge whether clipping is required according to the new count value. The situation of invalid clipping is reduced, and the efficiency of primitive clipping is improved.
[0158] Step S602: When the count value of each of the clipping planes indicates that there is no such vertex outside the corresponding clipping plane, determine the current primitive as the clipped primitive.
[0159] Here, the clipped primitive is the primitive obtained after clipping the primitive according to at least one clipping plane. In some embodiments, when the count value of each of the clipping planes corresponding to the current primitive is 0, each vertex in the current primitive is within each clipping plane. Therefore, there is no clipping plane that needs to clip the current primitive, and the clipping ends, and the current primitive is determined as the primitive obtained after clipping the primitive according to at least one clipping plane.
[0160] During the process of clipping the current primitive in the above embodiments, the count value corresponding to each clipping plane is updated based on the continuously updated current primitive, and the clipping is ended when the continuously updated count values all indicate that no clipping is required, avoiding invalid primitive clipping, reducing the time and power consumption required for primitive clipping, and improving the efficiency of primitive clipping.
[0161] The following describes the application of the primitive clipping method provided by the embodiments of the present application in an actual scenario.
[0162] The GPU can be used to implement the rendering of 2D images or 3D images. A 3D image is a geometric body composed of multiple primitives, which may include thousands of primitives. Therefore, a large amount of processing and calculation may be required during the process of the GPU implementing 3D image rendering. The invisible or unnecessary parts of the primitives in the image rendering process can be removed through primitive clipping to improve the image rendering efficiency and reduce unnecessary calculations.
[0163] During the process of implementing primitive clipping in the related art, the following problems exist:
[0164] During the process of implementing primitive clipping in the GPU, first, the primitive clipping mask of the primitive needs to be determined to determine which specific clipping planes the primitive needs to be clipped against according to the clipping mask. The clipping unit traverses each edge of the primitive and performs an intersection test on each edge and the corresponding clipping plane in turn. If the edge intersects the clipping plane, then a new vertex is clipped out, added to the primitive, and the primitive is reorganized. During the process of implementing primitive clipping through the above method, the primitive clipping mask of the primitive does not change.
[0165] During the process of primitive clipping, when a new vertex is clipped out, the shape of the primitive will change. After the shape of the primitive changes, it may no longer be necessary to clip against some specific clipping planes. If the above process continues and the initial clipping mask is used to perform primitive clipping on specific clipping planes, it may cause waste of the time and power consumption required for primitive clipping. Based on the above problems, during the process of clipping the current primitive in the embodiments of the present application, the clipping parameters are updated based on the current primitive updated after clipping, and the clipping is ended when the updated clipping parameters indicate that no further clipping is required, avoiding invalid primitive clipping, reducing the time and power consumption required for primitive clipping, and improving the efficiency of primitive clipping.
[0166] The primitive clipping method in the embodiments of the present application can be applied to a primitive clipping device and a primitive clipping device, or applied to a hardware system or device configured with a primitive clipping device or a primitive clipping device.
[0167] Such as Figure 1As shown in the figure, the system architecture 100 of the primitive clipping method provided by the embodiment of the present application includes a primitive assembly module 101, a clipping module 102, and a vertex buffer 103. Among them, the primitive assembly module 101 is used to generate vertex coordinates, primitive information, and guard band parameters. The primitive information includes the vertex coordinates that make up the primitive. The primitive assembly module 101 can eliminate the primitives whose vertices are all outside each clipping plane among at least one clipping plane and do not need to be clipped, eliminate the primitives whose vertices are all within the guard area determined by the guard band parameters and each clipping plane among at least one clipping plane, and send the vertex coordinates of the primitives with some vertices within the guard area to the clipping module 102. The clipping module 102 is used to clip the primitive according to the received primitive information. The vertex buffer 103 is used to cache the clipping results obtained by clipping the primitive.
[0168] The clipping module 102 includes a clipping parameter generation unit 1021, a clipping decision unit 1022, and a clipping execution unit 1023. Among them, the clipping parameter generation unit 1021 is used to generate the clipping parameters required in the process of clipping the primitive according to the positional relationship between the primitive and the clipping window, and update the clipping parameters according to the clipped primitive; the clipping decision unit 1022 is used to determine the current clipping plane for clipping the current primitive according to the current clipping parameters; the clipping execution unit 1023 can use the current clipping plane to clip the current primitive, and send the clipping result to the vertex buffer 103. The clipping execution unit 1023 can also send the clipping result to the clipping parameter generation unit 1021, so that the clipping parameter generation unit 1021 updates the clipping parameters according to the positional relationship between the new vertex and the clipping window.
[0169] The following takes the primitive clipping mask as the clipping parameter as an example for illustration.
[0170] Exemplarily, Figure 3 is a schematic diagram of the scenario of a primitive and a clipping plane provided by the embodiment of the present application. Figure 3 The triangle ABC in it represents the primitive to be clipped. 301, 302, 303, and 304 are respectively the four clipping planes corresponding to the primitive to be clipped. The following takes 301 as the upper clipping plane, 302 as the lower clipping plane, 303 as the right clipping plane, and 304 as the left clipping plane as an example for illustration.
[0171] As Figure 3 shown, in the case of the first round of clipping to be performed, the current primitive is the primitive ABC, and the primitive ABC has three vertices, namely vertex A, vertex B, and vertex C. Among them, vertex A is within all clipping planes. Vertex B is outside the lower clipping plane and the left clipping plane, and within the other two clipping planes. Vertex C is outside the right clipping plane and within the other three clipping planes.
[0172] Corresponding to the four clipping planes, the vertex clipping masks of vertex A, vertex B, and vertex C for the four clipping planes can be encoded by four vertex clipping mask bits respectively. Among them, the vertex clipping mask of a vertex is a binary number. If a certain vertex clipping mask bit is 1, it indicates that the vertex is outside the corresponding clipping plane; if a certain vertex clipping mask bit is 0, it indicates that the vertex is inside the corresponding clipping plane. The vertex clipping mask bits of the vertex can be arranged from high to low in the order of the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane. The vertex clipping mask of vertex A is obtained as 0b0000, the vertex clipping mask of vertex B is obtained as 0b0101, and the vertex clipping mask of vertex C is obtained as 0b0010.
[0173] In some embodiments, the primitive clipping mask P(ABC) of the primitive ABC can be obtained by bitwise OR of the vertex clipping masks of vertex A, vertex B, and vertex C as 0b0111, indicating that the lower clipping plane, the right clipping plane, and the left clipping plane need to clip the primitive ABC.
[0174] In some embodiments, after the primitive clipping mask is determined by the clipping parameter generation unit 1021, the primitive clipping mask can be sent to the clipping decision unit 1022. After the clipping decision unit 1022 determines that the primitive clipping mask is 0b0111, it determines the current clipping planes in the preset order as the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane in sequence. Since the upper clipping plane does not need to clip the primitive ABC, the clipping decision unit 1022 decides to clip the primitive ABC through the lower clipping plane, the right clipping plane, and the left clipping plane in sequence. Since the clipping execution unit can only perform primitive clipping for one clipping plane at a time, before performing the clipping of the primitive, the clipping decision unit 1022 can decide the current clipping plane used to clip the current primitive in the current clipping process. According to the preset order of the clipping planes, the clipping decision unit 1022 can first decide to perform primitive clipping for the lower clipping plane, so that the clipping execution unit 1023 clips the primitive ABC for the lower clipping plane to obtain the polygon ADEC. Next, the vertex clipping masks of the newly generated vertices D and E can be determined. The vertex clipping mask of vertex D is 0b0000, and the vertex clipping mask of vertex E is 0b0010.
[0175] Next, the clipping execution unit 1023 sends the vertex clipping masks of vertex D and vertex E to the clipping parameter generation unit 1021. The clipping parameter generation unit 1021 updates the corresponding primitive clipping mask P(ADEC) to 0b0010 according to the vertex clipping masks of the vertices of polygon ADEC. After the clipping decision unit 1022 determines that the primitive clipping mask is 0b0010, it decides to clip polygon ADEC against the right clipping plane. The clipping execution unit 1023 clips polygon ADEC against the right clipping plane to obtain polygon ADFG. It is determined that the vertex clipping masks of the newly generated vertices F and G are both 0b0000.
[0176] Next, the clipping execution unit 1023 sends the vertex clipping masks of vertex F and vertex G to the clipping parameter generation unit 1021. The clipping parameter generation unit 1021 updates the corresponding primitive clipping mask P(ADFG) to 0b0000 according to the vertex clipping masks of the vertices of polygon ADFG. Since all the primitive clipping mask bits in the primitive clipping mask are already 0, indicating that polygon ADFG does not need to be clipped against any clipping plane, the clipping ends.
[0177] Figure 7 This is a schematic diagram of the vertex clipping mask of a vertex provided by an embodiment of the present application. From Figure 7 it can be seen that the vertex clipping mask bits of vertex A, vertex B, vertex C, vertex D, vertex E, vertex F, and vertex G correspond to the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane respectively. As Figure 7 shown, the vertex clipping mask bits of vertex A for the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane are all 0, and the vertex clipping mask of vertex A is 0b0000; the vertex clipping mask bits of vertex B for the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane are 0, 1, 0, and 1 respectively, and the vertex clipping mask of vertex B is 0b0101; the vertex clipping mask bits of vertex C for the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane are 0, 0, 1, and 0 respectively, and the vertex clipping mask of vertex C is 0b0010.
[0178] As Figure 7 shown, for the newly generated vertices D, E, F, and G, only the specific part of the vertex clipping mask that does not meet the preset requirements needs to be calculated, and the part of the vertex clipping mask that meets the preset requirements is directly set to 0.
[0179] In some embodiments, the vertex clipping masks of the new vertices that meet the preset requirements can be confirmed by the following algorithm: for the new vertices, the clipping mask bits for the planes that have been clipped before and the current clipping plane are directly set to 0, that is, no intersection will occur. For example, Figure 3The midpoint E is a new vertex obtained by clipping the primitive with the lower clipping plane 302. For the previously clipped upper clipping plane 301 and the currently clipped lower clipping plane 302, the vertex clipping mask bits of vertex E with respect to the upper clipping plane 301 and the lower clipping plane 302 are directly set to 0. For a new vertex, if the vertex clipping mask bits of all vertices on the edge where the vertex is located with respect to the corresponding clipping plane are 0, the vertex clipping mask bit of the vertex with respect to the corresponding clipping plane can be directly set to 0. For example, Figure 3 The midpoint D is obtained by clipping the AB edge of the primitive ABC with the lower clipping plane 302. Since the vertex clipping mask bits of vertices A and B on the AB edge where vertex D is located with respect to the right clipping plane 303 are both 0, the vertex clipping mask bit of the vertex D obtained by clipping the AB edge with respect to the right clipping plane 303 can be directly set to 0.
[0180] The above embodiments optimize part of the clipping decision in the primitive clipping process. On the one hand, the newly generated vertices also participate in the clipping decision, which can avoid unnecessary clipping. On the other hand, when all the primitive clipping mask bits in the primitive clipping mask are 0, the primitive clipping ends, without having to loop through to the last clipping plane, saving the time and power consumption required for clipping and improving the efficiency of the clipping process.
[0181] Figure 8 The implementation process schematic of a primitive clipping method provided by an embodiment of the present application Figure 4 . As Figure 8 shown, the primitive clipping method of the embodiment of the present application may include steps S801 to S808.
[0182] Step S801: Determine the primitive clipping mask. Among them, according to the preset order of the clipping planes, determine the vertex clipping masks corresponding to each vertex of the primitive (corresponding to the current primitive in the above embodiment), and perform a bitwise OR operation on the vertex clipping masks of each vertex to obtain the primitive clipping mask.
[0183] Step S802: Determine the clipping plane with a mask of 1. Among them, determine the clipping plane corresponding to the case where the clipping mask bit in the primitive clipping mask is 1.
[0184] Step S803: Traverse each edge of the primitive. Among them, traverse each edge of the primitive to determine whether each edge intersects with the clipping plane (corresponding to the current clipping plane in the above embodiment).
[0185] Step S804: Determine whether the edge intersects with the clipping plane. Among them, if the edge intersects with the clipping plane, execute step S805; if the edge does not intersect with the clipping plane, execute step S803.
[0186] Step S805: Calculate the clipping mask of the intersection point. Specifically, in the case where an edge intersects a clipping plane, calculate the vertex clipping mask bits of the intersection point for each clipping plane respectively, and determine the vertex clipping mask of the intersection point based on each vertex clipping mask bit.
[0187] Step S806: Determine whether all edges of the primitive have been looped through. Specifically, if all edges of the primitive have been looped through, execute Step S807; if all edges of the primitive have not been looped through, execute Step S802.
[0188] Step S807: Update the primitive clipping mask. Specifically, determine new vertices based on each intersection point, and update the primitive clipping mask according to the vertex clipping masks of the new vertices.
[0189] Step S808: Determine whether each primitive clipping mask bit is 0. Specifically, if all primitive clipping mask bits in the primitive clipping mask are 0, it means that the updated primitive does not need to be clipped for any clipping plane, so the clipping ends; if not all primitive clipping mask bits in the primitive clipping mask are 0, then return to execute Step S802.
[0190] In the above embodiment, the primitive clipping mask is updated according to the vertex clipping masks of the new vertices generated during the primitive clipping process, and the primitive clipping is realized based on the continuously updated primitive clipping mask. When all primitive clipping mask bits in the primitive clipping mask are 0, the primitive clipping ends, without the need to loop through to the last clipping plane, reducing the situation of useless primitive clipping for some clipping planes according to the original primitive clipping mask, thereby reducing the time and power consumption required for primitive clipping and improving the efficiency of primitive clipping.
[0191] Figure 9 The implementation process schematic of a primitive clipping method provided by an embodiment of the present application Figure 5 As Figure 9 shown, the primitive clipping method of the embodiment of the present application may include Step S901 to Step S905.
[0192] Step S901: Determine whether to clip for a clipping plane. Determine whether the new vertices generated during the primitive clipping process are clipped for the corresponding clipping plane. If the new vertices are not clipped for the corresponding clipping plane, execute Step S902; if the new vertices have been clipped for the corresponding clipping plane, execute Step S904.
[0193] Step S902: Determine the vertex clipping mask bits of other vertices on the edge where the new vertex is located for the clipping plane. Determine the vertex clipping mask bits of other vertices on the edge where the new vertex is located for the clipping plane.
[0194] Step S903: Determine whether all other vertex clipping mask bits are 0. Determine whether the vertex clipping mask bits of other vertices on the edge where the new vertex is located with respect to the clipping plane are all 0. If the vertex clipping mask bits of other vertices with respect to the clipping plane are all 0, then execute Step S904; if the vertex clipping mask bits of other vertices with respect to the clipping plane are not all 0, then execute Step S905.
[0195] Step S904: Set the vertex clipping mask bit of the new vertex with respect to the clipping plane to 0. Set the vertex clipping mask bit of the new vertex with respect to the clipping plane to 0.
[0196] Step S905: Calculate the vertex clipping mask bit of the new vertex with respect to the clipping plane. Determine the vertex clipping mask bit of the new vertex with respect to the clipping plane according to the positional relationship between the new vertex and the clipping plane.
[0197] In the above embodiments, for a clipped clipping plane, the vertex clipping mask bit of the new vertex can be directly determined, or the vertex clipping mask bit of the new vertex with respect to the clipping plane can be determined according to the clipping mask bits of other vertices on the edge where the new vertex is located with respect to the clipping plane, improving the determination efficiency of the vertex clipping mask of the new vertex.
[0198] In some embodiments, the clipping of the primitive can also be completed by setting a counter for each clipping plane in at least one clipping plane. For example, a counter can be set for each clipping plane, and each counter can be used to record the number of vertices located outside the corresponding clipping plane. Taking Figure 3 the primitive ABC in as an example for clipping against the upper clipping plane 301, lower clipping plane 302, right clipping plane 303, and left clipping plane 304, refer to Figure 10 as shown. Before the primitive ABC starts to be clipped, there are 0 vertices outside the upper clipping plane, so the number recorded in the counter corresponding to the upper clipping plane is 0; there is 1 vertex outside the lower clipping plane, so the number recorded in the counter corresponding to the lower clipping plane is 1; there is 1 vertex outside the right clipping plane, so the number recorded in the counter corresponding to the right clipping plane is 1; there is 1 vertex outside the left clipping plane, so the number recorded in the counter corresponding to the left clipping plane is 1.
[0199] In some embodiments, the preset order can be the arrangement order of the upper clipping plane, lower clipping plane, right clipping plane, and left clipping plane. It can be determined whether the primitive ABC needs to be clipped against each clipping plane in at least one clipping plane according to the preset order. When the number in the counter corresponding to the upper clipping plane is 0, the primitive ABC does not need to be clipped against the upper clipping plane. When the number in the counter corresponding to the lower clipping plane is 1, the primitive ABC needs to be clipped against the lower clipping plane. After the primitive ABC is clipped against the lower clipping plane, the polygon ADEC can be obtained.
[0200] Compared with the graphic element ABC, the polygon ADEC adds vertices D and E and reduces vertex B. Therefore, the counter of the clipping plane needs to be updated according to the positions of the vertices of the polygon ADEC after clipping. As Figure 11 shown, after obtaining the polygon ADEC, there are 0 vertices outside the upper clipping plane. Therefore, the number recorded in the counter corresponding to the upper clipping plane is 0; there are 0 vertices outside the lower clipping plane. Therefore, the number recorded in the counter corresponding to the lower clipping plane is 0; there are 2 vertices outside the right clipping plane. Therefore, the number recorded in the counter corresponding to the right clipping plane is 2; there are 0 vertices outside the left clipping plane. Therefore, the number recorded in the counter corresponding to the left clipping plane is 0.
[0201] In some embodiments, the count values corresponding to the respective clipping planes can be represented by binary digits 0 or 1. It is characterized by the binary digit 0 that there are no vertices outside the corresponding clipping plane. In the case where the count value is 0, the clipping plane corresponding to the count value does not need to clip the current graphic element; it can be characterized by the binary digit 1 that there are vertices outside the corresponding clipping plane. In the case where the count value is 1, the clipping plane corresponding to the count value needs to clip the current graphic element.
[0202] In some embodiments, after the graphic element ABC clips the upper clipping plane and the lower clipping plane, the numbers recorded in the counters corresponding to the upper clipping plane and the lower clipping plane can be directly set to 0.
[0203] When the number in the counter corresponding to the right clipping plane is 2, the polygon ADEC needs to be clipped for the right clipping plane. After clipping, the polygon ADFG can be obtained. Next, the counter of the clipping plane can be updated according to the positions of the vertices of the polygon ADFG. Since the vertices A, D, F, and G are not outside the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane, the numbers in the counters corresponding to the upper clipping plane, the lower clipping plane, the right clipping plane, and the left clipping plane are all updated to 0. When the numbers in all the counters corresponding to the clipping planes are 0, the clipping of the graphic element ends.
[0204] In some embodiments, the counters corresponding to each clipping plane in at least one clipping plane can be respectively used to record whether there are vertices outside the clipping plane. For example, it can be indicated by the number 0 that there are no vertices outside the clipping plane, and by the number 1 that there are vertices outside the clipping plane.
[0205] Figure 12 The implementation process schematic of a graphic element clipping method provided by an embodiment of the present application Figure 6 As Figure 12 shown, the graphic element clipping method of the embodiment of the present application can include steps S1201 to S1208.
[0206] Step S1201: Set counters for the clipping planes. Set counters for each of at least one clipping plane, where the counter is used to record the number of vertices outside each clipping plane.
[0207] Step S1202: Determine the non-zero clipping planes. Determine the clipping planes for which the counters are non-zero. If the counter is non-zero, it means there are vertices outside the clipping plane, indicating that the clipping plane needs to clip the primitive.
[0208] Step S1203: Traverse each edge of the primitive. Traverse each edge of the primitive (corresponding to the current primitive in the above embodiment) to determine whether each edge intersects with the clipping plane.
[0209] Step S1204: Determine whether the edge intersects with the clipping plane. Determine whether the edge of the primitive intersects with the clipping plane. If the edge intersects with the clipping plane, execute Step S1205; if the edge does not intersect with the clipping plane, execute Step S1203.
[0210] Step S1205: Take the intersection point as a new vertex. When the edge of the primitive intersects with the clipping plane, take the intersection point as a new vertex of the primitive, and replace the vertex outside the clipping plane on this edge with the new vertex.
[0211] Step S1206: Determine whether all edges have been traversed in a loop. Determine whether all edges of the primitive have been traversed in a loop. If all edges of the primitive have been traversed in a loop, execute Step S1207; if all edges of the primitive have not been traversed in a loop, execute Step S1202.
[0212] Step S1207: Update the counter of the clipping plane. After replacing the vertices outside the clipping plane with all the intersection points on the clipping plane, there are no vertices outside the clipping plane, so the counter of this clipping plane can be updated to 0.
[0213] Step S1208: Determine whether each clipping plane is zero. Determine whether the counter of each clipping plane is zero. If the counter of each clipping plane is zero, it means that all the vertices of the updated primitive are not outside the clipping plane, so the primitive does not need to be clipped for any clipping plane, and thus the clipping ends; if the counters of each clipping plane are not all zero, return to execute Step S1202.
[0214] In the above embodiment, a counter is set for each clipping plane to record the number of vertices outside the corresponding clipping plane. For the clipped clipping plane, the number in the counter can be set to zero. When the numbers in all the counters corresponding to the clipping planes are zero, the primitive clipping ends, avoiding invalid primitive clipping and improving the efficiency of primitive clipping.
[0215] Figure 13Schematic diagram of a graphic primitive clipping device provided by an embodiment of the present application. As Figure 13 shown, the graphic primitive clipping device 1300 includes a data acquisition module 1301, a parameter determination module 1302, and a result determination module 1303, where:
[0216] The data acquisition module 1301 is configured to acquire a graphic primitive and at least one clipping plane corresponding to the graphic primitive;
[0217] The parameter determination module 1302 is configured to determine clipping parameters based on the positional relationship between the at least one clipping plane and the current graphic primitive before clipping the current graphic primitive with the current clipping plane; the current graphic primitive is the graphic primitive or the result after the graphic primitive has been clipped at least once;
[0218] The result determination module 1303 is configured to determine the current graphic primitive as the clipped graphic primitive when the clipping parameters indicate that there is no clipping plane that needs to clip the current graphic primitive.
[0219] In some embodiments, the clipping parameters include a graphic primitive clipping mask; the parameter determination module 1302 is further configured to determine a vertex clipping mask for each vertex in the current graphic primitive based on the positional relationship between the at least one clipping plane and each vertex in the current graphic primitive; and determine the graphic primitive clipping mask according to the vertex clipping masks of each vertex in the current graphic primitive.
[0220] In some embodiments, the vertex clipping mask includes a vertex clipping mask bit corresponding to each clipping plane; the parameter determination module 1302 is further configured to determine a vertex clipping mask bit corresponding to each clipping plane according to the positional relationship between each clipping plane and the vertex; the vertex clipping mask bit indicates whether the vertex is outside the clipping plane; and determine the vertex clipping mask of the vertex according to the vertex clipping mask bits corresponding to each clipping plane.
[0221] In some embodiments, the graphic primitive clipping mask includes a graphic primitive clipping mask bit; the parameter determination module 1302 is further configured to determine a graphic primitive clipping mask bit corresponding to each clipping plane according to the vertex clipping mask bits corresponding to each clipping plane; and determine the graphic primitive clipping mask according to the graphic primitive clipping mask bits corresponding to each clipping plane.
[0222] In some embodiments, the parameter determination module 1302 is further configured to, when there is a vertex clipping mask bit indicating that the vertex is outside the clipping plane, set the graphic primitive clipping mask bit to a first parameter indicating that the clipping plane needs to clip the current graphic primitive; and when there is no vertex clipping mask bit indicating that the vertex is outside the clipping plane, set the graphic primitive clipping mask bit to a second parameter indicating that the clipping plane does not need to clip the current graphic primitive.
[0223] In some embodiments, the clipping parameter includes a primitive clipping mask; the primitive clipping mask includes primitive clipping mask bits corresponding to each of the clipping planes; the result determination module 1303 is further configured to determine the current primitive as the clipped primitive when each of the primitive clipping mask bits indicates that the corresponding clipping plane does not need to clip the current primitive.
[0224] In some embodiments, the parameter determination module 1302 is further configured to, when the vertex is a new vertex and the new vertex meets a preset requirement, set the vertex clipping mask bit of the clipping plane corresponding to the new vertex to a third parameter indicating that the new vertex is within the clipping plane; when the vertex is a new vertex and the new vertex does not meet the preset requirement, determine the vertex clipping mask bit corresponding to the clipping plane based on the distance from the new vertex to the clipping plane corresponding to the new vertex; wherein the new vertex is a vertex obtained by clipping the primitive based on a historical clipping plane that has undergone a clipping process.
[0225] In some embodiments, the preset requirement includes any one of the following: the clipping plane corresponding to the new vertex is the historical clipping plane; the vertex clipping mask bit of the edge vertex of the primitive edge corresponding to the new vertex is set to the third parameter; the primitive edge is an edge in the primitive before the primitive is clipped based on the historical clipping plane.
[0226] In some embodiments, the clipping parameter includes a count value for each of the clipping planes; the parameter determination module 1302 is further configured to determine the count value for each of the clipping planes based on the positional relationship between each of the clipping planes in the at least one clipping plane and the vertices in the current primitive; the count value indicates whether there is a vertex outside the clipping plane.
[0227] In some embodiments, the count value includes a count sub-value; the parameter determination module 1302 is further configured to determine the count sub-value corresponding to each vertex according to the positional relationship between each vertex and the clipping plane; the count sub-value indicates whether the vertex is outside or inside the clipping plane; determine the count value of the clipping plane according to the count sub-values corresponding to each vertex.
[0228] In some embodiments, the result determination module 1303 is further configured to determine the current primitive as the clipped primitive when the count value of each clipping plane indicates that there is no vertex outside the corresponding clipping plane.
[0229] In some embodiments, the parameter determination module 1302 is further configured to, when the cropping parameter indicates that there is a planned cropping plane for cropping the current primitive, crop the current primitive using the planned cropping plane.
[0230] The description of the above device embodiments is similar to the description of the above method embodiments and has similar beneficial effects to those of the method embodiments. In some embodiments, the functions or modules included in the device provided in the embodiments of the present application can be used to execute the methods described in the above method embodiments. For the technical details not disclosed in the device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.
[0231] The embodiments of the present application provide a computer device, including a memory and a processor. The memory stores a computer program that can run on the processor. When the processor executes the program, some or all of the steps in the above method are implemented.
[0232] The embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, some or all of the steps in the above method are implemented. The computer-readable storage medium can be transient or non-transient.
[0233] The embodiments of the present application provide a computer program, including computer-readable code. When the computer-readable code runs on a computer device, the processor in the computer device executes to implement some or all of the steps in the above method.
[0234] The embodiments of the present application provide a computer program product. The computer program product includes a non-transient computer-readable storage medium storing a computer program. When the computer program is read and executed by a computer, some or all of the steps in the above method are implemented. The computer program product can be specifically implemented in a manner of hardware, software, or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium. In other embodiments, the computer program product is specifically embodied as a software product, such as a Software Development Kit (SDK), etc.
[0235] It should be noted here that: the descriptions of the above embodiments tend to emphasize the differences between the embodiments, and their similarities can be referred to each other. The descriptions of the above device, storage medium, computer program, and computer program product embodiments are similar to the descriptions of the above method embodiments and have similar beneficial effects to those of the method embodiments. For the technical details not disclosed in the device, storage medium, computer program, and computer program product embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.
[0236] Figure 14 The following is a schematic diagram of the hardware entity of a computer device provided by an embodiment of the present application. As Figure 14 shown, the hardware entity of the computer device 1400 includes: a processor 1401 and a memory 1402. Among them, the memory 1402 stores a computer program that can run on the processor 1401. When the processor 1401 executes the program, it implements the steps in the method of any of the above embodiments.
[0237] The memory 1402 stores a computer program that can run on the processor. The memory 1402 is configured to store instructions and applications executable by the processor 1401, and can also cache data to be processed or already processed by the processor 1401 and each module in the computer device 1400 (for example, image data, audio data, voice communication data, and video communication data). It can be implemented by flash memory (FLASH) or random access memory (Random Access Memory, RAM).
[0238] When the processor 1401 executes the program, it can implement the steps of the primitive clipping method of any of the above. The processor 1401 generally controls the overall operation of the computer device 1400.
[0239] An embodiment of the present application provides a computer storage medium. The computer storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the primitive clipping method of any of the above embodiments.
[0240] It should be pointed out here that: the descriptions of the above storage medium and device embodiments are similar to the descriptions of the above method embodiments, and have beneficial effects similar to those of the method embodiments. For the technical details not disclosed in the storage medium and device embodiments of the present application, please refer to the descriptions of the method embodiments of the present application for understanding. The above processor can be at least one of an application specific integrated circuit (ASIC), a digital signal processor (Digital Signal Processor, DSP), a digital signal processing device (Digital Signal Processing Device, DSPD), a programmable logic device (Programmable Logic Device, PLD), a field programmable gate array (Field Programmable Gate Array, FPGA), a central processing unit, a controller, a microcontroller, and a microprocessor. It can be understood that other electronic devices can also implement the functions of the above processor, and the embodiments of the present application do not make specific limitations.
[0241] The above computer storage medium / memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a ferromagnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM), etc.; it can also be various terminals including one or any combination of the above memories, such as a mobile phone, a computer, a tablet device, a personal digital assistant, etc.
[0242] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, the "in one embodiment" or "in an embodiment" that appears throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the order numbers of the above steps / processes do not mean the order of execution. The order of execution of each step / process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application. The serial numbers of the embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.
[0243] It should be noted that in this article, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of another identical element in the process, method, article or device including the element.
[0244] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed with each other can be through some interfaces. The indirect coupling or communication connection of the devices or units can be electrical, mechanical, or other forms.
[0245] The units described above as separate components may or may not be physically separated. The components shown as units may or may not be physical units. They can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0246] In addition, each functional unit in the embodiments of the present application can be all integrated in a processing unit, or each unit can be separately used as a unit, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware, or in the form of hardware plus software functional units.
[0247] Those of ordinary skill in the art can understand that all or part of the steps for implementing the above method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the above method embodiments. The foregoing storage medium includes: various media that can store program codes such as removable storage devices, read-only memory (ROM), magnetic disks, or optical discs.
[0248] Alternatively, if the above-mentioned integrated units of the present application are implemented in the form of software function modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application essentially or the part that contributes to the related technology can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the embodiments of the present application. The foregoing storage medium includes: various media that can store program codes such as removable storage devices, ROM, magnetic disks, or optical discs.
[0249] As described above, it is only the implementation mode of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art within the technical scope disclosed by this application can easily think of changes or substitutions, which should all be covered within the protection scope of this application.
Claims
1. A primitive clipping method, characterized in that: include: Obtaining a primitive and at least one clipping surface corresponding to the primitive; In the clipping process corresponding to each clipping plane executed in a preset order, a clipping parameter is determined based on a positional relationship between the at least one clipping plane and the current primitive; The current primitive is the primitive or a result of at least one clipping of the primitive; When the clipping parameter indicates that there is no clipping plane that needs to clip the current primitive, determining the current primitive as a clipped primitive; Wherein, the clipping parameters include vertex clipping masks corresponding to each vertex in the current primitive; the vertex clipping mask includes vertex clipping mask bits corresponding to each clipping surface; The method further includes: when the vertex is a new vertex and the new vertex meets a preset requirement, setting the vertex clipping mask bit of the clipping plane corresponding to the new vertex to a third parameter characterizing that the new vertex is within the clipping plane; The new vertex is a vertex obtained by clipping the primitive based on a historical clipping surface that has undergone a clipping process; the preset requirement includes any one of the following: The clipping surface corresponding to the new vertex is the historical clipping surface; The vertex clipping mask bit of the edge vertex of the primitive edge corresponding to the new vertex is set to the third parameter; the primitive edge is the edge in the primitive before the primitive is clipped based on the historical clipping plane.
2. The primitive clipping method according to claim 1, characterized in that: The clipping parameters include a primitive clipping mask; and determining the clipping parameters based on a positional relationship between the at least one clipping plane and the current primitive includes: Determine a vertex clipping mask for each vertex in the current primitive based on a positional relationship between the at least one clipping plane and each vertex in the current primitive; The primitive clipping mask is determined according to the vertex clipping masks of each vertex in the current primitive.
3. The primitive clipping method according to claim 2, characterized in that: The determining of the vertex clipping mask of each vertex in the current primitive based on the positional relationship between the at least one clipping plane and each vertex in the current primitive comprises: Determine the vertex clipping mask bit corresponding to each clipping surface according to the positional relationship between each clipping surface and the vertex; the vertex clipping mask bit indicates whether the vertex is outside the clipping surface; The vertex clipping mask of the vertex is determined according to the vertex clipping mask bit corresponding to each of the clipping planes.
4. The primitive clipping method according to claim 3, characterized in that: The primitive clipping mask includes primitive clipping mask bits; The determining the primitive clipping mask according to the vertex clipping mask of each vertex in the current primitive comprises: Determine the primitive clipping mask bit corresponding to each clipping surface according to the vertex clipping mask bit corresponding to each clipping surface; The primitive clipping mask is determined according to the primitive clipping mask bit corresponding to each of the clipping planes.
5. The primitive clipping method according to claim 4, characterized in that: Determining the primitive clipping mask bit corresponding to each clipping surface according to the vertex clipping mask bit corresponding to each clipping surface includes: In the case where there is a vertex clipping mask bit indicating that the vertex is outside the clipping plane, setting the primitive clipping mask bit to a first parameter indicating that the clipping plane needs to clip the current primitive; In the absence of a vertex clipping mask bit indicating that the vertex is outside the clipping plane, the primitive clipping mask bit is set to a second parameter indicating that the clipping plane does not need to clip the current primitive.
6. The primitive clipping method according to claim 1, characterized in that: The clipping parameters include a primitive clipping mask; the primitive clipping mask includes a primitive clipping mask bit corresponding to each clipping plane; when the clipping parameters indicate that there is no clipping plane that needs to clip the current primitive, determining the current primitive as a clipped primitive includes: When each of the primitive clipping mask bits indicates that the corresponding clipping plane does not need to clip the current primitive, the current primitive is determined as the clipped primitive.
7. The primitive clipping method according to claim 3, characterized in that: The step of determining the vertex clipping mask bit corresponding to each clipping surface according to the positional relationship between each clipping surface and the vertex comprises: When the vertex is a new vertex and the new vertex does not meet a preset requirement, a vertex clipping mask bit corresponding to the clipping plane is determined based on a distance from the new vertex to a clipping plane corresponding to the new vertex.
8. The primitive clipping method according to any one of claims 1 to 7, characterized in that: The clipping parameters include a count value of each clipping surface; The determining of the clipping parameters based on the positional relationship between the at least one clipping plane and the current primitive includes: A count value of each of the at least one clipping planes is determined based on a positional relationship between each of the clipping planes and each vertex in the current primitive; the count value indicates whether the vertex exists outside the clipping plane.
9. The primitive clipping method according to claim 8, characterized in that: The count value includes a count sub-value; and determining the count value of each clipping surface based on the positional relationship between each clipping surface in the at least one clipping surface and each vertex in the current primitive includes: Determine a count sub-value corresponding to each vertex according to a positional relationship between each vertex and the clipping plane; the count sub-value indicates whether the vertex is outside the clipping plane or inside the clipping plane; The count value of the clipping surface is determined according to the count sub-values corresponding to the vertices.
10. The primitive clipping method according to claim 8, characterized in that: The step of determining the current primitive as a clipped primitive when the clipping parameter indicates that there is no clipping plane that needs to clip the current primitive comprises: When the count value of each clipping surface indicates that the vertex does not exist outside the corresponding clipping surface, the current primitive is determined as the clipped primitive.
11. The primitive clipping method according to any one of claims 1 to 7, characterized in that: The method further comprises: In a case where the clipping parameters indicate that there is a planned clipping plane that needs to clip the current primitive, the current primitive is clipped using the planned clipping plane.
12. A primitive cutting device, characterized in that: include: A data acquisition module, used to acquire a graphic element and at least one clipping surface corresponding to the graphic element; A parameter determination module, configured to determine a clipping parameter based on a positional relationship between the at least one clipping plane and a current primitive during a clipping process corresponding to each clipping plane executed in a preset order; The current primitive is the primitive or a result of at least one clipping of the primitive; A result determination module, configured to determine the current primitive as a clipped primitive when the clipping parameters indicate that there is no clipping surface that needs to clip the current primitive; wherein the clipping parameters include vertex clipping masks corresponding to each vertex in the current primitive; and the vertex clipping mask includes vertex clipping mask bits corresponding to each clipping surface; The result determination module is also used to set the vertex clipping mask bit of the clipping plane corresponding to the new vertex to a third parameter characterizing that the new vertex is within the clipping plane when the vertex is a new vertex and the new vertex meets preset requirements; the new vertex is a vertex obtained after clipping the primitive based on a historical clipping plane that has undergone a clipping process; the preset requirements include any one of the following: the clipping plane corresponding to the new vertex is the historical clipping plane; the vertex clipping mask bit of the edge vertex of the primitive edge corresponding to the new vertex is set to the third parameter; the primitive edge is an edge in the primitive before the primitive is clipped based on the historical clipping plane.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the primitive clipping method according to any one of claims 1 to 11 is implemented.
14. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the primitive clipping method according to any one of claims 1 to 11 is implemented.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the primitive clipping method according to any one of claims 1 to 11 is implemented.
Citation Information
Patent Citations
Clipping method and clipping module with effective area and multiplex function in embedded GPU (Graphics Processing Unit)
CN103400338A
Device and method for entity clipping during graphic processing unit (GPU) graphic processing
CN104200425A