A method and system for implementing OpenGL dotted line function based on shader

By declaring Uniform variable C in the OpenGL shader program and generating corresponding instructions, the flexibility and versatility of the OpenGL dotted line function is solved, and the dotted line rendering effect is achieved on different GPU hardware, which is suitable for the development of OpenGL graphics drivers.

CN120182458BActive Publication Date: 2025-08-26WUHAN LINGJIU MICROELECTRONICS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510647040.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-05-20
Publication Date
2025-08-26
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, it cannot effectively render the dotted line effect.

Method used

Through a shader-based method, the OpenGL coloring program declares the Uniform variable C and generates corresponding instructions to realize the dotted line function, including data reception, retrieval and judgment, program modification and instruction writing, realizing the dotted line drawing logic.

Benefits of technology

Without relying on GPU hardware to support the dotted line drawing function, flexible and widely applicable dotted line rendering effect is achieved, meeting the OpenGL standard specifications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120182458B_ABST
    Figure CN120182458B_ABST
Patent Text Reader

Abstract

The present invention is applicable to the field of GPU technology and provides a shader-based method and system for implementing OpenGL's dashed line functionality. The present invention operates on an OpenGL graphics driver, processing data passed to glLineStipple and generating an instruction stream to instruct the GPU hardware to render dashed lines that comply with OpenGL standards. Since no GPU manufacturers currently offer publicly available methods for implementing dashed line functionality, the shader-based method and system for implementing dashed line functionality proposed in the present invention can meet the functional requirements of the glLineStipple interface in OpenGL and guide the development of graphics drivers. This method and system does not require the GPU hardware to have a dashed line drawing function, thus providing high flexibility and wide versatility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of GPU technology, and in particular relates to a method and system for realizing an OpenGL dotted line function based on a shader. Background Art

[0002] OpenGL (Open Graphics Library) is a popular 3D graphics standard used to create interactive 3D applications as a software interface for graphics hardware. GPU vendors supporting OpenGL must provide not only GPU hardware but also graphics driver software that implements OpenGL functionality. This allows OpenGL applications to use the driver to call upon the GPU hardware for rendering. The quality of the OpenGL driver code directly impacts the ability to fully utilize the GPU hardware's performance.

[0003] A dashed line is a discontinuous line drawn with dots or short lines. It's commonly used in visualization scenarios like maps and radar, and is often required in graphics rendering. In OpenGL, you can use the glLineStipple function (glLineStipple is an OpenGL function used to create dashed line segments) to pass in relevant parameters, which are then used to draw subsequent line primitives to achieve the dashed line effect.

[0004] For GPU manufacturers, the OpenGL standard specification does not specify the method used to achieve the dashed line rendering effect when implementing the dashed line function. Instead, it specifies the requirements that the dashed line style must meet. The choice of technical approach to implement the dashed line function is determined by the GPU manufacturer. The implementation of the dashed line function in OpenGL is closely related to the specific GPU hardware architecture. Different manufacturers' GPUs have differences in architecture, instruction sets, memory management, and other aspects, and the implementation methods of the dashed line function will also vary. Currently, no GPU manufacturer has publicly disclosed the underlying implementation method of the dashed line function in OpenGL.

[0005] Developers typically use the glLineStipple API provided by OpenGL to draw dotted lines, which requires GPU hardware support. If the GPU hardware doesn't support dotted line drawing, errors will occur. Therefore, this current method lacks flexibility and versatility. Summary of the Invention

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

[0007] The present invention adopts the following technical solutions:

[0008] 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:

[0009] Step S1: receiving graphics driver rendering context data through the OpenGL standard interface;

[0010] Step S2: Retrieve graphics driver rendering context data to determine whether the dashed line drawing function is enabled and whether the currently drawn primitive is a line type primitive;

[0011] Step S3: If the dotted line drawing function is enabled and the current drawing primitive type is a line 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;

[0012] 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;

[0013] Step S5: Generate instructions for inputting factor data, pattern data, and constant data "1" into uniform variables A, B, and C in the shading program, respectively, and write them into the rendering command buffer;

[0014] Step S6: If the dotted line drawing function is not enabled, or the current drawing primitive type is not a line primitive, then the shader program called by the current drawing is also obtained, and whether the uniform variable C is declared in the shader program is checked;

[0015] Step S7: If the uniform variable C is declared, an instruction is generated to pass the constant data "0" to the uniform variable C in the shading program and write it into the rendering command buffer;

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

[0017] On the other hand, the shader-based OpenGL dotted line function implementation system includes:

[0018] A data receiving unit, configured to receive graphics driver rendering context data via an OpenGL standard interface;

