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 | #ifndef R1_RENDER_API_HH
|
---|
10 | #define R1_RENDER_API_HH
|
---|
11 |
|
---|
12 | #include "tex_id.hh"
|
---|
13 | #include "video/display.hh"
|
---|
14 | #include "r1_vert.hh"
|
---|
15 | #include "tnode.hh"
|
---|
16 |
|
---|
17 | typedef struct
|
---|
18 | {
|
---|
19 | i4_float r,g,b;
|
---|
20 | } r1_color_tint;
|
---|
21 |
|
---|
22 | typedef w32 r1_color_tint_handle;
|
---|
23 |
|
---|
24 | enum r1_alpha_type
|
---|
25 | {
|
---|
26 | R1_ALPHA_DISABLED,
|
---|
27 | R1_ALPHA_CONSTANT, // use the constant color's alpha
|
---|
28 | R1_ALPHA_LINEAR // use the alpha specified in the verts
|
---|
29 | };
|
---|
30 |
|
---|
31 | enum r1_shading_type
|
---|
32 | {
|
---|
33 | R1_SHADE_DISABLED, // routines will not light
|
---|
34 | R1_CONSTANT_SHADING, // routines will use the constant color
|
---|
35 | R1_WHITE_SHADING, // routines will use only the red component (as white)
|
---|
36 | R1_COLORED_SHADING // routines will use r,g, and b
|
---|
37 | };
|
---|
38 |
|
---|
39 | enum
|
---|
40 | {
|
---|
41 | R1_WRITE_COLOR = 1, // write pixels to frame buffer
|
---|
42 | R1_WRITE_W = 2, // write w values to depth buffer
|
---|
43 | R1_COMPARE_W = 4 // if compare is off w then the depth buffer is not consulted
|
---|
44 | };
|
---|
45 | typedef w32 r1_write_mask_type;
|
---|
46 |
|
---|
47 | enum r1_filter_type
|
---|
48 | {
|
---|
49 | R1_NO_FILTERING,
|
---|
50 | R1_BILINEAR_FILTERING
|
---|
51 | };
|
---|
52 |
|
---|
53 | enum r1_expand_type
|
---|
54 | {
|
---|
55 | R1_COPY_1x1, // 1 - 1 pixel copy (render size = w,h)
|
---|
56 | R1_COPY_2x2, // 2 - 1 pixel blow up (render size = w/2, h/2)
|
---|
57 | R1_COPY_1x1_SCANLINE_SKIP // skips a scan line on each row (render size = w, h/2)
|
---|
58 | };
|
---|
59 |
|
---|
60 | enum r1_render_flags
|
---|
61 | {
|
---|
62 | R1_SOFTWARE=1
|
---|
63 | };
|
---|
64 |
|
---|
65 | enum r1_feature_flags
|
---|
66 | {
|
---|
67 | R1_SPANS=1,
|
---|
68 | R1_PERSPECTIVE_CORRECT=2,
|
---|
69 | R1_LOCK_CHEAT=4,
|
---|
70 | R1_Z_BIAS=8, //everything drawn after this is turned on is more likely to be drawn
|
---|
71 | //in front of things drawn before it was turned on
|
---|
72 | R1_ALL_FEATURES = R1_SPANS | R1_PERSPECTIVE_CORRECT | R1_LOCK_CHEAT | R1_Z_BIAS
|
---|
73 | };
|
---|
74 |
|
---|
75 | class r1_last_node;
|
---|
76 | class r1_texture_manager_class;
|
---|
77 | class r1_miplevel_t;
|
---|
78 |
|
---|
79 | class r1_texture_manager;
|
---|
80 | class g1_texture_node_struct;
|
---|
81 | class r1_render_window_class; // defined in r1_win.hh
|
---|
82 |
|
---|
83 | class r1_render_api_class
|
---|
84 | {
|
---|
85 | protected:
|
---|
86 | friend r1_render_api_class *r1_get_api(i4_display_class *for_display);
|
---|
87 | friend r1_render_api_class *r1_create_api(i4_display_class *for_display, char *name);
|
---|
88 |
|
---|
89 | friend void r1_destroy_api(r1_render_api_class *r);
|
---|
90 |
|
---|
91 | r1_texture_manager_class *tmanager;
|
---|
92 |
|
---|
93 | // make these global so they can be accessed without pointer indirection (faster)
|
---|
94 | static r1_miplevel_t *last_node;
|
---|
95 | static r1_shading_type shade_mode;
|
---|
96 | static r1_alpha_type alpha_mode;
|
---|
97 | static r1_write_mask_type write_mask;
|
---|
98 | static w32 const_color;
|
---|
99 | static r1_filter_type filter_mode;
|
---|
100 | static r1_render_api_class *first;
|
---|
101 |
|
---|
102 | static i4_float r_tint_mul;
|
---|
103 | static i4_float g_tint_mul;
|
---|
104 | static i4_float b_tint_mul;
|
---|
105 | static i4_bool color_tint_on;
|
---|
106 |
|
---|
107 | enum { MAX_COLOR_TINTS = 32 };
|
---|
108 |
|
---|
109 | static r1_color_tint color_tint_list[MAX_COLOR_TINTS];
|
---|
110 | static sw8 num_color_tints;
|
---|
111 |
|
---|
112 | r1_render_api_class *next;
|
---|
113 |
|
---|
114 | //currently the only flag is R1_SOFTWARE
|
---|
115 | w32 render_device_flags;
|
---|
116 |
|
---|
117 | // returns false if display is not compatible with render_api, i.e. if you pass
|
---|
118 | // the directx display to the glide render api it return false
|
---|
119 | // init will create the texture manager, which can be used after this call
|
---|
120 | // text_mem_size if size of buffer to hold compressed textures (in system memory)
|
---|
121 | virtual i4_bool init(i4_display_class *display);
|
---|
122 |
|
---|
123 | // this will delete the texture manager (and free textures associated with) created by init
|
---|
124 | virtual void uninit();
|
---|
125 |
|
---|
126 | virtual void copy_part(i4_image_class *im,
|
---|
127 | int x, int y, // position on screen
|
---|
128 | int x1, int y1, // area of image to copy
|
---|
129 | int x2, int y2) = 0;
|
---|
130 |
|
---|
131 | public:
|
---|
132 | w32 get_render_device_flags() { return render_device_flags; }
|
---|
133 | r1_shading_type get_shade_mode() { return shade_mode; }
|
---|
134 | r1_alpha_type get_alpha_mode() { return alpha_mode; }
|
---|
135 | r1_write_mask_type get_write_mask() { return write_mask; }
|
---|
136 | w32 get_constant_color() { return const_color; }
|
---|
137 | r1_filter_type get_filter_mode() { return filter_mode; }
|
---|
138 |
|
---|
139 | r1_render_api_class()
|
---|
140 | {
|
---|
141 | tmanager=0;
|
---|
142 | render_device_flags=0;
|
---|
143 | next=first;
|
---|
144 | first=this;
|
---|
145 | }
|
---|
146 |
|
---|
147 | static i4_draw_context_class *context;
|
---|
148 |
|
---|
149 | virtual i4_bool pixel_double() { return i4_F; }
|
---|
150 |
|
---|
151 | r1_texture_manager_class *get_tmanager() { return tmanager; } // created by init()
|
---|
152 |
|
---|
153 | // texture handle is obtained from the texture manager, this is enables texture mapping
|
---|
154 | virtual void use_texture(r1_texture_handle material_ref,
|
---|
155 | sw32 desired_width,
|
---|
156 | w32 frame) = 0;
|
---|
157 |
|
---|
158 | // drawing will the constant color to render with if textures are disabled
|
---|
159 | virtual void disable_texture() = 0;
|
---|
160 |
|
---|
161 | //tints all r g b values (multiplies)
|
---|
162 | virtual r1_color_tint_handle register_color_tint(i4_float r, i4_float g, i4_float b);
|
---|
163 |
|
---|
164 | //calling this with a handle of 0 disables tinting
|
---|
165 | virtual void set_color_tint(r1_color_tint_handle color_tint_handle);
|
---|
166 |
|
---|
167 | // constant color is used by line drawing, and poly draws-if disable_texture
|
---|
168 | virtual void set_constant_color(w32 color) { const_color=color; }
|
---|
169 | virtual void set_shading_mode(r1_shading_type type) { shade_mode=type; }
|
---|
170 | virtual void set_alpha_mode(r1_alpha_type type) { alpha_mode=type; }
|
---|
171 | virtual void set_write_mode(r1_write_mask_type mask) { write_mask=mask; }
|
---|
172 | virtual void set_filter_mode(r1_filter_type type) { filter_mode=type; }
|
---|
173 |
|
---|
174 | // api will scale all z's (or w's) to reflect this range with best percision
|
---|
175 | // near_z must be greater than 0
|
---|
176 | virtual void set_z_range(float near_z, float far_z) = 0;
|
---|
177 | // make sure this updates the following variables:
|
---|
178 | // r1_near_clip_z
|
---|
179 | // r1_far_clip_z
|
---|
180 |
|
---|
181 | virtual void render_poly(int t_verts, r1_vert *verts) = 0;
|
---|
182 | virtual void render_poly(int t_verts, r1_vert *verts, int *vertex_index);
|
---|
183 | virtual void render_poly(int t_verts, r1_vert *verts, w16 *vertex_index);
|
---|
184 |
|
---|
185 | //this had better be a rectangle
|
---|
186 | virtual void render_sprite(r1_vert *verts);
|
---|
187 |
|
---|
188 | virtual void render_pixel(r1_vert *pixel) = 0;
|
---|
189 | virtual void render_lines(int t_lines, r1_vert *verts ) = 0;
|
---|
190 |
|
---|
191 | // color is standard argb, (z should be within range specifed by set_z_range)
|
---|
192 | virtual void clear_area(int x1, int y1, int x2, int y2, w32 color, float z);
|
---|
193 |
|
---|
194 | // creates an image of the same bit depth and palette of screen (for use with put_image)
|
---|
195 | virtual i4_image_class *create_compatible_image(w16 w, w16 h) = 0;
|
---|
196 |
|
---|
197 | // these should be called for an image before drawing to them
|
---|
198 | virtual void lock_image(i4_image_class *im) { ; }
|
---|
199 | virtual void unlock_image(i4_image_class *im) { ; }
|
---|
200 |
|
---|
201 | // this function does clipping (based on context) and calls copy_part
|
---|
202 | virtual void put_image(i4_image_class *im,
|
---|
203 | int x, int y, // position on screen
|
---|
204 | int x1, int y1, // area of image to copy
|
---|
205 | int x2, int y2);
|
---|
206 |
|
---|
207 | virtual r1_vert *clip_poly(sw32 *num_clip_verts, //how many verts in this polygon
|
---|
208 | r1_vert *t_vertices, //pointer to the vertices
|
---|
209 | w16 *indices, //pointer to the indices
|
---|
210 | r1_vert *clip_buf_1, //pointer to clip buffer 1
|
---|
211 | r1_vert *clip_buf_2, //pointer to clip buffer 2
|
---|
212 | w8 flags); //flags to be considered when clipping
|
---|
213 |
|
---|
214 | virtual r1_vert *clip_poly(sw32 *num_clip_verts, //how many verts in this polygon
|
---|
215 | r1_vert *t_vertices, //pointer to the vertices
|
---|
216 | w32 *indices, //pointer to the indices
|
---|
217 | r1_vert *clip_buf_1, //pointer to clip buffer 1
|
---|
218 | r1_vert *clip_buf_2, //pointer to clip buffer 2
|
---|
219 | w8 flags); //flags to be considered when clipping
|
---|
220 |
|
---|
221 | // creates a window that rendering can occur in
|
---|
222 | // visable_w and & h is the area the window takes up on the actual screen
|
---|
223 | // expand type will determine the size you can actually render to
|
---|
224 |
|
---|
225 | virtual r1_render_window_class *create_render_window(int visable_w, int visable_h,
|
---|
226 | r1_expand_type type=R1_COPY_1x1) = 0;
|
---|
227 |
|
---|
228 |
|
---|
229 | virtual i4_bool expand_type_supported(r1_expand_type type)
|
---|
230 | { return (i4_bool)(type==R1_COPY_1x1); }
|
---|
231 |
|
---|
232 | virtual void modify_features(w32 feature_bits, int on) { ; }
|
---|
233 | virtual i4_bool is_feature_on(w32 feature_bits) { return i4_F; }
|
---|
234 |
|
---|
235 | virtual void default_state()
|
---|
236 | {
|
---|
237 | disable_texture();
|
---|
238 | set_constant_color(0xffffff);
|
---|
239 | set_z_range(0.001,10000);
|
---|
240 | set_shading_mode(R1_COLORED_SHADING);
|
---|
241 | set_write_mode(R1_WRITE_COLOR | R1_WRITE_W | R1_COMPARE_W);
|
---|
242 | set_alpha_mode(R1_ALPHA_DISABLED);
|
---|
243 | set_filter_mode(R1_NO_FILTERING);
|
---|
244 | set_color_tint(0);
|
---|
245 |
|
---|
246 | modify_features(R1_ALL_FEATURES, 0); // turn off these other features
|
---|
247 | modify_features(R1_SPANS, 1);
|
---|
248 | modify_features(R1_PERSPECTIVE_CORRECT, 1);
|
---|
249 | }
|
---|
250 |
|
---|
251 | virtual char *name() = 0;
|
---|
252 | };
|
---|
253 |
|
---|
254 | extern r1_render_api_class *r1_render_api_class_instance;
|
---|
255 |
|
---|
256 | r1_render_api_class *r1_create_api(i4_display_class *for_display, char *api_name=0);
|
---|
257 |
|
---|
258 | void r1_destroy_api(r1_render_api_class *render_api);
|
---|
259 |
|
---|
260 | inline i4_float r1_ooz(i4_float z) { return 0.9999/z; }
|
---|
261 |
|
---|
262 | #endif
|
---|