Introduction
A key part of using graphics libraries is dealing with a graphics API.
a graphics API is a set of functions that perform basic operations such as drawing images and 3D surfaces into windows on the screen.
two related APIs: a graphics API for visual output and a user-interface API to get input from the user.
the drawing commands are part of a software library tied to a language such as C++.
Graphics Pipeline
Every desktop computer today has a powerful 3D graphics pipeline. This is a special software/hardware subsystem that efficiently draws 3D primitives in perspective.
these systems are optimized for processing 3D triangles with shared vertices.
z-buffer, which uses a special memory buffer to solve the problem in a
brute-force manner.
This 4D coordinate system is one of the most subtle and beautiful constructs used in computer science
The speed at which images can be generated depends strongly on the number of triangles being drawn.
it is worthwhile to minimize the number of triangles used to represent a model.
if the model is viewed in the distance, fewer triangles are needed than when the model is viewed from a closer distance. This suggests that it is useful to represent a model with a varying level of detail (LOD).
Numerical Issues
three “special” values for real numbers in IEEE floating-point:
1. Infinity (∞). This is a valid number that is larger than all other valid numbers.
2. Minus infinity (−∞). This is a valid number that is smaller than all other valid numbers.
3. Not a number (NaN). This is an invalid number that arises from an operation with undefined consequences, such as zero divided by zero.
IEEE floating-point 常用的运算公式:
1. Any arithmetic expression that includes NaN results in NaN.
2. Any Boolean expression involving NaN is false.
Efficiency
heuristic : 启发式算法
a memory access pattern : the pattern with which a system or program reads and writes memory on secondary storage.
未来需要更注重内存读取模式 而非 运算次数,考量算法的效率。
因为,对存储器的读取速度跟不上处理器的提升速度,所以对内存读取的优化才是重中之重。
应该采取的方法有:
1. Compute intermediate results as needed on the fly rather than storing them
2. Compile in optimized mode.(???)
3. Use whatever profiling tools exist to find critical bottlenecks.
4. Examine data structures to look for ways to improve locality. If possible, make data unit sizes match the cache/page size on the target architecture.
5. If profiling reveals bottlenecks in numeric computations, examine the assembly code generated by the compiler for missed efficiencies. Rewrite source code to solve any problems you find.(Is really hard)
time spent upfront optimizing code is usually better spent correcting bugs or adding features;
beware of suggestions from old texts;
profiling is needed to be sure of the merit of any optimization for
a specific machine and compiler.
Designing and Coding Graphics Programs
locations and displacement debate
一些重要的类:vector2;vector3;hvector(4*1);rgb;transform(4*4 matrix);image(2D array of RGB pixels).
Efficiency suggests using single-precision data, while avoiding numerical problems suggests using double-precision arithmetic.
use traditional debuggers less and less. Because using such debuggers is more awkward for complex programs than for simple programs; the most difficult errors are conceptual ones.
omit