Debian Codegraph @

renderer/HardwareBaseGPU.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Descent Developers
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // TODO: This is missing a good way of overriding base behavior (like, you know, method overrides...)
20
21 #include "pserror.h"
22 #include "mono.h"
23 #include "3d.h"
24 #include "renderer.h"
25 #include "bitmap.h"
26 #include "grdefs.h"
27 #include <cstring>
28
29 #include "HardwareInternal.h"
30 #include "lightmap.h"
31
32 // FIXME: Unused
33 // The font characteristics
34 static float rend_FontRed[4], rend_FontBlue[4], rend_FontGreen[4], rend_FontAlpha[4];
35 char Renderer_error_message[256] = "Generic renderer error";
36
37 // The following values are referenced by the game code, but only
38 // UseMultitexture is actually referenced and used in this code - and
39 // even that can probably go away and we just assume there is more than
40 // one texture unit (which, since I believe OpenGL 1.2 is a requirement)
41 bool UseHardware = true;
42 bool NoLightmaps = false;
43 bool StateLimited = false;
44 bool UseMultitexture = false;
45 bool UseWBuffer = false;
46
47 // General renderer states
48 int gpu_Overlay_map = -1;
49 uint8_t gpu_Overlay_type = OT_NONE;
50 uint8_t Renderer_initted = 0;
51
52 // Generic GPU data
53 rendering_state gpu_state;
54 renderer_preferred_state gpu_preferred_state = {0, 1, 1.5};
55
56 int gpu_last_frame_polys_drawn = 0;
57 int gpu_last_frame_verts_processed = 0;
58 int gpu_last_uploaded = 0;
59
60 float gpu_Alpha_factor = 1.0f;
61 float gpu_Alpha_multiplier = 1.0f;
62
63 PosColorUVVertex vArray[100];
64 PosColorUV2Vertex vArray2[100];
65
66 // returns the alpha that we should use
67 float rend_GetAlphaMultiplier() {
68 switch (gpu_state.cur_alpha_type) {
69 case AT_ALWAYS:
70 case AT_TEXTURE:
71 case AT_VERTEX:
72 case AT_TEXTURE_VERTEX:
73 case AT_SATURATE_VERTEX:
74 case AT_SATURATE_TEXTURE_VERTEX:
75 case AT_SPECULAR:
76 return 1.0;
77 case AT_CONSTANT:
78 case AT_CONSTANT_TEXTURE:
79 case AT_CONSTANT_TEXTURE_VERTEX:
80 case AT_CONSTANT_VERTEX:
81 case AT_LIGHTMAP_BLEND:
82 case AT_LIGHTMAP_BLEND_SATURATE:
83 case AT_SATURATE_TEXTURE:
84 case AT_SATURATE_CONSTANT_VERTEX:
85 return gpu_state.cur_alpha / 255.0;
86 default:
87 // Int3(); // no type defined,get jason
88 return 0;
89 }
90 }
91
92 // Retrieves an error message
93 const char *rend_GetErrorMessage() { return Renderer_error_message; }
94
95 // Sets an error message
96 void rend_SetErrorMessage(const char *str) {
97 ASSERT(strlen(str) < 256);
98 strcpy(Renderer_error_message, str);
99 }
100
101 // FIXME: Unused
102 // Sets the argb characteristics of the font characters. color1 is the upper left and proceeds clockwise
103 void rend_SetCharacterParameters(ddgr_color color1, ddgr_color color2, ddgr_color color3, ddgr_color color4) {
104 rend_FontRed[0] = (float)(GR_COLOR_RED(color1) / 255.0f);
105 rend_FontRed[1] = (float)(GR_COLOR_RED(color2) / 255.0f);
106 rend_FontRed[2] = (float)(GR_COLOR_RED(color3) / 255.0f);
107 rend_FontRed[3] = (float)(GR_COLOR_RED(color4) / 255.0f);
108 rend_FontGreen[0] = (float)(GR_COLOR_GREEN(color1) / 255.0f);
109 rend_FontGreen[1] = (float)(GR_COLOR_GREEN(color2) / 255.0f);
110 rend_FontGreen[2] = (float)(GR_COLOR_GREEN(color3) / 255.0f);
111 rend_FontGreen[3] = (float)(GR_COLOR_GREEN(color4) / 255.0f);
112 rend_FontBlue[0] = (float)(GR_COLOR_BLUE(color1) / 255.0f);
113 rend_FontBlue[1] = (float)(GR_COLOR_BLUE(color2) / 255.0f);
114 rend_FontBlue[2] = (float)(GR_COLOR_BLUE(color3) / 255.0f);
115 rend_FontBlue[3] = (float)(GR_COLOR_BLUE(color4) / 255.0f);
116 rend_FontAlpha[0] = (color1 >> 24) / 255.0f;
117 rend_FontAlpha[1] = (color2 >> 24) / 255.0f;
118 rend_FontAlpha[2] = (color3 >> 24) / 255.0f;
119 rend_FontAlpha[3] = (color4 >> 24) / 255.0f;
120 }
121
122 // Sets where the software renderer should write to
123 void rend_SetSoftwareParameters(float aspect, int width, int height, int pitch, uint8_t *framebuffer) {}
124
125 // Sets the state of bilinear filtering for our textures
126 void rend_SetFiltering(int8_t state) {
127 gpu_state.cur_bilinear_state = state;
128 }
129
130 // Sets the near and far planes for z buffer
131 void rend_SetZValues(float nearz, float farz) {
132 gpu_state.cur_near_z = nearz;
133 gpu_state.cur_far_z = farz;
134 // mprintf(0,"OPENGL:Setting depth range to %f - %f\n",nearz,farz);
135
136 // JEFF: glDepthRange must take parameters [0,1]
137 // It is set in init
138 //@@dglDepthRange (0,farz);
139 }
140
141 // Sets a bitmap as a overlay map to rendered on top of the next texture map
142 // a -1 value indicates no overlay map
143 void rend_SetOverlayMap(int handle) { gpu_Overlay_map = handle; }
144
145 void rend_SetOverlayType(uint8_t type) { gpu_Overlay_type = type; }
146
147
148 void rend_FillCircle(ddgr_color col, int x, int y, int rad) {}
149
150 void rend_DrawCircle(int x, int y, int rad) {}
151
152 // Sets up a font character to draw. We draw our fonts as pieces of textures
153 void rend_DrawFontCharacter(int bm_handle, int x1, int y1, int x2, int y2, float u, float v, float w, float h) {
154 g3Point *ptr_pnts[4];
155 g3Point pnts[4];
156 for (int i = 0; i < 4; i++) {
157 pnts[i].p3_z = 1; // Make REALLY close!
158 pnts[i].p3_flags = PF_PROJECTED;
159 ptr_pnts[i] = &pnts[i];
160 }
161 pnts[0].p3_sx = x1;
162 pnts[0].p3_sy = y1;
163 pnts[0].p3_u = u;
164 pnts[0].p3_v = v;
165 pnts[1].p3_sx = x2;
166 pnts[1].p3_sy = y1;
167 pnts[1].p3_u = u + w;
168 pnts[1].p3_v = v;
169 pnts[2].p3_sx = x2;
170 pnts[2].p3_sy = y2;
171 pnts[2].p3_u = u + w;
172 pnts[2].p3_v = v + h;
173 pnts[3].p3_sx = x1;
174 pnts[3].p3_sy = y2;
175 pnts[3].p3_u = u;
176 pnts[3].p3_v = v + h;
177 rend_DrawPolygon2D(bm_handle, ptr_pnts, 4);
178 }
179
180 // Sets the alpha value for constant alpha
181 void rend_SetAlphaValue(uint8_t val) {
182 gpu_state.cur_alpha = val;
183 gpu_Alpha_multiplier = rend_GetAlphaMultiplier();
184 }
185
186 // Sets the texture wrapping type
187 void rend_SetWrapType(wrap_type val) { gpu_state.cur_wrap_type = val; }
188
189 void rend_SetZBias(float z_bias) {
190 if (Z_bias != z_bias) {
191 Z_bias = z_bias;
192
193 // Force refresh our transforms to take the Zbias into account
194 g3_GetModelViewMatrix(&View_position, &Unscaled_matrix, (float *)gTransformModelView);
195 g3_UpdateFullTransform();
196 g3_ForceTransformRefresh();
197 }
198 }
199
200 // Sets the overall alpha scale factor (all alpha values are scaled by this value)
201 // usefull for motion blur effect
202 void rend_SetAlphaFactor(float val) {
203 if (val < 0.0f)
204 val = 0.0f;
205 if (val > 1.0f)
206 val = 1.0f;
207 gpu_Alpha_factor = val;
208 }
209
210 // Returns the current Alpha factor
211 float rend_GetAlphaFactor(void) { return gpu_Alpha_factor; }
212
213 // Gets a pointer to a linear frame buffer
214 void rend_GetLFBLock(renderer_lfb *lfb) {}
215
216 // Releases an lfb lock
217 void rend_ReleaseLFBLock(renderer_lfb *lfb) {}
218
219 // Returns the aspect ratio of the physical screen
220 void rend_GetProjectionParameters(int *width, int *height) {
221 *width = gpu_state.clip_x2 - gpu_state.clip_x1;
222 *height = gpu_state.clip_y2 - gpu_state.clip_y1;
223 }
224
225 void rend_GetProjectionScreenParameters(int &screenLX, int &screenTY, int &screenW, int &screenH) {
226 screenLX = gpu_state.clip_x1;
227 screenTY = gpu_state.clip_y1;
228 screenW = gpu_state.clip_x2 - gpu_state.clip_x1 + 1;
229 screenH = gpu_state.clip_y2 - gpu_state.clip_y1 + 1;
230 }
231
232 // Returns the aspect ratio of the physical screen
233 float rend_GetAspectRatio(void) {
234 float aspect_ratio = (float)((3.0f * gpu_state.screen_width) / (4.0f * gpu_state.screen_height));
235 return aspect_ratio;
236 }
237
238 // Given a source x,y and width,height, draws any sized bitmap into the renderer lfb
239 void rend_DrawLFBBitmap(int sx, int sy, int w, int h, int dx, int dy, uint16_t *data, int rowsize) {}
240
241 // draws a scaled 2d bitmap to our buffer
242 void rend_DrawScaledBitmap(int x1, int y1, int x2, int y2, int bm, float u0, float v0, float u1, float v1, int color,
243 float *alphas) {
244 g3Point *ptr_pnts[4];
245 g3Point pnts[4];
246 float r, g, b;
247 if (color != -1) {
248 r = GR_COLOR_RED(color) / 255.0;
249 g = GR_COLOR_GREEN(color) / 255.0;
250 b = GR_COLOR_BLUE(color) / 255.0;
251 }
252 for (int i = 0; i < 4; i++) {
253 if (color == -1)
254 pnts[i].p3_l = 1.0;
255 else {
256 pnts[i].p3_r = r;
257 pnts[i].p3_g = g;
258 pnts[i].p3_b = b;
259 }
260 if (alphas) {
261 pnts[i].p3_a = alphas[i];
262 }
263
264 pnts[i].p3_z = 1.0f;
265 pnts[i].p3_flags = PF_PROJECTED;
266 }
267
268 pnts[0].p3_sx = x1;
269 pnts[0].p3_sy = y1;
270 pnts[0].p3_u = u0;
271 pnts[0].p3_v = v0;
272 pnts[1].p3_sx = x2;
273 pnts[1].p3_sy = y1;
274 pnts[1].p3_u = u1;
275 pnts[1].p3_v = v0;
276 pnts[2].p3_sx = x2;
277 pnts[2].p3_sy = y2;
278 pnts[2].p3_u = u1;
279 pnts[2].p3_v = v1;
280 pnts[3].p3_sx = x1;
281 pnts[3].p3_sy = y2;
282 pnts[3].p3_u = u0;
283 pnts[3].p3_v = v1;
284 ptr_pnts[0] = &pnts[0];
285 ptr_pnts[1] = &pnts[1];
286 ptr_pnts[2] = &pnts[2];
287 ptr_pnts[3] = &pnts[3];
288 rend_SetTextureType(TT_LINEAR);
289 rend_DrawPolygon2D(bm, ptr_pnts, 4);
290 }
291
292 // given a chunked bitmap, renders it.
293 void rend_DrawChunkedBitmap(chunked_bitmap *chunk, int x, int y, uint8_t alpha) {
294 int *bm_array = chunk->bm_array;
295 int w = chunk->w;
296 int h = chunk->h;
297 int piece_w = bm_w(bm_array[0], 0);
298 int piece_h = bm_h(bm_array[0], 0);
299 int screen_w, screen_h;
300 int i, t;
301 rend_SetZBufferState(0);
302 rend_GetProjectionParameters(&screen_w, &screen_h);
303 for (i = 0; i < h; i++) {
304 for (t = 0; t < w; t++) {
305 int dx = x + (piece_w * t);
306 int dy = y + (piece_h * i);
307 int dw, dh;
308 if ((dx + piece_w) > screen_w)
309 dw = piece_w - ((dx + piece_w) - screen_w);
310 else
311 dw = piece_w;
312 if ((dy + piece_h) > screen_h)
313 dh = piece_h - ((dy + piece_h) - screen_h);
314 else
315 dh = piece_h;
316
317 float u2 = (float)dw / (float)piece_w;
318 float v2 = (float)dh / (float)piece_h;
319 rend_DrawSimpleBitmap(bm_array[i * w + t], dx, dy);
320 }
321 }
322 rend_SetZBufferState(1);
323 }
324
325 // given a chunked bitmap, renders it.scaled
326 void rend_DrawScaledChunkedBitmap(chunked_bitmap *chunk, int x, int y, int neww, int newh, uint8_t alpha) {
327 int *bm_array = chunk->bm_array;
328 int w = chunk->w;
329 int h = chunk->h;
330 int piece_w;
331 int piece_h;
332 int screen_w, screen_h;
333 int i, t;
334
335 float scalew, scaleh;
336
337 scalew = ((float)neww) / ((float)chunk->pw);
338 scaleh = ((float)newh) / ((float)chunk->ph);
339 piece_w = scalew * ((float)bm_w(bm_array[0], 0));
340 piece_h = scaleh * ((float)bm_h(bm_array[0], 0));
341 rend_GetProjectionParameters(&screen_w, &screen_h);
342 rend_SetOverlayType(OT_NONE);
343 rend_SetLighting(LS_NONE);
344 rend_SetColorModel(CM_MONO);
345 rend_SetZBufferState(0);
346 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
347 rend_SetAlphaValue(alpha);
348 rend_SetWrapType(WT_WRAP);
349 for (i = 0; i < h; i++) {
350 for (t = 0; t < w; t++) {
351 int dx = x + (piece_w * t);
352 int dy = y + (piece_h * i);
353 int dw, dh;
354 if ((dx + piece_w) > screen_w)
355 dw = piece_w - ((dx + piece_w) - screen_w);
356 else
357 dw = piece_w;
358 if ((dy + piece_h) > screen_h)
359 dh = piece_h - ((dy + piece_h) - screen_h);
360 else
361 dh = piece_h;
362
363 float u2 = (float)dw / (float)piece_w;
364 float v2 = (float)dh / (float)piece_h;
365 rend_DrawScaledBitmap(dx, dy, dx + dw, dy + dh, bm_array[i * w + t], 0, 0, u2, v2);
366 }
367 }
368 rend_SetZBufferState(1);
369 }
370
371 // Sets some global preferences for the renderer
372 int rend_SetPreferredState(renderer_preferred_state *pref_state) {
373 int retval = 1;
374 renderer_preferred_state old_state = gpu_preferred_state;
375
376 gpu_preferred_state = *pref_state;
377 if (gpu_state.initted) {
378 int reinit = 0;
379 mprintf(0, "Inside pref state!\n");
380
381 // Change gamma if needed
382 if (pref_state->width != gpu_state.screen_width || pref_state->height != gpu_state.screen_height ||
383 old_state.bit_depth != pref_state->bit_depth) {
384 reinit = 1;
385 }
386
387 if (reinit) {
388 retval = rend_ReInit();
389 } else {
390 if (old_state.gamma != pref_state->gamma) {
391 rend_SetGammaValue(pref_state->gamma);
392 }
393 }
394 } else {
395 gpu_preferred_state = *pref_state;
396 }
397
398 return retval;
399 }
400
401 // Draws a simple bitmap at the specified x,y location
402 void rend_DrawSimpleBitmap(int bm_handle, int x, int y) {
403 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
404 rend_SetAlphaValue(255);
405 rend_SetLighting(LS_NONE);
406 rend_SetColorModel(CM_MONO);
407 rend_SetOverlayType(OT_NONE);
408 rend_SetFiltering(0);
409 rend_DrawScaledBitmap(x, y, x + bm_w(bm_handle, 0), y + bm_h(bm_handle, 0), bm_handle, 0, 0, 1, 1);
410 rend_SetFiltering(1);
411 }
412
413 // Fills in the passed in pointer with the current rendering state
414 void rend_GetRenderState(rendering_state *rstate) { memcpy(rstate, &gpu_state, sizeof(rendering_state)); }
415
416 // Preuploads a texture to the video card
417 void rend_PreUploadTextureToCard(int handle, int map_type) {}
418
419 // Frees an uploaded texture from the video card
420 void rend_FreePreUploadedTexture(int handle, int map_type) {}
421
422 // Returns 1 if there is mid video memory, 2 if there is low vid memory, or 0 if there is large vid memory
423 int rend_LowVidMem(void) { return 0; }
424
425 // Returns 1 if the renderer supports bumpmapping
426 int rend_SupportsBumpmapping(void) { return 0; }
427
428 // Sets a bumpmap to be rendered, or turns off bumpmapping altogether
429 void rend_SetBumpmapReadyState(int state, int map) {}
430
431 // returns rendering statistics for the frame
432 void rend_GetStatistics(tRendererStats *stats) {
433 if (Renderer_initted) {
434 stats->poly_count = gpu_last_frame_polys_drawn;
435 stats->vert_count = gpu_last_frame_verts_processed;
436 stats->texture_uploads = gpu_last_uploaded;
437 } else {
438 memset(stats, 0, sizeof(tRendererStats));
439 }
440 }
441
442 #ifdef DEDICATED_ONLY
443
444 void rend_DrawPolygon2D(int, g3Point **, int, int) {}
445 void rend_DrawPolygon3D(int, g3Point **, int, int) {}
446
447 #else
448
449 // Takes nv vertices and draws the 2D polygon defined by those vertices.
450 // Uses bitmap "handle" as a texture
451 void rend_DrawPolygon2D(int handle, g3Point **p, int nv) {
452 ASSERT(nv < 100);
453 ASSERT(gpu_Overlay_type == OT_NONE);
454
455 g3_RefreshTransforms(true);
456
457 if (UseMultitexture) {
458 gpu_SetMultitextureBlendMode(false);
459 }
460
461 int xAdd = gpu_state.clip_x1;
462 int yAdd = gpu_state.clip_y1;
463
464 float fr, fg, fb;
465 if (gpu_state.cur_light_state == LS_FLAT_GOURAUD || gpu_state.cur_texture_quality == 0) {
466 float scale = 1.0f / 255.0f;
467 fr = GR_COLOR_RED(gpu_state.cur_color) * scale;
468 fg = GR_COLOR_GREEN(gpu_state.cur_color) * scale;
469 fb = GR_COLOR_BLUE(gpu_state.cur_color) * scale;
470 }
471
472 // make sure our bitmap is ready to be drawn
473 gpu_BindTexture(handle, MAP_TYPE_BITMAP, 0);
474
475 float alpha = gpu_Alpha_multiplier * gpu_Alpha_factor;
476
477 PosColorUVVertex *vData = &vArray[0];
478
479 // Specify our coordinates
480 int i;
481 for (i = 0; i < nv; ++i, ++vData) {
482 g3Point *pnt = p[i];
483
484 if (gpu_state.cur_alpha_type & ATF_VERTEX) {
485 // the alpha should come from the vertex
486 alpha = pnt->p3_a * gpu_Alpha_multiplier * gpu_Alpha_factor;
487 }
488
489 // If we have a lighting model, apply the correct lighting!
490 if (gpu_state.cur_light_state == LS_FLAT_GOURAUD || gpu_state.cur_texture_quality == 0) {
491 // pull the color from the constant color data
492 vData->color.r = fr;
493 vData->color.g = fg;
494 vData->color.b = fb;
495 vData->color.a = alpha;
496 } else if (gpu_state.cur_light_state != LS_NONE) {
497 // Do lighting based on intensity (MONO) or colored (RGB)
498 if (gpu_state.cur_color_model == CM_MONO) {
499 vData->color.r = pnt->p3_l;
500 vData->color.g = pnt->p3_l;
501 vData->color.b = pnt->p3_l;
502 vData->color.a = alpha;
503 } else {
504 vData->color.r = pnt->p3_r;
505 vData->color.g = pnt->p3_g;
506 vData->color.b = pnt->p3_b;
507 vData->color.a = alpha;
508 }
509 } else {
510 // force white
511 vData->color.r = 1.0f;
512 vData->color.g = 1.0f;
513 vData->color.b = 1.0f;
514 vData->color.a = alpha;
515 }
516
517 vData->uv.s = pnt->p3_u;
518 vData->uv.t = pnt->p3_v;
519 vData->uv.r = 0.0f;
520 vData->uv.w = 1.0f;
521
522 // Finally, specify a vertex
523 vData->pos.x = pnt->p3_sx + xAdd;
524 vData->pos.y = pnt->p3_sy + yAdd;
525 vData->pos.z = 0.0f;
526 }
527
528 gpu_RenderPolygon(&vArray[0], nv);
529 }
530
531
532 // Takes nv vertices and draws the 3D polygon defined by those vertices.
533 // Uses bitmap "handle" as a texture
534 void rend_DrawPolygon3D(int handle, g3Point **p, int nv, int map_type) {
535 g3Point *pnt;
536 int i;
537 float fr, fg, fb;
538 float alpha;
539
540 ASSERT(nv < 100);
541
542 g3_RefreshTransforms(false);
543
544 if (gpu_state.cur_texture_quality == 0) {
545 gpu_DrawFlatPolygon3D(p, nv);
546 return;
547 }
548
549 if (gpu_Overlay_type != OT_NONE && UseMultitexture) {
550 rend_DrawMultitexturePolygon3D(handle, p, nv, map_type);
551 return;
552 }
553
554 if (gpu_state.cur_light_state == LS_FLAT_GOURAUD) {
555 fr = GR_COLOR_RED(gpu_state.cur_color) / 255.0;
556 fg = GR_COLOR_GREEN(gpu_state.cur_color) / 255.0;
557 fb = GR_COLOR_BLUE(gpu_state.cur_color) / 255.0;
558 }
559
560 if (UseMultitexture) {
561 gpu_SetMultitextureBlendMode(false);
562 }
563
564 gpu_BindTexture(handle, map_type, 0);
565
566 alpha = gpu_Alpha_multiplier * gpu_Alpha_factor;
567
568 PosColorUVVertex *vData = &vArray[0];
569
570 // Specify our coordinates
571 for (i = 0; i < nv; i++, vData++) {
572 pnt = p[i];
573
574 // all points should be original
575 ASSERT(pnt->p3_flags & PF_ORIGPOINT);
576
577 ////////////////////////////////////////////
578 if (pnt->p3_flags & PF_ORIGPOINT) {
579 if (!(pnt->p3_flags & PF_PROJECTED)) {
580 g3_ProjectPoint(pnt);
581 }
582
583 // get the original point
584 float origPoint[4];
585 origPoint[0] = pnt->p3_vecPreRot.x;
586 origPoint[1] = pnt->p3_vecPreRot.y;
587 origPoint[2] = pnt->p3_vecPreRot.z;
588 origPoint[3] = 1.0f;
589
590 // transform by the full transform
591 float view[4];
592 g3_TransformVert(view, origPoint, gTransformFull);
593
594 vector tempv = pnt->p3_vecPreRot - View_position;
595 vector testPt = tempv * Unscaled_matrix;
596
597 float screenX = pnt->p3_sx + gpu_state.clip_x1;
598 float screenY = pnt->p3_sy + gpu_state.clip_y1;
599
600 // normalize
601 float oOW = 1.0f / view[3];
602 view[0] *= oOW;
603 view[1] *= oOW;
604 view[2] *= oOW;
605
606 oOW *= 1.0f;
607 }
608 ////////////////////////////////////////////
609
610 if (gpu_state.cur_alpha_type & ATF_VERTEX) {
611 alpha = pnt->p3_a * gpu_Alpha_multiplier * gpu_Alpha_factor;
612 }
613
614 // If we have a lighting model, apply the correct lighting!
615 if (gpu_state.cur_light_state != LS_NONE) {
616 if (gpu_state.cur_light_state == LS_FLAT_GOURAUD) {
617 vData->color.r = fr;
618 vData->color.g = fg;
619 vData->color.b = fb;
620 vData->color.a = alpha;
621 } else {
622 // Do lighting based on intesity (MONO) or colored (RGB)
623 if (gpu_state.cur_color_model == CM_MONO) {
624 vData->color.r = pnt->p3_l;
625 vData->color.g = pnt->p3_l;
626 vData->color.b = pnt->p3_l;
627 vData->color.a = alpha;
628 } else {
629 vData->color.r = pnt->p3_r;
630 vData->color.g = pnt->p3_g;
631 vData->color.b = pnt->p3_b;
632 vData->color.a = alpha;
633 }
634 }
635 } else {
636 vData->color.r = 1;
637 vData->color.g = 1;
638 vData->color.b = 1;
639 vData->color.a = alpha;
640 }
641
642 vData->uv.s = pnt->p3_u;
643 vData->uv.t = pnt->p3_v;
644 vData->uv.r = 0.0f;
645 vData->uv.w = 1.0f;
646
647 // Finally, specify a vertex
648 vData->pos = pnt->p3_vecPreRot;
649 }
650
651 // And draw!
652 gpu_RenderPolygon(&vArray[0], nv);
653
654 // If there is a lightmap to draw, draw it as well
655 if (gpu_Overlay_type != OT_NONE) {
656 return; // Temp fix until I figure out whats going on
657 Int3(); // Shouldn't reach here
658 }
659 }
660
661 #endif // DEDICATED_ONLY
662
663 // Takes nv vertices and draws the polygon defined by those vertices. Uses bitmap "handle"
664 // as a texture
665 void rend_DrawMultitexturePolygon3D(int handle, g3Point **p, int nv, int map_type) {
666 g3Point *pnt;
667 int i, fr, fg, fb;
668 float alpha;
669
670 float one_over_square_res = 1.0 / GameLightmaps[gpu_Overlay_map].square_res;
671 float xscalar = (float)GameLightmaps[gpu_Overlay_map].width * one_over_square_res;
672 float yscalar = (float)GameLightmaps[gpu_Overlay_map].height * one_over_square_res;
673
674 ASSERT(nv < 100);
675
676 if (gpu_state.cur_light_state == LS_NONE) {
677 fr = GR_COLOR_RED(gpu_state.cur_color);
678 fg = GR_COLOR_GREEN(gpu_state.cur_color);
679 fb = GR_COLOR_BLUE(gpu_state.cur_color);
680 }
681
682 alpha = gpu_Alpha_multiplier * gpu_Alpha_factor;
683
684 PosColorUV2Vertex *vData = &vArray2[0];
685
686 // Specify our coordinates
687 for (i = 0; i < nv; i++, vData++) {
688 pnt = p[i];
689 ASSERT(pnt->p3_flags & PF_ORIGPOINT);
690
691 if (gpu_state.cur_alpha_type & ATF_VERTEX)
692 alpha = pnt->p3_a * gpu_Alpha_multiplier * gpu_Alpha_factor;
693
694 // If we have a lighting model, apply the correct lighting!
695 if (gpu_state.cur_light_state != LS_NONE) {
696 // Do lighting based on intesity (MONO) or colored (RGB)
697 if (gpu_state.cur_color_model == CM_MONO) {
698 vData->color.r = pnt->p3_l;
699 vData->color.g = pnt->p3_l;
700 vData->color.b = pnt->p3_l;
701 vData->color.a = alpha;
702 } else {
703 vData->color.r = pnt->p3_r;
704 vData->color.g = pnt->p3_g;
705 vData->color.b = pnt->p3_b;
706 vData->color.a = alpha;
707 }
708 } else {
709 vData->color.r = 1;
710 vData->color.g = 1;
711 vData->color.b = 1;
712 vData->color.a = alpha;
713 }
714
715 /*
716 // Texture this polygon!
717 float texw=1.0/(pnt->p3_z+Z_bias);
718 vData->uv0.s=pnt->p3_u*texw;
719 vData->uv0.t=pnt->p3_v*texw;
720 vData->uv0.r=0;
721 vData->uv0.w=texw;
722
723 vData->uv1.s=pnt->p3_u2*xscalar*texw;
724 vData->uv1.t=pnt->p3_v2*yscalar*texw;
725 vData->uv1.r=0;
726 vData->uv1.w=texw;
727 */
728 vData->uv0.s = pnt->p3_u;
729 vData->uv0.t = pnt->p3_v;
730 vData->uv0.r = 0.0f;
731 vData->uv0.w = 1.0f;
732
733 vData->uv1.s = pnt->p3_u2 * xscalar;
734 vData->uv1.t = pnt->p3_v2 * yscalar;
735 vData->uv1.r = 0.0f;
736 vData->uv1.w = 1.0f;
737
738 // Finally, specify a vertex
739 /*
740 vData->pos.x=pnt->p3_sx+x_add;
741 vData->pos.y=pnt->p3_sy+y_add;
742 vData->pos.z = -std::max(0,std::min(1.0,1.0-(1.0/(pnt->p3_z+Z_bias))));
743 */
744 vData->pos = pnt->p3_vecPreRot;
745 }
746
747 // make sure our bitmap is ready to be drawn
748 gpu_BindTexture(handle, map_type, 0);
749
750 // make sure our bitmap is ready to be drawn
751 gpu_BindTexture(gpu_Overlay_map, MAP_TYPE_LIGHTMAP, 1);
752
753 gpu_SetMultitextureBlendMode(true);
754
755 gpu_RenderPolygonUV2(&vArray2[0], nv);
756 }