Sync with released version for TIZEN 1.0 demo
[platform/core/uifw/coregl.git] / src / coregl_fastpath_gl.c
1 #include "coregl_fastpath.h"
2
3 #include <stdlib.h>
4
5 //----------------------------------------------------------------//
6 //                                                                //
7 //                      Fastpath GL Functions                     //
8 // The functions have prefix 'fpgl_' for (fastpath gl)            //
9 //                                                                //
10 //----------------------------------------------------------------//
11
12 #define CURR_STATE_COMPARE(curr_state, state ) \
13    if ((current_ctx->curr_state[0]) != (state))
14
15 #define DEFINE_FAST_GL_FUNC() \
16    GLThreadState *tstate = NULL; \
17    GLGlueContext *current_ctx = NULL;
18
19 #define INIT_FAST_GL_FUNC() \
20    tstate = get_current_thread_state(); \
21    AST(tstate != NULL); \
22    AST(tstate->cstate != NULL); \
23    current_ctx = (GLGlueContext *)tstate->cstate->data; \
24    AST(current_ctx != NULL);
25
26 #define GET_REAL_OBJ(type, glue_handle, real_handle) \
27         _get_real_obj(current_ctx->sostate, type, glue_handle, real_handle)
28
29 static inline int
30 _get_real_obj(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_handle, GLuint *real_handle)
31 {
32         if (glue_handle == 0)
33         {
34                 *real_handle = 0;
35         }
36         else
37         {
38                 AST(sostate != NULL);
39                 *real_handle = sostate_get_object(sostate, type, glue_handle);
40                 if (*real_handle == 0)
41                         return 0;
42         }
43         return 1;
44 }
45
46 static void
47 _set_gl_error(GLenum error)
48 {
49         GLenum glerror = GL_NONE;
50         DEFINE_FAST_GL_FUNC();
51         INIT_FAST_GL_FUNC();
52
53         glerror = _sym_glGetError();
54
55         if (current_ctx->gl_error == GL_NO_ERROR &&
56             glerror == GL_NO_ERROR &&
57             error != GL_NO_ERROR)
58         {
59                 current_ctx->gl_error = error;
60         }
61 }
62
63 GLenum
64 fpgl_glGetError(void)
65 {
66         GLenum ret = GL_NONE;
67
68         DEFINE_FAST_GL_FUNC();
69         _COREGL_FAST_FUNC_BEGIN();
70         INIT_FAST_GL_FUNC();
71
72         if (current_ctx->gl_error != GL_NO_ERROR)
73         {
74                 ret = current_ctx->gl_error;
75         }
76         else
77         {
78                 ret = _sym_glGetError();
79         }
80         goto finish;
81
82 finish:
83         _COREGL_FAST_FUNC_END();
84         return ret;
85 }
86
87 ////////////////////////////////////////////////////////////////////////
88
89 void
90 fpgl_glActiveTexture(GLenum texture)
91 {
92         DEFINE_FAST_GL_FUNC();
93         _COREGL_FAST_FUNC_BEGIN();
94         INIT_FAST_GL_FUNC();
95
96         CURR_STATE_COMPARE(gl_active_texture, texture)
97         {
98                 _sym_glActiveTexture(texture);
99
100                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
101
102                 current_ctx->_tex_flag1 |= FLAG_BIT_1;
103                 current_ctx->gl_active_texture[0] = texture;
104         }
105         goto finish;
106
107 finish:
108         _COREGL_FAST_FUNC_END();
109 }
110
111
112 void
113 fpgl_glGenTextures(GLsizei n, GLuint* textures)
114 {
115         int i;
116         GLuint *objid_array = NULL;
117
118         DEFINE_FAST_GL_FUNC();
119         _COREGL_FAST_FUNC_BEGIN();
120         INIT_FAST_GL_FUNC();
121
122         if (textures == NULL) goto finish;
123
124         AST(current_ctx->sostate != NULL);
125
126         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
127
128         _sym_glGenTextures(n, objid_array);
129
130         for (i = 0; i < n; i++)
131         {
132                 textures[i] = sostate_create_object(current_ctx->sostate, GL_OBJECT_TYPE_TEXTURE, objid_array[i]);
133         }
134
135         goto finish;
136
137 finish:
138         if (objid_array != NULL)
139         {
140                 free(objid_array);
141                 objid_array = NULL;
142         }
143         _COREGL_FAST_FUNC_END();
144 }
145
146
147 void
148 fpgl_glBindTexture(GLenum target, GLuint texture)
149 {
150         int active_idx;
151         GLuint real_obj;
152
153         DEFINE_FAST_GL_FUNC();
154         _COREGL_FAST_FUNC_BEGIN();
155         INIT_FAST_GL_FUNC();
156
157         active_idx = current_ctx->gl_active_texture[0] - GL_TEXTURE0;
158
159         if (GET_REAL_OBJ(GL_OBJECT_TYPE_TEXTURE, texture, &real_obj) != 1)
160         {
161                 _set_gl_error(GL_OUT_OF_MEMORY);
162                 goto finish;
163         }
164
165         if (target == GL_TEXTURE_2D)
166         {
167                 if (current_ctx->gl_tex_2d_state[active_idx] != real_obj)
168                 {
169                         _sym_glBindTexture(target, real_obj);
170
171                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
172
173                         current_ctx->_tex_flag1 |= FLAG_BIT_3;
174
175                         current_ctx->gl_tex_2d_state[active_idx] = real_obj;
176                 }
177         }
178         else if (target == GL_TEXTURE_CUBE_MAP)
179         {
180                 if (current_ctx->gl_tex_cube_state[active_idx] != real_obj)
181                 {
182                         _sym_glBindTexture(target, real_obj);
183
184                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
185
186                         current_ctx->_tex_flag1 |= FLAG_BIT_4;
187
188                         current_ctx->gl_tex_cube_state[active_idx] = real_obj;
189                 }
190         }
191         goto finish;
192
193 finish:
194         _COREGL_FAST_FUNC_END();
195 }
196
197
198 void
199 fpgl_glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
200 {
201         GLuint real_obj;
202
203         DEFINE_FAST_GL_FUNC();
204         _COREGL_FAST_FUNC_BEGIN();
205         INIT_FAST_GL_FUNC();
206
207         if (GET_REAL_OBJ(GL_OBJECT_TYPE_TEXTURE, texture, &real_obj) != 1)
208         {
209                 _set_gl_error(GL_OUT_OF_MEMORY);
210                 goto finish;
211         }
212
213         _sym_glFramebufferTexture2D(target, attachment, textarget, real_obj, level);
214
215         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
216         goto finish;
217
218 finish:
219         _COREGL_FAST_FUNC_END();
220 }
221
222 void
223 fpgl_glFramebufferTexture2DMultisampleEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples)
224 {
225         GLuint real_obj;
226
227         DEFINE_FAST_GL_FUNC();
228         _COREGL_FAST_FUNC_BEGIN();
229         INIT_FAST_GL_FUNC();
230
231         if (GET_REAL_OBJ(GL_OBJECT_TYPE_TEXTURE, texture, &real_obj) != 1)
232         {
233                 _set_gl_error(GL_OUT_OF_MEMORY);
234                 goto finish;
235         }
236
237         _sym_glFramebufferTexture2DMultisampleEXT(target, attachment, textarget, real_obj, level, samples);
238
239         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
240         goto finish;
241
242 finish:
243         _COREGL_FAST_FUNC_END();
244 }
245
246 GLboolean
247 fpgl_glIsTexture(GLuint texture)
248 {
249         GLboolean ret;
250         GLuint real_obj;
251
252         DEFINE_FAST_GL_FUNC();
253         _COREGL_FAST_FUNC_BEGIN();
254         INIT_FAST_GL_FUNC();
255
256         if (GET_REAL_OBJ(GL_OBJECT_TYPE_TEXTURE, texture, &real_obj) != 1)
257         {
258                 ret = GL_FALSE;
259                 goto finish;
260         }
261
262         ret = _sym_glIsTexture(real_obj);
263
264         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
265
266         goto finish;
267
268 finish:
269         _COREGL_FAST_FUNC_END();
270         return ret;
271 }
272
273
274 void
275 fpgl_glDeleteTextures(GLsizei n, const GLuint* textures)
276 {
277         int i, j;
278         GLuint *objid_array = NULL;
279
280         DEFINE_FAST_GL_FUNC();
281         _COREGL_FAST_FUNC_BEGIN();
282         INIT_FAST_GL_FUNC();
283
284         if (textures == NULL) goto finish;
285
286         AST(current_ctx->sostate != NULL);
287
288         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
289         {
290                 int real_n = 0;
291
292                 for (i = 0; i < n; i++)
293                 {
294                         int real_objid = _COREGL_INT_INIT_VALUE;
295                         if (textures[i] == 0) continue;
296
297                         real_objid = sostate_get_object(current_ctx->sostate, GL_OBJECT_TYPE_TEXTURE, textures[i]);
298                         if (real_objid == 0) continue;
299
300                         sostate_remove_object(current_ctx->sostate, GL_OBJECT_TYPE_TEXTURE, textures[i]);
301                         objid_array[real_n++] = real_objid;
302                 }
303
304                 _sym_glDeleteTextures(real_n, objid_array);
305                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
306
307                 for (i = 0; i < real_n; i++)
308                 {
309                         for (j = 0; j < current_ctx->gl_num_tex_units[0]; j++)
310                         {
311                                 if (current_ctx->gl_tex_2d_state[j] == objid_array[i])
312                                         current_ctx->gl_tex_2d_state[j] = 0;
313                                 if (current_ctx->gl_tex_cube_state[j] == objid_array[i])
314                                         current_ctx->gl_tex_cube_state[j] = 0;
315                         }
316                 }
317         }
318
319         goto finish;
320
321 finish:
322         if (objid_array != NULL)
323         {
324                 free(objid_array);
325                 objid_array = NULL;
326         }
327         _COREGL_FAST_FUNC_END();
328 }
329
330 ////////////////////////////////////////////////////////////////////////
331
332 void
333 fpgl_glGenBuffers(GLsizei n, GLuint* buffers)
334 {
335         int i;
336         GLuint *objid_array = NULL;
337
338         DEFINE_FAST_GL_FUNC();
339         _COREGL_FAST_FUNC_BEGIN();
340         INIT_FAST_GL_FUNC();
341
342         if (buffers == NULL) goto finish;
343
344         AST(current_ctx->sostate != NULL);
345
346         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
347
348         _sym_glGenBuffers(n, objid_array);
349
350         for (i = 0; i < n; i++)
351         {
352                 buffers[i] = sostate_create_object(current_ctx->sostate, GL_OBJECT_TYPE_BUFFER, objid_array[i]);
353         }
354
355         goto finish;
356
357 finish:
358         if (objid_array != NULL)
359         {
360                 free(objid_array);
361                 objid_array = NULL;
362         }
363         _COREGL_FAST_FUNC_END();
364 }
365
366
367 void
368 fpgl_glBindBuffer(GLenum target, GLuint buffer)
369 {
370         GLuint real_obj;
371
372         DEFINE_FAST_GL_FUNC();
373         _COREGL_FAST_FUNC_BEGIN();
374         INIT_FAST_GL_FUNC();
375
376         if (GET_REAL_OBJ(GL_OBJECT_TYPE_BUFFER, buffer, &real_obj) != 1)
377         {
378                 _set_gl_error(GL_OUT_OF_MEMORY);
379                 goto finish;
380         }
381
382         if (target == GL_ARRAY_BUFFER)
383         {
384                 CURR_STATE_COMPARE(gl_array_buffer_binding, real_obj)
385                 {
386                         _sym_glBindBuffer(target, real_obj);
387
388                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
389
390                         if (real_obj == 0)
391                                 current_ctx->_bind_flag &= (~FLAG_BIT_0);
392                         else
393                                 current_ctx->_bind_flag |= FLAG_BIT_0;
394                         current_ctx->gl_array_buffer_binding[0] = real_obj;
395                 }
396         }
397         else if (target == GL_ELEMENT_ARRAY_BUFFER)
398         {
399                 CURR_STATE_COMPARE(gl_element_array_buffer_binding, real_obj)
400                 {
401                         _sym_glBindBuffer(target, real_obj);
402                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
403
404                         if (real_obj == 0)
405                                 current_ctx->_bind_flag &= (~FLAG_BIT_1);
406                         else
407                                 current_ctx->_bind_flag |= FLAG_BIT_1;
408                         current_ctx->gl_element_array_buffer_binding[0] = real_obj;
409                 }
410         }
411         else
412         {
413                 // For error recording
414                 _sym_glBindBuffer(target, real_obj);
415                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
416         }
417         goto finish;
418
419 finish:
420         _COREGL_FAST_FUNC_END();
421 }
422
423 GLboolean
424 fpgl_glIsBuffer(GLuint buffer)
425 {
426         GLboolean ret;
427         GLuint real_obj;
428
429         DEFINE_FAST_GL_FUNC();
430         _COREGL_FAST_FUNC_BEGIN();
431         INIT_FAST_GL_FUNC();
432
433         if (GET_REAL_OBJ(GL_OBJECT_TYPE_BUFFER, buffer, &real_obj) != 1)
434         {
435                 ret = GL_FALSE;
436                 goto finish;
437         }
438
439         ret = _sym_glIsBuffer(real_obj);
440
441         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
442
443         goto finish;
444
445 finish:
446         _COREGL_FAST_FUNC_END();
447         return ret;
448 }
449
450
451 void
452 fpgl_glDeleteBuffers(GLsizei n, const GLuint* buffers)
453 {
454         int i;
455         GLuint *objid_array = NULL;
456
457         DEFINE_FAST_GL_FUNC();
458         _COREGL_FAST_FUNC_BEGIN();
459         INIT_FAST_GL_FUNC();
460
461         if (buffers == NULL) goto finish;
462
463         AST(current_ctx->sostate != NULL);
464
465         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
466         {
467                 int real_n = 0;
468
469                 for (i = 0; i < n; i++)
470                 {
471                         int real_objid = _COREGL_INT_INIT_VALUE;
472                         if (buffers[i] == 0) continue;
473
474                         real_objid = sostate_get_object(current_ctx->sostate, GL_OBJECT_TYPE_BUFFER, buffers[i]);
475                         if (real_objid == 0) continue;
476
477                         sostate_remove_object(current_ctx->sostate, GL_OBJECT_TYPE_BUFFER, buffers[i]);
478                         objid_array[real_n++] = real_objid;
479                 }
480
481                 _sym_glDeleteBuffers(real_n, objid_array);
482                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
483
484                 for (i = 0; i < real_n; i++)
485                 {
486                         if (current_ctx->gl_array_buffer_binding[0] == objid_array[i])
487                         {
488                                 current_ctx->_bind_flag &= (~FLAG_BIT_0);
489                                 current_ctx->gl_array_buffer_binding[0] = 0;
490                         }
491                         if (current_ctx->gl_element_array_buffer_binding[0] == objid_array[i])
492                         {
493                                 current_ctx->_bind_flag &= (~FLAG_BIT_1);
494                                 current_ctx->gl_element_array_buffer_binding[0] = 0;
495                         }
496                 }
497         }
498
499         goto finish;
500
501 finish:
502         if (objid_array != NULL)
503         {
504                 free(objid_array);
505                 objid_array = NULL;
506         }
507         _COREGL_FAST_FUNC_END();
508 }
509
510 //////////////////////////////////////////////////////////////////////////////////
511
512 void
513 fpgl_glGenFramebuffers(GLsizei n, GLuint* framebuffers)
514 {
515         int i;
516         GLuint *objid_array = NULL;
517
518         DEFINE_FAST_GL_FUNC();
519         _COREGL_FAST_FUNC_BEGIN();
520         INIT_FAST_GL_FUNC();
521
522         if (framebuffers == NULL) goto finish;
523
524         AST(current_ctx->sostate != NULL);
525
526         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
527
528         _sym_glGenFramebuffers(n, objid_array);
529
530         for (i = 0; i < n; i++)
531         {
532                 framebuffers[i] = sostate_create_object(current_ctx->sostate, GL_OBJECT_TYPE_FRAMEBUFFER, objid_array[i]);
533         }
534
535         goto finish;
536
537 finish:
538         if (objid_array != NULL)
539         {
540                 free(objid_array);
541                 objid_array = NULL;
542         }
543         _COREGL_FAST_FUNC_END();
544 }
545
546
547 void
548 fpgl_glBindFramebuffer(GLenum target, GLuint framebuffer)
549 {
550         GLuint real_obj;
551
552         DEFINE_FAST_GL_FUNC();
553         _COREGL_FAST_FUNC_BEGIN();
554         INIT_FAST_GL_FUNC();
555
556         if (GET_REAL_OBJ(GL_OBJECT_TYPE_FRAMEBUFFER, framebuffer, &real_obj) != 1)
557         {
558                 _set_gl_error(GL_OUT_OF_MEMORY);
559                 goto finish;
560         }
561
562         if (target == GL_FRAMEBUFFER)
563         {
564                 CURR_STATE_COMPARE(gl_framebuffer_binding, real_obj)
565                 {
566                         _sym_glBindFramebuffer(target, real_obj);
567                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
568
569                         if (real_obj == 0)
570                                 current_ctx->_bind_flag &= (~FLAG_BIT_2);
571                         else
572                                 current_ctx->_bind_flag |= FLAG_BIT_2;
573                         current_ctx->gl_framebuffer_binding[0] = real_obj;
574                 }
575         }
576         else
577         {
578                 // For error recording
579                 _sym_glBindFramebuffer(target, real_obj);
580                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
581
582         }
583         goto finish;
584
585 finish:
586         _COREGL_FAST_FUNC_END();
587 }
588
589 GLboolean
590 fpgl_glIsFramebuffer(GLuint framebuffer)
591 {
592         GLboolean ret;
593         GLuint real_obj;
594
595         DEFINE_FAST_GL_FUNC();
596         _COREGL_FAST_FUNC_BEGIN();
597         INIT_FAST_GL_FUNC();
598
599         if (GET_REAL_OBJ(GL_OBJECT_TYPE_FRAMEBUFFER, framebuffer, &real_obj) != 1)
600         {
601                 ret = GL_FALSE;
602                 goto finish;
603         }
604
605         ret = _sym_glIsFramebuffer(real_obj);
606
607         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
608
609         goto finish;
610
611 finish:
612         _COREGL_FAST_FUNC_END();
613         return ret;
614 }
615
616
617 void
618 fpgl_glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
619 {
620         int i;
621         GLuint *objid_array = NULL;
622
623         DEFINE_FAST_GL_FUNC();
624         _COREGL_FAST_FUNC_BEGIN();
625         INIT_FAST_GL_FUNC();
626
627         if (framebuffers == NULL) goto finish;
628
629         AST(current_ctx->sostate != NULL);
630
631         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
632         {
633                 int real_n = 0;
634
635                 for (i = 0; i < n; i++)
636                 {
637                         int real_objid = _COREGL_INT_INIT_VALUE;
638                         if (framebuffers[i] == 0) continue;
639
640                         real_objid = sostate_get_object(current_ctx->sostate, GL_OBJECT_TYPE_FRAMEBUFFER, framebuffers[i]);
641                         if (real_objid == 0) continue;
642
643                         sostate_remove_object(current_ctx->sostate, GL_OBJECT_TYPE_FRAMEBUFFER, framebuffers[i]);
644                         objid_array[real_n++] = real_objid;
645                 }
646
647                 _sym_glDeleteFramebuffers(real_n, objid_array);
648                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
649
650                 for (i = 0; i < real_n; i++)
651                 {
652                         if (current_ctx->gl_framebuffer_binding[0] == framebuffers[i])
653                         {
654                                 current_ctx->_bind_flag &= (~FLAG_BIT_2);
655                                 current_ctx->gl_framebuffer_binding[0] = 0;
656                         }
657                 }
658         }
659
660         goto finish;
661
662 finish:
663         if (objid_array != NULL)
664         {
665                 free(objid_array);
666                 objid_array = NULL;
667         }
668         _COREGL_FAST_FUNC_END();
669 }
670
671 //////////////////////////////////////////////////////////////////////////////////
672
673 void
674 fpgl_glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
675 {
676         int i;
677         GLuint *objid_array = NULL;
678
679         DEFINE_FAST_GL_FUNC();
680         _COREGL_FAST_FUNC_BEGIN();
681         INIT_FAST_GL_FUNC();
682
683         if (renderbuffers == NULL) goto finish;
684
685         AST(current_ctx->sostate != NULL);
686
687         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
688
689         _sym_glGenRenderbuffers(n, objid_array);
690
691         for (i = 0; i < n; i++)
692         {
693                 renderbuffers[i] = sostate_create_object(current_ctx->sostate, GL_OBJECT_TYPE_RENDERBUFFER, objid_array[i]);
694         }
695
696         goto finish;
697
698 finish:
699         if (objid_array != NULL)
700         {
701                 free(objid_array);
702                 objid_array = NULL;
703         }
704         _COREGL_FAST_FUNC_END();
705 }
706
707
708 void
709 fpgl_glBindRenderbuffer(GLenum target, GLuint renderbuffer)
710 {
711         GLuint real_obj;
712
713         DEFINE_FAST_GL_FUNC();
714         _COREGL_FAST_FUNC_BEGIN();
715         INIT_FAST_GL_FUNC();
716
717         if (GET_REAL_OBJ(GL_OBJECT_TYPE_RENDERBUFFER, renderbuffer, &real_obj) != 1)
718         {
719                 _set_gl_error(GL_OUT_OF_MEMORY);
720                 goto finish;
721         }
722
723         if (target == GL_RENDERBUFFER)
724         {
725                 CURR_STATE_COMPARE(gl_renderbuffer_binding, real_obj)
726                 {
727                         _sym_glBindRenderbuffer(target, real_obj);
728                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
729
730                         if (real_obj == 0)
731                                 current_ctx->_bind_flag &= (~FLAG_BIT_3);
732                         else
733                                 current_ctx->_bind_flag |= FLAG_BIT_3;
734                         current_ctx->gl_renderbuffer_binding[0] = real_obj;
735                 }
736         }
737         else
738         {
739                 // For error recording
740                 _sym_glBindRenderbuffer(target, real_obj);
741                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
742         }
743         goto finish;
744
745 finish:
746         _COREGL_FAST_FUNC_END();
747 }
748
749 void
750 fpgl_glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
751 {
752         GLuint real_obj;
753
754         DEFINE_FAST_GL_FUNC();
755         _COREGL_FAST_FUNC_BEGIN();
756         INIT_FAST_GL_FUNC();
757
758         if (GET_REAL_OBJ(GL_OBJECT_TYPE_RENDERBUFFER, renderbuffer, &real_obj) != 1)
759         {
760                 _set_gl_error(GL_OUT_OF_MEMORY);
761                 goto finish;
762         }
763
764         _sym_glFramebufferRenderbuffer(target, attachment, renderbuffertarget, real_obj);
765
766         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
767
768         goto finish;
769
770 finish:
771         _COREGL_FAST_FUNC_END();
772 }
773
774 GLboolean
775 fpgl_glIsRenderbuffer(GLuint renderbuffer)
776 {
777         GLboolean ret;
778         GLuint real_obj;
779
780         DEFINE_FAST_GL_FUNC();
781         _COREGL_FAST_FUNC_BEGIN();
782         INIT_FAST_GL_FUNC();
783
784         if (GET_REAL_OBJ(GL_OBJECT_TYPE_RENDERBUFFER, renderbuffer, &real_obj) != 1)
785         {
786                 ret = GL_FALSE;
787                 goto finish;
788         }
789
790         ret = _sym_glIsRenderbuffer(real_obj);
791
792         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
793
794         goto finish;
795
796 finish:
797         _COREGL_FAST_FUNC_END();
798         return ret;
799 }
800
801
802 void
803 fpgl_glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
804 {
805         int i;
806         GLuint *objid_array = NULL;
807
808         DEFINE_FAST_GL_FUNC();
809         _COREGL_FAST_FUNC_BEGIN();
810         INIT_FAST_GL_FUNC();
811
812         if (renderbuffers == NULL) goto finish;
813
814         AST(current_ctx->sostate != NULL);
815
816         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
817         {
818                 int real_n = 0;
819
820                 for (i = 0; i < n; i++)
821                 {
822                         int real_objid = _COREGL_INT_INIT_VALUE;
823                         if (renderbuffers[i] == 0) continue;
824
825                         real_objid = sostate_get_object(current_ctx->sostate, GL_OBJECT_TYPE_RENDERBUFFER, renderbuffers[i]);
826                         if (real_objid == 0) continue;
827
828                         sostate_remove_object(current_ctx->sostate, GL_OBJECT_TYPE_RENDERBUFFER, renderbuffers[i]);
829                         objid_array[real_n++] = real_objid;
830                 }
831
832                 _sym_glDeleteRenderbuffers(real_n, objid_array);
833                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
834
835                 for (i = 0; i < real_n; i++)
836                 {
837                         if (current_ctx->gl_renderbuffer_binding[0] == renderbuffers[i])
838                         {
839                                 current_ctx->_bind_flag &= (~FLAG_BIT_3);
840                                 current_ctx->gl_renderbuffer_binding[0] = 0;
841                         }
842                 }
843         }
844
845         goto finish;
846
847 finish:
848         if (objid_array != NULL)
849         {
850                 free(objid_array);
851                 objid_array = NULL;
852         }
853         _COREGL_FAST_FUNC_END();
854 }
855
856 //////////////////////////////////////////////////////////////////////////////////
857
858 GLuint
859 fpgl_glCreateProgram(void)
860 {
861         GLuint ret = _COREGL_INT_INIT_VALUE;
862         GLuint real_obj = _COREGL_INT_INIT_VALUE;
863
864         DEFINE_FAST_GL_FUNC();
865         _COREGL_FAST_FUNC_BEGIN();
866         INIT_FAST_GL_FUNC();
867
868         AST(current_ctx->sostate != NULL);
869
870         real_obj = _sym_glCreateProgram();
871         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
872
873         ret = sostate_create_object(current_ctx->sostate, GL_OBJECT_TYPE_PROGRAM, real_obj);
874
875         goto finish;
876
877 finish:
878         _COREGL_FAST_FUNC_END();
879         return ret;
880 }
881
882 GLuint
883 fpgl_glCreateShader(GLenum type)
884 {
885         GLuint ret = _COREGL_INT_INIT_VALUE;
886         GLuint real_obj = _COREGL_INT_INIT_VALUE;
887
888         DEFINE_FAST_GL_FUNC();
889         _COREGL_FAST_FUNC_BEGIN();
890         INIT_FAST_GL_FUNC();
891
892         AST(current_ctx->sostate != NULL);
893
894         real_obj = _sym_glCreateShader(type);
895         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
896
897         ret = sostate_create_object(current_ctx->sostate, GL_OBJECT_TYPE_PROGRAM, real_obj);
898
899         goto finish;
900
901 finish:
902         _COREGL_FAST_FUNC_END();
903         return ret;
904 }
905
906 void
907 fpgl_glShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length)
908 {
909         GLuint real_obj;
910
911         DEFINE_FAST_GL_FUNC();
912         _COREGL_FAST_FUNC_BEGIN();
913         INIT_FAST_GL_FUNC();
914
915         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1)
916         {
917                 _set_gl_error(GL_INVALID_VALUE);
918                 goto finish;
919         }
920         _sym_glShaderSource(real_obj, count, string, length);
921         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
922         goto finish;
923
924 finish:
925         _COREGL_FAST_FUNC_END();
926 }
927
928 void
929 fpgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
930 {
931         int i;
932         GLuint *objid_array = NULL;
933
934         DEFINE_FAST_GL_FUNC();
935         _COREGL_FAST_FUNC_BEGIN();
936         INIT_FAST_GL_FUNC();
937
938         if (shaders == NULL) goto finish;
939
940         AST(current_ctx->sostate != NULL);
941
942         objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
943
944         for (i = 0; i < n; i++)
945         {
946                 if (shaders[i] == 0) continue;
947                 objid_array[i] = sostate_get_object(current_ctx->sostate, GL_OBJECT_TYPE_PROGRAM, shaders[i]);
948         }
949
950 #ifndef _COREGL_DESKTOP_GL
951         _sym_glShaderBinary(n, objid_array, binaryformat, binary, length);
952         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
953 #else
954 // FIXME: need to dlsym/getprocaddress for this
955         /*
956            n = binaryformat = length = 0;
957            shaders = binary = 0;
958         */
959 #endif
960         goto finish;
961
962 finish:
963         if (objid_array != NULL)
964         {
965                 free(objid_array);
966                 objid_array = NULL;
967         }
968
969         _COREGL_FAST_FUNC_END();
970 }
971
972 void
973 fpgl_glCompileShader(GLuint shader)
974 {
975         GLuint real_obj;
976
977         DEFINE_FAST_GL_FUNC();
978         _COREGL_FAST_FUNC_BEGIN();
979         INIT_FAST_GL_FUNC();
980
981         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1)
982         {
983                 _set_gl_error(GL_INVALID_VALUE);
984                 goto finish;
985         }
986
987         _sym_glCompileShader(real_obj);
988         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
989         goto finish;
990
991 finish:
992         _COREGL_FAST_FUNC_END();
993 }
994
995 void
996 fpgl_glBindAttribLocation(GLuint program, GLuint index, const char* name)
997 {
998         GLuint real_obj;
999
1000         DEFINE_FAST_GL_FUNC();
1001         _COREGL_FAST_FUNC_BEGIN();
1002         INIT_FAST_GL_FUNC();
1003
1004         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1005         {
1006                 _set_gl_error(GL_INVALID_VALUE);
1007                 goto finish;
1008         }
1009
1010         _sym_glBindAttribLocation(real_obj, index, name);
1011         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1012         goto finish;
1013
1014 finish:
1015         _COREGL_FAST_FUNC_END();
1016 }
1017
1018 void
1019 fpgl_glAttachShader(GLuint program, GLuint shader)
1020 {
1021         GLuint real_obj_program;
1022         GLuint real_obj_shader;
1023
1024         DEFINE_FAST_GL_FUNC();
1025         _COREGL_FAST_FUNC_BEGIN();
1026         INIT_FAST_GL_FUNC();
1027
1028         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj_program) != 1 ||
1029             GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj_shader) != 1)
1030         {
1031                 _set_gl_error(GL_INVALID_VALUE);
1032                 goto finish;
1033         }
1034
1035         _sym_glAttachShader(real_obj_program, real_obj_shader);
1036         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1037         goto finish;
1038
1039 finish:
1040         _COREGL_FAST_FUNC_END();
1041 }
1042
1043 void
1044 fpgl_glDetachShader(GLuint program, GLuint shader)
1045 {
1046         GLuint real_obj_program;
1047         GLuint real_obj_shader;
1048
1049         DEFINE_FAST_GL_FUNC();
1050         _COREGL_FAST_FUNC_BEGIN();
1051         INIT_FAST_GL_FUNC();
1052
1053         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj_program) != 1 ||
1054             GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj_shader) != 1)
1055         {
1056                 _set_gl_error(GL_INVALID_VALUE);
1057                 goto finish;
1058         }
1059
1060         _sym_glDetachShader(real_obj_program, real_obj_shader);
1061         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1062         goto finish;
1063
1064 finish:
1065         _COREGL_FAST_FUNC_END();
1066 }
1067
1068 GLboolean
1069 fpgl_glIsShader(GLuint shader)
1070 {
1071         GLboolean ret;
1072         GLuint real_obj;
1073
1074         DEFINE_FAST_GL_FUNC();
1075         _COREGL_FAST_FUNC_BEGIN();
1076         INIT_FAST_GL_FUNC();
1077
1078         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1)
1079         {
1080                 ret = GL_FALSE;
1081                 goto finish;
1082         }
1083
1084         ret = _sym_glIsShader(real_obj);
1085         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1086         goto finish;
1087
1088 finish:
1089         _COREGL_FAST_FUNC_END();
1090         return ret;
1091 }
1092
1093 GLboolean
1094 fpgl_glIsProgram(GLuint program)
1095 {
1096         GLboolean ret;
1097         GLuint real_obj;
1098
1099         DEFINE_FAST_GL_FUNC();
1100         _COREGL_FAST_FUNC_BEGIN();
1101         INIT_FAST_GL_FUNC();
1102
1103         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1104         {
1105                 ret = GL_FALSE;
1106                 goto finish;
1107         }
1108
1109         ret = _sym_glIsProgram(real_obj);
1110         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1111         goto finish;
1112
1113 finish:
1114         _COREGL_FAST_FUNC_END();
1115         return ret;
1116 }
1117
1118 void
1119 fpgl_glLinkProgram(GLuint program)
1120 {
1121         GLuint real_obj;
1122
1123         DEFINE_FAST_GL_FUNC();
1124         _COREGL_FAST_FUNC_BEGIN();
1125         INIT_FAST_GL_FUNC();
1126
1127         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1128         {
1129                 _set_gl_error(GL_INVALID_VALUE);
1130                 goto finish;
1131         }
1132
1133         _sym_glLinkProgram(real_obj);
1134         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1135         goto finish;
1136
1137 finish:
1138         _COREGL_FAST_FUNC_END();
1139 }
1140
1141 void
1142 fpgl_glValidateProgram(GLuint program)
1143 {
1144         GLuint real_obj;
1145
1146         DEFINE_FAST_GL_FUNC();
1147         _COREGL_FAST_FUNC_BEGIN();
1148         INIT_FAST_GL_FUNC();
1149
1150         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1151         {
1152                 _set_gl_error(GL_INVALID_VALUE);
1153                 goto finish;
1154         }
1155
1156         _sym_glValidateProgram(real_obj);
1157         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1158         goto finish;
1159
1160 finish:
1161         _COREGL_FAST_FUNC_END();
1162 }
1163
1164 void
1165 fpgl_glUseProgram(GLuint program)
1166 {
1167         GLuint real_obj;
1168
1169         DEFINE_FAST_GL_FUNC();
1170         _COREGL_FAST_FUNC_BEGIN();
1171         INIT_FAST_GL_FUNC();
1172
1173         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1174         {
1175                 _set_gl_error(GL_INVALID_VALUE);
1176                 goto finish;
1177         }
1178
1179         CURR_STATE_COMPARE(gl_current_program, real_obj)
1180         {
1181                 _sym_glUseProgram(real_obj);
1182
1183                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1184
1185                 current_ctx->_clear_flag1 |= FLAG_BIT_1;
1186                 current_ctx->gl_current_program[0] = real_obj;
1187         }
1188         goto finish;
1189
1190 finish:
1191         _COREGL_FAST_FUNC_END();
1192 }
1193
1194 void
1195 fpgl_glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
1196 {
1197         GLuint real_obj;
1198
1199         DEFINE_FAST_GL_FUNC();
1200         _COREGL_FAST_FUNC_BEGIN();
1201         INIT_FAST_GL_FUNC();
1202
1203         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1204         {
1205                 _set_gl_error(GL_INVALID_VALUE);
1206                 goto finish;
1207         }
1208
1209         _sym_glGetActiveAttrib(real_obj, index, bufsize, length, size, type, name);
1210         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1211         goto finish;
1212
1213 finish:
1214         _COREGL_FAST_FUNC_END();
1215 }
1216
1217 void
1218 fpgl_glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
1219 {
1220         GLuint real_obj;
1221
1222         DEFINE_FAST_GL_FUNC();
1223         _COREGL_FAST_FUNC_BEGIN();
1224         INIT_FAST_GL_FUNC();
1225
1226         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1227         {
1228                 _set_gl_error(GL_INVALID_VALUE);
1229                 goto finish;
1230         }
1231
1232         _sym_glGetActiveUniform(real_obj, index, bufsize, length, size, type, name);
1233         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1234         goto finish;
1235
1236 finish:
1237         _COREGL_FAST_FUNC_END();
1238 }
1239
1240 void
1241 fpgl_glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
1242 {
1243         int i;
1244         GLsizei real_count = _COREGL_INT_INIT_VALUE;
1245         GLuint real_obj;
1246
1247         DEFINE_FAST_GL_FUNC();
1248         _COREGL_FAST_FUNC_BEGIN();
1249         INIT_FAST_GL_FUNC();
1250
1251         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1252         {
1253                 _set_gl_error(GL_INVALID_VALUE);
1254                 goto finish;
1255         }
1256
1257         _sym_glGetAttachedShaders(real_obj, maxcount, &real_count, shaders);
1258
1259         for (i = 0; i < real_count; i++)
1260         {
1261                 if (shaders[i] != 0)
1262                         shaders[i] = sostate_find_object(current_ctx->sostate, GL_OBJECT_TYPE_PROGRAM, shaders[i]);
1263         }
1264         if (count != NULL) *count = real_count;
1265
1266         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1267         goto finish;
1268
1269 finish:
1270         _COREGL_FAST_FUNC_END();
1271 }
1272
1273 int
1274 fpgl_glGetAttribLocation(GLuint program, const char* name)
1275 {
1276         int ret = _COREGL_INT_INIT_VALUE;
1277         GLuint real_obj;
1278
1279         DEFINE_FAST_GL_FUNC();
1280         _COREGL_FAST_FUNC_BEGIN();
1281         INIT_FAST_GL_FUNC();
1282
1283         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1284         {
1285                 _set_gl_error(GL_INVALID_VALUE);
1286                 goto finish;
1287         }
1288
1289         ret = _sym_glGetAttribLocation(real_obj, name);
1290         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1291         goto finish;
1292
1293 finish:
1294         _COREGL_FAST_FUNC_END();
1295         return ret;
1296 }
1297
1298 void
1299 fpgl_glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
1300 {
1301         GLuint real_obj;
1302
1303         DEFINE_FAST_GL_FUNC();
1304         _COREGL_FAST_FUNC_BEGIN();
1305         INIT_FAST_GL_FUNC();
1306
1307         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1)
1308         {
1309                 _set_gl_error(GL_INVALID_VALUE);
1310                 goto finish;
1311         }
1312
1313         _sym_glGetShaderiv(real_obj, pname, params);
1314         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1315         goto finish;
1316
1317 finish:
1318         _COREGL_FAST_FUNC_END();
1319 }
1320
1321 void
1322 fpgl_glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog)
1323 {
1324         GLuint real_obj;
1325
1326         DEFINE_FAST_GL_FUNC();
1327         _COREGL_FAST_FUNC_BEGIN();
1328         INIT_FAST_GL_FUNC();
1329
1330         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1)
1331         {
1332                 _set_gl_error(GL_INVALID_VALUE);
1333                 goto finish;
1334         }
1335
1336         _sym_glGetShaderInfoLog(real_obj, bufsize, length, infolog);
1337         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1338         goto finish;
1339
1340 finish:
1341         _COREGL_FAST_FUNC_END();
1342 }
1343
1344 void
1345 fpgl_glGetProgramiv(GLuint program, GLenum pname, GLint* params)
1346 {
1347         GLuint real_obj;
1348
1349         DEFINE_FAST_GL_FUNC();
1350         _COREGL_FAST_FUNC_BEGIN();
1351         INIT_FAST_GL_FUNC();
1352
1353         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1354         {
1355                 _set_gl_error(GL_INVALID_VALUE);
1356                 goto finish;
1357         }
1358
1359         _sym_glGetProgramiv(real_obj, pname, params);
1360         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1361         goto finish;
1362
1363 finish:
1364         _COREGL_FAST_FUNC_END();
1365 }
1366
1367 void
1368 fpgl_glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, char* infolog)
1369 {
1370         GLuint real_obj;
1371
1372         DEFINE_FAST_GL_FUNC();
1373         _COREGL_FAST_FUNC_BEGIN();
1374         INIT_FAST_GL_FUNC();
1375
1376         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1377         {
1378                 _set_gl_error(GL_INVALID_VALUE);
1379                 goto finish;
1380         }
1381
1382         _sym_glGetProgramInfoLog(real_obj, bufsize, length, infolog);
1383         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1384         goto finish;
1385
1386 finish:
1387         _COREGL_FAST_FUNC_END();
1388 }
1389
1390 void
1391 fpgl_glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, char* source)
1392 {
1393         GLuint real_obj;
1394
1395         DEFINE_FAST_GL_FUNC();
1396         _COREGL_FAST_FUNC_BEGIN();
1397         INIT_FAST_GL_FUNC();
1398
1399         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1)
1400         {
1401                 _set_gl_error(GL_INVALID_VALUE);
1402                 goto finish;
1403         }
1404
1405         _sym_glGetShaderSource(real_obj, bufsize, length, source);
1406         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1407         goto finish;
1408
1409 finish:
1410         _COREGL_FAST_FUNC_END();
1411 }
1412
1413 void
1414 fpgl_glGetUniformfv(GLuint program, GLint location, GLfloat* params)
1415 {
1416         GLuint real_obj;
1417
1418         DEFINE_FAST_GL_FUNC();
1419         _COREGL_FAST_FUNC_BEGIN();
1420         INIT_FAST_GL_FUNC();
1421
1422         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1423         {
1424                 _set_gl_error(GL_INVALID_VALUE);
1425                 goto finish;
1426         }
1427
1428         _sym_glGetUniformfv(real_obj, location, params);
1429         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1430         goto finish;
1431
1432 finish:
1433         _COREGL_FAST_FUNC_END();
1434 }
1435
1436 void
1437 fpgl_glGetUniformiv(GLuint program, GLint location, GLint* params)
1438 {
1439         GLuint real_obj;
1440
1441         DEFINE_FAST_GL_FUNC();
1442         _COREGL_FAST_FUNC_BEGIN();
1443         INIT_FAST_GL_FUNC();
1444
1445         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1446         {
1447                 _set_gl_error(GL_INVALID_VALUE);
1448                 goto finish;
1449         }
1450
1451         _sym_glGetUniformiv(real_obj, location, params);
1452         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1453         goto finish;
1454
1455 finish:
1456         _COREGL_FAST_FUNC_END();
1457 }
1458
1459 void
1460 fpgl_glGetProgramBinary(GLuint program, GLsizei bufsize, GLsizei* length, GLenum* binaryFormat, void* binary)
1461 {
1462         GLuint real_obj;
1463
1464         DEFINE_FAST_GL_FUNC();
1465         _COREGL_FAST_FUNC_BEGIN();
1466         INIT_FAST_GL_FUNC();
1467
1468         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1469         {
1470                 _set_gl_error(GL_INVALID_VALUE);
1471                 goto finish;
1472         }
1473
1474         _sym_glGetProgramBinary(real_obj, bufsize, length, binaryFormat, binary);
1475         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1476         goto finish;
1477
1478 finish:
1479         _COREGL_FAST_FUNC_END();
1480 }
1481
1482 void
1483 fpgl_glProgramBinary(GLuint program, GLenum binaryFormat, const void* binary, GLint length)
1484 {
1485         GLuint real_obj;
1486
1487         DEFINE_FAST_GL_FUNC();
1488         _COREGL_FAST_FUNC_BEGIN();
1489         INIT_FAST_GL_FUNC();
1490
1491         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1492         {
1493                 _set_gl_error(GL_INVALID_VALUE);
1494                 goto finish;
1495         }
1496
1497         _sym_glProgramBinary(real_obj, binaryFormat, binary, length);
1498         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1499         goto finish;
1500
1501 finish:
1502         _COREGL_FAST_FUNC_END();
1503 }
1504
1505
1506 void
1507 fpgl_glProgramParameteri(GLuint program, GLuint pname, GLint value)
1508 {
1509         GLuint real_obj;
1510
1511         DEFINE_FAST_GL_FUNC();
1512         _COREGL_FAST_FUNC_BEGIN();
1513         INIT_FAST_GL_FUNC();
1514
1515         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1516         {
1517                 _set_gl_error(GL_INVALID_VALUE);
1518                 goto finish;
1519         }
1520
1521         _sym_glProgramParameteri(real_obj, pname, value);
1522         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1523         goto finish;
1524
1525 finish:
1526         _COREGL_FAST_FUNC_END();
1527 }
1528
1529 int
1530 fpgl_glGetUniformLocation(GLuint program, const char* name)
1531 {
1532         int ret = _COREGL_INT_INIT_VALUE;
1533         GLuint real_obj;
1534
1535         DEFINE_FAST_GL_FUNC();
1536         _COREGL_FAST_FUNC_BEGIN();
1537         INIT_FAST_GL_FUNC();
1538
1539         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1540         {
1541                 _set_gl_error(GL_INVALID_VALUE);
1542                 ret = -1;
1543                 goto finish;
1544         }
1545
1546         ret = _sym_glGetUniformLocation(real_obj, name);
1547         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1548         goto finish;
1549
1550 finish:
1551         _COREGL_FAST_FUNC_END();
1552         return ret;
1553 }
1554
1555 void
1556 fpgl_glDeleteShader(GLuint shader)
1557 {
1558         GLuint real_obj;
1559
1560         DEFINE_FAST_GL_FUNC();
1561         _COREGL_FAST_FUNC_BEGIN();
1562         INIT_FAST_GL_FUNC();
1563
1564         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1)
1565         {
1566                 _set_gl_error(GL_INVALID_VALUE);
1567                 goto finish;
1568         }
1569
1570         _sym_glDeleteShader(real_obj);
1571         if (real_obj != 0)
1572         {
1573                 AST(sostate_remove_object(current_ctx->sostate, GL_OBJECT_TYPE_PROGRAM, shader) == 1);
1574         }
1575
1576         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1577         goto finish;
1578
1579 finish:
1580         _COREGL_FAST_FUNC_END();
1581 }
1582
1583 void
1584 fpgl_glDeleteProgram(GLuint program)
1585 {
1586         GLuint real_obj;
1587
1588         DEFINE_FAST_GL_FUNC();
1589         _COREGL_FAST_FUNC_BEGIN();
1590         INIT_FAST_GL_FUNC();
1591
1592         if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1)
1593         {
1594                 _set_gl_error(GL_INVALID_VALUE);
1595                 goto finish;
1596         }
1597
1598         _sym_glDeleteProgram(real_obj);
1599         if (real_obj != 0)
1600         {
1601                 AST(sostate_remove_object(current_ctx->sostate, GL_OBJECT_TYPE_PROGRAM, program) == 1);
1602         }
1603
1604         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1605         goto finish;
1606
1607 finish:
1608         _COREGL_FAST_FUNC_END();
1609 }
1610
1611
1612
1613 //////////////////////////////////////////////////////////////////////////////////
1614
1615 void
1616 fpgl_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1617 {
1618         DEFINE_FAST_GL_FUNC();
1619         _COREGL_FAST_FUNC_BEGIN();
1620         INIT_FAST_GL_FUNC();
1621
1622         if ((current_ctx->gl_blend_color[0] != red) ||
1623             (current_ctx->gl_blend_color[1] != green) ||
1624             (current_ctx->gl_blend_color[2] != blue) ||
1625             (current_ctx->gl_blend_color[3] != alpha))
1626         {
1627                 _sym_glBlendColor(red, green, blue, alpha);
1628
1629                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1630
1631                 current_ctx->_blend_flag |= FLAG_BIT_0;
1632                 current_ctx->gl_blend_color[0] = red;
1633                 current_ctx->gl_blend_color[1] = green;
1634                 current_ctx->gl_blend_color[2] = blue;
1635                 current_ctx->gl_blend_color[3] = alpha;
1636         }
1637         goto finish;
1638
1639 finish:
1640         _COREGL_FAST_FUNC_END();
1641 }
1642
1643
1644 //!!! Optimze?
1645 void
1646 fpgl_glBlendEquation(GLenum mode)
1647 {
1648         DEFINE_FAST_GL_FUNC();
1649         _COREGL_FAST_FUNC_BEGIN();
1650         INIT_FAST_GL_FUNC();
1651
1652         _sym_glBlendEquation(mode);
1653
1654         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1655
1656         current_ctx->_blend_flag |= (FLAG_BIT_5 | FLAG_BIT_6);
1657         _sym_glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*) & (current_ctx->gl_blend_equation_rgb));
1658         _sym_glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*) & (current_ctx->gl_blend_equation_alpha));
1659         goto finish;
1660
1661 finish:
1662         _COREGL_FAST_FUNC_END();
1663 }
1664
1665
1666 void
1667 fpgl_glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
1668 {
1669         DEFINE_FAST_GL_FUNC();
1670         _COREGL_FAST_FUNC_BEGIN();
1671         INIT_FAST_GL_FUNC();
1672
1673         if ((current_ctx->gl_blend_equation_rgb[0] != modeRGB) ||
1674             (current_ctx->gl_blend_equation_alpha[0] != modeAlpha))
1675         {
1676                 _sym_glBlendEquationSeparate(modeRGB, modeAlpha);
1677
1678                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1679
1680                 current_ctx->_blend_flag |= (FLAG_BIT_5 | FLAG_BIT_6);
1681                 current_ctx->gl_blend_equation_rgb[0]    = modeRGB;
1682                 current_ctx->gl_blend_equation_alpha[0]  = modeAlpha;
1683         }
1684         goto finish;
1685
1686 finish:
1687         _COREGL_FAST_FUNC_END();
1688 }
1689
1690
1691 //!!! Optimze?
1692 void
1693 fpgl_glBlendFunc(GLenum sfactor, GLenum dfactor)
1694 {
1695         DEFINE_FAST_GL_FUNC();
1696         _COREGL_FAST_FUNC_BEGIN();
1697         INIT_FAST_GL_FUNC();
1698
1699         _sym_glBlendFunc(sfactor, dfactor);
1700
1701         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1702
1703         current_ctx->_blend_flag |= (FLAG_BIT_1 | FLAG_BIT_2 | FLAG_BIT_3 | FLAG_BIT_4);
1704         _sym_glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*) & (current_ctx->gl_blend_src_rgb));
1705         _sym_glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*) & (current_ctx->gl_blend_src_alpha));
1706         _sym_glGetIntegerv(GL_BLEND_DST_RGB, (GLint*) & (current_ctx->gl_blend_dst_rgb));
1707         _sym_glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*) & (current_ctx->gl_blend_dst_alpha));
1708         goto finish;
1709
1710 finish:
1711         _COREGL_FAST_FUNC_END();
1712 }
1713
1714
1715 void
1716 fpgl_glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
1717 {
1718         DEFINE_FAST_GL_FUNC();
1719         _COREGL_FAST_FUNC_BEGIN();
1720         INIT_FAST_GL_FUNC();
1721
1722         if ((current_ctx->gl_blend_src_rgb[0] != srcRGB) ||
1723             (current_ctx->gl_blend_dst_rgb[0] != dstRGB) ||
1724             (current_ctx->gl_blend_src_alpha[0] != srcAlpha) ||
1725             (current_ctx->gl_blend_dst_alpha[0] != dstAlpha))
1726         {
1727                 _sym_glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
1728
1729                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1730
1731                 current_ctx->_blend_flag |= (FLAG_BIT_1 | FLAG_BIT_2 | FLAG_BIT_3 | FLAG_BIT_4);
1732                 current_ctx->gl_blend_src_rgb[0]   = srcRGB;
1733                 current_ctx->gl_blend_dst_rgb[0]   = dstRGB;
1734                 current_ctx->gl_blend_src_alpha[0] = srcAlpha;
1735                 current_ctx->gl_blend_dst_alpha[0] = dstAlpha;
1736         }
1737         goto finish;
1738
1739 finish:
1740         _COREGL_FAST_FUNC_END();
1741 }
1742
1743
1744 void
1745 fpgl_glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1746 {
1747         DEFINE_FAST_GL_FUNC();
1748         _COREGL_FAST_FUNC_BEGIN();
1749         INIT_FAST_GL_FUNC();
1750
1751         if ((current_ctx->gl_color_clear_value[0] != red) ||
1752             (current_ctx->gl_color_clear_value[1] != green) ||
1753             (current_ctx->gl_color_clear_value[2] != blue) ||
1754             (current_ctx->gl_color_clear_value[3] != alpha))
1755         {
1756                 _sym_glClearColor(red, green, blue, alpha);
1757
1758                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1759
1760                 current_ctx->_clear_flag1 |= (FLAG_BIT_2);
1761                 current_ctx->gl_color_clear_value[0] = red;
1762                 current_ctx->gl_color_clear_value[1] = green;
1763                 current_ctx->gl_color_clear_value[2] = blue;
1764                 current_ctx->gl_color_clear_value[3] = alpha;
1765         }
1766         goto finish;
1767
1768 finish:
1769         _COREGL_FAST_FUNC_END();
1770 }
1771
1772
1773 void
1774 fpgl_glClearDepthf(GLclampf depth)
1775 {
1776         DEFINE_FAST_GL_FUNC();
1777         _COREGL_FAST_FUNC_BEGIN();
1778         INIT_FAST_GL_FUNC();
1779
1780         CURR_STATE_COMPARE(gl_depth_clear_value, depth)
1781         {
1782                 _sym_glClearDepthf(depth);
1783
1784                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1785
1786                 current_ctx->_clear_flag2 |= FLAG_BIT_2;
1787                 current_ctx->gl_depth_clear_value[0] = depth;
1788         }
1789         goto finish;
1790
1791 finish:
1792         _COREGL_FAST_FUNC_END();
1793 }
1794
1795
1796 void
1797 fpgl_glClearStencil(GLint s)
1798 {
1799         DEFINE_FAST_GL_FUNC();
1800         _COREGL_FAST_FUNC_BEGIN();
1801         INIT_FAST_GL_FUNC();
1802
1803         CURR_STATE_COMPARE(gl_stencil_clear_value, s)
1804         {
1805                 _sym_glClearStencil(s);
1806
1807                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1808
1809                 current_ctx->_stencil_flag2 |= FLAG_BIT_7;
1810                 current_ctx->gl_stencil_clear_value[0] = s;
1811         }
1812         goto finish;
1813
1814 finish:
1815         _COREGL_FAST_FUNC_END();
1816 }
1817
1818
1819 void
1820 fpgl_glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
1821 {
1822         DEFINE_FAST_GL_FUNC();
1823         _COREGL_FAST_FUNC_BEGIN();
1824         INIT_FAST_GL_FUNC();
1825
1826         if ((current_ctx->gl_color_writemask[0] != red) ||
1827             (current_ctx->gl_color_writemask[1] != green) ||
1828             (current_ctx->gl_color_writemask[2] != blue) ||
1829             (current_ctx->gl_color_writemask[3] != alpha))
1830         {
1831                 _sym_glColorMask(red, green, blue, alpha);
1832
1833                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1834
1835                 current_ctx->_clear_flag2 |= FLAG_BIT_0;
1836                 current_ctx->gl_color_writemask[0] = red;
1837                 current_ctx->gl_color_writemask[1] = green;
1838                 current_ctx->gl_color_writemask[2] = blue;
1839                 current_ctx->gl_color_writemask[3] = alpha;
1840         }
1841         goto finish;
1842
1843 finish:
1844         _COREGL_FAST_FUNC_END();
1845 }
1846
1847
1848 void
1849 fpgl_glCullFace(GLenum mode)
1850 {
1851         DEFINE_FAST_GL_FUNC();
1852         _COREGL_FAST_FUNC_BEGIN();
1853         INIT_FAST_GL_FUNC();
1854
1855         CURR_STATE_COMPARE(gl_cull_face_mode, mode)
1856         {
1857                 _sym_glCullFace(mode);
1858
1859                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1860
1861                 current_ctx->_clear_flag2 |= FLAG_BIT_5;
1862                 current_ctx->gl_cull_face_mode[0] = mode;
1863         }
1864         goto finish;
1865
1866 finish:
1867         _COREGL_FAST_FUNC_END();
1868 }
1869
1870
1871 void
1872 fpgl_glDepthFunc(GLenum func)
1873 {
1874         DEFINE_FAST_GL_FUNC();
1875         _COREGL_FAST_FUNC_BEGIN();
1876         INIT_FAST_GL_FUNC();
1877
1878         CURR_STATE_COMPARE(gl_depth_func, func)
1879         {
1880                 _sym_glDepthFunc(func);
1881
1882                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1883
1884                 current_ctx->_clear_flag2 |= FLAG_BIT_3;
1885                 current_ctx->gl_depth_func[0] = func;
1886         }
1887         goto finish;
1888
1889 finish:
1890         _COREGL_FAST_FUNC_END();
1891 }
1892
1893
1894 void
1895 fpgl_glDepthMask(GLboolean flag)
1896 {
1897         DEFINE_FAST_GL_FUNC();
1898         _COREGL_FAST_FUNC_BEGIN();
1899         INIT_FAST_GL_FUNC();
1900
1901         CURR_STATE_COMPARE(gl_depth_writemask, flag)
1902         {
1903                 _sym_glDepthMask(flag);
1904
1905                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1906
1907                 current_ctx->_clear_flag2 |= FLAG_BIT_4;
1908                 current_ctx->gl_depth_writemask[0] = flag;
1909         }
1910         goto finish;
1911
1912 finish:
1913         _COREGL_FAST_FUNC_END();
1914 }
1915
1916
1917 void
1918 fpgl_glDepthRangef(GLclampf zNear, GLclampf zFar)
1919 {
1920         DEFINE_FAST_GL_FUNC();
1921         _COREGL_FAST_FUNC_BEGIN();
1922         INIT_FAST_GL_FUNC();
1923
1924         if ((current_ctx->gl_depth_range[0] != zNear) ||
1925             (current_ctx->gl_depth_range[1] != zFar))
1926         {
1927                 _sym_glDepthRangef(zNear, zFar);
1928
1929                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1930
1931                 current_ctx->_clear_flag2 |= FLAG_BIT_1;
1932                 current_ctx->gl_depth_range[0] = zNear;
1933                 current_ctx->gl_depth_range[1] = zFar;
1934         }
1935         goto finish;
1936
1937 finish:
1938         _COREGL_FAST_FUNC_END();
1939 }
1940
1941
1942 void
1943 fpgl_glDisable(GLenum cap)
1944 {
1945         DEFINE_FAST_GL_FUNC();
1946         _COREGL_FAST_FUNC_BEGIN();
1947         INIT_FAST_GL_FUNC();
1948
1949         switch (cap)
1950         {
1951                 case GL_BLEND:
1952                         CURR_STATE_COMPARE(gl_blend, GL_FALSE)
1953                         {
1954                                 _sym_glDisable(cap);
1955                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1956                                 current_ctx->_enable_flag1 &= (~FLAG_BIT_0);
1957                                 current_ctx->gl_blend[0] = GL_FALSE;
1958                         }
1959                         break;
1960                 case GL_CULL_FACE:
1961                         CURR_STATE_COMPARE(gl_cull_face, GL_FALSE)
1962                         {
1963                                 _sym_glDisable(cap);
1964                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1965                                 current_ctx->_enable_flag1 &= (~FLAG_BIT_1);
1966                                 current_ctx->gl_cull_face[0] = GL_FALSE;
1967                         }
1968                         break;
1969                 case GL_DEPTH_TEST:
1970                         CURR_STATE_COMPARE(gl_depth_test, GL_FALSE)
1971                         {
1972                                 _sym_glDisable(cap);
1973                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1974                                 current_ctx->_enable_flag1 &= (~FLAG_BIT_2);
1975                                 current_ctx->gl_depth_test[0] = GL_FALSE;
1976                         }
1977                         break;
1978                 case GL_DITHER:
1979                         CURR_STATE_COMPARE(gl_dither, GL_FALSE)
1980                         {
1981                                 _sym_glDisable(cap);
1982                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1983                                 current_ctx->_enable_flag1 &= (~FLAG_BIT_3);
1984                                 current_ctx->gl_dither[0] = GL_FALSE;
1985                         }
1986                         break;
1987                 case GL_POLYGON_OFFSET_FILL:
1988                         CURR_STATE_COMPARE(gl_polygon_offset_fill, GL_FALSE)
1989                         {
1990                                 _sym_glDisable(cap);
1991                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1992                                 current_ctx->_enable_flag2 &= (~FLAG_BIT_0);
1993                                 current_ctx->gl_polygon_offset_fill[0] = GL_FALSE;
1994                         }
1995                         break;
1996                 case GL_SAMPLE_ALPHA_TO_COVERAGE:
1997                         CURR_STATE_COMPARE(gl_sample_alpha_to_coverage, GL_FALSE)
1998                         {
1999                                 _sym_glDisable(cap);
2000                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2001                                 current_ctx->_enable_flag2 &= (~FLAG_BIT_1);
2002                                 current_ctx->gl_sample_alpha_to_coverage[0] = GL_FALSE;
2003                         }
2004                         break;
2005                 case GL_SAMPLE_COVERAGE:
2006                         CURR_STATE_COMPARE(gl_sample_coverage, GL_FALSE)
2007                         {
2008                                 _sym_glDisable(cap);
2009                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2010                                 current_ctx->_enable_flag2 &= (~FLAG_BIT_2);
2011                                 current_ctx->gl_sample_coverage[0] = GL_FALSE;
2012                         }
2013                         break;
2014                 case GL_SCISSOR_TEST:
2015                         CURR_STATE_COMPARE(gl_scissor_test, GL_FALSE)
2016                         {
2017                                 _sym_glDisable(cap);
2018                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2019                                 current_ctx->_enable_flag2 &= (~FLAG_BIT_3);
2020                                 current_ctx->gl_scissor_test[0] = GL_FALSE;
2021                         }
2022                         break;
2023                 case GL_STENCIL_TEST:
2024                         CURR_STATE_COMPARE(gl_stencil_test, GL_FALSE)
2025                         {
2026                                 _sym_glDisable(cap);
2027                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2028                                 current_ctx->_enable_flag2 &= (~FLAG_BIT_4);
2029                                 current_ctx->gl_stencil_test[0] = GL_FALSE;
2030                         }
2031                         break;
2032         }
2033         goto finish;
2034
2035 finish:
2036         _COREGL_FAST_FUNC_END();
2037 }
2038
2039
2040 void
2041 fpgl_glDisableVertexAttribArray(GLuint index)
2042 {
2043         DEFINE_FAST_GL_FUNC();
2044         _COREGL_FAST_FUNC_BEGIN();
2045         INIT_FAST_GL_FUNC();
2046
2047         _sym_glDisableVertexAttribArray(index);
2048
2049         current_ctx->_vattrib_flag |= FLAG_BIT_1;
2050         current_ctx->gl_vertex_array_enabled[index]    = GL_FALSE;
2051
2052         goto finish;
2053
2054 finish:
2055         _COREGL_FAST_FUNC_END();
2056 }
2057
2058
2059 void
2060 fpgl_glDrawArrays(GLenum mode, GLint first, GLsizei count)
2061 {
2062         DEFINE_FAST_GL_FUNC();
2063         _COREGL_FAST_FUNC_BEGIN();
2064         INIT_FAST_GL_FUNC();
2065
2066         _sym_glDrawArrays(mode, first, count);
2067         goto finish;
2068
2069 finish:
2070         _COREGL_FAST_FUNC_END();
2071 }
2072
2073
2074 void
2075 fpgl_glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
2076 {
2077         DEFINE_FAST_GL_FUNC();
2078         _COREGL_FAST_FUNC_BEGIN();
2079         INIT_FAST_GL_FUNC();
2080
2081         _sym_glDrawElements(mode, count, type, indices);
2082         goto finish;
2083
2084 finish:
2085         _COREGL_FAST_FUNC_END();
2086 }
2087
2088
2089 void
2090 fpgl_glEnable(GLenum cap)
2091 {
2092         DEFINE_FAST_GL_FUNC();
2093         _COREGL_FAST_FUNC_BEGIN();
2094         INIT_FAST_GL_FUNC();
2095
2096         switch (cap)
2097         {
2098                 case GL_BLEND:
2099                         CURR_STATE_COMPARE(gl_blend, GL_TRUE)
2100                         {
2101                                 _sym_glEnable(cap);
2102                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2103
2104                                 current_ctx->_enable_flag1 |= FLAG_BIT_0;
2105                                 current_ctx->gl_blend[0] = GL_TRUE;
2106                         }
2107                         break;
2108                 case GL_CULL_FACE:
2109                         CURR_STATE_COMPARE(gl_cull_face, GL_TRUE)
2110                         {
2111                                 _sym_glEnable(cap);
2112                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2113
2114
2115                                 current_ctx->_enable_flag1 |= FLAG_BIT_1;
2116                                 current_ctx->gl_cull_face[0] = GL_TRUE;
2117                         }
2118                         break;
2119                 case GL_DEPTH_TEST:
2120                         CURR_STATE_COMPARE(gl_depth_test, GL_TRUE)
2121                         {
2122                                 _sym_glEnable(cap);
2123                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2124
2125
2126                                 current_ctx->_enable_flag1 |= FLAG_BIT_2;
2127                                 current_ctx->gl_depth_test[0] = GL_TRUE;
2128                         }
2129                         break;
2130                 case GL_DITHER:
2131                         CURR_STATE_COMPARE(gl_dither, GL_TRUE)
2132                         {
2133                                 _sym_glEnable(cap);
2134                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2135
2136
2137                                 current_ctx->_enable_flag1 |= FLAG_BIT_3;
2138                                 current_ctx->gl_dither[0] = GL_TRUE;
2139                         }
2140                         break;
2141                 case GL_POLYGON_OFFSET_FILL:
2142                         CURR_STATE_COMPARE(gl_polygon_offset_fill, GL_TRUE)
2143                         {
2144                                 _sym_glEnable(cap);
2145                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2146
2147
2148                                 current_ctx->_enable_flag2 |= FLAG_BIT_0;
2149                                 current_ctx->gl_polygon_offset_fill[0] = GL_TRUE;
2150                         }
2151                         break;
2152                 case GL_SAMPLE_ALPHA_TO_COVERAGE:
2153                         CURR_STATE_COMPARE(gl_sample_alpha_to_coverage, GL_TRUE)
2154                         {
2155                                 _sym_glEnable(cap);
2156                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2157
2158
2159                                 current_ctx->_enable_flag2 |= FLAG_BIT_1;
2160                                 current_ctx->gl_sample_alpha_to_coverage[0] = GL_TRUE;
2161                         }
2162                         break;
2163                 case GL_SAMPLE_COVERAGE:
2164                         CURR_STATE_COMPARE(gl_sample_coverage, GL_TRUE)
2165                         {
2166                                 _sym_glEnable(cap);
2167                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2168
2169
2170                                 current_ctx->_enable_flag2 |= FLAG_BIT_2;
2171                                 current_ctx->gl_sample_coverage[0] = GL_TRUE;
2172                         }
2173                         break;
2174                 case GL_SCISSOR_TEST:
2175                         CURR_STATE_COMPARE(gl_scissor_test, GL_TRUE)
2176                         {
2177                                 _sym_glEnable(cap);
2178                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2179
2180
2181                                 current_ctx->_enable_flag2 |= FLAG_BIT_3;
2182                                 current_ctx->gl_scissor_test[0] = GL_TRUE;
2183                         }
2184                         break;
2185                 case GL_STENCIL_TEST:
2186                         CURR_STATE_COMPARE(gl_stencil_test, GL_TRUE)
2187                         {
2188                                 _sym_glEnable(cap);
2189                                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2190
2191
2192                                 current_ctx->_enable_flag2 |= FLAG_BIT_4;
2193                                 current_ctx->gl_stencil_test[0] = GL_TRUE;
2194                         }
2195                         break;
2196         }
2197         goto finish;
2198
2199 finish:
2200         _COREGL_FAST_FUNC_END();
2201 }
2202
2203
2204 // Optimze?
2205 void
2206 fpgl_glEnableVertexAttribArray(GLuint index)
2207 {
2208         DEFINE_FAST_GL_FUNC();
2209         _COREGL_FAST_FUNC_BEGIN();
2210         INIT_FAST_GL_FUNC();
2211
2212         _sym_glEnableVertexAttribArray(index);
2213
2214         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2215
2216         current_ctx->_vattrib_flag |= FLAG_BIT_1;
2217         current_ctx->gl_vertex_array_enabled[index]    = GL_TRUE;
2218
2219         goto finish;
2220
2221 finish:
2222         _COREGL_FAST_FUNC_END();
2223 }
2224
2225
2226 void
2227 fpgl_glFrontFace(GLenum mode)
2228 {
2229         DEFINE_FAST_GL_FUNC();
2230         _COREGL_FAST_FUNC_BEGIN();
2231         INIT_FAST_GL_FUNC();
2232
2233         CURR_STATE_COMPARE(gl_front_face, mode)
2234         {
2235                 _sym_glFrontFace(mode);
2236
2237                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2238
2239                 current_ctx->_misc_flag1 |= FLAG_BIT_0;
2240                 current_ctx->gl_front_face[0] = mode;
2241         }
2242         goto finish;
2243
2244 finish:
2245         _COREGL_FAST_FUNC_END();
2246 }
2247
2248
2249 void
2250 fpgl_glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
2251 {
2252         DEFINE_FAST_GL_FUNC();
2253         _COREGL_FAST_FUNC_BEGIN();
2254         INIT_FAST_GL_FUNC();
2255
2256         _sym_glGetVertexAttribfv(index, pname, params);
2257
2258         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2259         goto finish;
2260
2261 finish:
2262         _COREGL_FAST_FUNC_END();
2263 }
2264
2265
2266 void
2267 fpgl_glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
2268 {
2269         DEFINE_FAST_GL_FUNC();
2270         _COREGL_FAST_FUNC_BEGIN();
2271         INIT_FAST_GL_FUNC();
2272
2273         _sym_glGetVertexAttribiv(index, pname, params);
2274
2275         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2276         goto finish;
2277
2278 finish:
2279         _COREGL_FAST_FUNC_END();
2280 }
2281
2282
2283 void
2284 fpgl_glGetVertexAttribPointerv(GLuint index, GLenum pname, void** pointer)
2285 {
2286         DEFINE_FAST_GL_FUNC();
2287         _COREGL_FAST_FUNC_BEGIN();
2288         INIT_FAST_GL_FUNC();
2289
2290         _sym_glGetVertexAttribPointerv(index, pname, pointer);
2291
2292         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2293
2294         goto finish;
2295
2296 finish:
2297         _COREGL_FAST_FUNC_END();
2298 }
2299
2300 // Fix Maybe?
2301 void
2302 fpgl_glHint(GLenum target, GLenum mode)
2303 {
2304         DEFINE_FAST_GL_FUNC();
2305         _COREGL_FAST_FUNC_BEGIN();
2306         INIT_FAST_GL_FUNC();
2307
2308         if (target == GL_GENERATE_MIPMAP_HINT)
2309         {
2310                 CURR_STATE_COMPARE(gl_generate_mipmap_hint, mode)
2311                 {
2312                         _sym_glHint(target, mode);
2313
2314                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2315
2316                         current_ctx->_tex_flag1 |= FLAG_BIT_2;
2317                         current_ctx->gl_generate_mipmap_hint[0] = mode;
2318                 }
2319         }
2320         else
2321         {
2322                 // For GL Error to be picked up
2323                 _sym_glHint(target, mode);
2324                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2325         }
2326         goto finish;
2327
2328 finish:
2329         _COREGL_FAST_FUNC_END();
2330 }
2331
2332
2333 void
2334 fpgl_glLineWidth(GLfloat width)
2335 {
2336         DEFINE_FAST_GL_FUNC();
2337         _COREGL_FAST_FUNC_BEGIN();
2338         INIT_FAST_GL_FUNC();
2339
2340         CURR_STATE_COMPARE(gl_line_width, width)
2341         {
2342                 _sym_glLineWidth(width);
2343
2344                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2345
2346                 current_ctx->_misc_flag1 |= FLAG_BIT_1;
2347                 current_ctx->gl_line_width[0] = width;
2348         }
2349         goto finish;
2350
2351 finish:
2352         _COREGL_FAST_FUNC_END();
2353 }
2354
2355
2356 void
2357 fpgl_glPixelStorei(GLenum pname, GLint param)
2358 {
2359         DEFINE_FAST_GL_FUNC();
2360         _COREGL_FAST_FUNC_BEGIN();
2361         INIT_FAST_GL_FUNC();
2362
2363         if (pname == GL_PACK_ALIGNMENT)
2364         {
2365                 CURR_STATE_COMPARE(gl_pack_alignment, param)
2366                 {
2367                         _sym_glPixelStorei(pname, param);
2368
2369                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2370
2371                         current_ctx->_misc_flag2 |= FLAG_BIT_1;
2372                         current_ctx->gl_pack_alignment[0] = param;
2373                 }
2374         }
2375         else if (pname == GL_UNPACK_ALIGNMENT)
2376         {
2377                 CURR_STATE_COMPARE(gl_unpack_alignment, param)
2378                 {
2379                         _sym_glPixelStorei(pname, param);
2380
2381                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2382
2383                         current_ctx->_misc_flag2 |= FLAG_BIT_2;
2384                         current_ctx->gl_unpack_alignment[0] = param;
2385                 }
2386         }
2387         else
2388         {
2389                 // For GL Error to be picked up
2390                 _sym_glPixelStorei(pname, param);
2391                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2392         }
2393         goto finish;
2394
2395 finish:
2396         _COREGL_FAST_FUNC_END();
2397 }
2398
2399
2400 void
2401 fpgl_glPolygonOffset(GLfloat factor, GLfloat units)
2402 {
2403         DEFINE_FAST_GL_FUNC();
2404         _COREGL_FAST_FUNC_BEGIN();
2405         INIT_FAST_GL_FUNC();
2406
2407         if ((current_ctx->gl_polygon_offset_factor[0] != factor) ||
2408             (current_ctx->gl_polygon_offset_units[0] != units))
2409         {
2410                 _sym_glPolygonOffset(factor, units);
2411
2412                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2413
2414                 current_ctx->_misc_flag1 |= (FLAG_BIT_2 | FLAG_BIT_3);
2415                 current_ctx->gl_polygon_offset_factor[0] = factor;
2416                 current_ctx->gl_polygon_offset_units[0]  = units;
2417         }
2418         goto finish;
2419
2420 finish:
2421         _COREGL_FAST_FUNC_END();
2422 }
2423
2424
2425 void
2426 fpgl_glSampleCoverage(GLclampf value, GLboolean invert)
2427 {
2428         DEFINE_FAST_GL_FUNC();
2429         _COREGL_FAST_FUNC_BEGIN();
2430         INIT_FAST_GL_FUNC();
2431
2432         if ((current_ctx->gl_sample_coverage_value[0] != value) ||
2433             (current_ctx->gl_sample_coverage_invert[0] != invert))
2434         {
2435                 _sym_glSampleCoverage(value, invert);
2436
2437                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2438
2439                 current_ctx->_misc_flag1 |= (FLAG_BIT_4 | FLAG_BIT_5);
2440                 current_ctx->gl_sample_coverage_value[0]  = value;
2441                 current_ctx->gl_sample_coverage_invert[0] = invert;
2442         }
2443         goto finish;
2444
2445 finish:
2446         _COREGL_FAST_FUNC_END();
2447 }
2448
2449
2450 void
2451 fpgl_glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
2452 {
2453         DEFINE_FAST_GL_FUNC();
2454         _COREGL_FAST_FUNC_BEGIN();
2455         INIT_FAST_GL_FUNC();
2456
2457         if ((current_ctx->gl_scissor_box[0] != x) ||
2458             (current_ctx->gl_scissor_box[1] != y) ||
2459             (current_ctx->gl_scissor_box[2] != width) ||
2460             (current_ctx->gl_scissor_box[3] != height))
2461         {
2462                 _sym_glScissor(x, y, width, height);
2463
2464                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2465
2466                 current_ctx->_misc_flag2 |= FLAG_BIT_0;
2467                 current_ctx->gl_scissor_box[0] = x;
2468                 current_ctx->gl_scissor_box[1] = y;
2469                 current_ctx->gl_scissor_box[2] = width;
2470                 current_ctx->gl_scissor_box[3] = height;
2471         }
2472         goto finish;
2473
2474 finish:
2475         _COREGL_FAST_FUNC_END();
2476 }
2477
2478
2479 void
2480 fpgl_glStencilFunc(GLenum func, GLint ref, GLuint mask)
2481 {
2482         DEFINE_FAST_GL_FUNC();
2483         _COREGL_FAST_FUNC_BEGIN();
2484         INIT_FAST_GL_FUNC();
2485
2486         if ((current_ctx->gl_stencil_func[0] != func) ||
2487             (current_ctx->gl_stencil_ref[0] != ref) ||
2488             (current_ctx->gl_stencil_value_mask[0] != mask) ||
2489             (current_ctx->gl_stencil_back_func[0] != func) ||
2490             (current_ctx->gl_stencil_back_ref[0] != ref) ||
2491             (current_ctx->gl_stencil_back_value_mask[0] != mask))
2492         {
2493                 _sym_glStencilFunc(func, ref, mask);
2494
2495                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2496
2497                 current_ctx->_stencil_flag1 |= (FLAG_BIT_0 | FLAG_BIT_1 | FLAG_BIT_2);
2498                 current_ctx->gl_stencil_func[0]             = func;
2499                 current_ctx->gl_stencil_ref[0]              = ref;
2500                 current_ctx->gl_stencil_value_mask[0]       = mask;
2501
2502                 current_ctx->_stencil_flag2 |= (FLAG_BIT_0 | FLAG_BIT_1 | FLAG_BIT_2);
2503                 current_ctx->gl_stencil_back_func[0]        = func;
2504                 current_ctx->gl_stencil_back_ref[0]         = ref;
2505                 current_ctx->gl_stencil_back_value_mask[0]  = mask;
2506         }
2507         goto finish;
2508
2509 finish:
2510         _COREGL_FAST_FUNC_END();
2511 }
2512
2513
2514 void
2515 fpgl_glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
2516 {
2517         DEFINE_FAST_GL_FUNC();
2518         _COREGL_FAST_FUNC_BEGIN();
2519         INIT_FAST_GL_FUNC();
2520
2521         if ((face == GL_FRONT) || (face == GL_FRONT_AND_BACK))
2522         {
2523                 if ((current_ctx->gl_stencil_func[0] != func) ||
2524                     (current_ctx->gl_stencil_ref[0] != ref) ||
2525                     (current_ctx->gl_stencil_value_mask[0] != mask))
2526                 {
2527                         _sym_glStencilFuncSeparate(face, func, ref, mask);
2528
2529                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2530
2531                         current_ctx->_stencil_flag1 |= (FLAG_BIT_0 | FLAG_BIT_1 | FLAG_BIT_2);
2532
2533                         current_ctx->gl_stencil_func[0]             = func;
2534                         current_ctx->gl_stencil_ref[0]              = ref;
2535                         current_ctx->gl_stencil_value_mask[0]       = mask;
2536                 }
2537         }
2538         else if ((face == GL_BACK) || (face == GL_FRONT_AND_BACK))
2539         {
2540                 if ((current_ctx->gl_stencil_back_func[0] != func) ||
2541                     (current_ctx->gl_stencil_back_ref[0] != ref) ||
2542                     (current_ctx->gl_stencil_back_value_mask[0] != mask))
2543                 {
2544                         _sym_glStencilFuncSeparate(face, func, ref, mask);
2545
2546                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2547
2548                         current_ctx->_stencil_flag2 |= (FLAG_BIT_0 | FLAG_BIT_1 | FLAG_BIT_2);
2549
2550                         current_ctx->gl_stencil_back_func[0]        = func;
2551                         current_ctx->gl_stencil_back_ref[0]         = ref;
2552                         current_ctx->gl_stencil_back_value_mask[0]  = mask;
2553                 }
2554         }
2555         else
2556         {
2557                 // Have GL pick up the error
2558                 _sym_glStencilFuncSeparate(face, func, ref, mask);
2559
2560                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2561         }
2562         goto finish;
2563
2564 finish:
2565         _COREGL_FAST_FUNC_END();
2566 }
2567
2568
2569 void
2570 fpgl_glStencilMask(GLuint mask)
2571 {
2572         DEFINE_FAST_GL_FUNC();
2573         _COREGL_FAST_FUNC_BEGIN();
2574         INIT_FAST_GL_FUNC();
2575
2576         if ((current_ctx->gl_stencil_writemask[0] != mask) ||
2577             (current_ctx->gl_stencil_back_writemask[0] != mask))
2578         {
2579                 _sym_glStencilMask(mask);
2580
2581                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2582
2583                 current_ctx->_stencil_flag1 |= (FLAG_BIT_6);
2584                 current_ctx->_stencil_flag2 |= (FLAG_BIT_6);
2585
2586                 current_ctx->gl_stencil_writemask[0]        = mask;
2587                 current_ctx->gl_stencil_back_writemask[0]   = mask;
2588         }
2589         goto finish;
2590
2591 finish:
2592         _COREGL_FAST_FUNC_END();
2593 }
2594
2595
2596 void
2597 fpgl_glStencilMaskSeparate(GLenum face, GLuint mask)
2598 {
2599         DEFINE_FAST_GL_FUNC();
2600         _COREGL_FAST_FUNC_BEGIN();
2601         INIT_FAST_GL_FUNC();
2602
2603         if ((face == GL_FRONT) || (face == GL_FRONT_AND_BACK))
2604         {
2605                 if (current_ctx->gl_stencil_writemask[0] != mask)
2606                 {
2607                         _sym_glStencilMaskSeparate(face, mask);
2608
2609                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2610
2611                         current_ctx->_stencil_flag1 |= (FLAG_BIT_6);
2612                         current_ctx->gl_stencil_writemask[0] = mask;
2613                 }
2614         }
2615         else if ((face == GL_BACK) || (face == GL_FRONT_AND_BACK))
2616         {
2617                 if (current_ctx->gl_stencil_back_writemask[0] != mask)
2618                 {
2619                         _sym_glStencilMaskSeparate(face, mask);
2620
2621                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2622
2623                         current_ctx->_stencil_flag2 |= (FLAG_BIT_6);
2624                         current_ctx->gl_stencil_back_writemask[0]   = mask;
2625                 }
2626         }
2627         else
2628         {
2629                 // Have GL pick up the error
2630                 _sym_glStencilMaskSeparate(face, mask);
2631                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2632         }
2633         goto finish;
2634
2635 finish:
2636         _COREGL_FAST_FUNC_END();
2637 }
2638
2639
2640 void
2641 fpgl_glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
2642 {
2643         DEFINE_FAST_GL_FUNC();
2644         _COREGL_FAST_FUNC_BEGIN();
2645         INIT_FAST_GL_FUNC();
2646
2647         if ((current_ctx->gl_stencil_fail[0] != fail) ||
2648             (current_ctx->gl_stencil_pass_depth_fail[0] != zfail) ||
2649             (current_ctx->gl_stencil_pass_depth_pass[0] != zpass) ||
2650             (current_ctx->gl_stencil_back_fail[0] != fail) ||
2651             (current_ctx->gl_stencil_back_pass_depth_fail[0] != zfail) ||
2652             (current_ctx->gl_stencil_back_pass_depth_pass[0] != zpass))
2653         {
2654                 _sym_glStencilOp(fail, zfail, zpass);
2655
2656                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2657
2658                 current_ctx->_stencil_flag1 |= (FLAG_BIT_3 | FLAG_BIT_4 | FLAG_BIT_5);
2659                 current_ctx->gl_stencil_fail[0]              = fail;
2660                 current_ctx->gl_stencil_pass_depth_fail[0]   = zfail;
2661                 current_ctx->gl_stencil_pass_depth_pass[0]   = zpass;
2662
2663                 current_ctx->_stencil_flag2 |= (FLAG_BIT_3 | FLAG_BIT_4 | FLAG_BIT_5);
2664                 current_ctx->gl_stencil_back_fail[0]         = fail;
2665                 current_ctx->gl_stencil_back_pass_depth_fail[0]   = zfail;
2666                 current_ctx->gl_stencil_back_pass_depth_pass[0]   = zpass;
2667         }
2668         goto finish;
2669
2670 finish:
2671         _COREGL_FAST_FUNC_END();
2672 }
2673
2674
2675 void
2676 fpgl_glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
2677 {
2678         DEFINE_FAST_GL_FUNC();
2679         _COREGL_FAST_FUNC_BEGIN();
2680         INIT_FAST_GL_FUNC();
2681
2682         if ((face == GL_FRONT) || (face == GL_FRONT_AND_BACK))
2683         {
2684                 if ((current_ctx->gl_stencil_fail[0] != fail) ||
2685                     (current_ctx->gl_stencil_pass_depth_fail[0] != zfail) ||
2686                     (current_ctx->gl_stencil_pass_depth_pass[0] != zpass))
2687                 {
2688                         _sym_glStencilOpSeparate(face, fail, zfail, zpass);
2689                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2690
2691                         current_ctx->_stencil_flag1 |= (FLAG_BIT_3 | FLAG_BIT_4 | FLAG_BIT_5);
2692                         current_ctx->gl_stencil_fail[0]              = fail;
2693                         current_ctx->gl_stencil_pass_depth_fail[0]   = zfail;
2694                         current_ctx->gl_stencil_pass_depth_pass[0]   = zpass;
2695                 }
2696         }
2697         else if ((face == GL_BACK) || (face == GL_FRONT_AND_BACK))
2698         {
2699                 if ((current_ctx->gl_stencil_back_fail[0] != fail) ||
2700                     (current_ctx->gl_stencil_back_pass_depth_fail[0] != zfail) ||
2701                     (current_ctx->gl_stencil_back_pass_depth_pass[0] != zpass))
2702                 {
2703                         _sym_glStencilOpSeparate(face, fail, zfail, zpass);
2704                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2705
2706                         current_ctx->_stencil_flag2 |= (FLAG_BIT_3 | FLAG_BIT_4 | FLAG_BIT_5);
2707                         current_ctx->gl_stencil_back_fail[0]         = fail;
2708                         current_ctx->gl_stencil_back_pass_depth_fail[0]   = zfail;
2709                         current_ctx->gl_stencil_back_pass_depth_pass[0]   = zpass;
2710                 }
2711         }
2712         else
2713         {
2714                 // For picking up error purpose
2715                 _sym_glStencilOpSeparate(face, fail, zfail, zpass);
2716                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2717         }
2718         goto finish;
2719
2720 finish:
2721         _COREGL_FAST_FUNC_END();
2722 }
2723
2724 // Optmize?
2725 void
2726 fpgl_glVertexAttrib1f(GLuint indx, GLfloat x)
2727 {
2728         DEFINE_FAST_GL_FUNC();
2729         _COREGL_FAST_FUNC_BEGIN();
2730         INIT_FAST_GL_FUNC();
2731
2732         _sym_glVertexAttrib1f(indx, x);
2733
2734         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2735
2736         current_ctx->_vattrib_flag |= FLAG_BIT_0;
2737         current_ctx->gl_vertex_attrib_value[indx * 4 + 0] = x;
2738         current_ctx->gl_vertex_attrib_value[indx * 4 + 1] = 0;
2739         current_ctx->gl_vertex_attrib_value[indx * 4 + 2] = 0;
2740         current_ctx->gl_vertex_attrib_value[indx * 4 + 3] = 1;
2741         goto finish;
2742
2743 finish:
2744         _COREGL_FAST_FUNC_END();
2745 }
2746
2747
2748 // Optmize?
2749 void
2750 fpgl_glVertexAttrib1fv(GLuint indx, const GLfloat* values)
2751 {
2752         DEFINE_FAST_GL_FUNC();
2753         _COREGL_FAST_FUNC_BEGIN();
2754         INIT_FAST_GL_FUNC();
2755
2756         _sym_glVertexAttrib1fv(indx, values);
2757
2758         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2759
2760         current_ctx->_vattrib_flag |= FLAG_BIT_0;
2761         current_ctx->gl_vertex_attrib_value[indx * 4 + 0] = values[0];
2762         current_ctx->gl_vertex_attrib_value[indx * 4 + 1] = 0;
2763         current_ctx->gl_vertex_attrib_value[indx * 4 + 2] = 0;
2764         current_ctx->gl_vertex_attrib_value[indx * 4 + 3] = 1;
2765         goto finish;
2766
2767 finish:
2768         _COREGL_FAST_FUNC_END();
2769 }
2770
2771
2772 // Optmize?
2773 void
2774 fpgl_glVertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
2775 {
2776         DEFINE_FAST_GL_FUNC();
2777         _COREGL_FAST_FUNC_BEGIN();
2778         INIT_FAST_GL_FUNC();
2779
2780         _sym_glVertexAttrib2f(indx, x, y);
2781
2782         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2783
2784         current_ctx->_vattrib_flag |= FLAG_BIT_0;
2785         current_ctx->gl_vertex_attrib_value[indx * 4 + 0] = x;
2786         current_ctx->gl_vertex_attrib_value[indx * 4 + 1] = y;
2787         current_ctx->gl_vertex_attrib_value[indx * 4 + 2] = 0;
2788         current_ctx->gl_vertex_attrib_value[indx * 4 + 3] = 1;
2789         goto finish;
2790
2791 finish:
2792         _COREGL_FAST_FUNC_END();
2793 }
2794
2795
2796 // Optmize?
2797 void
2798 fpgl_glVertexAttrib2fv(GLuint indx, const GLfloat* values)
2799 {
2800         DEFINE_FAST_GL_FUNC();
2801         _COREGL_FAST_FUNC_BEGIN();
2802         INIT_FAST_GL_FUNC();
2803
2804         _sym_glVertexAttrib2fv(indx, values);
2805
2806         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2807
2808         current_ctx->_vattrib_flag |= FLAG_BIT_0;
2809         current_ctx->gl_vertex_attrib_value[indx * 4 + 0] = values[0];
2810         current_ctx->gl_vertex_attrib_value[indx * 4 + 1] = values[1];
2811         current_ctx->gl_vertex_attrib_value[indx * 4 + 2] = 0;
2812         current_ctx->gl_vertex_attrib_value[indx * 4 + 3] = 1;
2813         goto finish;
2814
2815 finish:
2816         _COREGL_FAST_FUNC_END();
2817 }
2818
2819
2820 // Optmize?
2821 void
2822 fpgl_glVertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
2823 {
2824         DEFINE_FAST_GL_FUNC();
2825         _COREGL_FAST_FUNC_BEGIN();
2826         INIT_FAST_GL_FUNC();
2827
2828         _sym_glVertexAttrib3f(indx, x, y, z);
2829
2830         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2831
2832         current_ctx->_vattrib_flag |= FLAG_BIT_0;
2833         current_ctx->gl_vertex_attrib_value[indx * 4 + 0] = x;
2834         current_ctx->gl_vertex_attrib_value[indx * 4 + 1] = y;
2835         current_ctx->gl_vertex_attrib_value[indx * 4 + 2] = z;
2836         current_ctx->gl_vertex_attrib_value[indx * 4 + 3] = 1;
2837         goto finish;
2838
2839 finish:
2840         _COREGL_FAST_FUNC_END();
2841 }
2842
2843
2844 // Optmize?
2845 void
2846 fpgl_glVertexAttrib3fv(GLuint indx, const GLfloat* values)
2847 {
2848         DEFINE_FAST_GL_FUNC();
2849         _COREGL_FAST_FUNC_BEGIN();
2850         INIT_FAST_GL_FUNC();
2851
2852         _sym_glVertexAttrib3fv(indx, values);
2853
2854         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2855
2856         current_ctx->_vattrib_flag |= FLAG_BIT_0;
2857         current_ctx->gl_vertex_attrib_value[indx * 4 + 0] = values[0];
2858         current_ctx->gl_vertex_attrib_value[indx * 4 + 1] = values[1];
2859         current_ctx->gl_vertex_attrib_value[indx * 4 + 2] = values[2];
2860         current_ctx->gl_vertex_attrib_value[indx * 4 + 3] = 1;
2861         goto finish;
2862
2863 finish:
2864         _COREGL_FAST_FUNC_END();
2865 }
2866
2867
2868 // Optmize?
2869 void
2870 fpgl_glVertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
2871 {
2872         DEFINE_FAST_GL_FUNC();
2873         _COREGL_FAST_FUNC_BEGIN();
2874         INIT_FAST_GL_FUNC();
2875
2876         _sym_glVertexAttrib4f(indx, x, y, z, w);
2877
2878         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2879
2880         current_ctx->_vattrib_flag |= FLAG_BIT_0;
2881         current_ctx->gl_vertex_attrib_value[indx * 4 + 0] = x;
2882         current_ctx->gl_vertex_attrib_value[indx * 4 + 1] = y;
2883         current_ctx->gl_vertex_attrib_value[indx * 4 + 2] = z;
2884         current_ctx->gl_vertex_attrib_value[indx * 4 + 3] = w;
2885         goto finish;
2886
2887 finish:
2888         _COREGL_FAST_FUNC_END();
2889 }
2890
2891
2892 // Optmize?
2893 void
2894 fpgl_glVertexAttrib4fv(GLuint indx, const GLfloat* values)
2895 {
2896         DEFINE_FAST_GL_FUNC();
2897         _COREGL_FAST_FUNC_BEGIN();
2898         INIT_FAST_GL_FUNC();
2899
2900         _sym_glVertexAttrib4fv(indx, values);
2901
2902         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2903
2904         current_ctx->_vattrib_flag |= FLAG_BIT_0;
2905         current_ctx->gl_vertex_attrib_value[indx * 4 + 0] = values[0];
2906         current_ctx->gl_vertex_attrib_value[indx * 4 + 1] = values[1];
2907         current_ctx->gl_vertex_attrib_value[indx * 4 + 2] = values[2];
2908         current_ctx->gl_vertex_attrib_value[indx * 4 + 3] = values[3];
2909         goto finish;
2910
2911 finish:
2912         _COREGL_FAST_FUNC_END();
2913 }
2914
2915
2916
2917 // Optmize?
2918 void
2919 fpgl_glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr)
2920 {
2921         DEFINE_FAST_GL_FUNC();
2922         _COREGL_FAST_FUNC_BEGIN();
2923         INIT_FAST_GL_FUNC();
2924
2925         _sym_glVertexAttribPointer(indx, size, type, normalized, stride, ptr);
2926
2927         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2928
2929         current_ctx->_vattrib_flag |= FLAG_BIT_1;
2930
2931         current_ctx->gl_vertex_array_buf_id[indx]     = current_ctx->gl_array_buffer_binding[0];
2932         current_ctx->gl_vertex_array_size[indx]       = size;
2933         current_ctx->gl_vertex_array_type[indx]       = type;
2934         current_ctx->gl_vertex_array_normalized[indx] = normalized;
2935         current_ctx->gl_vertex_array_stride[indx]     = stride;
2936         current_ctx->gl_vertex_array_pointer[indx]    = (GLvoid *)ptr;
2937         goto finish;
2938
2939 finish:
2940         _COREGL_FAST_FUNC_END();
2941 }
2942
2943
2944 void
2945 fpgl_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
2946 {
2947         DEFINE_FAST_GL_FUNC();
2948         _COREGL_FAST_FUNC_BEGIN();
2949         INIT_FAST_GL_FUNC();
2950
2951         if ((current_ctx->gl_viewport[0] != x) ||
2952             (current_ctx->gl_viewport[1] != y) ||
2953             (current_ctx->gl_viewport[2] != width) ||
2954             (current_ctx->gl_viewport[3] != height))
2955         {
2956                 _sym_glViewport(x, y, width, height);
2957
2958                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2959
2960                 current_ctx->_clear_flag1 |= FLAG_BIT_0;
2961                 current_ctx->gl_viewport[0] = x;
2962                 current_ctx->gl_viewport[1] = y;
2963                 current_ctx->gl_viewport[2] = width;
2964                 current_ctx->gl_viewport[3] = height;
2965         }
2966         goto finish;
2967
2968 finish:
2969         _COREGL_FAST_FUNC_END();
2970 }
2971
2972 void
2973 fpgl_glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
2974 {
2975         int tex_idx;
2976
2977         DEFINE_FAST_GL_FUNC();
2978         _COREGL_FAST_FUNC_BEGIN();
2979         INIT_FAST_GL_FUNC();
2980
2981         tex_idx = current_ctx->gl_active_texture[0] - GL_TEXTURE0;
2982
2983         switch (target)
2984         {
2985                 case GL_TEXTURE_2D:
2986                         current_ctx->gl_tex_2d_state[tex_idx] = -1;
2987                         break;
2988                 case GL_TEXTURE_CUBE_MAP:
2989                         current_ctx->gl_tex_cube_state[tex_idx] = -1;
2990                         break;
2991         }
2992
2993         _sym_glEGLImageTargetTexture2DOES(target, image);
2994
2995         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2996
2997         goto finish;
2998
2999 finish:
3000         _COREGL_FAST_FUNC_END();
3001 }
3002
3003 static GLboolean
3004 _process_getfunc(GLenum pname, GLvoid *ptr, GLenum get_type)
3005 {
3006         GLboolean ret = GL_FALSE;
3007
3008         DEFINE_FAST_GL_FUNC();
3009         INIT_FAST_GL_FUNC();
3010
3011         switch (pname)
3012         {
3013                 case GL_TEXTURE_BINDING_2D:
3014                 {
3015                         GLint real_tex_id = _COREGL_INT_INIT_VALUE;
3016                         GLuint glue_tex_id = _COREGL_INT_INIT_VALUE;
3017                         _sym_glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *)real_tex_id);
3018
3019                         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
3020
3021                         if (real_tex_id == 0)
3022                         {
3023                                 glue_tex_id = 0;
3024                         }
3025                         else
3026                         {
3027                                 AST(current_ctx->sostate != NULL);
3028                                 glue_tex_id = sostate_find_object(current_ctx->sostate, GL_OBJECT_TYPE_TEXTURE, real_tex_id);
3029                         }
3030
3031                         switch (get_type)
3032                         {
3033                                 case GL_INT:
3034                                         ((GLint *)ptr)[0] = glue_tex_id;
3035                                         break;
3036                                 case GL_FLOAT:
3037                                         ((GLfloat *)ptr)[0] = (GLfloat)glue_tex_id;
3038                                         break;
3039                                 case GL_BOOL:
3040                                         ((GLboolean *)ptr)[0] = (glue_tex_id == 0) ? GL_FALSE : GL_TRUE;
3041                                         break;
3042                         }
3043                         ret = GL_TRUE;
3044                         break;
3045                 }
3046         }
3047         goto finish;
3048
3049 finish:
3050         return ret;
3051 }
3052
3053
3054 void
3055 fpgl_glGetBooleanv(GLenum pname, GLboolean* params)
3056 {
3057         DEFINE_FAST_GL_FUNC();
3058         _COREGL_FAST_FUNC_BEGIN();
3059         INIT_FAST_GL_FUNC();
3060
3061         if (_process_getfunc(pname, params, GL_BOOL) != GL_TRUE)
3062         {
3063                 _sym_glGetBooleanv(pname, params);
3064                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
3065         }
3066         goto finish;
3067
3068 finish:
3069         _COREGL_FAST_FUNC_END();
3070 }
3071
3072 void
3073 fpgl_glGetFloatv(GLenum pname, GLfloat* params)
3074 {
3075         DEFINE_FAST_GL_FUNC();
3076         _COREGL_FAST_FUNC_BEGIN();
3077         INIT_FAST_GL_FUNC();
3078
3079         if (_process_getfunc(pname, params, GL_FLOAT) != GL_TRUE)
3080         {
3081                 _sym_glGetFloatv(pname, params);
3082                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
3083         }
3084         goto finish;
3085
3086 finish:
3087         _COREGL_FAST_FUNC_END();
3088 }
3089
3090 void
3091 fpgl_glGetIntegerv(GLenum pname, GLint* params)
3092 {
3093         DEFINE_FAST_GL_FUNC();
3094         _COREGL_FAST_FUNC_BEGIN();
3095         INIT_FAST_GL_FUNC();
3096
3097         if (_process_getfunc(pname, params, GL_INT) != GL_TRUE)
3098         {
3099                 _sym_glGetIntegerv(pname, params);
3100                 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
3101         }
3102         goto finish;
3103
3104 finish:
3105         _COREGL_FAST_FUNC_END();
3106 }
3107