| 1 | /* $Id: mesadive.c,v 1.1 2000-03-01 18:49:32 jeroen Exp $ */
|
|---|
| 2 | /*****************************************************************************/
|
|---|
| 3 | /* */
|
|---|
| 4 | /* DIVE code for OpenGL */
|
|---|
| 5 | /* */
|
|---|
| 6 | /*****************************************************************************/
|
|---|
| 7 |
|
|---|
| 8 | #define INCL_BASE
|
|---|
| 9 | #define INCL_WIN
|
|---|
| 10 | #define INCL_GPI
|
|---|
| 11 |
|
|---|
| 12 | #include <os2wrap.h>
|
|---|
| 13 | #include <memory.h>
|
|---|
| 14 | #include <malloc.h>
|
|---|
| 15 | #include <misc.h>
|
|---|
| 16 | #include <dive.h>
|
|---|
| 17 | #include <fourcc.h>
|
|---|
| 18 |
|
|---|
| 19 | #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
|
|---|
| 20 | ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) | \
|
|---|
| 21 | ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
|
|---|
| 22 |
|
|---|
| 23 | /* Some extra typedefs to be able to import some of the underneath headers */
|
|---|
| 24 | typedef ULONG HPALETTE;
|
|---|
| 25 | typedef ULONG HPEN;
|
|---|
| 26 | typedef ULONG COLORREF;
|
|---|
| 27 |
|
|---|
| 28 | #include "gl.h"
|
|---|
| 29 | #include "config.h"
|
|---|
| 30 | #include "context.h"
|
|---|
| 31 | #include "wmesadef.h"
|
|---|
| 32 | #include "colors.h"
|
|---|
| 33 |
|
|---|
| 34 | #include "mesadive.h"
|
|---|
| 35 |
|
|---|
| 36 | extern BYTE DITHER_RGB_2_8BIT( int red, int green, int blue, int pixel, int scanline);
|
|---|
| 37 | extern void WMesaUpdateScreenPos(PWMC c,HWND hWnd);
|
|---|
| 38 | extern HWND Win32ToOS2Handle(HWND);
|
|---|
| 39 |
|
|---|
| 40 | extern PWMC Current;
|
|---|
| 41 |
|
|---|
| 42 | DIVE_CAPS DiveCaps;
|
|---|
| 43 |
|
|---|
| 44 | typedef struct tagFN
|
|---|
| 45 | {
|
|---|
| 46 | HWND hwnd;
|
|---|
| 47 | PFNWP f;
|
|---|
| 48 | struct tagFN *Next;
|
|---|
| 49 | }FN;
|
|---|
| 50 |
|
|---|
| 51 | FN *WndFuncs;
|
|---|
| 52 |
|
|---|
| 53 | void StoreFn(HWND hwnd,PFNWP f)
|
|---|
| 54 | {
|
|---|
| 55 | FN *p=WndFuncs;
|
|---|
| 56 |
|
|---|
| 57 | while(p)
|
|---|
| 58 | {
|
|---|
| 59 | if(p->hwnd==hwnd)
|
|---|
| 60 | {
|
|---|
| 61 | p->f=f;
|
|---|
| 62 | return;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | p=p->Next;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | p=(FN *)calloc(sizeof(FN),1);
|
|---|
| 69 |
|
|---|
| 70 | p->hwnd=hwnd;
|
|---|
| 71 | p->f=f;
|
|---|
| 72 | p->Next=WndFuncs;
|
|---|
| 73 |
|
|---|
| 74 | WndFuncs=p;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | PFNWP QueryFn(HWND hwnd)
|
|---|
| 78 | {
|
|---|
| 79 | FN *p=WndFuncs;
|
|---|
| 80 |
|
|---|
| 81 | while(p)
|
|---|
| 82 | {
|
|---|
| 83 | if(p->hwnd==hwnd)
|
|---|
| 84 | return p->f;
|
|---|
| 85 |
|
|---|
| 86 | p=p->Next;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | return 0;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | FOURCC GetFOURCC(int pf)
|
|---|
| 93 | {
|
|---|
| 94 | switch(pf)
|
|---|
| 95 | {
|
|---|
| 96 | case PF_8A8B8G8R:
|
|---|
| 97 | dprintf(("OPENGL32: FOURCC(PF_8A8B8G8R)\n"));
|
|---|
| 98 | return FOURCC_BGR4;
|
|---|
| 99 |
|
|---|
| 100 | case PF_8R8G8B:
|
|---|
| 101 | dprintf(("OPENGL32: FOURCC(PF_8R8G8B)\n"));
|
|---|
| 102 | return FOURCC_RGB3;
|
|---|
| 103 |
|
|---|
| 104 | case PF_5R6G5B:
|
|---|
| 105 | dprintf(("OPENGL32: FOURCC(PF_5R6G5B)\n"));
|
|---|
| 106 | return FOURCC_R565;
|
|---|
| 107 |
|
|---|
| 108 | case PF_DITHER8:
|
|---|
| 109 | dprintf(("OPENGL32: FOURCC(PF_DITHER8)\n"));
|
|---|
| 110 | break;
|
|---|
| 111 |
|
|---|
| 112 | case PF_LOOKUP:
|
|---|
| 113 | dprintf(("OPENGL32: FOURCC(PF_LOOKUP)\n"));
|
|---|
| 114 | return FOURCC_LUT8;
|
|---|
| 115 |
|
|---|
| 116 | case PF_GRAYSCALE:
|
|---|
| 117 | dprintf(("OPENGL32: FOURCC(PF_GRAYSCALE)\n"));
|
|---|
| 118 | return FOURCC_GREY;
|
|---|
| 119 |
|
|---|
| 120 | case PF_BADFORMAT:
|
|---|
| 121 | dprintf(("OPENGL32: FOURCC(PF_BADFORMAT)\n"));
|
|---|
| 122 | return FOURCC_RGB3;
|
|---|
| 123 |
|
|---|
| 124 | case PF_INDEX8:
|
|---|
| 125 | dprintf(("OPENGL32: FOURCC(PF_INDEX8)\n"));
|
|---|
| 126 | return FOURCC_LUT8;
|
|---|
| 127 |
|
|---|
| 128 | default:
|
|---|
| 129 | dprintf(("OPENGL32: FOURCC(???) -> %d\n",pf));
|
|---|
| 130 | break;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | return 0;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | void DiveWriteBackbuffer( PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b)
|
|---|
| 137 | {
|
|---|
| 138 | /* dprintf(("OPENGL32: Accessing the BackBuffer %08X\n",pwc->pbPixels));*/
|
|---|
| 139 | PBYTE lpb = pwc->pbPixels;
|
|---|
| 140 | PDWORD lpdw;
|
|---|
| 141 | PWORD lpw;
|
|---|
| 142 | ULONG nBypp = pwc->cColorBits >> 3;
|
|---|
| 143 | ULONG nOffset = iPixel % nBypp;
|
|---|
| 144 |
|
|---|
| 145 | //dprintf(("OPENGL32: wmSetPixel(%d,%d) - lpb= %08X, nBypp=%d\n",iPixel,iScanLine,lpb,nBypp));
|
|---|
| 146 |
|
|---|
| 147 | lpb += pwc->ScanWidth * iScanLine;
|
|---|
| 148 |
|
|---|
| 149 | lpb += iPixel * nBypp;
|
|---|
| 150 | lpdw = (LPDWORD)lpb;
|
|---|
| 151 | lpw = (LPWORD)lpb;
|
|---|
| 152 |
|
|---|
| 153 | /* dprintf(("OPENGL32: wmSetPixel - lpb= %08X, lpdw=%08X\n",lpb,lpdw));*/
|
|---|
| 154 |
|
|---|
| 155 | if(nBypp == 1)
|
|---|
| 156 | {
|
|---|
| 157 | if(pwc->dither_flag)
|
|---|
| 158 | *lpb = DITHER_RGB_2_8BIT(r,g,b,iScanLine,iPixel);
|
|---|
| 159 | else
|
|---|
| 160 | *lpb = BGR8(r,g,b);
|
|---|
| 161 | }
|
|---|
| 162 | else
|
|---|
| 163 | if(nBypp == 2)
|
|---|
| 164 | *lpw = BGR16(r,g,b);
|
|---|
| 165 | else
|
|---|
| 166 | if (nBypp == 3)
|
|---|
| 167 | *lpdw = BGR24(r,g,b);
|
|---|
| 168 | else
|
|---|
| 169 | if (nBypp == 4)
|
|---|
| 170 | *lpdw = BGR32(r,g,b);
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | void DiveWriteFrontbuffer( PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b)
|
|---|
| 174 | {
|
|---|
| 175 | /* Check whether the point is clipped - if so don't draw it! */
|
|---|
| 176 | POINTL pt;
|
|---|
| 177 | ULONG rc;
|
|---|
| 178 |
|
|---|
| 179 | pt.x=iPixel; pt.y=iScanLine;
|
|---|
| 180 |
|
|---|
| 181 | rc=GpiPtInRegion(pwc->hps,pwc->hrgn,&pt);
|
|---|
| 182 |
|
|---|
| 183 | if(rc!=PRGN_INSIDE)
|
|---|
| 184 | return;
|
|---|
| 185 |
|
|---|
| 186 | if(DiveCaps.fBankSwitched)
|
|---|
| 187 | {
|
|---|
| 188 | dprintf(("OPENGL32: Bank-switched DIVE access not yet implemented\n"));
|
|---|
| 189 | }
|
|---|
| 190 | else
|
|---|
| 191 | {
|
|---|
| 192 | PBYTE lpb = (PBYTE)pwc->ppFrameBuffer;
|
|---|
| 193 | PDWORD lpdw;
|
|---|
| 194 | PWORD lpw;
|
|---|
| 195 | ULONG nBypp = DiveCaps.ulDepth >> 3;
|
|---|
| 196 | /* ULONG nOffset = iPixel % nBypp;*/
|
|---|
| 197 |
|
|---|
| 198 | iScanLine+=pwc->WinPos.y;
|
|---|
| 199 | iPixel+=pwc->WinPos.x;
|
|---|
| 200 |
|
|---|
| 201 | lpb += iScanLine * DiveCaps.ulScanLineBytes;
|
|---|
| 202 | lpb += iPixel * nBypp;
|
|---|
| 203 | lpdw = (LPDWORD)lpb;
|
|---|
| 204 | lpw = (LPWORD)lpb;
|
|---|
| 205 |
|
|---|
| 206 | if(nBypp == 1){
|
|---|
| 207 | if(pwc->dither_flag)
|
|---|
| 208 | *lpb = DITHER_RGB_2_8BIT(r,g,b,iScanLine,iPixel);
|
|---|
| 209 | else
|
|---|
| 210 | *lpb = BGR8(r,g,b);
|
|---|
| 211 | }
|
|---|
| 212 | else if(nBypp == 2)
|
|---|
| 213 | *lpw = BGR16(r,g,b);
|
|---|
| 214 | else if (nBypp == 3){
|
|---|
| 215 | *lpdw = BGR24(r,g,b);
|
|---|
| 216 | }
|
|---|
| 217 | else if (nBypp == 4)
|
|---|
| 218 | *lpdw = BGR32(r,g,b);
|
|---|
| 219 | }
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | void DiveFlush( PWMC pwc )
|
|---|
| 223 | {
|
|---|
| 224 | ULONG rc;
|
|---|
| 225 |
|
|---|
| 226 | dprintf(("DiveFlush -- Blitting will now occur\n"));
|
|---|
| 227 |
|
|---|
| 228 | if(!pwc->hDiveInstance)
|
|---|
| 229 | {
|
|---|
| 230 | dprintf(("OPENGL32: wmFlush ->> No backbuffer allocated yet!\n"));
|
|---|
| 231 | return;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | if(pwc->DiveSoftwareBlit)
|
|---|
| 235 | {
|
|---|
| 236 | /* Perform software blitting if DiveSetupBlitter failed! */
|
|---|
| 237 | /* The source and target format will always be identical */
|
|---|
| 238 | /* This is accomplished by wmesa.c's wmSetPixelFormat */
|
|---|
| 239 | /* routine that uses the native output-format... */
|
|---|
| 240 |
|
|---|
| 241 | dprintf(("OPENGL32: Dive -->> Software BLIT!\n"));
|
|---|
| 242 |
|
|---|
| 243 | PBYTE lpb = (PBYTE)pwc->ppFrameBuffer;
|
|---|
| 244 | PBYTE lpbb = pwc->pbPixels;
|
|---|
| 245 | ULONG nBypp = pwc->cColorBits >> 3;
|
|---|
| 246 | ULONG bpl = nBypp*pwc->awidth;
|
|---|
| 247 |
|
|---|
| 248 | lpb += pwc->WinPos.y*DiveCaps.ulScanLineBytes;
|
|---|
| 249 | lpb += pwc->WinPos.x*nBypp;
|
|---|
| 250 |
|
|---|
| 251 | lpbb += (pwc->height-1) * pwc->ScanWidth;
|
|---|
| 252 |
|
|---|
| 253 | for(int y=0; y<pwc->height; y++)
|
|---|
| 254 | {
|
|---|
| 255 | memcpy(lpb,lpbb,bpl);
|
|---|
| 256 |
|
|---|
| 257 | lpb+=DiveCaps.ulScanLineBytes;
|
|---|
| 258 | lpbb-=pwc->ScanWidth;
|
|---|
| 259 | }
|
|---|
| 260 | }
|
|---|
| 261 | else
|
|---|
| 262 | {
|
|---|
| 263 | rc=DiveEndImageBufferAccess(pwc->hDiveInstance,
|
|---|
| 264 | pwc->BackBufferNumber);
|
|---|
| 265 |
|
|---|
| 266 | dprintf(("OPENGL32: DiveEndImageBufferAccess rc %d\n",rc));
|
|---|
| 267 |
|
|---|
| 268 | rc=DiveBlitImage(pwc->hDiveInstance,
|
|---|
| 269 | pwc->BackBufferNumber,
|
|---|
| 270 | DIVE_BUFFER_SCREEN);
|
|---|
| 271 |
|
|---|
| 272 | dprintf(("OPENGL32: DiveBlitImage rc %d\n",rc));
|
|---|
| 273 |
|
|---|
| 274 | ULONG bsl;
|
|---|
| 275 |
|
|---|
| 276 | rc=DiveBeginImageBufferAccess(pwc->hDiveInstance,
|
|---|
| 277 | pwc->BackBufferNumber,
|
|---|
| 278 | &pwc->pbPixels,
|
|---|
| 279 | &pwc->ScanWidth,
|
|---|
| 280 | &bsl);
|
|---|
| 281 |
|
|---|
| 282 | dprintf(("OPENGL32: Buffered ->> DiveBeginImageBufferAccess rc %d, buffer #%d, pbPixels %08X\n",rc,pwc->BackBufferNumber,pwc->pbPixels));
|
|---|
| 283 | }
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | void DiveDefineRegion(PWMC wc,HWND hWnd)
|
|---|
| 287 | {
|
|---|
| 288 | RGNRECT rgnCtl;
|
|---|
| 289 | HWND hwnd=Win32ToOS2Handle(hWnd);
|
|---|
| 290 | ULONG rc;
|
|---|
| 291 |
|
|---|
| 292 | dprintf(("OPENGL32: DiveDefineRegion - hwnd %08X",hwnd));
|
|---|
| 293 |
|
|---|
| 294 | rgnCtl.ircStart=0;
|
|---|
| 295 | rgnCtl.crc=50;
|
|---|
| 296 | rgnCtl.ulDirection=RECTDIR_LFRT_TOPBOT;
|
|---|
| 297 |
|
|---|
| 298 | if(wc->hrgn)
|
|---|
| 299 | GpiDestroyRegion(wc->hps,wc->hrgn);
|
|---|
| 300 |
|
|---|
| 301 | if(wc->hps)
|
|---|
| 302 | WinReleasePS(wc->hps);
|
|---|
| 303 |
|
|---|
| 304 | wc->hps=WinGetPS(hwnd);
|
|---|
| 305 |
|
|---|
| 306 | dprintf(("OPENGL32: DiveDefineRegion - hps %08X",wc->hps));
|
|---|
| 307 |
|
|---|
| 308 | wc->hrgn=(ULONG)GpiCreateRegion(wc->hps,0,NULL);
|
|---|
| 309 |
|
|---|
| 310 | dprintf(("OPENGL32: DiveDefineRegion - hrgn %08X",wc->hrgn));
|
|---|
| 311 |
|
|---|
| 312 | rc=WinQueryVisibleRegion(hwnd,wc->hrgn);
|
|---|
| 313 |
|
|---|
| 314 | dprintf(("OPENGL32: DiveDefineRegion - WinQueryVisibleRegion rc %d",rc));
|
|---|
| 315 |
|
|---|
| 316 | rc=GpiQueryRegionRects(wc->hps,wc->hrgn,NULL,&rgnCtl,(RECTL *)wc->rctls);
|
|---|
| 317 |
|
|---|
| 318 | dprintf(("OPENGL32: DiveDefineRegion - GpiQueryRegionRects rc %d",rc));
|
|---|
| 319 |
|
|---|
| 320 | wc->NumClipRects=rgnCtl.crcReturned;
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | ULONG DiveBlitSetup(PWMC wc,BOOL fActivate)
|
|---|
| 324 | {
|
|---|
| 325 | SETUP_BLITTER setup;
|
|---|
| 326 | POINTL pointl;
|
|---|
| 327 | SWP swp;
|
|---|
| 328 | ULONG rc;
|
|---|
| 329 |
|
|---|
| 330 | dprintf(("OPENGL32: Entering DiveBlitSetup - wc %08X, fActivate %d\n",
|
|---|
| 331 | wc,fActivate));
|
|---|
| 332 |
|
|---|
| 333 | if(!wc)
|
|---|
| 334 | return 0;
|
|---|
| 335 |
|
|---|
| 336 | if(!fActivate)
|
|---|
| 337 | return DiveSetupBlitter(wc->hDiveInstance,0);
|
|---|
| 338 |
|
|---|
| 339 | DiveDefineRegion(wc,wc->hwnd);
|
|---|
| 340 |
|
|---|
| 341 | /* If not double-buffered we don't actually need to setup the blitter! */
|
|---|
| 342 | /* Also, if setting up the blitter failed once, it will probably fail */
|
|---|
| 343 | /* again, so no need to pursue this piece of logic... */
|
|---|
| 344 | if(!wc->db_flag || wc->DiveSoftwareBlit)
|
|---|
| 345 | return 0;
|
|---|
| 346 |
|
|---|
| 347 | memset(&setup,0,sizeof(SETUP_BLITTER));
|
|---|
| 348 |
|
|---|
| 349 | setup.ulStructLen=sizeof(SETUP_BLITTER);
|
|---|
| 350 |
|
|---|
| 351 | setup.fInvert=1;
|
|---|
| 352 |
|
|---|
| 353 | setup.fccSrcColorFormat=GetFOURCC(wc->pixelformat);
|
|---|
| 354 | setup.fccDstColorFormat=FOURCC_SCRN;
|
|---|
| 355 |
|
|---|
| 356 | setup.ulSrcWidth=wc->awidth;
|
|---|
| 357 | setup.ulDstWidth=wc->awidth;
|
|---|
| 358 | setup.ulSrcHeight=wc->aheight;
|
|---|
| 359 | setup.ulDstHeight=wc->aheight;
|
|---|
| 360 |
|
|---|
| 361 | WinQueryWindowPos(Win32ToOS2Handle(wc->hwnd),&swp);
|
|---|
| 362 |
|
|---|
| 363 | pointl.x=swp.x; pointl.y=swp.y;
|
|---|
| 364 |
|
|---|
| 365 | WinMapWindowPoints(WinQueryWindow(Win32ToOS2Handle(wc->hwnd),QW_PARENT),
|
|---|
| 366 | HWND_DESKTOP,
|
|---|
| 367 | &pointl,
|
|---|
| 368 | 1);
|
|---|
| 369 |
|
|---|
| 370 | setup.lScreenPosX=pointl.x;
|
|---|
| 371 | setup.lScreenPosY=pointl.y;
|
|---|
| 372 |
|
|---|
| 373 | setup.ulNumDstRects=wc->NumClipRects;
|
|---|
| 374 | setup.pVisDstRects=(RECTL *)wc->rctls;
|
|---|
| 375 |
|
|---|
| 376 | rc=DiveSetupBlitter(wc->hDiveInstance,&setup);
|
|---|
| 377 |
|
|---|
| 378 | dprintf(("OPENGL32: DiveSetupBlitter rc %d\n",rc));
|
|---|
| 379 |
|
|---|
| 380 | if(rc==DIVE_ERR_INVALID_CONVERSION)
|
|---|
| 381 | {
|
|---|
| 382 | /* Hmmm, my Matrox does this all the time in 24-bit depth mode */
|
|---|
| 383 | /* It works in lower color-depths, but in order to use Dive even */
|
|---|
| 384 | /* if the conversion-code in DIVE is somehow malfunctioning use */
|
|---|
| 385 | /* a software blitter to blit the image. Do however change the */
|
|---|
| 386 | /* backbuffer's pixelformat to that of the screen. */
|
|---|
| 387 | wc->DiveSoftwareBlit=TRUE;
|
|---|
| 388 |
|
|---|
| 389 | rc=0;
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | return rc;
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | MRESULT EXPENTRY os2DiveWndProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
|
|---|
| 396 | {
|
|---|
| 397 | PFNWP f=QueryFn(hwnd);
|
|---|
| 398 | ULONG rc;
|
|---|
| 399 |
|
|---|
| 400 | dprintf(("OPENGL32: DiveWndMsgRecv %d\n",msg));
|
|---|
| 401 |
|
|---|
| 402 | switch(msg)
|
|---|
| 403 | {
|
|---|
| 404 | case WM_VRNENABLED:
|
|---|
| 405 | if(Current)
|
|---|
| 406 | {
|
|---|
| 407 | DiveBlitSetup(Current,TRUE);
|
|---|
| 408 | WMesaUpdateScreenPos(Current,Current->hwnd);
|
|---|
| 409 | }
|
|---|
| 410 | break;
|
|---|
| 411 |
|
|---|
| 412 | case WM_VRNDISABLED:
|
|---|
| 413 | if(Current)
|
|---|
| 414 | DiveBlitSetup(Current,FALSE);
|
|---|
| 415 | break;
|
|---|
| 416 |
|
|---|
| 417 | case WM_SETFOCUS:
|
|---|
| 418 | if(Current)
|
|---|
| 419 | DiveDefineRegion(Current,Current->hwnd);
|
|---|
| 420 | break;
|
|---|
| 421 |
|
|---|
| 422 | case WM_SIZE:
|
|---|
| 423 | if(Current)
|
|---|
| 424 | {
|
|---|
| 425 | WMesaUpdateScreenPos(Current,Current->hwnd);
|
|---|
| 426 | /* DiveResizeBuffers(Current->width,Current->Height);*/
|
|---|
| 427 | }
|
|---|
| 428 | break;
|
|---|
| 429 |
|
|---|
| 430 | case WM_DESTROY:
|
|---|
| 431 | WinSetVisibleRegionNotify(hwnd,FALSE);
|
|---|
| 432 | break;
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | return (*f)(hwnd,msg,mp1,mp2);
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | PBYTE AllocateBuffer(int width,int height,int pf,ULONG *s)
|
|---|
| 439 | {
|
|---|
| 440 | *s=width*4;
|
|---|
| 441 |
|
|---|
| 442 | dprintf(("OPENGL32: Allocating buffer(%d/%d): %d bytes\n",
|
|---|
| 443 | width,height,width*height*4));
|
|---|
| 444 |
|
|---|
| 445 | return (PBYTE)malloc(width*height*4);
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | /*
|
|---|
| 449 | * doInit - do work required for every instance of the application:
|
|---|
| 450 | * create the window, initialize data
|
|---|
| 451 | */
|
|---|
| 452 | BOOL DiveInit( PWMC wc, HWND hwnd)
|
|---|
| 453 | {
|
|---|
| 454 | ULONG rc;
|
|---|
| 455 | RECT rect;
|
|---|
| 456 |
|
|---|
| 457 | dprintf(("OPENGL32: DiveInit on context %08X\n",wc));
|
|---|
| 458 |
|
|---|
| 459 | /* wc->fullScreen = displayOptions.fullScreen;
|
|---|
| 460 | wc->gMode = displayOptions.mode;*/
|
|---|
| 461 | wc->hwnd = hwnd;
|
|---|
| 462 |
|
|---|
| 463 | /* Register Region change Notifications for our window */
|
|---|
| 464 | /* This allows us to set the correct clipping rects and window position */
|
|---|
| 465 | /* We must subclass the OS/2 hwnd in order to accomplish this, since the*/
|
|---|
| 466 | /* WM_VRNxxxxx messages are not relayed to the WIN hwnd. */
|
|---|
| 467 | PFNWP f=WinSubclassWindow(Win32ToOS2Handle(hwnd),(PFNWP)os2DiveWndProc);
|
|---|
| 468 | StoreFn(Win32ToOS2Handle(hwnd),f);
|
|---|
| 469 |
|
|---|
| 470 | WinSetVisibleRegionNotify(Win32ToOS2Handle(hwnd),TRUE);
|
|---|
| 471 |
|
|---|
| 472 | /* stereo_flag = displayOptions.stereo;
|
|---|
| 473 |
|
|---|
| 474 | if(wc->db_flag!= TRUE)
|
|---|
| 475 | stereo_flag = FALSE;
|
|---|
| 476 | */
|
|---|
| 477 | rc=DiveOpen(&wc->hDiveInstance,
|
|---|
| 478 | FALSE,
|
|---|
| 479 | &wc->ppFrameBuffer);
|
|---|
| 480 |
|
|---|
| 481 | dprintf(("OPENGL32: DiveOpen rc %d - Framebuffer address %08X\n",rc,wc->ppFrameBuffer));
|
|---|
| 482 |
|
|---|
| 483 | if(rc)
|
|---|
| 484 | return FALSE;
|
|---|
| 485 | /* For later? Switch to FullScreen mode ...
|
|---|
| 486 | switch( wc->gMode )
|
|---|
| 487 | {
|
|---|
| 488 | case 1: ddrval = DiveSetDisplayMode( wc->lpDD, 640, 480, displayOptions.bpp); break;
|
|---|
| 489 | case 2: ddrval = DiveSetDisplayMode( wc->lpDD, 800, 600, displayOptions.bpp); break;
|
|---|
| 490 | case 3: ddrval = DiveSetDisplayMode( wc->lpDD, 1024, 768, displayOptions.bpp); break;
|
|---|
| 491 | case 4: ddrval = DiveSetDisplayMode( wc->lpDD, 1152, 864, displayOptions.bpp); break;
|
|---|
| 492 | case 5: ddrval = DiveSetDisplayMode( wc->lpDD, 1280, 1024, displayOptions.bpp); break;
|
|---|
| 493 | }
|
|---|
| 494 | */
|
|---|
| 495 |
|
|---|
| 496 | /* If in double-buffer mode allocate an offscreen rendering buffer! */
|
|---|
| 497 | if(wc->db_flag)
|
|---|
| 498 | {
|
|---|
| 499 | wc->BackBufferNumber=0;
|
|---|
| 500 |
|
|---|
| 501 | wc->awidth=wc->width;
|
|---|
| 502 | wc->aheight=wc->height;
|
|---|
| 503 |
|
|---|
| 504 | rc=DiveAllocImageBuffer(wc->hDiveInstance,
|
|---|
| 505 | &wc->BackBufferNumber,
|
|---|
| 506 | GetFOURCC(wc->pixelformat),
|
|---|
| 507 | wc->awidth,
|
|---|
| 508 | wc->aheight,
|
|---|
| 509 | 0,
|
|---|
| 510 | 0);
|
|---|
| 511 |
|
|---|
| 512 | dprintf(("OPENGL32: Buffered ->> DiveAllocImageBuffer rc %d, buffer #%d\n",rc,wc->BackBufferNumber));
|
|---|
| 513 |
|
|---|
| 514 | if(rc==DIVE_ERR_SOURCE_FORMAT)
|
|---|
| 515 | {
|
|---|
| 516 | /* Darn - the driver doesn't support the format we want! */
|
|---|
| 517 | /* Well, just allocate it ourselves then!! */
|
|---|
| 518 | wc->BackBufferOwnAllocation=TRUE;
|
|---|
| 519 |
|
|---|
| 520 | wc->pbPixels=AllocateBuffer(wc->awidth,
|
|---|
| 521 | wc->aheight,
|
|---|
| 522 | wc->pixelformat,
|
|---|
| 523 | &wc->ScanWidth);
|
|---|
| 524 |
|
|---|
| 525 | wc->BackBufferNumber=0;
|
|---|
| 526 |
|
|---|
| 527 | rc=DiveAllocImageBuffer(wc->hDiveInstance,
|
|---|
| 528 | &wc->BackBufferNumber,
|
|---|
| 529 | GetFOURCC(wc->pixelformat),
|
|---|
| 530 | wc->awidth,
|
|---|
| 531 | wc->aheight,
|
|---|
| 532 | wc->ScanWidth,
|
|---|
| 533 | wc->pbPixels);
|
|---|
| 534 |
|
|---|
| 535 | dprintf(("OPENGL32: Buffered ->> OwnAlloc %08X: DiveAllocImageBuffer rc %d, buffer #%d\n",wc->pbPixels,rc,wc->BackBufferNumber));
|
|---|
| 536 | }
|
|---|
| 537 | else
|
|---|
| 538 | {
|
|---|
| 539 | if(rc)
|
|---|
| 540 | {
|
|---|
| 541 | DiveClose(wc->hDiveInstance);
|
|---|
| 542 | wc->hDiveInstance=0;
|
|---|
| 543 |
|
|---|
| 544 | return FALSE;
|
|---|
| 545 | }
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | ULONG bsl;
|
|---|
| 549 |
|
|---|
| 550 | rc=DiveBeginImageBufferAccess(wc->hDiveInstance,
|
|---|
| 551 | wc->BackBufferNumber,
|
|---|
| 552 | &wc->pbPixels,
|
|---|
| 553 | &wc->ScanWidth,
|
|---|
| 554 | &bsl);
|
|---|
| 555 |
|
|---|
| 556 | dprintf(("OPENGL32: Buffered ->> DiveBeginImageBufferAccess rc %d, buffer #%d, pbPixels %08X\n",rc,wc->BackBufferNumber,wc->pbPixels));
|
|---|
| 557 |
|
|---|
| 558 | if(rc)
|
|---|
| 559 | {
|
|---|
| 560 | DiveFree(wc);
|
|---|
| 561 |
|
|---|
| 562 | return FALSE;
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | rc=DiveBlitSetup(wc,TRUE);
|
|---|
| 566 |
|
|---|
| 567 | if(rc)
|
|---|
| 568 | {
|
|---|
| 569 | DiveFree(wc);
|
|---|
| 570 |
|
|---|
| 571 | return FALSE;
|
|---|
| 572 | }
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | return TRUE;
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | void DiveFree(PWMC wc)
|
|---|
| 579 | {
|
|---|
| 580 | ULONG rc;
|
|---|
| 581 |
|
|---|
| 582 | dprintf(("OPENGL32: DiveFree ctx %08X\n",wc));
|
|---|
| 583 |
|
|---|
| 584 | if(wc->hDiveInstance!=0)
|
|---|
| 585 | {
|
|---|
| 586 | if(wc->BackBufferNumber) /* A backbuffer allocated??*/
|
|---|
| 587 | {
|
|---|
| 588 | rc=DiveEndImageBufferAccess(wc->hDiveInstance,
|
|---|
| 589 | wc->BackBufferNumber);
|
|---|
| 590 |
|
|---|
| 591 | dprintf(("OPENGL32: DiveEndImageBufferAccess rc %d\n",rc));
|
|---|
| 592 |
|
|---|
| 593 | rc=DiveFreeImageBuffer(wc->hDiveInstance,
|
|---|
| 594 | wc->BackBufferNumber);
|
|---|
| 595 |
|
|---|
| 596 | dprintf(("OPENGL32: DiveFreeImageBuffer rc %d\n",rc));
|
|---|
| 597 | }
|
|---|
| 598 |
|
|---|
| 599 | wc->BackBufferNumber=0;
|
|---|
| 600 |
|
|---|
| 601 | rc=DiveClose(wc->hDiveInstance);
|
|---|
| 602 |
|
|---|
| 603 | dprintf(("OPENGL32: DiveClose rc %d\n",rc));
|
|---|
| 604 |
|
|---|
| 605 | wc->hDiveInstance=0;
|
|---|
| 606 | }
|
|---|
| 607 | }
|
|---|
| 608 |
|
|---|
| 609 | void _System DiveGlobalInitialize(void)/* Called by INITTERM */
|
|---|
| 610 | {
|
|---|
| 611 | DiveQueryCaps(&DiveCaps,DIVE_BUFFER_SCREEN);
|
|---|
| 612 |
|
|---|
| 613 | dprintf(("OPENGL32: Dive Capabilities\n"));
|
|---|
| 614 | dprintf(("OPENGL32: ulPlaneCount %d\n",DiveCaps.ulPlaneCount));
|
|---|
| 615 | dprintf(("OPENGL32: fScreenDirect %d\n",DiveCaps.fScreenDirect));
|
|---|
| 616 | dprintf(("OPENGL32: fBankSwitched %d\n",DiveCaps.fBankSwitched));
|
|---|
| 617 | dprintf(("OPENGL32: ulDepth %d\n",DiveCaps.ulDepth));
|
|---|
| 618 | dprintf(("OPENGL32: ulHorizontalResolution %d\n",DiveCaps.ulHorizontalResolution));
|
|---|
| 619 | dprintf(("OPENGL32: ulVerticalResolution %d\n",DiveCaps.ulVerticalResolution));
|
|---|
| 620 | dprintf(("OPENGL32: ulScanLineBytes %d\n",DiveCaps.ulScanLineBytes));
|
|---|
| 621 | dprintf(("OPENGL32: fccColorEncoding %08X\n",DiveCaps.fccColorEncoding));
|
|---|
| 622 | dprintf(("OPENGL32: ulApertureSize %d\n",DiveCaps.ulApertureSize));
|
|---|
| 623 | dprintf(("OPENGL32: ulInputFormats %d\n",DiveCaps.ulInputFormats));
|
|---|
| 624 | dprintf(("OPENGL32: ulOutputFormats %d\n",DiveCaps.ulOutputFormats));
|
|---|
| 625 | dprintf(("OPENGL32: ulFormatLength %d\n",DiveCaps.ulFormatLength));
|
|---|
| 626 | dprintf(("OPENGL32: pFormatData %08X\n",DiveCaps.pFormatData));
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 | void _System DiveGlobalTerminate(void)
|
|---|
| 630 | {
|
|---|
| 631 | if(Current)
|
|---|
| 632 | {
|
|---|
| 633 | PWMC c=Current;
|
|---|
| 634 |
|
|---|
| 635 | Current=0;
|
|---|
| 636 |
|
|---|
| 637 | if(c->BackBufferNumber)
|
|---|
| 638 | {
|
|---|
| 639 | ULONG ulb=c->BackBufferNumber;
|
|---|
| 640 |
|
|---|
| 641 | c->BackBufferNumber=0;
|
|---|
| 642 |
|
|---|
| 643 | DiveEndImageBufferAccess(Current->hDiveInstance,ulb);
|
|---|
| 644 | }
|
|---|
| 645 | }
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 | BOOL _System DiveDirectAccess(void)
|
|---|
| 649 | {
|
|---|
| 650 | return DiveCaps.fScreenDirect;
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | ULONG _System DiveQueryDepth(void)
|
|---|
| 654 | {
|
|---|
| 655 | return DiveCaps.ulDepth;
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | ULONG _System DiveQueryNativePixelFormat(void)
|
|---|
| 659 | {
|
|---|
| 660 | switch(DiveCaps.fccColorEncoding)
|
|---|
| 661 | {
|
|---|
| 662 | case FOURCC_LUT8:
|
|---|
| 663 | return PF_INDEX8;
|
|---|
| 664 |
|
|---|
| 665 | case FOURCC_BGR4:
|
|---|
| 666 | return PF_8A8B8G8R;
|
|---|
| 667 |
|
|---|
| 668 | case FOURCC_RGB3:
|
|---|
| 669 | return PF_8R8G8B;
|
|---|
| 670 |
|
|---|
| 671 | case FOURCC_R565:
|
|---|
| 672 | return PF_5R6G5B;
|
|---|
| 673 |
|
|---|
| 674 | case FOURCC_GREY:
|
|---|
| 675 | return PF_GRAYSCALE;
|
|---|
| 676 |
|
|---|
| 677 | default:
|
|---|
| 678 | dprintf(("OPENGL32: Color encoding %X not matched\n",DiveCaps.fccColorEncoding));
|
|---|
| 679 | break;
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 | return 0;
|
|---|
| 683 | }
|
|---|
| 684 |
|
|---|
| 685 | void _System DiveResizeBuffers(GLint width,GLint height)
|
|---|
| 686 | {
|
|---|
| 687 | ULONG rc;
|
|---|
| 688 |
|
|---|
| 689 | dprintf(("OPENGL32: DiveResizeBuffers to %d/%d\n",width,height));
|
|---|
| 690 | dprintf(("OPENGL32: DiveResizeBuffers Current size %d/%d\n",Current->awidth,Current->aheight));
|
|---|
| 691 |
|
|---|
| 692 | if(!Current)
|
|---|
| 693 | return;
|
|---|
| 694 |
|
|---|
| 695 | if(Current->awidth==width && Current->aheight==height)
|
|---|
| 696 | return;
|
|---|
| 697 |
|
|---|
| 698 | DiveBlitSetup(Current,FALSE);
|
|---|
| 699 |
|
|---|
| 700 | Current->awidth=width;
|
|---|
| 701 | Current->aheight=height;
|
|---|
| 702 |
|
|---|
| 703 | if(Current->db_flag)
|
|---|
| 704 | {
|
|---|
| 705 | rc=DiveEndImageBufferAccess(Current->hDiveInstance,
|
|---|
| 706 | Current->BackBufferNumber);
|
|---|
| 707 |
|
|---|
| 708 | dprintf(("OPENGL32: DiveEndImageBufferAccess rc %d\n",rc));
|
|---|
| 709 |
|
|---|
| 710 | rc=DiveFreeImageBuffer(Current->hDiveInstance,
|
|---|
| 711 | Current->BackBufferNumber);
|
|---|
| 712 |
|
|---|
| 713 | dprintf(("OPENGL32: DiveFreeImageBuffer rc %d\n",rc));
|
|---|
| 714 |
|
|---|
| 715 | if(Current->BackBufferOwnAllocation)
|
|---|
| 716 | {
|
|---|
| 717 | dprintf(("OPENGL32: Reallocating OWN BlitBuffer %d/%d\n",
|
|---|
| 718 | Current->awidth,Current->aheight));
|
|---|
| 719 |
|
|---|
| 720 | free(Current->pbPixels);
|
|---|
| 721 |
|
|---|
| 722 | Current->pbPixels=AllocateBuffer(Current->awidth,
|
|---|
| 723 | Current->aheight,
|
|---|
| 724 | Current->pixelformat,
|
|---|
| 725 | &Current->ScanWidth);
|
|---|
| 726 |
|
|---|
| 727 | Current->BackBufferNumber=0;
|
|---|
| 728 |
|
|---|
| 729 | rc=DiveAllocImageBuffer(Current->hDiveInstance,
|
|---|
| 730 | &Current->BackBufferNumber,
|
|---|
| 731 | GetFOURCC(Current->pixelformat),
|
|---|
| 732 | Current->awidth,
|
|---|
| 733 | Current->aheight,
|
|---|
| 734 | Current->ScanWidth,
|
|---|
| 735 | Current->pbPixels);
|
|---|
| 736 |
|
|---|
| 737 | ULONG bsl;
|
|---|
| 738 |
|
|---|
| 739 | rc=DiveBeginImageBufferAccess(Current->hDiveInstance,
|
|---|
| 740 | Current->BackBufferNumber,
|
|---|
| 741 | &Current->pbPixels,
|
|---|
| 742 | &Current->ScanWidth,
|
|---|
| 743 | &bsl);
|
|---|
| 744 | }
|
|---|
| 745 | else
|
|---|
| 746 | {
|
|---|
| 747 | dprintf(("OPENGL32: Reallocating BlitBuffer %d/%d\n",
|
|---|
| 748 | Current->awidth,Current->aheight));
|
|---|
| 749 |
|
|---|
| 750 | Current->BackBufferNumber=0;
|
|---|
| 751 |
|
|---|
| 752 | rc=DiveAllocImageBuffer(Current->hDiveInstance,
|
|---|
| 753 | &Current->BackBufferNumber,
|
|---|
| 754 | GetFOURCC(Current->pixelformat),
|
|---|
| 755 | Current->awidth,
|
|---|
| 756 | Current->aheight,
|
|---|
| 757 | 0,
|
|---|
| 758 | 0);
|
|---|
| 759 |
|
|---|
| 760 | ULONG bsl;
|
|---|
| 761 |
|
|---|
| 762 | rc=DiveBeginImageBufferAccess(Current->hDiveInstance,
|
|---|
| 763 | Current->BackBufferNumber,
|
|---|
| 764 | &Current->pbPixels,
|
|---|
| 765 | &Current->ScanWidth,
|
|---|
| 766 | &bsl);
|
|---|
| 767 | }
|
|---|
| 768 | }
|
|---|
| 769 |
|
|---|
| 770 | DiveBlitSetup(Current,TRUE);
|
|---|
| 771 | }
|
|---|