2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 // Try to sort the faces by texture and make rendering faster
25 // Leonardo Zide (leo@lokigames.com)
36 static windingsort_t* sort;
37 static guint32 alloc, len;
38 static GPtrArray* notex_faces;
44 if (notex_faces == NULL)
45 notex_faces = g_ptr_array_new ();
46 g_ptr_array_set_size (notex_faces, 0);
49 void QueueFace (face_t *face)
53 if (face->d_texture->name[0] == '(')
55 g_ptr_array_add (notex_faces, face);
59 for (i = 0; i < len; i++)
60 if (sort[i].texture == face->d_texture)
62 g_ptr_array_add (sort[i].faces, face);
69 sort = (windingsort_t*)realloc (sort, alloc*sizeof(windingsort_t));
71 for (i = len; i < alloc; i++)
72 sort[i].faces = g_ptr_array_new ();
74 g_ptr_array_set_size (sort[len].faces, 0);
75 g_ptr_array_add (sort[len].faces, face);
76 sort[len].texture = face->d_texture;
85 int j, nDrawMode = g_pParentWnd->GetCamera().draw_mode;
89 qglDisable (GL_TEXTURE_2D);
91 for (i = 0; i < notex_faces->len; i++)
93 face = (face_t*)notex_faces->pdata[i];
94 w = face->face_winding;
96 qglBegin (GL_POLYGON);
100 //++timo FIXME: find a use case for this??
101 qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], 0.13);
104 qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], face->pShader->getTrans ());
106 if (g_PrefsDlg.m_bGLLighting)
107 qglNormal3fv (face->plane.normal);
109 for (j = 0; j < w->numpoints; j++)
111 if (nDrawMode == cd_texture || nDrawMode == cd_light)
112 qglTexCoord2fv( &w->points[j][3] );
113 qglVertex3fv(w->points[j]);
123 if (nDrawMode == cd_texture || nDrawMode == cd_light)
124 qglEnable (GL_TEXTURE_2D);
126 for (k = 0; k < len; k++)
128 qglBindTexture (GL_TEXTURE_2D, sort[k].texture->texture_number);
130 for (i = 0; i < sort[k].faces->len; i++)
132 face = (face_t*)sort[k].faces->pdata[i];
133 w = face->face_winding;
135 qglBegin (GL_POLYGON);
138 //++timo FIXME: find a use case for this??
139 qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], 0.13);
142 qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], face->pShader->getTrans ());
144 if (g_PrefsDlg.m_bGLLighting)
145 qglNormal3fv (face->plane.normal);
147 for (j = 0; j < w->numpoints; j++)
149 if (nDrawMode == cd_texture || nDrawMode == cd_light)
150 qglTexCoord2fv( &w->points[j][3] );
151 qglVertex3fv(w->points[j]);
157 qglBindTexture (GL_TEXTURE_2D, 0);