s_feedback.c revision 7c4268176eaaeb45003db4d5042a518b84c9f6dc
1/* $Id: s_feedback.c,v 1.9 2001/09/19 20:30:44 kschultz Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version:  3.5
6 *
7 * Copyright (C) 1999-2001  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
27#include "glheader.h"
28#include "colormac.h"
29#include "context.h"
30#include "enums.h"
31#include "feedback.h"
32#include "macros.h"
33#include "mmath.h"
34
35#include "s_context.h"
36#include "s_feedback.h"
37#include "s_triangle.h"
38
39
40#define FB_3D		0x01
41#define FB_4D		0x02
42#define FB_INDEX	0x04
43#define FB_COLOR	0x08
44#define FB_TEXTURE	0X10
45
46
47
48
49static void feedback_vertex( GLcontext *ctx,
50                             const SWvertex *v, const SWvertex *pv )
51{
52   const GLuint texUnit = 0;  /* See section 5.3 of 1.2.1 spec */
53   GLfloat win[4];
54   GLfloat color[4];
55   GLfloat tc[4];
56   GLuint index;
57
58   win[0] = v->win[0];
59   win[1] = v->win[1];
60   win[2] = v->win[2] / ctx->DepthMaxF;
61   win[3] = 1.0F / v->win[3];
62
63   color[0] = CHAN_TO_FLOAT(pv->color[0]);
64   color[1] = CHAN_TO_FLOAT(pv->color[1]);
65   color[2] = CHAN_TO_FLOAT(pv->color[2]);
66   color[3] = CHAN_TO_FLOAT(pv->color[3]);
67
68   if (v->texcoord[texUnit][3] != 1.0 &&
69       v->texcoord[texUnit][3] != 0.0) {
70      GLfloat invq = 1.0F / v->texcoord[texUnit][3];
71      tc[0] = v->texcoord[texUnit][0] * invq;
72      tc[1] = v->texcoord[texUnit][1] * invq;
73      tc[2] = v->texcoord[texUnit][2] * invq;
74      tc[3] = v->texcoord[texUnit][3];
75   }
76   else {
77      COPY_4V(tc, v->texcoord[texUnit]);
78   }
79
80   index = v->index;
81
82   _mesa_feedback_vertex( ctx, win, color, index, tc );
83}
84
85
86/*
87 * Put triangle in feedback buffer.
88 */
89void _mesa_feedback_triangle( GLcontext *ctx,
90                           const SWvertex *v0,
91                           const SWvertex *v1,
92			   const SWvertex *v2)
93{
94   if (_mesa_cull_triangle( ctx, v0, v1, v2 )) {
95      FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POLYGON_TOKEN );
96      FEEDBACK_TOKEN( ctx, (GLfloat) 3 );        /* three vertices */
97
98      if (ctx->Light.ShadeModel == GL_SMOOTH) {
99	 feedback_vertex( ctx, v0, v0 );
100	 feedback_vertex( ctx, v1, v1 );
101	 feedback_vertex( ctx, v2, v2 );
102      } else {
103	 feedback_vertex( ctx, v0, v2 );
104	 feedback_vertex( ctx, v1, v2 );
105	 feedback_vertex( ctx, v2, v2 );
106      }
107   }
108}
109
110
111void _mesa_feedback_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
112{
113   GLenum token = GL_LINE_TOKEN;
114   SWcontext *swrast = SWRAST_CONTEXT(ctx);
115
116   if (swrast->StippleCounter==0)
117      token = GL_LINE_RESET_TOKEN;
118
119   FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) token );
120
121   if (ctx->Light.ShadeModel == GL_SMOOTH) {
122      feedback_vertex( ctx, v0, v0 );
123      feedback_vertex( ctx, v1, v1 );
124   } else {
125      feedback_vertex( ctx, v0, v1 );
126      feedback_vertex( ctx, v1, v1 );
127   }
128
129   swrast->StippleCounter++;
130}
131
132
133void _mesa_feedback_point( GLcontext *ctx, const SWvertex *v )
134{
135   FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POINT_TOKEN );
136   feedback_vertex( ctx, v, v );
137}
138
139
140void _mesa_select_triangle( GLcontext *ctx,
141                         const SWvertex *v0,
142                         const SWvertex *v1,
143			 const SWvertex *v2)
144{
145   if (_mesa_cull_triangle( ctx, v0, v1, v2 )) {
146      const GLfloat zs = 1.0F / ctx->DepthMaxF;
147
148      _mesa_update_hitflag( ctx, v0->win[2] * zs );
149      _mesa_update_hitflag( ctx, v1->win[2] * zs );
150      _mesa_update_hitflag( ctx, v2->win[2] * zs );
151   }
152}
153
154
155void _mesa_select_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
156{
157   const GLfloat zs = 1.0F / ctx->DepthMaxF;
158   _mesa_update_hitflag( ctx, v0->win[2] * zs );
159   _mesa_update_hitflag( ctx, v1->win[2] * zs );
160}
161
162
163void _mesa_select_point( GLcontext *ctx, const SWvertex *v )
164{
165   const GLfloat zs = 1.0F / ctx->DepthMaxF;
166   _mesa_update_hitflag( ctx, v->win[2] * zs );
167}
168