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