现在的位置: 首页 > 综合 > 正文

OpenGL 进化史

2018年05月27日 ⁄ 综合 ⁄ 共 8133字 ⁄ 字号 评论关闭

选自 Graphcs shaders : Theory  and practice 2

OpenGL 2.0/GLSL 1.10

This version of OpenGL introduces shader-based graphics programming,
including programmable vertex and fragment shaders and the GLSL language. Each of these is the

subject of a later chapter in this book.These shaders restore an enormous amount of flexibility and creativity to

OpenGL graphics programming, and in some sense all the later OpenGL

developments are mainly evolutions of this approach. This version includes a
few of these evolutionary steps, including
Vertex buffer objects let you store vertex arrays in graphics memory to
reduce the amount of communication needed between the CPU and card.
Occlusion queries let you ask how many pixels a particular scene element
would occupy if displayed.
Texture-mapped point sprites let you create many small 2D objects for
uses such as particle systems.
Separate stencil operations for front and back faces give you better support
for shadowing.
OpenGL 3.x/GLSL 3.30
OpenGL 3.0 and GLSL 3.00 is a major revision in the standard that reflected
the growing processing power in graphics cards. It introduces geometry shaders,
the next development in shader technology and the subject of Chapter 12.
It also includes several new types of objects to store structured data on the
graphics card.
Frame buffer objects let you render into non-displayable buffers for such
uses as render-to-texture.
Texture buffer objects allow you to use much larger texture arrays.
Uniform buffer objects let you define a collection of uniform variables so
that you can quickly switch between different sets of uniform variables
(typically different ways to present a set of primitives) in a single program
object or share the same set of uniform variables between different
program objects.
All OpenGL buffer objects share the capability to replace a range of data in the
buffer instead of having to replace the data one item at a time.

The OpenGL 3.* and GLSL 3.30 standards also add several new capabilities
not available in earlier versions:
For textures, you can now define a texture array (sometimes called an
array texture) that contains a sequence of 1D or 2D textures of the same
size, so you can use different textures without having to do multiple texture
bindings.
You can use rectangular textures, which can be useful for
video processing, though these do not have bias or level-of-detail capability.
You can also query the size of a texture with the new textureSize( )
function.

• When variables are interpolated in the fragment shader, you can choose

different interpolation techniques with the interpolation qualifiers centroid,
flat, invariant, or nonperspective
. The differences are discussed in Chapter 8.
• There is now a layout qualifier that can be applied to either in or out variables
for some shaders. This qualifier’s effect varies considerably between
shader types, but it includes specifying the position of a vertex shader
input variable in an array, defining the input and output properties for a
geometry shader, or the input coordinates of a pixel in a fragment shader.
16-bit floats and 16-bit floating point variables are added, which have less
precision than 32-bit floats but are more compact and faster to compute.
This version also includes significant revisions of the GLSL standard,
moving it away from fixed-function OpenGL by deprecating a number of
capabilities that mirrored fixed-function operations. Because of the large number
of applications that were built with earlier versions of OpenGL and GLSL,
however, this version also supports compatibility mode operation that lets
you use these earlier versions. This book uses GLSL 4.1, but we include several
notes in the appropriate chapters that describe compatibility-mode alternatives.
These notes are marked with flags like the one in the margin. Among the
capabilities that have been deprecated are
• any use of the fixed-function vertex or fragment operations; you now
need to use shaders for everything,
• the use of glBegin / glEnd to define primitives; you now need to use vertex
arrays and vertex buffers for your geometry,
• use of quad or polygon primitives; you now only use triangles,
• use of display lists; you now use vertex arrays and vertex buffers,
• use of most of the built-in attribute and uniform variables in GLSL; you
now need to define all these in your application and pass them all into
your shaders.
While these features are deprecated, and are thus not guaranteed to be available
in all future versions, you really need not be afraid to use them. They are
said to be going away “at some future time,” but there is some feeling that this
might end up meaning, “when the sun burns itself out.”

