home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / swrast_setup / old / ss_vbtmp.h < prev   
Encoding:
C/C++ Source or Header  |  2002-12-01  |  8.2 KB  |  307 lines

  1. /* $Id: ss_vbtmp.h,v 1.22 2002/10/29 20:29:01 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  4.1
  6.  *
  7.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  8.  *
  9.  * Permission is hereby granted, free of charge, to any person obtaining a
  10.  * copy of this software and associated documentation files (the "Software"),
  11.  * to deal in the Software without restriction, including without limitation
  12.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13.  * and/or sell copies of the Software, and to permit persons to whom the
  14.  * Software is furnished to do so, subject to the following conditions:
  15.  *
  16.  * The above copyright notice and this permission notice shall be included
  17.  * in all copies or substantial portions of the Software.
  18.  *
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  23.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  * Authors:
  27.  *    Keith Whitwell <keith@tungstengraphics.com>
  28.  */
  29.  
  30.  
  31. static void TAG(emit)(GLcontext *ctx, GLuint start, GLuint end,
  32.                      GLuint newinputs )
  33. {
  34.    TNLcontext *tnl = TNL_CONTEXT(ctx);
  35.    struct vertex_buffer *VB = &tnl->vb;
  36.    SWvertex *v;
  37.    GLfloat *proj;              /* projected clip coordinates */
  38.    GLfloat *tc[MAX_TEXTURE_UNITS];
  39.    GLchan *color;
  40.    GLchan *spec;
  41.    GLuint *index;
  42.    GLfloat *fog;
  43.    GLfloat *pointSize;
  44.    GLuint tsz[MAX_TEXTURE_UNITS];
  45.    GLuint tstride[MAX_TEXTURE_UNITS];
  46.    GLuint proj_stride, color_stride, spec_stride, index_stride;
  47.    GLuint fog_stride, pointSize_stride;
  48.    GLuint i;
  49.    GLfloat *m = ctx->Viewport._WindowMap.m;
  50.    const GLfloat sx = m[0];
  51.    const GLfloat sy = m[5];
  52.    const GLfloat sz = m[10];
  53.    const GLfloat tx = m[12];
  54.    const GLfloat ty = m[13];
  55.    const GLfloat tz = m[14];
  56.    GLuint maxtex = 0;
  57.  
  58. // if (IND & TEX0) {
  59. #  if (IND & TEX0)
  60.       tc[0] = (GLfloat *)VB->TexCoordPtr[0]->data;
  61.       tsz[0] = VB->TexCoordPtr[0]->size;
  62.       tstride[0] = VB->TexCoordPtr[0]->stride;
  63. #endif
  64. // }
  65.  
  66. // if (IND & MULTITEX) {
  67. #  if (IND & MULTITEX)
  68.       for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
  69.         if (VB->TexCoordPtr[i]) {
  70.            maxtex = i+1;
  71.            tc[i] = (GLfloat *)VB->TexCoordPtr[i]->data;
  72.            tsz[i] = VB->TexCoordPtr[i]->size;
  73.            tstride[i] = VB->TexCoordPtr[i]->stride;
  74.         }
  75.         else tc[i] = 0;
  76.       }
  77. #endif
  78. // }
  79.  
  80.    proj = VB->NdcPtr->data[0];
  81.    proj_stride = VB->NdcPtr->stride;
  82.  
  83. // if (IND & FOG) {
  84. #  if (IND & FOG)
  85.       fog = (GLfloat *) VB->FogCoordPtr->data;
  86.       fog_stride = VB->FogCoordPtr->stride;
  87. #endif
  88. // }
  89. // if (IND & COLOR) {
  90. #  if (IND & COLOR)
  91.       if (VB->ColorPtr[0]->Type != CHAN_TYPE)
  92.         import_float_colors( ctx );
  93.  
  94.       color = (GLchan *) VB->ColorPtr[0]->Ptr;
  95.       color_stride = VB->ColorPtr[0]->StrideB;
  96. #endif
  97. // }
  98. // if (IND & SPEC) {
  99. #  if (IND & SPEC)
  100.       if (VB->SecondaryColorPtr[0]->Type != CHAN_TYPE)
  101.         import_float_spec_colors( ctx );
  102.  
  103.       spec = (GLchan *) VB->SecondaryColorPtr[0]->Ptr;
  104.       spec_stride = VB->SecondaryColorPtr[0]->StrideB;
  105. #endif
  106. // }
  107.  
  108. // if (IND & INDEX) {
  109. #  if (IND & INDEX)
  110.       index = VB->IndexPtr[0]->data;
  111.       index_stride = VB->IndexPtr[0]->stride;
  112. #endif
  113. //   }
  114.  
  115. //   if (IND & POINT) {
  116. #  if (IND & POINT)
  117.       pointSize = (GLfloat *) VB->PointSizePtr->data;
  118.       pointSize_stride = VB->PointSizePtr->stride;
  119. #endif
  120. //   }
  121.  
  122.    v = &(SWSETUP_CONTEXT(ctx)->verts[start]);
  123.  
  124.    for (i=start; i < end; i++, v++) {
  125.       if (VB->ClipMask[i] == 0) {
  126.         v->win[0] = sx * proj[0] + tx;
  127.         v->win[1] = sy * proj[1] + ty;
  128.         v->win[2] = sz * proj[2] + tz;
  129.         v->win[3] =      proj[3];
  130.       }
  131.       STRIDE_F(proj, proj_stride);
  132.  
  133. //    if (IND & TEX0) {
  134. #     if (IND & TEX0)
  135.         COPY_CLEAN_4V( v->texcoord[0], tsz[0], tc[0] );
  136.         STRIDE_F(tc[0], tstride[0]);
  137. //    }
  138. #endif
  139.  
  140. //    if (IND & MULTITEX) {
  141. #     if (IND & MULTITEX)
  142.       {
  143.         GLuint u;
  144.         for (u = 0 ; u < maxtex ; u++)
  145.            if (tc[u]) {
  146.               COPY_CLEAN_4V( v->texcoord[u], tsz[u], tc[u] );
  147.               STRIDE_F(tc[u], tstride[u]);
  148.            }
  149.     }
  150. #endif
  151.  
  152. //    if (IND & COLOR) {
  153. #     if (IND & COLOR)
  154.         COPY_CHAN4(v->color, color);
  155.         STRIDE_CHAN(color, color_stride);
  156. #endif
  157. //    }
  158.  
  159. //    if (IND & SPEC) {
  160. #     if (IND & SPEC)
  161.         COPY_CHAN4(v->specular, spec);
  162.         STRIDE_CHAN(spec, spec_stride);
  163. #endif
  164. //      }
  165.  
  166. //    if (IND & FOG) {
  167. #     if (IND & FOG)
  168.         v->fog = fog[0];
  169.         STRIDE_F(fog, fog_stride);
  170. #endif
  171. //    }
  172.  
  173. //    if (IND & INDEX) {
  174. #     if (IND & INDEX)
  175.         v->index = index[0];
  176.         STRIDE_UI(index, index_stride);
  177. #endif
  178. //    }
  179.  
  180. //    if (IND & POINT) {
  181. #     if (IND & POINT)
  182.         v->pointSize = pointSize[0];
  183.         STRIDE_F(pointSize, pointSize_stride);
  184. #endif
  185. //    }
  186.    }
  187. }
  188.  
  189.  
  190.  
  191. static void TAG(interp)( GLcontext *ctx,
  192.                         GLfloat t,
  193.                         GLuint edst, GLuint eout, GLuint ein,
  194.                         GLboolean force_boundary )
  195. {
  196.    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
  197.    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
  198.    GLfloat *m = ctx->Viewport._WindowMap.m;
  199.    GLfloat *clip = VB->ClipPtr->data[edst];
  200.  
  201.    SWvertex *dst = &swsetup->verts[edst];
  202.    SWvertex *in  = &swsetup->verts[ein];
  203.    SWvertex *out = &swsetup->verts[eout];
  204.  
  205.    /* Avoid division by zero by rearranging order of clip planes?
  206.     */
  207.    if (clip[3] != 0.0) {
  208.       GLfloat oow = 1.0F / clip[3];
  209.       dst->win[0] = m[0]  * clip[0] * oow + m[12];
  210.       dst->win[1] = m[5]  * clip[1] * oow + m[13];
  211.       dst->win[2] = m[10] * clip[2] * oow + m[14];
  212.       dst->win[3] =                   oow;
  213.    }
  214.  
  215. //  if (IND & TEX0) {
  216. #   if (IND & TEX0)
  217.       INTERP_4F( t, dst->texcoord[0], out->texcoord[0], in->texcoord[0] );
  218. #endif
  219. // }
  220.  
  221. // if (IND & MULTITEX) {
  222. #  if (IND & MULTITEX)
  223.    {
  224.       GLuint u;
  225.       GLuint maxtex = ctx->Const.MaxTextureUnits;
  226.       for (u = 0 ; u < maxtex ; u++)
  227.         if (VB->TexCoordPtr[u]) {
  228.            INTERP_4F( t, dst->texcoord[u], out->texcoord[u], in->texcoord[u] );
  229.         }
  230.    }
  231. #endif
  232.  
  233. // if (IND & COLOR) {
  234. #  if (IND & COLOR)
  235.       INTERP_CHAN( t, dst->color[0], out->color[0], in->color[0] );
  236.       INTERP_CHAN( t, dst->color[1], out->color[1], in->color[1] );
  237.       INTERP_CHAN( t, dst->color[2], out->color[2], in->color[2] );
  238.       INTERP_CHAN( t, dst->color[3], out->color[3], in->color[3] );
  239. #endif
  240. // }
  241.  
  242. // if (IND & SPEC) {
  243. #  if (IND & SPEC)
  244.       INTERP_CHAN( t, dst->specular[0], out->specular[0], in->specular[0] );
  245.       INTERP_CHAN( t, dst->specular[1], out->specular[1], in->specular[1] );
  246.       INTERP_CHAN( t, dst->specular[2], out->specular[2], in->specular[2] );
  247. #endif
  248. // }
  249.  
  250. // if (IND & FOG) {
  251. #  if (IND & FOG)
  252.       INTERP_F( t, dst->fog, out->fog, in->fog );
  253. #endif
  254. // }
  255.  
  256. // if (IND & INDEX) {
  257. #  if (IND & INDEX)
  258.       INTERP_UI( t, dst->index, out->index, in->index );
  259. #endif
  260. // }
  261.  
  262.    /* XXX Point size interpolation??? */
  263. // if (IND & POINT) {
  264. #  if (IND & POINT)
  265.       INTERP_F( t, dst->pointSize, out->pointSize, in->pointSize );
  266. #endif
  267. // }
  268. }
  269.  
  270.  
  271. static void TAG(copy_pv)( GLcontext *ctx, GLuint edst, GLuint esrc )
  272. {
  273.    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
  274.    SWvertex *dst = &swsetup->verts[edst];
  275.    SWvertex *src = &swsetup->verts[esrc];
  276.  
  277. // if (IND & COLOR) {
  278. #  if (IND & COLOR)
  279.       COPY_CHAN4( dst->color, src->color );
  280. #endif
  281. // }
  282.  
  283. // if (IND & SPEC) {
  284. #  if (IND & SPEC)
  285.       COPY_3V( dst->specular, src->specular );
  286. #endif
  287. // }
  288.  
  289. // if (IND & INDEX) {
  290. #  if (IND & INDEX)
  291.       dst->index = src->index;
  292. #endif
  293. // }
  294. }
  295.  
  296.  
  297. static void TAG(init)( void )
  298. {
  299.    setup_tab[IND] = TAG(emit);
  300.    interp_tab[IND] = TAG(interp);
  301.    copy_pv_tab[IND] = TAG(copy_pv);
  302. }
  303.  
  304. #undef TAG
  305. #undef IND
  306. #undef SETUP_FLAGS
  307.