OpenGL (Open Graphics Library) dotted line function implementation method and system based on shader

Through the shader-based method, the problem of lack of flexibility and universality in the implementation method of OpenGL dotted line function is solved, and the dotted line effect with strong versatility and high flexibility is achieved when the GPU hardware does not support the dotted line drawing function.

CN120182458AActive Publication Date: 2025-06-20WUHAN LINGJIU MICROELECTRONICS CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202510647040.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-20
Publication Date
2025-06-20
Estimated Expiration
2045-05-20

AI Technical Summary

Technical Problem

The existing OpenGL dotted line function implementation method lacks flexibility and versatility, especially when the GPU hardware does not support the dotted line drawing function.

Method used

Using a shader-based method, the graphics driver rendering context data is received through the OpenGL standard interface, and the opening status and element type of the dotted line drawing function are retrieved and judged. If it is enabled, the coloring program is obtained and modified to declare Uniform variables, and the corresponding rendering command buffer instructions are generated to achieve the dotted line effect.

Benefits of technology

It realizes the dotted line effect with strong versatility and flexibility when the GPU hardware does not support the dotted line drawing function, meeting the functional needs of the glLineStipple interface in OpenGL.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120182458A_ABST
    Figure CN120182458A_ABST
Patent Text Reader

Abstract

The invention is suitable for the technical field of GPU, and provides a shader-based OpenGL dotted line function implementation method and system. The method is applied to OpenGL graph driving, and is used for processing glLineStille incoming data and generating an instruction stream, and guiding GPU hardware to render a dotted line conforming to an OpenGL standard specification. Due to the fact that a GPU manufacturer does not disclose a method for achieving the dotted line function in the market at present, the method and system for achieving the dotted line function based on the shader can meet the function requirement of a glLineStille interface in an OpenGL, are used for guiding development of a graph driving program, do not require GPU hardware to have a dotted line drawing function, and are high in flexibility and wide in universality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of GPUs, and particularly relates to a method and system for implementing an OpenGL dotted line function based on a shader. Background Art

[0002] OpenGL (Open Graphics Library) is a software interface for graphics hardware and can be used to create interactive 3D applications. It is a popular 3D graphics standard. GPU manufacturers that support OpenGL need to provide not only GPU hardware but also graphics driver software that implements OpenGL functions so that OpenGL applications can complete rendering tasks by calling GPU hardware through the driver. The quality of OpenGL driver code is directly related to whether the performance of GPU hardware can be fully utilized.

[0003] A dotted line refers to a discontinuous line drawn with points or short lines and is often used in visualization scenarios such as maps and radar. Dotted line rendering is often required in the field of graphics rendering. In OpenGL, the glLineStipple standard interface function (glLineStipple is a function in OpenGL mainly used to create a dotted line style segment) can be used to pass in relevant parameters, and then subsequent line primitives can be drawn to achieve the dotted line effect.

[0004] For GPU manufacturers, when implementing the dotted line function, the OpenGL standard specification does not stipulate what method GPU manufacturers should use to achieve the dotted line rendering effect, but stipulates the requirements that the dotted line style needs to meet. It is up to GPU manufacturers to decide which technical route to choose to implement the dotted line function. The implementation of the dotted line function in OpenGL is closely related to the specific GPU hardware architecture. GPUs from different manufacturers have differences in architecture, instruction set, memory management, etc., and the ways to implement the dotted line function will also be different. Currently, no GPU manufacturer has publicly disclosed the underlying implementation method of the dotted line function in OpenGL.

[0005] Developers generally use the glLineStipple interface function provided by OpenGL to use the dotted line function, which requires GPU hardware support. If the GPU hardware does not support the dotted line drawing function, an error will occur. Therefore, the current method still has certain deficiencies in flexibility and generality. Summary of the Invention

