Major check-in of changes for GL_EXT_framebuffer_object extension.
[mesa.git] / src / mesa / swrast / s_feedback.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "glheader.h"
26 #include "colormac.h"
27 #include "context.h"
28 #include "enums.h"
29 #include "feedback.h"
30 #include "macros.h"
31
32 #include "s_context.h"
33 #include "s_feedback.h"
34 #include "s_triangle.h"
35
36
37 #define FB_3D 0x01
38 #define FB_4D 0x02
39 #define FB_INDEX 0x04
40 #define FB_COLOR 0x08
41 #define FB_TEXTURE 0X10
42
43
44
45
46 static void feedback_vertex( GLcontext *ctx,
47 const SWvertex *v, const SWvertex *pv )
48 {
49 const GLuint texUnit = 0; /* See section 5.3 of 1.2.1 spec */
50 GLfloat win[4];
51 GLfloat color[4];
52 GLfloat tc[4];
53
54 win[0] = v->win[0];
55 win[1] = v->win[1];
56 win[2] = v->win[2] / ctx->DrawBuffer->_DepthMaxF;
57 win[3] = 1.0F / v->win[3];
58
59 color[0] = CHAN_TO_FLOAT(pv->color[0]);
60 color[1] = CHAN_TO_FLOAT(pv->color[1]);
61 color[2] = CHAN_TO_FLOAT(pv->color[2]);
62 color[3] = CHAN_TO_FLOAT(pv->color[3]);
63
64 if (v->texcoord[texUnit][3] != 1.0 &&
65 v->texcoord[texUnit][3] != 0.0) {
66 GLfloat invq = 1.0F / v->texcoord[texUnit][3];
67 tc[0] = v->texcoord[texUnit][0] * invq;
68 tc[1] = v->texcoord[texUnit][1] * invq;
69 tc[2] = v->texcoord[texUnit][2] * invq;
70 tc[3] = v->texcoord[texUnit][3];
71 }
72 else {
73 COPY_4V(tc, v->texcoord[texUnit]);
74 }
75
76 _mesa_feedback_vertex( ctx, win, color, (GLfloat) v->index, tc );
77 }
78
79
80 /*
81 * Put triangle in feedback buffer.
82 */
83 void _swrast_feedback_triangle( GLcontext *ctx,
84 const SWvertex *v0,
85 const SWvertex *v1,
86 const SWvertex *v2)
87 {
88 if (_swrast_culltriangle( ctx, v0, v1, v2 )) {
89 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POLYGON_TOKEN );
90 FEEDBACK_TOKEN( ctx, (GLfloat) 3 ); /* three vertices */
91
92 if (ctx->Light.ShadeModel == GL_SMOOTH) {
93 feedback_vertex( ctx, v0, v0 );
94 feedback_vertex( ctx, v1, v1 );
95 feedback_vertex( ctx, v2, v2 );
96 } else {
97 feedback_vertex( ctx, v0, v2 );
98 feedback_vertex( ctx, v1, v2 );
99 feedback_vertex( ctx, v2, v2 );
100 }
101 }
102 }
103
104
105 void _swrast_feedback_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
106 {
107 GLenum token = GL_LINE_TOKEN;
108 SWcontext *swrast = SWRAST_CONTEXT(ctx);
109
110 if (swrast->StippleCounter==0)
111 token = GL_LINE_RESET_TOKEN;
112
113 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) token );
114
115 if (ctx->Light.ShadeModel == GL_SMOOTH) {
116 feedback_vertex( ctx, v0, v0 );
117 feedback_vertex( ctx, v1, v1 );
118 } else {
119 feedback_vertex( ctx, v0, v1 );
120 feedback_vertex( ctx, v1, v1 );
121 }
122
123 swrast->StippleCounter++;
124 }
125
126
127 void _swrast_feedback_point( GLcontext *ctx, const SWvertex *v )
128 {
129 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POINT_TOKEN );
130 feedback_vertex( ctx, v, v );
131 }
132
133
134 void _swrast_select_triangle( GLcontext *ctx,
135 const SWvertex *v0,
136 const SWvertex *v1,
137 const SWvertex *v2)
138 {
139 if (_swrast_culltriangle( ctx, v0, v1, v2 )) {
140 const GLfloat zs = 1.0F / ctx->DrawBuffer->_DepthMaxF;
141
142 _mesa_update_hitflag( ctx, v0->win[2] * zs );
143 _mesa_update_hitflag( ctx, v1->win[2] * zs );
144 _mesa_update_hitflag( ctx, v2->win[2] * zs );
145 }
146 }
147
148
149 void _swrast_select_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
150 {
151 const GLfloat zs = 1.0F / ctx->DrawBuffer->_DepthMaxF;
152 _mesa_update_hitflag( ctx, v0->win[2] * zs );
153 _mesa_update_hitflag( ctx, v1->win[2] * zs );
154 }
155
156
157 void _swrast_select_point( GLcontext *ctx, const SWvertex *v )
158 {
159 const GLfloat zs = 1.0F / ctx->DrawBuffer->_DepthMaxF;
160 _mesa_update_hitflag( ctx, v->win[2] * zs );
161 }