Clone of mesa.
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.

swrast.h 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /* $Id: swrast.h,v 1.15 2002/01/21 18:12:34 brianp Exp $ */
  2. /*
  3. * Mesa 3-D graphics library
  4. * Version: 4.1
  5. *
  6. * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  22. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Authors:
  26. * Keith Whitwell <keithw@valinux.com>
  27. */
  28. #ifndef SWRAST_H
  29. #define SWRAST_H
  30. #include "mtypes.h"
  31. /* The software rasterizer now uses this format for vertices. Thus a
  32. * 'RasterSetup' stage or other translation is required between the
  33. * tnl module and the swrast rasterization functions. This serves to
  34. * isolate the swrast module from the internals of the tnl module, and
  35. * improve its usefulness as a fallback mechanism for hardware
  36. * drivers.
  37. *
  38. * Full software drivers:
  39. * - Register the rastersetup and triangle functions from
  40. * utils/software_helper.
  41. * - On statechange, update the rasterization pointers in that module.
  42. *
  43. * Rasterization hardware drivers:
  44. * - Keep native rastersetup.
  45. * - Implement native twoside,offset and unfilled triangle setup.
  46. * - Implement a translator from native vertices to swrast vertices.
  47. * - On partial fallback (mix of accelerated and unaccelerated
  48. * prims), call a pass-through function which translates native
  49. * vertices to SWvertices and calls the appropriate swrast function.
  50. * - On total fallback (vertex format insufficient for state or all
  51. * primitives unaccelerated), hook in swrast_setup instead.
  52. */
  53. typedef struct {
  54. GLfloat win[4];
  55. GLfloat texcoord[MAX_TEXTURE_UNITS][4];
  56. GLchan color[4];
  57. GLchan specular[4];
  58. GLfloat fog;
  59. GLuint index;
  60. GLfloat pointSize;
  61. } SWvertex;
  62. /*
  63. * The sw_span structure is used by the triangle template code in
  64. * s_tritemp.h. It describes how colors, Z, texcoords, etc are to be
  65. * interpolated across each scanline of triangle.
  66. * With this structure it's easy to hand-off span rasterization to a
  67. * subroutine instead of doing it all inline like we used to do.
  68. * It also cleans up the local variable namespace a great deal.
  69. *
  70. * It would be interesting to experiment with multiprocessor rasterization
  71. * with this structure. The triangle rasterizer could simply emit a
  72. * stream of these structures which would be consumed by one or more
  73. * span-processing threads which could run in parallel.
  74. */
  75. /* When the sw_span struct is initialized, these flags indicates
  76. * which values are needed for rendering the triangle.
  77. */
  78. #define SPAN_RGBA 0x001
  79. #define SPAN_SPEC 0x002
  80. #define SPAN_INDEX 0x004
  81. #define SPAN_Z 0x008
  82. #define SPAN_FOG 0x010
  83. #define SPAN_TEXTURE 0x020
  84. #define SPAN_INT_TEXTURE 0x040
  85. #define SPAN_LAMBDA 0x080
  86. #define SPAN_FLAT 0x100 /* flat shading? */
  87. struct sw_span {
  88. GLint x, y;
  89. /* only need to process pixels between start <= i < end */
  90. GLuint start, end;
  91. /* This flag indicates that only a part of the span is visible */
  92. GLboolean writeAll;
  93. GLuint activeMask; /* OR of the SPAN_* flags */
  94. #if CHAN_TYPE == GL_FLOAT
  95. GLfloat red, redStep;
  96. GLfloat green, greenStep;
  97. GLfloat blue, blueStep;
  98. GLfloat alpha, alphaStep;
  99. GLfloat specRed, specRedStep;
  100. GLfloat specGreen, specGreenStep;
  101. GLfloat specBlue, specBlueStep;
  102. #else /* CHAN_TYPE == */
  103. GLfixed red, redStep;
  104. GLfixed green, greenStep;
  105. GLfixed blue, blueStep;
  106. GLfixed alpha, alphaStep;
  107. GLfixed specRed, specRedStep;
  108. GLfixed specGreen, specGreenStep;
  109. GLfixed specBlue, specBlueStep;
  110. #endif
  111. GLfixed index, indexStep;
  112. GLfixed z, zStep;
  113. GLfloat fog, fogStep;
  114. GLfloat tex[MAX_TEXTURE_UNITS][4], texStep[MAX_TEXTURE_UNITS][4];
  115. GLfixed intTex[2], intTexStep[2];
  116. /* Needed for texture lambda (LOD) computation */
  117. GLfloat rho[MAX_TEXTURE_UNITS];
  118. GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS];
  119. /**
  120. * Arrays of fragment values. These will either be computed from the
  121. * x/xStep values above or loadd from glDrawPixels, etc.
  122. */
  123. GLdepth depth[MAX_WIDTH];
  124. union {
  125. GLchan rgb[MAX_WIDTH][3];
  126. GLchan rgba[MAX_WIDTH][4];
  127. GLuint index[MAX_WIDTH];
  128. } color;
  129. GLchan specular[MAX_WIDTH][4];
  130. GLint itexcoords[MAX_WIDTH][2]; /* Integer texture (s, t) */
  131. /* Texture (s,t,r). 4th component only used for pixel texture */
  132. GLfloat texcoords[MAX_TEXTURE_UNITS][MAX_WIDTH][4];
  133. GLfloat lambda[MAX_TEXTURE_UNITS][MAX_WIDTH];
  134. GLfloat coverage[MAX_WIDTH];
  135. GLubyte mask[MAX_WIDTH];
  136. #ifdef DEBUG
  137. GLboolean filledDepth, filledMask, filledAlpha;
  138. GLboolean filledColor, filledSpecular;
  139. GLboolean filledLambda[MAX_TEXTURE_UNITS], filledTex[MAX_TEXTURE_UNITS];
  140. GLboolean testedDepth, testedAlpha;
  141. #endif
  142. };
  143. #ifdef DEBUG
  144. #define SW_SPAN_SET_FLAG(flag) {ASSERT((flag) == GL_FALSE);(flag) = GL_TRUE;}
  145. #define SW_SPAN_RESET(span) { \
  146. (span).filledDepth = (span).filledMask = (span).filledAlpha \
  147. = (span).filledColor = (span).filledSpecular \
  148. = (span).testedDepth = (span).testedAlpha = GL_FALSE; \
  149. MEMSET((span).filledTex, GL_FALSE, \
  150. MAX_TEXTURE_UNITS*sizeof(GLboolean)); \
  151. MEMSET((span).filledLambda, GL_FALSE, \
  152. MAX_TEXTURE_UNITS*sizeof(GLboolean)); \
  153. (span).start = 0; (span).writeAll = GL_TRUE;}
  154. #else
  155. #define SW_SPAN_SET_FLAG(flag) ;
  156. #define SW_SPAN_RESET(span) {(span).start = 0;(span).writeAll = GL_TRUE;}
  157. #endif
  158. struct swrast_device_driver;
  159. /* These are the public-access functions exported from swrast.
  160. */
  161. extern void
  162. _swrast_alloc_buffers( GLcontext *ctx );
  163. extern GLboolean
  164. _swrast_CreateContext( GLcontext *ctx );
  165. extern void
  166. _swrast_DestroyContext( GLcontext *ctx );
  167. /* Get a (non-const) reference to the device driver struct for swrast.
  168. */
  169. extern struct swrast_device_driver *
  170. _swrast_GetDeviceDriverReference( GLcontext *ctx );
  171. extern void
  172. _swrast_Bitmap( GLcontext *ctx,
  173. GLint px, GLint py,
  174. GLsizei width, GLsizei height,
  175. const struct gl_pixelstore_attrib *unpack,
  176. const GLubyte *bitmap );
  177. extern void
  178. _swrast_CopyPixels( GLcontext *ctx,
  179. GLint srcx, GLint srcy,
  180. GLint destx, GLint desty,
  181. GLsizei width, GLsizei height,
  182. GLenum type );
  183. extern void
  184. _swrast_DrawPixels( GLcontext *ctx,
  185. GLint x, GLint y,
  186. GLsizei width, GLsizei height,
  187. GLenum format, GLenum type,
  188. const struct gl_pixelstore_attrib *unpack,
  189. const GLvoid *pixels );
  190. extern void
  191. _swrast_ReadPixels( GLcontext *ctx,
  192. GLint x, GLint y, GLsizei width, GLsizei height,
  193. GLenum format, GLenum type,
  194. const struct gl_pixelstore_attrib *unpack,
  195. GLvoid *pixels );
  196. extern void
  197. _swrast_Clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
  198. GLint x, GLint y, GLint width, GLint height );
  199. extern void
  200. _swrast_Accum( GLcontext *ctx, GLenum op,
  201. GLfloat value, GLint xpos, GLint ypos,
  202. GLint width, GLint height );
  203. /* Reset the stipple counter
  204. */
  205. extern void
  206. _swrast_ResetLineStipple( GLcontext *ctx );
  207. /* These will always render the correct point/line/triangle for the
  208. * current state.
  209. *
  210. * For flatshaded primitives, the provoking vertex is the final one.
  211. */
  212. extern void
  213. _swrast_Point( GLcontext *ctx, const SWvertex *v );
  214. extern void
  215. _swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 );
  216. extern void
  217. _swrast_Triangle( GLcontext *ctx, const SWvertex *v0,
  218. const SWvertex *v1, const SWvertex *v2 );
  219. extern void
  220. _swrast_Quad( GLcontext *ctx,
  221. const SWvertex *v0, const SWvertex *v1,
  222. const SWvertex *v2, const SWvertex *v3);
  223. extern void
  224. _swrast_flush( GLcontext *ctx );
  225. /* Tell the software rasterizer about core state changes.
  226. */
  227. extern void
  228. _swrast_InvalidateState( GLcontext *ctx, GLuint new_state );
  229. /* Configure software rasterizer to match hardware rasterizer characteristics:
  230. */
  231. extern void
  232. _swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value );
  233. extern void
  234. _swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value );
  235. /* Debug:
  236. */
  237. extern void
  238. _swrast_print_vertex( GLcontext *ctx, const SWvertex *v );
  239. /*
  240. * Imaging fallbacks (a better solution should be found, perhaps
  241. * moving all the imaging fallback code to a new module)
  242. */
  243. void
  244. _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
  245. GLenum internalFormat,
  246. GLint x, GLint y, GLsizei width,
  247. GLsizei height);
  248. void
  249. _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
  250. GLenum internalFormat,
  251. GLint x, GLint y, GLsizei width);
  252. void
  253. _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
  254. GLint x, GLint y, GLsizei width);
  255. void
  256. _swrast_CopyColorTable( GLcontext *ctx,
  257. GLenum target, GLenum internalformat,
  258. GLint x, GLint y, GLsizei width);
  259. /*
  260. * Texture fallbacks, Brian Paul. Could also live in a new module
  261. * with the rest of the texture store fallbacks?
  262. */
  263. extern void
  264. _swrast_copy_teximage1d(GLcontext *ctx, GLenum target, GLint level,
  265. GLenum internalFormat,
  266. GLint x, GLint y, GLsizei width, GLint border);
  267. extern void
  268. _swrast_copy_teximage2d(GLcontext *ctx, GLenum target, GLint level,
  269. GLenum internalFormat,
  270. GLint x, GLint y, GLsizei width, GLsizei height,
  271. GLint border);
  272. extern void
  273. _swrast_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
  274. GLint xoffset, GLint x, GLint y, GLsizei width);
  275. extern void
  276. _swrast_copy_texsubimage2d(GLcontext *ctx,
  277. GLenum target, GLint level,
  278. GLint xoffset, GLint yoffset,
  279. GLint x, GLint y, GLsizei width, GLsizei height);
  280. extern void
  281. _swrast_copy_texsubimage3d(GLcontext *ctx,
  282. GLenum target, GLint level,
  283. GLint xoffset, GLint yoffset, GLint zoffset,
  284. GLint x, GLint y, GLsizei width, GLsizei height);
  285. /* The driver interface for the software rasterizer. Unless otherwise
  286. * noted, all functions are mandatory.
  287. */
  288. struct swrast_device_driver {
  289. void (*SetReadBuffer)( GLcontext *ctx, GLframebuffer *colorBuffer,
  290. GLenum buffer );
  291. /*
  292. * Specifies the current buffer for span/pixel reading.
  293. * colorBuffer will be one of:
  294. * GL_FRONT_LEFT - this buffer always exists
  295. * GL_BACK_LEFT - when double buffering
  296. * GL_FRONT_RIGHT - when using stereo
  297. * GL_BACK_RIGHT - when using stereo and double buffering
  298. */
  299. /***
  300. *** Functions for synchronizing access to the framebuffer:
  301. ***/
  302. void (*SpanRenderStart)(GLcontext *ctx);
  303. void (*SpanRenderFinish)(GLcontext *ctx);
  304. /* OPTIONAL.
  305. *
  306. * Called before and after all rendering operations, including DrawPixels,
  307. * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands.
  308. * These are a suitable place for grabbing/releasing hardware locks.
  309. *
  310. * NOTE: The swrast triangle/line/point routines *DO NOT* call
  311. * these functions. Locking in that case must be organized by the
  312. * driver by other mechanisms.
  313. */
  314. /***
  315. *** Functions for writing pixels to the frame buffer:
  316. ***/
  317. void (*WriteRGBASpan)( const GLcontext *ctx,
  318. GLuint n, GLint x, GLint y,
  319. CONST GLchan rgba[][4], const GLubyte mask[] );
  320. void (*WriteRGBSpan)( const GLcontext *ctx,
  321. GLuint n, GLint x, GLint y,
  322. CONST GLchan rgb[][3], const GLubyte mask[] );
  323. /* Write a horizontal run of RGBA or RGB pixels.
  324. * If mask is NULL, draw all pixels.
  325. * If mask is not null, only draw pixel [i] when mask [i] is true.
  326. */
  327. void (*WriteMonoRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  328. const GLchan color[4], const GLubyte mask[] );
  329. /* Write a horizontal run of RGBA pixels all with the same color.
  330. */
  331. void (*WriteRGBAPixels)( const GLcontext *ctx,
  332. GLuint n, const GLint x[], const GLint y[],
  333. CONST GLchan rgba[][4], const GLubyte mask[] );
  334. /* Write array of RGBA pixels at random locations.
  335. */
  336. void (*WriteMonoRGBAPixels)( const GLcontext *ctx,
  337. GLuint n, const GLint x[], const GLint y[],
  338. const GLchan color[4], const GLubyte mask[] );
  339. /* Write an array of mono-RGBA pixels at random locations.
  340. */
  341. void (*WriteCI32Span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  342. const GLuint index[], const GLubyte mask[] );
  343. void (*WriteCI8Span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  344. const GLubyte index[], const GLubyte mask[] );
  345. /* Write a horizontal run of CI pixels. One function is for 32bpp
  346. * indexes and the other for 8bpp pixels (the common case). You mus
  347. * implement both for color index mode.
  348. */
  349. void (*WriteMonoCISpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  350. GLuint colorIndex, const GLubyte mask[] );
  351. /* Write a horizontal run of color index pixels using the color index
  352. * last specified by the Index() function.
  353. */
  354. void (*WriteCI32Pixels)( const GLcontext *ctx,
  355. GLuint n, const GLint x[], const GLint y[],
  356. const GLuint index[], const GLubyte mask[] );
  357. /*
  358. * Write a random array of CI pixels.
  359. */
  360. void (*WriteMonoCIPixels)( const GLcontext *ctx,
  361. GLuint n, const GLint x[], const GLint y[],
  362. GLuint colorIndex, const GLubyte mask[] );
  363. /* Write a random array of color index pixels using the color index
  364. * last specified by the Index() function.
  365. */
  366. /***
  367. *** Functions to read pixels from frame buffer:
  368. ***/
  369. void (*ReadCI32Span)( const GLcontext *ctx,
  370. GLuint n, GLint x, GLint y, GLuint index[] );
  371. /* Read a horizontal run of color index pixels.
  372. */
  373. void (*ReadRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  374. GLchan rgba[][4] );
  375. /* Read a horizontal run of RGBA pixels.
  376. */
  377. void (*ReadCI32Pixels)( const GLcontext *ctx,
  378. GLuint n, const GLint x[], const GLint y[],
  379. GLuint indx[], const GLubyte mask[] );
  380. /* Read a random array of CI pixels.
  381. */
  382. void (*ReadRGBAPixels)( const GLcontext *ctx,
  383. GLuint n, const GLint x[], const GLint y[],
  384. GLchan rgba[][4], const GLubyte mask[] );
  385. /* Read a random array of RGBA pixels.
  386. */
  387. /***
  388. *** For supporting hardware Z buffers:
  389. *** Either ALL or NONE of these functions must be implemented!
  390. *** NOTE that Each depth value is a 32-bit GLuint. If the depth
  391. *** buffer is less than 32 bits deep then the extra upperbits are zero.
  392. ***/
  393. void (*WriteDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y,
  394. const GLdepth depth[], const GLubyte mask[] );
  395. /* Write a horizontal span of values into the depth buffer. Only write
  396. * depth[i] value if mask[i] is nonzero.
  397. */
  398. void (*ReadDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y,
  399. GLdepth depth[] );
  400. /* Read a horizontal span of values from the depth buffer.
  401. */
  402. void (*WriteDepthPixels)( GLcontext *ctx, GLuint n,
  403. const GLint x[], const GLint y[],
  404. const GLdepth depth[], const GLubyte mask[] );
  405. /* Write an array of randomly positioned depth values into the
  406. * depth buffer. Only write depth[i] value if mask[i] is nonzero.
  407. */
  408. void (*ReadDepthPixels)( GLcontext *ctx, GLuint n,
  409. const GLint x[], const GLint y[],
  410. GLdepth depth[] );
  411. /* Read an array of randomly positioned depth values from the depth buffer.
  412. */
  413. /***
  414. *** For supporting hardware stencil buffers:
  415. *** Either ALL or NONE of these functions must be implemented!
  416. ***/
  417. void (*WriteStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y,
  418. const GLstencil stencil[], const GLubyte mask[] );
  419. /* Write a horizontal span of stencil values into the stencil buffer.
  420. * If mask is NULL, write all stencil values.
  421. * Else, only write stencil[i] if mask[i] is non-zero.
  422. */
  423. void (*ReadStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y,
  424. GLstencil stencil[] );
  425. /* Read a horizontal span of stencil values from the stencil buffer.
  426. */
  427. void (*WriteStencilPixels)( GLcontext *ctx, GLuint n,
  428. const GLint x[], const GLint y[],
  429. const GLstencil stencil[],
  430. const GLubyte mask[] );
  431. /* Write an array of stencil values into the stencil buffer.
  432. * If mask is NULL, write all stencil values.
  433. * Else, only write stencil[i] if mask[i] is non-zero.
  434. */
  435. void (*ReadStencilPixels)( GLcontext *ctx, GLuint n,
  436. const GLint x[], const GLint y[],
  437. GLstencil stencil[] );
  438. /* Read an array of stencil values from the stencil buffer.
  439. */
  440. };
  441. #endif