[0006] In view of the above problems, the purpose of the present invention is to provide a method for implementing an OpenGL dotted line function based on a shader, aiming to solve the technical problem that the existing method for implementing the dotted line function still has certain deficiencies in flexibility and generality.

[0007] The present invention adopts the following technical solutions: On the one hand, the method for implementing the OpenGL dotted line function based on a shader is characterized in that the method comprises the following steps: Step S1: Receive the graphics driver rendering context data through the OpenGL standard interface; Step S2: Retrieve the graphics driver rendering context data, and judge whether the dotted line drawing function is enabled and whether the primitive to be drawn currently is a line type primitive; Step S3: If the dotted line drawing function is enabled and the current primitive type to be drawn is a line type primitive, further obtain the shader program called for the current drawing, and query whether the Uniform variable C is declared in the shader program; Step S4: If the Uniform variable C is not declared, modify the shader program to insert code or instructions to declare the Uniform variable C, and then declare two more Uniform variables, denoted as Uniform variable A and Uniform variable B respectively; Step S5: Generate instructions for respectively passing the factor data, the pattern data and the constant data "1" to the Uniform variable A, the Uniform variable B and the Uniform variable C in the shader program one by one, and write them into the rendering command buffer; Step S6: If the dotted line drawing function is not enabled, or the current primitive type to be drawn is not a line type primitive, also obtain the shader program called for the current drawing, and query whether the Uniform variable C is declared in the shader program; Step S7: If the Uniform variable C is declared, generate an instruction for passing the constant data "0" to the Uniform variable C in the shader program, and write it into the rendering command buffer; Step S8: Submit the instructions in the rendering command buffer and the shader program to the GPU hardware for rendering.

[0008] On the other hand, the system for implementing the OpenGL dotted line function based on a shader includes: A data receiving unit for receiving the graphics driver rendering context data through the OpenGL standard interface; A retrieval and judgment unit for retrieving the graphics driver rendering context data and judging whether the dotted line drawing function is enabled and whether the primitive to be drawn currently is a line type primitive; A first query unit for, if the dotted line drawing function is enabled and the current primitive type to be drawn is a line type primitive, further obtaining the shader program called for the current drawing and querying whether the Uniform variable C is declared in the shader program; A program modification unit, which is used to modify the shader insertion code or instructions to declare a Uniform variable C and then declare two more Uniform variables, denoted as Uniform variable A and Uniform variable B respectively if the Uniform variable C is not declared; A first instruction writing unit, which is used to generate instructions for respectively and correspondingly passing factor data, pattern data, and constant data "1" to Uniform variable A, Uniform variable B, and Uniform variable C in the shader, and write them into the rendering command buffer; A second query unit, which is used to also obtain the shader called by the current drawing and query whether the Uniform variable C is declared in the shader if the dotted line drawing function is not enabled or the current drawing primitive type is not a line type primitive; A second instruction writing unit, which is used to generate an instruction for passing constant data "0" to the Uniform variable C in the shader and write it into the rendering command buffer if the Uniform variable C is declared; A rendering unit, which is used to submit the instructions and the shader in the rendering command buffer to the GPU hardware for rendering.

[0009] The beneficial effects of the present invention are as follows: The method of the present invention is a pure software implementation method based on the driver source code, which can meet the functional requirements of the glLineStipple interface in OpenGL and can be used to guide the development of graphics driver programs. The present invention has strong versatility and can implement the dotted line effect when the GPU hardware does not support the dotted line drawing function, without requiring the GPU hardware to have the dotted line drawing function, so it has strong flexibility and wide versatility. Description of the Drawings

[0010] Figure 1 is a flowchart of the method for implementing the OpenGL dotted line function based on the shader provided by the embodiment of the present invention; Figure 2 is a structural block diagram of the system for implementing the OpenGL dotted line function based on the shader provided by the embodiment of the present invention. Detailed Embodiments

[0011] In order to make the objectives, technical solutions, and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0012] In order to illustrate the technical solutions described in the present invention, the following will be described through specific embodiments.

