CN110543620A - method and system for drawing graphics primitives based on OpenGL ES2.0 - Google Patents

method and system for drawing graphics primitives based on OpenGL ES2.0 Download PDF

Info

Publication number
CN110543620A
CN110543620A CN201910829623.2A CN201910829623A CN110543620A CN 110543620 A CN110543620 A CN 110543620A CN 201910829623 A CN201910829623 A CN 201910829623A CN 110543620 A CN110543620 A CN 110543620A
Authority
CN
China
Prior art keywords
shader
source code
code character
preset
opengl
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910829623.2A
Other languages
Chinese (zh)
Inventor
林云齐
甘霖
郑武贞
尚忠亮
罗跃军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Zhonghai Data Technology Co Ltd
Original Assignee
Wuhan Zhonghai Data Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Zhonghai Data Technology Co Ltd filed Critical Wuhan Zhonghai Data Technology Co Ltd
Priority to CN201910829623.2A priority Critical patent/CN110543620A/en
Publication of CN110543620A publication Critical patent/CN110543620A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/14Digital output to display device ; Cooperation and interconnection of the display device with other functional units
    • G06F3/1407General aspects irrespective of display type, e.g. determination of decimal point position, display with fixed or driving decimal point, suppression of non-significant zeros

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Image Generation (AREA)

Abstract

the embodiment of the invention provides a method and a system for drawing a primitive based on OpenGL ES2.0, wherein the method comprises the following steps: a shader management class is established, a plurality of preset shader source code character strings are stored in the shader management class, and each preset shader source code character string has a corresponding shader identifier; initializing the shader based on a shader identifier corresponding to the shader; packaging a method for using a shader according to the shader identification and the corresponding shader source code character string; and drawing and displaying the graphics primitives. By setting the shader management class which stores a plurality of preset shader source code character strings, the process of drawing the primitive by using OpenGL ES2.0 is simplified, meanwhile, the problem that the needed shader can be customized and created without frequently modifying the shader source code character strings is solved, and customized drawing can be conveniently carried out.

Description

