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