]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/queuedraw.cpp
reorganized about dialog code, added updated 1.5.0 .ico
[xonotic/netradiant.git] / radiant / queuedraw.cpp
1 /*
2    Copyright (C) 1999-2007 id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
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.
11
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.
16
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
20  */
21
22 //
23 // Try to sort the faces by texture and make rendering faster
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include "stdafx.h"
29
30 typedef struct
31 {
32         qtexture_t* texture;
33         GPtrArray* faces;
34 } windingsort_t;
35
36 static windingsort_t* sort;
37 static guint32 alloc, len;
38 static GPtrArray* notex_faces;
39
40 void QueueClear(){
41         len = 0;
42
43         if ( notex_faces == NULL ) {
44                 notex_faces = g_ptr_array_new();
45         }
46         g_ptr_array_set_size( notex_faces, 0 );
47 }
48
49 void QueueFace( face_t *face ){
50         guint32 i;
51
52         if ( face->d_texture->name[0] == '(' ) {
53                 g_ptr_array_add( notex_faces, face );
54                 return;
55         }
56
57         for ( i = 0; i < len; i++ )
58                 if ( sort[i].texture == face->d_texture ) {
59                         g_ptr_array_add( sort[i].faces, face );
60                         return;
61                 }
62
63         if ( len == alloc ) {
64                 alloc += 8;
65                 sort = (windingsort_t*)realloc( sort, alloc * sizeof( windingsort_t ) );
66
67                 for ( i = len; i < alloc; i++ )
68                         sort[i].faces = g_ptr_array_new();
69         }
70         g_ptr_array_set_size( sort[len].faces, 0 );
71         g_ptr_array_add( sort[len].faces, face );
72         sort[len].texture = face->d_texture;
73         len++;
74 }
75
76 void QueueDraw(){
77         guint32 i, k;
78         face_t *face;
79         winding_t *w;
80         int j, nDrawMode = g_pParentWnd->GetCamera().draw_mode;
81
82         if ( notex_faces->len ) {
83                 qglDisable( GL_TEXTURE_2D );
84
85                 for ( i = 0; i < notex_faces->len; i++ )
86                 {
87                         face = (face_t*)notex_faces->pdata[i];
88                         w = face->face_winding;
89
90                         qglBegin( GL_POLYGON );
91
92                         /*
93                            if (b->patchBrush)
94                            //++timo FIXME: find a use case for this??
95                            qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], 0.13);
96                            else
97                          */
98                         qglColor4f( face->d_color[0], face->d_color[1], face->d_color[2], face->pShader->getTrans() );
99
100                         if ( g_PrefsDlg.m_bGLLighting ) {
101                                 qglNormal3fv( face->plane.normal );
102                         }
103
104                         for ( j = 0; j < w->numpoints; j++ )
105                         {
106                                 if ( nDrawMode == cd_texture || nDrawMode == cd_light ) {
107                                         qglTexCoord2fv( &w->points[j][3] );
108                                 }
109                                 qglVertex3fv( w->points[j] );
110                         }
111
112                         qglEnd();
113                 }
114         }
115
116         if ( !len ) {
117                 return;
118         }
119
120         if ( nDrawMode == cd_texture || nDrawMode == cd_light ) {
121                 qglEnable( GL_TEXTURE_2D );
122         }
123
124         for ( k = 0; k < len; k++ )
125         {
126                 qglBindTexture( GL_TEXTURE_2D, sort[k].texture->texture_number );
127
128                 for ( i = 0; i < sort[k].faces->len; i++ )
129                 {
130                         face = (face_t*)sort[k].faces->pdata[i];
131                         w = face->face_winding;
132
133                         qglBegin( GL_POLYGON );
134                         /*
135                            if (b->patchBrush)
136                            //++timo FIXME: find a use case for this??
137                            qglColor4f (face->d_color[0], face->d_color[1], face->d_color[2], 0.13);
138                            else
139                          */
140                         qglColor4f( face->d_color[0], face->d_color[1], face->d_color[2], face->pShader->getTrans() );
141
142                         if ( g_PrefsDlg.m_bGLLighting ) {
143                                 qglNormal3fv( face->plane.normal );
144                         }
145
146                         for ( j = 0; j < w->numpoints; j++ )
147                         {
148                                 if ( nDrawMode == cd_texture || nDrawMode == cd_light ) {
149                                         qglTexCoord2fv( &w->points[j][3] );
150                                 }
151                                 qglVertex3fv( w->points[j] );
152                         }
153
154                         qglEnd();
155                 }
156         }
157         qglBindTexture( GL_TEXTURE_2D, 0 );
158 }