[0013] Embodiment 1: AsFigure 1 As shown in Figure 1 , the method for implementing the OpenGL dotted line function based on a shader provided in this embodiment includes the following steps: Step S1: Receive the graphics driver rendering context data through the OpenGL standard interface.

[0014] For a complete and reasonable OpenGL program, before calling the graphics driver to implement this method, first, a certain amount of rendering support data must have been passed into the graphics driver by calling the OpenGL standard interface. The data recorded in the graphics driver rendering context is sufficient to support the implementation of this method. Therefore, this step first needs to obtain the graphics driver rendering context data.

[0015] Step S2: Retrieve the graphics driver rendering context data and determine whether the dotted line drawing function is enabled and whether the primitive to be drawn currently is a line type primitive.

[0016] In this step, by retrieving the graphics driver rendering context data, first determine whether the dotted line drawing function has been enabled. GL_LINE_STIPPLE is a mode in OpenGL used to control the drawing style of line segments. GL_LINE_STIPPLE uses a 16-bit pattern to control the drawing of line segments. This pattern will loop continuously, thereby determining which parts of the line segment need to be drawn and which parts to skip.

[0017] In OpenGL, the function glEnable(GL_LINE_STIPPLE) represents enabling the dotted line drawing mode for line segments; glDisable(GL_LINE_STIPPLE) represents disabling the dotted line mode, that is, turning off the dotted line drawing mode for line segments. glLineStipple(factor, pattern) is used to set the drawing mode of the dotted line, where factor is an integer used to specify the number of times each pattern bit is repeated; pattern is a 16-bit unsigned integer representing the drawing pattern of the dotted line. Each bit in the pattern corresponds to a pixel, 1 means draw, and 0 means skip. When using it, it is necessary to first enable the dotted line mode through glEnable(GL_LINE_STIPPLE). After the drawing is completed, glDisable(GL_LINE_STIPPLE) can be used to turn off this mode to avoid affecting subsequent drawings. Therefore, in this step, in OpenGL, the dotted line drawing function is controlled to be enabled by calling glEnable(GL_LINE_STIPPLE). Additionally, the dotted line drawing function is also controlled to be turned off by calling glDisable(GL_LINE_STIPPLE).

[0018] When drawing primitive graphics, it is controlled by specifying the primitive type in the parameters of the drawing function (such as glDrawArrays). Among them, the line type primitives include GL_LINES, GL_LINE_LOOP, and GL_LINE_STRIP, which are three modes used to specify how to interpret vertex data as line segment primitives. The GL_LINES mode takes every two vertices as a group and connects them into a line segment. The GL_LINE_LOOP mode connects all vertices in sequence into a closed broken line. The GL_LINE_STRIP mode connects all vertices in sequence into a continuous broken line.

[0019] Therefore, it is possible to determine whether the currently drawn primitive is a line type primitive by retrieving the graphics driver rendering context data.

[0020] Step S3: If the dotted line drawing function is enabled and the currently drawn primitive type is a line type primitive, then further obtain the shader program called by the current drawing and query whether the Uniform variable C is declared in the shader program.

[0021] In glsl (OpenGL Shading Language), the Uniform variable is a special type of global variable. The Uniform variable is used to transfer data between the shader programs on the CPU side and the GPU side. These variables remain unchanged during the processing of the entire primitive (such as triangles, line segments, etc.), that is, for all vertices or fragments of a primitive, the value of the Uniform variable is the same.

[0022] The role of the Uniform variable C in this step is to receive the data passed in during the subsequent operations of the method of the present invention and affect whether the discard operation in the subsequent steps is executed. Here, the "C" in the Uniform variable C only represents this variable. In theory, the more complex the variable naming, the better, to avoid naming conflicts with the variables already declared in the shader program and prevent unpredictable results caused by naming conflicts.

