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