doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
glfile.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "dmap.h"
33 
35 
37 {
38  int fcon, bcon;
39 
40  if (!p->onnode)
41  return 0; // outside
42 
43  fcon = p->nodes[0]->opaque;
44  bcon = p->nodes[1]->opaque;
45 
46  // same contents never create a face
47  if (fcon == bcon)
48  return 0;
49 
50  if (!fcon)
51  return 1;
52  if (!bcon)
53  return 2;
54  return 0;
55 }
56 
57 void OutputWinding( idWinding *w, idFile *glview )
58 {
59  static int level = 128;
60  float light;
61  int i;
62 
63  glview->WriteFloatString( "%i\n", w->GetNumPoints() );
64  level += 28;
65  light = (level&255)/255.0;
66  for ( i = 0; i < w->GetNumPoints(); i++ ) {
67  glview->WriteFloatString( "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
68  (*w)[i][0],
69  (*w)[i][1],
70  (*w)[i][2],
71  light,
72  light,
73  light );
74  }
75  glview->WriteFloatString( "\n" );
76 }
77 
78 /*
79 =============
80 OutputPortal
81 =============
82 */
83 void OutputPortal( uPortal_t *p, idFile *glview ) {
84  idWinding *w;
85  int sides;
86 
87  sides = PortalVisibleSides( p );
88  if ( !sides ) {
89  return;
90  }
91 
92  c_glfaces++;
93 
94  w = p->winding;
95 
96  if ( sides == 2 ) { // back side
97  w = w->Reverse();
98  }
99 
100  OutputWinding( w, glview );
101 
102  if ( sides == 2 ) {
103  delete w;
104  }
105 }
106 
107 /*
108 =============
109 WriteGLView_r
110 =============
111 */
112 void WriteGLView_r( node_t *node, idFile *glview )
113 {
114  uPortal_t *p, *nextp;
115 
116  if ( node->planenum != PLANENUM_LEAF )
117  {
118  WriteGLView_r( node->children[0], glview );
119  WriteGLView_r( node->children[1], glview );
120  return;
121  }
122 
123  // write all the portals
124  for ( p = node->portals; p; p = nextp )
125  {
126  if ( p->nodes[0] == node )
127  {
128  OutputPortal( p, glview );
129  nextp = p->next[0];
130  }
131  else {
132  nextp = p->next[1];
133  }
134  }
135 }
136 
137 /*
138 =============
139 WriteGLView
140 =============
141 */
142 void WriteGLView( tree_t *tree, char *source )
143 {
144  idFile *glview;
145 
146  c_glfaces = 0;
147  common->Printf( "Writing %s\n", source );
148 
149  glview = fileSystem->OpenExplicitFileWrite( source );
150  if ( !glview ) {
151  common->Error( "Couldn't open %s", source );
152  }
153  WriteGLView_r( tree->headnode, glview );
154  fileSystem->CloseFile( glview );
155 
156  common->Printf( "%5i c_glfaces\n", c_glfaces );
157 }
158 
node_t * headnode
Definition: dmap.h:173
node_t * nodes[2]
Definition: dmap.h:166
void OutputWinding(idWinding *w, idFile *glview)
Definition: glfile.cpp:57
Definition: dmap.h:172
node_t * onnode
Definition: dmap.h:165
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
void WriteGLView_r(node_t *node, idFile *glview)
Definition: glfile.cpp:112
struct uPortal_s * next[2]
Definition: dmap.h:167
int PortalVisibleSides(uPortal_t *p)
Definition: glfile.cpp:36
idWinding * Reverse(void) const
Definition: Winding.cpp:478
int i
Definition: process.py:33
int planenum
Definition: dmap.h:140
Definition: File.h:50
GLsizei GLsizei GLcharARB * source
Definition: glext.h:3633
int GetNumPoints(void) const
Definition: Winding.h:238
struct node_s * children[2]
Definition: dmap.h:146
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3454
void OutputPortal(uPortal_t *p, idFile *glview)
Definition: glfile.cpp:83
idCommon * common
Definition: Common.cpp:206
struct uPortal_s * portals
Definition: dmap.h:159
virtual int WriteFloatString(const char *fmt,...) id_attribute((format(printf
Definition: File.cpp:294
idWinding * winding
Definition: dmap.h:168
bool opaque
Definition: dmap.h:150
virtual void Printf(const char *fmt,...) id_attribute((format(printf
#define PLANENUM_LEAF
Definition: dmap.h:81
virtual idFile * OpenExplicitFileWrite(const char *OSPath)=0
Definition: dmap.h:138
void WriteGLView(tree_t *tree, char *source)
Definition: glfile.cpp:142
GLint level
Definition: glext.h:2878
virtual void CloseFile(idFile *f)=0
virtual void Error(const char *fmt,...) id_attribute((format(printf
GLfloat GLfloat p
Definition: glext.h:4674
int c_glfaces
Definition: glfile.cpp:34