[0023] Therefore, in this step, the shader program called by the current drawing is retrieved from the graphics driver rendering context data, and it is queried whether the Uniform variable C is declared in the shader program.

[0024] Step S4: If the Uniform variable C is not declared, modify the shader program to insert code or instructions to declare the Uniform variable C, and then declare two more Uniform variables, denoted as Uniform variable A and Uniform variable B respectively.

[0025] If the Uniform variable C is not declared, it is necessary to modify the shader program to insert code or instructions for declaration.

[0026] Since different GPU manufacturers have different OpenGL implementation codes, the current shader program queried in this step may be in the form of GLSL source code or the intermediate language form specific to the manufacturer. If the current shader program uses the source code form of the high-level shader language GLSL, GLSL code is inserted when modifying the shader program; if the current shader program uses the intermediate language form of the manufacturer, the content inserted when modifying the shader program is in the form of instructions.

[0027] Taking the insertion of code in the form of GLSL source code as an example, the process is as follows: S41. Insert a code segment declaring Uniform variables A, Uniform variable B, and Uniform variable C before the main function of the shader program.

[0028] For example, first insert the code segment "uniform int A, B, C;" declaring Uniform variables A, Uniform variable B, and Uniform variable C before the main function in the fragment shader program.

[0029] S42. Insert a code segment for filtering and discarding fragments in the shader in the main function of the shader program. Specifically: add the x and y coordinates of the current fragment, then take the modulus with 16×A, and store the result in the integer variable n; perform a bitwise AND operation on Uniform variable B and the result of shifting 1 left by ceil(n / A) bits. If the result is 0 and C is 1, discard the current fragment; where ceil(n / A) represents rounding up the result of n / A.

[0030] Then insert the code segment in the main function: "int n = mod(gl_FragCoord.y + gl_FragCoord.x, 16×A);\n if(B & (1<<ceil(n / A)) == 0 && C==1)discard;"

[0031] Among them, "mod" is a common modulo operation function provided by the GLSL language; "gl_FragCoord" is a variable built into the GLSL syntax to describe the fragment position, and its x and y components represent the coordinates in the x and y directions respectively; 16×A is a constant, where A is the aforementioned integer Uniform variable A; "\n" represents the line break operator in the code syntax. Therefore, mod(gl_FragCoord.y + gl_FragCoord.x, 16×A) means adding the x and y coordinates of the previous fragment and then taking the modulo of 16×A, and storing the result in the integer variable n. 1<<ceil(n / A)) is a bitwise operation, where "<<" represents a left shift, and "ceil" is a common ceiling operation function provided by the GLSL language; B & (1<<ceil(n / A)) is a bitwise AND operation, and its function is to check whether a specific bit of B is 1. "discard" is a common function provided by the GLSL language for discarding fragments, that is, this fragment will not be rendered to the screen. Therefore, the if statement will check whether a specific bit of B is 0 and whether C is equal to 1. If both of these conditions are met, the discard statement will be executed.

[0032] The function implemented by the inserted code is to calculate based on the input parameters Uniform variables A, B, and C, and determine whether to discard the currently processed fragment according to the calculation result, so as to achieve the transparent effect of the partial area in the dashed line.

[0033] Step S5: Generate instructions that respectively and one-to-one pass the factor data, pattern data, and constant data "1" to the Uniform variable A, Uniform variable B, and Uniform variable C in the shader program, and write them into the rendering command buffer.

[0034] In this step, the factor data and pattern data are provided by the parameters factor and pattern in the OpenGL standard interface glLineStipple. The application calls glLineStipple to pass the data to the graphics driver through the parameters, and the graphics driver stores the data in the rendering context. When this step is executed, the factor and pattern data are obtained from the rendering context. The OpenGL driver first constructs a command buffer according to the rendering context, and then submits the command buffer to the GPU hardware for drawing, that is, finally execute step S8.

