graphics programming black book

Post on 12-Nov-2014

169 Views

Category:

Documents

16 Downloads

Preview:

Click to see full reader

DESCRIPTION

Michael Abrash's Graphics Programming Black Book is a collection of the author's previous books on assembly language and graphics programming, as well as past columns for Dr. Dobb's magazine. Though much of the book (such as 8088/286/386 assembly language optimization and VGA graphics programming) is out-of-date by now, the reader can see some of the larger tendencies in the author's work over the years--a reliance on profiling in order to test code, and creative thinking to improve performance wherever possible. This text features assembler optimization for a variety of problems including searching algorithms, and records the author's approaches to optimizing code for the evolving line of Intel CPUs, from the 8088 on to the early Pentium lines. The last few chapters of this book are more relevant, and include a series of explorations of some of the technology behind the popular Doom and Quake 3-D games by id Corporation (where the author worked). Optimized solutions to 3-D graphics problems from texture mapping, hidden surface removal, and Binary Space Partitioning (BSP) trees are explained. Current gaming and 3-D technology, such as Direct3D and VRML is left out, but it's clear that game programmers like the author will continue to push the limits of current hardware technology in inventive ways. This book is clearly targeted at game developers and serious assembly language programmers, not for the general reader.

TRANSCRIPT

Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

The brute-force searching technique. Figure 5.1

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

HomePrevious Next

Previous Home Next

HomePrevious Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

HomePrevious Next

Data flow through the Graphics Figure 25.1

a lo g Gr p Controller: g 5.

Bit mask operation. Figure 25.2

Data flow during a write mode 0 write operation. Figure 25.3

HomePrevious Next

NextHomePrevious

VGA data flow in write mode 2. Figure 27.1

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

f VGA Color Generation t the VGA’s 4bit to 8-bit to 18-bit color translation. d out how to generate a look-up table containing

efault color palette. And surely they are only the ing programmers from every corner of the planet

are no doubt tearing the place up looking for a discussion of VGA color, and venting their frustration at my mailbox. Let’s have i t, they’ve said, clearly and in considerable

ics might say, who is this humble writer to disagree? hope you all know what you’re getting into. To paraphrase

ter (and more confusing) than the average board. There’s the basic 8-bit to 18-bit translation, there’s the EGA-compatible 4bit to 6-bit translation, there’s the 2- or 4bit color paging register that’s used to pad 6- or 4bit pixel values out to 8 bits, and then there’s 256-color mode. Fear not, it will all make sense in the end, but it may take us a couple of additional chapters to get there-so let’s get started. Before we begin, though, I must refer you to Michael Covington’s excellent article, “Color Vision and the VGA,” in the June/July 1990 issue of PC TECHNIQUES. Michael, one of the most brilliant people it has ever been my pleasure to meet, is an expert in many areas I know nothing about, including linguistics and artificial intelligence. Add to that list the topic of color perception, for his article superbly describes the mechanisms by which we perceive color and ties that information to the VGA’s capa- bilities. After reading Michael’s article, you’ll understand what colors the VGA is capable of generating, and why.

625

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

725

728 Chapter 39

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

e the VGA Really Get up and Dance rmative anecdotes to kick off this chapter; lotta

ground to cover, g re impatient, I can smell it. I won’t talk about the of loudly saying “$100 bill” during an animated dis-

cussion while wa ums on Market Street in San Francisco one night, context is everything. I can’t spare a word about

how my daughter thinks my 11-year-old floppy-disk-based CP/M machine is more 6 with its 100-MB hard disk because the CP/M machine’s word runs twice as fast as the 386’s Windows-based word processor, rogress is not the neat exponential curve we’d like to think it is,

and that features and performance are often conflicting notions. And, lord knows, I can’t take the time to discuss the habits of small white dogs, notwithstanding that such dogs seem to be relevant to just about every aspect of computing, as Jeff Duntemann’s writings make manifest. No lighthearted fluff for us; we have real work to do, for today we animate with 256 colors in Mode X.

Masked Copying Over the past two chapters, we’ve put together most of the tools needed to imple- ment animation in the VGA’s undocumented 320x240 256-color Mode X. We now have mode set code, solid and 4x4 pattern fills, system memory-to-display memory block copies, and display memory-to-display memory block copies. The final piece

91 5

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

's Color Model in an

Once she turned six, my daughter wanted some fairly sophisticated books read to her. Wind in the Willows use on the Prairie. Pretty heady stuff for one so young, and sometimes I wondered how much of it she really understood. As an experiment, during one reading)! stopped whenever I came to a word I thought she might not know, and asked her what it meant. One such word was “mulling.”

ulling’ means?” I asked. r a while, then said, “Pondering.” e than a little surprised.

She smiled and said, “But, Dad, how do you know that I know what ‘pondering’ means?” “Okay,” I said, ‘What does ‘pondering’ mean?” “Mulling,” she said. What does this anecdote tell us about the universe in which we live? Well, it certainly indicates that this universe is inhabited by at least one comedian and one good straight man. Beyond that, though, it can be construed as a parable about the difficulty of defining things properly; for example, consider the complications inherent in the definition of color on a 256-color display adapter such as the VGA. Coincidentally, VGA color modeling just happens to be this chapter’s topic, and the place to start is with color modeling in general.