[0019] A retrieval and judgment unit is used to retrieve the graphics driver rendering context data, determine whether the dotted line drawing function is enabled, and whether the primitive currently to be drawn is a line type primitive;

[0020] The first query unit is configured to, if the dashed line drawing function is enabled and the current drawing primitive type is a line primitive, further obtain a shader program called by the current drawing and query whether a uniform variable C is declared in the shader program;

[0021] a program modification unit, configured to modify the shading program to insert code or instructions to declare the uniform variable C if the uniform variable C is not declared, and to declare two more uniform variables, which are respectively denoted as uniform variable A and uniform variable B;

[0022] The first instruction writing unit is used to generate instructions for inputting factor data, pattern data, and constant data "1" into uniform variables A, B, and C in the shading program in a one-to-one correspondence manner, and write them into the rendering command buffer;

[0023] 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;

[0024] The second instruction writing unit is used to generate an instruction for passing constant data "0" to the uniform variable C in the shading program if the uniform variable C is declared, and write the instruction into the rendering command buffer;

[0025] The rendering unit is used to submit the instructions and shader programs in the rendering command buffer to the GPU hardware for rendering.

[0026] The present invention has the beneficial effects of being a pure software implementation method based on driver source code, meeting the functional requirements of the glLineStipple interface in OpenGL and being useful for guiding the development of graphics drivers. The present invention is highly versatile and can achieve dashed line effects even when GPU hardware does not support dashed line drawing, without requiring the GPU hardware to have this function. Therefore, the present invention is highly flexible and versatile. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 This is a flowchart of a method for implementing an OpenGL dotted line function based on a shader provided by an embodiment of the present invention;

[0028] Figure 2This is a structural block diagram of a shader-based OpenGL dotted line function implementation system provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0029] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, 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 intended to limit the present invention.

[0030] In order to illustrate the technical solution of the present invention, specific embodiments are provided below.

[0031] Example 1:

[0032] like Figure 1 As shown, the shader-based OpenGL dotted line function implementation method provided in this embodiment includes the following steps:

[0033] Step S1: Receive graphics driver rendering context data through the OpenGL standard interface.

[0034] For a complete and valid OpenGL program, before calling the graphics driver to implement this method, a certain amount of rendering support data must first be passed to the graphics driver through the OpenGL standard interface. The data recorded in the graphics driver's rendering context is sufficient to support the implementation of this method. Therefore, the first step is to obtain the graphics driver rendering context data.

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

[0036] This step retrieves the graphics driver's rendering context data and first determines whether dashed line drawing is enabled. GL_LINE_STIPPLE is a mode used in OpenGL to control the style of line drawing. GL_LINE_STIPPLE uses a 16-bit pattern to control line drawing. This pattern is repeatedly cycled, determining which parts of the line to draw and which to skip.

[0037] In OpenGL, the function glEnable(GL_LINE_STIPPLE) means turning on the dashed line drawing mode for line segments; glDisable(GL_LINE_STIPPLE) means disabling the dashed line mode, that is, turning off the dashed line drawing mode for line segments. glLineStipple(factor, pattern) is used to set the dashed line drawing mode, where factor is an integer that specifies the number of times each pattern bit is repeated; pattern is a 16-bit unsigned integer that represents the dashed line drawing pattern. Each bit in the pattern corresponds to a pixel, 1 means drawing, and 0 means skipping. When using it, you need to first turn on the dashed line mode through glEnable(GL_LINE_STIPPLE). After drawing is completed, you can use glDisable(GL_LINE_STIPPLE) to turn off the mode to avoid affecting subsequent drawing.

[0038] Therefore, in this step, in OpenGL, the dotted line drawing function is enabled by calling glEnable(GL_LINE_STIPPLE) and the dotted line drawing function is disabled by calling glDisable(GL_LINE_STIPPLE).

[0039] When drawing primitives, the primitive type is specified in the parameters of the drawing function (such as glDrawArrays) to control it. The line type primitives include GL_LINES, GL_LINE_LOOP, and GL_LINE_STRIP, which are three modes for specifying how to interpret vertex data as line segment primitives. The GL_LINES mode treats 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 polyline. The GL_LINE_STRIP mode connects all vertices in sequence into a continuous polyline.

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

[0041] 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 query whether the uniform variable C is declared in the shader program.

[0042] In GLSL (OpenGL Shading Language), uniform variables are a special type of global variable. Uniform variables are used to pass data between shader programs on the CPU and GPU. These variables remain constant throughout the processing of primitives (such as triangles and line segments). That is, the value of a uniform variable remains the same for all vertices or fragments of a primitive.

