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