home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / AOS / cmnDisplay.c < prev    next >
C/C++ Source or Header  |  1999-09-25  |  28KB  |  814 lines

  1. /*
  2.  * $Id: $
  3.  */
  4.  
  5. /*
  6.  * Mesa 3-D graphics library
  7.  * Version:  3.1
  8.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  9.  *
  10.  * This library is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU Library General Public
  12.  * License as published by the Free Software Foundation; either
  13.  * version 2 of the License, or (at your option) any later version.
  14.  *
  15.  * This library is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * Library General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU Library General Public
  21.  * License along with this library; if not, write to the Free
  22.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #undef    NO_CONTEXT_AVAILABLE
  26. #include <AOS/amigamesa.h>
  27. #include "AOS/accessArray.h"
  28.  
  29. #define    MyWritePixelArray    WritePixelArray
  30. #define    MyWriteChunkyPixels    WriteChunkyPixels
  31.  
  32. /**********************************************************************/
  33.  
  34. GLboolean cmnSetBuffer(GLcontext * ctx, GLenum mode)
  35. {
  36.   DEBUGOUT(1, "cmnSetBuffer()\n");
  37.  
  38.   /* Selects the color buffer(s) for reading and writing.
  39.    * The following values must be accepted when applicable:
  40.    *    GL_FRONT_LEFT - this buffer always exists
  41.    *    GL_BACK_LEFT - when double buffering
  42.    *    GL_FRONT_RIGHT - when using stereo
  43.    *    GL_BACK_RIGHT - when using stereo and double buffering
  44.    * The folowing values may optionally be accepted.  Return GL_TRUE
  45.    * if accepted, GL_FALSE if not accepted.  In practice, only drivers
  46.    * which can write to multiple color buffers at once should accept
  47.    * these values.
  48.    *    GL_FRONT - write to front left and front right if it exists
  49.    *    GL_BACK - write to back left and back right if it exists
  50.    *    GL_LEFT - write to front left and back left if it exists
  51.    *    GL_RIGHT - write to right left and back right if they exist
  52.    *    GL_FRONT_AND_BACK - write to all four buffers if they exist
  53.    *    GL_NONE - disable buffer write in device driver.
  54.    *
  55.    * TODO implemed a set of buffers 
  56.    */
  57.  
  58.   if (mode == GL_FRONT)
  59.     return (GL_TRUE);
  60.   else if (mode == GL_BACK)
  61.     return (GL_TRUE);
  62.   else
  63.     return (GL_FALSE);
  64. }
  65.  
  66. /**********************************************************************/
  67.  
  68. /* prototypes for natFast* */
  69. void natFastTriangleFunction(GLcontext * ctx, GLuint v0, GLuint v1, GLuint v2, GLuint pv);
  70. void natFastQuadFunction(GLcontext * ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv);
  71.  
  72. /* These are called whenever glBegin() or glEnd() are called.
  73.  * The device driver may do some sort of window locking/unlocking here.
  74.  */
  75. void cmnRenderStart(GLcontext *ctx) {
  76.   amigaMesaContext amesa;
  77.   const GLenum mode = 0;
  78.  
  79.   amesa = (amigaMesaContext) ctx->DriverCtx;
  80.  
  81.   DEBUGOUT(1, "cmnRenderStart(0x%08x)\n", amesa);
  82.  
  83. #if 0
  84.   switch (mode) {
  85.     case GL_TRIANGLES:
  86.     case GL_TRIANGLE_STRIP:
  87.     case GL_TRIANGLE_FAN:
  88.     case GL_QUADS:
  89.     case GL_QUAD_STRIP:
  90.     case GL_POLYGON:
  91.       /* 4 - 9 */
  92. #endif
  93.       if (!TstF(amesa->visual->flags, VISUAL_DOUBLEBUFFER) &&
  94.           ((ctx->Driver.TriangleFunc == natFastTriangleFunction) ||
  95.        (ctx->Driver.QuadFunc     == natFastQuadFunction))) {
  96.         /* non-db filled triangle- and quad-functions needs Areas */
  97.         allocArea(amesa, amesa->rp);
  98.         makeTempRaster(amesa, amesa->rp);                    /* allocate temp raster */
  99.       }
  100. #if 0
  101.     default:
  102.       break;
  103.   }
  104. #endif
  105.  
  106.   amesa->lastAction = mode;
  107. }
  108.  
  109. void cmnRenderFinish(GLcontext *ctx) {
  110.   amigaMesaContext amesa;
  111.  
  112.   amesa = (amigaMesaContext) ctx->DriverCtx;
  113.  
  114.   DEBUGOUT(1, "cmnRenderFinish(0x%08x)\n", amesa);
  115.  
  116. #if 0
  117.   switch (amesa->lastAction) {
  118.     case GL_TRIANGLES:
  119.     case GL_TRIANGLE_STRIP:
  120.     case GL_TRIANGLE_FAN:
  121.     case GL_QUADS:
  122.     case GL_QUAD_STRIP:
  123.     case GL_POLYGON:
  124.       /* 4 - 9 */
  125. #endif
  126.       if (!TstF(amesa->visual->flags, VISUAL_DOUBLEBUFFER) &&
  127.           ((ctx->Driver.TriangleFunc == natFastTriangleFunction) ||
  128.        (ctx->Driver.QuadFunc     == natFastQuadFunction))) {
  129.         /* non-db filled triangle- and quad-functions needs Areas */
  130.         destroyTempRaster(amesa, amesa->rp);                /* deallocate temp raster  */
  131.         freeArea(amesa, amesa->rp);
  132.       }
  133. #if 0
  134.     default:
  135.       break;
  136.   }
  137. #endif
  138.  
  139.   amesa->lastAction = 0;
  140. }
  141.  
  142. void cmnDither(GLcontext *ctx, GLboolean enable) {
  143.   amigaMesaContext amesa;
  144.  
  145.   amesa = (amigaMesaContext) ctx->DriverCtx;
  146.  
  147.   DEBUGOUT(1, "cmnDither(0x%08x, %d)\n", amesa, enable);
  148.  
  149.   /* TODO: don't enable dither if it's off by TAGs */
  150. #if 0
  151.   if (enable) {
  152.     SetF(amesa->flags, PALETTE_DITHER);
  153.     if (!IS_DITHER(amesa->trueColor))
  154.       MATCHtoDITHER(amesa->trueColor);
  155. #ifdef    AOS_WARP3D
  156.     if (Amesa->TDdriver)
  157.       W3D_SetState(amesa->TDdriver->td_ctx, W3D_DITHERING, W3D_ENABLE );
  158. #endif
  159.   }
  160.   else {
  161.     ClrF(amesa->flags, PALETTE_DITHER);
  162.     if (IS_DITHER(amesa->trueColor))
  163.       DITHERtoMATCH(amesa->trueColor);
  164. #ifdef    AOS_WARP3D
  165.     if (amesa->TDdriver)
  166.       W3D_SetState(amesa->TDdriver->td_ctx, W3D_DITHERING, W3D_DISABLE);
  167. #endif
  168.   }
  169. #endif
  170. }
  171.  
  172. void cmnFinish(void)
  173. {
  174.   /* implements glFinish if possible */
  175. }
  176.  
  177. void cmnFlush(GLcontext * ctx)
  178. {
  179.   amigaMesaContext amesa;
  180.  
  181.   amesa = (amigaMesaContext) ctx->DriverCtx;
  182.  
  183.   DEBUGOUT(1, "cmnFlush(0x%08x)\n", amesa);
  184.  
  185.   /* implements glFlush if possible */
  186.   if (amesa->SwapBuffer)
  187.     (*amesa->SwapBuffer) (amesa);
  188. }
  189.  
  190. /**********************************************************************/
  191.  
  192. void cmnStandardSwapBuffer(amigaMesaContext amesa)
  193. {
  194.   DEBUGOUT(1, "cmnStandardSwapBuffer(0x%08x)\n", amesa);
  195.  
  196. #ifdef    AOS_WARP3D
  197.   if (Warp3DBase)
  198.     wrpStandardSwapBufferDB(amesa);
  199. #endif
  200.   else if (amesa->rp != amesa->front_rp) {
  201.     /* TODO: glLogicOp with minterms! */
  202.     GLubyte minterm = 0xC0;
  203.     struct gl_viewport_attrib *vport;
  204.  
  205.     vport = &amesa->gl_ctx->Viewport;
  206.  
  207.     DEBUGOUT(8, " ClipBlit(0x%08x, %d, %d, 0x%08x, %d, %d, %d, %d, %02x)\n",
  208.          amesa->rp,
  209.          FIXx(vport->X),
  210.          FIXy(vport->Y) - vport->Height,
  211.          amesa->front_rp,
  212.          FIXx(vport->X),
  213.          FIXy(vport->Y) - vport->Height,
  214.          vport->Width,
  215.          vport->Height,
  216.          minterm);
  217.     ClipBlit(amesa->rp,
  218.          FIXx(vport->X),
  219.          FIXy(vport->Y) - vport->Height,                      /*  from  */
  220.          amesa->front_rp,
  221.          FIXx(vport->X),
  222.          FIXy(vport->Y) - vport->Height,                      /*  to  */
  223.          vport->Width,
  224.          vport->Height,                              /*  size  */
  225.          minterm);
  226.   }
  227. }
  228.  
  229. void cmnStandardSwapBufferDB(amigaMesaContext amesa)
  230. {
  231.   struct gl_viewport_attrib *vport;
  232.  
  233.   vport = &amesa->gl_ctx->Viewport;
  234.  
  235.   DEBUGOUT(1, "cmnStandardSwapBufferDB(0x%08x)\n", amesa);
  236.  
  237.   if (CyberGfxBase) {
  238. #ifdef    AOS_WARP3D
  239.     if (Warp3DBase)
  240.       wrpStandardSwapBufferDB(amesa);
  241. #endif
  242.     /* TODO: check if WritePixelArray is faster than WriteChunkyPixels/WritePixelArray8 */
  243.     else {
  244.       GLshort rowSize, rowFormat;
  245.  
  246.       if (amesa->depth <= 8) {
  247.     rowSize = amesa->FixedWidth;
  248.     rowFormat = RECTFMT_LUT8;
  249.       }
  250.       else {
  251.     rowSize = amesa->FixedWidth * 4;
  252.     rowFormat = RECTFMT_RGBA;
  253.       }
  254.  
  255.       DEBUGOUT(8, " WritePixelArray(0x%08x, %d, %d, %d, 0x%08x, %d, %d, %d, %d)\n",
  256.             amesa->BackArray,
  257.             FIXx(vport->X),
  258.             FIXy(vport->Y) - vport->Height,
  259.             rowSize,
  260.             amesa->rp,
  261.             FIXx(vport->X),
  262.             FIXy(vport->Y) - vport->Height,
  263.             vport->Width,
  264.             vport->Height);
  265.       MyWritePixelArray(amesa->BackArray,
  266.             vport->X,
  267.             amesa->height - vport->Height - vport->Y,
  268.             rowSize,
  269.             amesa->rp,
  270.             FIXx(vport->X),
  271.             FIXy(vport->Y) - vport->Height,
  272.             vport->Width,
  273.             vport->Height,
  274.             rowFormat);
  275.     }
  276.   }
  277.   else {
  278. #if 0
  279.     DEBUGOUT(8, " a) WritePixelArray(0x%08x, %d, %d, %d, %d, 0x%08x, 0x%08x)\n",
  280.             amesa->rp,
  281.             FIXx(vport->X),
  282.                 FIXy(vport->Y) - vport->Height,
  283.                 FIXx(vport->X) + vport->Width - 1,
  284.                 FIXy(vport->Y) - 1,
  285.                 amesa->BackArray,
  286.                 amesa->temprp);
  287.     WritePixelArray8(amesa->rp,
  288.              FIXx(vport->X),
  289.              FIXy(vport->Y) - vport->Height,
  290.              FIXx(vport->X) + vport->Width - 1,
  291.              FIXy(vport->Y) - 1,
  292.              amesa->BackArray,
  293.              amesa->temprp);
  294. #else
  295.     DEBUGOUT(8, " b) WriteChunkyPixels(0x%08x, %d, %d, %d, %d, 0x%08x, %d)\n",
  296.             amesa->rp,
  297.             FIXx(vport->X),
  298.                 FIXy(vport->Y) - vport->Height,
  299.                 FIXx(vport->X) + vport->Width - 1,
  300.                 FIXy(vport->Y) - 1,
  301.                 amesa->BackArray,
  302.                 amesa->FixedWidth);
  303.     MyWriteChunkyPixels(amesa->rp,
  304.                 FIXx(vport->X),
  305.                 FIXy(vport->Y) - vport->Height,
  306.                 FIXx(vport->X) + vport->Width - 1,
  307.                 FIXy(vport->Y) - 1,
  308.                 amesa->BackArray,
  309.                 amesa->FixedWidth);
  310. #endif
  311.   }
  312. }
  313.  
  314. /**********************************************************************/
  315. /*****               amiga/Mesa private init/despose/resize       *****/
  316. /**********************************************************************/
  317.  
  318. void cmnStandardResize(GLcontext *ctx, GLuint *width, GLuint *height)
  319. {
  320.   amigaMesaContext amesa;
  321.  
  322.   amesa = (amigaMesaContext) ctx->DriverCtx;
  323.  
  324.   *width = amesa->width;
  325.   *height = amesa->height;
  326.   DEBUGOUT(1, "cmnStandardResize(0x%08x/0x%08x, %d, %d)\n", ctx, amesa, *width, *height);
  327.  
  328.   if (!((amesa->width == (LayerWidth(amesa->rp->Layer) - amesa->left - amesa->right)) &&
  329.     (amesa->height == (LayerHeight(amesa->rp->Layer) - amesa->bottom - amesa->top)))) {
  330.     if (CyberGfxBase && IsCyberModeID(GetVPModeID(&amesa->Screen->ViewPort)))
  331.       amesa->depth = GetCyberMapAttr(amesa->rp->BitMap, CYBRMATTR_DEPTH);
  332.     else
  333.       amesa->depth = GetBitMapAttr(amesa->rp->BitMap, BMA_DEPTH);
  334.  
  335.     amesa->RealWidth = 
  336.     amesa->FixedWidth = LayerWidth(amesa->rp->Layer);
  337.     amesa->RealHeight = 
  338.     amesa->FixedHeight = LayerHeight(amesa->rp->Layer);
  339.  
  340.     DEBUGOUT(2, "cmnStandardResize: resize %d/%d to %d/%d\n", *width, *height, amesa->RealWidth - amesa->left - amesa->right, amesa->RealHeight - amesa->bottom - amesa->top);
  341.     *width = amesa->width = amesa->RealWidth - amesa->left - amesa->right;
  342.     *height = amesa->height = amesa->RealHeight - amesa->bottom - amesa->top;
  343.  
  344.     amesa->gl_ctx->Color.DrawBuffer = GL_FRONT;
  345.     if (TstF(amesa->visual->flags, VISUAL_DOUBLEBUFFER)) {
  346.       destroyRPort(amesa, amesa->back_rp);
  347.       amesa->gl_ctx->Color.DrawBuffer = GL_BACK;
  348.       if (!(amesa->rp = amesa->back_rp = makeRPort(amesa, amesa->RealWidth, amesa->RealHeight, amesa->depth, 0, amesa->front_rp->BitMap)) == NULL) {
  349.     amesa->rp = amesa->front_rp;
  350.      /* amesa->visual->flags ^= VISUAL_DOUBLEBUFFER; */
  351.     DEBUGOUT(0, "cmnStandardResize: Not enough memory to allocate back-Rastport\n");
  352.       }
  353.     }
  354.  
  355. #ifdef    AOS_WARP3D
  356.     if (amesa->TDdriver) {
  357.       struct TDdriver *TDdriver = amesa->TDdriver;
  358.       W3D_Context *TDcontext = TDdriver->td_ctx;
  359.  
  360.       W3D_SetDrawRegion(TDcontext, amesa->rp->BitMap, 0, &TDdriver->scissor);
  361.       ClrF(TDdriver->flags, TD_NOVMEM);
  362.  
  363.       if (TstF(TDdriver->flags, TD_ZBUFFER)) {
  364.     W3D_FreeZBuffer(TDcontext);
  365.     if (W3D_AllocZBuffer(TDcontext) != W3D_SUCCESS)
  366.       ClrF(TDdriver->flags, TD_ZBUFFER);
  367.       }
  368.     }
  369. #endif
  370.  
  371.     ReallocOneLine("cmnStandardResize", amesa);
  372.     if (amesa->depth <= 8)
  373.       ReallocTempRPort("cmnStandardResize", amesa, 0);
  374.  
  375.     /* fast FIXx/FIXy/FIXxy */
  376.     if (!makeFixedXY(amesa))
  377.       Error("cmnStandardResize: Not enough memory to allocate FixedXY\n");
  378.  
  379.     DEBUGOUT(1, " amesa->RealWidth   = %d\n", amesa->RealWidth);
  380.     DEBUGOUT(1, " amesa->RealHeight  = %d\n", amesa->RealHeight);
  381.     DEBUGOUT(1, " amesa->FixedWidth  = %d\n", amesa->FixedWidth);
  382.     DEBUGOUT(1, " amesa->FixedHeight = %d\n", amesa->FixedHeight);
  383.     DEBUGOUT(1, " amesa->width       = %d\n", amesa->width);
  384.     DEBUGOUT(1, " amesa->height      = %d\n", amesa->height);
  385.     DEBUGOUT(1, " amesa->left        = %d\n", amesa->left);
  386.     DEBUGOUT(1, " amesa->bottom      = %d\n", amesa->bottom);
  387.     DEBUGOUT(1, " amesa->right       = %d\n", amesa->right);
  388.     DEBUGOUT(1, " amesa->top         = %d\n", amesa->top);
  389.     DEBUGOUT(1, " amesa->depth       = %d\n", amesa->depth);
  390.   }
  391. }
  392.  
  393. void cmnStandardResizeDB(GLcontext * ctx, GLuint * width, GLuint * height)
  394. {
  395.   amigaMesaContext amesa;
  396.  
  397.   amesa = (amigaMesaContext) ctx->DriverCtx;
  398.  
  399.   *width = amesa->width;
  400.   *height = amesa->height;
  401.   DEBUGOUT(1, "cmnStandardResizeDB(0x%08x/0x%08x, %d, %d)\n", ctx, amesa, *width, *height);
  402.  
  403.   if (!((amesa->width == (LayerWidth(amesa->rp->Layer) - amesa->left - amesa->right)) &&
  404.     (amesa->height == (LayerHeight(amesa->rp->Layer) - amesa->bottom - amesa->top)))) {
  405.     if (CyberGfxBase && IsCyberModeID(GetVPModeID(&amesa->Screen->ViewPort)))
  406.       amesa->depth = GetCyberMapAttr(amesa->rp->BitMap, CYBRMATTR_DEPTH);
  407.     else
  408.       amesa->depth = GetBitMapAttr(amesa->rp->BitMap, BMA_DEPTH);
  409.  
  410.     amesa->RealWidth = LayerWidth(amesa->rp->Layer);
  411.     amesa->RealHeight = LayerHeight(amesa->rp->Layer);
  412.     if (amesa->depth <= 8)
  413.       amesa->FixedWidth = natFixedMask(amesa->RealWidth);
  414.     else
  415.       amesa->FixedWidth = cybFixedMask(amesa->RealWidth);
  416.     amesa->FixedHeight = amesa->RealHeight;
  417.  
  418.     DEBUGOUT(2, "cmnStandardResizeDB: resize %d/%d to %d/%d\n", *width, *height, amesa->RealWidth - amesa->left - amesa->right, amesa->RealHeight - amesa->bottom - amesa->top);
  419.     *width = amesa->width = amesa->RealWidth - amesa->left - amesa->right;
  420.     *height = amesa->height = amesa->RealHeight - amesa->bottom - amesa->top;
  421.  
  422.     amesa->gl_ctx->Color.DrawBuffer = GL_FRONT;
  423.     if (TstF(amesa->visual->flags, VISUAL_DOUBLEBUFFER)) {
  424.       amesa->gl_ctx->Color.DrawBuffer = GL_BACK;
  425.       ReallocPenBackArray("cmnStandardResizeDB", amesa);
  426.     }
  427.  
  428.     if (amesa->depth <= 8)
  429.       ReallocTempRPort("cmnStandardResize", amesa, 0);
  430.  
  431.     /* fast FIXx/FIXy/FIXxy */
  432.     if (!makeFixedXY(amesa))
  433.       Error("cmnStandardResizeDB: Not enough memory to allocate FixedXY\n");
  434.  
  435.     DEBUGOUT(1, " amesa->RealWidth   = %d\n", amesa->RealWidth);
  436.     DEBUGOUT(1, " amesa->RealHeight  = %d\n", amesa->RealHeight);
  437.     DEBUGOUT(1, " amesa->FixedWidth  = %d\n", amesa->FixedWidth);
  438.     DEBUGOUT(1, " amesa->FixedHeight = %d\n", amesa->FixedHeight);
  439.     DEBUGOUT(1, " amesa->width       = %d\n", amesa->width);
  440.     DEBUGOUT(1, " amesa->height      = %d\n", amesa->height);
  441.     DEBUGOUT(1, " amesa->left        = %d\n", amesa->left);
  442.     DEBUGOUT(1, " amesa->bottom      = %d\n", amesa->bottom);
  443.     DEBUGOUT(1, " amesa->right       = %d\n", amesa->right);
  444.     DEBUGOUT(1, " amesa->top         = %d\n", amesa->top);
  445.     DEBUGOUT(1, " amesa->depth       = %d\n", amesa->depth);
  446.   }
  447. }
  448.  
  449. /**********************************************************************/
  450.  
  451. void cmnStandardDispose(amigaMesaContext amesa)
  452. {
  453.   DEBUGOUT(1, "cmnStandardDispose(0x%08x)\n", amesa);
  454.  
  455. #ifdef    AOS_WARP3D
  456.   /* do Warp3D */
  457.   if (amesa->TDdriver)
  458.     wrpStandardDispose(amesa);
  459. #endif
  460.  
  461.   Forbid();                                    /* atomize Dispose */
  462.  
  463.   /* in case of break before glEnd(), as it is not atomic this could be a leak */
  464.   if (amesa->lastAction) {
  465.     freeArea(amesa, amesa->rp);
  466.     destroyTempRaster(amesa, amesa->rp);
  467.   }
  468.  
  469.   FreeCMap(amesa, amesa->Screen);
  470.   if (amesa->depth <= 8)
  471.     freeTempRPort(amesa);
  472.   FreeOneLine(amesa);
  473.  
  474.   if (amesa->back_rp) {
  475.     if (amesa->rp == amesa->back_rp)
  476.       amesa->rp = amesa->front_rp;
  477.     destroyRPort(amesa, amesa->back_rp);
  478.     amesa->back_rp = NULL;
  479.   }
  480.  
  481.   Permit();
  482. }
  483.  
  484. void cmnStandardDisposeDB(amigaMesaContext amesa)
  485. {
  486.   DEBUGOUT(1, "cmnStandardDisposeDB(0x%08x)\n", amesa);
  487.  
  488. #ifdef    AOS_WARP3D
  489.   /* do Warp3D */
  490.   if (amesa->TDdriver)
  491.     wrpStandardDisposeDB(amesa);
  492. #endif
  493.  
  494.   Forbid();                                    /* atomize DisposeDB */
  495.  
  496.   FreeCMap(amesa, amesa->Screen);
  497.   if (amesa->depth <= 8)
  498.     freeTempRPort(amesa);
  499.  
  500.   destroyPenBackArray(amesa, amesa->BackArray);
  501.   amesa->BackArray = NULL;
  502.  
  503.   Permit();
  504. }
  505.  
  506. /**********************************************************************/
  507.  
  508. GLboolean cmnStandardInit(amigaMesaContext amesa, struct TagItem *tagList)
  509. {
  510.   struct Screen *oldScreen = amesa->Screen;
  511.   GLint newModeID;
  512.   GLboolean TDMode = GL_FALSE;
  513.  
  514.   DEBUGOUT(1, "cmnStandardInit(0x%08x, 0x%08x)\n", amesa, tagList);
  515.  
  516.   if ((amesa->left = GetTagData(AMA_Left, amesa->left, tagList)) < 0)
  517.     return GL_FALSE;
  518.   if ((amesa->right = GetTagData(AMA_Right, amesa->right, tagList)) < 0)
  519.     return GL_FALSE;
  520.   if ((amesa->top = GetTagData(AMA_Top, amesa->top, tagList)) < 0)
  521.     return GL_FALSE;
  522.   if ((amesa->bottom = GetTagData(AMA_Bottom, amesa->bottom, tagList)) < 0)
  523.     return GL_FALSE;
  524.  
  525.   if (!(amesa->window = (struct Window *)GetTagData(AMA_Window, (ULONG)amesa->window, tagList))) {
  526.     if (!(amesa->Screen = (struct Screen *)GetTagData(AMA_Screen, (ULONG)amesa->Screen, tagList))) {
  527.       DEBUGOUT(0, "cmnStandardInit: missing screen\n");
  528.       LastError = AMESA_SCREEN_TAG_MISSING;
  529.       return (GL_FALSE);
  530.     }
  531.     if (!(amesa->rp = (struct RastPort *)GetTagData(AMA_RastPort, (ULONG)amesa->rp, tagList))) {
  532.       DEBUGOUT(0, "cmnStandardInit: missing rastport (don't use Screens rastport without verification!)\n");
  533.       LastError = AMESA_RASTPORT_TAG_MISSING;
  534.       return (GL_FALSE);
  535.     }
  536.   }
  537.   else {
  538.     amesa->rp = amesa->window->RPort;
  539.     amesa->Screen = amesa->window->WScreen;
  540.  
  541.     if (amesa->left < amesa->window->BorderLeft)
  542.       amesa->left = amesa->window->BorderLeft;
  543.     if (amesa->right < amesa->window->BorderRight)
  544.       amesa->right = amesa->window->BorderRight;
  545.     if (amesa->top < amesa->window->BorderTop)
  546.       amesa->top = amesa->window->BorderTop;
  547.     if (amesa->bottom < amesa->window->BorderBottom)
  548.       amesa->bottom = amesa->window->BorderBottom;
  549.   }
  550.  
  551.   if (CyberGfxBase && IsCyberModeID(newModeID = GetVPModeID(&amesa->Screen->ViewPort))) {
  552. #ifdef    AOS_WARP3D
  553.     if (Warp3DBase) {
  554.       W3D_Driver *checkMode;
  555.       int pixFmt;
  556.  
  557.       pixFmt = GetCyberMapAttr(amesa->rp->BitMap, CYBRMATTR_PIXFMT);
  558.       if ((checkMode = W3D_TestMode(newModeID))) {
  559.     switch (pixFmt) {
  560.       case PIXFMT_RGB15:    TDMode = (checkMode->formats & W3D_FMT_R5G5B5  );    break;
  561.       case PIXFMT_BGR15:    TDMode = (checkMode->formats & W3D_FMT_B5G5R5  );    break;
  562.       case PIXFMT_RGB15PC:    TDMode = (checkMode->formats & W3D_FMT_R5G5B5PC);    break;
  563.       case PIXFMT_BGR15PC:    TDMode = (checkMode->formats & W3D_FMT_B5G5R5PC);    break;
  564.       case PIXFMT_RGB16:    TDMode = (checkMode->formats & W3D_FMT_R5G6B5  );      break;
  565.       case PIXFMT_BGR16:    TDMode = (checkMode->formats & W3D_FMT_B5G6R5  );    break;
  566.       case PIXFMT_RGB16PC:    TDMode = (checkMode->formats & W3D_FMT_R5G6B5PC);    break;
  567.       case PIXFMT_BGR16PC:    TDMode = (checkMode->formats & W3D_FMT_B5G6R5PC);    break;
  568.       case PIXFMT_RGB24:    TDMode = (checkMode->formats & W3D_FMT_R8G8B8  );    break;
  569.       case PIXFMT_BGR24:    TDMode = (checkMode->formats & W3D_FMT_B8G8R8  );    break;
  570.       case PIXFMT_ARGB32:    TDMode = (checkMode->formats & W3D_FMT_A8R8G8B8);    break;
  571.       case PIXFMT_BGRA32:    TDMode = (checkMode->formats & W3D_FMT_B8G8R8A8);    break;
  572.       case PIXFMT_RGBA32:    TDMode = (checkMode->formats & W3D_FMT_R8G8B8A8);    break;
  573.       case PIXFMT_LUT8:
  574.       default:                                    break;
  575.     }
  576.       }
  577.     }
  578. #endif
  579.  
  580.     amesa->depth = GetCyberMapAttr(amesa->rp->BitMap, CYBRMATTR_DEPTH);
  581.   }
  582.   else
  583.     amesa->depth = GetBitMapAttr(amesa->rp->BitMap, BMA_DEPTH);
  584.  
  585.   amesa->RealWidth = 
  586.   amesa->FixedWidth = LayerWidth(amesa->rp->Layer);
  587.   amesa->RealHeight = 
  588.   amesa->FixedHeight = LayerHeight(amesa->rp->Layer);
  589.  
  590.   if ((amesa->width = GetTagData(AMA_Width, amesa->RealWidth - amesa->left - amesa->right, tagList)) < 0)
  591.     return GL_FALSE;
  592.   if ((amesa->height = GetTagData(AMA_Height, amesa->RealHeight - amesa->bottom - amesa->top, tagList)) < 0)
  593.     return GL_FALSE;
  594.  
  595.   if (!amesa->right)
  596.     amesa->right = amesa->RealWidth - amesa->left - amesa->width;
  597.   if (!amesa->top)
  598.     amesa->top = amesa->RealHeight - amesa->bottom - amesa->height;
  599.  
  600.   amesa->front_rp = amesa->rp;
  601.   amesa->back_rp = NULL;
  602. /*amesa->rp = amesa->front_rp; */
  603.  
  604. /*amesa->gl_ctx->BufferWidth = amesa->width; */
  605. /*amesa->gl_ctx->BufferHeight = amesa->height; */
  606.  
  607.   amesa->gl_ctx->Color.DrawBuffer = GL_FRONT;
  608.   if (TstF(amesa->visual->flags, VISUAL_DOUBLEBUFFER)) {
  609.     destroyRPort(amesa, amesa->back_rp);
  610.     amesa->gl_ctx->Color.DrawBuffer = GL_BACK;
  611.     if (!(amesa->rp = amesa->back_rp = makeRPort(amesa, amesa->RealWidth, amesa->RealHeight, amesa->depth, 0, amesa->front_rp->BitMap))) {
  612.       amesa->rp = amesa->front_rp;
  613.       amesa->gl_ctx->Color.DrawBuffer = GL_FRONT;
  614.    /* amesa->visual->flags ^= VISUAL_DOUBLEBUFFER; */
  615.       DEBUGOUT(0, "cmnStandardInit: Not enough memory to allocate back-Rastport\n");
  616.     }
  617.   }
  618.  
  619. #ifdef    AOS_WARP3D
  620.   /* TDMode isn't true on missing Warp3DBase, allocate Warp3D-context */
  621.   if (TDMode) {
  622.     struct TDdriver *TDdriver;
  623.     W3D_Context *TDcontext;
  624.  
  625.     if ((TDdriver = AllocVecPooled(amesaPool, sizeof(struct TDdriver)))) {
  626.       if ((TDcontext = W3D_CreateContextTags(NULL,
  627.                        W3D_CC_BITMAP,    amesa->rp->BitMap,    /* use the render-bitmap */
  628.                        W3D_CC_YOFFSET,    0,
  629.                        W3D_CC_DRIVERTYPE,    W3D_DRIVER_3DHW,
  630.                        W3D_CC_GLOBALTEXENV,    TRUE,
  631.                        W3D_CC_INDIRECT,    TRUE,
  632.                        W3D_CC_FAST,        TRUE,
  633.                        TAG_DONE,         NULL))) {
  634.     TDdriver->envmode = W3D_MODULATE;
  635.     TDdriver->wscale = 1.0;
  636.     TDdriver->far = 1.0;
  637.  
  638.     if (W3D_Query(TDcontext, W3D_Q_RECTTEXTURES, NULL) == W3D_FULLY_SUPPORTED)
  639.       SetF(TDdriver->flags, TD_RECTTEX);
  640.     W3D_SetTexEnv(TDcontext, NULL, TDdriver->envmode, &TDdriver->envcolor);
  641.     if (W3D_GetDriverState(TDcontext) == W3D_SUCCESS)
  642.       SetF(TDdriver->flags, TD_ACTIVE);
  643.  
  644.     if (TstF(amesa->flags, PALETTE_DITHER))
  645.       W3D_SetState(amesa->TDdriver->td_ctx, W3D_DITHERING, W3D_ENABLE );
  646.     else
  647.       W3D_SetState(amesa->TDdriver->td_ctx, W3D_DITHERING, W3D_DISABLE);
  648.  
  649.     TDdriver->td_ctx = TDcontext;
  650.     amesa->TDdriver = TDdriver;
  651.       }
  652.       else
  653.     FreeVecPooled(amesaPool, (ULONG *)TDdriver);
  654.     }
  655.   }
  656. #endif
  657.  
  658.   ReallocOneLine("cmnStandardInit", amesa);
  659.   if (amesa->depth <= 8)
  660.     ReallocTempRPort("cmnStandardInit", amesa, 0);
  661.  
  662.   /* CMaps are even allocated if we are in high-color modes to allow fast CI32 reading
  663.    * if moved from one screen to another free old pens
  664.    */
  665.   if (oldScreen)
  666.     FreeCMap(amesa, oldScreen);
  667.   AllocCMap(amesa, amesa->Screen);
  668.   /* rethink the ItoP/PtoI if the screen changes */
  669.   if (oldScreen && (oldScreen != amesa->Screen))
  670.     RethinkCMap(amesa);
  671.  
  672.   /* fast FIXx/FIXy/FIXxy */
  673.   if (!makeFixedXY(amesa))
  674.     Error("cmnStandardInit: Not enough memory to allocate FixedXY\n");
  675.  
  676.   amesa->pixel =                                 /* current drawing pen  */
  677.   amesa->clearpixel = MakeRGBP(amesa, 0, 0, 0, 0, 0);                /* current clear pen */
  678.  
  679.   amesa->InitDD = amesa->depth <= 8 ? natStandardDDPointers : cybStandardDDPointers;    /*  standard drawing */
  680.   amesa->Dispose = cmnStandardDispose;
  681.   amesa->SwapBuffer = cmnStandardSwapBuffer;
  682.   (*amesa->InitDD) (amesa->gl_ctx);
  683.  
  684.   DEBUGOUT(1, " amesa->RealWidth   = %d\n", amesa->RealWidth);
  685.   DEBUGOUT(1, " amesa->RealHeight  = %d\n", amesa->RealHeight);
  686.   DEBUGOUT(1, " amesa->FixedWidth  = %d\n", amesa->FixedWidth);
  687.   DEBUGOUT(1, " amesa->FixedHeight = %d\n", amesa->FixedHeight);
  688.   DEBUGOUT(1, " amesa->width       = %d\n", amesa->width);
  689.   DEBUGOUT(1, " amesa->height      = %d\n", amesa->height);
  690.   DEBUGOUT(1, " amesa->left        = %d\n", amesa->left);
  691.   DEBUGOUT(1, " amesa->bottom      = %d\n", amesa->bottom);
  692.   DEBUGOUT(1, " amesa->right       = %d\n", amesa->right);
  693.   DEBUGOUT(1, " amesa->top         = %d\n", amesa->top);
  694.   DEBUGOUT(1, " amesa->depth       = %d\n", amesa->depth);
  695.  
  696.   return (GL_TRUE);
  697. }
  698.  
  699. GLboolean cmnStandardInitDB(amigaMesaContext amesa, struct TagItem * tagList)
  700. {
  701.   struct Screen *oldScreen = amesa->Screen;
  702.  
  703.   DEBUGOUT(1, "cmnStandardInitDB(0x%08x, 0x%08x)\n", amesa, tagList);
  704.  
  705.   if ((amesa->left = GetTagData(AMA_Left, amesa->left, tagList)) < 0)
  706.     return GL_FALSE;
  707.   if ((amesa->right = GetTagData(AMA_Right, amesa->right, tagList)) < 0)
  708.     return GL_FALSE;
  709.   if ((amesa->top = GetTagData(AMA_Top, amesa->top, tagList)) < 0)
  710.     return GL_FALSE;
  711.   if ((amesa->bottom = GetTagData(AMA_Bottom, amesa->bottom, tagList)) < 0)
  712.     return GL_FALSE;
  713.  
  714.   if (!(amesa->window = (struct Window *)GetTagData(AMA_Window, (ULONG)amesa->window, tagList))) {
  715.     if (!(amesa->Screen = (struct Screen *)GetTagData(AMA_Screen, (ULONG)amesa->Screen, tagList))) {
  716.       DEBUGOUT(0, "cmnStandardInitDB: missing screen\n");
  717.       LastError = AMESA_SCREEN_TAG_MISSING;
  718.       return (GL_FALSE);
  719.     }
  720.     if (!(amesa->rp = (struct RastPort *)GetTagData(AMA_RastPort, (ULONG)amesa->rp, tagList))) {
  721.       DEBUGOUT(0, "cmnStandardInitDB: missing rastport (don't use Screens rastport without verification!)\n");
  722.       LastError = AMESA_RASTPORT_TAG_MISSING;
  723.       return (GL_FALSE);
  724.     }
  725.   }
  726.   else {
  727.     amesa->rp = amesa->window->RPort;
  728.     amesa->Screen = amesa->window->WScreen;
  729.  
  730.     if (amesa->left < amesa->window->BorderLeft)
  731.       amesa->left = amesa->window->BorderLeft;
  732.     if (amesa->right < amesa->window->BorderRight)
  733.       amesa->right = amesa->window->BorderRight;
  734.     if (amesa->top < amesa->window->BorderTop)
  735.       amesa->top = amesa->window->BorderTop;
  736.     if (amesa->bottom < amesa->window->BorderBottom)
  737.       amesa->bottom = amesa->window->BorderBottom;
  738.   }
  739.  
  740.   if (CyberGfxBase && IsCyberModeID(GetVPModeID(&amesa->Screen->ViewPort)))
  741.     amesa->depth = GetCyberMapAttr(amesa->rp->BitMap, CYBRMATTR_DEPTH);
  742.   else
  743.     amesa->depth = GetBitMapAttr(amesa->rp->BitMap, BMA_DEPTH);
  744.  
  745.   amesa->RealWidth = LayerWidth(amesa->rp->Layer);
  746.   amesa->RealHeight = LayerHeight(amesa->rp->Layer);
  747.   if (amesa->depth <= 8)
  748.     amesa->FixedWidth = natFixedMask(amesa->RealWidth);
  749.   else
  750.     amesa->FixedWidth = cybFixedMask(amesa->RealWidth);
  751.   amesa->FixedHeight = amesa->RealHeight;
  752.  
  753.   if ((amesa->width = GetTagData(AMA_Width, amesa->RealWidth - amesa->left - amesa->right, tagList)) < 0)
  754.     return GL_FALSE;
  755.   if ((amesa->height = GetTagData(AMA_Height, amesa->RealHeight - amesa->bottom - amesa->top, tagList)) < 0)
  756.     return GL_FALSE;
  757.  
  758.   if (!amesa->right)
  759.     amesa->right = amesa->RealWidth - amesa->left - amesa->width;
  760.   if (!amesa->top)
  761.     amesa->top = amesa->RealHeight - amesa->bottom - amesa->height;
  762.  
  763.   amesa->front_rp = amesa->rp;
  764.   amesa->back_rp = NULL;
  765. /*amesa->rp = amesa->front_rp; */
  766.  
  767. /*amesa->gl_ctx->BufferWidth = amesa->width; */
  768. /*amesa->gl_ctx->BufferHeight = amesa->height; */
  769.  
  770.   amesa->gl_ctx->Color.DrawBuffer = GL_FRONT;
  771.   if (TstF(amesa->visual->flags, VISUAL_DOUBLEBUFFER)) {
  772.     amesa->gl_ctx->Color.DrawBuffer = GL_BACK;
  773.     ReallocPenBackArray("cmnStandardInitDB", amesa);
  774.   }
  775.  
  776.   if (amesa->depth <= 8)
  777.     ReallocTempRPort("cmnStandardInitDB", amesa, 0);
  778.  
  779.   /* CMaps are even allocated if we are in high-color modes to allow fast CI32 reading */
  780.   /* if moved from one screen to another free old pens */
  781.   if (oldScreen)
  782.     FreeCMap(amesa, oldScreen);
  783.   AllocCMap(amesa, amesa->Screen);
  784.   /* rethink the ItoP/PtoI if the screen changes */
  785.   if (oldScreen && (oldScreen != amesa->Screen))
  786.     RethinkCMap(amesa);
  787.  
  788.   /* fast FIXx/FIXy/FIXxy */
  789.   if (!makeFixedXY(amesa))
  790.     Error("cmnStandardInitDB: Not enough memory to allocate FixedXY\n");
  791.  
  792.   amesa->pixel =                                 /* current drawing pen  */
  793.   amesa->clearpixel = MakeRGBP(amesa, 0, 0, 0, 0, 0);                /* current clear pen */
  794.  
  795.   amesa->InitDD = amesa->depth <= 8 ? natFasterDDPointers : cybFasterDDPointers;    /*  fast drawing */
  796.   amesa->Dispose = cmnStandardDisposeDB;
  797.   amesa->SwapBuffer = cmnStandardSwapBufferDB;
  798.   (*amesa->InitDD) (amesa->gl_ctx);
  799.  
  800.   DEBUGOUT(1, " amesa->RealWidth   = %d\n", amesa->RealWidth);
  801.   DEBUGOUT(1, " amesa->RealHeight  = %d\n", amesa->RealHeight);
  802.   DEBUGOUT(1, " amesa->FixedWidth  = %d\n", amesa->FixedWidth);
  803.   DEBUGOUT(1, " amesa->FixedHeight = %d\n", amesa->FixedHeight);
  804.   DEBUGOUT(1, " amesa->width       = %d\n", amesa->width);
  805.   DEBUGOUT(1, " amesa->height      = %d\n", amesa->height);
  806.   DEBUGOUT(1, " amesa->left        = %d\n", amesa->left);
  807.   DEBUGOUT(1, " amesa->bottom      = %d\n", amesa->bottom);
  808.   DEBUGOUT(1, " amesa->right       = %d\n", amesa->right);
  809.   DEBUGOUT(1, " amesa->top         = %d\n", amesa->top);
  810.   DEBUGOUT(1, " amesa->depth       = %d\n", amesa->depth);
  811.  
  812.   return (GL_TRUE);
  813. }
  814.