[0043] The uniform variable C in this step receives data passed in subsequent operations of the present method and influences whether the discard operation is executed in subsequent steps. The "C" in the uniform variable C here only represents the variable itself, not its actual name. In theory, the more complex the variable name, the better, to avoid duplication with variables already declared in the shading program and prevent unpredictable results caused by duplication.

[0044] Therefore, this step retrieves the shader program called by the current drawing in the graphics driver rendering context data, and checks whether the uniform variable C is declared in the shader program.

[0045] 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, which are respectively recorded as uniform variable A and uniform variable B.

[0046] If the uniform variable C is not declared, you need to modify the shader program to insert code or instructions to declare it.

[0047] Because different GPU vendors have different OpenGL implementations, the current shader program retrieved in this step may be in GLSL source code or in a vendor-specific intermediate language. If the current shader program uses GLSL source code, GLSL code is inserted when modifying the shader program. If the current shader program uses the vendor's intermediate language, instructions are inserted when modifying the shader program.

[0048] The following is an example of inserting code in the form of glsl source code. The process is as follows:

[0049] S41. Insert a code segment declaring uniform variable A, uniform variable B, and uniform variable C before the main function of the shading program.

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

[0051] S42. Insert the code segment for screening and discarding fragments in the shader into 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) means rounding up the result of n / A.

[0052] Then insert the code segment in the main function:

[0053] "int n = mod(gl_FragCoord.y+gl_FragCoord.x, 16×A);\n if(B & (1<<ceil(n / A)) == 0 && C==1)discard;"

[0054] Here, "mod" is a common modulus operation function provided by the glsl language; "gl_FragCoord" is a variable built into the glsl syntax to describe the position of the fragment, and its x and y components represent the coordinates in the x and y directions respectively; 16×A is a constant, and A here 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, then taking the modulus with 16×A, and storing the result in the integer variable n. 1<<ceil(n / A)) is a bitwise operation, where "<< " means left shift, and "ceil" is a common rounding-up operation function provided by the glsl language; B & (1<<ceil(n / A)) is a bitwise AND operation, whose 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 on 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.

[0055] The function implemented by inserting the code is to calculate based on the input parameters Uniform variable A, B, 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 dotted line.

[0056] Step S5: Generate instructions for inputting factor data, pattern data, and constant data "1" into uniform variables A, B, and C in the shading program, respectively, and write them into the rendering command buffer.

[0057] The factor and pattern data in this step are provided by the parameters factor and pattern in the standard OpenGL interface glLineStipple. The application calls glLineStipple and passes the data to the graphics driver through the parameters. The graphics driver stores the data in the rendering context and retrieves the factor and pattern data from the rendering context during this step. The OpenGL driver first constructs a command buffer based on the rendering context and then submits the command buffer to the GPU hardware for drawing, which concludes with step S8.

[0058] Step S6: If the dotted line drawing function is not enabled, or the current drawing primitive type is not a line type primitive, then the shader program called by the current drawing is also obtained to check whether the uniform variable C is declared in the shader program.

[0059] Step S7: If the uniform variable C is declared, an instruction is generated to pass the constant data "0" to the uniform variable C in the shading program and write it into the rendering command buffer.

[0060] The aforementioned steps S3-S5 are for the case where dashed lines need to be drawn. If dashed lines are not required, the dashed line drawing function is not enabled, or the currently drawn primitive type is not a line primitive. Again, the shader program called for the current drawing is first obtained to check whether the uniform variable C is declared in the shader program. If not, the process proceeds directly to step S8 for normal rendering. If the uniform variable C is declared, an instruction is generated to pass the constant data "0" to the uniform variable C in the current shader program and write it to the rendering command buffer, and then step S8 is executed.

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

[0062] It should be noted that the dotted line function implementation method provided by the present invention is used to build an OpenGL graphics driver, and takes effect before the graphics driver submits rendering instructions to the GPU hardware. After this method takes effect and when the rendering instructions are submitted to the GPU hardware, the dotted line state, shader state, and primitive type state cannot be modified.

[0063] When running, an OpenGL application calls a standard interface function provided by the GPU graphics driver and passes the data required for rendering to the interface function. The graphics driver collects and processes the rendering data, instructing the GPU hardware to perform the rendering work. The dashed line function implementation method provided in this invention is used to guide the development of OpenGL graphics drivers. It is used to process the data passed by glLineStipple and generate an instruction stream to instruct the GPU hardware to render dashed lines that comply with the OpenGL standard.

[0064] Example 2:

[0065] like Figure 2 As shown, the shader-based OpenGL dotted line function implementation system provided in this embodiment includes:

[0066] The data receiving unit 1 is used to receive graphics driver rendering context data through the OpenGL standard interface;

