Miscellaneous Fixes:
[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                 glDisableClientState(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         glDisable(GL_COLOR_MATERIAL);
129
130         RAS_OpenGLRasterizer::Exit();
131 }
132
133
134
135 void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays,
136                                                         const vecIndexArrays & indexarrays,
137                                                         int mode,
138                                                         class RAS_IPolyMaterial* polymat,
139                                                         class RAS_IRenderTools* rendertools,
140                                                         bool useObjectColor,
141                                                         const MT_Vector4& rgbacolor)
142 {
143         unsigned char* mypointer=NULL;
144         static const GLsizei vtxstride = sizeof(RAS_TexVert);
145         GLenum drawmode;
146         switch (mode)
147         {
148         case 0:
149                 {
150                 drawmode = GL_TRIANGLES;
151                 break;
152                 }
153         case 2:
154                 {
155                 drawmode = GL_QUADS;
156                 break;
157                 }
158         case 1: //lines
159                 {
160                 }
161         default:
162                 {
163                 drawmode = GL_LINES;
164                 break;
165                 }
166         }
167         const RAS_TexVert* vertexarray;
168         unsigned int numindices, vt;
169         if (drawmode != GL_LINES)
170         {
171                 if (useObjectColor)
172                 {
173                         glDisableClientState(GL_COLOR_ARRAY);
174                         glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
175                 } else
176                 {
177                         glColor4d(0,0,0,1.0);
178                         glEnableClientState(GL_COLOR_ARRAY);
179                 }
180         }
181         else
182         {
183                 glColor3d(0,0,0);
184         }
185         // use glDrawElements to draw each vertexarray
186         for (vt=0;vt<vertexarrays.size();vt++)
187         {
188                 vertexarray = &((*vertexarrays[vt]) [0]);
189                 const KX_IndexArray & indexarray = (*indexarrays[vt]);
190                 numindices = indexarray.size();
191                 int numverts = vertexarrays[vt]->size();
192
193                 if (!numindices)
194                         continue;
195                 
196                 glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ());
197                 glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1());
198                 glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,&vertexarray->getRGBA());
199                 glNormalPointer(GL_SHORT,vtxstride,vertexarray->getNormal());
200                 //glLockArraysEXT(0,numverts);
201                 // here the actual drawing takes places
202                 glDrawElements(drawmode,numindices,GL_UNSIGNED_INT,&(indexarray[0]));
203                 //glUnlockArraysEXT();
204         }
205 }
206
207
208 void RAS_VAOpenGLRasterizer::EnableTextures(bool enable)
209 {
210         if (enable)
211                 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
212         else
213                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
214 }
215
216 bool RAS_VAOpenGLRasterizer::Stereo()
217 {
218 /*
219         if(m_stereomode == RAS_STEREO_NOSTEREO)
220                 return false;
221         else
222                 return true;
223 */
224         return false;
225 }
226