Method and system for drawing graphics primitives based on OpenGL ES2.0
Technical Field
The invention relates to the technical field of computers, in particular to a method and a system for drawing a primitive based on OpenGL ES 2.0.
background
Conventional OpenGL ES2.0 rendering primitives (including points, lines, planes) generally includes creating shaders (including vertex shaders and fragment shaders), specifying shader source code strings, compiling shaders, creating shader executables, adding shaders to executables, linking executables, using executables, rendering and displaying primitives. When a shader source code string is designated, a GLSL language is generally used, the shader source code string is either directly written and used in a program or loaded in a GLSL file mode, and whether the shader source code string is successfully written or not directly influences whether a shader executable program can be successfully created or not, and finally influences whether a primitive can be displayed or not. In summary, the conventional method for drawing a primitive by OpenGL ES2.0 is complex, and when customized drawing is performed, a shader source code string needs to be modified, which is inconvenient and easy to fail.
Disclosure of Invention
Embodiments of the present invention provide a method and system for drawing primitives based on OpenGL ES2.0, which overcome the above problems or at least partially solve the above problems.
in a first aspect, an embodiment of the present invention provides a method for drawing a primitive based on OpenGL ES2.0, including:
A shader management class is established, a plurality of preset shader source code character strings are stored in the shader management class, and each preset shader source code character string has a corresponding shader identifier;
initializing the shader based on a shader identifier corresponding to the shader;
Packaging a method for using a shader according to the shader identification and the corresponding shader source code character string;
and drawing and displaying the graphics primitives.
Optionally, a shader source code string preset in a pair of a vertex shader and a fragment shader is stored in the shader management class.
Optionally, initializing the shader based on a shader identifier corresponding to the shader specifically includes:
Selecting a corresponding preset shader source code character string from the shader management class based on the shader identifier corresponding to the shader;
initializing the shader by using the corresponding preset shader source code character string.
optionally, initializing the shader by using the corresponding preset shader source code character string specifically includes:
And compiling shaders, creating shader executable programs, adding shaders into the executable programs, linking the executable programs and using the executable programs in sequence by utilizing the corresponding preset shader source code character strings.
Optionally, the method further comprises:
adding additional types of predetermined shader source code strings to the shader management class.
in a second aspect, an embodiment of the present invention provides a system for drawing primitives based on OpenGL ES2.0, including:
the system comprises a construction module, a shader management module and a management module, wherein the construction module is used for constructing a shader management class, a plurality of preset shader source code character strings are stored in the shader management class, and each preset shader source code character string is provided with a corresponding shader identifier;
The initialization module is used for initializing the shader based on the shader identifier corresponding to the shader;
The packaging module is used for packaging a method for using the shader according to the shader identifier and the corresponding shader source code character string;
and the drawing module is used for drawing and displaying the graphics primitives.
In a third aspect, an embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor implements the steps of the method for drawing primitives based on OpenGL ES2.0 as provided in the first aspect when executing the program.
in a fourth aspect, embodiments of the present invention provide a non-transitory computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps of the OpenGL ES 2.0-based primitive rendering method as provided in the first aspect.
According to the method and the system for drawing the primitives based on the OpenGL ES2.0, which are provided by the embodiment of the invention, the process of drawing the primitives by using the OpenGL ES2.0 is simplified by setting the shader management classes in which a plurality of preset shader source code character strings are stored, meanwhile, the problem that the needed shaders can be customized and created without frequently modifying the shader source code character strings is solved, and the customized drawing can be conveniently carried out.
drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a method for drawing primitives based on OpenGL ES2.0 according to an embodiment of the present invention;
Fig. 2 is a block diagram of a system for drawing primitives based on OpenGL ES2.0 according to an embodiment of the present invention;
Fig. 3 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Before explaining the scheme of the embodiment of the present invention in detail, some terms involved in the scheme are explained as follows:
a shader: shaders (shaders) are used to implement image rendering, replacing the editable programs of a fixed rendering pipeline. Shaders referred to herein refer to vertex shaders and fragment shaders.
And (3) a vertex shader: a vertex shader is a set of instruction code that is executed when a vertex is rendered. The vertex shader only manages independent vertexes, does not establish a relation between the vertexes, and is used for calculating clipping coordinates, depth buffering, color and texture coordinates and the like of the vertexes.
a fragment shader: the fragment shader is also a set of instruction codes that act to process each fragment generated by the rasterization stage, ultimately calculating the final color of each pixel.
GLSL: the language of the colored programming in OpenGL, that is, a short custom program written by a developer.
fig. 1 is a schematic flowchart of a method for drawing a primitive based on OpenGL ES2.0 according to an embodiment of the present invention, as shown in fig. 1, where the method includes:
s101, a shader management class is constructed, wherein a plurality of preset shader source code character strings are stored in the shader management class, and each preset shader source code character string has a corresponding shader identifier;
S102, initializing the shader based on the shader identifier corresponding to the shader;
S103, packaging a method for using a shader according to the shader identifier and the corresponding shader source code character string;
And S104, drawing and displaying the graphics primitives.
specifically, the primitive drawing process may include the following steps: firstly, a shader management class is created, several commonly used shader source code character strings are written in the class, and are added when the shader source code character strings are expanded, and the management class can simultaneously manage a vertex shader and a fragment shader. Second, an identification is set for each shader. Thirdly, initializing the shader based on the shader identification; according to the result of initialization, the colorers are compiled, added and linked. Fourthly, packaging a method for using a shader according to the identifier and the shader source code character string; when the customized drawing is carried out, the vertex data of the user is created, the corresponding shader is used according to the identifier, and the shader source code character string does not need to be modified.
According to the method for drawing the primitive based on the OpenGL ES2.0, which is provided by the embodiment of the invention, the process of drawing the primitive by using the OpenGL ES2.0 is simplified by setting the shader management class which stores a plurality of preset shader source code character strings, and meanwhile, the problem that the needed shader can be customized and created without frequently modifying the shader source code character strings is solved, and the customized drawing can be conveniently carried out.
In an optional embodiment of the present invention, the shader management class stores a shader source code string preset in a pair of a vertex shader and a fragment shader.
in an optional embodiment of the present invention, initializing a shader based on a shader identifier corresponding to the shader specifically includes:
Selecting a corresponding preset shader source code character string from the shader management class based on the shader identifier corresponding to the shader;
Initializing the shader by using the corresponding preset shader source code character string.
In an optional embodiment of the present invention, the initializing the shader with the corresponding preset shader source code character string specifically includes:
and compiling shaders, creating shader executable programs, adding shaders into the executable programs, linking the executable programs and using the executable programs in sequence by utilizing the corresponding preset shader source code character strings.
in an optional embodiment of the invention, the method further comprises:
adding additional types of predetermined shader source code strings to the shader management class.
Fig. 2 is a block diagram of a system for drawing primitives based on OpenGL ES2.0 according to an embodiment of the present invention, and as shown in fig. 2, the system includes: a build module 201, an initialization module 202, an encapsulation module 203, and a render module 204. Wherein:
the construction module 201 is configured to construct a shader management class, where multiple preset shader source code strings are stored in the shader management class, and each preset shader source code string has a corresponding shader identifier. The initialization module 202 is configured to initialize a shader based on a shader identifier corresponding to the shader. The packaging module 203 is used for packaging a method for using the shader according to the shader identifier and the corresponding shader source code string. The rendering module 204 is used for rendering and displaying the primitives.
The system for drawing the primitives based on the OpenGL ES2.0, provided by the embodiment of the invention, simplifies the process of drawing the primitives by using the OpenGL ES2.0 by setting the shader management classes in which a plurality of preset shader source code character strings are stored, and simultaneously solves the problem that the needed shaders can be customized and created without frequently modifying the shader source code character strings, so that customized drawing can be conveniently carried out.
fig. 3 is a schematic entity structure diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 3, the electronic device may include: a processor (processor)310, a communication Interface (communication Interface)320, a memory (memory)330 and a communication bus 340, wherein the processor 310, the communication Interface 320 and the memory 330 communicate with each other via the communication bus 340. The processor 310 may invoke a computer program stored on the memory 330 and executable on the processor 310 to perform the network topology detection method provided by the above method embodiments, for example, including: a shader management class is established, a plurality of preset shader source code character strings are stored in the shader management class, and each preset shader source code character string has a corresponding shader identifier; initializing the shader based on a shader identifier corresponding to the shader; packaging a method for using a shader according to the shader identification and the corresponding shader source code character string; and drawing and displaying the graphics primitives.
In addition, the logic instructions in the memory 330 may be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solutions of the embodiments of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the methods described in the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
an embodiment of the present invention further provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the network topology detection method provided in the foregoing method embodiments, and for example, the method includes: a shader management class is established, a plurality of preset shader source code character strings are stored in the shader management class, and each preset shader source code character string has a corresponding shader identifier; initializing the shader based on a shader identifier corresponding to the shader; packaging a method for using a shader according to the shader identification and the corresponding shader source code character string; and drawing and displaying the graphics primitives.
the above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (8)

