home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / _SVGALIB.TAR / usr / doc / svgalib / README.gl < prev    next >
Encoding:
Text File  |  1995-01-18  |  14.8 KB  |  380 lines

  1.  
  2. This is a fast framebuffer-level graphics library for linear 1, 2, 3 and 4
  3. byte-per-pixel modes (256-color, hicolor, truecolor). It uses a limited
  4. number of functions from svgalib (libvga) for low-level hardware
  5. communication (the library is included in the svgalib shared image).
  6. In particular, svgalib maps the 64K VGA frame buffer window, and this library
  7. directly addresses the buffer. For SVGA modes that use more than 64K of
  8. screen memory, SVGA paging is required when writing to the physical screen;
  9. this is done automatically for most functions (at a certain cost).
  10. Alternatively, any number of virtual screens of any type in system memory can
  11. be used, which can then be copied to the physical screen. There is also
  12. support for 4 bytes per pixel framebuffers (and copying them to a 3 bytes per
  13. pixel context), and limited planar 256 color mode support (copyscreen,
  14. aligned putbox).
  15.  
  16. The planar 256 color modes (available on all VGA cards) can now be used
  17. with a virtual screen, which is copied to the physical screen (with optional
  18. page-flipping).
  19.  
  20. Bitmaps are raw, with one (or more) bytes per pixel (like pixmaps in X),
  21. stored in row-major order. They are usually manipulated with the getbox
  22. and putbox functions.
  23.  
  24. A graphics context is just a structure that holds the size of the associated
  25. graphics screen, how it is organized, clipping status etc. You can define a
  26. custom virtual (system memory) graphics context of any size with the
  27. setcontextvirtual function. All operations work on the current context.
  28.  
  29. Any questions, bug-reports, additions, suggestions etc. are welcome.
  30.  
  31.  
  32. Functions (all have a "gl_" prefix):
  33.  
  34.     - simple line drawing 
  35.  
  36.     setpixel( int x, int y, int c )
  37.         Draw a single pixel at position (x, y) in color c. The lower
  38.         8, 15, 16 or 24 bits of the color are significant, depending
  39.         on the number of colors the current mode supports. 
  40.  
  41.     setpixelrgb( int x, int y, int r, int g, int b )
  42.         Draw a single pixel at (x, y) with color components r, g,
  43.         and b, ranging from 0 to 255. In 256 color mode, only
  44.         meaningful if the RGB palette is set (setrgbpalette).
  45.  
  46.     int getpixel( int x, int y )
  47.         Returns color of pixel at position (x, y).
  48.  
  49.     getpixelrgb( int x, int y, int *r, int *g, int *b )
  50.         Store color components from pixel at (x, y) ranging from 0
  51.         to 255, into integers pointed to by r, g and b.
  52.  
  53.     int rgbcolor( int r, int g, int b )
  54.         Returns pixel value that corresponds with the given color
  55.         components. Used by setpixelrgb.
  56.  
  57.     line( int x1, int y1, int x2, int y2, int c )
  58.         Draw a line from (x1, y1) to (x2, y2) inclusive in 
  59.         color c.
  60.  
  61.     hline( int x1, int y, int x2, int c )
  62.         Draw a horizontal line from (x1, y) to (x2, y) in color c.
  63.  
  64.     circle( int x, int y, int r, int c )
  65.         Draw a circle of radius r in color c.
  66.  
  67.  
  68.     - box (bitmap) functions 
  69.  
  70.     fillbox( int x, int y, int w, int h, int c )
  71.         Screen position (x, y), box size (w, h).
  72.         Fill a rectangular area of the screen with a single color.
  73.  
  74.     getbox( int x, int y, int w, int h, void *dp )
  75.         Bitmap data pointer dp. Bitmaps are in row-major order.
  76.         Copy a rectangular bitmap from the screen to a buffer.
  77.  
  78.     putbox(    int x, int y, int w, int h, void *dp )
  79.         Bitmap data pointer dp.
  80.         Copy a bitmap to a rectangular area of the screen.
  81.  
  82.     putboxpart( int x, int y, int w, int h, int bw, int bh, void *bp,
  83.     int xo, int yo )
  84.         Copy a partial bitmap to the screen. (w, h) is the size
  85.         of the partial bitmap, (bw, bh) that of the source bitmap,
  86.         and (xo, yo) is the offset in pixels into the source bitmap.
  87.  
  88.     putboxmask( int x, int y, int w, int h, void *dp )
  89.         As putbox, but do not write bitmap pixels of color zero.
  90.  
  91.     copybox( int x1, int y1, int w, int h, int x2, int y2 )
  92.         Copy the rectangular area at (x1, y1) of size (w, h),
  93.         to (x2, y2) (bitblit).
  94.  
  95.     copyboxtocontext( int x1, int y1, int w, int h, GraphicsContext *gc,
  96.     int x2, int y2 )
  97.         Copy the rectangular area at (x1, y1) of size (w, h), to
  98.         position (x2, y2) in the context gc.
  99.  
  100.     copyboxfromtocontext( GraphicsContext *gc, int x1, int y1, int w,
  101.     int h, int x2, int y2 )
  102.         Copy the rectangular area at (x1, y1) in the context gc, of
  103.         size (w, h), to position (x2, y2) in the current context.
  104.         This is more efficient than copyboxtocontext.
  105.  
  106.  
  107.     - compiled bitmaps (linear 256 color mode only)
  108.  
  109.     compileboxmask( int w, int h, void *sdp, void *ddp )
  110.         Convert rectangular masked bitmap of size (w, h) at sdp to
  111.         a compressed format that allows faster drawing, which is
  112.         stored at ddp. Allocating w * h bytes for the compiled
  113.         version is usually enough; an upper limit should be 
  114.         (w + 2) * h.
  115.  
  116.     int compiledboxmasksize( int w, int h, void *sdp )
  117.         Returns the size of the compiled version of the masked
  118.         bitmap of size (w, h) at sdp that will be generated by
  119.         compileboxmask.
  120.  
  121.     putboxmaskcompiled( int x, int y, int w, int h, void *dp )
  122.         Write compiled bitmap to screen. This is significantly
  123.         faster than non-compiled masked bitmaps, especially for
  124.         sparse bitmaps.
  125.  
  126.  
  127.     - clipping
  128.     
  129.     enableclipping()
  130.         Enable automatic clipping in most functions.
  131.  
  132.     disableclipping()
  133.         Disable clipping.
  134.  
  135.     setclippingwindow( int x1, int y1, int x2, int y2 )
  136.         Set the clipping window to the rectangle with top-left
  137.         corner (x1, y1) and bottom-right corner (x2, y2) (incl.).
  138.  
  139.  
  140.     - graphics contexts and virtual screens
  141.  
  142.     setcontextvga( int mode )
  143.         Set the graphics context to the physical screen of a
  144.         vga mode (as defined in svgalib). The mode must be set
  145.         first. The only thing you can do with a planar (mode X-like)
  146.         256 color mode is aligned putbox, and use it as a target for
  147.         copyscreen.
  148.  
  149.     setcontextvgavirtual( int mode )
  150.         Allocate a virtual screen in system memory identical to
  151.         the graphics mode, and make that the current graphics
  152.         context.
  153.  
  154.     setcontextvirtual( int w, int h, int bpp, int bitspp, void *vbuf )
  155.         Define the current graphics context to have a width of w
  156.         pixels, height h, bpp bytes per pixel, bitspp significant
  157.         color bits per pixel (8, 15, 16 or 24), with the framebuffer
  158.         at vbuf. A 4 bytes per pixel context, with 24 significant
  159.         color bits is also valid.
  160.  
  161.     getcontext( GraphicsContext *gc )
  162.         Save the current context in a structure variable.
  163.  
  164.     setcontext( GraphicsContext *gc )
  165.         Restore a previously saved context (make it the current
  166.         context).
  167.  
  168.     freecontext( GraphicsContext *gc )
  169.         Free the space allocated for the virtual screen in the
  170.         given context.
  171.  
  172.     copyscreen( GraphicsContext *gc )
  173.         Copy the current graphics context contents (screen data) to
  174.         the specified graphics context (the physical screen, for
  175.         example). Contexts are assumed to be identical in size.
  176.  
  177.     setscreenoffset( int o )
  178.         Set the offset in pixels into video memory for copyscreen
  179.         and copyboxtoscreen, allows for page-flipping. Must be a
  180.         multiple of the scanline width in bytes. It is reset to
  181.         zero after completion of copyscreen.
  182.  
  183.     int enablepageflipping( GraphicsContext *gc )
  184.         Enable page flipping or triple buffering in copyscreen if
  185.         the physical context gc can do it. Returns 3 if triple
  186.         buffering will be used, 2 for page flipping, 0 if page
  187.         flipping is not possible (due to video memory/mode
  188.         limitations). When pageflipping is enabled, the screenoffset
  189.         is ignored in copyscreen.
  190.  
  191.  
  192.     - text writing, font handling
  193.  
  194.     setfont( int fw, int fh, void *fp )
  195.         Use the font stored as character bitmaps at fp, with 
  196.         characters of size (fw, fh), as the basic font for write
  197.         operations. Note that the font included in the library must
  198.         be expanded first, because it is stored bit-per-pixel;
  199.         this is not required if the FONT_COMPRESSED writemode
  200.         flag is set.
  201.  
  202.     setwritemode( int m )
  203.         Sets writemode flags. If WRITEMODE_MASKED is set (as opposed
  204.         to WRITEMODE_OVERWRITE), only foreground pixels of the font
  205.         are used for write operations; the screen background is not
  206.         erased. If FONT_COMPRESSED is set (as opposed to
  207.         FONT_EXPANDED), text writes will use the compressed
  208.         bit-per-pixel font rather than the expanded font.
  209.  
  210.     write( int x, int y, char *s )
  211.         Write string s at (x, y) using currently selected font.
  212.  
  213.     writen( int x, int y, int n, char *s )
  214.         Write n character string s at (x, y).
  215.  
  216.     expandfont( int fw, int fh, int c, void *sfp, void *dfp )
  217.         Convert bit-per-pixel font at sfp, with characters of size
  218.         (fw, fh), to an expanded font of character bitmaps, stored at
  219.         dfp (size will be 256 * fw * fw * BYTESPERPIXEL). All
  220.         non-zero pixels are set to color c.
  221.  
  222.     colorfont( int fw, int fh, int c, void *fp )
  223.         Set all nonzero pixels in the expanded font to color c.
  224.  
  225.     setfontcolors( int bg, int fg )
  226.         Set the background and foreground colors for the compressed
  227.         font write mode.
  228.  
  229.  
  230.     - VGA 256-color palette handling
  231.  
  232.     These functions are only valid in 256-color modes.
  233.  
  234.     getpalettecolor( int c, int *r, int *g, int *b )
  235.         Get red, green and blue values (in the range 0-63) of 
  236.         color c from the color-lookup-table, and store them as
  237.         integers in the memory locations pointed to by r, g and b.  
  238.  
  239.     setpalettecolor( int c, int r, int g, int b )
  240.         Set RGB values (0-63) for color c.
  241.  
  242.     getpalettecolors( int s, int n, void *dp )
  243.         Get RGB values of n colors starting at s, which are stored
  244.         as a table of groups of three bytes at dp. 
  245.  
  246.     setpalettecolors( int s, int n, void *dp )
  247.         Set RGB values of n colors starting at color s.
  248.  
  249.     getpalette( void *p )
  250.         Equivalent to getpalettecolors(0, 256, p).
  251.  
  252.     setpalette( void *p )
  253.         Equivalent to setpalettecolors(0, 256, p).
  254.  
  255.     setrgbpalette()
  256.         Set 256-color RGB palette (bits 0-2 blue, 3-5 green,
  257.         6-7 red). Use with setpixelrgb.
  258.  
  259.  
  260.     - miscellaneous
  261.  
  262.     clearscreen( int c )
  263.         Fill the entire screen with color c.
  264.  
  265.     scalebox( int w1, int h1, void *sdp, int w2, int h2, void *ddp )
  266.         Scale the bitmap of size (w1, h1) at sdp to size (w2, h2)
  267.         and store it at ddp, which must be a large enough buffer.
  268.         The pixel size of the current graphics context is used.
  269.  
  270.     setdisplaystart(int x, int y)
  271.         Set the physical display start address to the pixel at (x,
  272.         y). Can be used for hardware scrolling, or for page flipping
  273.         (e.g. setdisplaystart(0, HEIGHT) displays from the second
  274.         page). Make sure the scanline width (BYTEWIDTH) in bytes
  275.         of the current context corresponds with the physical
  276.         screen.
  277.  
  278.  
  279. Macros defined in vgagl.h:
  280.  
  281.     WIDTH        The width in pixels of the current graphics context.
  282.     HEIGHT         Height in pixels.
  283.     BYTESPERPIXEL    Number of bytes per pixel (1, 2, 3 or 4).
  284.     BYTEWIDTH    Width of a scanline in bytes.
  285.     COLORS        Number of colors.
  286.     BITSPERPIXEL    Number of significant color bits.
  287.     VBUF        Address of the framebuffer.
  288.     __clip        Clipping flag.
  289.     __clipx1    Top-left corner of clipping window.
  290.     __clipy1
  291.     __clipx2    Bottom-right corner of clipping window.
  292.     __clipy2
  293.  
  294.  
  295. Use the environment variable GSVGAMODE to select the graphics mode used by
  296. the testgl program (e.g. export GSVGAMODE=G640x480x256).
  297.  
  298. It may be interesting to compare the framebuffer video speeds for certain
  299. modes, especially among Vesa Local Bus cards (even if only 320x200x256
  300. works). There is considerable variation in performance among VLB motherboard
  301. implementations and cards. If you want, you can mail them to me
  302. (hhanemaa@cs.ruu.nl) and I'll collect the results at this place. Please state
  303. CPU, card type/chipset, and bus type (of the card)/(ISA) bus speed.
  304.  
  305. The speedtest program is using aligned REP STOSL (memset), which is
  306. relatively slow on a 486 (4 cycles); unrolled MOV's may be faster. It does
  307. show that many VLB cards have in fact only a 16-bit bus interface (like my
  308. Cirrus 5426 based card). The maximum throughput using STOSL on a 386 (5 
  309. cycles) is about 15M/s at 16-bit VLB 40MHz, 30M/s with 32 bits. Anyone with
  310. an ET4000/W32(i) to show off?
  311.  
  312. The 'fun' program displays a frame rate that is also very dependent on general
  313. memory architecture (it uses two virtual screens). Notice that the frame rate
  314. has a significant variation between runs (up to 15% on my machine), but it
  315. doesn't change within a run. I believe this is because of pages mapping to
  316. the same external cache slot, which happens quite often with a direct mapped
  317. cache (a bad thing for a multi-tasking VM OS). This means that if you were
  318. to run a small but memory-intensive program taking say a day to calculate
  319. something, it would be a good idea to display timed progress information at
  320. the start. Restarting until the speed is good would possibly save several
  321. hours of computation time.
  322.  
  323. Note: there seem to be VLB motherboards around that have problems with
  324. (sound) DMA when writing video data to the local bus (possibly related to
  325. running the VLB in 'slave' mode).
  326.  
  327. Speeds are in MByte/s.
  328.                   bus    256-color        hicolor    truec.
  329. card            system     speed    320x200    640x480    800x600 640x480 640x480
  330. AVGA3, CL-GD5426, VLB    386DX/40  40.0    12.5    13.7    12.8     7.6     4.6
  331. --same, high MCLK    386DX/40  40.0    15.5    15.5    15.5    11.7     8.4
  332. --same          486SX/40  40.0    15.6    15.6    15.6    11.7     8.4
  333. --same, low write delay    486SX/40  40.0       -    19.5       -       -       -
  334. Trident 9000, 512K ISA  386DX/40   8.0     2.1     2.2     2.2       -       -
  335. Trident 8900C, ISA    386DX/33     2.6     3.1     2.1       -       -
  336. Tseng MegaVGA/1024 ISA    486DX/33  13.3     8.5     8.5     8.5     8.5     6.0
  337. --ET4000, AT&T491/2 DAC    386SX/40  10.0     4.8     4.8     4.8     4.8     4.8
  338. Trident 9000, 512K ISA  486DX/33  13.3     2.9     2.3     2.5       -       -
  339. S3-805 VLB (stosl)    486DX2/66 33    10.8       -       -       -       -
  340. --same (stosw)        486DX2/66 33    16.0       -       -       -       -
  341. ATI Ultra Pro EISA    486DX/50   8     6.2     6.2     6.2      6.2    6.2
  342. Morse KP1024 ET4000    486SX/40  10.0   3.8     3.8     3.8
  343. --same            486SX/40  13.3     5.2     5.2     5.2
  344. Oak OTI-087         486DX2/66 33     7.7     6.6     6.7
  345. CL-GD5428 (same mb)    486DX2/66 33     8.0     6.8     6.8
  346. CL-GD5434E VLB 0-wait    486SX/33  33    56.1    56.1    54.2    52.5    48.5
  347. --same, non 0-wait    486SX/33  33        30.2    29.1    28.1    25.4
  348.  
  349. Note
  350.  
  351.     For three bytes per pixel (true color) modes, it is possible that
  352.     pixels cross a SVGA segment boundary. This should be correctly
  353.     handled    by most functions. It can be avoided by using a logical
  354.     scanline length that is a divisor of 65536 (a power of 2), like 1024
  355.     (as opposed to 960) for 320x200 and 2048 (1920) for 640x480. For
  356.     800x600, this is impractical (4096 as opposed to 2400 doesn't fit in
  357.     2MB). Alternatively, avoid those functions by using a virtual screen.
  358.  
  359.  
  360. Question: How do I poll the keyboard without waiting and handle multiple
  361.       keypresses?
  362.  
  363. You can have complete keyboard control by using RAW mode. An example should
  364. be in the kbd-08? package (nic.funet.fi, /pub/Linux/PEOPLE/Linus or similar).
  365.  
  366. There is now a low-level keyboard interface in svgalib.
  367. There is also a seperate 'rawkey' library for use with svgalib, by Russell
  368. Marks.
  369.  
  370.  
  371. Q: What's the fuss about a DLL library?
  372. A: The building of a DLL library includes a conversion, at the assembler
  373.    level, of all references in the library code of exported global variables
  374.    into indirect references with some overhead added to preserve register
  375.    values. This is not very efficient if the global variables are used all
  376.    over the place (e.g. currentcontext and its fields). The testgl program
  377.    ran 20% slower because of this. Therefore, the library internally uses a
  378.    copy of currentcontext that is not exported. This means that the current
  379.    context may only be changed with vgagl functions.
  380.