]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/queuedraw.cpp
eol style
[xonotic/netradiant.git] / radiant / queuedraw.cpp
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 //\r
23 // Try to sort the faces by texture and make rendering faster\r
24 //\r
25 // Leonardo Zide (leo@lokigames.com)\r
26 //\r
27 \r
28 #include "stdafx.h"\r
29 \r
30 typedef struct\r
31 {\r
32   qtexture_t* texture;\r
33   GPtrArray* faces;\r
34 } windingsort_t;\r
35 \r
36 static windingsort_t* sort;\r
37 static guint32 alloc, len;\r
38 static GPtrArray* notex_faces;\r
39 \r
40 void QueueClear ()\r
41 {\r
42   len = 0;\r
43 \r
44   if (notex_faces == NULL)\r
45     notex_faces = g_ptr_array_new ();\r
46   g_ptr_array_set_size (notex_faces, 0);\r
47 }\r
48 \r
49 void QueueFace (face_t *face)\r
50 {\r
51   guint32 i;\r
52 \r
53   if (face->d_texture->name[0] == '(')\r
54   {\r
55     g_ptr_array_add (notex_faces, face);\r
56     return;\r
57   }\r
58 \r
59   for (i = 0; i < len; i++)\r
60     if (sort[i].texture == face->d_texture)\r
61     {\r
62       g_ptr_array_add (sort[i].faces, face);\r
63       return;\r
64     }\r
65 \r
66   if (len == alloc)\r
67   {\r
68     alloc += 8;\r
69     sort = (windingsort_t*)realloc (sort, alloc*sizeof(windingsort_t));\r
70 \r
71     for (i = len; i < alloc; i++)\r
72       sort[i].faces = g_ptr_array_new ();\r
73   }\r
74   g_ptr_array_set_size (sort[len].faces, 0);\r
75   g_ptr_array_add (sort[len].faces, face);\r
76   sort[len].texture = face->d_texture;\r
77   len++;\r
78 }\r
79 \r
80 void QueueDraw ()\r
81 {\r
82   guint32 i, k;\r
83   face_t *face;\r
84   winding_t *w;\r
85   int j, nDrawMode = g_pParentWnd->GetCamera().draw_mode;\r
86 \r
87   if (notex_faces->len)\r
88   {\r
89     qglDisable (GL_TEXTURE_2D);\r
90 \r
91     for (i = 0; i < notex_faces->len; i++)\r
92     {\r
93       face = (face_t*)notex_faces->pdata[i];\r
94       w = face->face_winding;\r
95 \r
96       qglBegin (GL_POLYGON);\r
97 \r
98       /*\r
99       if (b->patchBrush)\r
100         //++timo FIXME: find a use case for this??\r
101         qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], 0.13);\r
102       else\r
103       */\r
104         qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], face->pShader->getTrans ());\r
105 \r
106       if (g_PrefsDlg.m_bGLLighting)\r
107         qglNormal3fv (face->plane.normal);\r
108 \r
109       for (j = 0; j < w->numpoints; j++)\r
110       {\r
111         if (nDrawMode == cd_texture || nDrawMode == cd_light)\r
112           qglTexCoord2fv( &w->points[j][3] );\r
113         qglVertex3fv(w->points[j]);\r
114       }\r
115 \r
116       qglEnd ();\r
117     }\r
118   }\r
119 \r
120   if (!len)\r
121     return;\r
122 \r
123   if (nDrawMode == cd_texture || nDrawMode == cd_light)\r
124     qglEnable (GL_TEXTURE_2D);\r
125 \r
126   for (k = 0; k < len; k++)\r
127   {\r
128     qglBindTexture (GL_TEXTURE_2D, sort[k].texture->texture_number);\r
129 \r
130     for (i = 0; i < sort[k].faces->len; i++)\r
131     {\r
132       face = (face_t*)sort[k].faces->pdata[i];\r
133       w = face->face_winding;\r
134 \r
135       qglBegin (GL_POLYGON);\r
136       /*\r
137       if (b->patchBrush)\r
138         //++timo FIXME: find a use case for this??\r
139         qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], 0.13);\r
140       else\r
141       */\r
142         qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], face->pShader->getTrans ());\r
143 \r
144       if (g_PrefsDlg.m_bGLLighting)\r
145         qglNormal3fv (face->plane.normal);\r
146 \r
147       for (j = 0; j < w->numpoints; j++)\r
148       {\r
149         if (nDrawMode == cd_texture || nDrawMode == cd_light)\r
150           qglTexCoord2fv( &w->points[j][3] );\r
151         qglVertex3fv(w->points[j]);\r
152       }\r
153 \r
154       qglEnd ();\r
155     }\r
156   }\r
157   qglBindTexture (GL_TEXTURE_2D, 0);\r
158 }\r