1. A method for drawing a primitive based on OpenGL ES2.0, comprising:
A shader management class is established, a plurality of preset shader source code character strings are stored in the shader management class, and each preset shader source code character string has a corresponding shader identifier;
initializing the shader based on a shader identifier corresponding to the shader;
Packaging a method for using a shader according to the shader identification and the corresponding shader source code character string;
And drawing and displaying the graphics primitives.
2. The method of claim 1, wherein a shader source code string preset in a pair of a vertex shader and a fragment shader is stored in the shader management class.
3. The method of claim 1, wherein initializing the shader based on a shader identifier corresponding to the shader comprises:
selecting a corresponding preset shader source code character string from the shader management class based on the shader identifier corresponding to the shader;
Initializing the shader by using the corresponding preset shader source code character string.
4. the method of claim 3, wherein initializing the shader with the corresponding predetermined shader source code string specifically comprises:
And compiling shaders, creating shader executable programs, adding shaders into the executable programs, linking the executable programs and using the executable programs in sequence by utilizing the corresponding preset shader source code character strings.
5. The method of claim 1, further comprising:
adding additional types of predetermined shader source code strings to the shader management class.
6. A system for drawing primitives based on OpenGL ES2.0, comprising:
the system comprises a construction module, a shader management module and a management module, wherein the construction module is used for constructing a shader management class, a plurality of preset shader source code character strings are stored in the shader management class, and each preset shader source code character string is provided with a corresponding shader identifier;
The initialization module is used for initializing the shader based on the shader identifier corresponding to the shader;
the packaging module is used for packaging a method for using the shader according to the shader identifier and the corresponding shader source code character string;
And the drawing module is used for drawing and displaying the graphics primitives.
7. an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor when executing the program performs the steps of the method for drawing primitives according to any of claims 1 to 6 based on OpenGL ES 2.0.
8. A non-transitory computer readable storage medium, having stored thereon a computer program, which, when being executed by a processor, performs the steps of the method for OpenGL ES 2.0-based primitive rendering according to any of the claims 1 to 6.
CN201910829623.2A 2019-09-03 2019-09-03 method and system for drawing graphics primitives based on OpenGL ES2.0 Pending CN110543620A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910829623.2A CN110543620A (en) 2019-09-03 2019-09-03 method and system for drawing graphics primitives based on OpenGL ES2.0

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910829623.2A CN110543620A (en) 2019-09-03 2019-09-03 method and system for drawing graphics primitives based on OpenGL ES2.0

