home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / AOS / amigamesa.h < prev    next >
C/C++ Source or Header  |  1999-09-26  |  13KB  |  392 lines

  1. #ifndef    AMIGAMESAint_H
  2. #define    AMIGAMESAint_H
  3.  
  4. #if !defined(NDEBUG) && !defined(NODEBUG)
  5. #define    MESA_DEBUG
  6. #endif
  7.  
  8. /*
  9.  * $Id: $
  10.  */
  11.  
  12. /*
  13.  * Mesa 3-D graphics library
  14.  * Version:  3.1
  15.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  16.  *
  17.  * This library is free software; you can redistribute it and/or
  18.  * modify it under the terms of the GNU Library General Public
  19.  * License as published by the Free Software Foundation; either
  20.  * version 2 of the License, or (at your option) any later version.
  21.  *
  22.  * This library is distributed in the hope that it will be useful,
  23.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25.  * Library General Public License for more details.
  26.  *
  27.  * You should have received a copy of the GNU Library General Public
  28.  * License along with this library; if not, write to the Free
  29.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30.  */
  31.  
  32. #define    NO_CONTEXT_LIBRARIES        /* do not pass library-bases over contexts */
  33. #define    REPLACE_ALLOC            /* replace malloc/calloc/free with pool-functions (only in libMesaGL) */
  34. //#define    PREVENT_LUT        /* use real calculation instead of LUTs */
  35.  
  36. /************************************************************************
  37.  *
  38.  * basic os-dependent
  39.  */
  40. #include <cybergraphx/cybergraphx.h>
  41. #include <Warp3D/Warp3D.h>
  42. #include <exec/memory.h>
  43. #include <exec/types.h>
  44. #include <hardware/blit.h>
  45. #include <intuition/intuition.h>
  46. #include <intuition/screens.h>
  47.  
  48. #if 0
  49. /*
  50.  * A is the blitmask (temporary memory passed to Blt#? as TempA)
  51.  * B is the source-bitmap
  52.  * C is the destination bitmap
  53.  */
  54.  
  55. #define    LOGIC_CLEAR    
  56. #define    LOGIC_SET    
  57. #define    LOGIC_COPY    (ABC | ABNC)
  58. #define    LOGIC_COPY_INV    (ANBC | ANBNC)
  59. #define    LOGIC_NOOP    
  60. #define    LOGIC_INV    
  61. #define    LOGIC_AND    (ABC)
  62. #define    LOGIC_NAND    (ANBC)
  63. #define    LOGIC_OR    (ABC | ANBC | ABNC) | (NABC | NANBC | NABNC)
  64. #define    LOGIC_NOR    (ANBC | ABC | ANBNC) | (NANBC | NABC | NANBNC)
  65. #define    LOGIC_XOR    (ANBC | ABNC) | (NANBC | NABNC)
  66. #define    LOGIC_XNOR    (ABC | ANBNC) | (NABC | NANBNC)
  67. #endif
  68.  
  69. /************************************************************************
  70.  *
  71.  * inlines
  72.  */
  73. #include <inline/cybergraphx.h>
  74. #include <inline/Warp3D.h>
  75. #include <inline/dos.h>
  76. #include <inline/exec.h>
  77. #include <inline/graphics.h>
  78. #include <inline/intuition.h>
  79. #include <inline/utility.h>
  80.  
  81. /************************************************************************
  82.  *
  83.  * MESA_AOS kernel structures
  84.  */
  85. #include <assert.h>
  86. #include <GL/gl.h>
  87. #include "types.h"
  88. #include "context.h"
  89. #include "dd.h"
  90. #include "xform.h"
  91. #include "macros.h"
  92. #include "vb.h"
  93.  
  94. #define    AOS_KERNEL
  95. #define    AOS_WARP3D
  96.  
  97. /*****************************************************************************
  98.  *
  99.  * private palette-definitions
  100.  */
  101. #define    PALETTE_DEFS
  102. #include "AOS/palettes.h"
  103. #undef    PALETTE_DEFS
  104.  
  105. /*****************************************************************************
  106.  *
  107.  * private visual
  108.  */
  109. struct amigamesa_context;
  110.  
  111. struct amigamesa_visual {
  112.   struct amigamesa_context *context;                /* to which context are we bound to? */
  113.   GLvisual *gl_visual;
  114.  
  115.   GLushort flags;
  116. #define    VISUAL_DOUBLEBUFFER    (1 << 0)            /* double buffered? */
  117. #define    VISUAL_STEREO        (1 << 1)            /* stereo mode? */
  118. #define    VISUAL_RGBMODE        (1 << 2)            /* RGB mode?  */
  119. #define    VISUAL_ALPHACHANNEL    (1 << 3)            /* Alphacolor? */
  120.  
  121. #define    VISUAL_AUTORGB        (1 << 8)            /* autodetect RGB mode? */
  122.  
  123.   GLshort depthBits, accumBits, stencilBits;            /* number of bits per extra-channel */
  124.   GLshort depth;                        /* bits per pixel (1, 8, 24, etc) */
  125. };
  126.  
  127. /*****************************************************************************
  128.  *
  129.  * private buffer
  130.  *
  131.  * TODO: check for size compatibility of buffer vs. context if AMA_Buffer!!!
  132.  */
  133. struct amigamesa_buffer {
  134.   struct amigamesa_context *context;                /* to which context are we bound to? */
  135.   GLframebuffer *gl_buffer;                    /* The depth, stencil, accum, etc buffers */
  136.  
  137.   GLint attachedWindowID;
  138. };
  139.  
  140. /*****************************************************************************
  141.  *
  142.  * private context
  143.  */
  144. typedef void (*rastersetup_func) (GLcontext *, GLuint, GLuint);
  145. typedef    void (*linestrip_func) (GLcontext *, GLuint, GLuint);
  146. typedef void (*tristrip_func) (GLcontext *, GLuint, GLuint);
  147. typedef void (*trifan_func) (GLcontext *, GLuint, GLuint, GLuint);
  148.  
  149. struct amigamesa_context {
  150.   GLcontext *gl_ctx;                        /* the core library context */
  151.   GLcontext *share;                        /* share this context with this */
  152.  
  153.   struct amigamesa_visual *visual;                /* the visual context */
  154.   struct amigamesa_buffer *buffer;                /* the buffer context */
  155.  
  156.   void *mempool;                        /* special mempool for this context, with it's death all mem is freed */
  157.  
  158.   GLenum lastAction;                        /* the last call to glBegin was this */
  159.  
  160.   GLushort flags;                        /* 0x1 = own visuel 0x2 = own buffer */
  161. #define    RESOURCE_VISUAL        (1 <<  0)            /* contexts visual is it's own */
  162. #define    RESOURCE_BUFFER        (1 <<  1)            /* contexts buffer is it's own */
  163.  
  164. #define    PALETTE_CACHE        (1 <<  8)            /* try to cache pens for speedup pen-determination */
  165. #define    PALETTE_DITHER        (1 <<  9)            /* dither all values before GetPen */
  166.  
  167.   GLuint pixel;                            /* current color index or RGBA pixel value */
  168.   GLuint clearpixel;                        /* pixel for clearing the color buffers */
  169.  
  170.   /* the things this context is bind to */
  171.   struct Window *window;                    /* Not neaded if in dubbelbuff needed */
  172.   struct RastPort *rp;                        /* current rastport */
  173.   struct Screen *Screen;                    /* current screen */
  174.  
  175.   /* single/double-buffering resources */
  176.   struct RastPort *front_rp;                    /* front rastport */
  177.   struct RastPort *back_rp;                    /* back rastport (NULL if SB or RGB) */
  178.   struct TmpRas *tmpras;                    /* tmpras rastport */
  179.   struct RastPort *temprp;
  180.   GLubyte *BackArray;                        /* a pen Array big as drawing area for use in dubelbuff mode */
  181.   GLubyte *imageline;                        /* One Line for WritePixelRow renders */
  182.   struct TDdriver {
  183.     W3D_Context *td_ctx;
  184.  
  185.     struct gl_texture_object *GLtex;
  186.     W3D_Texture *TDtex;
  187.  
  188.     GLuint flags, envmode, failed;
  189. #define TD_ACTIVE    (1 <<  0)                /* hardware driver active/inactive */
  190. #define TD_ZBUFFER    (1 <<  1)                /* Z buffer allocated */
  191. #define TD_SBUFFER    (1 <<  2)                /* Stencil buffer allocated */
  192. #define TD_RECTTEX    (1 <<  3)                /* Rectangular textures supported */
  193. #define TD_STATS    (1 <<  4)                /* statistics enabled */
  194. #define TD_NOCLAMP    (1 <<  5)                /* use HW even if clamping not supported */
  195. #define TD_NICETEX    (1 <<  6)                /* highquality texturing */
  196. #define TD_NICEFOG    (1 <<  7)                /* highquality fogging */
  197. #define TD_DIRTY    (1 <<  8)                /* flush necessary before Zbuffer access */
  198. #define TD_NOVMEM    (1 <<  9)                /* no VMEM for textures */
  199. #define TD_LOCKED    (1 << 10)                /* in locked state  */
  200.  
  201.     W3D_Color Palette[palNumColsMax];                /* the actual palette-tables */
  202.  
  203.     W3D_Vertex vbuffer[VB_SIZE];
  204.     W3D_Float height;
  205.     W3D_Float wscale;
  206.     W3D_Float woffset;
  207.     W3D_Float near;
  208.     W3D_Float far;
  209.     W3D_Scissor scissor;
  210.     W3D_Float texwidth;
  211.     W3D_Float texheight;
  212.     W3D_Color envcolor;
  213.  
  214.     linestrip_func LineStripFunc;
  215.     tristrip_func TriStripFunc;
  216.     trifan_func TriFanFunc;
  217.  
  218.     void (*CopyVertex) (W3D_Vertex *dest, W3D_Vertex *source);
  219.   } *TDdriver;                            /* Warp3Ddriver */
  220.  
  221.   GLshort depth;                        /* bits per pixel (1, 8, 24, etc) */
  222.  
  223.   GLshort width, height;                    /* drawable area */
  224.   GLshort left, bottom;                        /* offsets due to window border */
  225.   GLshort right, top;                        /* offsets due to window border */
  226.   GLshort RealWidth, RealHeight;                /* the drawingareas real size */
  227.   GLshort FixedWidth, FixedHeight;                /* The internal buffer real size speeds up the drawing a bit */
  228.  
  229.   /* provide fast FIXx/FIXy/FIXxy macros */
  230.   GLshort FixedX, FixedY;                    /* */
  231.   GLint *FixedXY, **FixedXYdb;                    /* */
  232.  
  233.   /* ItoP[] is changed if auxSetOneColor(index,r,g,b); is called */
  234.   palMode trueColor;                        /* the palette allocation-mode */
  235.   GLshort PaletteCols;                        /* the actual palette-colors */
  236.   struct ColorEntry Palette[palNumColsMax];            /* the actual palette-tables */
  237.   GLshort (*MatchErrors)[ERROR_RANGE][4];            /* the actual match-error-tables */
  238.   struct ColorCache penCache[256];                /* the cached pens */
  239.   GLuint ItoP[256];                        /* when allocating index 13 with a color ItoP[13] is the actual pen color */
  240.   GLuint PtoI[256];                        /* PtoI[ItoP[13]] is index 13 */
  241.  
  242.   void (*InitDD) (GLcontext *);                    /* keep track of witch drawing rutines should be used */
  243.   void (*Dispose) (struct amigamesa_context *);            /* Use this when AmigaMesaDestroyContext is called */
  244.   void (*SwapBuffer) (struct amigamesa_context *);        /* Use this when AmigaMesaSwapBuffers is called */
  245.  
  246. #define    NO_CONTEXT_LIBRARIES
  247. #ifndef    NO_CONTEXT_LIBRARIES
  248.   /* speeds up inlines needn't to restore a4 as they get the library-bases
  249.    * out of the context not a4! */
  250.   struct ExecBase *aSysBase;
  251.   struct Library *aDOSBase;
  252.   struct Library *aGfxBase;
  253.   struct Library *aUtilityBase;
  254.   struct Library *aCyberGfxBase;
  255.   struct Library *aWarp3DBase;
  256. #ifndef    NO_CONTEXT_AVAILABLE
  257. #define    SysBase        (amesa->aSysBase)
  258. #define    DOSBase        (amesa->aDOSBase)
  259. #define    GfxBase        (amesa->aGfxBase)
  260. #define    UtilityBase    (amesa->aUtilityBase)
  261. #define    CyberGfxBase    (amesa->aCyberGfxBase)
  262. #define    Warp3DBase    (amesa->aWarp3DBase)
  263. #endif
  264. #endif
  265. };
  266.  
  267. /* set a flag */
  268. #define    SetF(field, flag)    ((field) |= (flag))
  269. /* clear a flag */
  270. #define    ClrF(field, flag)    ((field) &= ~(flag))
  271. /* swap a flag */
  272. #define    SwpF(field, flag)    ((field) ^= (flag))
  273. /* test a flag */
  274. #define    TstF(field, flag)    ((field) & (flag))
  275.  
  276. /* convert a flag to a boolean */
  277. #define    FtoB(field, flag)    (TstF(field, flag) ? GL_TRUE : GL_FALSE)
  278.  
  279. /*****************************************************************************
  280.  *
  281.  * private externals
  282.  */
  283. #if defined(NO_CONTEXT_AVAILABLE) || defined(NO_CONTEXT_LIBRARIES)
  284. extern struct ExecBase *SysBase;
  285. extern struct Library *DOSBase;
  286. extern struct Library *GfxBase;
  287. extern struct Library *UtilityBase;
  288. extern struct Library *CyberGfxBase;
  289. extern struct Library *Warp3DBase;
  290. #endif
  291.  
  292. //#define    TRYTEST    1
  293. extern struct presets {
  294.   palMode trueColor;
  295.   GLboolean tryCached, tryTest, Dither;
  296. } preset;
  297. extern APTR amesaPool;
  298.  
  299. /*****************************************************************************
  300.  *
  301.  * includes
  302.  */
  303. #include <GL/amigamesa.h>
  304.  
  305. #include "AOS/amesatools.h"
  306. #include "AOS/mempools.h"
  307.  
  308. #include "AOS/cmnDisplay.h"
  309. #include "AOS/cybDisplay.h"
  310. #include "AOS/natDisplay.h"
  311. #include "AOS/wrpDisplay.h"
  312.  
  313. /*****************************************************************************
  314.  *
  315.  * private palette-prototypes
  316.  */
  317. #define    PALETTE_PROTOS
  318. #include "AOS/palettes.h"
  319. #undef    PALETTE_PROTOS
  320.  
  321. /*****************************************************************************
  322.  *
  323.  * Note that you'll usually have to flip Y coordinates since Mesa's
  324.  * window coordinates start at the bottom and increase upward.  Most
  325.  * window system's Y-axis increases downward
  326.  *
  327.  * See dd.h for more device driver info.
  328.  * See the other device driver implementations for ideas.
  329.  */
  330. #define    LayerWidth(l)        (l->bounds.MaxX - l->bounds.MinX + 1)
  331. #define    LayerHeight(l)        (l->bounds.MaxY - l->bounds.MinY + 1)
  332. #define    natFixedMask(width)    (((width) + 15) & 0xFFFFFFF0)    /* 16byte aligned */
  333. #define    cybFixedMask(width)    (((width) +  3) & 0xFFFFFFFC)    /*  4byte aligned */
  334. #ifdef    PREVENT_LUT
  335. #define FIXx(x)            (amesa->left + (x))
  336. #define FIXy(y)            (amesa->FixedHeight - amesa->bottom - (y))
  337. #define FIXxy(x,y)        (amesa->FixedWidth * FIXy(y) + FIXx(x))
  338. #define    dbPenGet(am)        ((GLubyte *)((am)->BackArray))
  339. #define    dbPen(db, x, y)        (((GLubyte *)(db)) + FIXxy((x), (y)))
  340. #define    dbRGBAGet(am)        ((GLuint *)((am)->BackArray))
  341. #define    dbRGBA(db, x, y)    (((GLuint *)(db)) + FIXxy((x), (y)))
  342. #else
  343. #define FIXx(x)            (amesa->FixedX + (x))
  344. #define FIXy(y)            (amesa->FixedY - (y))
  345. #define FIXxy(x,y)        (amesa->FixedXY[(y)] + (x))
  346. #define    dbPenGet(am)        ((GLubyte *)((am)->FixedXYdb))    /*  (GLubyte **) */
  347. #define    dbPen(db, x, y)        (((GLubyte **)(db))[(y)] + (x))    /* *(GLubyte **) */
  348. #define    dbRGBAGet(am)        ((GLuint *)((am)->FixedXYdb))    /*  (GLuint **) */
  349. #define    dbRGBA(db, x, y)    (((GLuint **)(db))[(y)] + (x))    /* *(GLuint **) */
  350. #endif
  351.  
  352. /*****************************************************************************
  353.  *
  354.  * ???
  355.  */
  356.  
  357. #define MAX_POLYGON 300
  358.  
  359. /*****************************************************************************
  360.  *
  361.  * debugging output
  362.  */
  363. /* deactive debugging-output only on request */
  364. #if !defined(NDEBUG) && !defined(NODEBUG)
  365. extern LONG debugOutput;
  366. #include <stdio.h>
  367. #define DEBUGOUT(level,str,args...) ({    \
  368.   if(debugOutput >= level) {        \
  369.  /* Printf(str,"gl  : "); */        \
  370.  /* Printf(str,##args);    */        \
  371.     fprintf(stderr,"gl  : ");        \
  372.     fprintf(stderr,str,##args);        \
  373.     fflush(stderr);            \
  374.   }                    \
  375. })
  376. #else
  377. #define DEBUGOUT(level,str,args...) ({})
  378. #define    DEBUGOUT_REMOVED
  379. #endif
  380.  
  381. #include <stdio.h>
  382. #define Error(str,args...) ({        \
  383. /*Printf("Fatal error: "); */        \
  384. /*Printf(str,##args); */        \
  385.   fprintf(stderr,"Fatal error: ");    \
  386.   fprintf(stderr,str,##args);        \
  387.   fflush(stderr);            \
  388.   abort();                \
  389. })
  390.  
  391. #endif
  392.