[0067] Retrieval and judgment unit 2 is used to retrieve graphics driver rendering context data, determine whether the dotted line drawing function is enabled and whether the primitive currently to be drawn is a line type primitive;

[0068] The first query unit 3 is configured to, if the dashed line drawing function is enabled and the current drawing primitive type is a line primitive, further obtain a shader program called by the current drawing and query whether a uniform variable C is declared in the shader program;

[0069] A program modification unit 4 is configured to modify the shading program to insert code or instructions to declare the uniform variable C if the uniform variable C is not declared, and to declare two more uniform variables, which are respectively denoted as uniform variable A and uniform variable B;

[0070] The first instruction writing unit 5 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 the rendering command buffer;

[0071] The second query unit 6 is configured 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 primitive, and query whether a uniform variable is declared in the shader program, which is recorded as a uniform variable C;

[0072] The second instruction writing unit 7 is used for generating an instruction to pass constant data "0" to the uniform variable C in the shading program if the uniform variable C is declared, and writing the instruction into the rendering command buffer;

[0073] A rendering unit 8 for submitting the instructions and shader programs in the rendering command buffer to the GPU hardware for rendering.

[0074] 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 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 inserted content form is an instruction.

[0075] The program modification unit includes:

[0076] A declaration module for inserting a code segment for declaring Uniform variable A, Uniform variable B, and Uniform variable C before the main function of the shader program;

[0077] A screening and discarding module for inserting a code segment for screening 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 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.

[0078] 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.

[0079] The present invention introduces Uniform variable C to receive data passed in subsequent operations, specifically sets 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 glsl source code, 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;" is inserted, and the shader program and 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.

[0080] In summary, the present invention provides a method and system for implementing a dashed line function, which acts on an OpenGL graphics driver and is used to process data passed to glLineStipple and generate an instruction stream, thereby guiding the GPU hardware to render dashed lines that comply with OpenGL standards. Currently, no GPU manufacturer on the market has publicly disclosed a method for implementing a dashed line function. The present invention proposes a shader-based method and system for implementing a dashed line function, which can meet the functional requirements of the glLineStipple interface in OpenGL and is used to guide the development of graphics drivers. It does not require the GPU hardware to have a dashed line drawing function, and therefore has high flexibility and wide versatility.

[0081] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of protection 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: Retrieve graphics driver rendering context data to determine whether the dashed line drawing function is enabled and whether the currently drawn primitive is a line type primitive; Step S3: If the dotted line drawing function is enabled and the current drawing primitive type is a line 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: Generate instructions for inputting factor data, pattern data, and constant data "1" into uniform variables A, B, and C in the shading program, respectively, and write 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 primitive, then the shader program called by the current drawing is also obtained, and whether the uniform variable C is declared in the shader program is checked; Step S7: If the uniform variable C is declared, an instruction is generated to pass 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 and shader program in the rendering command buffer to the GPU hardware for rendering; 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 shader uses the manufacturer's intermediate language format, the content inserted when modifying the shader is in the form of instructions; 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; where ceil(n / A) means rounding up the result of n / A.

2. The method for implementing the OpenGL dotted line function based on a shader as claimed in claim 1, wherein: 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. A shader-based OpenGL dotted line function implementation system, characterized in that: The system comprises: A data receiving unit, configured to receive graphics driver rendering context data via an OpenGL standard interface; A retrieval and judgment unit is used to retrieve the graphics driver rendering context data, determine whether the dotted line drawing function is enabled, and whether the primitive currently to be drawn is a line type primitive; The first query unit is configured to, if the dashed line drawing function is enabled and the current drawing primitive type is a line primitive, further obtain a shader program called by the current drawing and query whether a uniform variable C is declared in the shader program; a program modification unit, configured to modify the shading program to insert code or instructions to declare the uniform variable C if the uniform variable C is not declared, and to declare two more uniform variables, which are respectively denoted 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, B, and C in the shading program in a one-to-one correspondence manner, and write them into the 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 to generate an instruction for passing constant data "0" to the uniform variable C in the shader program if the uniform variable C is declared, and write 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; 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 intermediate language form of the manufacturer, the content inserted when modifying the shading program is in the form of instructions; The program modification unit includes: A declaration module is used to insert a code segment 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 the modulus is 16×A, and the result is stored in the integer variable n; the uniform variable B is left-shifted 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.

4. The shader-based OpenGL dotted line function implementation system according to claim 3, characterized in that: In the search and judgment unit, in OpenGL, the dotted line drawing function is enabled by calling glEnable(GL_LINE_STIPPLE) and the dotted line drawing function is disabled by calling glDisable(GL_LINE_STIPPLE).

Citation Information

Patent Citations

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

    CN118154759A