home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / MesaDLL / os2mesaDive.cpp < prev    next >
Text File  |  2002-12-12  |  8KB  |  270 lines

  1. /* os2mesaDive.c  */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define INCL_DEV
  5. #include "WarpGL.h"
  6. #include "GL/os2mesa.h"
  7.  
  8. #include "macros.h"
  9. #include "context.h"
  10. #include "dd.h"
  11. #include "matrix.h"
  12. #include "depth.h"
  13.  
  14. #define  _MEERROR_H_
  15. #include <mmioos2.h>                   /* It is from MMPM toolkit           */
  16. #include <dive.h>
  17. #include <fourcc.h>
  18.  
  19. #include "os2mesadef.h"
  20.                 #include "glutint.h"
  21.  
  22. #define POKA 0
  23.  
  24. #include "malloc.h"
  25.  
  26. BOOL  DiveFlush(PWMC pwc);
  27. int DivePMInit(WMesaContext c);
  28.  
  29. //DIVE_CAPS DiveCaps = {0};
  30. //FOURCC    fccFormats[100] = {0};        /* Color format code */
  31.  
  32.  
  33. //
  34. // Blit memory DC to screen DC
  35. //
  36. BOOL  DiveFlush(PWMC pwc)
  37. {
  38.     BOOL  bRet = 0;
  39.     int   dwErr = 0,ulWidth,rc;
  40.     POINTL aptl[4];
  41.     int cx,cy, cx0,cy0;
  42.     int i,csum=0;
  43.     char *pstr;
  44.  
  45.     SETUP_BLITTER SetupBlitter;      /* structure for DiveSetupBlitter       */
  46.  RECTL     rCtls[52];
  47.  FOURCC  fcc, fccscr;
  48. extern GLUTwindow * __glutCurrentWindow;
  49. // ULONG     ulNumRcls;
  50. /*********************************/
  51. /* «í¡π½∩Ѽ óßÑ, τΓ« ¼«ª¡« */
  52.     pstr = (char *)&SetupBlitter;
  53.    for(i=0; i < sizeof(SetupBlitter); i++,pstr++) *pstr = 0;
  54.     pstr = (char *)&rCtls;
  55.    for(i=0; i < sizeof(PRECTL); i++,pstr++) *pstr = 0;
  56. /*
  57.   {int rc;
  58.       rc = _heapchk();
  59.  
  60.     if (_HEAPOK != rc) {
  61.        switch(rc) {
  62.           case _HEAPEMPTY:
  63.              printf("The heap has not been initialized.");
  64.              break;
  65.           case _HEAPBADNODE:
  66.              printf("A memory node is corrupted or the heap is damaged.");
  67.              break;
  68.           case _HEAPBADBEGIN:
  69.              printf("The heap specified is not valid.");
  70.              break;
  71.        }
  72.        exit(rc);
  73.     }
  74.   }
  75. */
  76. /********************************/
  77.    cx = pwc->width ;
  78.    cy = pwc->height;
  79.    cx0 = cx;
  80.    cy0 = cy;
  81.  
  82.     ulWidth = pwc->bmi.cBitCount * (pwc->bmi.cx+7)/8;
  83.     switch(pwc->bmi.cBitCount)
  84.     {   case 32:
  85.              fcc =  FOURCC_RGB4;
  86.              fccscr = FOURCC_RGB4;
  87.  
  88. //             fccscr = FOURCC_SCRN;
  89. //             fcc =  FOURCC_BGR4;
  90. //             fccscr = FOURCC_BGR4;
  91.            break;
  92.         case 24:
  93.              fcc =  FOURCC_BGR3;
  94. //           fccscr = FOURCC_RGB3; //?? FOURCC_SCRN;
  95.              fccscr = FOURCC_SCRN; // Matrox 256, 64K
  96.  
  97. //             if(pwc->useDive&0x100)
  98. //                             cx = cx0 *2/3; /* Matrox & Dive ??? 64K */
  99. //             else if(pwc->useDive&0x200)
  100. //                             cx = cx0 /3;   /* Matrox & Dive ??? 256 */
  101.  
  102.            break;
  103.         default:
  104.              fcc =  FOURCC_LUT8;
  105.              fccscr =  FOURCC_SCRN;
  106.     }
  107. //    ulWidth = 4 * pwc->bmi.cy;
  108.  
  109.     ulWidth = 0;  // ????
  110.     if(pwc->bDiveHaveBuffer)
  111.     {   rc = DiveFreeImageBuffer ( pwc->hDive, pwc->ulDiveBufferNumber );
  112.         pwc->bDiveHaveBuffer = FALSE;
  113.     }
  114.     pwc->ulDiveBufferNumber = 0;
  115. // Associate the canvas with a DIVE handle
  116.    rc = DiveAllocImageBuffer (pwc->hDive, &pwc->ulDiveBufferNumber, fcc,
  117.                           cx0, cy0,
  118.                           ulWidth,
  119.                           pwc->memb.pBmpBuffer);
  120.   if(rc)
  121.   {  printf("DiveAllocImageBuffer rc=%i\n",rc);
  122.      rc = DiveFreeImageBuffer ( pwc->hDive, pwc->ulDiveBufferNumber );
  123.      pwc->bDiveHaveBuffer = FALSE;
  124.      return FALSE;
  125.   }
  126.  
  127.  
  128. //DiveEndImageBufferAccess
  129. //DiveBeginImageBufferAccess(pwc->hDive,pwc->ulDiveBufferNumber
  130. pwc->bDiveHaveBuffer = TRUE;
  131.  
  132.    SetupBlitter.ulStructLen = sizeof ( SETUP_BLITTER );
  133.    SetupBlitter.fInvert      = TRUE;
  134.    SetupBlitter.fccSrcColorFormat = fcc;
  135.  
  136.        SetupBlitter.ulSrcWidth  = cx;
  137.        SetupBlitter.ulSrcHeight = cy;
  138.    SetupBlitter.ulSrcPosX = 0;
  139.    SetupBlitter.ulSrcPosY = 0;
  140.  
  141.    SetupBlitter.ulDitherType = 0;
  142.    if(pwc->useDive&0x200)
  143.                  SetupBlitter.ulDitherType = 1; //1;
  144.    SetupBlitter.fccDstColorFormat = fccscr;
  145.  
  146.    SetupBlitter.ulDstWidth  = cx;
  147.    SetupBlitter.ulDstHeight = cy;
  148.     SetupBlitter.lDstPosX =  0;
  149.     SetupBlitter.lDstPosY =  0;
  150.  
  151.    SetupBlitter.lScreenPosX = pwc->xDiveScr;
  152.    SetupBlitter.lScreenPosY = pwc->yDiveScr;
  153.  
  154.    rCtls[0].xLeft = 0;
  155.    rCtls[0].yBottom = 0;
  156.    rCtls[0].xRight  = cx;
  157.    rCtls[0].yTop    = cy;
  158. //   SetupBlitter.ulNumDstRects = ulNumRcls;
  159.    SetupBlitter.ulNumDstRects = 1;
  160.  
  161.    SetupBlitter.pVisDstRects = rCtls;
  162. /* ßτ¿ΓáѼ ¬«¡Γp«½∞¡πε ßπ¼¼π SetupBlitter */
  163. /* pstr = (char *)&SetupBlitter;
  164.    for(i=0; i < sizeof(SetupBlitter)- sizeof(PRECTL); i++,pstr++)
  165.    {   csum += ((int) *pstr);
  166.    }
  167.    printf("SetutBlitter CSum =%i\n",csum); fflush(stdout);
  168. */
  169.    rc = DiveSetupBlitter ( pwc->hDive, &SetupBlitter );
  170.    if(rc)
  171.    {    printf("SetutBlitterrc=%i\n",rc);
  172.      rc = DiveFreeImageBuffer ( pwc->hDive, pwc->ulDiveBufferNumber );
  173.      pwc->bDiveHaveBuffer = FALSE;
  174.         return FALSE;
  175.    }
  176. /**************************************/
  177.     rc = DiveBeginImageBufferAccess ( pwc->hDive,
  178.                                      pwc->ulDiveBufferNumber,
  179.                                      &pwc->memb.pBmpBuffer,
  180.                                      (PULONG) &ulWidth,
  181.                                      (PULONG) &cy0 );
  182. if(rc)
  183.   {  printf("DiveBeginImageBufferAccess rc=%i\n",rc);
  184.      rc = DiveFreeImageBuffer ( pwc->hDive, pwc->ulDiveBufferNumber );
  185.      pwc->bDiveHaveBuffer = FALSE;
  186.      return FALSE;
  187.   }
  188.  
  189. /************************************/
  190.  
  191.  
  192. // blit Dive buffer to screen.
  193.  
  194.  
  195.    if(!rc)
  196.    {
  197.        rc = DiveBlitImage (pwc->hDive,
  198.                       pwc->ulDiveBufferNumber,
  199.                       DIVE_BUFFER_SCREEN );
  200.       if(rc)
  201.       {     printf("Blitrc=%i,bn=%i",rc,pwc->ulDiveBufferNumber);
  202.            rc = DiveFreeImageBuffer ( pwc->hDive, pwc->ulDiveBufferNumber );
  203.             printf("DiveFreeImageBuffer rc=%i",rc);
  204.            pwc->bDiveHaveBuffer = FALSE;
  205.       } else {
  206.         rc = DiveEndImageBufferAccess (pwc->hDive, pwc->ulDiveBufferNumber );
  207.       }
  208.    }
  209.  
  210.   return TRUE;
  211. }
  212.  
  213. int DivePMInit(WMesaContext c)
  214. {
  215.    c->ulDiveBufferNumber = 0;
  216.    c->bDiveHaveBuffer = FALSE;
  217.    c->DiveCaps.pFormatData = c->fccFormats;
  218.    c->DiveCaps.ulFormatLength = 100;
  219.    c->DiveCaps.ulStructLen = sizeof(c->DiveCaps /* DIVE_CAPS */);
  220.    c->xDiveScr = 0;
  221.    c->yDiveScr = 0;
  222.    if ( DiveQueryCaps ( &c->DiveCaps, DIVE_BUFFER_SCREEN ))
  223.    {
  224.           /*  The sample program can not run on this system environment. */
  225.       return  1;
  226.    }
  227.  
  228. /*
  229. {   int i;
  230.     FILE *fp;
  231.     char *p, str[10];
  232.     fp=fopen("testDive.txt","w");
  233.  
  234.       fprintf(fp,"ulStructLen           = %i\n",c->DiveCaps.ulStructLen);
  235.       fprintf(fp,"ulPlaneCount          = %i\n",c->DiveCaps.ulPlaneCount);
  236.       fprintf(fp,"fScreenDirect         = %i\n",c->DiveCaps.fScreenDirect);
  237.       fprintf(fp,"fBankSwitched         = %i\n",c->DiveCaps.fBankSwitched);
  238.       fprintf(fp,"ulDepth               = %i\n",c->DiveCaps.ulDepth);
  239.       fprintf(fp,"ulHorizontalResolution= %i\n",c->DiveCaps.ulHorizontalResolution);
  240.       fprintf(fp,"ulVerticalResolution  = %i\n",c->DiveCaps.ulVerticalResolution);
  241.       fprintf(fp,"ulScanLineBytes       = %i\n",c->DiveCaps.ulScanLineBytes);
  242.       p = &(c->DiveCaps.fccColorEncoding);
  243.       str[0] = p[0], str[1] = p[1], str[2] = p[2], str[3] = p[3];
  244.       str[4] = 0;
  245.       fprintf(fp,"fccColorEncoding      = %s\n",str);
  246.  
  247.       fprintf(fp,"ulApertureSize        = %2i\n",c->DiveCaps.ulApertureSize);
  248.       fprintf(fp,"ulInputFormats        = %2i\n",c->DiveCaps.ulInputFormats);
  249.       fprintf(fp,"ulOutputFormats       = %2i\n",c->DiveCaps.ulOutputFormats);
  250.       fprintf(fp,"ulFormatLength        = %2i\n",c->DiveCaps.ulFormatLength);
  251.  
  252.  
  253.     fclose(fp);
  254.  }
  255. */
  256. //  PVOID      pFormatData;             /*  Pointer to color-format buffer FOURCCs. */
  257.  
  258.    if ( c->DiveCaps.ulDepth < 8 )
  259.       return  2;
  260.    if ( DiveOpen ( &(c->hDive), FALSE, 0 ) )
  261.    {
  262.        return 3;
  263.    }
  264.    printf("Dive open Ok\n"); fflush(stdout);
  265.  
  266.  
  267.    return 0;
  268. }
  269.  
  270.