[0035] Step S6: If the dashed line drawing function is not enabled, or the current primitive type being drawn is not a line type primitive, then also obtain the shader program called by the current drawing, and query whether the Uniform variable C is declared in the shader program.

[0036] Step S7: If the Uniform variable C is declared, generate an instruction to pass the constant data "0" to the Uniform variable C in the shader program and write it into the render command buffer.

[0037] The aforementioned steps S3 - S5 are for the case where dotted lines need to be drawn. If the dotted line drawing function is not required, or the current primitive type being drawn is not a line type primitive, first obtain the shader program called for the current drawing and query whether the Uniform variable C is declared in the shader program. If not declared, directly enter step S8 for normal rendering. If the Uniform variable C is declared, generate an instruction to pass the constant data "0" to the Uniform variable C in the current shader program and write it into the render command buffer, and then execute step S8.

[0038] Step S8: Submit the instructions in the render command buffer and the shader program to the GPU hardware for rendering.

[0039] It should be noted that the method for implementing the dotted line function provided by the present invention is used to construct the OpenGL graphics driver, takes effect before the graphics driver submits the render instructions to the GPU hardware, and the dotted line state, shader state, and primitive type state cannot be modified between the time when this method takes effect and the time of submitting the render instructions to the GPU hardware.

[0040] The OpenGL application will call the standard interface functions provided by the GPU graphics driver during operation and pass the data required for rendering to the interface functions. The graphics driver collects and processes the render data and guides the GPU hardware to perform the rendering work. The method for implementing the dotted line function provided by the present invention is used to guide the writing of the OpenGL graphics driver, process the data passed to glLineStipple, generate an instruction stream, and guide the GPU hardware to render dotted lines that conform to the OpenGL standard specification.

[0041] Embodiment 2: As Figure 2 shown, the shader - based OpenGL dotted line function implementation system provided in this embodiment includes: A data receiving unit 1, configured to receive the graphics driver render context data through the OpenGL standard interface; A retrieval and judgment unit 2, configured to retrieve the graphics driver render context data and judge whether to enable the dotted line drawing function and whether the current primitive to be drawn is a line type primitive; A first query unit 3, configured to, if the dotted line drawing function is enabled and the current primitive type being drawn is a line type primitive, further obtain the shader program called for the current drawing and query whether the Uniform variable C is declared in the shader program; Program modification unit 4, which is used to modify the shading program to insert code or instructions to declare Uniform variable C and then declare two more Uniform variables, denoted as Uniform variable A and Uniform variable B, if Uniform variable C is not declared; First instruction writing unit 5, which is used to generate instructions for respectively passing factor data, pattern data, and constant data "1" to Uniform variable A, Uniform variable B, and Uniform variable C in the shading program one by one, and write them into the rendering command buffer; Second query unit 6, which is used to also obtain the shading program called by the current drawing, and query whether Uniform variable C is declared in the shading program if the dotted line drawing function is not enabled or the current drawing primitive type is not a line type primitive; Second instruction writing unit 7, which is used to generate an instruction for passing constant data "0" to Uniform variable C in the shading program and write it into the rendering command buffer if Uniform variable C is declared; Rendering unit 8, which is used to submit the instructions and the shading program in the rendering command buffer to the GPU hardware for rendering.

[0042] In the retrieval and judgment unit, in OpenGL, the dotted line drawing function is controlled to be enabled by calling glEnable(GL_LINE_STIPPLE), and the dotted line drawing function is controlled to be disabled by calling glDisable(GL_LINE_STIPPLE). In the program modification unit, if the current shading program uses the source code form of the high-level shading language glsl, glsl code is inserted when modifying the shading program; if the current shading program uses the intermediate language form of the manufacturer, the inserted content form is an instruction.

