501f3721c60f0eaade60d285d6859aca99ef55a6
[mesa.git] / src / mesa / swrast / s_feedback.c
1 /* $Id: s_feedback.c,v 1.1 2000/11/05 18:24:40 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999-2000 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
49 static void feedback_vertex( GLcontext *ctx, SWvertex *v )
50 {
51 GLfloat win[4];
52 GLfloat color[4];
53 GLfloat tc[4];
54 GLuint texUnit = ctx->Texture.CurrentTransformUnit;
55 GLuint index;
56
57 win[0] = v->win[0];
58 win[1] = v->win[1];
59 win[2] = v->win[2] / ctx->Visual.DepthMaxF;
60 win[3] = 1.0 / v->win[3];
61
62 color[0] = CHAN_TO_FLOAT(v->color[0]);
63 color[1] = CHAN_TO_FLOAT(v->color[1]);
64 color[2] = CHAN_TO_FLOAT(v->color[2]);
65 color[3] = CHAN_TO_FLOAT(v->color[3]);
66
67 if (v->texcoord[texUnit][3] != 1.0 &&
68 v->texcoord[texUnit][3] != 0.0) {
69 GLfloat invq = 1.0F / v->texcoord[texUnit][3];
70 tc[0] = v->texcoord[texUnit][0] * invq;
71 tc[1] = v->texcoord[texUnit][1] * invq;
72 tc[2] = v->texcoord[texUnit][2] * invq;
73 tc[3] = v->texcoord[texUnit][3];
74 }
75 else {
76 COPY_4V(tc, v->texcoord[texUnit]);
77 }
78
79 index = v->index;
80
81 gl_feedback_vertex( ctx, win, color, index, tc );
82 }
83
84
85 /*
86 * Put triangle in feedback buffer.
87 */
88 void gl_feedback_triangle( GLcontext *ctx, SWvertex *v0, SWvertex *v1,
89 SWvertex *v2)
90 {
91 if (gl_cull_triangle( ctx, v0, v1, v2 )) {
92 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POLYGON_TOKEN );
93 FEEDBACK_TOKEN( ctx, (GLfloat) 3 ); /* three vertices */
94
95 feedback_vertex( ctx, v0 );
96 feedback_vertex( ctx, v1 );
97 feedback_vertex( ctx, v2 );
98 }
99 }
100
101
102 void gl_feedback_line( GLcontext *ctx, SWvertex *v0, SWvertex *v1 )
103 {
104 GLenum token = GL_LINE_TOKEN;
105 SWcontext *swrast = SWRAST_CONTEXT(ctx);
106
107 if (swrast->StippleCounter==0)
108 token = GL_LINE_RESET_TOKEN;
109
110 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) token );
111
112 feedback_vertex( ctx, v0 );
113 feedback_vertex( ctx, v1 );
114
115 swrast->StippleCounter++;
116 }
117
118
119 void gl_feedback_point( GLcontext *ctx, SWvertex *v )
120 {
121 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POINT_TOKEN );
122 feedback_vertex( ctx, v );
123 }
124
125
126 void gl_select_triangle( GLcontext *ctx, SWvertex *v0, SWvertex *v1,
127 SWvertex *v2)
128 {
129 if (gl_cull_triangle( ctx, v0, v1, v2 )) {
130 const GLfloat zs = 1.0F / ctx->Visual.DepthMaxF;
131 gl_update_hitflag( ctx, v0->win[2] * zs );
132 gl_update_hitflag( ctx, v1->win[2] * zs );
133 gl_update_hitflag( ctx, v2->win[2] * zs );
134 }
135 }
136
137
138 void gl_select_line( GLcontext *ctx, SWvertex *v0, SWvertex *v1 )
139 {
140 const GLfloat zs = 1.0F / ctx->Visual.DepthMaxF;
141 gl_update_hitflag( ctx, v0->win[2] * zs );
142 gl_update_hitflag( ctx, v1->win[2] * zs );
143 }
144
145
146 void gl_select_point( GLcontext *ctx, SWvertex *v )
147 {
148 const GLfloat zs = 1.0F / ctx->Visual.DepthMaxF;
149 gl_update_hitflag( ctx, v->win[2] * zs );
150 }
151
152
153