1033

Previous Home Next

Using Using reverse reverse transformation transformation Figure 56. Using reverse transformation to find the source pixel colol: Figure 56.1

Figure 56.2

Mapping a texture onto an untransformed polygon

Previous Home Next

le of Experience in Implementing Mapping

ning how to shear a sheep. Among other the importance of selecting the proper comb for who holds the world’s record for sheep sheared in serves), and discovered, Lord help me, the many Zealand Sheep Shearing Board improves the a p ry year. The fellow giving the presentation did his n’t very interesting. If you have children, you’ll

f you don’t, there’s no use explaining. one thing that stuck with me, although it may

not sound particularly profound. (Actually, it sounds pretty silly, but bear with me.) He said, ‘You don’t get really good at sheep shearing for 10 years, or 10,000 sheep.” I’ll buy that. In fact, to extend that morsel of wisdom to the greater, non-ovine-cen- tric universe, it actually takes a good chunk of experience before you get good at anything worthwhile-especially graphics, for a couple of reasons. First, performance matters a lot in graphics, and performance programming is largely a matter of expe- rience. You can’t speed up PC graphics simply by looking in a book for a better algorithm; you have to understand the code C compilers generate, assembly lan- guage optimization, VGA hardware, and the performance implications of various graphics-programming approaches and algorithms. Second, computer graphics is a

Fast,

things, I

1063

Previous Home Next

hole-Brain Approach to Accelerate

reading several of the works of Robert A. Heinlein, a teenager-but in a different way. The first time r romance of technology married to powerful sto- l by The Master’s remarkable prescience. ‘‘Blowups lear power, and their effects on human psychol- on had ever happened on this planet. “Solution

out the unsolvable dilemma-ultimate offense, no defense- 941. And in Between Planets (1951), consider this

minor bit of action: The doctor’s phone regretted politely that Dr. Jefferson was not at home and requested him to leave a message. He was dictating it when a warm voice interrupted: ‘I’m at home to you, Donald. Where are you, lad?’

Predicting the widespread use of answering machines is perhaps not so remarkable, but foreseeing that they would be used for call screening is; technology is much easier to extrapolate than are social patterns. Even so, Heinlein was no prophet; his crystal ball was just a little less fuzzy than ours. The aforementioned call in Between Planets was placed on a viewphone; while that technology has indeed come to pass, its widespread use has not. The ultimate weapon

1079

Previous Home Next

1097

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

The substance described by node E.Figure 64.3

Figure 64.4

Previous Home Next

Previous Home Next

Previous Home Next

Previous Home Next

1252 Chapter

68

Previous Home Next

Previous Home Next

matrix math, assembly routines, 992, 996-999

ModelColoffoColorIndex function, ' 1036, 1038 older processors, support for, 1007-

overview, 984-985 POLYG0N.H header file, 982-984 RGB color model

1008, 1008-1023

mapping to 256-color mode, 1036,

overview, 1034-1035 1037-1038, 1039

RotateAndMovePObject function,

XforrnAndProjaect hnction, 974 XformVec function

assembly implementation, 996-997,

C implementation, 976

977-978

1017-1019

XSortAET function complex polygons, 748 monotone-vertical polygons, 769

Y Yaw angle, in polygon clipping, 1206 Y-clipping, in BSP tree rendering, 1159

Z Z-buffers

performance, 1213 Quake 3-D engine, 1285-1286 vs. sorted spans, 1215 sorting moving models, 1212-1213

Z-clipping, in BSP tree rendering, 1158 Zen timer

See also Long-period Zen timer. calling, 48

calling from C code, 69-72 and DRAM refresh, 99 and interrupts, 43 interval length, 45 overhead of, timing, 46, 72 PC compatibility, 48-49 precision, 48, 52 prefetch queue cycle-eater, 88, 92 PS/2 compatibility, 66 PZTEST.ASM listing, 49 PZTIME.BAT listing, 51 PZTIMER.ASM listing, 35-42 ReferenceZTimerOff subroutine, 41 ReferenceZTimerOn subroutine, 40 reporting results, 47 starting, 43 stopping, 46 system clock inaccuracies, 43, 45-46, 48 test-bed program, 48-52 TESTCODE listing, 50 timing 486 code, 245-246 ZTimerOff subroutine, 38-41, 46-47 2TimerOn subroutine, 37-38, 43 ZTimerReport subroutine, 41-42,

47-48 Zero-wait-state memory, 21 1 Z-order display, masked images, 872 Z-sorting, for hidden surface removal,

ZSortObjects function, 1201 ZTimerOff subroutine

1220-1222

long-period Zen timer, 59-63 Zen timer, 38-41, 46-47

ZTimerOn subroutine long-period Zen timer, 58-59 Zen timer, 37-38, 43

ZTimerReport subroutine long-period Zen timer, 63-65 Zen timer, 41-42, 47-48

Index

HomePrevious

top related