Graph mask method, system and device based on OpenGL SC and medium
By using template testing functions and simplified algorithms in OpenGL SC, efficient graphics masking operations are achieved, solving the problems of large computing volume, low rendering performance and poor cross-platformity in the existing technology, and improving the performance and portability of graphics masking.
Patent Information
- Application Number
- CN202510092201.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-05-16
AI Technical Summary
The existing graphics masking methods have shortcomings in computing volume and rendering performance, and are poor in cross-platformity and portability.
The graphic masking method based on OpenGL SC is adopted, and masking operations are implemented at the hardware level through template testing functions, simplifying the masking algorithm, and implementing it based on OpenGL SC to improve portability.
Improve rendering efficiency, reduce implementation difficulty, and improve cross-platformity and portability of graphics masks.
Smart Images

Figure CN120014148A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of image processing, and in particular to a graphics masking method, system, device and medium based on OpenGL SC. Background Art
[0002] Graphics masking is a common technique in computer graphics. It can cover or hide certain areas in an image, thereby achieving selective display of the image. In practical applications, graphic masks are widely used in image editing, video synthesis, game special effects and other fields. For example, in image editing software, graphic masks can be used to modify or process specific areas of an image, such as adjusting brightness, contrast, color, etc., without affecting other areas; in video synthesis, graphic masks can overlay different video layers to achieve special effects synthesis; in games, graphic masks can be used to create realistic light and shadow effects, achieve scene transitions, etc.
[0003] At present, there are two main methods for implementing graphic masking: one is pixel-level masking, and the other is vector-graphics-based masking. Pixel-level masking requires assigning a transparency value to each pixel, and controlling the visibility of the pixel by setting different transparencies. This method is highly flexible, but has a large amount of calculation and low rendering performance. Vector-graphics-based masking uses vector graphics (such as polygons, Bezier curves, etc.) to define the mask area. Compared with pixel-level masking, it has a smaller amount of calculation, but when dealing with complex mask shapes, the algorithm implementation is more complicated. In addition, existing graphic masking methods usually rely on specific graphics libraries or rendering engines, and have poor cross-platform and portability. Summary of the invention
[0004] To solve the above problems, the present invention provides a graphics masking method, system, device and medium based on OpenGL SC.
[0005] The first aspect of the present invention discloses a graphics masking method based on OpenGL SC, comprising:
[0006] receiving a mask generation request, wherein the mask generation request includes a mask type and a plurality of mask vertices;
[0007] Determine a target graphic according to the mask type and all the mask vertices;
[0008] According to the template test method of OpenGL SC, a template test is performed on the target graphics to set the template buffer in OpenGL SC;
[0009] Receive image data to be rendered, and render the image data according to the template buffer.
[0010] Furthermore, when the mask type is a rectangular mask, the step of determining the target graphic according to the mask type and all the mask vertices includes:
[0011] Determining the shape of the target graphic according to the mask type;
[0012] The position of the target graphic in the display interface is determined according to all the mask vertices.
[0013] Furthermore, when the mask type is a plane mask, the mask generation request further includes a clockwise direction; and according to the mask type and all the mask vertices, the step of determining the target graphic includes:
[0014] Determine a plane dividing line according to the mask type and all the mask vertices;
[0015] According to the clockwise direction, a figure formed by the plane dividing line and the boundary of the display interface is used as a target figure.
[0016] Furthermore, when the mask type is an irregular graphic mask, the mask generation request further includes a plurality of direction angles; wherein one mask vertex corresponds to one direction angle, and the direction angle represents the arc of a line between the mask vertex and its adjacent mask vertex;
[0017] And, according to the mask type and all the mask vertices, the step of determining the target graphic includes:
[0018] Determine a plurality of boundary line segments according to the mask type, all the mask vertices and the corresponding direction angles;
[0019] The figure composed of all boundary line segments is used as the target figure.
[0020] Furthermore, the mask generation request also includes a target graphic outer mask indication;
[0021] And, according to the template test method of OpenGL SC, the steps of performing a template test on the target graphics to set the template buffer in OpenGLSC include:
[0022] Initializing the template values corresponding to all pixels of the display interface in the template buffer to the first template value;
[0023] Performing a stencil test on pixels of a display interface including a target graphic according to the stencil test method:
[0024] If the test passes, the template values of all pixels that pass the test are set to the second template value;
[0025] If the test fails, the template value of the pixel that failed the test is kept as the initial first template value.
[0026] Further, the mask generation request also includes a target graphic internal mask indication;
[0027] And, according to the template test method of OpenGL SC, the steps of performing a template test on the target graphics to set the template buffer in OpenGLSC include:
[0028] Initializing the template values corresponding to all pixels of the display interface in the template buffer to the second template value;
[0029] Performing a stencil test on pixels of a display interface including a target graphic according to the stencil test method:
[0030] If the test passes, the template values of all pixels that pass the test are set to the first template value;
[0031] If the test fails, the template value of the pixel that fails the test is kept as the initial second template value.
[0032] Further, after the step of performing a template test on the target graphics according to the template test method of OpenGL SC to set the template buffer in OpenGL SC, the graphics masking method further includes:
[0033] Keeping all pixels of the display interface unchanged in the color buffer and the depth buffer;
[0034] Furthermore, the step of receiving the image data to be rendered and rendering the image data according to the template buffer comprises:
[0035] Image data to be rendered is received, and the image data is rendered according to the template buffer, the color buffer, and the depth buffer.
[0036] The second aspect of the present invention discloses a graphics mask system based on OpenGL SC, comprising:
[0037] A receiving module, configured to receive a mask generation request, wherein the mask generation request includes a mask type and a plurality of mask vertices;
[0038] A determination module, used for determining a target graphic according to the mask type and all the mask vertices;
[0039] The stencil test module is used to perform a stencil test on a target graphic according to a stencil test method of OpenGL SC to set a stencil buffer in OpenGL SC;
[0040] The rendering module is used to receive image data to be rendered and render the image data according to the template buffer.
[0041] The third aspect of the present invention discloses an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any OpenGL SC-based graphics masking method disclosed in the first aspect of the present invention when executing the computer program.
[0042] The fourth aspect of the present invention discloses a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any OpenGLSC-based graphics masking method disclosed in the first aspect of the present invention.
[0043] The present invention realizes mask operation at the hardware level by utilizing the template test function of OpenGL SC, avoids complex pixel-level calculations, and improves rendering efficiency. At the same time, by simplifying the mask algorithm, the difficulty of implementation is reduced, and based on the OpenGL SC implementation, it has good portability and can be easily integrated into different application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0045] Figure 1 It is a flowchart of a graphics masking method based on OpenGL SC disclosed in an embodiment of the present invention;
[0046] Figure 2 It is a structural schematic diagram of a graphics mask system based on OpenGL SC disclosed in an embodiment of the present invention;
[0047] Figure 3 It is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, or product end that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, devices, or product ends.
[0050] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0051] See also Figure 1 As shown, Figure 1 FIG. 1 is a flow chart of a graphics masking method based on OpenGL SC disclosed in an embodiment of the present invention. Figure 1 As shown, the OpenGL SC-based graphics masking method may include the following operations:
[0052] S101, receiving a mask generation request, where the mask generation request includes a mask type and a plurality of mask vertices;
[0053] In this optional embodiment, the mask generation request may be in JSON format, XML format, or any other structured format, which is not limited in the embodiment of the present invention. All mask vertices are arranged in order, and the mask vertices include coordinate information.
[0054] S102, determining a target graphic according to the mask type and all the mask vertices;
[0055] In this optional embodiment, the mask type may be a rectangular mask, a plane mask, an irregular graphic mask, etc., which is not limited by the embodiment of the present invention. An irregular graphic refers to a closed polygonal graphic, which may include arc segments. When the mask type is a rectangular mask, the portion outside the rectangular frame may be masked, and the portion inside the rectangular frame may be rendered normally; or the portion inside the rectangular frame may be masked, and the portion outside the rectangular frame may be rendered normally. When the mask type is a plane mask, the display interface is divided into two planes by a straight line determined by the mask vertices, one plane is masked, and the other plane is rendered normally. When the mask type is an irregular graphic mask, the portion outside the irregular graphic frame may be masked, and the portion inside the irregular graphic frame may be rendered normally; or the portion inside the irregular graphic frame may be masked, and the portion outside the irregular graphic frame may be rendered normally.
[0056] In an optional embodiment, when the mask type is a rectangular mask, the step of determining the target graphic according to the mask type and all the mask vertices includes:
[0057] Determining the shape of the target graphic according to the mask type;
[0058] The position of the target graphic in the display interface is determined according to all the mask vertices.
[0059] In this optional embodiment, the mask vertices refer to four vertices constituting a rectangle, which are arranged in a specific order, such as in the order of upper left, upper right, lower right, and lower left, or in a clockwise or counterclockwise order.
[0060] According to the mask vertices, the shape and position of the target graphic (ie, the rectangular mask) can be determined. By analyzing the coordinate information of the mask vertices, the specific position of the rectangle in the display interface can be determined and the width and height of the rectangle can be calculated.
[0061] It can be seen that this optional embodiment uses the information of mask type and mask vertex to quickly determine the key attributes of the target graphic, including shape and position, avoiding complex calculation and construction processes, reducing system overhead, and improving the efficiency of mask generation. At the same time, since a rectangle is a common and practical mask shape, this optional embodiment can meet the needs of a variety of practical application scenarios, has a wide range of applicability, enhances the flexibility and controllability of graphics rendering, and provides developers with a powerful tool to create rich and diverse graphics effects, improving the expressiveness and user experience of graphics applications.
[0062] In another optional embodiment, when the mask type is a plane mask, the mask generation request further includes a clockwise direction; and according to the mask type and all the mask vertices, the step of determining the target graphic includes:
[0063] Determine a plane dividing line according to the mask type and all the mask vertices;
[0064] According to the clockwise direction, a figure formed by the plane dividing line and the boundary of the display interface is used as a target figure.
[0065] In this optional embodiment, the mask vertex refers to the vertex constituting the plane dividing line. The plane dividing line is a straight line passing through the display interface, which divides the display interface into two parts. The mask vertex can be the intersection of the plane dividing line and the boundary of the display interface, or any two points on the plane dividing line.
[0066] The shape of the target graphic is determined by the plane dividing line and the boundary of the display interface. It can be a rectangle, triangle or trapezoid. The vertices of the target graphic include the intersection of the plane dividing line and the boundary of the display interface, and the corresponding corner points of the display interface.
[0067] It can be seen that this optional embodiment uses simple parameters to describe complex mask shapes, reduces data transmission and storage overhead, and can generate planar masks of various directions and positions to meet diverse mask requirements. In addition, by combining mask generation with the boundaries of the display interface, this optional embodiment can adapt to display devices of different sizes and resolutions, improving the applicability and compatibility of the mask.
[0068] In another optional embodiment, when the mask type is an irregular graphic mask, the mask generation request further includes a plurality of direction angles; wherein one mask vertex corresponds to one direction angle, and the direction angle represents the arc of a line between the mask vertex and its adjacent mask vertex;
[0069] And, according to the mask type and all the mask vertices, the step of determining the target graphic includes:
[0070] Determine a plurality of boundary line segments according to the mask type, all the mask vertices and the corresponding direction angles;
[0071] The figure composed of all boundary line segments is used as the target figure.
[0072] In this optional embodiment, the direction angle may include a straight line indication to indicate whether the line segment between a mask vertex and its adjacent mask vertex is a straight line, i.e., has no curvature. When the straight line indication indicates that the line segment between a mask vertex and its adjacent mask vertex is not a straight line, the direction angle may also include the center angle and the clockwise direction, or include information such as the coordinates of the center of the circle and the size of the radius to determine the shape and position of the arc. The center angle refers to the angle value of the center angle between the mask vertex and its adjacent mask vertex when they are located on a circle, and the clockwise direction indicates that the adjacent mask vertex is located on the circumference in the clockwise direction or counterclockwise direction of the mask vertex.
[0073] According to the mask vertices and their corresponding direction angles, the shape and position of the target figure (i.e., the irregular figure mask) can be determined. Specifically, all mask vertices are regarded as corner points of the irregular figure, and each boundary line segment is determined in turn according to their coordinate position and direction angle information to form a closed irregular figure, which is the target figure. The overall shape of the target figure is determined by the shape and arrangement order of all boundary line segments, while its position is determined by the coordinate range of the mask vertices.
[0074] It can be seen that this optional embodiment uses the least amount of data to represent complex mask shapes, reduces data redundancy and transmission overhead, and meets various complex and changing mask requirements.
[0075] S103, performing a stencil test on the target graphic according to the stencil test method of OpenGL SC to set a stencil buffer in OpenGL SC;
[0076] Stencil testing is a pixel operation technique in OpenGL SC, which can decide whether to update the contents of the color buffer and depth buffer based on the contents of the stencil buffer. The stencil test occurs after the depth test and before the fragment shader is executed.
[0077] The stencil buffer is a buffer similar to the color buffer and the depth buffer, which stores the stencil value of each pixel. The stencil value is an unsigned integer, usually 8 bits, that is, the stencil value of each pixel can be any integer between 0 and 255. The size of the stencil buffer is the same as that of the color buffer and the depth buffer, that is, each pixel corresponds to a stencil value.
[0078] During the template test, OpenGL SC compares the pixel's template value with the reference template value, and decides whether to write the fragment's color value to the color buffer based on the comparison result and the setting of the template function. If the template test passes, the fragment's color value will be written to the color buffer; otherwise, the fragment will be discarded and the content of the color buffer remains unchanged.
[0079] When drawing graphics, you can control the result of the template test by setting the template function and template value. The template function defines how to compare the template value of the current pixel with the reference template value. Common template functions include equal, not equal, greater than, less than, etc. The reference template value is a pre-set value and can be a constant.
[0080] In yet another optional embodiment, the mask generation request further includes a target graphic outer mask indication;
[0081] And, according to the template test method of OpenGL SC, the steps of performing a template test on the target graphics to set the template buffer in OpenGLSC include:
[0082] Initializing the template values corresponding to all pixels of the display interface in the template buffer to the first template value;
[0083] Performing a stencil test on pixels of a display interface including a target graphic according to the stencil test method:
[0084] If the test passes, the template values of all pixels that pass the test are set to the second template value;
[0085] If the test fails, the template value of the pixel that failed the test is kept as the initial first template value.
[0086] In this optional embodiment, the first template value is 0, the second template value is 1, the pixels corresponding to the target graphic all pass the test, and the pixels corresponding to the non-target graphic area all fail the test.
[0087] In this optional embodiment, the stencil values of all pixels can be initialized to the first stencil value through the glClearStencil and glClear functions. The first input parameter of the glStencilFunc function is passed to GL_ALWAYS to set all pixels to pass the test. The action of setting the template test to pass is to set the stencil value corresponding to the stencil buffer to the second stencil value after the test passes, and do not change the corresponding stencil value when the test fails. The test of the target graphics is completed by rendering the target graphics. When the test is completed, the stencil value corresponding to the pixels in the target graphics in the stencil buffer is the second stencil value, and the stencil value corresponding to the pixels outside the target graphics in the stencil buffer is the first stencil value, that is, the area outside the target graphics will be masked.
[0088] It can be seen that this optional embodiment can achieve a mask effect outside the target graphic by introducing a mask indication outside the target graphic, initializing the template values corresponding to all pixels of the display interface in the template buffer to the first template value, and then performing a template test on the pixels of the target graphic according to the template test method in which all pixels have passed the test. Specifically, for pixels that pass the test, that is, pixels within the target graphic, their template values are set to the second template value; for pixels that fail the test, that is, pixels outside the target graphic, their template values are maintained as the initial first template value. In this way, in subsequent image rendering, it can be decided whether to render the pixel based on its template value, thereby achieving a mask effect outside the target graphic. Compared with the traditional mask method based on the color buffer, the mask method based on the template buffer has higher flexibility and efficiency, can support more complex mask shapes and dynamically changing mask areas, and at the same time avoids frequent read and write operations on the color buffer, thereby improving rendering performance.
[0089] In yet another optional embodiment, the mask generation request further includes a target graphic intra-mask indication;
[0090] And, according to the template test method of OpenGL SC, the steps of performing a template test on the target graphics to set the template buffer in OpenGLSC include:
[0091] Initializing the template values corresponding to all pixels of the display interface in the template buffer to the second template value;
[0092] Performing a stencil test on pixels of a display interface including a target graphic according to the stencil test method:
[0093] If the test passes, the template values of all pixels that pass the test are set to the first template value;
[0094] If the test fails, the template value of the pixel that fails the test is kept as the initial second template value.
[0095] In this optional embodiment, the first template value is 0, the second template value is 1, the pixels corresponding to the target graphic all pass the test, and the pixels corresponding to the non-target graphic area all fail the test.
[0096] In this optional embodiment, the stencil values of all pixels can be initialized to the second stencil value through the glClearStencil and glClear functions. The first input parameter of the glStencilFunc function is passed to GL_ALWAYS to set all pixels to pass the test. The action of setting the template test to pass is to set the stencil value corresponding to the stencil buffer to the first stencil value after the test passes, and do not change the corresponding stencil value when the test fails. The test of the target graphics is completed by rendering the target graphics. When the test is completed, the stencil value corresponding to the pixels in the target graphics in the stencil buffer is the first stencil value, and the stencil value corresponding to the pixels outside the target graphics in the stencil buffer is the second stencil value, that is, the area within the target graphics will be masked.
[0097] It can be seen that this optional embodiment can achieve a mask effect within the target graphic by introducing a mask indication within the target graphic, initializing the template values corresponding to all pixels of the display interface in the template buffer to the second template value, and then performing a template test on the pixels of the target graphic according to the template test method in which all pixels have passed the test. Specifically, for pixels that pass the test, that is, pixels within the target graphic, their template values are set to the first template value; for pixels that fail the test, that is, pixels outside the target graphic, their template values are maintained as the initial second template value. In this way, in subsequent image rendering, it is possible to decide whether to render the pixel based on its template value, thereby achieving a mask effect within the target graphic.
[0098] S104: Receive image data to be rendered, and render the image data according to the template buffer.
[0099] In an optional embodiment, after the step of performing a stencil test on the target graphics according to the stencil test method of OpenGL SC to set the stencil buffer in OpenGL SC, the graphics masking method further comprises:
[0100] Keeping all pixels of the display interface unchanged in the color buffer and the depth buffer;
[0101] Furthermore, the step of receiving the image data to be rendered and rendering the image data according to the template buffer comprises:
[0102] Image data to be rendered is received, and the image data is rendered according to the template buffer, the color buffer, and the depth buffer.
[0103] The color buffer and depth buffer are two important buffers in OpenGL SC, which together with the template buffer constitute the frame buffer of OpenGL.
[0104] The color buffer is used to store the color information of each pixel, usually including four components: red, green, blue, and alpha (transparency). During the rendering process, the color value output by the fragment shader will be written to the color buffer and finally displayed on the screen. The size and format of the color buffer can be configured as needed, such as using different color formats such as RGB, RGBA, BGR, BGRA, and 8-bit, 16-bit, or 32-bit color depth.
[0105] The depth buffer is used to store the depth information of each pixel, that is, the distance of the pixel from the observer. In the rendering of 3D graphics, the depth information is used to determine the occlusion relationship and visibility of objects. When multiple objects overlap, the object with a smaller depth value will occlude the object with a larger depth value. The depth buffer usually uses 16-bit or 24-bit floating point numbers to represent the depth value, which can provide enough accuracy to handle complex 3D scenes.
[0106] It can be seen that this optional embodiment can achieve a more flexible and accurate graphic masking effect by keeping the color buffer and the depth buffer unchanged after the template test, and then considering the template buffer, the color buffer and the depth buffer at the same time when rendering the image data. Specifically, the template buffer is used to control the visibility of pixels and determine which pixels need to be rendered; the color buffer is used to save the color information of existing objects in the current scene to ensure that the masking operation does not affect the color of other objects; the depth buffer is used to save the depth information of existing objects in the current scene to ensure that the masking operation does not affect the occlusion relationship of other objects. By comprehensively considering the information of these three buffers, the masking effect can be applied to a specific area without changing the current scene, thereby realizing local graphic editing and processing. This method can not only improve the accuracy and controllability of the mask, but also maximize the retention of the visual effect of the original scene, providing a more realistic and natural user experience.
[0107] See also Figure 2 As shown, Figure 2 FIG. 1 is a schematic diagram of a graphic mask system based on OpenGL SC disclosed in an embodiment of the present invention. Figure 2 As shown, the OpenGL SC-based graphics mask system includes:
[0108] A receiving module 201 is used to receive a mask generation request, wherein the mask generation request includes a mask type and a plurality of mask vertices;
[0109] A determination module 202, configured to determine a target graphic according to the mask type and all the mask vertices;
[0110] The stencil test module 203 is used to perform a stencil test on the target graphic according to the stencil test method of OpenGL SC to set the stencil buffer in OpenGL SC;
[0111] The rendering module 204 is used to receive image data to be rendered, and render the image data according to the template buffer.
[0112] For the specific definition of the graphics masking system based on OpenGL SC, please refer to the definition of the graphics masking method based on OpenGL SC above, which will not be repeated here. Each module in the above-mentioned graphics masking system based on OpenGL SC can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the electronic device in hardware format, or can be stored in the memory of the electronic device in software format, so that the processor can call the corresponding operations of each of the above modules.
[0113] It should be noted that, in order to highlight the innovative part of the present invention, the present embodiment does not introduce modules that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other modules in the present embodiment.
[0114] like Figure 3 As shown, the electronic device 1 provided by the present invention may include a memory 12, a processor 13 and a bus, and may also include a computer program stored in the memory 12 and executable on the processor 13, such as a graphics mask program based on OpenGLSC.
[0115] The memory 12 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 12 may be an internal storage unit of the electronic device 1, such as a mobile hard disk of the electronic device 1. In other embodiments, the memory 12 may also be an external storage device of the electronic device 1, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 1. Further, the memory 12 may also include both an internal storage unit of the electronic device 1 and an external storage device. The memory 12 may not only be used to store application software and various types of data installed in the electronic device 1, such as the code of the graphics mask based on OpenGL SC, etc., but may also be used to temporarily store data that has been output or is to be output.
[0116] In some embodiments, the processor 13 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 13 is the control core (Control Unit) of the electronic device 1, and uses various interfaces and lines to connect various components of the entire electronic device 1, and executes or executes programs or modules (such as graphics mask programs based on OpenGL SC, etc.) stored in the memory 12, and calls data stored in the memory 12 to execute various functions of the electronic device 1 and process data.
[0117] The processor 13 executes the operating system and various installed application programs of the electronic device 1. The processor 13 executes the application programs to implement the steps in the above-mentioned OpenGL SC-based graphics masking method.
[0118] Exemplarily, the computer program may be divided into one or more modules, which are stored in the memory 12 and executed by the processor 13 to complete the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device 1. For example, the computer program may be divided into a receiving module 201, a determining module 202, a template testing module 203, and a rendering module 204.
[0119] In summary, the present invention discloses a graphics masking method, system, device and medium based on OpenGL SC, which realizes masking operation at the hardware level by utilizing the template test function of OpenGL SC, avoids complex pixel-level calculations and improves rendering efficiency; at the same time, by simplifying the masking algorithm, the difficulty of implementation is reduced, and based on OpenGL SC implementation, it has good portability and can be easily integrated into different application scenarios. Therefore, the present invention effectively overcomes various shortcomings in the prior art and has high industrial utilization value.
[0120] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A graphics masking method based on OpenGL SC, characterized in that: The method comprises: receiving a mask generation request, wherein the mask generation request includes a mask type and a plurality of mask vertices; Determine a target graphic according to the mask type and all the mask vertices; According to the template test method of OpenGL SC, a template test is performed on the target graphics to set the template buffer in OpenGL SC; Receive image data to be rendered, and render the image data according to the template buffer.
2. The OpenGL SC-based graphics masking method according to claim 1, characterized in that: When the mask type is a rectangular mask, the step of determining the target graphic according to the mask type and all the mask vertices includes: Determining the shape of the target graphic according to the mask type; The position of the target graphic in the display interface is determined according to all the mask vertices.
3. The OpenGL SC-based graphics masking method according to claim 1, characterized in that: When the mask type is a plane mask, the mask generation request further includes a clockwise direction; and according to the mask type and all the mask vertices, the step of determining the target graphic includes: Determine a plane dividing line according to the mask type and all the mask vertices; According to the clockwise direction, a figure formed by the plane dividing line and the boundary of the display interface is used as a target figure.
4. The OpenGL SC-based graphics masking method according to claim 1, characterized in that: When the mask type is an irregular graphic mask, the mask generation request further includes a plurality of direction angles; wherein one mask vertex corresponds to one direction angle, and the direction angle represents the arc of a line between the mask vertex and its adjacent mask vertex; And, according to the mask type and all the mask vertices, the step of determining the target graphic includes: Determine a plurality of boundary line segments according to the mask type, all the mask vertices and the corresponding direction angles; The figure composed of all boundary line segments is used as the target figure.
5. The OpenGL SC-based graphics masking method according to claim 1, characterized in that: The mask generation request also includes a target graphic outer mask indication; And, according to the template test method of OpenGL SC, the steps of performing a template test on the target graphics to set the template buffer in OpenGL SC include: Initializing the template values corresponding to all pixels of the display interface in the template buffer to the first template value; Performing a stencil test on pixels of a display interface including a target graphic according to the stencil test method: If the test passes, the template values of all pixels that pass the test are set to the second template value; If the test fails, the template value of the pixel that failed the test is kept as the initial first template value.
6. The OpenGL SC-based graphics masking method according to claim 1, characterized in that: The mask generation request also includes a target graphic intra-mask indication; And, according to the template test method of OpenGL SC, the steps of performing a template test on the target graphics to set the template buffer in OpenGL SC include: Initializing the template values corresponding to all pixels of the display interface in the template buffer to the second template value; Performing a stencil test on pixels of a display interface including a target graphic according to the stencil test method: If the test passes, the template values of all pixels that pass the test are set to the first template value; If the test fails, the template value of the pixel that fails the test is kept as the initial second template value.
7. A graphics masking method based on OpenGL SC according to any one of claims 1 to 6, characterized in that: After the step of performing a template test on the target graphics according to the template test method of OpenGL SC to set the template buffer in OpenGL SC, the graphics masking method further includes: Keeping all pixels of the display interface unchanged in the color buffer and the depth buffer; Furthermore, the step of receiving the image data to be rendered and rendering the image data according to the template buffer comprises: Image data to be rendered is received, and the image data is rendered according to the template buffer, the color buffer, and the depth buffer.
8. A graphics mask system based on OpenGL SC, characterized in that: include: A receiving module, configured to receive a mask generation request, wherein the mask generation request includes a mask type and a plurality of mask vertices; A determination module, used for determining a target graphic according to the mask type and all the mask vertices; The stencil test module is used to perform a stencil test on a target graphic according to a stencil test method of OpenGL SC to set a stencil buffer in OpenGL SC; The rendering module is used to receive image data to be rendered and render the image data according to the template buffer.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the OpenGL SC-based graphics masking method according to any one of claims 1 to 7 are implemented.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the OpenGL SC-based graphics masking method as claimed in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Virtual reality ideological and political content self-adaptive generation method based on emotion calculation
CN121544785A
Virtual reality ideological and political content adaptive generation method based on affective computing
CN121544785B