Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /*
  3.  * Mesa 3-D graphics library
  4.  * Version:  3.5
  5.  *
  6.  * Copyright (C) 1999-2001  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 <keith_whitwell@yahoo.com>
  27.  */
  28.  
  29. /* Template to build support for t_dd_imm_* tnl module using vertices
  30.  * as defined in t_dd_vertex.h.
  31.  *
  32.  * See t_dd_vbtmp.h for definitions of arguments to this file.
  33.  * Unfortunately it seems necessary to duplicate a lot of that code.
  34.  */
  35.  
  36. #ifndef LOCALVARS
  37. #define LOCALVARS
  38. #endif
  39.  
  40.  
  41.  
  42. /* COPY_VERTEX_FROM_CURRENT in t_dd_imm_vapi.c
  43.  */
  44. static void TAG(emit_vfmt)( struct gl_context *ctx, VERTEX *v )
  45. {
  46.    LOCALVARS
  47.       ;
  48.  
  49.    /* This template assumes (like t_dd_vbtmp.h) that color is ubyte.
  50.     */
  51.    if (DO_TEX0 || DO_TEX1 || !HAVE_TINY_VERTICES)
  52.    {
  53.       const GLubyte *col = GET_HARDWARE_COLOR();
  54.       if (HAVE_RGBA_COLOR) {
  55.          v->v.ui[4] = *(GLuint *)&col;
  56.       } else {
  57.          v->v.color.blue  = col[2];
  58.          v->v.color.green = col[1];
  59.          v->v.color.red   = col[0];
  60.          v->v.color.alpha = col[3];
  61.       }
  62.    }
  63.    else {
  64.       if (HAVE_RGBA_COLOR) {
  65.          v->v.ui[3] = *(GLuint *)col;
  66.       }
  67.       else {
  68.          v->tv.color.blue  = col[2];
  69.          v->tv.color.green = col[1];
  70.          v->tv.color.red   = col[0];
  71.          v->tv.color.alpha = col[3];
  72.       }
  73.    }
  74.  
  75.    if (DO_TEX0) {
  76.       GLfloat *tc = ctx->Current.Texture[0];
  77.       v->v.u0 = tc[0];
  78.       v->v.v0 = tc[1];
  79.       if (DO_PTEX) {
  80.          if (HAVE_PTEX_VERTICES) {
  81.             v->pv.q0 = tc[3];
  82.          }
  83.          else {
  84.             float rhw = 1.0 / tc[3];
  85.             v->v.w *= tc[3];
  86.             v->v.u0 *= rhw;
  87.             v->v.v0 *= rhw;
  88.          }
  89.       }
  90.    }
  91.    if (DO_TEX1) {
  92.       GLfloat *tc = ctx->Current.Texture[1];
  93.       if (DO_PTEX) {
  94.          v->pv.u1 = tc[0];
  95.          v->pv.v1 = tc[1];
  96.          v->pv.q1 = tc[3];
  97.       }
  98.       else {
  99.          v->v.u1 = tc[0];
  100.          v->v.v1 = tc[1];
  101.       }
  102.    }
  103.    else if (DO_PTEX) {
  104.       *(GLuint *)&v->pv.q1 = 0; /* avoid culling on radeon */
  105.    }
  106.    if (DO_TEX2) {
  107.       GLfloat *tc = ctx->Current.Texture[2];
  108.       if (DO_PTEX) {
  109.          v->pv.u2 = tc[0];
  110.          v->pv.v2 = tc[1];
  111.          v->pv.q2 = tc[3];
  112.       }
  113.       else {
  114.          v->v.u2 = tc[0];
  115.          v->v.v2 = tc[1];
  116.       }
  117.    }
  118.    if (DO_TEX3) {
  119.       GLfloat *tc = ctx->Current.Texture[3];
  120.       if (DO_PTEX) {
  121.          v->pv.u3 = tc[0];
  122.          v->pv.v3 = tc[1];
  123.          v->pv.q3 = tc[3];
  124.       }
  125.       else {
  126.          v->v.u3 = tc[0];
  127.          v->v.v3 = tc[1];
  128.       }
  129.    }
  130. }
  131.  
  132.  
  133.  
  134.  
  135. static void TAG(interp)( struct gl_context *ctx,
  136.                          GLfloat t,
  137.                          TNL_VERTEX *dst,
  138.                          TNL_VERTEX *in,
  139.                          TNL_VERTEX *out )
  140. {
  141.    LOCALVARS
  142.    const GLfloat *s = GET_VIEWPORT_MAT();
  143.    GLfloat w;
  144.  
  145.    (void)s;
  146.  
  147.    if (HAVE_HW_DIVIDE) {
  148.       VIEWPORT_X( dst->v.v.x, dst->clip[0] );
  149.       VIEWPORT_Y( dst->v.v.y, dst->clip[1] );
  150.       VIEWPORT_Z( dst->v.v.z, dst->clip[2] );
  151.       w = dstclip[3];
  152.    }
  153.    else {
  154.       w = 1.0 / dst->clip[3];
  155.       VIEWPORT_X( dst->v.v.x, dst->clip[0] * w );
  156.       VIEWPORT_Y( dst->v.v.y, dst->clip[1] * w );
  157.       VIEWPORT_Z( dst->v.v.z, dst->clip[2] * w );
  158.    }
  159.  
  160.    if (HAVE_HW_DIVIDE || DO_TEX0) {
  161.  
  162.       dst->v.v.w = w;
  163.  
  164.       INTERP_UB( t, dst->v.ub4[4][0], out->v.ub4[4][0], in->v.ub4[4][0] );
  165.       INTERP_UB( t, dst->v.ub4[4][1], out->v.ub4[4][1], in->v.ub4[4][1] );
  166.       INTERP_UB( t, dst->v.ub4[4][2], out->v.ub4[4][2], in->v.ub4[4][2] );
  167.       INTERP_UB( t, dst->v.ub4[4][3], out->v.ub4[4][3], in->v.ub4[4][3] );
  168.  
  169.       if (DO_TEX0) {
  170.          if (DO_PTEX) {
  171.             if (HAVE_PTEX_VERTICES) {
  172.                INTERP_F( t, dst->v.pv.u0, out->v.pv.u0, in->v.pv.u0 );
  173.                INTERP_F( t, dst->v.pv.v0, out->v.pv.v0, in->v.pv.v0 );
  174.                INTERP_F( t, dst->v.pv.q0, out->v.pv.q0, in->v.pv.q0 );
  175.             } else {
  176.                GLfloat wout = out->clip[3]; /* projected clip */
  177.                GLfloat win = in->clip[3]; /* projected clip */
  178.                GLfloat qout = out->v.pv.w / wout;
  179.                GLfloat qin = in->v.pv.w / win;
  180.                GLfloat qdst, rqdst;
  181.  
  182.                ASSERT( !HAVE_HW_DIVIDE ); /* assert win, wout projected clip */
  183.  
  184.                INTERP_F( t, dst->v.v.u0, out->v.v.u0 * qout, in->v.v.u0 * qin );
  185.                INTERP_F( t, dst->v.v.v0, out->v.v.v0 * qout, in->v.v.v0 * qin );
  186.                INTERP_F( t, qdst, qout, qin );
  187.  
  188.                rqdst = 1.0 / qdst;
  189.                dst->v.v.u0 *= rqdst;
  190.                dst->v.v.v0 *= rqdst;
  191.                dst->v.v.w *= rqdst;
  192.             }
  193.          }
  194.          else {
  195.             INTERP_F( t, dst->v.v.u0, out->v.v.u0, in->v.v.u0 );
  196.             INTERP_F( t, dst->v.v.v0, out->v.v.v0, in->v.v.v0 );
  197.          }
  198.       }
  199.       if (DO_TEX1) {
  200.          if (DO_PTEX) {
  201.             INTERP_F( t, dst->v.pv.u1, out->v.pv.u1, in->v.pv.u1 );
  202.             INTERP_F( t, dst->v.pv.v1, out->v.pv.v1, in->v.pv.v1 );
  203.             INTERP_F( t, dst->v.pv.q1, out->v.pv.q1, in->v.pv.q1 );
  204.          } else {
  205.             INTERP_F( t, dst->v.v.u1, out->v.v.u1, in->v.v.u1 );
  206.             INTERP_F( t, dst->v.v.v1, out->v.v.v1, in->v.v.v1 );
  207.          }
  208.       }
  209.       else if (DO_PTEX) {
  210.          dst->v.pv.q0 = 0.0;    /* must be a valid float on radeon */
  211.       }
  212.       if (DO_TEX2) {
  213.          if (DO_PTEX) {
  214.             INTERP_F( t, dst->v.pv.u2, out->v.pv.u2, in->v.pv.u2 );
  215.             INTERP_F( t, dst->v.pv.v2, out->v.pv.v2, in->v.pv.v2 );
  216.             INTERP_F( t, dst->v.pv.q2, out->v.pv.q2, in->v.pv.q2 );
  217.          } else {
  218.             INTERP_F( t, dst->v.v.u2, out->v.v.u2, in->v.v.u2 );
  219.             INTERP_F( t, dst->v.v.v2, out->v.v.v2, in->v.v.v2 );
  220.          }
  221.       }
  222.       if (DO_TEX3) {
  223.          if (DO_PTEX) {
  224.             INTERP_F( t, dst->v.pv.u3, out->v.pv.u3, in->v.pv.u3 );
  225.             INTERP_F( t, dst->v.pv.v3, out->v.pv.v3, in->v.pv.v3 );
  226.             INTERP_F( t, dst->v.pv.q3, out->v.pv.q3, in->v.pv.q3 );
  227.          } else {
  228.             INTERP_F( t, dst->v.v.u3, out->v.v.u3, in->v.v.u3 );
  229.             INTERP_F( t, dst->v.v.v3, out->v.v.v3, in->v.v.v3 );
  230.          }
  231.       }
  232.    } else {
  233.       /* 4-dword vertex.  Color is in v[3] and there is no oow coordinate.
  234.        */
  235.       INTERP_UB( t, dst->v.ub4[3][0], out->v.ub4[3][0], in->v.ub4[3][0] );
  236.       INTERP_UB( t, dst->v.ub4[3][1], out->v.ub4[3][1], in->v.ub4[3][1] );
  237.       INTERP_UB( t, dst->v.ub4[3][2], out->v.ub4[3][2], in->v.ub4[3][2] );
  238.       INTERP_UB( t, dst->v.ub4[3][3], out->v.ub4[3][3], in->v.ub4[3][3] );
  239.    }
  240. }
  241.  
  242.  
  243. static __inline void TAG(copy_pv)( struct gl_context *ctx,
  244.                                    TNL_VERTEX *dst,
  245.                                    TNL_VERTEX *src )
  246. {
  247.    if (DO_TEX0 || DO_TEX1 || !HAVE_TINY_VERTICES) {
  248.       dst->v.v.ui[4] = src->v.v.ui[4];
  249.    }
  250.    else {
  251.       dst->v.v.ui[3] = src->v.v.ui[3];
  252.    }
  253. }
  254.  
  255.  
  256.  
  257. static void TAG(init)( void )
  258. {
  259.    setup_tab[IND].emit = TAG(emit_vfmt);
  260.    setup_tab[IND].interp = TAG(interp_vfmt);
  261. }
  262.  
  263.  
  264. #undef IND
  265. #undef TAG
  266.  
  267.  
  268.  
  269.