* Only load needed extensions (ie none.)
[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                 // if possible, add extensions to other platforms too, if this
77                 // rasterizer becomes messy just derive one for each platform 
78                 // (ie. KX_Win32Rasterizer, KX_LinuxRasterizer etc.)
79
80                 glEnableClientState(GL_VERTEX_ARRAY);
81                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
82                 glDisableClientState(GL_NORMAL_ARRAY);
83                 glDisableClientState(GL_COLOR_ARRAY);
84
85                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
86         }
87
88         return result;
89 }
90
91
92
93 void RAS_VAOpenGLRasterizer::SetDrawingMode(int drawingmode)
94 {
95         m_drawingmode = drawingmode;
96
97                 switch (m_drawingmode)
98         {
99         case KX_BOUNDINGBOX:
100                 {
101                 }
102         case KX_WIREFRAME:
103                 {
104                         glDisable (GL_CULL_FACE);
105                         break;
106                 }
107         case KX_TEXTURED:
108                 {
109                 }
110         case KX_SHADED:
111                 {
112                         glEnableClientState(GL_COLOR_ARRAY);
113                 }
114         case KX_SOLID:
115                 {
116                         break;
117                 }
118         default:
119                 {
120                 }
121         }
122 }
123
124
125
126 void RAS_VAOpenGLRasterizer::Exit()
127 {
128         glDisableClientState(GL_VERTEX_ARRAY);
129         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
130         glDisableClientState(GL_COLOR_ARRAY);
131         glDisableClientState(GL_NORMAL_ARRAY);
132         glDisable(GL_COLOR_MATERIAL);
133
134         RAS_OpenGLRasterizer::Exit();
135 }
136
137
138
139 void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays,
140                                                         const vecIndexArrays & indexarrays,
141                                                         int mode,
142                                                         class RAS_IPolyMaterial* polymat,
143                                                         class RAS_IRenderTools* rendertools,
144                                                         bool useObjectColor,
145                                                         const MT_Vector4& rgbacolor)
146 {
147         unsigned char* mypointer=NULL;
148         static const GLsizei vtxstride = sizeof(RAS_TexVert);
149         GLenum drawmode;
150         switch (mode)
151         {
152         case 0:
153                 {
154                 drawmode = GL_TRIANGLES;
155                 break;
156                 }
157         case 2:
158                 {
159                 drawmode = GL_QUADS;
160                 break;
161                 }
162         case 1: //lines
163                 {
164                 }
165         default:
166                 {
167                 drawmode = GL_LINES;
168                 break;
169                 }
170         }
171         const RAS_TexVert* vertexarray;
172         unsigned int numindices, vt;
173         if (drawmode != GL_LINES)
174         {
175                 if (useObjectColor)
176                 {
177                         glDisableClientState(GL_COLOR_ARRAY);
178                         glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
179                 } else
180                 {
181                         glColor4d(0,0,0,1.0);
182                         glEnableClientState(GL_COLOR_ARRAY);
183                 }
184         }
185         else
186         {
187                 glColor3d(0,0,0);
188         }
189         // use glDrawElements to draw each vertexarray
190         for (vt=0;vt<vertexarrays.size();vt++)
191         {
192                 vertexarray = &((*vertexarrays[vt]) [0]);
193                 const KX_IndexArray & indexarray = (*indexarrays[vt]);
194                 numindices = indexarray.size();
195                 int numverts = vertexarrays[vt]->size();
196
197                 if (!numindices)
198                         break;
199                 
200                 glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ());
201                 glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1());
202                 glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,&vertexarray->getRGBA());
203                 glNormalPointer(GL_SHORT,vtxstride,vertexarray->getNormal());
204                 //glLockArraysEXT(0,numverts);
205                 // here the actual drawing takes places
206                 glDrawElements(drawmode,numindices,GL_UNSIGNED_INT,&(indexarray[0]));
207                 //glUnlockArraysEXT();
208         }
209 }
210
211
212 void RAS_VAOpenGLRasterizer::EnableTextures(bool enable)
213 {
214         if (enable)
215                 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
216         else
217                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
218 }
219
220 bool RAS_VAOpenGLRasterizer::Stereo()
221 {
222 /*
223         if(m_stereomode == RAS_STEREO_NOSTEREO)
224                 return false;
225         else
226                 return true;
227 */
228         return false;
229 }
230