| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 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 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/main/render.h $ |
| 21 | * $Revision: 38 $ |
| 22 | * $Date: 10/21/99 9:29p $ |
| 23 | * $Author: Jeff $ |
| 24 | * |
| 25 | * Header for render.c |
| 26 | * |
| 27 | * $Log: /DescentIII/main/render.h $ |
| 28 | * |
| 29 | * 38 10/21/99 9:29p Jeff |
| 30 | * B.A. Macintosh code merge |
| 31 | * |
| 32 | * 37 8/10/99 11:19p Gwar |
| 33 | * |
| 34 | * 36 4/18/99 5:42a Chris |
| 35 | * Added the FQ_IGNORE_RENDER_THROUGH_PORTALS flag |
| 36 | * |
| 37 | * 35 4/15/99 12:19p Jason |
| 38 | * made mirrors more robust and able to have multiple mirrored faces in |
| 39 | * the same room (as long as they are all on the same plane) |
| 40 | * |
| 41 | * 34 3/31/99 5:15p Matt |
| 42 | * Added checkboxes on the room tab to control rendering of faces based on |
| 43 | * shell flag. |
| 44 | * |
| 45 | * 33 2/17/99 1:05p Jason |
| 46 | * revamped object/face/terrain selection code |
| 47 | * |
| 48 | * 32 2/09/99 12:10p Jason |
| 49 | * rewriting indoor engine |
| 50 | * |
| 51 | * 31 10/16/98 1:54p Kevin |
| 52 | * Changes for Demo Beta 4 |
| 53 | * |
| 54 | * 30 10/12/98 3:01p Jeff |
| 55 | * added vsync_enable global |
| 56 | * |
| 57 | * 29 10/08/98 3:11p Matt |
| 58 | * Constant for all outline modes didn't include sky bit. |
| 59 | * |
| 60 | * 28 10/04/98 2:35p Matt |
| 61 | * Added debug options to limit rendering |
| 62 | * |
| 63 | * 27 10/03/98 11:21p Matt |
| 64 | * Added system to seperately control outline mode for mine, terrain, sky, |
| 65 | * & objects |
| 66 | * |
| 67 | * 26 9/24/98 12:57p Jason |
| 68 | * more state limited optimizations |
| 69 | * |
| 70 | * 25 9/22/98 3:55p Samir |
| 71 | * ifdef out stuff for non-debug version. |
| 72 | * |
| 73 | * 24 8/27/98 5:19p Jason |
| 74 | * added first rev of reflected surfaces |
| 75 | * |
| 76 | * 23 8/19/98 2:19p Jeff |
| 77 | * moved detail globals to a struct |
| 78 | * |
| 79 | * 22 8/18/98 11:38a Jason |
| 80 | * fixed polymodel fog lighting |
| 81 | * |
| 82 | * 21 8/13/98 6:56p Jason |
| 83 | * made objects foggable correctly |
| 84 | * |
| 85 | * 20 6/19/98 6:42p Jason |
| 86 | * made specular mapping a config detail item |
| 87 | * |
| 88 | * 19 5/25/98 3:46p Jason |
| 89 | * added better light glows |
| 90 | * |
| 91 | * 18 5/19/98 12:27p Jason |
| 92 | * cleaned up some 3d stuff |
| 93 | * |
| 94 | * 17 4/30/98 6:46p Jason |
| 95 | * more framerate testing |
| 96 | * |
| 97 | * 16 4/30/98 3:40p Jason |
| 98 | * framerate optimizations |
| 99 | * |
| 100 | * 15 2/03/98 11:43p Matt |
| 101 | * Added defaults for RenderMine() parameters |
| 102 | * |
| 103 | * 14 1/12/98 3:34p Jason |
| 104 | * sped up indoor rendering by clipping faces against portals |
| 105 | * |
| 106 | * 13 1/06/98 1:28p Matt |
| 107 | * Cleaned up interfaces to rendering routines, deleted unused code, etc. |
| 108 | * |
| 109 | * 12 1/02/98 6:40p Matt |
| 110 | * User renderer library (instead of viewport) functions to draw lines and |
| 111 | * to set and read pixels. Also made FindRoomFace() work without |
| 112 | * Render_viewport. |
| 113 | * |
| 114 | * 11 12/29/97 5:44p Samir |
| 115 | * Took out references to grViewport and old 2d library. |
| 116 | * |
| 117 | * 10 12/01/97 4:20p Jason |
| 118 | * shadow and lighting changes |
| 119 | * |
| 120 | * 9 11/04/97 6:25p Matt |
| 121 | * Added code to render all external rooms for editing purposes |
| 122 | * |
| 123 | * 8 9/16/97 5:50p Matt |
| 124 | * Changed conditional for debug code |
| 125 | * |
| 126 | * 7 9/16/97 4:09p Jason |
| 127 | * implemented software zbuffer |
| 128 | * |
| 129 | * 6 9/11/97 3:14p Matt |
| 130 | * Added code to render floating triggers in the editor |
| 131 | * |
| 132 | * 5 9/04/97 5:23p Matt |
| 133 | * |
| 134 | * 4 9/04/97 12:12p Jason |
| 135 | * added lightmap visibility |
| 136 | * |
| 137 | * 3 7/23/97 6:36p Matt |
| 138 | * Changed Outline_mode & Lighting_on to be type bool |
| 139 | * |
| 140 | * 12 6/12/97 1:19p Matt |
| 141 | * Added version of rotate_list that takes list of int point numbers |
| 142 | * |
| 143 | * 11 5/27/97 3:30p Matt |
| 144 | * Added editor button to toggle lighting |
| 145 | * |
| 146 | * 10 5/08/97 7:46p Matt |
| 147 | * Added called_from_terrain parm for RenderMine() |
| 148 | * |
| 149 | * 9 5/07/97 1:30p Jason |
| 150 | * more changes for terrain/mine integration |
| 151 | * |
| 152 | * 8 5/05/97 4:47p Jason |
| 153 | * made terrain and mine rendering work without explicit calls to |
| 154 | * g3_Startframe in their main function calls |
| 155 | * This allows us to integrate mine/terrain engines nicely |
| 156 | * |
| 157 | * 7 4/29/97 5:15p Jason |
| 158 | * added mirrored textures...I don't know if we'll keep them in though |
| 159 | * |
| 160 | * 6 2/26/97 6:00p Matt |
| 161 | * Renamed 3d lib structs for D3 naming convention |
| 162 | * |
| 163 | * $NoKeywords: $ |
| 164 | */ |
| 165 | #ifndef RENDER_H |
| 166 | #define RENDER_H |
| 167 | |
| 168 | #include "3d.h" |
| 169 | |
| 170 | // Variables for debug/test |
| 171 | #if (defined(_DEBUG) || defined(NEWEDITOR) || defined(EDITOR)) |
| 172 | |
| 173 | #define SRF_NO_SHELL 1 // don't render the shell |
| 174 | #define SRF_NO_NON_SHELL 2 // don't render the non-shell |
| 175 | |
| 176 | extern int Render_portals; |
| 177 | extern bool Lighting_on; // If true, draw w/ normal lighting, else draw full brightness |
| 178 | extern uint8_t Outline_mode; // Controls outline drawing. See constants below |
| 179 | extern uint8_t Shell_render_flag; |
| 180 | extern bool Render_floating_triggers; // If true, render the floating triggers |
| 181 | extern bool Outline_lightmaps; |
| 182 | extern bool Use_software_zbuffer; |
| 183 | extern bool Render_all_external_rooms; // If true, draw all the outside rooms |
| 184 | extern bool Render_one_room_only; |
| 185 | extern bool Render_inside_only; |
| 186 | |
| 187 | #else |
| 188 | #define Lighting_on 1 |
| 189 | #define Outline_mode 0 |
| 190 | #endif |
| 191 | extern int16_t use_opengl_1555_format; // DAJ |
| 192 | |
| 193 | #ifndef RELEASE |
| 194 | extern int Mine_depth; |
| 195 | #endif |
| 196 | // Macro for checking Outline mode |
| 197 | #define OUTLINE_ON(flag) ((Outline_mode & (flag + OM_ON)) == (flag + OM_ON)) |
| 198 | |
| 199 | // Constants for outline mode |
| 200 | #define OM_ON 1 |
| 201 | #define OM_MINE 2 |
| 202 | #define OM_TERRAIN 4 |
| 203 | #define OM_OBJECTS 8 |
| 204 | #define OM_SKY 16 |
| 205 | #define OM_ALL (OM_MINE + OM_TERRAIN + OM_OBJECTS + OM_SKY) |
| 206 | |
| 207 | extern float Fog_zone_start, Fog_zone_end; |
| 208 | extern bool DoBumpmaps; |
| 209 | extern bool Render_mirror_for_room; |
| 210 | extern bool Vsync_enabled; |
| 211 | |
| 212 | extern float Room_light_val; |
| 213 | extern int Room_fog_plane_check; |
| 214 | extern float Room_fog_distance; |
| 215 | extern float Room_fog_eye_distance; |
| 216 | extern vector Room_fog_plane, Room_fog_portal_vert; |
| 217 | |
| 218 | struct face; |
| 219 | |
| 220 | struct fog_portal_data { |
| 221 | int16_t roomnum; |
| 222 | float close_dist; |
| 223 | face *close_face; |
| 224 | }; |
| 225 | |
| 226 | extern fog_portal_data Fog_portal_data[]; |
| 227 | |
| 228 | extern int Num_fogged_rooms_this_frame; |
| 229 | |
| 230 | // Sets fogzone start and end points |
| 231 | void SetFogZoneStart(float z); |
| 232 | void SetFogZoneEnd(float z); |
| 233 | |
| 234 | struct room; |
| 235 | |
| 236 | // For sorting our textures in state limited environments |
| 237 | struct state_limited_element { |
| 238 | int facenum; |
| 239 | int sort_key; |
| 240 | }; |
| 241 | |
| 242 | #define MAX_STATE_ELEMENTS 8000 |
| 243 | extern state_limited_element State_elements[MAX_STATE_ELEMENTS]; |
| 244 | |
| 245 | extern g3Point SolidFogPoints[], AlphaFogPoints[]; |
| 246 | |
| 247 | // Takes a face and adds the appropriate vertices for drawing in the fog zone |
| 248 | // Returns number of points in new polygon |
| 249 | // New polygon points are in FogPoints array |
| 250 | int FogBlendFace(g3Point **src, int nv, int *num_solid, int *num_alpha); |
| 251 | |
| 252 | // Draws the mine, starting at a the specified room |
| 253 | // The rendering surface must be set up, and g3_StartFrame() must have been called |
| 254 | // Parameters: viewer_roomnum - what room the viewer is in |
| 255 | // flag_automap - if true, flag segments as visited when rendered |
| 256 | // called_from_terrain - set if calling this routine from the terrain renderer |
| 257 | void RenderMine(int viewer_roomnum, int flag_automap = 0, int called_from_terrain = 0); |
| 258 | |
| 259 | // Finds what room & face is visible at a given screen x & y |
| 260 | // Everything must be set up just like for RenderMineRoom(), and presumably is the same as |
| 261 | // for the last frame rendered (though it doesn't have to be) |
| 262 | // Parameters: x,y - the screen coordinates |
| 263 | // start_roomnum - where to start rendering |
| 264 | // roomnum,facenum - these are filled in with the found values |
| 265 | // if room<0, then an object was found, and the object number is -room-1 |
| 266 | // Returns: 1 if found a room, else 0 |
| 267 | int FindRoomFace(int16_t x, int16_t y, int start_roomnum, int *roomnum, int *facenum); |
| 268 | |
| 269 | // finds what room,face,lumel is visible at a given screen x & y |
| 270 | // Everything must be set up just like for RenderMineRoom(), and presumably is the same as |
| 271 | // for the last frame rendered (though it doesn't have to be) |
| 272 | // Parameters: x,y - the screen coordinates |
| 273 | // start_roomnum - where to start rendering |
| 274 | // roomnum,facenum,lumel_num - these are filled in with the found values |
| 275 | // Returns: 1 if found a room, else 0 |
| 276 | int FindLightmapFace(int16_t x, int16_t y, int start_roomnum, int *roomnum, int *facenum, int *lumel_num); |
| 277 | |
| 278 | // This is needed for small view cameras |
| 279 | // It clears the facing array so that it is recomputed |
| 280 | void ResetFacings(); |
| 281 | |
| 282 | // Renders all the lights glows for this frame |
| 283 | void RenderLightGlows(); |
| 284 | |
| 285 | // Called before a frame starts to render - sets all of our light glows to decreasing |
| 286 | void PreUpdateAllLightGlows(); |
| 287 | |
| 288 | // Called after a frame has been rendered - slowly morphs our light glows into nothing |
| 289 | void PostUpdateAllLightGlows(); |
| 290 | |
| 291 | // Resets our light glows to zero |
| 292 | void ResetLightGlows(); |
| 293 | |
| 294 | // Gets the dynamic light value for this position |
| 295 | void GetRoomDynamicScalar(vector *pos, room *rp, float *r, float *g, float *b); |
| 296 | |
| 297 | // Sorts our texture states using the quicksort algorithm |
| 298 | void SortStates(state_limited_element *state_array, int cellcount); |
| 299 | |
| 300 | // Sets up fog if this room is fogged |
| 301 | void SetupRoomFog(room *rp, vector *eye, matrix *orient, int viewer_room); |
| 302 | |
| 303 | // Draw the specified face |
| 304 | // Parameters: rp - pointer to the room the face is un |
| 305 | // facenum - which face in the specified room |
| 306 | void RenderFace(room *rp, int facenum); |
| 307 | |
| 308 | // Renders a specular face |
| 309 | void RenderSpecularFacesFlat(room *rp); |
| 310 | |
| 311 | // Renders fog faces for a room |
| 312 | void RenderFogFaces(room *rp); |
| 313 | |
| 314 | // Builds a list of mirror faces for each room and allocs memory accordingly |
| 315 | void ConsolidateMineMirrors(); |
| 316 | |
| 317 | extern int Num_specular_faces_to_render, Num_fog_faces_to_render; |
| 318 | |
| 319 | #endif |