source: golgotha/src/render/software/mappers.cc

Last change on this file was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 10.4 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "software/r1_software.hh"
10#include "software/r1_software_globals.hh"
11#include "software/mappers.hh"
12#include "device/processor.hh"
13
14//global instance of the various function tables
15
16texture_scanline_func_ptr texture_scanline_functions[SPAN_TRI_LAST];
17poly_setup_func_ptr       poly_setup_functions[SPAN_TRI_LAST];
18tri_draw_func_ptr         tri_draw_functions[SPAN_TRI_LAST];
19span_draw_func_ptr        span_draw_functions[SPAN_TRI_LAST];
20
21//this is super important. this points to the current scanline texturemapping function
22//and is used by all of the rasterizers / span drawers (so before you call the rasterizer /
23//setup function, make sure you set this pointer correctly)
24texture_scanline_func_ptr cur_scanline_texture_func = 0;
25
26//the current span list builder (either the one optimized for intel or amd3d)
27build_triangle_span_lists_func_ptr cur_build_span_lists_function = 0;
28
29void r1_software_class::initialize_function_pointers(i4_bool amd3d)
30{
31  //zero them out to start with
32  memset(texture_scanline_functions, 0, sizeof(texture_scanline_func_ptr) * SPAN_TRI_LAST);
33  memset(poly_setup_functions,       0, sizeof(poly_setup_func_ptr)       * SPAN_TRI_LAST); 
34  memset(tri_draw_functions,         0, sizeof(tri_draw_func_ptr)         * SPAN_TRI_LAST);
35  memset(span_draw_functions,        0, sizeof(span_draw_func_ptr)        * SPAN_TRI_LAST);
36 
37  cur_build_span_lists_function = intel_build_triangle_span_lists;
38
39  //scanline texturing / drawing functions
40  texture_scanline_functions[SPAN_TRI_AFFINE_UNLIT]              = texture_scanline_affine_unlit;
41  texture_scanline_functions[SPAN_TRI_AFFINE_UNLIT_HOLY]         = texture_scanline_affine_unlit_holy;
42  texture_scanline_functions[SPAN_TRI_AFFINE_UNLIT_HOLY_BLEND]   = texture_scanline_affine_unlit_holy_blend;
43  texture_scanline_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA]        = texture_scanline_affine_unlit_alpha;
44   
45#ifdef USE_ASM
46  //this is a special case mapper optimized in asm only
47  //(ignores the t gradient, basically, since sprites have no delta t per screen x)
48  texture_scanline_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA_SPRITE] = texture_scanline_affine_unlit_alpha_sprite;
49#else 
50  texture_scanline_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA_SPRITE] = texture_scanline_affine_unlit_alpha;
51#endif
52
53  texture_scanline_functions[SPAN_TRI_AFFINE_LIT]              = texture_scanline_affine_lit;
54  texture_scanline_functions[SPAN_TRI_PERSPECTIVE_LIT]         = texture_scanline_perspective_lit;
55  texture_scanline_functions[SPAN_TRI_PERSPECTIVE_UNLIT_ALPHA] = texture_scanline_perspective_unlit_alpha;
56  texture_scanline_functions[SPAN_TRI_PERSPECTIVE_UNLIT]       = texture_scanline_perspective_unlit;
57  texture_scanline_functions[SPAN_TRI_PERSPECTIVE_UNLIT_HOLY]  = texture_scanline_perspective_unlit_holy;
58 
59  texture_scanline_functions[SPAN_TRI_SOLID_FILL]              = texture_scanline_solid_fill;
60  texture_scanline_functions[SPAN_TRI_SOLID_BLEND]             = texture_scanline_solid_blend_half;
61
62  //poly setup functions (calculates deltas, gradients, etc)
63  poly_setup_functions[SPAN_TRI_AFFINE_UNLIT]              = poly_setup_affine_lit;
64  poly_setup_functions[SPAN_TRI_AFFINE_UNLIT_HOLY]         = poly_setup_affine_lit;
65  poly_setup_functions[SPAN_TRI_AFFINE_UNLIT_HOLY_BLEND]   = poly_setup_affine_lit;
66  poly_setup_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA]        = poly_setup_affine_lit;
67  poly_setup_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA_SPRITE] = poly_setup_affine_lit;
68  poly_setup_functions[SPAN_TRI_AFFINE_LIT]                = poly_setup_affine_lit;
69
70  poly_setup_functions[SPAN_TRI_PERSPECTIVE_UNLIT]       = poly_setup_perspective_lit;
71  poly_setup_functions[SPAN_TRI_PERSPECTIVE_UNLIT_HOLY]  = poly_setup_perspective_lit;
72  poly_setup_functions[SPAN_TRI_PERSPECTIVE_UNLIT_ALPHA] = poly_setup_perspective_lit;
73  poly_setup_functions[SPAN_TRI_PERSPECTIVE_LIT]         = poly_setup_perspective_lit;
74
75  poly_setup_functions[SPAN_TRI_SOLID_FILL]              = poly_setup_solid_color;
76  poly_setup_functions[SPAN_TRI_SOLID_BLEND]             = poly_setup_solid_color;
77
78  //span drawing functions (sets up some variables, steps through spans, calculates starting s,t,etc, for each span)
79  span_draw_functions[SPAN_TRI_AFFINE_UNLIT]              = span_draw_affine_unlit;
80  span_draw_functions[SPAN_TRI_AFFINE_UNLIT_HOLY]         = span_draw_affine_unlit;
81  span_draw_functions[SPAN_TRI_AFFINE_UNLIT_HOLY_BLEND]   = span_draw_affine_unlit;
82  span_draw_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA]        = span_draw_affine_unlit;
83  span_draw_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA_SPRITE] = span_draw_affine_unlit;
84  span_draw_functions[SPAN_TRI_AFFINE_LIT]                = span_draw_affine_lit;
85  span_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT]         = span_draw_perspective_unlit;
86  span_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT_HOLY]    = span_draw_perspective_unlit;
87  span_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT_ALPHA]   = span_draw_perspective_unlit;
88  span_draw_functions[SPAN_TRI_PERSPECTIVE_LIT]           = span_draw_perspective_lit;
89
90  span_draw_functions[SPAN_TRI_SOLID_FILL]              = span_draw_solid_color;
91  span_draw_functions[SPAN_TRI_SOLID_BLEND]             = span_draw_solid_color;
92 
93  //triangle drawing functions (rasterizes triangles, steps the necessary values (s,t,l,etc) )
94  tri_draw_functions[SPAN_TRI_AFFINE_UNLIT]              = tri_draw_affine_unlit;
95  tri_draw_functions[SPAN_TRI_AFFINE_UNLIT_HOLY]         = tri_draw_affine_unlit;
96  tri_draw_functions[SPAN_TRI_AFFINE_UNLIT_HOLY_BLEND]   = tri_draw_affine_unlit;
97  tri_draw_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA]        = tri_draw_affine_unlit;
98  tri_draw_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA_SPRITE] = tri_draw_affine_unlit;
99  tri_draw_functions[SPAN_TRI_AFFINE_LIT]                = tri_draw_affine_lit; 
100
101  tri_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT]       = tri_draw_perspective_unlit;
102  tri_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT_HOLY]  = tri_draw_perspective_unlit;
103  tri_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT_ALPHA] = tri_draw_perspective_unlit;
104  tri_draw_functions[SPAN_TRI_PERSPECTIVE_LIT]         = tri_draw_perspective_lit;
105
106  tri_draw_functions[SPAN_TRI_SOLID_FILL]              = 0;//tri_draw_solid_color;
107  tri_draw_functions[SPAN_TRI_SOLID_BLEND]             = 0;//tri_draw_solid_color;
108
109  do_amd3d = i4_F;
110
111#ifdef USE_AMD3D
112  if (amd3d)
113  {
114    i4_cpu_info_struct s;
115    i4_get_cpu_info(&s);
116
117    if (s.cpu_flags & i4_cpu_info_struct::AMD3D)
118    {
119      do_amd3d = i4_T;
120
121      //we're compiling amd3d stuff, its requesting the amd3d functions,
122      //the processor supports them, do it
123      cur_build_span_lists_function = amd3d_build_triangle_span_lists;
124   
125      span_draw_functions[SPAN_TRI_AFFINE_UNLIT]              = span_draw_affine_unlit_amd3d;
126      span_draw_functions[SPAN_TRI_AFFINE_UNLIT_HOLY]         = span_draw_affine_unlit_amd3d;
127      span_draw_functions[SPAN_TRI_AFFINE_UNLIT_HOLY_BLEND]   = span_draw_affine_unlit_amd3d;
128      span_draw_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA]        = span_draw_affine_unlit_amd3d;
129      span_draw_functions[SPAN_TRI_AFFINE_UNLIT_ALPHA_SPRITE] = span_draw_affine_unlit_amd3d;
130      span_draw_functions[SPAN_TRI_AFFINE_LIT]                = span_draw_affine_lit_amd3d;
131      span_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT]         = span_draw_perspective_unlit_amd3d;
132      span_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT_HOLY]    = span_draw_perspective_unlit_amd3d;
133      span_draw_functions[SPAN_TRI_PERSPECTIVE_UNLIT_ALPHA]   = span_draw_perspective_unlit_amd3d;
134      span_draw_functions[SPAN_TRI_PERSPECTIVE_LIT]           = span_draw_perspective_lit_amd3d;
135
136      texture_scanline_functions[SPAN_TRI_AFFINE_LIT]              = texture_scanline_affine_lit_amd3d;
137      texture_scanline_functions[SPAN_TRI_PERSPECTIVE_LIT]         = texture_scanline_perspective_lit_amd3d;
138      texture_scanline_functions[SPAN_TRI_PERSPECTIVE_UNLIT_ALPHA] = texture_scanline_perspective_unlit_alpha_amd3d;
139      texture_scanline_functions[SPAN_TRI_PERSPECTIVE_UNLIT]       = texture_scanline_perspective_unlit_amd3d;
140      texture_scanline_functions[SPAN_TRI_PERSPECTIVE_UNLIT_HOLY]  = texture_scanline_perspective_unlit_holy_amd3d;
141    }
142  }
143#endif
144}
145
146#ifdef USE_ASM
147
148//laziness. include all the scanline texturemappers / fillers
149#include "software/affine_map_lit_asm.cc"
150#include "software/affine_map_unlit_asm.cc"
151#include "software/affine_map_unlit_holy_asm.cc"
152#include "software/affine_map_unlit_holy_blend_asm.cc"
153#include "software/affine_map_unlit_alpha_asm.cc"
154#include "software/affine_map_unlit_alpha_sprite_asm.cc"
155#include "software/affine_map_unlit_true_alpha_c.cc"
156#include "software/perspective_map_lit_asm.cc"
157#include "software/perspective_map_unlit_asm.cc"
158#include "software/perspective_map_unlit_holy_asm.cc"
159#include "software/perspective_map_unlit_alpha_asm.cc"
160#include "software/perspective_map_unlit_true_alpha_c.cc"
161#include "software/solid_blend_half_asm.cc"
162#include "software/solid_fill_asm.cc"
163
164#ifdef USE_AMD3D
165//include all the amd3d texturemappers too
166#include "software/amd3d/affine_map_lit_asm_amd3d.cc"
167#include "software/amd3d/perspective_map_lit_asm_amd3d.cc"
168#include "software/amd3d/perspective_map_unlit_alpha_asm_amd3d.cc"
169#include "software/amd3d/perspective_map_unlit_asm_amd3d.cc"
170#include "software/amd3d/perspective_map_unlit_holy_asm_amd3d.cc"
171#endif
172
173#else
174
175#include "software/affine_map_lit_c.cc"
176#include "software/affine_map_unlit_c.cc"
177#include "software/affine_map_unlit_holy_c.cc"
178#include "software/affine_map_unlit_holy_blend_c.cc"
179#include "software/affine_map_unlit_alpha_c.cc"
180#include "software/affine_map_unlit_true_alpha_c.cc"
181#include "software/perspective_map_lit_c.cc"
182#include "software/perspective_map_unlit_c.cc"
183#include "software/perspective_map_unlit_holy_c.cc"
184#include "software/perspective_map_unlit_alpha_c.cc"
185#include "software/perspective_map_unlit_true_alpha_c.cc"
186#include "software/solid_blend_half_c.cc"
187#include "software/solid_fill_c.cc"
188
189#endif
Note: See TracBrowser for help on using the repository browser.