Publications (1)

Publication Number Publication Date
CN110543620A true CN110543620A (en) 2019-12-06

Family

ID=68712424

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910829623.2A Pending CN110543620A (en) 2019-09-03 2019-09-03 method and system for drawing graphics primitives based on OpenGL ES2.0

Country Status (1)

Country Link
CN (1) CN110543620A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115018955A (en) * 2021-09-01 2022-09-06 荣耀终端有限公司 Image generation method and equipment

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20090077432A (en) * 2008-01-11 2009-07-15 엠텍비젼 주식회사 Method of processing opengl programmable shader by using off-line compiling
CN103413344A (en) * 2013-07-10 2013-11-27 深圳Tcl新技术有限公司 3D frame animation realization method, device and terminal
CN107038060A (en) * 2016-09-29 2017-08-11 阿里巴巴集团控股有限公司 A kind of page coloring device code debugging method, device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20090077432A (en) * 2008-01-11 2009-07-15 엠텍비젼 주식회사 Method of processing opengl programmable shader by using off-line compiling
CN103413344A (en) * 2013-07-10 2013-11-27 深圳Tcl新技术有限公司 3D frame animation realization method, device and terminal
CN107038060A (en) * 2016-09-29 2017-08-11 阿里巴巴集团控股有限公司 A kind of page coloring device code debugging method, device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115018955A (en) * 2021-09-01 2022-09-06 荣耀终端有限公司 Image generation method and equipment

Similar Documents

Publication Publication Date Title
Kessenich et al. OpenGL Programming Guide: The official guide to learning OpenGL, version 4.5 with SPIR-V
US8400444B2 (en) Method to render a root-less scene graph with a user controlled order of rendering
KR102150993B1 (en) Method for forming an optimized polygon based shell mesh
EP3137985B1 (en) Method and system to create a rendering pipeline
US20120174079A1 (en) Systems and methods for simulating a mobile device application
Cozzi et al. OpenGL insights
US9355464B2 (en) Dynamic generation of texture atlases
US20230120253A1 (en) Method and apparatus for generating virtual character, electronic device and readable storage medium
US8466919B1 (en) Re-rendering a portion of an image
CN109544658B (en) Map rendering method and device, storage medium and electronic device
US11069119B1 (en) Methods and systems for constructing a shader
US10600142B2 (en) Compression and decompression of indices in a graphics pipeline
US8854368B1 (en) Point sprite rendering in a cross platform environment
Hu et al. Parallel view-dependent level-of-detail control
US9858708B2 (en) Convex polygon clipping during rendering
US20130120381A1 (en) Fast rendering of knockout groups using a depth buffer of a graphics processing unit
CN113168312A (en) Method for generating binding between C/C + + library and interpreted language, and executing the method to convert three-dimensional (3D) model
CN111833429A (en) Three-dimensional game rendering method, three-dimensional engine, electronic device and readable storage medium
CN109976827B (en) Model loading method, server and terminal
CN110543620A (en) method and system for drawing graphics primitives based on OpenGL ES2.0
CN114089999A (en) Front-end page generation method and system
CN112604293A (en) Data processing method and device, electronic equipment and readable medium
CN112907436A (en) OpenGL-based line type drawing method, system and medium
Karwowski et al. LPFG user’s manual
US10818059B1 (en) Sculpt transfer

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20191206

RJ01 Rejection of invention patent application after publication