2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Flat shader derived from texture mapper (a little slow)
32 //#include "tmapext.h"
36 void (*scanline_func)(int,fix,fix);
38 // -------------------------------------------------------------------------------------
39 // Texture map current scanline.
40 // Uses globals Du_dx and Dv_dx to incrementally compute u,v coordinates
41 // -------------------------------------------------------------------------------------
42 void tmap_scanline_flat(int y, fix xleft, fix xright)
47 // setup to call assembler scanline renderer
50 fx_xleft = xleft/F1_0; // (xleft >> 16) != xleft/F1_0 for negative numbers, f2i caused random crashes
51 fx_xright = xright/F1_0;
53 if ( Gr_scanline_darkening_level >= GR_FADE_LEVELS )
54 cur_tmap_scanline_flat();
56 tmap_flat_shade_value = Gr_scanline_darkening_level;
57 cur_tmap_scanline_shaded();
62 //--unused-- void tmap_scanline_shaded(int y, fix xleft, fix xright)
66 //--unused-- dx = xright - xleft;
68 //--unused-- // setup to call assembler scanline renderer
70 //--unused-- fx_y = y << 16;
71 //--unused-- fx_xleft = xleft;
72 //--unused-- fx_xright = xright;
74 //--unused-- asm_tmap_scanline_shaded();
78 // -------------------------------------------------------------------------------------
79 // Render a texture map.
80 // Linear in outer loop, linear in inner loop.
81 // -------------------------------------------------------------------------------------
82 void texture_map_flat(g3ds_tmap *t, int color)
84 int vlt,vrt,vlb,vrb; // vertex left top, vertex right top, vertex left bottom, vertex right bottom
86 fix dx_dy_left,dx_dy_right;
94 tmap_flat_color = color;
96 // Determine top and bottom y coords.
97 compute_y_bounds(t,&vlt,&vlb,&vrt,&vrb,&max_y_vertex);
99 // Set top and bottom (of entire texture map) y coordinates.
100 topy = f2i(v3d[vlt].y2d);
101 boty = f2i(v3d[max_y_vertex].y2d);
103 // Set amount to change x coordinate for each advance to next scanline.
104 dy = f2i(t->verts[vlb].y2d) - f2i(t->verts[vlt].y2d);
105 if (dy < FIX_RECIP_TABLE_SIZE)
106 recip_dy = fix_recip[dy];
110 dx_dy_left = compute_dx_dy(t,vlt,vlb, recip_dy);
112 dy = f2i(t->verts[vrb].y2d) - f2i(t->verts[vrt].y2d);
113 if (dy < FIX_RECIP_TABLE_SIZE)
114 recip_dy = fix_recip[dy];
118 dx_dy_right = compute_dx_dy(t,vrt,vrb, recip_dy);
120 // Set initial values for x, u, v
121 xleft = v3d[vlt].x2d;
122 xright = v3d[vrt].x2d;
124 // scan all rows in texture map from top through first break.
125 // @mk: Should we render the scanline for y==boty? This violates Matt's spec.
127 for (y = topy; y < boty; y++) {
129 // See if we have reached the end of the current left edge, and if so, set
130 // new values for dx_dy and x,u,v
131 if (y == f2i(v3d[vlb].y2d)) {
132 // Handle problem of double points. Search until y coord is different. Cannot get
133 // hung in an infinite loop because we know there is a vertex with a lower y coordinate
134 // because in the for loop, we don't scan all spanlines.
135 while (y == f2i(v3d[vlb].y2d)) {
137 vlb = prevmod(vlb,t->nv);
139 dy = f2i(t->verts[vlb].y2d) - f2i(t->verts[vlt].y2d);
140 if (dy < FIX_RECIP_TABLE_SIZE)
141 recip_dy = fix_recip[dy];
145 dx_dy_left = compute_dx_dy(t,vlt,vlb, recip_dy);
147 xleft = v3d[vlt].x2d;
150 // See if we have reached the end of the current left edge, and if so, set
151 // new values for dx_dy and x. Not necessary to set new values for u,v.
152 if (y == f2i(v3d[vrb].y2d)) {
153 while (y == f2i(v3d[vrb].y2d)) {
155 vrb = succmod(vrb,t->nv);
158 dy = f2i(t->verts[vrb].y2d) - f2i(t->verts[vrt].y2d);
159 if (dy < FIX_RECIP_TABLE_SIZE)
160 recip_dy = fix_recip[dy];
164 dx_dy_right = compute_dx_dy(t,vrt,vrb, recip_dy);
166 xright = v3d[vrt].x2d;
170 //tmap_scanline_flat(y, xleft, xright);
171 (*scanline_func)(y, xleft, xright);
174 xright += dx_dy_right;
177 //tmap_scanline_flat(y, xleft, xright);
178 (*scanline_func)(y, xleft, xright);
182 // -----------------------------------------------------------------------------------------
183 // This is the gr_upoly-like interface to the texture mapper which uses texture-mapper compatible
184 // (ie, avoids cracking) edge/delta computation.
185 void gr_upoly_tmap(int nverts, int *vert )
187 gr_upoly_tmap_ylr(nverts, vert, tmap_scanline_flat);
193 typedef struct pnt2d {
198 #pragma off (unreferenced) //bp not referenced
201 //this takes the same partms as draw_tmap, but draws a flat-shaded polygon
202 void draw_tmap_flat(grs_bitmap *bp,int nverts,g3s_point **vertbuf)
204 pnt2d points[MAX_TMAP_VERTS];
209 Assert(nverts < MAX_TMAP_VERTS);
211 average_light = vertbuf[0]->p3_l;
212 for (i=1; i<nverts; i++)
213 average_light += vertbuf[i]->p3_l;
216 average_light = f2i(average_light * NUM_LIGHTING_LEVELS/4);
218 average_light = f2i(average_light * NUM_LIGHTING_LEVELS/nverts);
220 if (average_light < 0)
222 else if (average_light > NUM_LIGHTING_LEVELS-1)
223 average_light = NUM_LIGHTING_LEVELS-1;
225 color = gr_fade_table[average_light*256 + bp->avg_color];
228 for (i=0;i<nverts;i++) {
229 points[i].x = vertbuf[i]->p3_sx;
230 points[i].y = vertbuf[i]->p3_sy;
233 gr_upoly_tmap(nverts,(int *) points);
237 #pragma on (unreferenced)
240 // -----------------------------------------------------------------------------------------
241 //This is like gr_upoly_tmap() but instead of drawing, it calls the specified
242 //function with ylr values
243 void gr_upoly_tmap_ylr(int nverts, int *vert, void (*ylr_func)(int,fix,fix) )
248 //--now called from g3_start_frame-- init_interface_vars_to_assembler();
252 for (i=0; i<nverts; i++) {
253 my_tmap.verts[i].x2d = *vert++;
254 my_tmap.verts[i].y2d = *vert++;
257 scanline_func = ylr_func;
259 texture_map_flat(&my_tmap, COLOR);