Adaptation layer implementation method based on OpenGL (Open Graphics Library)
By introducing an OpenGL-based adaptation layer into the model-based design tool, the problems of low image adaptation efficiency and poor code readability are solved, efficient graphics rendering and concise code generation are achieved, and the overall performance and usability of the tool are improved.
Patent Information
- Application Number
- CN202510188318.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2045-02-20
AI Technical Summary
Existing model-based design tools have problems with inefficiency in image adaptation and poor code readability, especially when used across platforms.
An adaptation layer implementation method based on OpenGL is proposed. Through the combination of unified management, computing optimization and external interfaces, an interface matching with onModel tool is provided, which reduces the coupling between application logic and OpenGL, and improves the graphics rendering efficiency and code readability.
It realizes seamless integration with onModel tools, simplifies the code generation process, improves graphics rendering efficiency and code readability, reduces resource leakage and performance losses, and provides a more complete error handling mechanism.
Smart Images

Figure CN120029621A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of model-driven system engineering, and in particular relates to an adaptation layer realization method based on OpenGL. Background Art
[0002] Model-Based Systems Engineering (MBSE) is a system engineering method that uses models rather than documents as core artifacts throughout the entire life cycle of system development. Compared with traditional software development methods, it can effectively solve problems such as information islands, consistency issues, poor traceability, and low development efficiency. At the same time, with the increase in system complexity, especially in the fields of aerospace, automobiles, defense, and medical care, the advantages of MBSE are gradually emerging.
[0003] Currently, mature MBSE tools such as SCADE and MagicDraw are monopolized by foreign countries. With the improvement of my country's independent research and development capabilities of industrial software, benchmarking tools in the MBSE field are also developing rapidly. Among them, OnModel, as a model-based detailed design tool independently developed by our unit, can provide a graphic design and development environment for embedded human-machine interfaces, as well as code generation functions. In order to ensure that the code can be used across platforms, the underlying layer implements graphics rendering based on OpenGL. In order to make the graphics code generation process smoother, the generated code is more readable and more efficient, the present invention proposes an adaptation layer implementation method based on OpenGL. Based on the graphics provided by the onModel tool, an adaptation layer is established from the aspects of rendering efficiency and ease of use. It mainly implements a set of interfaces that match the onModel tool graphics, making the code generation process of the human-machine interface simpler and the generated code graphics rendering more efficient. Summary of the invention
[0004] 1. Technical issues to be resolved
[0005] The technical problem to be solved by the present invention is how to provide an OpenGL-based adaptation layer implementation method to solve the image adaptation problem of model-based design tools.
[0006] (II) Technical solution
[0007] In order to solve the above technical problems, the present invention proposes an adaptation layer implementation method based on OpenGL, the adaptation layer includes: unified management, calculation optimization and external interface, unified management includes resource, state and error management; calculation optimization includes mathematical operation optimization, curve and polygon drawing optimization; external interface includes an interface matching with onModel tool;
[0008] In the unified management part, the adaptation layer defines a structure that stores all status information, resource information, and error information; the onModel tool provides six resource tables, namely line type, line width, texture, font, gradient, and color. The adaptation layer loads all these resource tables into the structure during initialization, and obtains the corresponding resources through indexes when used to implement resource management; at the same time, the structure contains all the states required for drawing; error management defines an error identifier and error parameter identifier for each external interface, checks the input or status during function execution, and uses the error setting function to push the error to the error storage variable of the structure when an error is detected, and provides an error acquisition function to obtain all error information;
[0009] In the calculation optimization part, the adaptation layer first optimizes the commonly used mathematical operations in graphics drawing, including trigonometric functions, inverse trigonometric functions, exponential operations, square root, and division; the adaptation layer also provides methods for drawing Bezier curves and arcs. By calculating the coordinates of each point on the curve, the curve is approximated by a polygon. When approximating an arc, the point interval is associated with the radius and the scaling ratio. When approximating a Bezier curve, the point interval is proportional to the distance between the starting point, the control point, and the end point. Complex polygons are drawn using the ear cutting method.
[0010] In terms of external interfaces, the adaptation layer provides interfaces that match the onModel tool. The interfaces are divided into five categories according to their functions: initialization, basic primitive drawing, clipping, interaction, and appearance. When the onModel tool generates code for the human-computer interface, these matching interfaces are called to implement OpenGL calls and complete graphics rendering.
[0011] (III) Beneficial effects
[0012] The present invention proposes a method for implementing an adaptation layer based on OpenGL. The present invention proposes a method for implementing an adaptation layer based on OpenGL. The method mainly has the following characteristics:
[0013] (1) Based on the human-machine interface design elements provided by the onModel tool, a set of matching interfaces is provided to reduce the coupling between the application logic and OpenGL, achieve seamless integration with the onModel tool, and enable the human-machine interface drawn in the onModel tool to generate embedded code more conveniently. The generated code is easier to understand than OpenGL.
[0014] (2) The adaptation layer manages all used states, resources, and error information in a unified manner, which can reduce resource leakage and performance loss, provide a more complete error handling mechanism, and make errors easier to track and fix.
[0015] (3) The adaptation layer implements common mathematical operations, Bezier curve drawing, arc drawing and other functions, which can improve rendering efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 This is a composition diagram of the adaptation layer of the present invention. DETAILED DESCRIPTION
[0017] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.
[0018] In view of the actual functions and performance requirements of OnModel, a model-based software analysis, design and verification tool, users need to generate corresponding C code according to the designed human-machine interface during the modeling process to realize the graphic design of the embedded human-machine interface. The present invention provides an adaptation layer implementation method based on OpenGL, establishes an adaptation layer according to the primitives provided by the onModel tool, realizes the encapsulation of OpenGL, and forms an adaptation layer matching the onModel primitives. The process of generating C code from the graphical interface is simplified, and the readability of the code is improved. Support is provided for the realization of subsequent functions of the OnModel tool.
[0019] The purpose of this invention is to solve the problem of generating C code for the key step of the human-machine interface for the self-developed tool OnModel in the MBSE field, and propose an adaptation layer implementation method based on OpenGL. The adaptation layer includes three functions: unified management, calculation optimization and external interface. The unified management includes resource, state and error management; the calculation optimization includes mathematical operation optimization, curve and polygon drawing optimization; the external interface includes an interface matching the onModel tool.
[0020] In the unified management part, the adaptation layer defines a structure that stores all status information, resource information, and error information. The onModel tool provides six resource tables: line type, line width, texture, font, gradient, and color. The adaptation layer loads all these resource tables into the structure during initialization, and obtains the corresponding resources through indexes when used to implement resource management. At the same time, the structure contains all the states required for drawing, such as the current drawing mode, whether blending is enabled, the current view depth, texture target, whether gradient is enabled, whether polygon smoothing is enabled, etc. Error management defines an error identifier and an error parameter identifier for each external interface. The input or status is checked during the execution of the function. When an error is detected, the error setting function is used to push the error to the error storage variable of the structure. An error acquisition function is provided to obtain all error information.
[0021] In the calculation optimization part, the adaptation layer first optimizes the commonly used mathematical operations in graphics drawing, including trigonometric functions, inverse trigonometric functions, exponential operations, square root, division, etc. Among them, the inverse trigonometric function and square root operation are implemented by table lookup method to reduce calculation consumption and improve rendering efficiency. The division operation is optimized for different data types, and error handling is performed to improve program security and robustness. The adaptation layer provides a method for drawing Bezier curves and arcs. By calculating the coordinates of each point on the curve, the curve is approximated by a polygon. In order to improve accuracy while reducing calculation loss, the point interval is associated with the radius and scaling ratio when the arc is approximated. When the Bezier curve is approximated, the point interval is proportional to the distance between the starting point, control point and end point. Complex polygons are drawn using the ear cutting method.
[0022] In terms of external interfaces, the adaptation layer provides interfaces that match the onModel tool. The interfaces are divided into five categories according to their functions: initialization, basic primitive drawing, clipping, interaction, and appearance. When the onModel tool generates code for the human-machine interface, these matching interfaces are called to implement OpenGL calls and complete graphics rendering.
[0023] Embodiment 1:
[0024] The composition of the present invention is as follows Figure 1 As shown in the figure, it is divided into two parts: external interface and internal implementation. Unified management and calculation optimization belong to the internal implementation part. The internal implementation calls the OpenGL interface to achieve the final graphics rendering. All functions calling OpenGL are declared in mgl_private.h. The external interface provides an interface matching the primitives in the onModel tool for the application layer to call.
[0025] The structure in unified management is defined in mgl_context_type.h. The variables involved in resource management are shown below. All color, line type, line width, font, texture and gradient data point to the corresponding data table in the form of pointers. When a resource needs to be used, it is indexed by the current resource serial number to reduce the overhead of repeated creation and destruction of resources.
[0026]
[0027] Some of the relevant variables of state management are as follows, including drawing mode, basic primitive information of the current drawing, coordinate transformation information, scaling information, clipping plane, text information, and path information. After the external interface is called, the essence is to change these state quantities, and then call OpenGL to realize graphics rendering.
[0028]
[0029]
[0030] Some error identifiers and related error functions defined by error management are shown below. Error identifiers are defined in mgl_constant.h. First, an error identifier is defined for each external interface. Some are listed here. After each interface is called, the parameters are checked. If an error is found, the error information is stored in the assigned error output variable through the error function oglxSetError. Users can obtain all error information and the status of error storage through the mglGetErrors function.
[0031]
[0032] In the calculation optimization part, common mathematical operations are declared in mth.h. They include trigonometric functions, inverse trigonometric functions, square root, exponentiation, modulus, and drawing.
[0033] Since the arccosine function in the inverse trigonometric function changes very slowly at both ends, the formula is used to implement it in the middle part, and the parts greater than 0.98 and less than -0.98 at both ends are implemented by table lookup method, which can take into account both memory usage and calculation accuracy.
[0034] In the square root operation, the square root of a single-precision floating-point number is calculated by dividing the floating-point number into an exponent and a mantissa, which are calculated separately. The exponent part is obtained by shifting, and the mantissa is obtained by looking up a table. Then the sign bit, exponent, and mantissa are combined to obtain the square root of the single-precision floating-point number. This method can speed up the calculation efficiency.
[0035] In the drawing part, the method of drawing the Bezier curve is as follows: first calculate the distance between the starting point, the control point and the end point, divide the sum of the distances by 10 to get the number of points on the curve that need to be obtained, and then use the Bezier curve formula to obtain the coordinates of each point, put all these points into the vertex cache, and draw them uniformly.
[0036] The method for drawing an arc is: according to the radius size, set different point intervals, specifically, when the radius is less than 10, the point interval is 28°; when the radius is less than 20, the point interval is 17°, when the radius is less than 60, the point interval is 9°, when the radius is less than 260, the point interval is 5°, and in other cases the point interval is 3.4°. Then calculate the points on the arcs of these angles, put the vertices in the vertex cache, and draw them uniformly.
[0037] This method of decreasing the point interval as the radius increases can obtain better visual effects with less calculation. When drawing polygons, the ear cutting method is used to draw the polygons.
[0038] In terms of external interfaces, the onModel tool provides basic elements for human-machine interface design, which can be divided into: basic primitives, clipping, interaction, and container according to their functions. In order to match the basic elements, the adaptation layer can be divided into initialization, basic primitives, clipping, interaction, and coordinate transformation. All external interface declarations are in mgl.h.
[0039] The function of the interface in initialization is to initialize the defined global structure and load resource data. Some of the interfaces in initialization are as follows:
[0040]
[0041]
[0042] The interface of basic primitives is to provide basic primitive drawing functions, including lines, paths, arcs, elliptical arcs, circles, polygons, rings, and text. Among them, the path can be subdivided into straight lines, Bezier curves, arcs, horizontal lines, and vertical lines. Some interfaces are shown in the following table:
[0043]
[0044] The interface of the clipping part provides functions such as clipping plane, clipping inside / outside of rectangle, clipping custom closed graphics, and judging whether a point is within the clipping range. Some of the interfaces are shown in the following table:
[0045]
[0046]
[0047] The interface of the coordinate transformation part provides functions such as coordinate translation, coordinate rotation, scaling, setting the current viewpoint, and transformation between the user coordinate system and the screen coordinate system. Some of the interfaces are shown in the following table:
[0048]
[0049] The interface of the interactive part provides functions such as judging whether the cursor is in a given circular / rectangular / polygonal area, and the position of the cursor in the rectangular / circular area. Some interfaces are shown in the following table:
[0050]
[0051]
[0052] Technical effect:
[0053] The present invention proposes an OpenGL-based adaptation layer implementation method, which has the following main features:
[0054] (1) Provide a set of matching interfaces according to the human-machine interface design elements provided by the onModel tool, reduce the coupling degree between the application logic and OpenGL, achieve seamless integration with the onModel tool, enable the human-machine interface drawn in the onModel tool to generate embedded code more conveniently, and the generated code is easier to understand than OpenGL.
[0055] (2) The adaptation layer uniformly manages all used states, resources, and error information, can reduce resource leakage and performance loss, provide a more perfect error handling mechanism, and make errors easier to track and repair.
[0056] (3) The adaptation layer implements functions such as common mathematical operations, Bezier curve drawing, and arc drawing, which can improve the rendering efficiency.
[0057] The above are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the technical principle of the present invention, several improvements and deformations can be made, and these improvements and deformations should also be regarded as the protection scope of the present invention.
Claims
1. A method for implementing an adaptation layer based on OpenGL, characterized in that: The adaptation layer includes: unified management, calculation optimization and external interface. The unified management includes resource, status and error management; the calculation optimization includes mathematical operation optimization, curve and polygon drawing optimization; the external interface includes the interface matching the onModel tool; In the unified management part, the adaptation layer defines a structure that stores all status information, resource information, and error information; the onModel tool provides six resource tables, namely line type, line width, texture, font, gradient, and color. The adaptation layer loads all these resource tables into the structure during initialization, and obtains the corresponding resources through indexes when used to implement resource management; at the same time, the structure contains all the states required for drawing; error management defines an error identifier and error parameter identifier for each external interface, checks the input or status during function execution, and uses the error setting function to push the error to the error storage variable of the structure when an error is detected, and provides an error acquisition function to obtain all error information; In the calculation optimization part, the adaptation layer first optimizes the commonly used mathematical operations in graphics drawing, including trigonometric functions, inverse trigonometric functions, exponential operations, square root, and division; the adaptation layer also provides methods for drawing Bezier curves and arcs. By calculating the coordinates of each point on the curve, the curve is approximated by a polygon. When approximating an arc, the point interval is associated with the radius and the scaling ratio. When approximating a Bezier curve, the point interval is proportional to the distance between the starting point, the control point, and the end point. Complex polygons are drawn using the ear cutting method. In terms of external interfaces, the adaptation layer provides interfaces that match the onModel tool. The interfaces are divided into five categories according to their functions: initialization, basic primitive drawing, clipping, interaction, and appearance. When the onModel tool generates code for the human-computer interface, these matching interfaces are called to implement OpenGL calls and complete graphics rendering.
2. The OpenGL-based adaptation layer implementation method according to claim 1, characterized in that: The adaptation layer is divided into two parts: external interface and internal implementation. Unified management and calculation optimization belong to the internal implementation. The internal implementation calls the OpenGL interface to achieve the final graphics rendering. All functions calling OpenGL are declared in mgl_private.h. The external interface provides an interface that matches the primitives in the onModel tool for the application layer to call.
3. The OpenGL-based adaptation layer implementation method according to claim 2, characterized in that: The structure in unified management is defined in mgl_context_type.h. All color, line type, line width, font, texture and gradient data point to the corresponding data table in the form of pointers. When a resource needs to be used, it is indexed by the current resource serial number.
4. The OpenGL-based adaptation layer implementation method according to claim 2, characterized in that: Some relevant variables of state management include drawing mode, basic primitive information of the current drawing, coordinate transformation information, scaling information, clipping plane, text information and path information; after the external interface is called, the essence is to change these state quantities, and then call OpenGL to realize graphics rendering.
5. The OpenGL-based adaptation layer implementation method according to claim 2, characterized in that: Error management defines some error identifiers and related error functions. The error identifiers are defined in mgl_constant.h. First, an error identifier is defined for each external interface. After each interface is called, the parameters are checked. If an error is found, the error information is stored in the allocated error output variable through the error function oglxSetError. The user obtains all error information and the status of error storage through the mglGetErrors function.
6. The method for implementing an adaptation layer based on OpenGL according to any one of claims 3 to 5, characterized in that: In the calculation optimization part, mathematical operations are declared in mth.h, including trigonometric functions, inverse trigonometric functions, square root, exponentiation, modulus, and drawing.
7. The OpenGL-based adaptation layer implementation method according to claim 6, characterized in that: In the inverse trigonometric function, the two ends of the inverse cosine function change very slowly, so the formula is used to implement the middle part, and the parts greater than 0.98 and less than -0.98 at both ends are implemented by table lookup method; In the square root operation, the square root of a single-precision floating-point number is calculated by dividing the floating-point number into the exponent and the mantissa, which are calculated separately. The exponent part is obtained by shifting, and the mantissa is obtained by looking up a table. Then the sign bit, exponent, and mantissa are combined to obtain the square root of the single-precision floating-point number.
8. The OpenGL-based adaptation layer implementation method according to claim 6, characterized in that: In the drawing part, the drawing method of the Bezier curve is as follows: first calculate the distance between the starting point, the control point and the end point, divide the sum of the distances by 10 to get the number of points on the curve that need to be obtained, then use the Bezier curve formula to obtain the coordinates of each point, put all these points into the vertex buffer, and draw them uniformly; The method for drawing an arc is: according to the radius size, set different point intervals, specifically, when the radius is less than 10, the point interval is 28°; when the radius is less than 20, the point interval is 17°, when the radius is less than 60, the point interval is 9°, when the radius is less than 260, the point interval is 5°, and in other cases the point interval is 3.4°. Then calculate the points on the arcs of these angles, put the vertices in the vertex cache, and draw them uniformly.
9. The method for implementing the adaptation layer based on OpenGL as claimed in claim 6, characterized in that: In terms of external interfaces, the onModel tool provides the basic elements of human-computer interface design, which are divided into: basic primitives, clipping, interaction and containers by function; the adaptation layer interface includes: initialization, basic primitives, clipping, interaction and coordinate transformation; all external interface declarations are in mgl.h.
10. The OpenGL-based adaptation layer implementation method according to claim 9, characterized in that: The function of the interface in initialization is to initialize the defined global structure and load resource data; The interface function of the basic primitives is to provide basic primitive drawing functions, including lines, paths, arcs, elliptical arcs, circles, polygons, rings and texts; among them, the path is further subdivided into straight lines, Bezier curves, arcs, horizontal lines and vertical lines; The interface of the clipping part provides the functions of clipping plane, clipping inside / outside of rectangle, clipping custom closed figures, and judging whether a point is within the clipping range; The interface of the coordinate transformation part provides the functions of coordinate translation, coordinate rotation, scaling, setting the current viewpoint, and transformation between the user coordinate system and the screen coordinate system; The interface of the interactive part provides the function of judging whether the cursor is in a given circular / rectangular / polygonal area and the position of the cursor in the rectangular / circular area.
Citation Information
Patent Citations
Partition drawing-based industrial control master station picture rendering implementation method
CN118823169A
System, method and article of manufacture for a programmable processing model with instruction set
US8264492B1