当前位置:网站首页>Chapter 7 vertex processing and drawing commands of OpenGL super classic (7th Edition)
Chapter 7 vertex processing and drawing commands of OpenGL super classic (7th Edition)
2022-06-30 05:01:00 【Jason_ Chen__】
List of articles
Preface
This chapter mainly studies the first two stages of pipeline ———— Vertex assembly and vertex shading .
One 、 Vertex Processing
Vertex read ——》 Vertex shader
1. Vertex shader input
(1) void glVertexAttribPointer() Link the buffered data to the input of the vertex shader
(2) The main auxiliary functions introduce void glVertexAttribFormat()、void glVertexAttribBinding()、void glBindVertexBuffer() function
2. Vertex shader output
(1) A built-in output variable interface block that vertex shaders can manipulate :
out gl_PerVertex
{
vec4 gl_Position; // Vertex Position
float gl_PointSize; // Vertex size
float gl_ClipDistance[]; // tailoring
float gl_CullDistance[]; // To eliminate
};
(2) Change vertex size
Mode one : adopt glPointSize()
Mode two :glEnable(GL_PROGRAM_POINT_SIZE)+gl_PointSize Set up
difference : The dimensions of mode 2 points can be different
Distance point size attenuation …
Two 、 Drawing command
1. Drawing command :
glDrawArrays() Vertex Paint , Need vertex buffer
glDrawElements() Index drawing , Vertex buffer and index buffer are required , Save a space
glDrawElementsBaseVertex() The advanced version above …
2. Restart merging geometry using primitives :
sketch : Using tools, you can set triangles “ Banding ”, So that you can use GL_TRIANGLE_STRIP And so on ,
The primitive restart index can be split at the index point “ Strip ”
3. Instantiation
glDrawArraysInstanced() and glDrawArraysInstanced() Draw a large number of the same objects using this function
void glVertexAttribDivisor() Used in conjunction with the above two functions , The main purpose is to determine the interval between input vertex attributes to each instance , for example : Set the divisor to 1, Then each instance has this vertex attribute , Let the divisor be 2, Then an instance at an interval has this vertex attribute .
4. Draw indirectly
The essence : Put the drawing command into the cache in advance , Call the indirect drawing command to execute
glDrawArraysIndirect()
typedef struct{
GLuint vertexCount;
GLuint instanceCount;
GLuint firstVertex;
GLuint baseInstance;
} DrawArraysIndirectCommand;
glDrawElementsIndirect()
typedef struct{
GLuint vertexCount;
GLuint instanceCount;
GLuint firstIndex;
GLuint firstVertex;
GLuint baseInstance;
} DrawElementsIndirectCommand;
3、 ... and 、 Save transform vertex
sketch : Connect the... Of the pipeline “ front end ”( Vertex shader 、 Surface subdivision evaluation shader or geometry shader ) The output of is stored in a cache ( Transform feedback cache ) in , For later use .
Variable variable :“ front end ” Output
Variable set changed , You must reconnect the shader program
1. Use transformation feedback :
(1) Set save
void glTransformFeedbackVaryings( Shader program , Number of outputs , The output array , Save mode )
(2) Save mode :
GL_INTERLEAVED_ATTRIBS, Save to a single cache ( Tightly placed at the binding point of the transform cache 0 position ), Can be set in a variable set gl_NextBuffer, Skip binding points
GL_SEPARATE_ATTRIBS, Save to multiple caches ( Put the output at the specified binding point position of the transform cache respectively )
(3) Set the variable to be saved in the cache location
void glBindBufferBase()
void glBindBufferRange(), Start and offset can be set
2. Start 、 Pause and stop the change feedback
Start to finish , The change feedback state cannot be changed ( Cache size , Location ...)
Many systems where particles interact in a deterministic manner can be modeled and simulated using vertex shaders and transform feedback alone
glEnable(GL_RASTERIZER_DISCARD), Turn off rasterization
glDisable(GL_RASTERIZER_DISCARD), Turn on rasterization
void glBeginTransformFeedback(GLenum primitiveMode), Start ,primitiveMode Must match the exported entity type
void glPauseTransformFeedback(), stop it
void glResumeTransformFeedback(), restart
void glEndTransformFeedback(), stop it
Four 、 tailoring
sketch : Determines the visible part of the drawing in the viewport
For triangles , If half of it is in the viewport , Half out of the viewport , Will produce one more triangle and one more vertex , There will be additional costs , Solve this problem , Protective tape is used
Custom crop
(1) Can be in “ Front end shaders ” adopt gl_ClipDistance[] Write clipping distance , The distance sign is negative , Then cut , The distance symbol is positive , Pass to the next shader ( Clip shaders can be used to clip larger primitive gradients away or get anti aliasing compensation for clip shaders )
(2) Large dots and thick lines may have bounce artifacts
(3)gl_CullDistance[] It's elimination , Usage and gl_ClipDistance[] be similar
边栏推荐
- Lambda&Stream
- [control] multi agent system summary. 1. system model. 2. control objectives. 3. model transformation.
- Connect to the database and run node JS running database shows that the database is missing
- Preorder traversal of Li Kou 589:n fork tree
- Unreal 4 unavigationsystemv1 compilation error
- Unity3d Google Earth
- 力扣27. 移除元素
- C # equipment synthesis
- Detailed explanation of sorting sort method of JS array
- Spring Festival Tourism Strategy: welcome the new year in Bangkok, Thailand
猜你喜欢

What is multimodal interaction?

Force buckle 59 Spiral matrix II

Writing unityshader with sublimetext

Spring Festival Tourism Strategy: welcome the new year in Bangkok, Thailand

Unity Logitech steering wheel access

Procedural animation -- inverse kinematics of tentacles

Exploration of unity webgl

Unity3d Google Earth

Solution to Autowired annotation warning

【Paper】2017_ Distributed control for high-speed trains movements
随机推荐
Four methods of unity ugui button binding events
Check London attractions suitable for parents and children in winter vacation
Unreal 4 learning notes - Animated Montage
【Paper】2017_ Distributed control for high-speed trains movements
Tcp/ip protocol details Volume I (Reading Guide)
Passing values between classes using delegates and events
Singleton mode in unity
MySQL查询小工具(一)json格式的字符串字段中,替换json数组中对象的某个属性值
Unity/ue reads OPC UA and OPC Da data (UE4)
Pourquoi l'ordinateur n'a - t - il pas de réseau après l'ouverture du Hotspot win10?
0 foundation starts self-study unit notes control direction becomes larger
力扣292周赛题解
003-JS-DOM-Attr-innerText
What is multimodal interaction?
JPA composite primary key usage
Photon pun refresh hall room list
Modbus protocol register
Redis cluster concept
Free travel recommendation in Bangkok: introduction to the Mekong River in Bangkok
svg和canvas的区别