Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

837 lines
30 KiB

  1. /*
  2. ** Copyright 1991, 1992, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. */
  17. #ifndef __GLGENCONTXT_H__
  18. #define __GLGENCONTXT_H__
  19. #include "context.h"
  20. #ifdef _MCD_
  21. #include <winddi.h>
  22. #include "mcdrv.h"
  23. #include "mcd2hack.h"
  24. #include "mcd.h"
  25. #endif
  26. // Re-enable long to float conversion warning. see also context.h
  27. #pragma warning (default:4244)
  28. #ifdef _CLIENTSIDE_
  29. #include "glscreen.h"
  30. #include "glgenwin.h"
  31. #endif
  32. #ifdef _MCD_
  33. #include "mcdcx.h"
  34. #endif
  35. /*
  36. * Define maximum color-index table size
  37. */
  38. #define MAXPALENTRIES 4096
  39. /*
  40. * Machine dependent implementation limits
  41. * (stolen from gfx/lib/opengl/LIGHT/rexcx.h)
  42. */
  43. #define __GL_WGL_SUBPIXEL_BITS 3
  44. #define __GL_WGL_NUMBER_OF_CLIP_PLANES 6
  45. #define __GL_WGL_NUMBER_OF_LIGHTS 8
  46. #define __GL_WGL_NUMBER_OF_TEXTURES 1
  47. #define __GL_WGL_NUMBER_OF_TEXTURE_ENVS 1
  48. #define __GL_WGL_MAX_MODELVIEW_STACK_DEPTH 32
  49. #define __GL_WGL_MAX_PROJECTION_STACK_DEPTH 10
  50. #define __GL_WGL_MAX_TEXTURE_STACK_DEPTH 10
  51. #define __GL_WGL_MAX_ATTRIB_STACK_DEPTH 16
  52. #define __GL_WGL_MAX_CLIENT_ATTRIB_STACK_DEPTH 16
  53. #define __GL_WGL_MAX_NAME_STACK_DEPTH 128
  54. #define __GL_WGL_MAX_EVAL_ORDER 30
  55. #define __GL_WGL_MAX_MIPMAP_LEVEL 11
  56. #define __GL_WGL_MAX_PIXEL_MAP_TABLE 65536
  57. #define __GL_WGL_MAX_LIST_NESTING 64
  58. #define __GL_WGL_POINT_SIZE_MINIMUM ((__GLfloat) 0.5)
  59. #define __GL_WGL_POINT_SIZE_MAXIMUM ((__GLfloat) 10.0)
  60. #define __GL_WGL_POINT_SIZE_GRANULARITY ((__GLfloat) 0.125)
  61. #define __GL_WGL_LINE_WIDTH_MINIMUM ((__GLfloat) 0.5)
  62. #define __GL_WGL_LINE_WIDTH_MAXIMUM ((__GLfloat) 10.0)
  63. #define __GL_WGL_LINE_WIDTH_GRANULARITY ((__GLfloat) 0.125)
  64. // Constants for fast accelerated texture code...
  65. #define TEX_SCALEFACT ((float)65536.0)
  66. #define TEX_SCALESHIFT 16
  67. #define TEX_SHIFTPER4BPPTEXEL 2
  68. #define TEX_SHIFTPER2BPPTEXEL 1
  69. #define TEX_SHIFTPER1BPPTEXEL 0
  70. #define TEX_T_FRAC_BITS 6
  71. #define TEX_SUBDIV 8
  72. #define TEX_SUBDIV_LOG2 3
  73. // This is the largest size we support in the software-accelerated
  74. // perspective-corrected texture code. This allows 8.6 representation for
  75. // s and t, which permits shifting by constant values in the inner loop.
  76. // Note that the maximum size for paletted textures is greater than for
  77. // RGBA textures, since the number of address bits is smaller (1 byte vs
  78. // 4 bytes).
  79. #define TEX_MAX_SIZE_LOG2 10
  80. #define __GL_MAX_INV_TABLE 31
  81. #define __GL_UNBIAS_AND_INVERT_Y(gc, y) \
  82. ((gc)->constants.height - __GL_UNBIAS_Y((gc), (y)))
  83. // XXX do we need to add .5?
  84. #define __GL_COLOR_TO_COLORREF(color) \
  85. RGB( (BYTE)((color)->r), (BYTE)((color)->g), (BYTE)((color)->b))
  86. typedef struct __RenderStateRec {
  87. GLuint *SrvSelectBuffer; // Server side address of
  88. // the selection buffer.
  89. GLuint *CltSelectBuffer; // Client address of the
  90. // Selection buffer
  91. GLuint SelectBufferSize; // Size of select buffer in bytes
  92. GLfloat *SrvFeedbackBuffer; // Server side address of the
  93. // feedback buffer
  94. GLfloat *CltFeedbackBuffer; // Client side address of the
  95. // Feedback buffer.
  96. GLuint FeedbackBufferSize; // Size of the feedback buffer
  97. GLenum FeedbackType; // Type of elements for feedback
  98. } __RenderState;
  99. typedef BOOL (APIENTRY *PIXVISPROC)(LONG, LONG);
  100. typedef void (*PIXCOPYPROC)(struct __GLGENcontextRec *, __GLcolorBuffer *,
  101. GLint, GLint, GLint, BOOL);
  102. /****************************************************************************/
  103. typedef struct _SPANREC {
  104. LONG r;
  105. LONG g;
  106. LONG b;
  107. LONG a;
  108. ULONG z;
  109. LONG s;
  110. LONG t;
  111. } SPANREC;
  112. typedef struct __GLGENcontextRec __GLGENcontext;
  113. typedef void (FASTCALL *__genSpanFunc)(__GLGENcontext *gc);
  114. typedef ULONG (FASTCALL *__computeColorFunc)(__GLcontext *gc,
  115. __GLcolor *color);
  116. typedef struct _GENTEXCACHE {
  117. __GLcontext *gc;
  118. ULONG paletteTimeStamp;
  119. UCHAR *texImageReplace;
  120. GLenum internalFormat;
  121. LONG height;
  122. LONG width;
  123. } GENTEXCACHE;
  124. typedef GLboolean (FASTCALL *fastGenLineProc)(__GLcontext *gc);
  125. typedef struct _GENACCEL {
  126. //
  127. // stuff below here is used in the rendering inner loops
  128. //
  129. ULONG constantR; // These are used for scaling texture color values
  130. ULONG constantG;
  131. ULONG constantB;
  132. ULONG constantA;
  133. SPANREC spanValue;
  134. SPANREC spanDelta;
  135. ULONG rAccum;
  136. ULONG gAccum;
  137. ULONG bAccum;
  138. ULONG aAccum;
  139. ULONG sAccum;
  140. ULONG tAccum;
  141. ULONG sResult[2];
  142. ULONG tResult[2];
  143. ULONG sResultNew[2];
  144. ULONG tResultNew[2];
  145. ULONG sStepX;
  146. ULONG tStepX;
  147. ULONG subDs;
  148. ULONG subDt;
  149. ULONG pixAccum;
  150. ULONG ditherAccum;
  151. __GLfloat qwStepX;
  152. __GLfloat qwAccum;
  153. ULONG zAccum;
  154. PBYTE pPix;
  155. BYTE displayColor[4];
  156. __genSpanFunc __fastSpanFuncPtr;
  157. //
  158. // stuff below here is used in the FillTriangle routine
  159. //
  160. SPANREC spanDeltaY;
  161. int xMultiplier;
  162. __genSpanFunc __fastFlatSpanFuncPtr;
  163. __genSpanFunc __fastSmoothSpanFuncPtr;
  164. __genSpanFunc __fastTexSpanFuncPtr;
  165. __GLspanFunc __fastZSpanFuncPtr;
  166. __GLspanFunc __fastStippleDepthTestSpan;
  167. __GLfloat rAccelScale; // Span scale values
  168. __GLfloat gAccelScale;
  169. __GLfloat bAccelScale;
  170. __GLfloat aAccelScale;
  171. __GLfloat zScale;
  172. void (FASTCALL *__fastFillSubTrianglePtr)(__GLcontext *, GLint, GLint);
  173. void (FASTCALL *__fastCalcDeltaPtr)(__GLcontext *gc, __GLvertex *a,
  174. __GLvertex *b, __GLvertex *c);
  175. void (*__fastSetInitParamPtr)(__GLcontext *gc,
  176. const __GLvertex *a,
  177. __GLfloat dx,
  178. __GLfloat dy);
  179. //
  180. // these things are used in the generic rendering or texture path
  181. //
  182. int bpp;
  183. ULONG flags;
  184. ULONG tShift;
  185. ULONG sMask, tMask;
  186. ULONG *texImage;
  187. ULONG *texPalette;
  188. ULONG tMaskSubDiv;
  189. ULONG tShiftSubDiv;
  190. __GLfloat texXScale;
  191. __GLfloat texYScale;
  192. UCHAR *texImageReplace;
  193. __GLtexture *tex;
  194. GLboolean (FASTCALL *__fastGenZStore)(__GLzValue z, __GLzValue *fp);
  195. fastGenLineProc __fastGenLineProc;
  196. BOOL (FASTCALL *__fastGenInitLineData)(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  197. //
  198. // stuff below here is not used in drawing triangles
  199. //
  200. char *buffer;
  201. FLONG flLineAccelModes;
  202. BOOL bFastLineDispAccel;
  203. BOOL bFastLineDIBAccel;
  204. __computeColorFunc fastLineComputeColor;
  205. BYTE *pFastLineBuffer;
  206. POINT *pFastLinePoint;
  207. DWORD *pFastLineCount;
  208. DWORD fastLineCounts;
  209. __GLfloat fastLineOffsetX;
  210. __GLfloat fastLineOffsetY;
  211. double zDevScale; // z scaling for MCD
  212. } GENACCEL;
  213. /*
  214. ** Secondary dispatch tables for GENENERIC implementation (eg CPU specific)
  215. */
  216. // Define the Rendering context used by the Generic implementation
  217. // One of these structures is allocated for each wglCreateContext(). The
  218. // TEB will contain a pointer to this structure after a wglMakeCurrent()
  219. // NOTE: the TEB will also have a pointer to DispatchTables, if we need
  220. // another entry on the server side, reuse that one. Could generate code to
  221. // offset into contextRec to get a tables.
  222. typedef struct __GLGENcontextRec
  223. {
  224. // Must be first entry
  225. struct __GLcontextRec gc;
  226. HGLRC hrc; // handle from gdi code
  227. GLWINDOWID gwidCurrent; // Surface made current
  228. DWORD dwCurrentFlags; // GLSURF flags for current surface
  229. GLDDSURF *pgddsFront; // Current DirectDraw surface for
  230. // front buffer
  231. GLuint flags; // misc. state flags
  232. // Window that this context was made current to. Set in MakeCurrent and
  233. // kept to validate that attentions are taking place on the same
  234. // window as was made current.
  235. GLGENwindow *pwndMakeCur;
  236. // Window that this context current is holding a lock on. While
  237. // locked, this must always match pwndMakeCur. When outside the
  238. // lock it will be NULL. Any context-derived window access must
  239. // use this field rather than pwndMakeCur to ensure that access
  240. // only takes place while the window lock is held.
  241. GLGENwindow *pwndLocked;
  242. GLint WndUniq;
  243. GLint WndSizeUniq;
  244. ULONG PaletteTimestamp;
  245. GLint errorcode;
  246. // info for render DC, surface
  247. GLSURF gsurf;
  248. int ipfdCurrent;
  249. BYTE *pajTranslateVector; // Used for Logical <--> System xlate
  250. BYTE *pajInvTranslateVector;
  251. HBITMAP ColorsBitmap; // GDI dibs for device managed surfs
  252. PVOID ColorsBits;
  253. HBITMAP StippleBitmap;
  254. PVOID StippleBits;
  255. #ifdef _CLIENTSIDE_
  256. HDC ColorsMemDC;
  257. HDC ColorsDdbDc;
  258. HBITMAP ColorsDdb;
  259. #endif
  260. // Cached GDI objects for rectangle filling and line drawing
  261. HBRUSH hbrFill;
  262. COLORREF crFill;
  263. HDC hdcFill;
  264. HPEN hpenStroke;
  265. __GLcolor cStroke;
  266. COLORREF crStroke;
  267. HDC hdcStroke;
  268. BOOL fStrokeInvalid;
  269. // A COLORREF value which isn't a legal COLORREF, used for marking
  270. // the caches as empty
  271. #define COLORREF_UNUSED 0xffffffff
  272. __RenderState RenderState;
  273. VOID *pPrivateArea; // Pointer to implementation-specific
  274. // memory area.
  275. GENACCEL genAccel; // Always have this handy...
  276. BYTE xlatPalette[256]; // goes here to save indirection
  277. GLint visibleWidth;
  278. GLint visibleHeight;
  279. // Information so that OpenGL can adaptively change the amount of
  280. // time the lock is held.
  281. DWORD dwLockTick; // tick count when lock was acquired
  282. DWORD dwCalls; // tracks number of calls for this tick
  283. DWORD dwCallsPerTick; // number of calls per tick allowed
  284. DWORD dwLastTick; // last recorded tick count
  285. // Locks held by OpenGL while drawing to this context (see values
  286. // below).
  287. FSHORT fsGenLocks; // locks needed for generic code
  288. FSHORT fsLocks; // locks actually held
  289. HANDLE hTexture; // current texture handle
  290. PIXCOPYPROC pfnCopyPixels;
  291. PIXVISPROC pfnPixelVisible;
  292. #ifdef _CLIENTSIDE_
  293. // Pointers to LOGPALETTE buffers. The pointer ppalBuf is storage for
  294. // for two maximally sized (MAXPALENTRIES) LOGPALETTEs. One, pointed
  295. // to by ppalSave, is a copy of the last LOGPALETTE used. The other,
  296. // pointed to by ppalTmp, is used for temporary storage of the current
  297. // LOGPALETTE. To keep the saved copy current, rather than copy the
  298. // contents of the temp buffer, the two pointers are swapped.
  299. //
  300. // We need to do this comparison to detect LOGPALETTE changes to maintain
  301. // the window ulPaletteUniq when doing >= 16bpp color index-mode drawing
  302. // (WM_PALETTECHANGED messages are not sent for this case).
  303. //
  304. // The LOGPALETTE pointers are NULL if pixelformat is RGBA or < 16bpp.
  305. LOGPALETTE *ppalBuf; // Room for both save and tmp buffers.
  306. LOGPALETTE *ppalSave; // Saved copy of LOGPALETTE
  307. LOGPALETTE *ppalTemp; // Temp storage for current LOGPALETTE
  308. // In addition, if we are rendering to a 4bpp or 8bpp DIB, we need to
  309. // track changes in the DIB color table. In this case, the ppalBuf
  310. // buffer also includes room for two 256-entry RGBQUAD tables.
  311. ULONG crgbSave; // Num of valid entries in color table
  312. RGBQUAD *prgbSave; // Saved copy of color table
  313. ULONG crgbTemp;
  314. RGBQUAD *prgbTemp; // Temp storage for color table
  315. #endif
  316. #ifdef _MCD_
  317. // MCD state
  318. GENMCDSTATE *_pMcdState; // pointer to MCD context/state
  319. GENMCDSTATE *pMcdState; // pointer to bound MCD context/state
  320. // (implies both _pMcdState and pMcdSurf
  321. // valid; i.e., valid MCD context is
  322. // bound to a valid MCD surface)
  323. LONG iLayerPlane;
  324. #endif
  325. // Add other rc info here
  326. } __GLGENcontext;
  327. /*
  328. * Mark the gc as dirty so that pick procs will be executed when
  329. * __glGenericPickAllProcs is called (probably via gc->proc.pickAllProcs).
  330. */
  331. #define __GL_INVALIDATE(gc) \
  332. (gc)->dirtyMask |= __GL_DIRTY_GENERIC
  333. /*
  334. * __GLGENcontext flags
  335. *
  336. * GLGEN_MCD_CONVERTED_TO_GENERIC context used to be MCD, but now
  337. * converted to generic
  338. *
  339. * GENGC_MCD_BGR_INTO_RGB fake 233BGR format to appear internally
  340. * as 332RGB (more 332RGB fast path code)
  341. *
  342. * GENGC_GENERIC_COMPATIBLE_FORMAT pixel format is compatible with
  343. * generic code (see in pixelfmt.c
  344. * GenMcdGenericCompatibleFormat)
  345. */
  346. #define GLGEN_MCD_CONVERTED_TO_GENERIC 0x0001
  347. #define GENGC_MCD_BGR_INTO_RGB 0x0002
  348. #define GENGC_GENERIC_COMPATIBLE_FORMAT 0x0004
  349. /*
  350. * Error codes
  351. */
  352. #define GLGEN_NO_ERROR 0
  353. #define GLGEN_OUT_OF_MEMORY 1
  354. #define GLGEN_GRE_FAILURE 2
  355. #define GLGEN_DEVLOCK_FAILED 3
  356. /*
  357. * Locks that can be held during operation.
  358. *
  359. * Value Description
  360. * ------------------------------------------------------------------
  361. * LOCKFLAG_WINDOW Window information semaphore.
  362. * LOCKFLAG_MCD MCD lock.
  363. * LOCKFLAG_FRONT_BUFFER Primary surface lock.
  364. * LOCKFLAG_DD_DEPTH DirectDraw depth buffer surface lock.
  365. * LOCKFLAG_DD_TEXTURE DirectDraw texture mipmap surface locks.
  366. *
  367. * __GLGENcontext.fsLocks indicates the locks currently held by the context.
  368. * __GLGENcontext.fsGenLocks indicates the locks that need to be held
  369. * if generic code is going to be executed. The two fields allow
  370. * lazy acquisition of locks by deferring actual locking until just
  371. * before generic code is executed.
  372. *
  373. */
  374. #define LOCKFLAG_WINDOW 0x0001
  375. #define LOCKFLAG_MCD 0x0002
  376. #define LOCKFLAG_FRONT_BUFFER 0x0004
  377. #define LOCKFLAG_DD_DEPTH 0x0008
  378. #define LOCKFLAG_DD_TEXTURE 0x0010
  379. // All lock flags that can be lazily acquired.
  380. #define LAZY_LOCK_FLAGS \
  381. (LOCKFLAG_MCD | LOCKFLAG_FRONT_BUFFER | LOCKFLAG_DD_DEPTH | \
  382. LOCKFLAG_DD_TEXTURE)
  383. // All lock flags for surfaces.
  384. #define SURFACE_LOCK_FLAGS \
  385. (LOCKFLAG_FRONT_BUFFER | LOCKFLAG_DD_DEPTH | LOCKFLAG_DD_TEXTURE)
  386. // All lock flags for color buffer access.
  387. #define COLOR_LOCK_FLAGS (LOCKFLAG_MCD | LOCKFLAG_FRONT_BUFFER)
  388. // All lock flags for depth buffer access.
  389. #define DEPTH_LOCK_FLAGS (LOCKFLAG_MCD | LOCKFLAG_DD_DEPTH)
  390. // All lock flags for texture access.
  391. #define TEXTURE_LOCK_FLAGS LOCKFLAG_DD_TEXTURE
  392. // Accesses required for fragment rendering.
  393. #define RENDER_LOCK_FLAGS (COLOR_LOCK_FLAGS | DEPTH_LOCK_FLAGS | \
  394. TEXTURE_LOCK_FLAGS)
  395. /*
  396. * Screen lock testing functions. GDI drawing calls should not be made
  397. * when the screen lock is held. These are for
  398. * use on a checked (debug system) to assert the state of the lock.
  399. */
  400. #if DBG
  401. #define GENGC_LOCK \
  402. (((__GLGENcontext *)GLTEB_SRVCONTEXT())->fsLocks)
  403. #define PWNDFLAGS \
  404. ((((__GLGENcontext *)GLTEB_SRVCONTEXT())->pwndLocked)->ulFlags)
  405. #define CHECKSCREENLOCKOUT() \
  406. ASSERTOPENGL(GLTEB_SRVCONTEXT() == NULL || \
  407. !(GENGC_LOCK & LOCKFLAG_FRONT_BUFFER) || \
  408. !(PWNDFLAGS & GLGENWIN_DIRECTSCREEN), \
  409. "Screen lock held\n")
  410. #define CHECKSCREENLOCKIN() \
  411. ASSERTOPENGL(GLTEB_SRVCONTEXT() != NULL && \
  412. (GENGC_LOCK & LOCKFLAG_FRONT_BUFFER) && \
  413. (PWNDFLAGS & GLGENWIN_DIRECTSCREEN), \
  414. "Screen lock not held\n")
  415. #else
  416. #define CHECKSCREENLOCKOUT()
  417. #define CHECKSCREENLOCKIN()
  418. #endif
  419. /*
  420. * Structure to keep track of ancillary buffers for a window/drawable
  421. * All RCs/threads must share the ancillary buffers, including fake back buffer
  422. */
  423. typedef struct __GLGENbitmapRec {
  424. GLGENwindow *pwnd; // This must be the first member in this structure
  425. GLGENwindow wnd;
  426. HBITMAP hbm;
  427. HDC hdc;
  428. PVOID pvBits;
  429. } __GLGENbitmap;
  430. #define CURRENT_DC_CFB(cfb) ((cfb)->bitmap->hdc)
  431. #define CURRENT_DC CURRENT_DC_CFB(cfb)
  432. #define CURRENT_DC_GC(gc) CURRENT_DC_CFB(gc->drawBuffer)
  433. #define CURRENT_DC_FRONT_GC(gc) CURRENT_DC_CFB(gc->front)
  434. /*
  435. * Structure used to cache clip rectangles enumerated from window clip region.
  436. */
  437. typedef struct __GLGENclipCacheRec {
  438. GLint WndUniq;
  439. GLint crcl;
  440. RECTL *prcl;
  441. } __GLGENclipCache;
  442. /****************************************************************************/
  443. // Make sure this header file is loaded, it contains the rectlist definition.
  444. #include "srvp.h"
  445. /****************************************************************************/
  446. // Comment it out if the __glDoPolygonClip stack allocation fix is not
  447. // wanted
  448. #define __CLIP_FIX
  449. #ifdef __CLIP_FIX
  450. #define __GL_TOTAL_CLIP_PLANES 20 /*XXX*/
  451. #define __GL_MAX_CLIP_VERTEX (__GL_TOTAL_CLIP_PLANES + __GL_MAX_POLYGON_CLIP_SIZE)
  452. #endif
  453. /*
  454. * This structure contains the buffers shared by all gc's using the
  455. * same window.
  456. */
  457. struct __GLGENbuffersRec {
  458. // Global (within this structure) state.
  459. GLint WndUniq;
  460. GLint WndSizeUniq;
  461. GLint flags;
  462. GLint width, height;
  463. // Ancillary buffers and state.
  464. // The ancillary buffers are lazily created. The createdXBuffer flags
  465. // indicate one of two states: FALSE means that the lazy allocation
  466. // function has never been called, TRUE means that it has. What this
  467. // allows us to do, in the event of an ancillary buffer allocation
  468. // failure, is temporarily disable the ancillary buffer and continue to
  469. // render. At some later time, the createdXBuffer flag serves as an
  470. // indication that the buffer SHOULD exist and that we may need to try
  471. // and retry the allocation.
  472. //
  473. // The stencil, depth, accum, and color bits must match the corresponding
  474. // bits in the context. Otherwise, glsrvMakeCurrent should not succeed.
  475. GLboolean createdStencilBuffer;
  476. GLboolean createdDepthBuffer;
  477. GLboolean createdAccumBuffer;
  478. GLint stencilBits;
  479. GLint depthBits;
  480. GLint accumBits;
  481. GLint colorBits;
  482. __GLbuffer stencilBuffer;
  483. __GLbuffer depthBuffer;
  484. __GLbuffer accumBuffer;
  485. GLint alphaBits;
  486. __GLbuffer alphaBuffer0;
  487. __GLbuffer alphaBuffer1;
  488. __GLbuffer *alphaFrontBuffer;
  489. __GLbuffer *alphaBackBuffer;
  490. // Back buffer.
  491. __GLbuffer backBuffer;
  492. __GLGENbitmap backBitmap;
  493. // Ancillary buffer resize functions.
  494. GLboolean (*resize)(__GLGENbuffers *, __GLbuffer *, GLint, GLint);
  495. GLboolean (*resizeDepth)(__GLGENbuffers *, __GLbuffer *, GLint, GLint);
  496. // Clip rectangle cache.
  497. __GLGENclipCache clip;
  498. // dirty regions data
  499. PXLIST pxlist; // free lists
  500. PYLIST pylist;
  501. RECTLIST rl; // SwapBuffers Hint Region
  502. BOOL fMax; // should we blt the entire window?
  503. #ifdef _MCD_
  504. // MCD surface.
  505. GENMCDSURFACE *pMcdSurf; // pointer MCD surface
  506. GENMCDSTATE *pMcdState; // pointer to current MCD state
  507. // holding McdSurf for rendering
  508. // (i.e., holds the window lock)
  509. #endif
  510. #ifdef __CLIP_FIX
  511. __GLvertex *clip_verts[__GL_TOTAL_CLIP_PLANES][__GL_MAX_CLIP_VERTEX];
  512. #endif
  513. };
  514. /* flags */
  515. #define GLGENBUF_HAS_BACK_BUF 0x0001
  516. #define GLGENBUF_MCD_LOST 0x0002
  517. /****************************************************************************/
  518. void RECTLISTAddRect(PRECTLIST prl, int xs, int ys, int xe, int ye);
  519. void RECTLISTSetEmpty(PRECTLIST prl);
  520. BOOL RECTLISTIsEmpty(PRECTLIST prl);
  521. void YLISTFree(__GLGENbuffers *buffers, PYLIST pylist);
  522. void XLISTFree(__GLGENbuffers *buffers, PXLIST pxlist);
  523. /****************************************************************************/
  524. /* colorbuffer flags */
  525. #define COLORMASK_ON 0x0001 // glColorMask() not all true for r,g,b
  526. #define INDEXMASK_ON 0x0001 // glIndexMask() not all 1's
  527. #define DIB_FORMAT 0x0002 // surface is DIB format
  528. #define NEED_FETCH 0x0004 // fetch required
  529. #define MEMORY_DC 0x0008 // set if DIB in memory (ie !display)
  530. #define NO_CLIP 0x0010 // Set if surface never requires clip
  531. #define ALPHA_ON 0x0020 // have alphaBits, alphaMask is true
  532. #define ALPHA_IN_PIXEL_BIT 0x0040 // alpha is part of the pixel
  533. #define ALPHA_WRITE_ENABLED( cfb ) \
  534. ( (cfb)->buf.flags & ALPHA_ON )
  535. // These next macros take into account the fact that alpha values can either be
  536. // part of the pixel (e.g. MCD color buffer), or are kept in a separate software
  537. // buffer (generic software implementation). They are mostly used by the span
  538. // routines in genrgb.c to determine where to store/fetch alpha values.
  539. #define ALPHA_IN_PIXEL( cfb ) \
  540. ( (cfb)->buf.flags & ALPHA_IN_PIXEL_BIT )
  541. #define ALPHA_BUFFER_WRITE( cfb ) \
  542. (((cfb)->buf.flags & (ALPHA_ON | ALPHA_IN_PIXEL_BIT)) == ALPHA_ON)
  543. #define ALPHA_PIXEL_WRITE( cfb ) \
  544. (((cfb)->buf.flags & (ALPHA_ON | ALPHA_IN_PIXEL_BIT)) == \
  545. (ALPHA_ON | ALPHA_IN_PIXEL_BIT))
  546. /*
  547. * Structures and flags for accelerated span and line functions.
  548. */
  549. #define SURFACE_TYPE_DIB 0x001
  550. #define HAVE_STIPPLE 0x002
  551. #define GEN_TEXTURE_ORTHO 0x008
  552. #define GEN_TEXTURE 0x010
  553. #define GEN_RGBMODE 0x020
  554. #define GEN_DITHER 0x040
  555. #define GEN_SHADE 0x080
  556. #define GEN_FASTZBUFFER 0x100
  557. #define GEN_LESS 0x200
  558. #define ACCEL_FIX_SCALE 65536.0
  559. #define ACCEL_COLOR_SCALE ((GLfloat)(255.0))
  560. #define ACCEL_COLOR_SCALE_FIX ((GLfloat)(65536.0 * 255.0))
  561. // Overall size of fast line buffer
  562. #define __FAST_LINE_BUFFER_SIZE 65536
  563. // Number of polyline counts reserved in the fast line buffer
  564. // This is computed to roughly handle lines with eight vertices
  565. #define __FAST_LINE_BUFFER_COUNTS (__FAST_LINE_BUFFER_SIZE/64)
  566. #define GENACCEL(gc) (((__GLGENcontext *)gc)->genAccel)
  567. BOOL FASTCALL __glGenCreateAccelContext(__GLcontext *gc);
  568. void FASTCALL __glGenDestroyAccelContext(__GLcontext *gc);
  569. #define Copy3Bytes( dst, src ) \
  570. { \
  571. GLubyte *ps = (GLubyte *)src, *pd = (GLubyte *)dst; \
  572. *pd++ = *ps++; \
  573. *pd++ = *ps++; \
  574. *pd = *ps ; \
  575. }
  576. #define NeedLogicOpFetch( op ) \
  577. !( (op == GL_CLEAR) || (op == GL_COPY) || (op == GL_COPY_INVERTED) || \
  578. (op == GL_SET) )
  579. GLuint FASTCALL DoLogicOp( GLenum logicOp, GLuint SrcColor, GLuint DstColor );
  580. /*
  581. * Function Prototypes for Generic calls
  582. */
  583. void FASTCALL __fastGenPickSpanProcs(__GLcontext *gc);
  584. void FASTCALL __fastGenPickZStoreProc(__GLcontext *gc);
  585. void FASTCALL __fastGenPickTriangleProcs(__GLcontext *gc);
  586. void FASTCALL __fastGenPickLineProcs(__GLcontext *gc);
  587. void FASTCALL __fastGenFillSubTriangle(__GLcontext *, GLint, GLint);
  588. void FASTCALL __fastGenFillSubTriangleTexRGBA(__GLcontext *, GLint, GLint);
  589. void FASTCALL __glGenPickStoreProcs(__GLcontext *gc);
  590. __GLcontext *__glGenCreateContext( HDC hdc, ULONG handle);
  591. void ResizeBitmapBuffer(__GLGENbuffers *, __GLcolorBuffer *, GLint, GLint);
  592. void FASTCALL ClearBitmapBuffer(__GLcolorBuffer *);
  593. void UpdateSharedBuffer(__GLbuffer *to, __GLbuffer *from);
  594. void FASTCALL LazyAllocateDepth(__GLcontext *gc);
  595. void FASTCALL LazyAllocateAccum(__GLcontext *gc);
  596. void FASTCALL LazyAllocateStencil(__GLcontext *gc);
  597. void FASTCALL glGenInitCommon(__GLGENcontext *gengc, __GLcolorBuffer *cfb, GLenum type);
  598. BOOL FASTCALL wglCreateScanlineBuffers(__GLGENcontext *gengc);
  599. VOID FASTCALL wglDeleteScanlineBuffers(__GLGENcontext *gengc);
  600. VOID FASTCALL wglInitializeColorBuffers(__GLGENcontext *gengc);
  601. VOID FASTCALL wglInitializeDepthBuffer(__GLGENcontext *gengc);
  602. VOID FASTCALL wglInitializePixelCopyFuncs(__GLGENcontext *gengc);
  603. GLboolean ResizeAncillaryBuffer(__GLGENbuffers *, __GLbuffer *, GLint, GLint);
  604. GLboolean ResizeUnownedDepthBuffer(__GLGENbuffers *, __GLbuffer *, GLint, GLint);
  605. VOID wglResizeBuffers(__GLGENcontext *gengc, GLint width, GLint height);
  606. BOOL wglUpdateBuffers(__GLGENcontext *gengc, __GLGENbuffers *buffers);
  607. extern void APIPRIVATE glsrvFlushDrawPolyArray(struct _POLYARRAY *, BOOL);
  608. MCDHANDLE FASTCALL __glGenLoadTexture(__GLcontext *gc, __GLtexture *tex, ULONG flags);
  609. BOOL FASTCALL __glGenUpdateTexture(__GLcontext *gc, __GLtexture *tex, MCDHANDLE loadKey);
  610. void FASTCALL __glGenFreeTexture(__GLcontext *gc, __GLtexture *tex, MCDHANDLE loadKey);
  611. BOOL FASTCALL __glGenMakeTextureCurrent(__GLcontext *gc, __GLtexture *tex, MCDHANDLE loadKey);
  612. void FASTCALL __glGenUpdateTexturePalette(__GLcontext *gc, __GLtexture *tex, MCDHANDLE loadKey,
  613. ULONG start, ULONG count);
  614. #ifdef GL_EXT_flat_paletted_lighting
  615. void FASTCALL __glGenSetPaletteOffset(__GLcontext *gc, __GLtexture *tex,
  616. GLint offset);
  617. #endif
  618. /*
  619. * Function Prototypes and Externs for accelerated generic calls
  620. */
  621. extern __genSpanFunc __fastGenRGBFlatFuncs[];
  622. extern __genSpanFunc __fastGenCIFlatFuncs[];
  623. extern __genSpanFunc __fastGenRGBFuncs[];
  624. extern __genSpanFunc __fastGenCIFuncs[];
  625. extern __genSpanFunc __fastGenTexDecalFuncs[];
  626. extern __genSpanFunc __fastGenTexFuncs[];
  627. extern __genSpanFunc __fastGenWTexDecalFuncs[];
  628. extern __genSpanFunc __fastGenWTexFuncs[];
  629. extern __genSpanFunc __fastPerspTexReplaceFuncs[];
  630. extern __genSpanFunc __fastPerspTexPalReplaceFuncs[];
  631. extern __genSpanFunc __fastPerspTexFlatFuncs[];
  632. extern __genSpanFunc __fastPerspTexSmoothFuncs[];
  633. extern __GLspanFunc __fastDepthFuncs[];
  634. extern __GLspanFunc __fastDepth16Funcs[];
  635. extern void FASTCALL __fastGenDeltaSpan(__GLcontext *gc, SPANREC *spanDelta);
  636. extern void FASTCALL __fastGenFillTriangle(__GLcontext *gc, __GLvertex *a,
  637. __GLvertex *b, __GLvertex *c, GLboolean ccw);
  638. extern void FASTCALL __fastLineComputeOffsets(__GLGENcontext *gengc);
  639. extern void FASTCALL __fastGenRenderLineDIBRGB8(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  640. extern void FASTCALL __fastGenRenderLineDIBRGB16(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  641. extern void FASTCALL __fastGenRenderLineDIBRGB(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  642. extern void FASTCALL __fastGenRenderLineDIBBGR(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  643. extern void FASTCALL __fastGenRenderLineDIBRGB32(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  644. extern void FASTCALL __fastGenRenderLineDIBCI8(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  645. extern void FASTCALL __fastGenRenderLineDIBCI16(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  646. extern void FASTCALL __fastGenRenderLineDIBCIRGB(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  647. extern void FASTCALL __fastGenRenderLineDIBCIBGR(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  648. extern void FASTCALL __fastGenRenderLineDIBCI32(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  649. extern void FASTCALL __fastGenRenderLineWideDIBRGB8(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  650. extern void FASTCALL __fastGenRenderLineWideDIBRGB16(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  651. extern void FASTCALL __fastGenRenderLineWideDIBRGB(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  652. extern void FASTCALL __fastGenRenderLineWideDIBBGR(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  653. extern void FASTCALL __fastGenRenderLineWideDIBRGB32(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  654. extern void FASTCALL __fastGenRenderLineWideDIBCI8(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  655. extern void FASTCALL __fastGenRenderLineWideDIBCI16(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  656. extern void FASTCALL __fastGenRenderLineWideDIBCIRGB(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  657. extern void FASTCALL __fastGenRenderLineWideDIBCIBGR(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  658. extern void FASTCALL __fastGenRenderLineWideDIBCI32(__GLcontext *gc, __GLvertex *v0, __GLvertex *v1);
  659. extern void gdiCopyPixels(__GLGENcontext *, __GLcolorBuffer *, GLint, GLint,
  660. GLint, BOOL);
  661. extern void dibCopyPixels(__GLGENcontext *, __GLcolorBuffer *, GLint, GLint,
  662. GLint, BOOL);
  663. typedef void (FASTCALL *PFNZIPPYSUB)(__GLcontext *gc, GLint iyBottom, GLint iyTop);
  664. void FASTCALL __ZippyFSTRGBTex(__GLcontext *gc, GLint iyBottom, GLint iyTop);
  665. void FASTCALL __ZippyFSTTex(__GLcontext *gc, GLint iyBottom, GLint iyTop);
  666. void FASTCALL __ZippyFSTRGB(__GLcontext *gc, GLint iyBottom, GLint iyTop);
  667. void FASTCALL __ZippyFSTCI(__GLcontext *gc, GLint iyBottom, GLint iyTop);
  668. void FASTCALL __ZippyFSTZ(__GLcontext *gc, GLint iyBottom, GLint iyTop);
  669. void FASTCALL __ZippyFSTCI8Flat(__GLcontext *gc, GLint iyBottom, GLint iyTop);
  670. void FASTCALL __fastGenSpan(__GLGENcontext *gengc);
  671. GLboolean FASTCALL __fastGenStippleLt32Span(__GLcontext *gc);
  672. GLboolean FASTCALL __fastGenStippleLt16Span(__GLcontext *gc);
  673. GLboolean FASTCALL __fastGenStippleAnyDepthTestSpan(__GLcontext *gc);
  674. extern BYTE gbMulTable[];
  675. extern BYTE gbSatTable[];
  676. extern DWORD ditherShade[];
  677. extern DWORD ditherTexture[];
  678. extern __GLfloat invTable[];
  679. extern __GLfloat fDitherIncTable[]; // defined in genrgb.c
  680. void FASTCALL __glGenFreeBuffers( __GLGENbuffers *buffers );
  681. #endif /* __GLGENCONTXT_H__ */