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