More warning cleanups...
[blender.git] / source / gameengine / Rasterizer / RAS_OpenGLRasterizer / RAS_VAOpenGLRasterizer.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30  */
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34
35 #include "RAS_VAOpenGLRasterizer.h"
36
37 #ifdef WIN32
38 #include <windows.h>
39 #endif // WIN32
40 #ifdef __APPLE__
41 #include <OpenGL/gl.h>
42 #else
43 #include <GL/gl.h>
44 #endif
45
46 #include "STR_String.h"
47 #include "RAS_TexVert.h"
48 #include "MT_CmMatrix4x4.h"
49 #include "RAS_IRenderTools.h" // rendering text
50
51 #include "RAS_GLExtensionManager.h"
52         
53
54 using namespace bgl;
55
56 RAS_VAOpenGLRasterizer::RAS_VAOpenGLRasterizer(RAS_ICanvas* canvas)
57 :RAS_OpenGLRasterizer(canvas)
58 {
59 }
60
61
62
63 RAS_VAOpenGLRasterizer::~RAS_VAOpenGLRasterizer()
64 {
65 }
66
67
68
69 bool RAS_VAOpenGLRasterizer::Init(void)
70 {
71         
72         bool result = RAS_OpenGLRasterizer::Init();
73         
74         if (result)
75         {
76                 glEnableClientState(GL_VERTEX_ARRAY);
77                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
78                 glEnableClientState(GL_NORMAL_ARRAY);
79                 glDisableClientState(GL_COLOR_ARRAY);
80
81                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
82         }
83
84         return result;
85 }
86
87
88
89 void RAS_VAOpenGLRasterizer::SetDrawingMode(int drawingmode)
90 {
91         m_drawingmode = drawingmode;
92
93                 switch (m_drawingmode)
94         {
95         case KX_BOUNDINGBOX:
96                 {
97                 }
98         case KX_WIREFRAME:
99                 {
100                         glDisable (GL_CULL_FACE);
101                         break;
102                 }
103         case KX_TEXTURED:
104                 {
105                 }
106         case KX_SHADED:
107                 {
108                         glEnableClientState(GL_COLOR_ARRAY);
109                 }
110         case KX_SOLID:
111                 {
112                         break;
113                 }
114         default:
115                 {
116                 }
117         }
118 }
119
120
121
122 void RAS_VAOpenGLRasterizer::Exit()
123 {
124         glDisableClientState(GL_VERTEX_ARRAY);
125         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
126         glDisableClientState(GL_COLOR_ARRAY);
127         glDisableClientState(GL_NORMAL_ARRAY);
128
129         RAS_OpenGLRasterizer::Exit();
130 }
131
132
133
134 void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays,
135                                                         const vecIndexArrays & indexarrays,
136                                                         int mode,
137                                                         class RAS_IPolyMaterial* polymat,
138                                                         class RAS_IRenderTools* rendertools,
139                                                         bool useObjectColor,
140                                                         const MT_Vector4& rgbacolor)
141 {
142         static const GLsizei vtxstride = sizeof(RAS_TexVert);
143         GLenum drawmode;
144         switch (mode)
145         {
146         case 0:
147                 {
148                 drawmode = GL_TRIANGLES;
149                 break;
150                 }
151         case 2:
152                 {
153                 drawmode = GL_QUADS;
154                 break;
155                 }
156         case 1: //lines
157                 {
158                 }
159         default:
160                 {
161                 drawmode = GL_LINES;
162                 break;
163                 }
164         }
165         const RAS_TexVert* vertexarray;
166         unsigned int numindices, vt;
167         if (drawmode != GL_LINES)
168         {
169                 if (useObjectColor)
170                 {
171                         glDisableClientState(GL_COLOR_ARRAY);
172                         glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
173                 } else
174                 {
175                         glColor4d(0,0,0,1.0);
176                         glEnableClientState(GL_COLOR_ARRAY);
177                 }
178         }
179         else
180         {
181                 glColor3d(0,0,0);
182         }
183         // use glDrawElements to draw each vertexarray
184         for (vt=0;vt<vertexarrays.size();vt++)
185         {
186                 vertexarray = &((*vertexarrays[vt]) [0]);
187                 const KX_IndexArray & indexarray = (*indexarrays[vt]);
188                 numindices = indexarray.size();
189                 // int numverts = vertexarrays[vt]->size();
190
191                 if (!numindices)
192                         continue;
193                 
194                 glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ());
195                 glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1());
196                 glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA());
197                 glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal());
198                 //glLockArraysEXT(0,numverts);
199                 // here the actual drawing takes places
200                 glDrawElements(drawmode,numindices,GL_UNSIGNED_SHORT,&(indexarray[0]));
201                 //glUnlockArraysEXT();
202         }
203 }
204
205
206 void RAS_VAOpenGLRasterizer::EnableTextures(bool enable)
207 {
208         if (enable)
209                 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
210         else
211                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
212 }
213