[0043] The program modification unit includes: Declaration module, which is used to insert a code segment for declaring Uniform variable A, Uniform variable B, and Uniform variable C before the main function of the shading program; Screening and discarding module, which is used to insert a code segment for screening and discarding fragments in the shader in the main function of the shading program. Specifically: add the x and y coordinates of the current fragment, then take the modulus of 16×A, and store the result in the integer variable n; perform a bitwise AND operation on Uniform variable B and the result of shifting 1 left by ceil(n / A) bits. If the result is 0 and C is 1, discard the current fragment; where ceil(n / A) represents rounding up the result of n / A.

[0044] Each functional unit in this system correspondingly implements steps S1 - S8 in Embodiment 1, and the specific implementation processes of each functional unit will not be elaborated here.

[0045] The present invention introduces a Uniform variable C to receive the data passed in subsequent operations, specifically sets up glsl built - in variables and functions to implement the dotted - line algorithm, and stipulates that the algorithm is implemented at a specified position in the fragment shader. For the glsl source code, that is, insert the code segment "int n = mod(gl_FragCoord.y+gl_FragCoord.x, 16×A);\n if(B &(1<<ceil(n / A)) == 0 && C==1)discard;" Moreover, the shading program and the command buffer are reconstructed to implement the dotted - line drawing function in the graphics driver, and the supporting GPU hardware only needs to support the solid - line drawing function.

[0046] In summary, the present invention provides a method and system for implementing a dotted - line function, which acts on the OpenGL graphics driver, is used to process the data passed by glLineStipple and generate an instruction stream to guide the GPU hardware to render a dotted line that conforms to the OpenGL standard specification. Currently, no GPU manufacturer on the market has publicly disclosed a method for implementing the dotted - line function. The present invention proposes a method and system for implementing a dotted - line function based on a shader, which can meet the functional requirements of the glLineStipple interface in OpenGL, is used to guide the development of the graphics driver program, and does not require the GPU hardware to have the dotted - line drawing function, so it has strong flexibility and wide generality.

[0047] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.

Claims

1. A method for implementing the OpenGL dotted line function based on a shader, characterized in that: The method comprises the following steps: Step S1, receiving graphics driver rendering context data through the OpenGL standard interface; Step S2, retrieving the graphics driver rendering context data, determining whether the dotted line drawing function is enabled and whether the primitive currently to be drawn is a line type primitive; Step S3: if the dotted line drawing function is enabled and the current drawing primitive type is a line type primitive, then further obtain the shader program called by the current drawing, and check whether the uniform variable C is declared in the shader program; Step S4: if the uniform variable C is not declared, modify the shader program to insert code or instructions to declare the uniform variable C, and declare two more uniform variables, which are respectively recorded as uniform variable A and uniform variable B; Step S5, generating instructions for inputting factor data, pattern data and constant data "1" into uniform variables A, uniform variables B and uniform variables C in the shading program in a one-to-one correspondence, and writing them into the rendering command buffer; Step S6: If the dotted line drawing function is not enabled, or the current drawing primitive type is not a line type primitive, the shader program called by the current drawing is also obtained to check whether the uniform variable C is declared in the shader program; Step S7: if the uniform variable C is declared, an instruction is generated to pass constant data "0" to the uniform variable C in the shading program and write it into the rendering command buffer; Step S8: Submit the instructions and shader program in the rendering command buffer to the GPU hardware for rendering.

2. The method for implementing the OpenGL dotted line function based on a shader as claimed in claim 1, characterized in that: In step S2, in OpenGL, the dashed line drawing function is enabled by calling glEnable(GL_LINE_STIPPLE), and the dashed line drawing function is disabled by calling glDisable(GL_LINE_STIPPLE).

3. The method for implementing the OpenGL dotted line function based on a shader as claimed in claim 1, characterized in that: In step S4, if the current shading program uses the source code form of the high-level shader language glsl, the glsl code is inserted when the shading program is modified; if the current shading program uses the manufacturer's intermediate language form, the content inserted when modifying the shading program is in the form of instructions.

