您的位置:首页 > 运维架构

OpenGL Insights 一本不错的新书

2012-09-03 14:57 337 查看



OpenGL
Insights

OpenGL, OpenGL ES, and WebGL community experiences



 

Assembling contributions from experienced developers, hardware vendors, researchers, and educators, OpenGL
Insights present real-world techniques for intermediate and advanced OpenGL, OpenGL ES, and WebGL developers. Focusing on current and emerging techniques for the OpenGL family of APIs, the book demonstrates the breadth and depth of OpenGL. Readers will
gain practical skills to solve problems related to performance, rendering, profiling, framework design, and more. The text is complemented by an enclosed poster detailing the OpenGL pipeline. 





OpenGLglCreateShaderProgram may provide faster build performance than a sequence of glCompilerShader and glLinkProgram.
However, it only creates a single shader stage program.
OpenGL

WebGL

OpenGL ES
Not all shader objects need a main() function. Multiple shader objects can be linked together in the same program to allow sharing the same code between different programs.
OpenGL

WebGL

OpenGL ES
Build all GLSL shaders and programs first, and then query the results to hide build and query latency.
OpenGL

WebGL

OpenGL ES
Call glDeleteShader after attaching a shader to a program to simplify cleanup later.
OpenGLFive OpenGL 4.2 functions generate info logs:
glCompileShader
glCreateShaderProgram
glLinkProgram
glValidateProgram
glValidateProgramPipeline
OpenGL

OpenGL ES
Functions like glGenTextures do not create an object, they return a name for use with a new object. Objects are typically created with glBind* unless
they are based on direct state access, in which case any other function may actually create the object.
OpenGL

WebGL

OpenGL ES
glGenerateMipmap may execute on the CPU, and therefore may be especially slow. Generate mipmaps offline or profile this function.
OpenGL

WebGL

OpenGL ES
When using the default texture scanline alignment, GL_PACK_ALIGNMENT, of four bytes, with glTexImage2D or glTexSubImage2D,
the end of each row of pixel data may need to be padded to the next multiple of the alignment.
OpenGLInteger textures, GL_EXT_texture_integer, do not support filtering.
OpenGLA buffer texture is a 1D texture with a buffer object as storage which can only be fetched, not sampled.
OpenGL

WebGL

OpenGL ES
Unmap buffers as soon as possible to allow the driver to start the transfer or to schedule the transfer.
OpenGL

WebGL

OpenGL ES
Use buffer usage flags appropriately: COPY, GL to GL; DRAW, APP to GL; READ,
GL to APP; STREAM, update always, DYNAMIC, update often, STATIC, update rarely.
OpenGL

WebGL

OpenGL ES
Set a GLSL sampler uniform to the texture unit number, not the OpenGL texture ID.
OpenGL

WebGL

OpenGL ES
glGetUniformLocation returns −1 but doesn’t generate an error if the uniform name does not correspond to an active uniform. All declared uniforms are not active; uniforms
that do not contribute to the shader's output can be optimized out by the compiler.
OpenGLAn OpenGL context must always be current for the duration of Op
c9d8
enGL/compute interoperability.
OpenGLAn OpenGL object should not be accessed by OpenGL while it is mapped for usage within the compute portion.
OpenGL

WebGL

OpenGL ES
Avoid extraneous glBindFramebuffer calls. Use multiple attachments to a FBO rather than managing multiple FBOs.
OpenGL

WebGL

OpenGL ES
FBOs must always be validated before use to ensure that the selected format is renderable.
OpenGLOnly one OpenGL query per query type, e.g., timer or occlusion, can be active at a time.
OpenGLFor occlusion queries, using GL_ANY_SAMPLES_PASSED may be more effective than GL_SAMPLES_PASSED, as a rendering
doesn't have to continue as soon as one fragment passed.
OpenGL

WebGL

OpenGL ES
For image-space rendering on GPUs with a large clipping guard band clipping, e.g., GeForce, Radeon, and PowerVR series 6 use a large clipped triangle instead of a quad. Measure both if in doubt.
OpenGL

WebGL

OpenGL ES
To test vertex throughput, do not render to a 1×1 viewport because parallelism is lost; instead, render outside of the view frustum.
OpenGL

WebGL

OpenGL ES
glGetError is particularly slow, especially in multi-process WebGL architectures. Only use it in debug builds or instead use GL_ARB_debug output when available.
OpenGLGeometry shaders are usually output bound so spending ALU time to reduce the amount of data output is a performance win.
WebGLIn addition to #defining GL_OES_standard_derivatives before usingdFdx, dFdy,
and fwidth, also remember to callcontext.getExtension("OES standard derivatives") in JavaScript.
OpenGL

WebGL

OpenGL ES
To accurately compute the length of a gradient, avoid fwidth(v); instead usesqrt(dFdx(v) * dFdx(v) + dFdy(v) * dFdy(v)).
WebGL

OpenGL ES
highp is only available in fragment shaders ifGL_FRAGMENT_PRECISION_HIGH is #defined. Beware of the performance
implications of using highp in vertex or fragment shaders.
OpenGLIn OpenGL, precision qualifiers were reserved in GLSL 1.20 and OpenGL 2.1 but actually introduced with GLSL 1.30 and OpenGL 3.0. From GLSL 1.40 and OpenGL 3.1, and for the purpose of convergence with OpenGL ES 2.0,GL_FRAGMENT_PRECISION_HIGH is
defined as 1 in a fragment shader.
OpenGLBy default, precision for vertex, tessellation, and geometry shader stages ishighp for int types, and mediump for
the fragment shader stage int types. This may lead to warnings on some implementations. float is always highp by
default.
WebGLGiven a WebGL context gl, gl.TRUE is undefined. When porting OpenGL or OpenGL ES code, do not change GL_TRUE to gl.TRUE because
it will silently evaluate to false.
OpenGL

WebGL

OpenGL ES
Depth writes only occur if GL_DEPTH_TEST is enabled.
OpenGL

WebGL

OpenGL ES
The noise functions are still unimplemented in GLSL. Chapter 7 fixes this.
OpenGLgl_VertexID gets values in [first, first+count-1] when generated from a DrawArray* command,
and not in [0, count-1]. Especially useful when using a zero input attributes vertex shader.
OpenGLThere are two ways to work with point size: glPointSize in the client-side code or gl_PointSize in the GLSL
code if PROGRAM_POINT_SIZE is enabled.
源码地址:https://github.com/OpenGLInsights/OpenGLInsightsCode

---

准备上Amazon买本,不知道要多久才会到
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息