OpenGL 4.0/GLSL 4.00
OpenGL 4.0 introduces the final kind of shaders discussed in this book: tessellation
shaders. These let you generate new geometry to provide greater detail
in your geometry, and are covered in Chapter 13. One object of this version

is to implement shader model 5 by applying more of an object model to the

GLSL shader language. This includes such features as shader subroutines, giving
you runtime selection of the particular function to be called so you can
keep multiple ways of doing things in a single shader.
GLSL 4.00 includes significant developments for geometry shaders,
which are discussed in more detail in Chapter 12. You can now have multiple
iterations of a single geometry shader to create multiple instances of the
shader, letting you recursively subdivide geometry primitives. You can also
create multiple vertex streams from a geometry shader, with the first stream
being the normal output to primitive assembly and the rasterizer, and with
additional streams going to transform feedback objects.
Texture interpolation is enhanced in GLSL 4.00. It includes the
texture
gather operation, returning the four texel values that would be returned by
standard texel interpolation so that you can apply your own interpolation to
them
.
The GLSL compiler is designed to optimize expressions for the sake of
efficiency, but the optimization makes it impossible to know exactly how an
expression is implemented. GLSL 4.00 introduces the invariant qualifier for
a variable that requires the compiler to compute the same variable expression
the same way in two different shaders. This lets you maintain computational
consistency in multipass algorithms.
With GLSL 4.00, the shader language becomes even more C-like. You
finally get the functionality of the #include statement, you get full 64-bit IEEE
floating point variables
with the keyword double, function overloading, and
you get a wider set of implicit type conversions, including float → double,
int → double, uint → double, and int → int. You also get a new operator,
the fused multiply-add, written as fma(a,b,c);this performs the operation
(a*b)+c with a single operation and no loss of precision.
OpenGL 4.x/GLSL 4.x0
OpenGL 4.x and GLSL 4.x0 are probably best characterized by the way they
increase the generality of shader operations. They support shader binaries, precompiled
shaders that can be written to a file and loaded separately to save
recompilation, as well as separable shader pipeline stages, linking shaders to
a shader program at runtime
so you can select different shader stages then.
This standard level also supports viewport arrays, supporting drawing into
multiple viewports by allowing the geometry shader to select which viewport
to render into
.
One of the newest features in OpenGL 4.x and GLSL 4.x0 is the ability to
generate “side effects.” GLSL programs can now read and write to image tex

tures and can perform atomic arithmetic operations in uniform buffers. (This
should keep algorithm developers busy for some time!)
The other key feature of this standard is its relation to OpenGL ES 2.0.
The growing importance of OpenGL ES has made it important to support
application development for both desktop and embedded systems, and this
standard release makes desktop OpenGL a proper superset of OpenGL ES 2.0.
That is, if you develop for OpenGL ES 2.0, your application will run correctly
with OpenGL 4.x and GLSL 4.x0
.
Finally, this standard extends the 64-bit floating point capability to vertex
shader input variables
(that is, to attribute and uniform variables), allowing
you to do your application computation in double precision and maintain that
precision when your data is sent to the shaders.

OpenGL ES
OpenGL ES 2.0 is designed to support high-quality graphics on embedded
systems such as cell phones. It is based on OpenGL 2.0, but does not support
any fixed-function operations—all the vertex and fragment processing must
be done with shaders. It also does not support tessellation and geometry shaders,
just vertex and fragment shaders.
The key issue with embedded systems is the need to operate with limited
memory sizes and limited computing capabilities. Supporting the full set of
fixed-function operations requires a significant memory overhead, but using
shaders only requires memory for the data and operations you actually use.
Only vertex and fragment shaders are supported, however, because geometry
and tessellation shaders may expand the input geometry and require additional
memory.
The OpenGL ES shading language is more restrictive than the GLSL 1.10
that is associated with OpenGL 2.0, however. It does not include the set of

built-in attribute and uniform variables of GLSL 1.10, but requires you to create
your own variables as needed. This is similar to GLSL 3.30, and in fact
GLSL 4.10 is a proper superset of the OpenGL ES shader language 1.10—if you
write a shader program in OpenGL ES, it will run with OpenGL 4.1.

抱歉!评论已关闭.