4. The method for implementing the OpenGL dotted line function based on a shader as claimed in claim 3, characterized in that: In step S4, when inserted in the form of glsl code, the specific process is as follows: Insert the code segments declaring uniform variables A, B, and C before the main function of the shader program; Insert the code segment for filtering and discarding fragments in the shader into the main function of the shading program. Specifically, add the x and y coordinates of the current fragment, then take the modulus of 16×A, and store the result in the integer variable n; perform a bitwise AND operation on the uniform variable B and 1 after shifting it left by ceil(n / A) bits. If the result is 0 and C is 1, discard the current fragment; ceil(n / A) means rounding up the result of n / A.

5. A shader-based OpenGL dotted line function implementation system, characterized in that: The system comprises: A data receiving unit, used for receiving graphics driver rendering context data through an OpenGL standard interface; A search and judgment unit is used to retrieve the graphics driver rendering context data, determine whether the dotted line drawing function is turned on and whether the primitive currently required to be drawn is a line type primitive; The first query unit is used to further obtain the shader program called by the current drawing if the dashed line drawing function is enabled and the current drawing primitive type is a line type primitive, and query whether the uniform variable C is declared in the shader program; A program modification unit is used for modifying the shading program to insert codes or instructions to declare the uniform variable C if the uniform variable C is not declared, and further declare two uniform variables, which are respectively recorded as uniform variable A and uniform variable B; A first instruction writing unit is used to generate instructions for inputting factor data, pattern data and constant data "1" into uniform variables A, uniform variables B and uniform variables C in the shading program in a one-to-one correspondence, and write them into a rendering command buffer; The second query unit is used to obtain the shader program called by the current drawing if the dashed line drawing function is not enabled or the current drawing primitive type is not a line type primitive, and query whether the uniform variable C is declared in the shader program; The second instruction writing unit is used for generating an instruction for transferring constant data "0" to the uniform variable C in the shader program if the uniform variable C is declared, and writing the instruction into the rendering command buffer; The rendering unit is used to submit the instructions and shader programs in the rendering command buffer to the GPU hardware for rendering.

6. The shader-based OpenGL dotted line function implementation system as claimed in claim 5, characterized in that: In the retrieval judgment unit, in OpenGL, the dashed line drawing function is turned on by calling glEnable(GL_LINE_STIPPLE) and the dashed line drawing function is turned off by calling glDisable(GL_LINE_STIPPLE).

7. The shader-based OpenGL dotted line function implementation system as claimed in claim 6, characterized in that: In the program modification unit, if the current shading program uses the source code form of the high-level shader language glsl, the glsl code is inserted when the shading program is modified; if the current shading program uses the manufacturer's intermediate language form, the content inserted when modifying the shading program is in the form of instructions.

8. The shader-based OpenGL dotted line function implementation system as claimed in claim 7, characterized in that: The program modification unit comprises: A declaration module is used to insert a code segment for declaring uniform variables A, uniform variables B, and uniform variables C before the main function of the shader program; The filtering and discarding module is used to insert a code segment for filtering and discarding fragments in the shader into the main function of the shading program. Specifically, the x and y coordinates of the current fragment are added, and then modulo 16×A, and the result is stored in the integer variable n; the uniform variable B is shifted left by 1 by ceil(n / A) bits, and the result is performed a bitwise AND operation. If the result is 0 and C is 1, the current fragment is discarded; where ceil(n / A) means rounding up the result of n / A.

Citation Information

Patent Citations

  • Hierarchical Z-Culling (HiZ) Optimization for Texture-Dependent Discard Operations

    CN109564700A

  • Primitive shader

    CN109690629A

  • Method and system for drawing primitives based on OpenGL ES2.0

    CN110543620A

  • Method for realizing fixed pipeline function in programmable pipeline GPU (Graphics Processing Unit)

    CN118154759A

  • Usage semantics

    US20040164987A1