Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / source / blender / gpu / intern / gpu_draw.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. The Blender
8  * Foundation also sells licenses for use in proprietary software under
9  * the Blender License.  See http://www.blender.org/BL/ for information
10  * about this.
11  *
12  * This program 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 this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The Original Code is Copyright (C) 2005 Blender Foundation.
22  * All rights reserved.
23  *
24  * The Original Code is: all of this file.
25  *
26  * Contributor(s): Brecht Van Lommel.
27  *
28  * ***** END GPL LICENSE BLOCK *****
29  */
30
31 /** \file blender/gpu/intern/gpu_draw.c
32  *  \ingroup gpu
33  */
34
35
36 #include <string.h>
37
38 #include "GL/glew.h"
39
40 #include "BLI_math.h"
41 #include "BLI_utildefines.h"
42
43 #include "DNA_lamp_types.h"
44 #include "DNA_material_types.h"
45 #include "DNA_meshdata_types.h"
46 #include "DNA_modifier_types.h"
47 #include "DNA_node_types.h"
48 #include "DNA_object_types.h"
49 #include "DNA_scene_types.h"
50 #include "DNA_smoke_types.h"
51 #include "DNA_view3d_types.h"
52
53 #include "MEM_guardedalloc.h"
54
55 #include "IMB_imbuf.h"
56 #include "IMB_imbuf_types.h"
57
58 #include "BKE_bmfont.h"
59 #include "BKE_global.h"
60 #include "BKE_image.h"
61 #include "BKE_main.h"
62 #include "BKE_material.h"
63 #include "BKE_node.h"
64 #include "BKE_object.h"
65 #include "BKE_scene.h"
66
67 #include "BLI_threads.h"
68 #include "BLI_blenlib.h"
69
70 #include "GPU_buffers.h"
71 #include "GPU_draw.h"
72 #include "GPU_extensions.h"
73 #include "GPU_material.h"
74
75 #include "smoke_API.h"
76
77 extern Material defmaterial; /* from material.c */
78
79 /* These are some obscure rendering functions shared between the
80  * game engine and the blender, in this module to avoid duplicaten
81  * and abstract them away from the rest a bit */
82
83 /* Text Rendering */
84
85 static void gpu_mcol(unsigned int ucol)
86 {
87         /* mcol order is swapped */
88         char *cp= (char *)&ucol;
89         glColor3ub(cp[3], cp[2], cp[1]);
90 }
91
92 void GPU_render_text(MTFace *tface, int mode,
93         const char *textstr, int textlen, unsigned int *col,
94         float *v1, float *v2, float *v3, float *v4, int glattrib)
95 {
96         if ((mode & GEMAT_TEXT) && (textlen>0) && tface->tpage) {
97                 Image* ima = (Image*)tface->tpage;
98                 int index, character;
99                 float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance;
100                 float advance_tab;
101                 
102                 /* multiline */
103                 float line_start= 0.0f, line_height;
104                 
105                 if (v4)
106                         line_height= MAX4(v1[1], v2[1], v3[1], v4[2]) - MIN4(v1[1], v2[1], v3[1], v4[2]);
107                 else
108                         line_height= MAX3(v1[1], v2[1], v3[1]) - MIN3(v1[1], v2[1], v3[1]);
109                 line_height *= 1.2f; /* could be an option? */
110                 /* end multiline */
111
112                 
113                 /* color has been set */
114                 if (tface->mode & TF_OBCOL)
115                         col= NULL;
116                 else if (!col)
117                         glColor3f(1.0f, 1.0f, 1.0f);
118
119                 glPushMatrix();
120                 
121                 /* get the tab width */
122                 matrixGlyph((ImBuf *)ima->ibufs.first, ' ', & centerx, &centery,
123                         &sizex, &sizey, &transx, &transy, &movex, &movey, &advance);
124                 
125                 advance_tab= advance * 4; /* tab width could also be an option */
126                 
127                 
128                 for (index = 0; index < textlen; index++) {
129                         float uv[4][2];
130
131                         // lets calculate offset stuff
132                         character = textstr[index];
133                         
134                         if (character=='\n') {
135                                 glTranslatef(line_start, -line_height, 0.0);
136                                 line_start = 0.0f;
137                                 continue;
138                         }
139                         else if (character=='\t') {
140                                 glTranslatef(advance_tab, 0.0, 0.0);
141                                 line_start -= advance_tab; /* so we can go back to the start of the line */
142                                 continue;
143                                 
144                         }
145                         
146                         // space starts at offset 1
147                         // character = character - ' ' + 1;
148                         matrixGlyph((ImBuf *)ima->ibufs.first, character, & centerx, &centery,
149                                 &sizex, &sizey, &transx, &transy, &movex, &movey, &advance);
150
151                         uv[0][0] = (tface->uv[0][0] - centerx) * sizex + transx;
152                         uv[0][1] = (tface->uv[0][1] - centery) * sizey + transy;
153                         uv[1][0] = (tface->uv[1][0] - centerx) * sizex + transx;
154                         uv[1][1] = (tface->uv[1][1] - centery) * sizey + transy;
155                         uv[2][0] = (tface->uv[2][0] - centerx) * sizex + transx;
156                         uv[2][1] = (tface->uv[2][1] - centery) * sizey + transy;
157                         
158                         glBegin(GL_POLYGON);
159                         if(glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[0]);
160                         else glTexCoord2fv(uv[0]);
161                         if(col) gpu_mcol(col[0]);
162                         glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]);
163                         
164                         if(glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[1]);
165                         else glTexCoord2fv(uv[1]);
166                         if(col) gpu_mcol(col[1]);
167                         glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]);
168
169                         if(glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[2]);
170                         else glTexCoord2fv(uv[2]);
171                         if(col) gpu_mcol(col[2]);
172                         glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]);
173
174                         if(v4) {
175                                 uv[3][0] = (tface->uv[3][0] - centerx) * sizex + transx;
176                                 uv[3][1] = (tface->uv[3][1] - centery) * sizey + transy;
177
178                                 if(glattrib >= 0) glVertexAttrib2fvARB(glattrib, uv[3]);
179                                 else glTexCoord2fv(uv[3]);
180                                 if(col) gpu_mcol(col[3]);
181                                 glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]);
182                         }
183                         glEnd();
184
185                         glTranslatef(advance, 0.0, 0.0);
186                         line_start -= advance; /* so we can go back to the start of the line */
187                 }
188                 glPopMatrix();
189         }
190 }
191
192 /* Checking powers of two for images since opengl 1.x requires it */
193
194 static int is_pow2(int num)
195 {
196         /* (n&(n-1)) zeros the least significant bit of n */
197         return ((num)&(num-1))==0;
198 }
199
200 static int smaller_pow2(int num)
201 {
202         while (!is_pow2(num))
203                 num= num&(num-1);
204
205         return num;     
206 }
207
208 static int is_pow2_limit(int num)
209 {
210         /* take texture clamping into account */
211
212         /* XXX: texturepaint not global!
213         if (G.f & G_TEXTUREPAINT)
214                 return 1;*/
215
216         if (U.glreslimit != 0 && num > U.glreslimit)
217                 return 0;
218
219         return ((num)&(num-1))==0;
220 }
221
222 static int smaller_pow2_limit(int num)
223 {
224         /* XXX: texturepaint not global!
225         if (G.f & G_TEXTUREPAINT)
226                 return 1;*/
227         
228         /* take texture clamping into account */
229         if (U.glreslimit != 0 && num > U.glreslimit)
230                 return U.glreslimit;
231
232         return smaller_pow2(num);
233 }
234
235 /* Current OpenGL state caching for GPU_set_tpage */
236
237 static struct GPUTextureState {
238         int curtile, tile;
239         int curtilemode, tilemode;
240         int curtileXRep, tileXRep;
241         int curtileYRep, tileYRep;
242         Image *ima, *curima;
243
244         int domipmap, linearmipmap;
245
246         int alphablend;
247         float anisotropic;
248         MTFace *lasttface;
249 } GTS = {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 1, 0, -1, 1.f, NULL};
250
251 /* Mipmap settings */
252
253 void GPU_set_mipmap(int mipmap)
254 {
255         if (GTS.domipmap != (mipmap != 0)) {
256                 GPU_free_images();
257                 GTS.domipmap = mipmap != 0;
258         }
259 }
260
261 void GPU_set_linear_mipmap(int linear)
262 {
263         if (GTS.linearmipmap != (linear != 0)) {
264                 GPU_free_images();
265                 GTS.linearmipmap = linear != 0;
266         }
267 }
268
269 static int gpu_get_mipmap(void)
270 {
271         return GTS.domipmap;
272 }
273
274 static GLenum gpu_get_mipmap_filter(int mag)
275 {
276         /* linearmipmap is off by default *when mipmapping is off,
277          * use unfiltered display */
278         if(mag) {
279                 if(GTS.linearmipmap || GTS.domipmap)
280                         return GL_LINEAR;
281                 else
282                         return GL_NEAREST;
283         }
284         else {
285                 if(GTS.linearmipmap)
286                         return GL_LINEAR_MIPMAP_LINEAR;
287                 else if(GTS.domipmap)
288                         return GL_LINEAR_MIPMAP_NEAREST;
289                 else
290                         return GL_NEAREST;
291         }
292 }
293
294 /* Anisotropic filtering settings */
295 void GPU_set_anisotropic(float value)
296 {
297         if (GTS.anisotropic != value)
298         {
299                 GPU_free_images();
300
301                 /* Clamp value to the maximum value the graphics card supports */
302                 if (value > GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)
303                         value = GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT;
304
305                 GTS.anisotropic = value;
306         }
307 }
308
309 float GPU_get_anisotropic(void)
310 {
311         return GTS.anisotropic;
312 }
313
314 /* Set OpenGL state for an MTFace */
315
316 static void gpu_make_repbind(Image *ima)
317 {
318         ImBuf *ibuf;
319         
320         ibuf = BKE_image_get_ibuf(ima, NULL);
321         if(ibuf==NULL)
322                 return;
323
324         if(ima->repbind) {
325                 glDeleteTextures(ima->totbind, (GLuint *)ima->repbind);
326                 MEM_freeN(ima->repbind);
327                 ima->repbind= NULL;
328                 ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
329         }
330
331         ima->totbind= ima->xrep*ima->yrep;
332
333         if(ima->totbind>1)
334                 ima->repbind= MEM_callocN(sizeof(int)*ima->totbind, "repbind");
335 }
336
337 static void gpu_clear_tpage(void)
338 {
339         if(GTS.lasttface==NULL)
340                 return;
341         
342         GTS.lasttface= NULL;
343         GTS.curtile= 0;
344         GTS.curima= NULL;
345         if(GTS.curtilemode!=0) {
346                 glMatrixMode(GL_TEXTURE);
347                 glLoadIdentity();
348                 glMatrixMode(GL_MODELVIEW);
349         }
350         GTS.curtilemode= 0;
351         GTS.curtileXRep=0;
352         GTS.curtileYRep=0;
353         GTS.alphablend= -1;
354         
355         glDisable(GL_BLEND);
356         glDisable(GL_TEXTURE_2D);
357         glDisable(GL_TEXTURE_GEN_S);
358         glDisable(GL_TEXTURE_GEN_T);
359         glDisable(GL_ALPHA_TEST);
360 }
361
362 static void gpu_set_alpha_blend(GPUBlendMode alphablend)
363 {
364         if(alphablend == GPU_BLEND_SOLID) {
365                 glDisable(GL_BLEND);
366                 glDisable(GL_ALPHA_TEST);
367                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
368         }
369         else if(alphablend==GPU_BLEND_ADD) {
370                 glEnable(GL_BLEND);
371                 glBlendFunc(GL_ONE, GL_ONE);
372                 glDisable(GL_ALPHA_TEST);
373         }
374         else if(ELEM(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ALPHA_SORT)) {
375                 glEnable(GL_BLEND);
376                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
377                 
378                 /* if U.glalphaclip == 1.0, some cards go bonkers...
379                  * turn off alpha test in this case */
380
381                 /* added after 2.45 to clip alpha */
382                 if(U.glalphaclip == 1.0f) {
383                         glDisable(GL_ALPHA_TEST);
384                 }
385                 else {
386                         glEnable(GL_ALPHA_TEST);
387                         glAlphaFunc(GL_GREATER, U.glalphaclip);
388                 }
389         }
390         else if(alphablend==GPU_BLEND_CLIP) {
391                 glDisable(GL_BLEND); 
392                 glEnable(GL_ALPHA_TEST);
393                 glAlphaFunc(GL_GREATER, 0.5f);
394         }
395 }
396
397 static void gpu_verify_alpha_blend(int alphablend)
398 {
399         /* verify alpha blending modes */
400         if(GTS.alphablend == alphablend)
401                 return;
402
403         gpu_set_alpha_blend(alphablend);
404         GTS.alphablend= alphablend;
405 }
406
407 static void gpu_verify_reflection(Image *ima)
408 {
409         if (ima && (ima->flag & IMA_REFLECT)) {
410                 /* enable reflection mapping */
411                 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
412                 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
413
414                 glEnable(GL_TEXTURE_GEN_S);
415                 glEnable(GL_TEXTURE_GEN_T);
416         }
417         else {
418                 /* disable reflection mapping */
419                 glDisable(GL_TEXTURE_GEN_S);
420                 glDisable(GL_TEXTURE_GEN_T);
421         }
422 }
423
424 int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap)
425 {
426         ImBuf *ibuf = NULL;
427         unsigned int *bind = NULL;
428         int rectw, recth, tpx=0, tpy=0, y;
429         unsigned int *rectrow, *tilerectrow;
430         unsigned int *tilerect= NULL, *scalerect= NULL, *rect= NULL;
431         short texwindx, texwindy, texwinsx, texwinsy;
432
433         /* initialize tile mode and number of repeats */
434         GTS.ima = ima;
435         GTS.tilemode= (ima && (ima->tpageflag & (IMA_TILES|IMA_TWINANIM)));
436         GTS.tileXRep = 0;
437         GTS.tileYRep = 0;
438
439         /* setting current tile according to frame */
440         if(ima && (ima->tpageflag & IMA_TWINANIM))
441                 GTS.tile= ima->lastframe;
442         else
443                 GTS.tile= tftile;
444
445         GTS.tile = MAX2(0, GTS.tile);
446
447         if(ima) {
448                 GTS.tileXRep = ima->xrep;
449                 GTS.tileYRep = ima->yrep;
450         }
451
452         /* if same image & tile, we're done */
453         if(compare && ima == GTS.curima && GTS.curtile == GTS.tile &&
454            GTS.tilemode == GTS.curtilemode && GTS.curtileXRep == GTS.tileXRep &&
455            GTS.curtileYRep == GTS.tileYRep)
456                 return (ima != NULL);
457
458         /* if tiling mode or repeat changed, change texture matrix to fit */
459         if(GTS.tilemode!=GTS.curtilemode || GTS.curtileXRep!=GTS.tileXRep ||
460            GTS.curtileYRep != GTS.tileYRep) {
461
462                 glMatrixMode(GL_TEXTURE);
463                 glLoadIdentity();
464
465                 if(ima && (ima->tpageflag & IMA_TILES))
466                         glScalef(ima->xrep, ima->yrep, 1.0);
467
468                 glMatrixMode(GL_MODELVIEW);
469         }
470
471         /* check if we have a valid image */
472         if(ima==NULL || ima->ok==0)
473                 return 0;
474
475         /* check if we have a valid image buffer */
476         ibuf= BKE_image_get_ibuf(ima, iuser);
477
478         if(ibuf==NULL)
479                 return 0;
480
481         /* ensure we have a char buffer and not only float */
482         if ((ibuf->rect==NULL) && ibuf->rect_float)
483                 IMB_rect_from_float(ibuf);
484
485         /* currently, tpage refresh is used by ima sequences */
486         if(ima->tpageflag & IMA_TPAGE_REFRESH) {
487                 GPU_free_image(ima);
488                 ima->tpageflag &= ~IMA_TPAGE_REFRESH;
489         }
490         
491         if(GTS.tilemode) {
492                 /* tiled mode */
493                 if(ima->repbind==NULL) gpu_make_repbind(ima);
494                 if(GTS.tile>=ima->totbind) GTS.tile= 0;
495                 
496                 /* this happens when you change repeat buttons */
497                 if(ima->repbind) bind= &ima->repbind[GTS.tile];
498                 else bind= &ima->bindcode;
499                 
500                 if(*bind==0) {
501                         
502                         texwindx= ibuf->x/ima->xrep;
503                         texwindy= ibuf->y/ima->yrep;
504                         
505                         if(GTS.tile>=ima->xrep*ima->yrep)
506                                 GTS.tile= ima->xrep*ima->yrep-1;
507         
508                         texwinsy= GTS.tile / ima->xrep;
509                         texwinsx= GTS.tile - texwinsy*ima->xrep;
510         
511                         texwinsx*= texwindx;
512                         texwinsy*= texwindy;
513         
514                         tpx= texwindx;
515                         tpy= texwindy;
516
517                         rect= ibuf->rect + texwinsy*ibuf->x + texwinsx;
518                 }
519         }
520         else {
521                 /* regular image mode */
522                 bind= &ima->bindcode;
523                 
524                 if(*bind==0) {
525                         tpx= ibuf->x;
526                         tpy= ibuf->y;
527                         rect= ibuf->rect;
528                 }
529         }
530
531         if(*bind != 0) {
532                 /* enable opengl drawing with textures */
533                 glBindTexture(GL_TEXTURE_2D, *bind);
534                 return *bind;
535         }
536
537         rectw = tpx;
538         recth = tpy;
539
540         /* for tiles, copy only part of image into buffer */
541         if (GTS.tilemode) {
542                 tilerect= MEM_mallocN(rectw*recth*sizeof(*tilerect), "tilerect");
543
544                 for (y=0; y<recth; y++) {
545                         rectrow= &rect[y*ibuf->x];
546                         tilerectrow= &tilerect[y*rectw];
547                                 
548                         memcpy(tilerectrow, rectrow, tpx*sizeof(*rectrow));
549                 }
550                         
551                 rect= tilerect;
552         }
553
554         /* scale if not a power of two */
555         if (!is_pow2_limit(rectw) || !is_pow2_limit(recth)) {
556                 rectw= smaller_pow2_limit(rectw);
557                 recth= smaller_pow2_limit(recth);
558                 
559                 scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
560                 gluScaleImage(GL_RGBA, tpx, tpy, GL_UNSIGNED_BYTE, rect, rectw, recth, GL_UNSIGNED_BYTE, scalerect);
561                 rect= scalerect;
562         }
563
564         /* create image */
565         glGenTextures(1, (GLuint *)bind);
566         glBindTexture( GL_TEXTURE_2D, *bind);
567
568         if (!(gpu_get_mipmap() && mipmap)) {
569                 glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGBA,  rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
570                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
571                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
572         }
573         else {
574                 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect);
575                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
576                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
577
578                 ima->tpageflag |= IMA_MIPMAP_COMPLETE;
579         }
580
581         if (GLEW_EXT_texture_filter_anisotropic)
582                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
583         /* set to modulate with vertex color */
584         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
585                 
586         /* clean up */
587         if (tilerect)
588                 MEM_freeN(tilerect);
589         if (scalerect)
590                 MEM_freeN(scalerect);
591
592         return *bind;
593 }
594
595 static void gpu_verify_repeat(Image *ima)
596 {
597         /* set either clamp or repeat in X/Y */
598         if (ima->tpageflag & IMA_CLAMP_U)
599            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
600         else
601                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
602
603         if (ima->tpageflag & IMA_CLAMP_V)
604                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
605         else
606                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
607 }
608
609 int GPU_set_tpage(MTFace *tface, int mipmap, int alphablend)
610 {
611         Image *ima;
612         
613         /* check if we need to clear the state */
614         if(tface==NULL) {
615                 gpu_clear_tpage();
616                 return 0;
617         }
618
619         ima= tface->tpage;
620         GTS.lasttface= tface;
621
622         gpu_verify_alpha_blend(alphablend);
623         gpu_verify_reflection(ima);
624
625         if(GPU_verify_image(ima, NULL, tface->tile, 1, mipmap)) {
626                 GTS.curtile= GTS.tile;
627                 GTS.curima= GTS.ima;
628                 GTS.curtilemode= GTS.tilemode;
629                 GTS.curtileXRep = GTS.tileXRep;
630                 GTS.curtileYRep = GTS.tileYRep;
631
632                 glEnable(GL_TEXTURE_2D);
633         }
634         else {
635                 glDisable(GL_TEXTURE_2D);
636                 
637                 GTS.curtile= 0;
638                 GTS.curima= NULL;
639                 GTS.curtilemode= 0;
640                 GTS.curtileXRep = 0;
641                 GTS.curtileYRep = 0;
642
643                 return 0;
644         }
645         
646         gpu_verify_repeat(ima);
647         
648         /* Did this get lost in the image recode? */
649         /* tag_image_time(ima);*/
650
651         return 1;
652 }
653
654 /* these two functions are called on entering and exiting texture paint mode,
655    temporary disabling/enabling mipmapping on all images for quick texture
656    updates with glTexSubImage2D. images that didn't change don't have to be
657    re-uploaded to OpenGL */
658 void GPU_paint_set_mipmap(int mipmap)
659 {
660         Image* ima;
661         
662         if(!GTS.domipmap)
663                 return;
664
665         if(mipmap) {
666                 for(ima=G.main->image.first; ima; ima=ima->id.next) {
667                         if(ima->bindcode) {
668                                 if(ima->tpageflag & IMA_MIPMAP_COMPLETE) {
669                                         glBindTexture(GL_TEXTURE_2D, ima->bindcode);
670                                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
671                                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
672                                 }
673                                 else
674                                         GPU_free_image(ima);
675                         }
676                 }
677
678         }
679         else {
680                 for(ima=G.main->image.first; ima; ima=ima->id.next) {
681                         if(ima->bindcode) {
682                                 glBindTexture(GL_TEXTURE_2D, ima->bindcode);
683                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
684                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
685                         }
686                 }
687         }
688 }
689
690 void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
691 {
692         ImBuf *ibuf;
693         
694         ibuf = BKE_image_get_ibuf(ima, NULL);
695         
696         if (ima->repbind || (gpu_get_mipmap() && mipmap) || !ima->bindcode || !ibuf ||
697                 (!is_pow2(ibuf->x) || !is_pow2(ibuf->y)) ||
698                 (w == 0) || (h == 0)) {
699                 /* these cases require full reload still */
700                 GPU_free_image(ima);
701         }
702         else {
703                 /* for the special case, we can do a partial update
704                  * which is much quicker for painting */
705                 GLint row_length, skip_pixels, skip_rows;
706
707                 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length);
708                 glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
709                 glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
710
711                 if (ibuf->rect_float){
712                         /*This case needs a whole new buffer*/
713                         if(ibuf->rect==NULL) {
714                                 IMB_rect_from_float(ibuf);
715                         }
716                         else {
717                                 /* Do partial drawing. 'buffer' holds only the changed part. Needed for color corrected result */
718                                 float *buffer = (float *)MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
719                                 IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h);
720                                 glBindTexture(GL_TEXTURE_2D, ima->bindcode);
721                                 glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
722                                         GL_FLOAT, buffer);
723                                 MEM_freeN(buffer);
724                                 if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
725                                         ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
726                                 return;
727                         }
728                 }
729                 
730                 glBindTexture(GL_TEXTURE_2D, ima->bindcode);
731
732                 glPixelStorei(GL_UNPACK_ROW_LENGTH, ibuf->x);
733                 glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
734                 glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
735
736                 glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
737                         GL_UNSIGNED_BYTE, ibuf->rect);
738
739                 glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
740                 glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels);
741                 glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows);
742
743                 if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
744                         ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
745         }
746 }
747
748 void GPU_update_images_framechange(void)
749 {
750         Image *ima;
751         
752         for(ima=G.main->image.first; ima; ima=ima->id.next) {
753                 if(ima->tpageflag & IMA_TWINANIM) {
754                         if(ima->twend >= ima->xrep*ima->yrep)
755                                 ima->twend= ima->xrep*ima->yrep-1;
756                 
757                         /* check: is bindcode not in the array? free. (to do) */
758                         
759                         ima->lastframe++;
760                         if(ima->lastframe > ima->twend)
761                                 ima->lastframe= ima->twsta;
762                 }
763         }
764 }
765
766 int GPU_update_image_time(Image *ima, double time)
767 {
768         int     inc = 0;
769         float   diff;
770         int     newframe;
771
772         if (!ima)
773                 return 0;
774
775         if (ima->lastupdate<0)
776                 ima->lastupdate = 0;
777
778         if (ima->lastupdate>time)
779                 ima->lastupdate=(float)time;
780
781         if(ima->tpageflag & IMA_TWINANIM) {
782                 if(ima->twend >= ima->xrep*ima->yrep) ima->twend= ima->xrep*ima->yrep-1;
783                 
784                 /* check: is the bindcode not in the array? Then free. (still to do) */
785                 
786                 diff = (float)(time-ima->lastupdate);
787                 inc = (int)(diff*(float)ima->animspeed);
788
789                 ima->lastupdate+=((float)inc/(float)ima->animspeed);
790
791                 newframe = ima->lastframe+inc;
792
793                 if(newframe > (int)ima->twend) {
794                         if(ima->twend-ima->twsta != 0)
795                                 newframe = (int)ima->twsta-1 + (newframe-ima->twend)%(ima->twend-ima->twsta);
796                         else
797                                 newframe = ima->twsta;
798                 }
799
800                 ima->lastframe = newframe;
801         }
802
803         return inc;
804 }
805
806
807 void GPU_free_smoke(SmokeModifierData *smd)
808 {
809         if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain)
810         {
811                 if(smd->domain->tex)
812                          GPU_texture_free(smd->domain->tex);
813                 smd->domain->tex = NULL;
814
815                 if(smd->domain->tex_shadow)
816                          GPU_texture_free(smd->domain->tex_shadow);
817                 smd->domain->tex_shadow = NULL;
818         }
819 }
820
821 void GPU_create_smoke(SmokeModifierData *smd, int highres)
822 {
823 #ifdef WITH_SMOKE
824         if(smd->type & MOD_SMOKE_TYPE_DOMAIN && !smd->domain->tex && !highres)
825                 smd->domain->tex = GPU_texture_create_3D(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2], smoke_get_density(smd->domain->fluid));
826         else if(smd->type & MOD_SMOKE_TYPE_DOMAIN && !smd->domain->tex && highres)
827                 smd->domain->tex = GPU_texture_create_3D(smd->domain->res_wt[0], smd->domain->res_wt[1], smd->domain->res_wt[2], smoke_turbulence_get_density(smd->domain->wt));
828
829         smd->domain->tex_shadow = GPU_texture_create_3D(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2], smd->domain->shadow);
830 #else // WITH_SMOKE
831         (void)highres;
832         smd->domain->tex= NULL;
833         smd->domain->tex_shadow= NULL;
834 #endif // WITH_SMOKE
835 }
836
837 static ListBase image_free_queue = {NULL, NULL};
838
839 static void gpu_queue_image_for_free(Image *ima)
840 {
841         Image *cpy = MEM_dupallocN(ima);
842
843         BLI_lock_thread(LOCK_OPENGL);
844         BLI_addtail(&image_free_queue, cpy);
845         BLI_unlock_thread(LOCK_OPENGL);
846 }
847
848 void GPU_free_unused_buffers(void)
849 {
850         Image *ima;
851
852         if(!BLI_thread_is_main())
853                 return;
854
855         BLI_lock_thread(LOCK_OPENGL);
856
857         /* images */
858         for(ima=image_free_queue.first; ima; ima=ima->id.next)
859                 GPU_free_image(ima);
860
861         BLI_freelistN(&image_free_queue);
862
863         /* vbo buffers */
864         /* it's probably not necessary to free all buffers every frame */
865         /* GPU_buffer_pool_free_unused(0); */
866
867         BLI_unlock_thread(LOCK_OPENGL);
868 }
869
870 void GPU_free_image(Image *ima)
871 {
872         if(!BLI_thread_is_main()) {
873                 gpu_queue_image_for_free(ima);
874                 return;
875         }
876
877         /* free regular image binding */
878         if(ima->bindcode) {
879                 glDeleteTextures(1, (GLuint *)&ima->bindcode);
880                 ima->bindcode= 0;
881                 ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
882         }
883
884         /* free glsl image binding */
885         if(ima->gputexture) {
886                 GPU_texture_free(ima->gputexture);
887                 ima->gputexture= NULL;
888         }
889
890         /* free repeated image binding */
891         if(ima->repbind) {
892                 glDeleteTextures(ima->totbind, (GLuint *)ima->repbind);
893         
894                 MEM_freeN(ima->repbind);
895                 ima->repbind= NULL;
896                 ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
897         }
898 }
899
900 void GPU_free_images(void)
901 {
902         Image* ima;
903
904         if(G.main)
905                 for(ima=G.main->image.first; ima; ima=ima->id.next)
906                         GPU_free_image(ima);
907 }
908
909 /* same as above but only free animated images */
910 void GPU_free_images_anim(void)
911 {
912         Image* ima;
913
914         if(G.main)
915                 for(ima=G.main->image.first; ima; ima=ima->id.next)
916                         if(ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE))
917                                 GPU_free_image(ima);
918 }
919
920 /* OpenGL Materials */
921
922 #define FIXEDMAT        8
923
924 /* OpenGL state caching for materials */
925
926 typedef struct GPUMaterialFixed {
927         float diff[4];
928         float spec[4];
929         int hard;
930 } GPUMaterialFixed; 
931
932 static struct GPUMaterialState {
933         GPUMaterialFixed (*matbuf);
934         GPUMaterialFixed matbuf_fixed[FIXEDMAT];
935         int totmat;
936
937         Material **gmatbuf;
938         Material *gmatbuf_fixed[FIXEDMAT];
939         Material *gboundmat;
940         Object *gob;
941         Scene *gscene;
942         int glay;
943         float (*gviewmat)[4];
944         float (*gviewinv)[4];
945
946         GPUBlendMode *alphablend;
947         GPUBlendMode alphablend_fixed[FIXEDMAT];
948         int alphapass;
949
950         int lastmatnr, lastretval;
951         GPUBlendMode lastalphablend;
952 } GMS = {NULL};
953
954 /* fixed function material, alpha handed by caller */
955 static void gpu_material_to_fixed(GPUMaterialFixed *smat, const Material *bmat, const int gamma, const Object *ob, const int new_shading_nodes)
956 {
957         if(new_shading_nodes || bmat->mode & MA_SHLESS) {
958                 copy_v3_v3(smat->diff, &bmat->r);
959                 smat->diff[3]= 1.0;
960
961                 if(gamma)
962                         linearrgb_to_srgb_v3_v3(smat->diff, smat->diff);
963
964                 zero_v4(smat->spec);
965                 smat->hard= 0;
966         }
967         else {
968                 mul_v3_v3fl(smat->diff, &bmat->r, bmat->ref + bmat->emit);
969                 smat->diff[3]= 1.0; /* caller may set this to bmat->alpha */
970
971                 if(bmat->shade_flag & MA_OBCOLOR)
972                         mul_v3_v3(smat->diff, ob->col);
973                 
974                 mul_v3_v3fl(smat->spec, &bmat->specr, bmat->spec);
975                 smat->spec[3]= 1.0; /* always 1 */
976                 smat->hard= CLAMPIS(bmat->har, 0, 128);
977
978                 if(gamma) {
979                         linearrgb_to_srgb_v3_v3(smat->diff, smat->diff);
980                         linearrgb_to_srgb_v3_v3(smat->spec, smat->spec);
981                 }       
982         }
983 }
984
985 static Material *gpu_active_node_material(Material *ma)
986 {
987         if(ma && ma->use_nodes && ma->nodetree) {
988                 bNode *node= nodeGetActiveID(ma->nodetree, ID_MA);
989
990                 if(node)
991                         return (Material *)node->id;
992                 else
993                         return NULL;
994         }
995
996         return ma;
997 }
998
999 void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Object *ob, int glsl, int *do_alpha_pass)
1000 {
1001         Material *ma;
1002         GPUMaterial *gpumat;
1003         GPUBlendMode alphablend;
1004         int a;
1005         int gamma = scene->r.color_mgt_flag & R_COLOR_MANAGEMENT;
1006         int new_shading_nodes = scene_use_new_shading_nodes(scene);
1007         
1008         /* initialize state */
1009         memset(&GMS, 0, sizeof(GMS));
1010         GMS.lastmatnr = -1;
1011         GMS.lastretval = -1;
1012         GMS.lastalphablend = GPU_BLEND_SOLID;
1013
1014         GMS.gob = ob;
1015         GMS.gscene = scene;
1016         GMS.totmat= ob->totcol+1; /* materials start from 1, default material is 0 */
1017         GMS.glay= v3d->lay;
1018         GMS.gviewmat= rv3d->viewmat;
1019         GMS.gviewinv= rv3d->viewinv;
1020
1021         GMS.alphapass = (v3d && v3d->transp);
1022         if(do_alpha_pass)
1023                 *do_alpha_pass = 0;
1024         
1025         if(GMS.totmat > FIXEDMAT) {
1026                 GMS.matbuf= MEM_callocN(sizeof(GPUMaterialFixed)*GMS.totmat, "GMS.matbuf");
1027                 GMS.gmatbuf= MEM_callocN(sizeof(*GMS.gmatbuf)*GMS.totmat, "GMS.matbuf");
1028                 GMS.alphablend= MEM_callocN(sizeof(*GMS.alphablend)*GMS.totmat, "GMS.matbuf");
1029         }
1030         else {
1031                 GMS.matbuf= GMS.matbuf_fixed;
1032                 GMS.gmatbuf= GMS.gmatbuf_fixed;
1033                 GMS.alphablend= GMS.alphablend_fixed;
1034         }
1035
1036         /* no materials assigned? */
1037         if(ob->totcol==0) {
1038                 gpu_material_to_fixed(&GMS.matbuf[0], &defmaterial, 0, ob, new_shading_nodes);
1039
1040                 /* do material 1 too, for displists! */
1041                 memcpy(&GMS.matbuf[1], &GMS.matbuf[0], sizeof(GPUMaterialFixed));
1042
1043                 if(glsl) {
1044                         GMS.gmatbuf[0]= &defmaterial;
1045                         GPU_material_from_blender(GMS.gscene, &defmaterial);
1046                 }
1047
1048                 GMS.alphablend[0]= GPU_BLEND_SOLID;
1049         }
1050         
1051         /* setup materials */
1052         for(a=1; a<=ob->totcol; a++) {
1053                 /* find a suitable material */
1054                 ma= give_current_material(ob, a);
1055                 if(!glsl && !new_shading_nodes) ma= gpu_active_node_material(ma);
1056                 if(ma==NULL) ma= &defmaterial;
1057
1058                 /* create glsl material if requested */
1059                 gpumat = (glsl)? GPU_material_from_blender(GMS.gscene, ma): NULL;
1060
1061                 if(gpumat) {
1062                         /* do glsl only if creating it succeed, else fallback */
1063                         GMS.gmatbuf[a]= ma;
1064                         alphablend = GPU_material_alpha_blend(gpumat, ob->col);
1065                 }
1066                 else {
1067                         /* fixed function opengl materials */
1068                         gpu_material_to_fixed(&GMS.matbuf[a], ma, gamma, ob, new_shading_nodes);
1069
1070                         alphablend = (ma->alpha == 1.0f)? GPU_BLEND_SOLID: GPU_BLEND_ALPHA;
1071                         if(do_alpha_pass && GMS.alphapass)
1072                                 GMS.matbuf[a].diff[3]= ma->alpha;
1073                         else
1074                                 GMS.matbuf[a].diff[3]= 1.0f;
1075                 }
1076
1077                 /* setting do_alpha_pass = 1 indicates this object needs to be
1078                  * drawn in a second alpha pass for improved blending */
1079                 if(do_alpha_pass) {
1080                         GMS.alphablend[a]= alphablend;
1081                         if(ELEM3(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ADD, GPU_BLEND_ALPHA_SORT) && !GMS.alphapass)
1082                                 *do_alpha_pass= 1;
1083                 }
1084         }
1085
1086         /* let's start with a clean state */
1087         GPU_disable_material();
1088 }
1089
1090 int GPU_enable_material(int nr, void *attribs)
1091 {
1092         GPUVertexAttribs *gattribs = attribs;
1093         GPUMaterial *gpumat;
1094         GPUBlendMode alphablend;
1095
1096         /* no GPU_begin_object_materials, use default material */
1097         if(!GMS.matbuf) {
1098                 float diff[4], spec[4];
1099
1100                 memset(&GMS, 0, sizeof(GMS));
1101
1102                 mul_v3_v3fl(diff, &defmaterial.r, defmaterial.ref + defmaterial.emit);
1103                 diff[3]= 1.0;
1104
1105                 mul_v3_v3fl(spec, &defmaterial.specr, defmaterial.spec);
1106                 spec[3]= 1.0;
1107
1108                 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff);
1109                 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
1110                 glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 35); /* blender default */
1111
1112                 return 0;
1113         }
1114
1115         /* prevent index to use un-initialized array items */
1116         if(nr>=GMS.totmat)
1117                 nr= 0;
1118
1119         if(gattribs)
1120                 memset(gattribs, 0, sizeof(*gattribs));
1121
1122         /* keep current material */
1123         if(nr==GMS.lastmatnr)
1124                 return GMS.lastretval;
1125
1126         /* unbind glsl material */
1127         if(GMS.gboundmat) {
1128                 if(GMS.alphapass) glDepthMask(0);
1129                 GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
1130                 GMS.gboundmat= NULL;
1131         }
1132
1133         /* draw materials with alpha in alpha pass */
1134         GMS.lastmatnr = nr;
1135         GMS.lastretval = ELEM(GMS.alphablend[nr], GPU_BLEND_SOLID, GPU_BLEND_CLIP);
1136         if(GMS.alphapass)
1137                 GMS.lastretval = !GMS.lastretval;
1138
1139         if(GMS.lastretval) {
1140                 /* for alpha pass, use alpha blend */
1141                 alphablend = (GMS.alphapass)? GPU_BLEND_ALPHA: GPU_BLEND_SOLID;
1142
1143                 if(gattribs && GMS.gmatbuf[nr]) {
1144                         /* bind glsl material and get attributes */
1145                         Material *mat = GMS.gmatbuf[nr];
1146
1147                         gpumat = GPU_material_from_blender(GMS.gscene, mat);
1148                         GPU_material_vertex_attributes(gpumat, gattribs);
1149                         GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0, !(GMS.gob->mode & OB_MODE_TEXTURE_PAINT));
1150                         GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gviewmat, GMS.gviewinv, GMS.gob->col);
1151                         GMS.gboundmat= mat;
1152
1153                         /* for glsl use alpha blend mode, unless it's set to solid and
1154                            we are already drawing in an alpha pass */
1155                         if(mat->game.alpha_blend != GPU_BLEND_SOLID)
1156                                 alphablend= mat->game.alpha_blend;
1157
1158                         if(GMS.alphapass) glDepthMask(1);
1159                 }
1160                 else {
1161                         /* or do fixed function opengl material */
1162                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, GMS.matbuf[nr].diff);
1163                         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, GMS.matbuf[nr].spec);
1164                         glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, GMS.matbuf[nr].hard);
1165                 }
1166
1167                 /* set (alpha) blending mode */
1168                 GPU_set_material_alpha_blend(alphablend);
1169         }
1170
1171         return GMS.lastretval;
1172 }
1173
1174 void GPU_set_material_alpha_blend(int alphablend)
1175 {
1176         if(GMS.lastalphablend == alphablend)
1177                 return;
1178         
1179         gpu_set_alpha_blend(alphablend);
1180         GMS.lastalphablend = alphablend;
1181 }
1182
1183 int GPU_get_material_alpha_blend(void)
1184 {
1185         return GMS.lastalphablend;
1186 }
1187
1188 void GPU_disable_material(void)
1189 {
1190         GMS.lastmatnr= -1;
1191         GMS.lastretval= 1;
1192
1193         if(GMS.gboundmat) {
1194                 if(GMS.alphapass) glDepthMask(0);
1195                 GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
1196                 GMS.gboundmat= NULL;
1197         }
1198
1199         GPU_set_material_alpha_blend(GPU_BLEND_SOLID);
1200 }
1201
1202 void GPU_end_object_materials(void)
1203 {
1204         GPU_disable_material();
1205
1206         if(GMS.matbuf && GMS.matbuf != GMS.matbuf_fixed) {
1207                 MEM_freeN(GMS.matbuf);
1208                 MEM_freeN(GMS.gmatbuf);
1209                 MEM_freeN(GMS.alphablend);
1210         }
1211
1212         GMS.matbuf= NULL;
1213         GMS.gmatbuf= NULL;
1214         GMS.alphablend= NULL;
1215
1216         /* resetting the texture matrix after the glScale needed for tiled textures */
1217         if(GTS.tilemode)
1218         {
1219                 glMatrixMode(GL_TEXTURE);
1220                 glLoadIdentity();
1221                 glMatrixMode(GL_MODELVIEW);
1222         }
1223 }
1224
1225 /* Lights */
1226
1227 int GPU_default_lights(void)
1228 {
1229         float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}, position[4];
1230         int a, count = 0;
1231         
1232         /* initialize */
1233         if(U.light[0].flag==0 && U.light[1].flag==0 && U.light[2].flag==0) {
1234                 U.light[0].flag= 1;
1235                 U.light[0].vec[0]= -0.3; U.light[0].vec[1]= 0.3; U.light[0].vec[2]= 0.9;
1236                 U.light[0].col[0]= 0.8; U.light[0].col[1]= 0.8; U.light[0].col[2]= 0.8;
1237                 U.light[0].spec[0]= 0.5; U.light[0].spec[1]= 0.5; U.light[0].spec[2]= 0.5;
1238                 U.light[0].spec[3]= 1.0;
1239                 
1240                 U.light[1].flag= 0;
1241                 U.light[1].vec[0]= 0.5; U.light[1].vec[1]= 0.5; U.light[1].vec[2]= 0.1;
1242                 U.light[1].col[0]= 0.4; U.light[1].col[1]= 0.4; U.light[1].col[2]= 0.8;
1243                 U.light[1].spec[0]= 0.3; U.light[1].spec[1]= 0.3; U.light[1].spec[2]= 0.5;
1244                 U.light[1].spec[3]= 1.0;
1245         
1246                 U.light[2].flag= 0;
1247                 U.light[2].vec[0]= 0.3; U.light[2].vec[1]= -0.3; U.light[2].vec[2]= -0.2;
1248                 U.light[2].col[0]= 0.8; U.light[2].col[1]= 0.5; U.light[2].col[2]= 0.4;
1249                 U.light[2].spec[0]= 0.5; U.light[2].spec[1]= 0.4; U.light[2].spec[2]= 0.3;
1250                 U.light[2].spec[3]= 1.0;
1251         }
1252
1253         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
1254
1255         for(a=0; a<8; a++) {
1256                 if(a<3) {
1257                         if(U.light[a].flag) {
1258                                 glEnable(GL_LIGHT0+a);
1259
1260                                 normalize_v3_v3(position, U.light[a].vec);
1261                                 position[3]= 0.0f;
1262                                 
1263                                 glLightfv(GL_LIGHT0+a, GL_POSITION, position); 
1264                                 glLightfv(GL_LIGHT0+a, GL_DIFFUSE, U.light[a].col); 
1265                                 glLightfv(GL_LIGHT0+a, GL_SPECULAR, U.light[a].spec); 
1266
1267                                 count++;
1268                         }
1269                         else {
1270                                 glDisable(GL_LIGHT0+a);
1271
1272                                 glLightfv(GL_LIGHT0+a, GL_POSITION, zero); 
1273                                 glLightfv(GL_LIGHT0+a, GL_DIFFUSE, zero); 
1274                                 glLightfv(GL_LIGHT0+a, GL_SPECULAR, zero);
1275                         }
1276
1277                         // clear stuff from other opengl lamp usage
1278                         glLightf(GL_LIGHT0+a, GL_SPOT_CUTOFF, 180.0);
1279                         glLightf(GL_LIGHT0+a, GL_CONSTANT_ATTENUATION, 1.0);
1280                         glLightf(GL_LIGHT0+a, GL_LINEAR_ATTENUATION, 0.0);
1281                 }
1282                 else
1283                         glDisable(GL_LIGHT0+a);
1284         }
1285         
1286         glDisable(GL_LIGHTING);
1287
1288         glDisable(GL_COLOR_MATERIAL);
1289
1290         return count;
1291 }
1292
1293 int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[][4], int ortho)
1294 {
1295         Base *base;
1296         Lamp *la;
1297         int count;
1298         float position[4], direction[4], energy[4];
1299         
1300         /* disable all lights */
1301         for(count=0; count<8; count++)
1302                 glDisable(GL_LIGHT0+count);
1303         
1304         /* view direction for specular is not compute correct by default in
1305          * opengl, so we set the settings ourselfs */
1306         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (ortho)? GL_FALSE: GL_TRUE);
1307
1308         count= 0;
1309         
1310         for(base=scene->base.first; base; base=base->next) {
1311                 if(base->object->type!=OB_LAMP)
1312                         continue;
1313
1314                 if(!(base->lay & lay) || !(base->lay & ob->lay))
1315                         continue;
1316
1317                 la= base->object->data;
1318                 
1319                 /* setup lamp transform */
1320                 glPushMatrix();
1321                 glLoadMatrixf((float *)viewmat);
1322                 
1323                 where_is_object_simul(scene, base->object);
1324                 
1325                 if(la->type==LA_SUN) {
1326                         /* sun lamp */
1327                         copy_v3_v3(direction, base->object->obmat[2]);
1328                         direction[3]= 0.0;
1329
1330                         glLightfv(GL_LIGHT0+count, GL_POSITION, direction); 
1331                 }
1332                 else {
1333                         /* other lamps with attenuation */
1334                         copy_v3_v3(position, base->object->obmat[3]);
1335                         position[3]= 1.0f;
1336
1337                         glLightfv(GL_LIGHT0+count, GL_POSITION, position); 
1338                         glLightf(GL_LIGHT0+count, GL_CONSTANT_ATTENUATION, 1.0);
1339                         glLightf(GL_LIGHT0+count, GL_LINEAR_ATTENUATION, la->att1/la->dist);
1340                         glLightf(GL_LIGHT0+count, GL_QUADRATIC_ATTENUATION, la->att2/(la->dist*la->dist));
1341                         
1342                         if(la->type==LA_SPOT) {
1343                                 /* spot lamp */
1344                                 negate_v3_v3(direction, base->object->obmat[2]);
1345                                 glLightfv(GL_LIGHT0+count, GL_SPOT_DIRECTION, direction);
1346                                 glLightf(GL_LIGHT0+count, GL_SPOT_CUTOFF, la->spotsize/2.0f);
1347                                 glLightf(GL_LIGHT0+count, GL_SPOT_EXPONENT, 128.0f*la->spotblend);
1348                         }
1349                         else
1350                                 glLightf(GL_LIGHT0+count, GL_SPOT_CUTOFF, 180.0);
1351                 }
1352                 
1353                 /* setup energy */
1354                 mul_v3_v3fl(energy, &la->r, la->energy);
1355                 energy[3]= 1.0;
1356
1357                 glLightfv(GL_LIGHT0+count, GL_DIFFUSE, energy); 
1358                 glLightfv(GL_LIGHT0+count, GL_SPECULAR, energy);
1359                 glEnable(GL_LIGHT0+count);
1360                 
1361                 glPopMatrix();                                  
1362                 
1363                 count++;
1364                 if(count==8)
1365                         break;
1366         }
1367
1368         return count;
1369 }
1370
1371 /* Default OpenGL State */
1372
1373 void GPU_state_init(void)
1374 {
1375         /* also called when doing opengl rendering and in the game engine */
1376         float mat_ambient[] = { 0.0, 0.0, 0.0, 0.0 };
1377         float mat_specular[] = { 0.5, 0.5, 0.5, 1.0 };
1378         int a, x, y;
1379         GLubyte pat[32*32];
1380         const GLubyte *patc= pat;
1381         
1382         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
1383         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_specular);
1384         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
1385         glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 35);
1386
1387         GPU_default_lights();
1388         
1389         glDepthFunc(GL_LEQUAL);
1390         /* scaling matrices */
1391         glEnable(GL_NORMALIZE);
1392
1393         glShadeModel(GL_FLAT);
1394
1395         glDisable(GL_ALPHA_TEST);
1396         glDisable(GL_BLEND);
1397         glDisable(GL_DEPTH_TEST);
1398         glDisable(GL_FOG);
1399         glDisable(GL_LIGHTING);
1400         glDisable(GL_LOGIC_OP);
1401         glDisable(GL_STENCIL_TEST);
1402         glDisable(GL_TEXTURE_1D);
1403         glDisable(GL_TEXTURE_2D);
1404
1405         /* default disabled, enable should be local per function */
1406         glDisableClientState(GL_VERTEX_ARRAY);
1407         glDisableClientState(GL_NORMAL_ARRAY);
1408         glDisableClientState(GL_COLOR_ARRAY);
1409         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1410         
1411         glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
1412         glPixelTransferi(GL_RED_SCALE, 1);
1413         glPixelTransferi(GL_RED_BIAS, 0);
1414         glPixelTransferi(GL_GREEN_SCALE, 1);
1415         glPixelTransferi(GL_GREEN_BIAS, 0);
1416         glPixelTransferi(GL_BLUE_SCALE, 1);
1417         glPixelTransferi(GL_BLUE_BIAS, 0);
1418         glPixelTransferi(GL_ALPHA_SCALE, 1);
1419         glPixelTransferi(GL_ALPHA_BIAS, 0);
1420         
1421         glPixelTransferi(GL_DEPTH_BIAS, 0);
1422         glPixelTransferi(GL_DEPTH_SCALE, 1);
1423         glDepthRange(0.0, 1.0);
1424         
1425         a= 0;
1426         for(x=0; x<32; x++) {
1427                 for(y=0; y<4; y++) {
1428                         if( (x) & 1) pat[a++]= 0x88;
1429                         else pat[a++]= 0x22;
1430                 }
1431         }
1432         
1433         glPolygonStipple(patc);
1434
1435         glMatrixMode(GL_TEXTURE);
1436         glLoadIdentity();
1437         glMatrixMode(GL_MODELVIEW);
1438
1439         glFrontFace(GL_CCW);
1440         glCullFace(GL_BACK);
1441         glDisable(GL_CULL_FACE);
1442
1443         /* calling this makes drawing very slow when AA is not set up in ghost
1444            on Linux/NVIDIA.
1445         glDisable(GL_MULTISAMPLE); */
1446 }
1447
1448 /* debugging aid */
1449 static void gpu_get_print(const char *name, GLenum type)
1450 {
1451         float value[16];
1452         int a;
1453         
1454         memset(value, 0, sizeof(value));
1455         glGetFloatv(type, value);
1456
1457         printf("%s: ", name);
1458         for(a=0; a<16; a++)
1459                 printf("%.2f ", value[a]);
1460         printf("\n");
1461 }
1462
1463 void GPU_state_print(void)
1464 {
1465         gpu_get_print("GL_ACCUM_ALPHA_BITS", GL_ACCUM_ALPHA_BITS);
1466         gpu_get_print("GL_ACCUM_BLUE_BITS", GL_ACCUM_BLUE_BITS);
1467         gpu_get_print("GL_ACCUM_CLEAR_VALUE", GL_ACCUM_CLEAR_VALUE);
1468         gpu_get_print("GL_ACCUM_GREEN_BITS", GL_ACCUM_GREEN_BITS);
1469         gpu_get_print("GL_ACCUM_RED_BITS", GL_ACCUM_RED_BITS);
1470         gpu_get_print("GL_ACTIVE_TEXTURE", GL_ACTIVE_TEXTURE);
1471         gpu_get_print("GL_ALIASED_POINT_SIZE_RANGE", GL_ALIASED_POINT_SIZE_RANGE);
1472         gpu_get_print("GL_ALIASED_LINE_WIDTH_RANGE", GL_ALIASED_LINE_WIDTH_RANGE);
1473         gpu_get_print("GL_ALPHA_BIAS", GL_ALPHA_BIAS);
1474         gpu_get_print("GL_ALPHA_BITS", GL_ALPHA_BITS);
1475         gpu_get_print("GL_ALPHA_SCALE", GL_ALPHA_SCALE);
1476         gpu_get_print("GL_ALPHA_TEST", GL_ALPHA_TEST);
1477         gpu_get_print("GL_ALPHA_TEST_FUNC", GL_ALPHA_TEST_FUNC);
1478         gpu_get_print("GL_ALPHA_TEST_REF", GL_ALPHA_TEST_REF);
1479         gpu_get_print("GL_ARRAY_BUFFER_BINDING", GL_ARRAY_BUFFER_BINDING);
1480         gpu_get_print("GL_ATTRIB_STACK_DEPTH", GL_ATTRIB_STACK_DEPTH);
1481         gpu_get_print("GL_AUTO_NORMAL", GL_AUTO_NORMAL);
1482         gpu_get_print("GL_AUX_BUFFERS", GL_AUX_BUFFERS);
1483         gpu_get_print("GL_BLEND", GL_BLEND);
1484         gpu_get_print("GL_BLEND_COLOR", GL_BLEND_COLOR);
1485         gpu_get_print("GL_BLEND_DST_ALPHA", GL_BLEND_DST_ALPHA);
1486         gpu_get_print("GL_BLEND_DST_RGB", GL_BLEND_DST_RGB);
1487         gpu_get_print("GL_BLEND_EQUATION_RGB", GL_BLEND_EQUATION_RGB);
1488         gpu_get_print("GL_BLEND_EQUATION_ALPHA", GL_BLEND_EQUATION_ALPHA);
1489         gpu_get_print("GL_BLEND_SRC_ALPHA", GL_BLEND_SRC_ALPHA);
1490         gpu_get_print("GL_BLEND_SRC_RGB", GL_BLEND_SRC_RGB);
1491         gpu_get_print("GL_BLUE_BIAS", GL_BLUE_BIAS);
1492         gpu_get_print("GL_BLUE_BITS", GL_BLUE_BITS);
1493         gpu_get_print("GL_BLUE_SCALE", GL_BLUE_SCALE);
1494         gpu_get_print("GL_CLIENT_ACTIVE_TEXTURE", GL_CLIENT_ACTIVE_TEXTURE);
1495         gpu_get_print("GL_CLIENT_ATTRIB_STACK_DEPTH", GL_CLIENT_ATTRIB_STACK_DEPTH);
1496         gpu_get_print("GL_CLIP_PLANE0", GL_CLIP_PLANE0);
1497         gpu_get_print("GL_COLOR_ARRAY", GL_COLOR_ARRAY);
1498         gpu_get_print("GL_COLOR_ARRAY_BUFFER_BINDING", GL_COLOR_ARRAY_BUFFER_BINDING);
1499         gpu_get_print("GL_COLOR_ARRAY_SIZE", GL_COLOR_ARRAY_SIZE);
1500         gpu_get_print("GL_COLOR_ARRAY_STRIDE", GL_COLOR_ARRAY_STRIDE);
1501         gpu_get_print("GL_COLOR_ARRAY_TYPE", GL_COLOR_ARRAY_TYPE);
1502         gpu_get_print("GL_COLOR_CLEAR_VALUE", GL_COLOR_CLEAR_VALUE);
1503         gpu_get_print("GL_COLOR_LOGIC_OP", GL_COLOR_LOGIC_OP);
1504         gpu_get_print("GL_COLOR_MATERIAL", GL_COLOR_MATERIAL);
1505         gpu_get_print("GL_COLOR_MATERIAL_FACE", GL_COLOR_MATERIAL_FACE);
1506         gpu_get_print("GL_COLOR_MATERIAL_PARAMETER", GL_COLOR_MATERIAL_PARAMETER);
1507         gpu_get_print("GL_COLOR_MATRIX", GL_COLOR_MATRIX);
1508         gpu_get_print("GL_COLOR_MATRIX_STACK_DEPTH", GL_COLOR_MATRIX_STACK_DEPTH);
1509         gpu_get_print("GL_COLOR_SUM", GL_COLOR_SUM);
1510         gpu_get_print("GL_COLOR_TABLE", GL_COLOR_TABLE);
1511         gpu_get_print("GL_COLOR_WRITEMASK", GL_COLOR_WRITEMASK);
1512         gpu_get_print("GL_COMPRESSED_TEXTURE_FORMATS", GL_COMPRESSED_TEXTURE_FORMATS);
1513         gpu_get_print("GL_CONVOLUTION_1D", GL_CONVOLUTION_1D);
1514         gpu_get_print("GL_CONVOLUTION_2D", GL_CONVOLUTION_2D);
1515         gpu_get_print("GL_CULL_FACE", GL_CULL_FACE);
1516         gpu_get_print("GL_CULL_FACE_MODE", GL_CULL_FACE_MODE);
1517         gpu_get_print("GL_CURRENT_COLOR", GL_CURRENT_COLOR);
1518         gpu_get_print("GL_CURRENT_FOG_COORD", GL_CURRENT_FOG_COORD);
1519         gpu_get_print("GL_CURRENT_INDEX", GL_CURRENT_INDEX);
1520         gpu_get_print("GL_CURRENT_NORMAL", GL_CURRENT_NORMAL);
1521         gpu_get_print("GL_CURRENT_PROGRAM", GL_CURRENT_PROGRAM);
1522         gpu_get_print("GL_CURRENT_RASTER_COLOR", GL_CURRENT_RASTER_COLOR);
1523         gpu_get_print("GL_CURRENT_RASTER_DISTANCE", GL_CURRENT_RASTER_DISTANCE);
1524         gpu_get_print("GL_CURRENT_RASTER_INDEX", GL_CURRENT_RASTER_INDEX);
1525         gpu_get_print("GL_CURRENT_RASTER_POSITION", GL_CURRENT_RASTER_POSITION);
1526         gpu_get_print("GL_CURRENT_RASTER_POSITION_VALID", GL_CURRENT_RASTER_POSITION_VALID);
1527         gpu_get_print("GL_CURRENT_RASTER_SECONDARY_COLOR", GL_CURRENT_RASTER_SECONDARY_COLOR);
1528         gpu_get_print("GL_CURRENT_RASTER_TEXTURE_COORDS", GL_CURRENT_RASTER_TEXTURE_COORDS);
1529         gpu_get_print("GL_CURRENT_SECONDARY_COLOR", GL_CURRENT_SECONDARY_COLOR);
1530         gpu_get_print("GL_CURRENT_TEXTURE_COORDS", GL_CURRENT_TEXTURE_COORDS);
1531         gpu_get_print("GL_DEPTH_BIAS", GL_DEPTH_BIAS);
1532         gpu_get_print("GL_DEPTH_BITS", GL_DEPTH_BITS);
1533         gpu_get_print("GL_DEPTH_CLEAR_VALUE", GL_DEPTH_CLEAR_VALUE);
1534         gpu_get_print("GL_DEPTH_FUNC", GL_DEPTH_FUNC);
1535         gpu_get_print("GL_DEPTH_RANGE", GL_DEPTH_RANGE);
1536         gpu_get_print("GL_DEPTH_SCALE", GL_DEPTH_SCALE);
1537         gpu_get_print("GL_DEPTH_TEST", GL_DEPTH_TEST);
1538         gpu_get_print("GL_DEPTH_WRITEMASK", GL_DEPTH_WRITEMASK);
1539         gpu_get_print("GL_DITHER", GL_DITHER);
1540         gpu_get_print("GL_DOUBLEBUFFER", GL_DOUBLEBUFFER);
1541         gpu_get_print("GL_DRAW_BUFFER", GL_DRAW_BUFFER);
1542         gpu_get_print("GL_DRAW_BUFFER0", GL_DRAW_BUFFER0);
1543         gpu_get_print("GL_EDGE_FLAG", GL_EDGE_FLAG);
1544         gpu_get_print("GL_EDGE_FLAG_ARRAY", GL_EDGE_FLAG_ARRAY);
1545         gpu_get_print("GL_EDGE_FLAG_ARRAY_BUFFER_BINDING", GL_EDGE_FLAG_ARRAY_BUFFER_BINDING);
1546         gpu_get_print("GL_EDGE_FLAG_ARRAY_STRIDE", GL_EDGE_FLAG_ARRAY_STRIDE);
1547         gpu_get_print("GL_ELEMENT_ARRAY_BUFFER_BINDING", GL_ELEMENT_ARRAY_BUFFER_BINDING);
1548         gpu_get_print("GL_FEEDBACK_BUFFER_SIZE", GL_FEEDBACK_BUFFER_SIZE);
1549         gpu_get_print("GL_FEEDBACK_BUFFER_TYPE", GL_FEEDBACK_BUFFER_TYPE);
1550         gpu_get_print("GL_FOG", GL_FOG);
1551         gpu_get_print("GL_FOG_COORD_ARRAY", GL_FOG_COORD_ARRAY);
1552         gpu_get_print("GL_FOG_COORD_ARRAY_BUFFER_BINDING", GL_FOG_COORD_ARRAY_BUFFER_BINDING);
1553         gpu_get_print("GL_FOG_COORD_ARRAY_STRIDE", GL_FOG_COORD_ARRAY_STRIDE);
1554         gpu_get_print("GL_FOG_COORD_ARRAY_TYPE", GL_FOG_COORD_ARRAY_TYPE);
1555         gpu_get_print("GL_FOG_COORD_SRC", GL_FOG_COORD_SRC);
1556         gpu_get_print("GL_FOG_COLOR", GL_FOG_COLOR);
1557         gpu_get_print("GL_FOG_DENSITY", GL_FOG_DENSITY);
1558         gpu_get_print("GL_FOG_END", GL_FOG_END);
1559         gpu_get_print("GL_FOG_HINT", GL_FOG_HINT);
1560         gpu_get_print("GL_FOG_INDEX", GL_FOG_INDEX);
1561         gpu_get_print("GL_FOG_MODE", GL_FOG_MODE);
1562         gpu_get_print("GL_FOG_START", GL_FOG_START);
1563         gpu_get_print("GL_FRAGMENT_SHADER_DERIVATIVE_HINT", GL_FRAGMENT_SHADER_DERIVATIVE_HINT);
1564         gpu_get_print("GL_FRONT_FACE", GL_FRONT_FACE);
1565         gpu_get_print("GL_GENERATE_MIPMAP_HINT", GL_GENERATE_MIPMAP_HINT);
1566         gpu_get_print("GL_GREEN_BIAS", GL_GREEN_BIAS);
1567         gpu_get_print("GL_GREEN_BITS", GL_GREEN_BITS);
1568         gpu_get_print("GL_GREEN_SCALE", GL_GREEN_SCALE);
1569         gpu_get_print("GL_HISTOGRAM", GL_HISTOGRAM);
1570         gpu_get_print("GL_INDEX_ARRAY", GL_INDEX_ARRAY);
1571         gpu_get_print("GL_INDEX_ARRAY_BUFFER_BINDING", GL_INDEX_ARRAY_BUFFER_BINDING);
1572         gpu_get_print("GL_INDEX_ARRAY_STRIDE", GL_INDEX_ARRAY_STRIDE);
1573         gpu_get_print("GL_INDEX_ARRAY_TYPE", GL_INDEX_ARRAY_TYPE);
1574         gpu_get_print("GL_INDEX_BITS", GL_INDEX_BITS);
1575         gpu_get_print("GL_INDEX_CLEAR_VALUE", GL_INDEX_CLEAR_VALUE);
1576         gpu_get_print("GL_INDEX_LOGIC_OP", GL_INDEX_LOGIC_OP);
1577         gpu_get_print("GL_INDEX_MODE", GL_INDEX_MODE);
1578         gpu_get_print("GL_INDEX_OFFSET", GL_INDEX_OFFSET);
1579         gpu_get_print("GL_INDEX_SHIFT", GL_INDEX_SHIFT);
1580         gpu_get_print("GL_INDEX_WRITEMASK", GL_INDEX_WRITEMASK);
1581         gpu_get_print("GL_LIGHT0", GL_LIGHT0);
1582         gpu_get_print("GL_LIGHTING", GL_LIGHTING);
1583         gpu_get_print("GL_LIGHT_MODEL_AMBIENT", GL_LIGHT_MODEL_AMBIENT);
1584         gpu_get_print("GL_LIGHT_MODEL_COLOR_CONTROL", GL_LIGHT_MODEL_COLOR_CONTROL);
1585         gpu_get_print("GL_LIGHT_MODEL_LOCAL_VIEWER", GL_LIGHT_MODEL_LOCAL_VIEWER);
1586         gpu_get_print("GL_LIGHT_MODEL_TWO_SIDE", GL_LIGHT_MODEL_TWO_SIDE);
1587         gpu_get_print("GL_LINE_SMOOTH", GL_LINE_SMOOTH);
1588         gpu_get_print("GL_LINE_SMOOTH_HINT", GL_LINE_SMOOTH_HINT);
1589         gpu_get_print("GL_LINE_STIPPLE", GL_LINE_STIPPLE);
1590         gpu_get_print("GL_LINE_STIPPLE_PATTERN", GL_LINE_STIPPLE_PATTERN);
1591         gpu_get_print("GL_LINE_STIPPLE_REPEAT", GL_LINE_STIPPLE_REPEAT);
1592         gpu_get_print("GL_LINE_WIDTH", GL_LINE_WIDTH);
1593         gpu_get_print("GL_LINE_WIDTH_GRANULARITY", GL_LINE_WIDTH_GRANULARITY);
1594         gpu_get_print("GL_LINE_WIDTH_RANGE", GL_LINE_WIDTH_RANGE);
1595         gpu_get_print("GL_LIST_BASE", GL_LIST_BASE);
1596         gpu_get_print("GL_LIST_INDEX", GL_LIST_INDEX);
1597         gpu_get_print("GL_LIST_MODE", GL_LIST_MODE);
1598         gpu_get_print("GL_LOGIC_OP_MODE", GL_LOGIC_OP_MODE);
1599         gpu_get_print("GL_MAP1_COLOR_4", GL_MAP1_COLOR_4);
1600         gpu_get_print("GL_MAP1_GRID_DOMAIN", GL_MAP1_GRID_DOMAIN);
1601         gpu_get_print("GL_MAP1_GRID_SEGMENTS", GL_MAP1_GRID_SEGMENTS);
1602         gpu_get_print("GL_MAP1_INDEX", GL_MAP1_INDEX);
1603         gpu_get_print("GL_MAP1_NORMAL", GL_MAP1_NORMAL);
1604         gpu_get_print("GL_MAP1_TEXTURE_COORD_1", GL_MAP1_TEXTURE_COORD_1);
1605         gpu_get_print("GL_MAP1_TEXTURE_COORD_2", GL_MAP1_TEXTURE_COORD_2);
1606         gpu_get_print("GL_MAP1_TEXTURE_COORD_3", GL_MAP1_TEXTURE_COORD_3);
1607         gpu_get_print("GL_MAP1_TEXTURE_COORD_4", GL_MAP1_TEXTURE_COORD_4);
1608         gpu_get_print("GL_MAP1_VERTEX_3", GL_MAP1_VERTEX_3);
1609         gpu_get_print("GL_MAP1_VERTEX_4", GL_MAP1_VERTEX_4);
1610         gpu_get_print("GL_MAP2_COLOR_4", GL_MAP2_COLOR_4);
1611         gpu_get_print("GL_MAP2_GRID_DOMAIN", GL_MAP2_GRID_DOMAIN);
1612         gpu_get_print("GL_MAP2_GRID_SEGMENTS", GL_MAP2_GRID_SEGMENTS);
1613         gpu_get_print("GL_MAP2_INDEX", GL_MAP2_INDEX);
1614         gpu_get_print("GL_MAP2_NORMAL", GL_MAP2_NORMAL);
1615         gpu_get_print("GL_MAP2_TEXTURE_COORD_1", GL_MAP2_TEXTURE_COORD_1);
1616         gpu_get_print("GL_MAP2_TEXTURE_COORD_2", GL_MAP2_TEXTURE_COORD_2);
1617         gpu_get_print("GL_MAP2_TEXTURE_COORD_3", GL_MAP2_TEXTURE_COORD_3);
1618         gpu_get_print("GL_MAP2_TEXTURE_COORD_4", GL_MAP2_TEXTURE_COORD_4);
1619         gpu_get_print("GL_MAP2_VERTEX_3", GL_MAP2_VERTEX_3);
1620         gpu_get_print("GL_MAP2_VERTEX_4", GL_MAP2_VERTEX_4);
1621         gpu_get_print("GL_MAP_COLOR", GL_MAP_COLOR);
1622         gpu_get_print("GL_MAP_STENCIL", GL_MAP_STENCIL);
1623         gpu_get_print("GL_MATRIX_MODE", GL_MATRIX_MODE);
1624         gpu_get_print("GL_MAX_3D_TEXTURE_SIZE", GL_MAX_3D_TEXTURE_SIZE);
1625         gpu_get_print("GL_MAX_CLIENT_ATTRIB_STACK_DEPTH", GL_MAX_CLIENT_ATTRIB_STACK_DEPTH);
1626         gpu_get_print("GL_MAX_ATTRIB_STACK_DEPTH", GL_MAX_ATTRIB_STACK_DEPTH);
1627         gpu_get_print("GL_MAX_CLIP_PLANES", GL_MAX_CLIP_PLANES);
1628         gpu_get_print("GL_MAX_COLOR_MATRIX_STACK_DEPTH", GL_MAX_COLOR_MATRIX_STACK_DEPTH);
1629         gpu_get_print("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS);
1630         gpu_get_print("GL_MAX_CUBE_MAP_TEXTURE_SIZE", GL_MAX_CUBE_MAP_TEXTURE_SIZE);
1631         gpu_get_print("GL_MAX_DRAW_BUFFERS", GL_MAX_DRAW_BUFFERS);
1632         gpu_get_print("GL_MAX_ELEMENTS_INDICES", GL_MAX_ELEMENTS_INDICES);
1633         gpu_get_print("GL_MAX_ELEMENTS_VERTICES", GL_MAX_ELEMENTS_VERTICES);
1634         gpu_get_print("GL_MAX_EVAL_ORDER", GL_MAX_EVAL_ORDER);
1635         gpu_get_print("GL_MAX_FRAGMENT_UNIFORM_COMPONENTS", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS);
1636         gpu_get_print("GL_MAX_LIGHTS", GL_MAX_LIGHTS);
1637         gpu_get_print("GL_MAX_LIST_NESTING", GL_MAX_LIST_NESTING);
1638         gpu_get_print("GL_MAX_MODELVIEW_STACK_DEPTH", GL_MAX_MODELVIEW_STACK_DEPTH);
1639         gpu_get_print("GL_MAX_NAME_STACK_DEPTH", GL_MAX_NAME_STACK_DEPTH);
1640         gpu_get_print("GL_MAX_PIXEL_MAP_TABLE", GL_MAX_PIXEL_MAP_TABLE);
1641         gpu_get_print("GL_MAX_PROJECTION_STACK_DEPTH", GL_MAX_PROJECTION_STACK_DEPTH);
1642         gpu_get_print("GL_MAX_TEXTURE_COORDS", GL_MAX_TEXTURE_COORDS);
1643         gpu_get_print("GL_MAX_TEXTURE_IMAGE_UNITS", GL_MAX_TEXTURE_IMAGE_UNITS);
1644         gpu_get_print("GL_MAX_TEXTURE_LOD_BIAS", GL_MAX_TEXTURE_LOD_BIAS);
1645         gpu_get_print("GL_MAX_TEXTURE_SIZE", GL_MAX_TEXTURE_SIZE);
1646         gpu_get_print("GL_MAX_TEXTURE_STACK_DEPTH", GL_MAX_TEXTURE_STACK_DEPTH);
1647         gpu_get_print("GL_MAX_TEXTURE_UNITS", GL_MAX_TEXTURE_UNITS);
1648         gpu_get_print("GL_MAX_VARYING_FLOATS", GL_MAX_VARYING_FLOATS);
1649         gpu_get_print("GL_MAX_VERTEX_ATTRIBS", GL_MAX_VERTEX_ATTRIBS);
1650         gpu_get_print("GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS);
1651         gpu_get_print("GL_MAX_VERTEX_UNIFORM_COMPONENTS", GL_MAX_VERTEX_UNIFORM_COMPONENTS);
1652         gpu_get_print("GL_MAX_VIEWPORT_DIMS", GL_MAX_VIEWPORT_DIMS);
1653         gpu_get_print("GL_MINMAX", GL_MINMAX);
1654         gpu_get_print("GL_MODELVIEW_MATRIX", GL_MODELVIEW_MATRIX);
1655         gpu_get_print("GL_MODELVIEW_STACK_DEPTH", GL_MODELVIEW_STACK_DEPTH);
1656         gpu_get_print("GL_NAME_STACK_DEPTH", GL_NAME_STACK_DEPTH);
1657         gpu_get_print("GL_NORMAL_ARRAY", GL_NORMAL_ARRAY);
1658         gpu_get_print("GL_NORMAL_ARRAY_BUFFER_BINDING", GL_NORMAL_ARRAY_BUFFER_BINDING);
1659         gpu_get_print("GL_NORMAL_ARRAY_STRIDE", GL_NORMAL_ARRAY_STRIDE);
1660         gpu_get_print("GL_NORMAL_ARRAY_TYPE", GL_NORMAL_ARRAY_TYPE);
1661         gpu_get_print("GL_NORMALIZE", GL_NORMALIZE);
1662         gpu_get_print("GL_NUM_COMPRESSED_TEXTURE_FORMATS", GL_NUM_COMPRESSED_TEXTURE_FORMATS);
1663         gpu_get_print("GL_PACK_ALIGNMENT", GL_PACK_ALIGNMENT);
1664         gpu_get_print("GL_PACK_IMAGE_HEIGHT", GL_PACK_IMAGE_HEIGHT);
1665         gpu_get_print("GL_PACK_LSB_FIRST", GL_PACK_LSB_FIRST);
1666         gpu_get_print("GL_PACK_ROW_LENGTH", GL_PACK_ROW_LENGTH);
1667         gpu_get_print("GL_PACK_SKIP_IMAGES", GL_PACK_SKIP_IMAGES);
1668         gpu_get_print("GL_PACK_SKIP_PIXELS", GL_PACK_SKIP_PIXELS);
1669         gpu_get_print("GL_PACK_SKIP_ROWS", GL_PACK_SKIP_ROWS);
1670         gpu_get_print("GL_PACK_SWAP_BYTES", GL_PACK_SWAP_BYTES);
1671         gpu_get_print("GL_PERSPECTIVE_CORRECTION_HINT", GL_PERSPECTIVE_CORRECTION_HINT);
1672         gpu_get_print("GL_PIXEL_MAP_A_TO_A_SIZE", GL_PIXEL_MAP_A_TO_A_SIZE);
1673         gpu_get_print("GL_PIXEL_MAP_B_TO_B_SIZE", GL_PIXEL_MAP_B_TO_B_SIZE);
1674         gpu_get_print("GL_PIXEL_MAP_G_TO_G_SIZE", GL_PIXEL_MAP_G_TO_G_SIZE);
1675         gpu_get_print("GL_PIXEL_MAP_I_TO_A_SIZE", GL_PIXEL_MAP_I_TO_A_SIZE);
1676         gpu_get_print("GL_PIXEL_MAP_I_TO_B_SIZE", GL_PIXEL_MAP_I_TO_B_SIZE);
1677         gpu_get_print("GL_PIXEL_MAP_I_TO_G_SIZE", GL_PIXEL_MAP_I_TO_G_SIZE);
1678         gpu_get_print("GL_PIXEL_MAP_I_TO_I_SIZE", GL_PIXEL_MAP_I_TO_I_SIZE);
1679         gpu_get_print("GL_PIXEL_MAP_I_TO_R_SIZE", GL_PIXEL_MAP_I_TO_R_SIZE);
1680         gpu_get_print("GL_PIXEL_MAP_R_TO_R_SIZE", GL_PIXEL_MAP_R_TO_R_SIZE);
1681         gpu_get_print("GL_PIXEL_MAP_S_TO_S_SIZE", GL_PIXEL_MAP_S_TO_S_SIZE);
1682         gpu_get_print("GL_PIXEL_PACK_BUFFER_BINDING", GL_PIXEL_PACK_BUFFER_BINDING);
1683         gpu_get_print("GL_PIXEL_UNPACK_BUFFER_BINDING", GL_PIXEL_UNPACK_BUFFER_BINDING);
1684         gpu_get_print("GL_POINT_DISTANCE_ATTENUATION", GL_POINT_DISTANCE_ATTENUATION);
1685         gpu_get_print("GL_POINT_FADE_THRESHOLD_SIZE", GL_POINT_FADE_THRESHOLD_SIZE);
1686         gpu_get_print("GL_POINT_SIZE", GL_POINT_SIZE);
1687         gpu_get_print("GL_POINT_SIZE_GRANULARITY", GL_POINT_SIZE_GRANULARITY);
1688         gpu_get_print("GL_POINT_SIZE_MAX", GL_POINT_SIZE_MAX);
1689         gpu_get_print("GL_POINT_SIZE_MIN", GL_POINT_SIZE_MIN);
1690         gpu_get_print("GL_POINT_SIZE_RANGE", GL_POINT_SIZE_RANGE);
1691         gpu_get_print("GL_POINT_SMOOTH", GL_POINT_SMOOTH);
1692         gpu_get_print("GL_POINT_SMOOTH_HINT", GL_POINT_SMOOTH_HINT);
1693         gpu_get_print("GL_POINT_SPRITE", GL_POINT_SPRITE);
1694         gpu_get_print("GL_POLYGON_MODE", GL_POLYGON_MODE);
1695         gpu_get_print("GL_POLYGON_OFFSET_FACTOR", GL_POLYGON_OFFSET_FACTOR);
1696         gpu_get_print("GL_POLYGON_OFFSET_UNITS", GL_POLYGON_OFFSET_UNITS);
1697         gpu_get_print("GL_POLYGON_OFFSET_FILL", GL_POLYGON_OFFSET_FILL);
1698         gpu_get_print("GL_POLYGON_OFFSET_LINE", GL_POLYGON_OFFSET_LINE);
1699         gpu_get_print("GL_POLYGON_OFFSET_POINT", GL_POLYGON_OFFSET_POINT);
1700         gpu_get_print("GL_POLYGON_SMOOTH", GL_POLYGON_SMOOTH);
1701         gpu_get_print("GL_POLYGON_SMOOTH_HINT", GL_POLYGON_SMOOTH_HINT);
1702         gpu_get_print("GL_POLYGON_STIPPLE", GL_POLYGON_STIPPLE);
1703         gpu_get_print("GL_POST_COLOR_MATRIX_COLOR_TABLE", GL_POST_COLOR_MATRIX_COLOR_TABLE);
1704         gpu_get_print("GL_POST_COLOR_MATRIX_RED_BIAS", GL_POST_COLOR_MATRIX_RED_BIAS);
1705         gpu_get_print("GL_POST_COLOR_MATRIX_GREEN_BIAS", GL_POST_COLOR_MATRIX_GREEN_BIAS);
1706         gpu_get_print("GL_POST_COLOR_MATRIX_BLUE_BIAS", GL_POST_COLOR_MATRIX_BLUE_BIAS);
1707         gpu_get_print("GL_POST_COLOR_MATRIX_ALPHA_BIAS", GL_POST_COLOR_MATRIX_ALPHA_BIAS);
1708         gpu_get_print("GL_POST_COLOR_MATRIX_RED_SCALE", GL_POST_COLOR_MATRIX_RED_SCALE);
1709         gpu_get_print("GL_POST_COLOR_MATRIX_GREEN_SCALE", GL_POST_COLOR_MATRIX_GREEN_SCALE);
1710         gpu_get_print("GL_POST_COLOR_MATRIX_BLUE_SCALE", GL_POST_COLOR_MATRIX_BLUE_SCALE);
1711         gpu_get_print("GL_POST_COLOR_MATRIX_ALPHA_SCALE", GL_POST_COLOR_MATRIX_ALPHA_SCALE);
1712         gpu_get_print("GL_POST_CONVOLUTION_COLOR_TABLE", GL_POST_CONVOLUTION_COLOR_TABLE);
1713         gpu_get_print("GL_POST_CONVOLUTION_RED_BIAS", GL_POST_CONVOLUTION_RED_BIAS);
1714         gpu_get_print("GL_POST_CONVOLUTION_GREEN_BIAS", GL_POST_CONVOLUTION_GREEN_BIAS);
1715         gpu_get_print("GL_POST_CONVOLUTION_BLUE_BIAS", GL_POST_CONVOLUTION_BLUE_BIAS);
1716         gpu_get_print("GL_POST_CONVOLUTION_ALPHA_BIAS", GL_POST_CONVOLUTION_ALPHA_BIAS);
1717         gpu_get_print("GL_POST_CONVOLUTION_RED_SCALE", GL_POST_CONVOLUTION_RED_SCALE);
1718         gpu_get_print("GL_POST_CONVOLUTION_GREEN_SCALE", GL_POST_CONVOLUTION_GREEN_SCALE);
1719         gpu_get_print("GL_POST_CONVOLUTION_BLUE_SCALE", GL_POST_CONVOLUTION_BLUE_SCALE);
1720         gpu_get_print("GL_POST_CONVOLUTION_ALPHA_SCALE", GL_POST_CONVOLUTION_ALPHA_SCALE);
1721         gpu_get_print("GL_PROJECTION_MATRIX", GL_PROJECTION_MATRIX);
1722         gpu_get_print("GL_PROJECTION_STACK_DEPTH", GL_PROJECTION_STACK_DEPTH);
1723         gpu_get_print("GL_READ_BUFFER", GL_READ_BUFFER);
1724         gpu_get_print("GL_RED_BIAS", GL_RED_BIAS);
1725         gpu_get_print("GL_RED_BITS", GL_RED_BITS);
1726         gpu_get_print("GL_RED_SCALE", GL_RED_SCALE);
1727         gpu_get_print("GL_RENDER_MODE", GL_RENDER_MODE);
1728         gpu_get_print("GL_RESCALE_NORMAL", GL_RESCALE_NORMAL);
1729         gpu_get_print("GL_RGBA_MODE", GL_RGBA_MODE);
1730         gpu_get_print("GL_SAMPLE_BUFFERS", GL_SAMPLE_BUFFERS);
1731         gpu_get_print("GL_SAMPLE_COVERAGE_VALUE", GL_SAMPLE_COVERAGE_VALUE);
1732         gpu_get_print("GL_SAMPLE_COVERAGE_INVERT", GL_SAMPLE_COVERAGE_INVERT);
1733         gpu_get_print("GL_SAMPLES", GL_SAMPLES);
1734         gpu_get_print("GL_SCISSOR_BOX", GL_SCISSOR_BOX);
1735         gpu_get_print("GL_SCISSOR_TEST", GL_SCISSOR_TEST);
1736         gpu_get_print("GL_SECONDARY_COLOR_ARRAY", GL_SECONDARY_COLOR_ARRAY);
1737         gpu_get_print("GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING", GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING);
1738         gpu_get_print("GL_SECONDARY_COLOR_ARRAY_SIZE", GL_SECONDARY_COLOR_ARRAY_SIZE);
1739         gpu_get_print("GL_SECONDARY_COLOR_ARRAY_STRIDE", GL_SECONDARY_COLOR_ARRAY_STRIDE);
1740         gpu_get_print("GL_SECONDARY_COLOR_ARRAY_TYPE", GL_SECONDARY_COLOR_ARRAY_TYPE);
1741         gpu_get_print("GL_SELECTION_BUFFER_SIZE", GL_SELECTION_BUFFER_SIZE);
1742         gpu_get_print("GL_SEPARABLE_2D", GL_SEPARABLE_2D);
1743         gpu_get_print("GL_SHADE_MODEL", GL_SHADE_MODEL);
1744         gpu_get_print("GL_SMOOTH_LINE_WIDTH_RANGE", GL_SMOOTH_LINE_WIDTH_RANGE);
1745         gpu_get_print("GL_SMOOTH_LINE_WIDTH_GRANULARITY", GL_SMOOTH_LINE_WIDTH_GRANULARITY);
1746         gpu_get_print("GL_SMOOTH_POINT_SIZE_RANGE", GL_SMOOTH_POINT_SIZE_RANGE);
1747         gpu_get_print("GL_SMOOTH_POINT_SIZE_GRANULARITY", GL_SMOOTH_POINT_SIZE_GRANULARITY);
1748         gpu_get_print("GL_STENCIL_BACK_FAIL", GL_STENCIL_BACK_FAIL);
1749         gpu_get_print("GL_STENCIL_BACK_FUNC", GL_STENCIL_BACK_FUNC);
1750         gpu_get_print("GL_STENCIL_BACK_PASS_DEPTH_FAIL", GL_STENCIL_BACK_PASS_DEPTH_FAIL);
1751         gpu_get_print("GL_STENCIL_BACK_PASS_DEPTH_PASS", GL_STENCIL_BACK_PASS_DEPTH_PASS);
1752         gpu_get_print("GL_STENCIL_BACK_REF", GL_STENCIL_BACK_REF);
1753         gpu_get_print("GL_STENCIL_BACK_VALUE_MASK", GL_STENCIL_BACK_VALUE_MASK);
1754         gpu_get_print("GL_STENCIL_BACK_WRITEMASK", GL_STENCIL_BACK_WRITEMASK);
1755         gpu_get_print("GL_STENCIL_BITS", GL_STENCIL_BITS);
1756         gpu_get_print("GL_STENCIL_CLEAR_VALUE", GL_STENCIL_CLEAR_VALUE);
1757         gpu_get_print("GL_STENCIL_FAIL", GL_STENCIL_FAIL);
1758         gpu_get_print("GL_STENCIL_FUNC", GL_STENCIL_FUNC);
1759         gpu_get_print("GL_STENCIL_PASS_DEPTH_FAIL", GL_STENCIL_PASS_DEPTH_FAIL);
1760         gpu_get_print("GL_STENCIL_PASS_DEPTH_PASS", GL_STENCIL_PASS_DEPTH_PASS);
1761         gpu_get_print("GL_STENCIL_REF", GL_STENCIL_REF);
1762         gpu_get_print("GL_STENCIL_TEST", GL_STENCIL_TEST);
1763         gpu_get_print("GL_STENCIL_VALUE_MASK", GL_STENCIL_VALUE_MASK);
1764         gpu_get_print("GL_STENCIL_WRITEMASK", GL_STENCIL_WRITEMASK);
1765         gpu_get_print("GL_STEREO", GL_STEREO);
1766         gpu_get_print("GL_SUBPIXEL_BITS", GL_SUBPIXEL_BITS);
1767         gpu_get_print("GL_TEXTURE_1D", GL_TEXTURE_1D);
1768         gpu_get_print("GL_TEXTURE_BINDING_1D", GL_TEXTURE_BINDING_1D);
1769         gpu_get_print("GL_TEXTURE_2D", GL_TEXTURE_2D);
1770         gpu_get_print("GL_TEXTURE_BINDING_2D", GL_TEXTURE_BINDING_2D);
1771         gpu_get_print("GL_TEXTURE_3D", GL_TEXTURE_3D);
1772         gpu_get_print("GL_TEXTURE_BINDING_3D", GL_TEXTURE_BINDING_3D);
1773         gpu_get_print("GL_TEXTURE_BINDING_CUBE_MAP", GL_TEXTURE_BINDING_CUBE_MAP);
1774         gpu_get_print("GL_TEXTURE_COMPRESSION_HINT", GL_TEXTURE_COMPRESSION_HINT);
1775         gpu_get_print("GL_TEXTURE_COORD_ARRAY", GL_TEXTURE_COORD_ARRAY);
1776         gpu_get_print("GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING", GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING);
1777         gpu_get_print("GL_TEXTURE_COORD_ARRAY_SIZE", GL_TEXTURE_COORD_ARRAY_SIZE);
1778         gpu_get_print("GL_TEXTURE_COORD_ARRAY_STRIDE", GL_TEXTURE_COORD_ARRAY_STRIDE);
1779         gpu_get_print("GL_TEXTURE_COORD_ARRAY_TYPE", GL_TEXTURE_COORD_ARRAY_TYPE);
1780         gpu_get_print("GL_TEXTURE_CUBE_MAP", GL_TEXTURE_CUBE_MAP);
1781         gpu_get_print("GL_TEXTURE_GEN_Q", GL_TEXTURE_GEN_Q);
1782         gpu_get_print("GL_TEXTURE_GEN_R", GL_TEXTURE_GEN_R);
1783         gpu_get_print("GL_TEXTURE_GEN_S", GL_TEXTURE_GEN_S);
1784         gpu_get_print("GL_TEXTURE_GEN_T", GL_TEXTURE_GEN_T);
1785         gpu_get_print("GL_TEXTURE_MATRIX", GL_TEXTURE_MATRIX);
1786         gpu_get_print("GL_TEXTURE_STACK_DEPTH", GL_TEXTURE_STACK_DEPTH);
1787         gpu_get_print("GL_TRANSPOSE_COLOR_MATRIX", GL_TRANSPOSE_COLOR_MATRIX);
1788         gpu_get_print("GL_TRANSPOSE_MODELVIEW_MATRIX", GL_TRANSPOSE_MODELVIEW_MATRIX);
1789         gpu_get_print("GL_TRANSPOSE_PROJECTION_MATRIX", GL_TRANSPOSE_PROJECTION_MATRIX);
1790         gpu_get_print("GL_TRANSPOSE_TEXTURE_MATRIX", GL_TRANSPOSE_TEXTURE_MATRIX);
1791         gpu_get_print("GL_UNPACK_ALIGNMENT", GL_UNPACK_ALIGNMENT);
1792         gpu_get_print("GL_UNPACK_IMAGE_HEIGHT", GL_UNPACK_IMAGE_HEIGHT);
1793         gpu_get_print("GL_UNPACK_LSB_FIRST", GL_UNPACK_LSB_FIRST);
1794         gpu_get_print("GL_UNPACK_ROW_LENGTH", GL_UNPACK_ROW_LENGTH);
1795         gpu_get_print("GL_UNPACK_SKIP_IMAGES", GL_UNPACK_SKIP_IMAGES);
1796         gpu_get_print("GL_UNPACK_SKIP_PIXELS", GL_UNPACK_SKIP_PIXELS);
1797         gpu_get_print("GL_UNPACK_SKIP_ROWS", GL_UNPACK_SKIP_ROWS);
1798         gpu_get_print("GL_UNPACK_SWAP_BYTES", GL_UNPACK_SWAP_BYTES);
1799         gpu_get_print("GL_VERTEX_ARRAY", GL_VERTEX_ARRAY);
1800         gpu_get_print("GL_VERTEX_ARRAY_BUFFER_BINDING", GL_VERTEX_ARRAY_BUFFER_BINDING);
1801         gpu_get_print("GL_VERTEX_ARRAY_SIZE", GL_VERTEX_ARRAY_SIZE);
1802         gpu_get_print("GL_VERTEX_ARRAY_STRIDE", GL_VERTEX_ARRAY_STRIDE);
1803         gpu_get_print("GL_VERTEX_ARRAY_TYPE", GL_VERTEX_ARRAY_TYPE);
1804         gpu_get_print("GL_VERTEX_PROGRAM_POINT_SIZE", GL_VERTEX_PROGRAM_POINT_SIZE);
1805         gpu_get_print("GL_VERTEX_PROGRAM_TWO_SIDE", GL_VERTEX_PROGRAM_TWO_SIDE);
1806         gpu_get_print("GL_VIEWPORT", GL_VIEWPORT);
1807         gpu_get_print("GL_ZOOM_X", GL_ZOOM_X);
1808         gpu_get_print("GL_ZOOM_Y", GL_ZOOM_Y);
1809 }
1810