1 | /* $Id: indirect_tmp.h,v 1.1 2000-02-29 00:48:32 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Mesa 3-D graphics library
|
---|
5 | * Version: 3.1
|
---|
6 | *
|
---|
7 | * Copyright (C) 1999 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 | /*
|
---|
28 | * New (3.1) transformation code written by Keith Whitwell.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | #define DO_CULL 0x1
|
---|
33 | #define DO_OFFSET 0x2
|
---|
34 | #define DO_LIGHT_TWOSIDE 0x4
|
---|
35 | #define DO_UNFILLED 0x8
|
---|
36 | #define HAVE_CULL_MASK 0x10
|
---|
37 |
|
---|
38 |
|
---|
39 | static void TAG(render_triangle)( GLcontext *ctx,
|
---|
40 | GLuint v0, GLuint v1, GLuint v2, GLuint pv )
|
---|
41 | {
|
---|
42 | struct vertex_buffer *VB = ctx->VB;
|
---|
43 |
|
---|
44 | #if ((IND & NEED_FACING) && !(IND & HAVE_CULL_MASK)) || (IND & DO_OFFSET)
|
---|
45 | GLfloat (*win)[4] = VB->Win.data;
|
---|
46 | GLfloat ex = win[v1][0] - win[v0][0];
|
---|
47 | GLfloat ey = win[v1][1] - win[v0][1];
|
---|
48 | GLfloat fx = win[v2][0] - win[v0][0];
|
---|
49 | GLfloat fy = win[v2][1] - win[v0][1];
|
---|
50 | GLfloat c = ex*fy-ey*fx;
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | #if (IND & NEED_FACING)
|
---|
54 | #if (IND & HAVE_CULL_MASK)
|
---|
55 | GLuint facing = ((VB->CullMask[pv]&PRIM_FACE_REAR)?1:0);
|
---|
56 | #else
|
---|
57 | GLuint facing = (c<0.0F) ^ (ctx->Polygon.FrontFace==GL_CW);
|
---|
58 | #endif
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | #if (IND & DO_CULL)
|
---|
62 | if ((facing+1) & ctx->Polygon.CullBits)
|
---|
63 | return;
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | #if (IND & DO_OFFSET)
|
---|
67 | {
|
---|
68 | /* finish computing plane equation of polygon, compute offset */
|
---|
69 | GLfloat fz = win[v2][2] - win[v0][2];
|
---|
70 | GLfloat ez = win[v1][2] - win[v0][2];
|
---|
71 | GLfloat a = ey*fz-ez*fy;
|
---|
72 | GLfloat b = ez*fx-ex*fz;
|
---|
73 | offset_polygon( ctx, a, b, c );
|
---|
74 | }
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | #if (IND & DO_LIGHT_TWOSIDE)
|
---|
78 | VB->Specular = VB->Spec[facing];
|
---|
79 | VB->ColorPtr = VB->Color[facing];
|
---|
80 | VB->IndexPtr = VB->Index[facing];
|
---|
81 | #endif
|
---|
82 |
|
---|
83 |
|
---|
84 | #if (IND & DO_UNFILLED)
|
---|
85 | {
|
---|
86 | GLuint vlist[3];
|
---|
87 | vlist[0] = v0;
|
---|
88 | vlist[1] = v1;
|
---|
89 | vlist[2] = v2;
|
---|
90 | unfilled_polygon( ctx, 3, vlist, pv, facing );
|
---|
91 | }
|
---|
92 | #else
|
---|
93 | ctx->Driver.TriangleFunc( ctx, v0, v1, v2, pv );
|
---|
94 | #endif
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 |
|
---|
99 | /* Implements quad rendering when direct_triangles is false.
|
---|
100 | *
|
---|
101 | * Need to implement cull check ?
|
---|
102 | */
|
---|
103 | static void render_quad( GLcontext *ctx, GLuint v0, GLuint v1,
|
---|
104 | GLuint v2, GLuint v3, GLuint pv )
|
---|
105 | {
|
---|
106 | struct vertex_buffer *VB = ctx->VB;
|
---|
107 |
|
---|
108 | GLuint facing = ((VB->CullMask[pv]&PRIM_FACE_REAR)?1:0);
|
---|
109 |
|
---|
110 |
|
---|
111 | if (ctx->IndirectTriangles & DD_TRI_OFFSET) {
|
---|
112 | GLfloat (*win)[4] = VB->Win.data;
|
---|
113 | GLfloat ez = win[v2][2] - win[v0][2];
|
---|
114 | GLfloat fz = win[v3][2] - win[v1][2];
|
---|
115 | GLfloat ex = win[v2][0] - win[v0][0];
|
---|
116 | GLfloat ey = win[v2][1] - win[v0][1];
|
---|
117 | GLfloat fx = win[v3][0] - win[v1][0];
|
---|
118 | GLfloat fy = win[v3][1] - win[v1][1];
|
---|
119 | GLfloat a = ey*fz-ez*fy;
|
---|
120 | GLfloat b = ez*fx-ex*fz;
|
---|
121 | GLfloat c = ex*fy-ey*fx;
|
---|
122 | offset_polygon( ctx, a, b, c );
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | if (ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE) {
|
---|
127 | VB->Specular = VB->Spec[facing];
|
---|
128 | VB->ColorPtr = VB->Color[facing];
|
---|
129 | VB->IndexPtr = VB->Index[facing];
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | /* Render the quad! */
|
---|
134 | if (ctx->Polygon.Unfilled) {
|
---|
135 | GLuint vlist[4];
|
---|
136 | vlist[0] = v0;
|
---|
137 | vlist[1] = v1;
|
---|
138 | vlist[2] = v2;
|
---|
139 | vlist[3] = v3;
|
---|
140 | unfilled_polygon( ctx, 4, vlist, pv, facing );
|
---|
141 | }
|
---|
142 | else {
|
---|
143 | (*ctx->Driver.QuadFunc)( ctx, v0, v1, v2, v3, pv );
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | void unfilled_triangle( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2,
|
---|
149 | GLuint pv )
|
---|
150 | {
|
---|
151 | GLuint vlist[4];
|
---|
152 | vlist[0] = v0;
|
---|
153 | vlist[1] = v1;
|
---|
154 | vlist[2] = v2;
|
---|
155 | unfilled_polygon( ctx, 3, vlist, pv, facing );
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | void unfilled_quad( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2,
|
---|
160 | GLuint v3, GLuint pv )
|
---|
161 | {
|
---|
162 | GLuint vlist[4];
|
---|
163 | vlist[0] = v0;
|
---|
164 | vlist[1] = v1;
|
---|
165 | vlist[2] = v2;
|
---|
166 | vlist[3] = v3;
|
---|
167 | unfilled_polygon( ctx, 4, vlist, pv, facing );
|
---|
168 | }
|
---|
169 |
|
---|