Replace invalid characters with HTML entities
— with — ’ with ’ + with + × with x ç with ç “ with “ ” with ” ‘ with ‘ • with • – with - µ with µ † with † Fix C++ θ with θ Yen symbol instead of times Fix broken apos Bullet again E-circumflex
This commit is contained in:
parent
9e52de9586
commit
500e7f5654
353 changed files with 5091 additions and 5091 deletions
24
40-04.html
24
40-04.html
|
|
@ -41,16 +41,16 @@
|
|||
<P>The set of V-shaped polygons drawn by Listing 40.4 demonstrate that polygons sharing common edges meet but do not overlap. This characteristic, which I discussed at length in Chapter 38, is not a trivial matter; it allows polygons to fit together without fear of overlapping or missed pixels. In general, Listing 40.1 guarantees that polygons are filled such that common boundaries and vertices are drawn once and only once. This has the side-effect for any individual polygon of not drawing pixels that lie exactly on the bottom or right boundaries or at vertices that terminate bottom or right boundaries.</P>
|
||||
<P>By the way, I have not seen polygon boundary filling handled precisely this way elsewhere. The boundary filling approach in Foley and van Dam is similar, but seems to me to not draw all boundary and vertex pixels once and only once.</P>
|
||||
<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">More on Active Edges</FONT></H4>
|
||||
<P>Edges of zero height—horizontal edges and edges defined by two vertices at the same location—never even make it into the GET in Listing 40.1. A polygon edge of zero height can never be an active edge, because it can never intersect a scan line; it can only run along the scan line, and the span it runs along is defined not by that edge but by the edges that connect to its endpoints.
|
||||
<P>Edges of zero height—horizontal edges and edges defined by two vertices at the same location—never even make it into the GET in Listing 40.1. A polygon edge of zero height can never be an active edge, because it can never intersect a scan line; it can only run along the scan line, and the span it runs along is defined not by that edge but by the edges that connect to its endpoints.
|
||||
</P>
|
||||
<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">Performance Considerations</FONT></H4>
|
||||
<P>How fast is Listing 40.1? When drawing triangles on a 20-MHz 386, it’s less than one-fifth the speed of the fast convex polygon fill code. However, most of that time is spent drawing individual pixels; when Listing 40.2 is replaced with the fast assembly line segment drawing code in Listing 40.5, performance improves by two and one-half times, to about half as fast as the fast convex fill code. Even after conversion to assembly in Listing 40.5, <B>DrawHorizontalLineSeg</B> still takes more than half of the total execution time, and the remaining time is spread out fairly evenly over the various subroutines in Listing 40.1. Consequently, there’s no single place in which it’s possible to greatly improve performance, and the maximum additional improvement that’s possible looks to be a good deal less than two times; for that reason, and because of space limitations, I’m not going to convert the rest of the code to assembly. However, when filling a polygon with a great many edges, and especially one with a great many active edges at one time, relatively more time would be spent traversing the linked lists. In such a case, conversion to assembly (which does a very good job with linked list processing) could pay off reasonably well.</P>
|
||||
<P>How fast is Listing 40.1? When drawing triangles on a 20-MHz 386, it’s less than one-fifth the speed of the fast convex polygon fill code. However, most of that time is spent drawing individual pixels; when Listing 40.2 is replaced with the fast assembly line segment drawing code in Listing 40.5, performance improves by two and one-half times, to about half as fast as the fast convex fill code. Even after conversion to assembly in Listing 40.5, <B>DrawHorizontalLineSeg</B> still takes more than half of the total execution time, and the remaining time is spread out fairly evenly over the various subroutines in Listing 40.1. Consequently, there’s no single place in which it’s possible to greatly improve performance, and the maximum additional improvement that’s possible looks to be a good deal less than two times; for that reason, and because of space limitations, I’m not going to convert the rest of the code to assembly. However, when filling a polygon with a great many edges, and especially one with a great many active edges at one time, relatively more time would be spent traversing the linked lists. In such a case, conversion to assembly (which does a very good job with linked list processing) could pay off reasonably well.</P>
|
||||
<P><B>LISTING 40.5 L40-5.ASM</B></P>
|
||||
<!-- CODE //-->
|
||||
<PRE>
|
||||
; Draws all pixels in the horizontal line segment passed in, from
|
||||
; (LeftX,Y) to (RightX,Y), in the specified color in mode 13h, the
|
||||
; VGA’s 320x200 256-color mode. No drawing will take place if
|
||||
; VGA’s 320x200 256-color mode. No drawing will take place if
|
||||
; LeftX > RightX. Tested with TASM
|
||||
; C near-callable as:
|
||||
; void DrawHorizontalLineSeg(Y, LeftX, RightX, Color);
|
||||
|
|
@ -71,36 +71,36 @@
|
|||
public _DrawHorizontalLineSeg
|
||||
align 2
|
||||
_DrawHorizontalLineSeg proc
|
||||
push bp ;preserve caller’s stack frame
|
||||
push bp ;preserve caller’s stack frame
|
||||
mov bp,sp ;point to our stack frame
|
||||
push di ;preserve caller’s register variable
|
||||
push di ;preserve caller’s register variable
|
||||
cld ;make string instructions inc pointers
|
||||
mov ax,SCREEN_SEGMENT
|
||||
mov es,ax ;point ES to display memory
|
||||
mov di,[bp+LeftX]
|
||||
mov cx,[bp+RightX]
|
||||
mov di,[bp+LeftX]
|
||||
mov cx,[bp+RightX]
|
||||
sub cx,di ;width of line
|
||||
jl DrawDone ;RightX < LeftX; no drawing to do
|
||||
inc cx ;include both endpoints
|
||||
mov ax,SCREEN_WIDTH
|
||||
mul [bp+Y] ;offset of scan line on which to draw
|
||||
mul [bp+Y] ;offset of scan line on which to draw
|
||||
add di,ax ;ES:DI points to start of line seg
|
||||
mov al,byte ptr [bp+Color] ;color in which to draw
|
||||
mov al,byte ptr [bp+Color] ;color in which to draw
|
||||
mov ah,al ;put color in AH for STOSW
|
||||
shr cx,1 ;# of words to fill
|
||||
rep stosw ;fill a word at a time
|
||||
adc cx,cx
|
||||
rep stosb ;draw the odd byte, if any
|
||||
DrawDone:
|
||||
pop di ;restore caller’s register variable
|
||||
pop bp ;restore caller’s stack frame
|
||||
pop di ;restore caller’s register variable
|
||||
pop bp ;restore caller’s stack frame
|
||||
ret
|
||||
_DrawHorizontalLineSeg endp
|
||||
end
|
||||
|
||||
</PRE>
|
||||
<!-- END CODE //-->
|
||||
<P>The algorithm used to X-sort the AET is an interesting performance consideration. Listing 40.1 uses a bubble sort, usually a poor choice for performance. However, bubble sorts perform well when the data are already almost sorted, and because of the X coherence of edges from one scan line to the next, that’s generally the case with the AET. An insertion sort might be somewhat faster, depending on the state of the AET when any particular sort occurs, but a bubble sort will generally do just fine.
|
||||
<P>The algorithm used to X-sort the AET is an interesting performance consideration. Listing 40.1 uses a bubble sort, usually a poor choice for performance. However, bubble sorts perform well when the data are already almost sorted, and because of the X coherence of edges from one scan line to the next, that’s generally the case with the AET. An insertion sort might be somewhat faster, depending on the state of the AET when any particular sort occurs, but a bubble sort will generally do just fine.
|
||||
</P><P><BR></P>
|
||||
<CENTER>
|
||||
<TABLE BORDER>
|
||||
|
|
|
|||
Loading…
Reference in a new issue