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