OpenGL Programming Guide (2)

1, there are strict regulations on the OpenGL shared edges: 1) because the shared edge of the pixel is covered by both colleagues, and therefore could not be affected by lighting calculations;

                            2) sharing the edge of the pixel values, it can not be affected by more than one triangle lighting calculations.

 

2, the presence of positive and negative polygon, in order to clearly observe the vertices of the polygon, can void glPolygonMode (GLenum face, GLenum mode) drawing mode is provided

   face must be GL_FRONT_AND_BACK, mode can be GL_POINT, GL_LINE, GL_FILL, default is GL_FILL fill mode.

 

3, OpenGL cache type

 

 

 

4, data is written to the cache

 1) void glBufferData (GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); write data in the cache memory is allocated when used, if the data is nullptr a, then memory is allocated only.

 2) void glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); above the write data buffer with respect to the whole, this method is just beginning to write data size size starting at offset.

 3) if you only want to clear the cache data for the object has a value, the following method may be used

   void glClearBufferData(GLenum target, GLenum internalformat, GLenum format, GLenum type, const GLvoid* data)

   void glClearBufferSubData(GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const GLvoid* data)

 4)缓存中的数据可以互相拷贝

   void glCopyBufferSubData(GLenum readtarget, GLenum writetarget, GLintptr readoffset, GLintptr writeoffset, GLsizeiptr size)

 

5、void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid* data)这个方法能够将绑定的缓存目标中的数据读取到data指定的内存中。

 

6、上面介绍的众多方法都有一个问题,都会对指定的数据进行一次拷贝,下面的这个方法将会返回一个指向目标内存的指针

  void* glMapBuffer(GLenum target, GLenum access)

  GLboolean glUnmapBuffer(GLenum target) 如果在映射后target没有发生损坏,将会返回GL_TRUE;发生损坏的原因通常与系统相关,例如屏幕模式发生变化,这将影响图形内容的可用性。

 

7、使用glBufferData 或 glBufferSubData 返回后,可以对返回的内存区域中的数据进行任何操作。也就是说,这些函数在完成后不能与内存区域再有任何瓜葛,因此需要采用数据拷贝的方式。如果使用glMapBuffer,返回的指针是OpenGL端管理,调用glUnmapBuffer时,OpenGL依然管理这个指针指向的内存,而应用程序与这出内存已经没有任何瓜葛。这样的话即使数据需要移动或者拷贝,也是调用glUnmapBuffer之后才执行并且立即返回,而内容操作是在系统的空闲时间之内完成,不在受应用程序的影响。因此,OpenGL的数据拷贝操作与应用程序之后的操作实际上是同步进行的。

 

8、void* glMapBufferRange(GLenum target, Glintptr offset, GLsizeiptr length, GLbitfield access)是相对于上面有着更为严格访问限制的映射方式。

 

9、丢弃缓存数据,使得OpenGL能够完成一些优化工作,如内存紧密等

  void glInvalidateBufferData(Gluint buffer)

  void glInvalidateBufferSubData(GLuint buffer, GLintptr offset, Glsizeiptr length)是唯一一个可以抛弃缓存对象中区域数据的方法。

 

10、绘制命令分为两种:索引形式与非索引形式。所谓的索引意图是在三角形顶点重复的时候通过使用顶点数组中索引来避免顶点数组找那个存在相同的顶点数据。

  void glDrawArrays(GLenum mode, GLint first, GLsizei count)

  void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)

  有许多的绘制命令都是通过以上两个实现的。

  存在两个特殊的绘制命令,它们的绘制参数不是从程序中得到,而是从缓存对象中获得,称之为间接绘制函数。

  1) void glDrawArraysIndirect(GLenum node, const GLvoid* indirect)

  使用它时,必须要将一个缓存对象绑定到GL_DRAW_INDIRECT_BUFFER上,它的特性与glDrawArraysInstanced完全一致。间接绘制缓存的 C 结构体形式如下

  typedef struct DrawArraysIndirectCommand_t

  {

        GLuint count;

        GLuint primCount;//表示多实例的个数

        GLuint first;

        GLuint baseInstance;//多实例顶点属性的偏移

  } DrawArraysIndirectCommand;

 

 2)void glDrawElementsIndirect(GLenum mode, GLenum type, const GLvoid* indirect)

  它的特性与glDrawElements一致,使用限制也是一样的。

  typedef struct DrawElementsIndirectCommand_t

  {

        GLuint count;

        GLuint primCount;

        GLuint firstIndex;

        GLuint baseVertex;

        GLuint baseInstance;

  } DrawElementsIndirectCommand;

 

11、多实例渲染最大的不同在于需要启用多实例顶点属性 void glVertexAttribDivisor(GLuint index, GLuint divisor) 完成这项工作。divisor的值如果是0,那么该属性的多实例特性将被禁用,如果是其它值则是多实例点顶属性的间隔;index表示的是顶点属性的索引位置。vertex shader内存在对应实例id的内置变量 gl_InstanceID,从0开始累加,非多实例渲染时这个值一直保持为0。

 

Guess you like

Origin www.cnblogs.com/haihuahuang/p/12337890.html
Recommended