Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / opengl / FGrpGles2.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /*
19  * @file        FGrpGles2.cpp
20  * @brief       This is the implementation file for OpenGL ES 2.X.
21  *
22  */
23
24
25 #define FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING
26 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
27 #include <string>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <stddef.h>
32 #include <dlfcn.h>
33 #endif
34
35 #include <unique_ptr.h>
36
37 #include <GLES2/gl2.h>
38 #include <GLES2/gl2ext.h>
39
40 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
41 #include <FBaseSysLog.h>
42 #endif
43
44 #define FGRAPHICS_INTERNAL_USE_FBO
45 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
46 #include <FUiCtrlFrame.h>
47 #endif
48
49 #include "../util/FGrp_UtilTemplate.h"
50 using namespace Tizen::Base;
51 using namespace Tizen::Ui;
52 using namespace Tizen::Ui::Controls;
53
54 namespace Tizen { namespace Graphics
55 {
56
57 namespace Opengl
58 {
59
60 #if !defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
61
62 #ifdef __cplusplus
63 extern "C"
64 {
65 #endif
66
67 void
68 _GlActiveTexture_2(GLenum texture)
69 {
70         glActiveTexture(texture);
71 }
72
73 void
74 _GlAttachShader_2(GLuint program, GLuint shader)
75 {
76         glAttachShader(program, shader);
77 }
78
79 void
80 _GlBindAttribLocation_2(GLuint program, GLuint index, const char* pName)
81 {
82         glBindAttribLocation(program, index, pName);
83 }
84
85 void
86 _GlBindBuffer_2(GLenum target, GLuint buffer)
87 {
88         glBindBuffer(target, buffer);
89 }
90
91 void
92 _GlBindFramebuffer_2(GLenum target, GLuint framebuffer)
93 {
94         glBindFramebuffer(target, framebuffer);
95 }
96
97 void
98 _GlBindRenderbuffer_2(GLenum target, GLuint renderbuffer)
99 {
100         glBindRenderbuffer(target, renderbuffer);
101 }
102
103 void
104 _GlBindTexture_2(GLenum target, GLuint texture)
105 {
106         glBindTexture(target, texture);
107 }
108
109 void
110 _GlBlendColor_2(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
111 {
112         glBlendColor(red, green, blue, alpha);
113 }
114
115 void
116 _GlBlendEquation_2(GLenum mode)
117 {
118         glBlendEquation(mode);
119 }
120
121 void
122 _GlBlendEquationSeparate_2(GLenum modeRGB, GLenum modeAlpha)
123 {
124         glBlendEquationSeparate(modeRGB, modeAlpha);
125 }
126
127 void
128 _GlBlendFunc_2(GLenum sfactor, GLenum dfactor)
129 {
130         glBlendFunc(sfactor, dfactor);
131 }
132
133 void
134 _GlBlendFuncSeparate_2(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
135 {
136         glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
137 }
138
139 void
140 _GlBufferData_2(GLenum target, GLsizeiptr size, const void* pData, GLenum usage)
141 {
142         glBufferData(target, size, pData, usage);
143 }
144
145 void
146 _GlBufferSubData_2(GLenum target, GLintptr offset, GLsizeiptr size, const void* pData)
147 {
148         glBufferSubData(target, offset, size, pData);
149 }
150
151 GLenum
152 _GlCheckFramebufferStatus_2(GLenum target)
153 {
154         return glCheckFramebufferStatus(target);
155 }
156
157 void
158 _GlClear_2(GLbitfield mask)
159 {
160         glClear(mask);
161 }
162
163 void
164 _GlClearColor_2(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
165 {
166         glClearColor(red, green, blue, alpha);
167 }
168
169 void
170 _GlClearDepthf_2(GLclampf depth)
171 {
172         glClearDepthf(depth);
173 }
174
175 void
176 _GlClearStencil_2(GLint s)
177 {
178         glClearStencil(s);
179 }
180
181 void
182 _GlColorMask_2(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
183 {
184         glColorMask(red, green, blue, alpha);
185 }
186
187 void
188 _GlCompileShader_2(GLuint shader)
189 {
190         glCompileShader(shader);
191 }
192
193 void
194 _GlCompressedTexImage2D_2(GLenum target, GLint level, GLenum internalformat,
195                 GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* pData)
196 {
197         glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, pData);
198 }
199
200 void
201 _GlCompressedTexSubImage2D_2(GLenum target, GLint level, GLint xoffset, GLint yoffset,
202                 GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* pData)
203 {
204         glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, pData);
205 }
206
207 void
208 _GlCopyTexImage2D_2(GLenum target, GLint level,
209                 GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
210 {
211         glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
212 }
213
214 void
215 _GlCopyTexSubImage2D_2(GLenum target, GLint level,
216                 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
217 {
218         glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
219 }
220
221 GLuint
222 _GlCreateProgram_2(void)
223 {
224         return glCreateProgram();
225 }
226
227 GLuint
228 _GlCreateShader_2(GLenum type)
229 {
230         return glCreateShader(type);
231 }
232
233 void
234 _GlCullFace_2(GLenum mode)
235 {
236         glCullFace(mode);
237 }
238
239 void
240 _GlDeleteBuffers_2(GLsizei n, const GLuint* pBuffers)
241 {
242         glDeleteBuffers(n, pBuffers);
243 }
244
245 void
246 _GlDeleteFramebuffers_2(GLsizei n, const GLuint* pFramebuffers)
247 {
248         glDeleteFramebuffers(n, pFramebuffers);
249 }
250
251 void
252 _GlDeleteProgram_2(GLuint program)
253 {
254         glDeleteProgram(program);
255 }
256
257 void
258 _GlDeleteRenderbuffers_2(GLsizei n, const GLuint* pRenderbuffers)
259 {
260         glDeleteRenderbuffers(n, pRenderbuffers);
261 }
262
263 void
264 _GlDeleteShader_2(GLuint shader)
265 {
266         glDeleteShader(shader);
267 }
268
269 void
270 _GlDeleteTextures_2(GLsizei n, const GLuint* pTextures)
271 {
272         glDeleteTextures(n, pTextures);
273 }
274
275 void
276 _GlDepthFunc_2(GLenum func)
277 {
278         glDepthFunc(func);
279 }
280
281 void
282 _GlDepthMask_2(GLboolean flag)
283 {
284         glDepthMask(flag);
285 }
286
287 void
288 _GlDepthRangef_2(GLclampf zNear, GLclampf zFar)
289 {
290         glDepthRangef(zNear, zFar);
291 }
292
293 void
294 _GlDetachShader_2(GLuint program, GLuint shader)
295 {
296         glDetachShader(program, shader);
297 }
298
299 void
300 _GlDisable_2(GLenum cap)
301 {
302         glDisable(cap);
303 }
304
305 void
306 _GlDisableVertexAttribArray_2(GLuint index)
307 {
308         glDisableVertexAttribArray(index);
309 }
310
311 void
312 _GlDrawArrays_2(GLenum mode, GLint first, GLsizei count)
313 {
314         glDrawArrays(mode, first, count);
315 }
316
317 void
318 _GlDrawElements_2(GLenum mode, GLsizei count, GLenum type, const void* pIndices)
319 {
320         glDrawElements(mode, count, type, pIndices);
321 }
322
323 void
324 _GlEnable_2(GLenum cap)
325 {
326         glEnable(cap);
327 }
328
329 void
330 _GlEnableVertexAttribArray_2(GLuint index)
331 {
332         glEnableVertexAttribArray(index);
333 }
334
335 void
336 _GlFinish_2(void)
337 {
338         glFinish();
339 }
340
341 void
342 _GlFlush_2(void)
343 {
344         glFlush();
345 }
346
347 void
348 _GlFramebufferRenderbuffer_2(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
349 {
350         glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
351 }
352
353 void
354 _GlFramebufferTexture2D_2(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
355 {
356         glFramebufferTexture2D(target, attachment, textarget, texture, level);
357 }
358
359 void
360 _GlFrontFace_2(GLenum mode)
361 {
362         glFrontFace(mode);
363 }
364
365 void
366 _GlGenBuffers_2(GLsizei n, GLuint* pBuffers)
367 {
368         glGenBuffers(n, pBuffers);
369 }
370
371 void
372 _GlGenerateMipmap_2(GLenum target)
373 {
374         glGenerateMipmap(target);
375 }
376
377 void
378 _GlGenFramebuffers_2(GLsizei n, GLuint* pFramebuffers)
379 {
380         glGenFramebuffers(n, pFramebuffers);
381 }
382
383 void
384 _GlGenRenderbuffers_2(GLsizei n, GLuint* pRenderbuffers)
385 {
386         glGenRenderbuffers(n, pRenderbuffers);
387 }
388
389 void
390 _GlGenTextures_2(GLsizei n, GLuint* pTextures)
391 {
392         glGenTextures(n, pTextures);
393 }
394
395 void
396 _GlGetActiveAttrib_2(GLuint program, GLuint index, GLsizei bufsize,
397                 GLsizei* pLength, GLint* pSize, GLenum* pType, char* pName)
398 {
399         glGetActiveAttrib(program, index, bufsize, pLength, pSize, pType, pName);
400 }
401
402 void
403 _GlGetActiveUniform_2(GLuint program, GLuint index, GLsizei bufsize,
404                 GLsizei* pLength, GLint* pSize, GLenum* pType, char* pName)
405 {
406         glGetActiveUniform(program, index, bufsize, pLength, pSize, pType, pName);
407 }
408
409 void
410 _GlGetAttachedShaders_2(GLuint program, GLsizei maxcount, GLsizei* pCount, GLuint* pShaders)
411 {
412         glGetAttachedShaders(program, maxcount, pCount, pShaders);
413 }
414
415 int
416 _GlGetAttribLocation_2(GLuint program, const char* pName)
417 {
418         return glGetAttribLocation(program, pName);
419 }
420
421 void
422 _GlGetBooleanv_2(GLenum pname, GLboolean* pParams)
423 {
424         glGetBooleanv(pname, pParams);
425 }
426
427 void
428 _GlGetBufferParameteriv_2(GLenum target, GLenum pname, GLint* pParams)
429 {
430         glGetBufferParameteriv(target, pname, pParams);
431 }
432
433 GLenum
434 _GlGetError_2(void)
435 {
436         return glGetError();
437 }
438
439 void
440 _GlGetFloatv_2(GLenum pname, GLfloat* pParams)
441 {
442         glGetFloatv(pname, pParams);
443 }
444
445 void
446 _GlGetFramebufferAttachmentParameteriv_2(GLenum target, GLenum attachment, GLenum pname, GLint* pParams)
447 {
448         glGetFramebufferAttachmentParameteriv(target, attachment, pname, pParams);
449 }
450
451 void
452 _GlGetIntegerv_2(GLenum pname, GLint* pParams)
453 {
454         glGetIntegerv(pname, pParams);
455 }
456
457 void
458 _GlGetProgramiv_2(GLuint program, GLenum pname, GLint* pParams)
459 {
460         glGetProgramiv(program, pname, pParams);
461 }
462
463 void
464 _GlGetProgramInfoLog_2(GLuint program, GLsizei bufsize, GLsizei* pLength, char* pInfolog)
465 {
466         glGetProgramInfoLog(program, bufsize, pLength, pInfolog);
467 }
468
469 void
470 _GlGetRenderbufferParameteriv_2(GLenum target, GLenum pname, GLint* pParams)
471 {
472         glGetRenderbufferParameteriv(target, pname, pParams);
473 }
474
475 void
476 _GlGetShaderiv_2(GLuint shader, GLenum pname, GLint* pParams)
477 {
478         glGetShaderiv(shader, pname, pParams);
479 }
480
481 void
482 _GlGetShaderInfoLog_2(GLuint shader, GLsizei bufsize, GLsizei* pLength, char* pInfolog)
483 {
484         glGetShaderInfoLog(shader, bufsize, pLength, pInfolog);
485 }
486
487 void
488 _GlGetShaderPrecisionFormat_2(GLenum shadertype, GLenum precisiontype, GLint* pRange, GLint* pPrecision)
489 {
490         glGetShaderPrecisionFormat(shadertype, precisiontype, pRange, pPrecision);
491 }
492
493 void
494 _GlGetShaderSource_2(GLuint shader, GLsizei bufsize, GLsizei* pLength, char* pSource)
495 {
496         glGetShaderSource(shader, bufsize, pLength, pSource);
497 }
498
499 const GLubyte*
500 _GlGetString_2(GLenum name)
501 {
502         return glGetString(name);
503 }
504
505 void
506 _GlGetTexParameterfv_2(GLenum target, GLenum pname, GLfloat* pParams)
507 {
508         glGetTexParameterfv(target, pname, pParams);
509 }
510
511 void
512 _GlGetTexParameteriv_2(GLenum target, GLenum pname, GLint* pParams)
513 {
514         glGetTexParameteriv(target, pname, pParams);
515 }
516
517 void
518 _GlGetUniformfv_2(GLuint program, GLint location, GLfloat* pParams)
519 {
520         glGetUniformfv(program, location, pParams);
521 }
522
523 void
524 _GlGetUniformiv_2(GLuint program, GLint location, GLint* pParams)
525 {
526         glGetUniformiv(program, location, pParams);
527 }
528
529 int
530 _GlGetUniformLocation_2(GLuint program, const char* pName)
531 {
532         return glGetUniformLocation(program, pName);
533 }
534
535 void
536 _GlGetVertexAttribfv_2(GLuint index, GLenum pname, GLfloat* pParams)
537 {
538         glGetVertexAttribfv(index, pname, pParams);
539 }
540
541 void
542 _GlGetVertexAttribiv_2(GLuint index, GLenum pname, GLint* pParams)
543 {
544         glGetVertexAttribiv(index, pname, pParams);
545 }
546
547 void
548 _GlGetVertexAttribPointerv_2(GLuint index, GLenum pname, void** ppPointer)
549 {
550         glGetVertexAttribPointerv(index, pname, ppPointer);
551 }
552
553 void
554 _GlHint_2(GLenum target, GLenum mode)
555 {
556         glHint(target, mode);
557 }
558
559 GLboolean
560 _GlIsBuffer_2(GLuint buffer)
561 {
562         return glIsBuffer(buffer);
563 }
564
565 GLboolean
566 _GlIsEnabled_2(GLenum cap)
567 {
568         return glIsEnabled(cap);
569 }
570
571 GLboolean
572 _GlIsFramebuffer_2(GLuint framebuffer)
573 {
574         return glIsFramebuffer(framebuffer);
575 }
576
577 GLboolean
578 _GlIsProgram_2(GLuint program)
579 {
580         return glIsProgram(program);
581 }
582
583 GLboolean
584 _GlIsRenderbuffer_2(GLuint renderbuffer)
585 {
586         return glIsRenderbuffer(renderbuffer);
587 }
588
589 GLboolean
590 _GlIsShader_2(GLuint shader)
591 {
592         return glIsShader(shader);
593 }
594
595 GLboolean
596 _GlIsTexture_2(GLuint texture)
597 {
598         return glIsTexture(texture);
599 }
600
601 void
602 _GlLineWidth_2(GLfloat width)
603 {
604         glLineWidth(width);
605 }
606
607 void
608 _GlLinkProgram_2(GLuint program)
609 {
610         glLinkProgram(program);
611 }
612
613 void
614 _GlPixelStorei_2(GLenum pname, GLint param)
615 {
616         glPixelStorei(pname, param);
617 }
618
619 void
620 _GlPolygonOffset_2(GLfloat factor, GLfloat units)
621 {
622         glPolygonOffset(factor, units);
623 }
624
625 void
626 _GlReadPixels_2(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pPixels)
627 {
628         glReadPixels(x, y, width, height, format, type, pPixels);
629 }
630
631 void
632 _GlReleaseShaderCompiler_2(void)
633 {
634         glReleaseShaderCompiler();
635 }
636
637 void
638 _GlRenderbufferStorage_2(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
639 {
640         glRenderbufferStorage(target, internalformat, width, height);
641 }
642
643 void
644 _GlSampleCoverage_2(GLclampf value, GLboolean invert)
645 {
646         glSampleCoverage(value, invert);
647 }
648
649 void
650 _GlScissor_2(GLint x, GLint y, GLsizei width, GLsizei height)
651 {
652         glScissor(x, y, width, height);
653 }
654
655 void
656 _GlShaderBinary_2(GLint n, GLuint* pShaders, GLenum binaryformat, const void* pBinary, GLint length)
657 {
658         glShaderBinary(n, pShaders, binaryformat, pBinary, length);
659 }
660
661 void
662 _GlShaderSource_2(GLuint shader, GLsizei count, const char** pString, const GLint* pLength)
663 {
664         glShaderSource(shader, count, pString, pLength);
665 }
666
667 void
668 _GlStencilFunc_2(GLenum func, GLint ref, GLuint mask)
669 {
670         glStencilFunc(func, ref, mask);
671 }
672
673 void
674 _GlStencilFuncSeparate_2(GLenum face, GLenum func, GLint ref, GLuint mask)
675 {
676         glStencilFuncSeparate(face, func, ref, mask);
677 }
678
679 void
680 _GlStencilMask_2(GLuint mask)
681 {
682         glStencilMask(mask);
683 }
684
685 void
686 _GlStencilMaskSeparate_2(GLenum face, GLuint mask)
687 {
688         glStencilMaskSeparate(face, mask);
689 }
690
691 void
692 _GlStencilOp_2(GLenum fail, GLenum zfail, GLenum zpass)
693 {
694         glStencilOp(fail, zfail, zpass);
695 }
696
697 void
698 _GlStencilOpSeparate_2(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
699 {
700         glStencilOpSeparate(face, fail, zfail, zpass);
701 }
702
703 void
704 _GlTexImage2D_2(GLenum target, GLint level, GLenum internalformat,
705                 GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pPixels)
706 {
707         glTexImage2D(target, level, internalformat, width, height, border, format, type, pPixels);
708 }
709
710 void
711 _GlTexParameterf_2(GLenum target, GLenum pname, GLfloat param)
712 {
713         glTexParameterf(target, pname, param);
714 }
715
716 void
717 _GlTexParameterfv_2(GLenum target, GLenum pname, const GLfloat* pParams)
718 {
719         glTexParameterfv(target, pname, pParams);
720 }
721
722 void
723 _GlTexParameteri_2(GLenum target, GLenum pname, GLint param)
724 {
725         glTexParameteri(target, pname, param);
726 }
727
728 void
729 _GlTexParameteriv_2(GLenum target, GLenum pname, const GLint* pParams)
730 {
731         glTexParameteriv(target, pname, pParams);
732 }
733
734 void
735 _GlTexSubImage2D_2(GLenum target, GLint level, GLint xoffset, GLint yoffset,
736                 GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pPixels)
737 {
738         glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pPixels);
739 }
740
741 void
742 _GlUniform1f_2(GLint location, GLfloat x)
743 {
744         glUniform1f(location, x);
745 }
746
747 void
748 _GlUniform1fv_2(GLint location, GLsizei count, const GLfloat* pV)
749 {
750         glUniform1fv(location, count, pV);
751 }
752
753 void
754 _GlUniform1i_2(GLint location, GLint x)
755 {
756         glUniform1i(location, x);
757 }
758
759 void
760 _GlUniform1iv_2(GLint location, GLsizei count, const GLint* pV)
761 {
762         glUniform1iv(location, count, pV);
763 }
764
765 void
766 _GlUniform2f_2(GLint location, GLfloat x, GLfloat y)
767 {
768         glUniform2f(location, x, y);
769 }
770
771 void
772 _GlUniform2fv_2(GLint location, GLsizei count, const GLfloat* pV)
773 {
774         glUniform2fv(location, count, pV);
775 }
776
777 void
778 _GlUniform2i_2(GLint location, GLint x, GLint y)
779 {
780         glUniform2i(location, x, y);
781 }
782
783 void
784 _GlUniform2iv_2(GLint location, GLsizei count, const GLint* pV)
785 {
786         glUniform2iv(location, count, pV);
787 }
788
789 void
790 _GlUniform3f_2(GLint location, GLfloat x, GLfloat y, GLfloat z)
791 {
792         glUniform3f(location, x, y, z);
793 }
794
795 void
796 _GlUniform3fv_2(GLint location, GLsizei count, const GLfloat* pV)
797 {
798         glUniform3fv(location, count, pV);
799 }
800
801 void
802 _GlUniform3i_2(GLint location, GLint x, GLint y, GLint z)
803 {
804         glUniform3i(location, x, y, z);
805 }
806
807 void
808 _GlUniform3iv_2(GLint location, GLsizei count, const GLint* pV)
809 {
810         glUniform3iv(location, count, pV);
811 }
812
813 void
814 _GlUniform4f_2(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
815 {
816         glUniform4f(location, x, y, z, w);
817 }
818
819 void
820 _GlUniform4fv_2(GLint location, GLsizei count, const GLfloat* pV)
821 {
822         glUniform4fv(location, count, pV);
823 }
824
825 void
826 _GlUniform4i_2(GLint location, GLint x, GLint y, GLint z, GLint w)
827 {
828         glUniform4i(location, x, y, z, w);
829 }
830
831 void
832 _GlUniform4iv_2(GLint location, GLsizei count, const GLint* pV)
833 {
834         glUniform4iv(location, count, pV);
835 }
836
837 void
838 _GlUniformMatrix2fv_2(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue)
839 {
840         glUniformMatrix2fv(location, count, transpose, pValue);
841 }
842
843 void
844 _GlUniformMatrix3fv_2(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue)
845 {
846         glUniformMatrix3fv(location, count, transpose, pValue);
847 }
848
849 void
850 _GlUniformMatrix4fv_2(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue)
851 {
852         glUniformMatrix4fv(location, count, transpose, pValue);
853 }
854
855 void
856 _GlUseProgram_2(GLuint program)
857 {
858         glUseProgram(program);
859 }
860
861 void
862 _GlValidateProgram_2(GLuint program)
863 {
864         glValidateProgram(program);
865 }
866
867 void
868 _GlVertexAttrib1f_2(GLuint indx, GLfloat x)
869 {
870         glVertexAttrib1f(indx, x);
871 }
872
873 void
874 _GlVertexAttrib1fv_2(GLuint indx, const GLfloat* pValues)
875 {
876         glVertexAttrib1fv(indx, pValues);
877 }
878
879 void
880 _GlVertexAttrib2f_2(GLuint indx, GLfloat x, GLfloat y)
881 {
882         glVertexAttrib2f(indx, x, y);
883 }
884
885 void
886 _GlVertexAttrib2fv_2(GLuint indx, const GLfloat* pValues)
887 {
888         glVertexAttrib2fv(indx, pValues);
889 }
890
891 void
892 _GlVertexAttrib3f_2(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
893 {
894         glVertexAttrib3f(indx, x, y, z);
895 }
896
897 void
898 _GlVertexAttrib3fv_2(GLuint indx, const GLfloat* pValues)
899 {
900         glVertexAttrib3fv(indx, pValues);
901 }
902
903 void
904 _GlVertexAttrib4f_2(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
905 {
906         glVertexAttrib4f(indx, x, y, z, w);
907 }
908
909 void
910 _GlVertexAttrib4fv_2(GLuint indx, const GLfloat* pValues)
911 {
912         glVertexAttrib4fv(indx, pValues);
913 }
914
915 void
916 _GlVertexAttribPointer_2(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pPtr)
917 {
918         glVertexAttribPointer(indx, size, type, normalized, stride, pPtr);
919 }
920
921 void
922 _GlViewport_2(GLint x, GLint y, GLsizei width, GLsizei height)
923 {
924         glViewport(x, y, width, height);
925 }
926
927 #ifdef __cplusplus
928 }
929 #endif
930
931 #else
932
933 #define _GLES_CHECK_INTERFACE_VOID_2 if (!_GlesInterfaceInitialize_2()) \
934         { \
935                 return; \
936         }
937 #define _GLES_CHECK_INTERFACE_GLBOOLEAN_2 if (!_GlesInterfaceInitialize_2()) \
938         { \
939                 return GL_FALSE; \
940         }
941 #define _GLES_CHECK_INTERFACE_GLENUM_2 if (!_GlesInterfaceInitialize_2()) \
942         { \
943                 return 0; \
944         }
945 #define _GLES_CHECK_INTERFACE_CONSTGLUBYTEP_2 if (!_GlesInterfaceInitialize_2()) \
946         { \
947                 return (const GLubyte*) 0; \
948         }
949 #define _GLES_CHECK_INTERFACE_GLUINT_2 if (!_GlesInterfaceInitialize_2()) \
950         { \
951                 return 0; \
952         }
953 #define _GLES_CHECK_INTERFACE_INT_2 if (!_GlesInterfaceInitialize_2()) \
954         { \
955                 return -1; \
956         }
957
958 namespace // unnamed
959 {
960
961 struct _GlesInterface2
962 {
963         void (* glActiveTexture)(GLenum texture);
964         void (* glAttachShader)(GLuint program, GLuint shader);
965         void (* glBindAttribLocation)(GLuint program, GLuint index, const char* pName);
966         void (* glBindBuffer)(GLenum target, GLuint buffer);
967         void (* glBindFramebuffer)(GLenum target, GLuint framebuffer);
968         void (* glBindRenderbuffer)(GLenum target, GLuint renderbuffer);
969         void (* glBindTexture)(GLenum target, GLuint texture);
970         void (* glBlendColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
971         void (* glBlendEquation)(GLenum mode);
972         void (* glBlendEquationSeparate)(GLenum modeRGB, GLenum modeAlpha);
973         void (* glBlendFunc)(GLenum sfactor, GLenum dfactor);
974         void (* glBlendFuncSeparate)(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
975         void (* glBufferData)(GLenum target, GLsizeiptr size, const void* pData, GLenum usage);
976         void (* glBufferSubData)(GLenum target, GLintptr offset, GLsizeiptr size, const void* pData);
977         GLenum (* glCheckFramebufferStatus)(GLenum target);
978         void (* glClear)(GLbitfield mask);
979         void (* glClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
980         void (* glClearDepthf)(GLclampf depth);
981         void (* glClearStencil)(GLint s);
982         void (* glColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
983         void (* glCompileShader)(GLuint shader);
984         void (* glCompressedTexImage2D)(GLenum target, GLint level, GLenum internalformat,
985                         GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* pData);
986         void (* glCompressedTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset,
987                         GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* pData);
988         void (* glCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y,
989                         GLsizei width, GLsizei height, GLint border);
990         void (* glCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y,
991                         GLsizei width, GLsizei height);
992         GLuint (* glCreateProgram)(void);
993         GLuint (* glCreateShader)(GLenum type);
994         void (* glCullFace)(GLenum mode);
995         void (* glDeleteBuffers)(GLsizei n, const GLuint* pBuffers);
996         void (* glDeleteFramebuffers)(GLsizei n, const GLuint* pFramebuffers);
997         void (* glDeleteProgram)(GLuint program);
998         void (* glDeleteRenderbuffers)(GLsizei n, const GLuint* pRenderbuffers);
999         void (* glDeleteShader)(GLuint shader);
1000         void (* glDeleteTextures)(GLsizei n, const GLuint* pTextures);
1001         void (* glDepthFunc)(GLenum func);
1002         void (* glDepthMask)(GLboolean flag);
1003         void (* glDepthRangef)(GLclampf zNear, GLclampf zFar);
1004         void (* glDetachShader)(GLuint program, GLuint shader);
1005         void (* glDisable)(GLenum cap);
1006         void (* glDisableVertexAttribArray)(GLuint index);
1007         void (* glDrawArrays)(GLenum mode, GLint first, GLsizei count);
1008         void (* glDrawElements)(GLenum mode, GLsizei count, GLenum type, const void* pIndices);
1009         void (* glEnable)(GLenum cap);
1010         void (* glEnableVertexAttribArray)(GLuint index);
1011         void (* glFinish)(void);
1012         void (* glFlush)(void);
1013         void (* glFramebufferRenderbuffer)(GLenum target, GLenum attachment,
1014                         GLenum renderbuffertarget, GLuint renderbuffer);
1015         void (* glFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
1016         void (* glFrontFace)(GLenum mode);
1017         void (* glGenBuffers)(GLsizei n, GLuint* pBuffers);
1018         void (* glGenerateMipmap)(GLenum target);
1019         void (* glGenFramebuffers)(GLsizei n, GLuint* pFramebuffers);
1020         void (* glGenRenderbuffers)(GLsizei n, GLuint* pRenderbuffers);
1021         void (* glGenTextures)(GLsizei n, GLuint* pTextures);
1022         void (* glGetActiveAttrib)(GLuint program, GLuint index, GLsizei bufsize,
1023                         GLsizei* pLength, GLint* pSize, GLenum* pType, char* pName);
1024         void (* glGetActiveUniform)(GLuint program, GLuint index, GLsizei bufsize, GLsizei* pLength, GLint* pSize,
1025                         GLenum* pType, char* pName);
1026         void (* glGetAttachedShaders)(GLuint program, GLsizei maxcount, GLsizei* pCount, GLuint* pShaders);
1027         int (* glGetAttribLocation)(GLuint program, const char* pName);
1028         void (* glGetBooleanv)(GLenum pname, GLboolean* pParams);
1029         void (* glGetBufferParameteriv)(GLenum target, GLenum pname, GLint* pParams);
1030         GLenum (* glGetError)(void);
1031         void (* glGetFloatv)(GLenum pname, GLfloat* pParams);
1032         void (* glGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment, GLenum pname, GLint* pParams);
1033         void (* glGetIntegerv)(GLenum pname, GLint* pParams);
1034         void (* glGetProgramiv)(GLuint program, GLenum pname, GLint* pParams);
1035         void (* glGetProgramInfoLog)(GLuint program, GLsizei bufsize, GLsizei* pLength, char* pInfolog);
1036         void (* glGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint* pParams);
1037         void (* glGetShaderiv)(GLuint shader, GLenum pname, GLint* pParams);
1038         void (* glGetShaderInfoLog)(GLuint shader, GLsizei bufsize, GLsizei* pLength, char* pInfolog);
1039         void (* glGetShaderPrecisionFormat)(GLenum shadertype, GLenum precisiontype, GLint* pRange, GLint* pPrecision);
1040         void (* glGetShaderSource)(GLuint shader, GLsizei bufsize, GLsizei* pLength, char* pSource);
1041         const GLubyte* (*glGetString)(GLenum name);
1042         void (* glGetTexParameterfv)(GLenum target, GLenum pname, GLfloat* pParams);
1043         void (* glGetTexParameteriv)(GLenum target, GLenum pname, GLint* pParams);
1044         void (* glGetUniformfv)(GLuint program, GLint location, GLfloat* pParams);
1045         void (* glGetUniformiv)(GLuint program, GLint location, GLint* pParams);
1046         int (* glGetUniformLocation)(GLuint program, const char* pName);
1047         void (* glGetVertexAttribfv)(GLuint index, GLenum pname, GLfloat* pParams);
1048         void (* glGetVertexAttribiv)(GLuint index, GLenum pname, GLint* pParams);
1049         void (* glGetVertexAttribPointerv)(GLuint index, GLenum pname, void** ppPointer);
1050         void (* glHint)(GLenum target, GLenum mode);
1051         GLboolean (* glIsBuffer)(GLuint buffer);
1052         GLboolean (* glIsEnabled)(GLenum cap);
1053         GLboolean (* glIsFramebuffer)(GLuint framebuffer);
1054         GLboolean (* glIsProgram)(GLuint program);
1055         GLboolean (* glIsRenderbuffer)(GLuint renderbuffer);
1056         GLboolean (* glIsShader)(GLuint shader);
1057         GLboolean (* glIsTexture)(GLuint texture);
1058         void (* glLineWidth)(GLfloat width);
1059         void (* glLinkProgram)(GLuint program);
1060         void (* glPixelStorei)(GLenum pname, GLint param);
1061         void (* glPolygonOffset)(GLfloat factor, GLfloat units);
1062         void (* glReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pPixels);
1063         void (* glReleaseShaderCompiler)(void);
1064         void (* glRenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
1065         void (* glSampleCoverage)(GLclampf value, GLboolean invert);
1066         void (* glScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
1067         void (* glShaderBinary)(GLint n, GLuint* pShaders, GLenum binaryformat, const void* pBinary, GLint length);
1068         void (* glShaderSource)(GLuint shader, GLsizei count, const char** ppString, const GLint* pLength);
1069         void (* glStencilFunc)(GLenum func, GLint ref, GLuint mask);
1070         void (* glStencilFuncSeparate)(GLenum face, GLenum func, GLint ref, GLuint mask);
1071         void (* glStencilMask)(GLuint mask);
1072         void (* glStencilMaskSeparate)(GLenum face, GLuint mask);
1073         void (* glStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
1074         void (* glStencilOpSeparate)(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
1075         void (* glTexImage2D)(GLenum target, GLint level, GLenum internalformat,
1076                         GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pPixels);
1077         void (* glTexParameterf)(GLenum target, GLenum pname, GLfloat param);
1078         void (* glTexParameterfv)(GLenum target, GLenum pname, const GLfloat* pParams);
1079         void (* glTexParameteri)(GLenum target, GLenum pname, GLint param);
1080         void (* glTexParameteriv)(GLenum target, GLenum pname, const GLint* pParams);
1081         void (* glTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset,
1082                         GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pPixels);
1083         void (* glUniform1f)(GLint location, GLfloat x);
1084         void (* glUniform1fv)(GLint location, GLsizei count, const GLfloat* pV);
1085         void (* glUniform1i)(GLint location, GLint x);
1086         void (* glUniform1iv)(GLint location, GLsizei count, const GLint* pV);
1087         void (* glUniform2f)(GLint location, GLfloat x, GLfloat y);
1088         void (* glUniform2fv)(GLint location, GLsizei count, const GLfloat* pV);
1089         void (* glUniform2i)(GLint location, GLint x, GLint y);
1090         void (* glUniform2iv)(GLint location, GLsizei count, const GLint* pV);
1091         void (* glUniform3f)(GLint location, GLfloat x, GLfloat y, GLfloat z);
1092         void (* glUniform3fv)(GLint location, GLsizei count, const GLfloat* pV);
1093         void (* glUniform3i)(GLint location, GLint x, GLint y, GLint z);
1094         void (* glUniform3iv)(GLint location, GLsizei count, const GLint* pV);
1095         void (* glUniform4f)(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
1096         void (* glUniform4fv)(GLint location, GLsizei count, const GLfloat* pV);
1097         void (* glUniform4i)(GLint location, GLint x, GLint y, GLint z, GLint w);
1098         void (* glUniform4iv)(GLint location, GLsizei count, const GLint* pV);
1099         void (* glUniformMatrix2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue);
1100         void (* glUniformMatrix3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue);
1101         void (* glUniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue);
1102         void (* glUseProgram)(GLuint program);
1103         void (* glValidateProgram)(GLuint program);
1104         void (* glVertexAttrib1f)(GLuint indx, GLfloat x);
1105         void (* glVertexAttrib1fv)(GLuint indx, const GLfloat* pValues);
1106         void (* glVertexAttrib2f)(GLuint indx, GLfloat x, GLfloat y);
1107         void (* glVertexAttrib2fv)(GLuint indx, const GLfloat* pValues);
1108         void (* glVertexAttrib3f)(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
1109         void (* glVertexAttrib3fv)(GLuint indx, const GLfloat* pValues);
1110         void (* glVertexAttrib4f)(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
1111         void (* glVertexAttrib4fv)(GLuint indx, const GLfloat* pValues);
1112         void (* glVertexAttribPointer)(GLuint indx, GLint size,
1113                         GLenum type, GLboolean normalized, GLsizei stride, const void* pPtr);
1114         void (* glViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
1115 };
1116
1117 void* _pGlesLib2 = NULL;
1118 _GlesInterface2 _glesImpl2 = {0, };
1119
1120 const int _MAX_GLES_FUNCTION_2 = 142;
1121 const char _glesStrings2[_MAX_GLES_FUNCTION_2][64] =
1122 {
1123         "glActiveTexture",
1124         "glAttachShader",
1125         "glBindAttribLocation",
1126         "glBindBuffer",
1127         "glBindFramebuffer",
1128         "glBindRenderbuffer",
1129         "glBindTexture",
1130         "glBlendColor",
1131         "glBlendEquation",
1132         "glBlendEquationSeparate",
1133         "glBlendFunc", //10
1134         "glBlendFuncSeparate",
1135         "glBufferData",
1136         "glBufferSubData",
1137         "glCheckFramebufferStatus",
1138         "glClear",
1139         "glClearColor",
1140         "glClearDepthf",
1141         "glClearStencil",
1142         "glColorMask",
1143         "glCompileShader", //20
1144         "glCompressedTexImage2D",
1145         "glCompressedTexSubImage2D",
1146         "glCopyTexImage2D",
1147         "glCopyTexSubImage2D",
1148         "glCreateProgram",
1149         "glCreateShader",
1150         "glCullFace",
1151         "glDeleteBuffers",
1152         "glDeleteFramebuffers",
1153         "glDeleteProgram", //30
1154         "glDeleteRenderbuffers",
1155         "glDeleteShader",
1156         "glDeleteTextures",
1157         "glDepthFunc",
1158         "glDepthMask",
1159         "glDepthRangef",
1160         "glDetachShader",
1161         "glDisable",
1162         "glDisableVertexAttribArray",
1163         "glDrawArrays", //40
1164         "glDrawElements",
1165         "glEnable",
1166         "glEnableVertexAttribArray",
1167         "glFinish",
1168         "glFlush",
1169         "glFramebufferRenderbuffer",
1170         "glFramebufferTexture2D",
1171         "glFrontFace",
1172         "glGenBuffers",
1173         "glGenerateMipmap", //50
1174         "glGenFramebuffers",
1175         "glGenRenderbuffers",
1176         "glGenTextures",
1177         "glGetActiveAttrib",
1178         "glGetActiveUniform",
1179         "glGetAttachedShaders",
1180         "glGetAttribLocation",
1181         "glGetBooleanv",
1182         "glGetBufferParameteriv",
1183         "glGetError", //60
1184         "glGetFloatv",
1185         "glGetFramebufferAttachmentParameteriv",
1186         "glGetIntegerv",
1187         "glGetProgramiv",
1188         "glGetProgramInfoLog",
1189         "glGetRenderbufferParameteriv",
1190         "glGetShaderiv",
1191         "glGetShaderInfoLog",
1192         "glGetShaderPrecisionFormat",
1193         "glGetShaderSource", //70
1194         "glGetString",
1195         "glGetTexParameterfv",
1196         "glGetTexParameteriv",
1197         "glGetUniformfv",
1198         "glGetUniformiv",
1199         "glGetUniformLocation",
1200         "glGetVertexAttribfv",
1201         "glGetVertexAttribiv",
1202         "glGetVertexAttribPointerv",
1203         "glHint", //80
1204         "glIsBuffer",
1205         "glIsEnabled",
1206         "glIsFramebuffer",
1207         "glIsProgram",
1208         "glIsRenderbuffer",
1209         "glIsShader",
1210         "glIsTexture",
1211         "glLineWidth",
1212         "glLinkProgram",
1213         "glPixelStorei", //90
1214         "glPolygonOffset",
1215         "glReadPixels",
1216         "glReleaseShaderCompiler",
1217         "glRenderbufferStorage",
1218         "glSampleCoverage",
1219         "glScissor",
1220         "glShaderBinary",
1221         "glShaderSource",
1222         "glStencilFunc",
1223         "glStencilFuncSeparate", //100
1224         "glStencilMask",
1225         "glStencilMaskSeparate",
1226         "glStencilOp",
1227         "glStencilOpSeparate",
1228         "glTexImage2D",
1229         "glTexParameterf",
1230         "glTexParameterfv",
1231         "glTexParameteri",
1232         "glTexParameteriv",
1233         "glTexSubImage2D", //110
1234         "glUniform1f",
1235         "glUniform1fv",
1236         "glUniform1i",
1237         "glUniform1iv",
1238         "glUniform2f",
1239         "glUniform2fv",
1240         "glUniform2i",
1241         "glUniform2iv",
1242         "glUniform3f",
1243         "glUniform3fv", //120
1244         "glUniform3i",
1245         "glUniform3iv",
1246         "glUniform4f",
1247         "glUniform4fv",
1248         "glUniform4i",
1249         "glUniform4iv",
1250         "glUniformMatrix2fv",
1251         "glUniformMatrix3fv",
1252         "glUniformMatrix4fv",
1253         "glUseProgram", //130
1254         "glValidateProgram",
1255         "glVertexAttrib1f",
1256         "glVertexAttrib1fv",
1257         "glVertexAttrib2f",
1258         "glVertexAttrib2fv",
1259         "glVertexAttrib3f",
1260         "glVertexAttrib3fv",
1261         "glVertexAttrib4f",
1262         "glVertexAttrib4fv",
1263         "glVertexAttribPointer", //140
1264         "glViewport"
1265 };
1266
1267 bool
1268 _GlesInterfaceInitialize_2(void)
1269 {
1270         int count = 0;
1271
1272         if (_pGlesLib2 == NULL)
1273         {
1274                 ptrdiff_t** ppPtr = (ptrdiff_t**) (&_glesImpl2);
1275
1276                 _pGlesLib2 = dlopen("libGLESv2.so", RTLD_LAZY | RTLD_GLOBAL);
1277                 if (_pGlesLib2 == NULL)
1278                 {
1279                         SysLog(NID_GRP, "gles2 dlopen failed! %s", dlerror());
1280                         return false;
1281                 }
1282
1283                 for (count = 0; count < _MAX_GLES_FUNCTION_2; count++)
1284                 {
1285                         *ppPtr = (ptrdiff_t*) (dlsym(_pGlesLib2, _glesStrings2[count]));
1286
1287                         if (*ppPtr == NULL)
1288                         {
1289                                 SysLog(NID_GRP, "dlsym failed! %s name : %s", dlerror(), _glesStrings2[count]);
1290                         }
1291                         ppPtr++;
1292                 }
1293         }
1294
1295         return true;
1296 }
1297
1298 }
1299
1300 #ifdef __cplusplus
1301 extern "C"
1302 {
1303 #endif
1304
1305 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
1306 GLuint _GlesGetCurrentFbo(void);
1307 bool _GlesFboEnableStencil(GLuint& frameBufferObject, GLuint& renderBuffer);
1308 #endif
1309
1310 _OSP_LOCAL_ void
1311 _GlesInterfaceTerminate_2(void)
1312 {
1313         if (_pGlesLib2 != NULL)
1314         {
1315                 dlclose(_pGlesLib2);
1316                 _pGlesLib2 = NULL;
1317         }
1318 }
1319
1320 void
1321 _GlActiveTexture_2(GLenum texture)
1322 {
1323         _GLES_CHECK_INTERFACE_VOID_2
1324         _glesImpl2.glActiveTexture(texture);
1325 }
1326
1327 void
1328 _GlAttachShader_2(GLuint program, GLuint shader)
1329 {
1330         _GLES_CHECK_INTERFACE_VOID_2
1331         _glesImpl2.glAttachShader(program, shader);
1332 }
1333
1334 void
1335 _GlBindAttribLocation_2(GLuint program, GLuint index, const char* pNname)
1336 {
1337         _GLES_CHECK_INTERFACE_VOID_2
1338         _glesImpl2.glBindAttribLocation(program, index, pNname);
1339 }
1340
1341 void
1342 _GlBindBuffer_2(GLenum target, GLuint buffer)
1343 {
1344         _GLES_CHECK_INTERFACE_VOID_2
1345         _glesImpl2.glBindBuffer(target, buffer);
1346 }
1347
1348 void
1349 _GlBindFramebuffer_2(GLenum target, GLuint framebuffer)
1350 {
1351         _GLES_CHECK_INTERFACE_VOID_2
1352
1353 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
1354         if (framebuffer == 0)
1355         {
1356                 framebuffer = _GlesGetCurrentFbo();
1357         }
1358 #endif
1359
1360         _glesImpl2.glBindFramebuffer(target, framebuffer);
1361 }
1362
1363 void
1364 _GlBindRenderbuffer_2(GLenum target, GLuint renderbuffer)
1365 {
1366         _GLES_CHECK_INTERFACE_VOID_2
1367         _glesImpl2.glBindRenderbuffer(target, renderbuffer);
1368 }
1369
1370 void
1371 _GlBindTexture_2(GLenum target, GLuint texture)
1372 {
1373         _GLES_CHECK_INTERFACE_VOID_2
1374         _glesImpl2.glBindTexture(target, texture);
1375 }
1376
1377 void
1378 _GlBlendColor_2(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1379 {
1380         _GLES_CHECK_INTERFACE_VOID_2
1381         _glesImpl2.glBlendColor(red, green, blue, alpha);
1382 }
1383
1384 void
1385 _GlBlendEquation_2(GLenum mode)
1386 {
1387         _GLES_CHECK_INTERFACE_VOID_2
1388         _glesImpl2.glBlendEquation(mode);
1389 }
1390
1391 void
1392 _GlBlendEquationSeparate_2(GLenum modeRGB, GLenum modeAlpha)
1393 {
1394         _GLES_CHECK_INTERFACE_VOID_2
1395         _glesImpl2.glBlendEquationSeparate(modeRGB, modeAlpha);
1396 }
1397
1398 void
1399 _GlBlendFunc_2(GLenum sfactor, GLenum dfactor)
1400 {
1401         _GLES_CHECK_INTERFACE_VOID_2
1402         _glesImpl2.glBlendFunc(sfactor, dfactor);
1403 }
1404
1405 void
1406 _GlBlendFuncSeparate_2(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
1407 {
1408         _GLES_CHECK_INTERFACE_VOID_2
1409         _glesImpl2.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
1410 }
1411
1412 void
1413 _GlBufferData_2(GLenum target, GLsizeiptr size, const void* pData, GLenum usage)
1414 {
1415         _GLES_CHECK_INTERFACE_VOID_2
1416         _glesImpl2.glBufferData(target, size, pData, usage);
1417 }
1418
1419 void
1420 _GlBufferSubData_2(GLenum target, GLintptr offset, GLsizeiptr size, const void* pData)
1421 {
1422         _GLES_CHECK_INTERFACE_VOID_2
1423         _glesImpl2.glBufferSubData(target, offset, size, pData);
1424 }
1425
1426 GLenum
1427 _GlCheckFramebufferStatus_2(GLenum target)
1428 {
1429         _GLES_CHECK_INTERFACE_GLENUM_2
1430         return _glesImpl2.glCheckFramebufferStatus(target);
1431 }
1432
1433 void
1434 _GlClear_2(GLbitfield mask)
1435 {
1436         _GLES_CHECK_INTERFACE_VOID_2
1437         _glesImpl2.glClear(mask);
1438 }
1439
1440 void
1441 _GlClearColor_2(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1442 {
1443         _GLES_CHECK_INTERFACE_VOID_2
1444         _glesImpl2.glClearColor(red, green, blue, alpha);
1445 }
1446
1447 void
1448 _GlClearDepthf_2(GLclampf depth)
1449 {
1450         _GLES_CHECK_INTERFACE_VOID_2
1451         _glesImpl2.glClearDepthf(depth);
1452 }
1453
1454 void
1455 _GlClearStencil_2(GLint s)
1456 {
1457         _GLES_CHECK_INTERFACE_VOID_2
1458         _glesImpl2.glClearStencil(s);
1459 }
1460
1461 void
1462 _GlColorMask_2(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
1463 {
1464         _GLES_CHECK_INTERFACE_VOID_2
1465         _glesImpl2.glColorMask(red, green, blue, alpha);
1466 }
1467
1468 void
1469 _GlCompileShader_2(GLuint shader)
1470 {
1471         _GLES_CHECK_INTERFACE_VOID_2
1472         _glesImpl2.glCompileShader(shader);
1473 }
1474
1475 void
1476 _GlCompressedTexImage2D_2(GLenum target, GLint level, GLenum internalformat,
1477                 GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* pData)
1478 {
1479         _GLES_CHECK_INTERFACE_VOID_2
1480         _glesImpl2.glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, pData);
1481 }
1482
1483 void
1484 _GlCompressedTexSubImage2D_2(GLenum target, GLint level, GLint xoffset, GLint yoffset,
1485                 GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* pData)
1486 {
1487         _GLES_CHECK_INTERFACE_VOID_2
1488         _glesImpl2.glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, pData);
1489 }
1490
1491 void
1492 _GlCopyTexImage2D_2(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y,
1493                 GLsizei width, GLsizei height, GLint border)
1494 {
1495         _GLES_CHECK_INTERFACE_VOID_2
1496         _glesImpl2.glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
1497 }
1498
1499 void
1500 _GlCopyTexSubImage2D_2(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x,
1501                 GLint y, GLsizei width, GLsizei height)
1502 {
1503         _GLES_CHECK_INTERFACE_VOID_2
1504         _glesImpl2.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
1505 }
1506
1507 GLuint
1508 _GlCreateProgram_2(void)
1509 {
1510         _GLES_CHECK_INTERFACE_GLUINT_2
1511         return _glesImpl2.glCreateProgram();
1512 }
1513
1514 GLuint
1515 _GlCreateShader_2(GLenum type)
1516 {
1517         _GLES_CHECK_INTERFACE_GLUINT_2
1518         return _glesImpl2.glCreateShader(type);
1519 }
1520
1521 void
1522 _GlCullFace_2(GLenum mode)
1523 {
1524         _GLES_CHECK_INTERFACE_VOID_2
1525         _glesImpl2.glCullFace(mode);
1526 }
1527
1528 void
1529 _GlDeleteBuffers_2(GLsizei n, const GLuint* pBuffers)
1530 {
1531         _GLES_CHECK_INTERFACE_VOID_2
1532         _glesImpl2.glDeleteBuffers(n, pBuffers);
1533 }
1534
1535 void
1536 _GlDeleteFramebuffers_2(GLsizei n, const GLuint* pFramebuffers)
1537 {
1538         _GLES_CHECK_INTERFACE_VOID_2
1539         _glesImpl2.glDeleteFramebuffers(n, pFramebuffers);
1540 }
1541
1542 void
1543 _GlDeleteProgram_2(GLuint program)
1544 {
1545         _GLES_CHECK_INTERFACE_VOID_2
1546         _glesImpl2.glDeleteProgram(program);
1547 }
1548
1549 void
1550 _GlDeleteRenderbuffers_2(GLsizei n, const GLuint* pRenderbuffers)
1551 {
1552         _GLES_CHECK_INTERFACE_VOID_2
1553         _glesImpl2.glDeleteRenderbuffers(n, pRenderbuffers);
1554 }
1555
1556 void
1557 _GlDeleteShader_2(GLuint shader)
1558 {
1559         _GLES_CHECK_INTERFACE_VOID_2
1560         _glesImpl2.glDeleteShader(shader);
1561 }
1562
1563 void
1564 _GlDeleteTextures_2(GLsizei n, const GLuint* pTextures)
1565 {
1566         _GLES_CHECK_INTERFACE_VOID_2
1567         _glesImpl2.glDeleteTextures(n, pTextures);
1568 }
1569
1570 void
1571 _GlDepthFunc_2(GLenum func)
1572 {
1573         _GLES_CHECK_INTERFACE_VOID_2
1574         _glesImpl2.glDepthFunc(func);
1575 }
1576
1577 void
1578 _GlDepthMask_2(GLboolean flag)
1579 {
1580         _GLES_CHECK_INTERFACE_VOID_2
1581         _glesImpl2.glDepthMask(flag);
1582 }
1583
1584 void
1585 _GlDepthRangef_2(GLclampf zNear, GLclampf zFar)
1586 {
1587         _GLES_CHECK_INTERFACE_VOID_2
1588         _glesImpl2.glDepthRangef(zNear, zFar);
1589 }
1590
1591 void
1592 _GlDetachShader_2(GLuint program, GLuint shader)
1593 {
1594         _GLES_CHECK_INTERFACE_VOID_2
1595         _glesImpl2.glDetachShader(program, shader);
1596 }
1597
1598 void
1599 _GlDisable_2(GLenum cap)
1600 {
1601         _GLES_CHECK_INTERFACE_VOID_2
1602         _glesImpl2.glDisable(cap);
1603 }
1604
1605 void
1606 _GlDisableVertexAttribArray_2(GLuint index)
1607 {
1608         _GLES_CHECK_INTERFACE_VOID_2
1609         _glesImpl2.glDisableVertexAttribArray(index);
1610 }
1611
1612 void
1613 _GlDrawArrays_2(GLenum mode, GLint first, GLsizei count)
1614 {
1615         _GLES_CHECK_INTERFACE_VOID_2
1616         _glesImpl2.glDrawArrays(mode, first, count);
1617 }
1618
1619 void
1620 _GlDrawElements_2(GLenum mode, GLsizei count, GLenum type, const void* pIndices)
1621 {
1622         _GLES_CHECK_INTERFACE_VOID_2
1623         _glesImpl2.glDrawElements(mode, count, type, pIndices);
1624 }
1625
1626 void
1627 _GlEnable_2(GLenum cap)
1628 {
1629         _GLES_CHECK_INTERFACE_VOID_2
1630 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
1631         if (cap == GL_STENCIL_TEST)
1632         {
1633                 GLuint frameBufferObject = 0;
1634                 GLuint stencilRenderBuffer = 0;
1635
1636                 bool ret = _GlesFboEnableStencil(frameBufferObject, stencilRenderBuffer);
1637
1638                 if (ret)
1639                 {
1640                         _glesImpl2.glBindFramebuffer(GL_FRAMEBUFFER, frameBufferObject);
1641                         _glesImpl2.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRenderBuffer);
1642                 }
1643         }
1644 #endif
1645         _glesImpl2.glEnable(cap);
1646 }
1647
1648 void
1649 _GlEnableVertexAttribArray_2(GLuint index)
1650 {
1651         _GLES_CHECK_INTERFACE_VOID_2
1652         _glesImpl2.glEnableVertexAttribArray(index);
1653 }
1654
1655 void
1656 _GlFinish_2(void)
1657 {
1658         _GLES_CHECK_INTERFACE_VOID_2
1659         _glesImpl2.glFinish();
1660 }
1661
1662 void
1663 _GlFlush_2(void)
1664 {
1665         _GLES_CHECK_INTERFACE_VOID_2
1666         _glesImpl2.glFlush();
1667 }
1668
1669 void
1670 _GlFramebufferRenderbuffer_2(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1671 {
1672         _GLES_CHECK_INTERFACE_VOID_2
1673         _glesImpl2.glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
1674 }
1675
1676 void
1677 _GlFramebufferTexture2D_2(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1678 {
1679         _GLES_CHECK_INTERFACE_VOID_2
1680         _glesImpl2.glFramebufferTexture2D(target, attachment, textarget, texture, level);
1681 }
1682
1683 void
1684 _GlFrontFace_2(GLenum mode)
1685 {
1686         _GLES_CHECK_INTERFACE_VOID_2
1687         _glesImpl2.glFrontFace(mode);
1688 }
1689
1690 void
1691 _GlGenBuffers_2(GLsizei n, GLuint* pBuffers)
1692 {
1693         _GLES_CHECK_INTERFACE_VOID_2
1694         _glesImpl2.glGenBuffers(n, pBuffers);
1695 }
1696
1697 void
1698 _GlGenerateMipmap_2(GLenum target)
1699 {
1700         _GLES_CHECK_INTERFACE_VOID_2
1701         _glesImpl2.glGenerateMipmap(target);
1702 }
1703
1704 void
1705 _GlGenFramebuffers_2(GLsizei n, GLuint* pFramebuffers)
1706 {
1707         _GLES_CHECK_INTERFACE_VOID_2
1708         _glesImpl2.glGenFramebuffers(n, pFramebuffers);
1709 }
1710
1711 void
1712 _GlGenRenderbuffers_2(GLsizei n, GLuint* pRenderbuffers)
1713 {
1714         _GLES_CHECK_INTERFACE_VOID_2
1715         _glesImpl2.glGenRenderbuffers(n, pRenderbuffers);
1716 }
1717
1718 void
1719 _GlGenTextures_2(GLsizei n, GLuint* textures)
1720 {
1721         _GLES_CHECK_INTERFACE_VOID_2
1722         _glesImpl2.glGenTextures(n, textures);
1723 }
1724
1725 void
1726 _GlGetActiveAttrib_2(GLuint program, GLuint index, GLsizei bufsize,
1727                 GLsizei* pLength, GLint* pSize, GLenum* pType, char* pName)
1728 {
1729         _GLES_CHECK_INTERFACE_VOID_2
1730         _glesImpl2.glGetActiveAttrib(program, index, bufsize, pLength, pSize, pType, pName);
1731 }
1732
1733 void
1734 _GlGetActiveUniform_2(GLuint program, GLuint index, GLsizei bufsize,
1735                 GLsizei* pLength, GLint* pSize, GLenum* pType, char* pName)
1736 {
1737         _GLES_CHECK_INTERFACE_VOID_2
1738         _glesImpl2.glGetActiveUniform(program, index, bufsize, pLength, pSize, pType, pName);
1739 }
1740
1741 void
1742 _GlGetAttachedShaders_2(GLuint program, GLsizei maxcount, GLsizei* pCount, GLuint* pShaders)
1743 {
1744         _GLES_CHECK_INTERFACE_VOID_2
1745         _glesImpl2.glGetAttachedShaders(program, maxcount, pCount, pShaders);
1746 }
1747
1748 int
1749 _GlGetAttribLocation_2(GLuint program, const char* pName)
1750 {
1751         _GLES_CHECK_INTERFACE_INT_2
1752         return _glesImpl2.glGetAttribLocation(program, pName);
1753 }
1754
1755 void
1756 _GlGetBooleanv_2(GLenum pname, GLboolean* pParams)
1757 {
1758         _GLES_CHECK_INTERFACE_VOID_2
1759         _glesImpl2.glGetBooleanv(pname, pParams);
1760 }
1761
1762 void
1763 _GlGetBufferParameteriv_2(GLenum target, GLenum pname, GLint* pParams)
1764 {
1765         _GLES_CHECK_INTERFACE_VOID_2
1766         _glesImpl2.glGetBufferParameteriv(target, pname, pParams);
1767 }
1768
1769 GLenum
1770 _GlGetError_2(void)
1771 {
1772         _GLES_CHECK_INTERFACE_GLENUM_2
1773         return _glesImpl2.glGetError();
1774 }
1775
1776 void
1777 _GlGetFloatv_2(GLenum pname, GLfloat* pParams)
1778 {
1779         _GLES_CHECK_INTERFACE_VOID_2
1780         _glesImpl2.glGetFloatv(pname, pParams);
1781 }
1782
1783 void
1784 _GlGetFramebufferAttachmentParameteriv_2(GLenum target, GLenum attachment, GLenum pname, GLint* pParams)
1785 {
1786         _GLES_CHECK_INTERFACE_VOID_2
1787         _glesImpl2.glGetFramebufferAttachmentParameteriv(target, attachment, pname, pParams);
1788 }
1789
1790 void
1791 _GlGetIntegerv_2(GLenum pname, GLint* pParams)
1792 {
1793         _GLES_CHECK_INTERFACE_VOID_2
1794         _glesImpl2.glGetIntegerv(pname, pParams);
1795 }
1796
1797 void
1798 _GlGetProgramiv_2(GLuint program, GLenum pname, GLint* pParams)
1799 {
1800         _GLES_CHECK_INTERFACE_VOID_2
1801         _glesImpl2.glGetProgramiv(program, pname, pParams);
1802 }
1803
1804 void
1805 _GlGetProgramInfoLog_2(GLuint program, GLsizei bufsize, GLsizei* pLength, char* pInfolog)
1806 {
1807         _GLES_CHECK_INTERFACE_VOID_2
1808         _glesImpl2.glGetProgramInfoLog(program, bufsize, pLength, pInfolog);
1809 }
1810
1811 void
1812 _GlGetRenderbufferParameteriv_2(GLenum target, GLenum pname, GLint* pParams)
1813 {
1814         _GLES_CHECK_INTERFACE_VOID_2
1815         _glesImpl2.glGetRenderbufferParameteriv(target, pname, pParams);
1816 }
1817
1818 void
1819 _GlGetShaderiv_2(GLuint shader, GLenum pname, GLint* pParams)
1820 {
1821         _GLES_CHECK_INTERFACE_VOID_2
1822         _glesImpl2.glGetShaderiv(shader, pname, pParams);
1823 }
1824
1825 void
1826 _GlGetShaderInfoLog_2(GLuint shader, GLsizei bufsize, GLsizei* pLength, char* pInfolog)
1827 {
1828         _GLES_CHECK_INTERFACE_VOID_2
1829         _glesImpl2.glGetShaderInfoLog(shader, bufsize, pLength, pInfolog);
1830 }
1831
1832 void
1833 _GlGetShaderPrecisionFormat_2(GLenum shadertype, GLenum precisiontype, GLint* pRange, GLint* pPrecision)
1834 {
1835         _GLES_CHECK_INTERFACE_VOID_2
1836         _glesImpl2.glGetShaderPrecisionFormat(shadertype, precisiontype, pRange, pPrecision);
1837 }
1838
1839 void
1840 _GlGetShaderSource_2(GLuint shader, GLsizei bufsize, GLsizei* pLength, char* pSource)
1841 {
1842         _GLES_CHECK_INTERFACE_VOID_2
1843         _glesImpl2.glGetShaderSource(shader, bufsize, pLength, pSource);
1844 }
1845
1846 const GLubyte*
1847 _GlGetString_2(GLenum name)
1848 {
1849         _GLES_CHECK_INTERFACE_CONSTGLUBYTEP_2
1850         return _glesImpl2.glGetString(name);
1851 }
1852
1853 void
1854 _GlGetTexParameterfv_2(GLenum target, GLenum pname, GLfloat* pParams)
1855 {
1856         _GLES_CHECK_INTERFACE_VOID_2
1857         _glesImpl2.glGetTexParameterfv(target, pname, pParams);
1858 }
1859
1860 void
1861 _GlGetTexParameteriv_2(GLenum target, GLenum pname, GLint* pParams)
1862 {
1863         _GLES_CHECK_INTERFACE_VOID_2
1864         _glesImpl2.glGetTexParameteriv(target, pname, pParams);
1865 }
1866
1867 void
1868 _GlGetUniformfv_2(GLuint program, GLint location, GLfloat* pParams)
1869 {
1870         _GLES_CHECK_INTERFACE_VOID_2
1871         _glesImpl2.glGetUniformfv(program, location, pParams);
1872 }
1873
1874 void
1875 _GlGetUniformiv_2(GLuint program, GLint location, GLint* pParams)
1876 {
1877         _GLES_CHECK_INTERFACE_VOID_2
1878         _glesImpl2.glGetUniformiv(program, location, pParams);
1879 }
1880
1881 int
1882 _GlGetUniformLocation_2(GLuint program, const char* pName)
1883 {
1884         _GLES_CHECK_INTERFACE_INT_2
1885         return _glesImpl2.glGetUniformLocation(program, pName);
1886 }
1887
1888 void
1889 _GlGetVertexAttribfv_2(GLuint index, GLenum pname, GLfloat* pParams)
1890 {
1891         _GLES_CHECK_INTERFACE_VOID_2
1892         _glesImpl2.glGetVertexAttribfv(index, pname, pParams);
1893 }
1894
1895 void
1896 _GlGetVertexAttribiv_2(GLuint index, GLenum pname, GLint* pParams)
1897 {
1898         _GLES_CHECK_INTERFACE_VOID_2
1899         _glesImpl2.glGetVertexAttribiv(index, pname, pParams);
1900 }
1901
1902 void
1903 _GlGetVertexAttribPointerv_2(GLuint index, GLenum pname, void** ppPointer)
1904 {
1905         _GLES_CHECK_INTERFACE_VOID_2
1906         _glesImpl2.glGetVertexAttribPointerv(index, pname, ppPointer);
1907 }
1908
1909 void
1910 _GlHint_2(GLenum target, GLenum mode)
1911 {
1912         _GLES_CHECK_INTERFACE_VOID_2
1913         _glesImpl2.glHint(target, mode);
1914 }
1915
1916 GLboolean
1917 _GlIsBuffer_2(GLuint buffer)
1918 {
1919         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
1920         return _glesImpl2.glIsBuffer(buffer);
1921 }
1922
1923 GLboolean
1924 _GlIsEnabled_2(GLenum cap)
1925 {
1926         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
1927         return _glesImpl2.glIsEnabled(cap);
1928 }
1929
1930 GLboolean
1931 _GlIsFramebuffer_2(GLuint framebuffer)
1932 {
1933         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
1934         return _glesImpl2.glIsFramebuffer(framebuffer);
1935 }
1936
1937 GLboolean
1938 _GlIsProgram_2(GLuint program)
1939 {
1940         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
1941         return _glesImpl2.glIsProgram(program);
1942 }
1943
1944 GLboolean
1945 _GlIsRenderbuffer_2(GLuint renderbuffer)
1946 {
1947         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
1948         return _glesImpl2.glIsRenderbuffer(renderbuffer);
1949 }
1950
1951 GLboolean
1952 _GlIsShader_2(GLuint shader)
1953 {
1954         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
1955         return _glesImpl2.glIsShader(shader);
1956 }
1957
1958 GLboolean
1959 _GlIsTexture_2(GLuint texture)
1960 {
1961         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
1962         return _glesImpl2.glIsTexture(texture);
1963 }
1964
1965 void
1966 _GlLineWidth_2(GLfloat width)
1967 {
1968         _GLES_CHECK_INTERFACE_VOID_2
1969         _glesImpl2.glLineWidth(width);
1970 }
1971
1972 void
1973 _GlLinkProgram_2(GLuint program)
1974 {
1975         _GLES_CHECK_INTERFACE_VOID_2
1976         _glesImpl2.glLinkProgram(program);
1977 }
1978
1979 void
1980 _GlPixelStorei_2(GLenum pname, GLint param)
1981 {
1982         _GLES_CHECK_INTERFACE_VOID_2
1983         _glesImpl2.glPixelStorei(pname, param);
1984 }
1985
1986 void
1987 _GlPolygonOffset_2(GLfloat factor, GLfloat units)
1988 {
1989         _GLES_CHECK_INTERFACE_VOID_2
1990         _glesImpl2.glPolygonOffset(factor, units);
1991 }
1992
1993 void
1994 _GlReadPixels_2(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pPixels)
1995 {
1996         _GLES_CHECK_INTERFACE_VOID_2
1997         _glesImpl2.glReadPixels(x, y, width, height, format, type, pPixels);
1998 }
1999
2000 void
2001 _GlReleaseShaderCompiler_2(void)
2002 {
2003         _GLES_CHECK_INTERFACE_VOID_2
2004         _glesImpl2.glReleaseShaderCompiler();
2005 }
2006
2007 void
2008 _GlRenderbufferStorage_2(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
2009 {
2010         _GLES_CHECK_INTERFACE_VOID_2
2011         _glesImpl2.glRenderbufferStorage(target, internalformat, width, height);
2012 }
2013
2014 void
2015 _GlSampleCoverage_2(GLclampf value, GLboolean invert)
2016 {
2017         _GLES_CHECK_INTERFACE_VOID_2
2018         _glesImpl2.glSampleCoverage(value, invert);
2019 }
2020
2021 void
2022 _GlScissor_2(GLint x, GLint y, GLsizei width, GLsizei height)
2023 {
2024         _GLES_CHECK_INTERFACE_VOID_2
2025         _glesImpl2.glScissor(x, y, width, height);
2026 }
2027
2028 void
2029 _GlShaderBinary_2(GLint n, GLuint* shaders, GLenum binaryformat, const void* pBinary, GLint length)
2030 {
2031         _GLES_CHECK_INTERFACE_VOID_2
2032         _glesImpl2.glShaderBinary(n, shaders, binaryformat, pBinary, length);
2033 }
2034
2035 void
2036 _GlShaderSource_2(GLuint shader, GLsizei count, const char** ppString, const GLint* pLength)
2037 {
2038         _GLES_CHECK_INTERFACE_VOID_2
2039         _glesImpl2.glShaderSource(shader, count, ppString, pLength);
2040 }
2041
2042 void
2043 _GlStencilFunc_2(GLenum func, GLint ref, GLuint mask)
2044 {
2045         _GLES_CHECK_INTERFACE_VOID_2
2046         _glesImpl2.glStencilFunc(func, ref, mask);
2047 }
2048
2049 void
2050 _GlStencilFuncSeparate_2(GLenum face, GLenum func, GLint ref, GLuint mask)
2051 {
2052         _GLES_CHECK_INTERFACE_VOID_2
2053         _glesImpl2.glStencilFuncSeparate(face, func, ref, mask);
2054 }
2055
2056 void
2057 _GlStencilMask_2(GLuint mask)
2058 {
2059         _GLES_CHECK_INTERFACE_VOID_2
2060         _glesImpl2.glStencilMask(mask);
2061 }
2062
2063 void
2064 _GlStencilMaskSeparate_2(GLenum face, GLuint mask)
2065 {
2066         _GLES_CHECK_INTERFACE_VOID_2
2067         _glesImpl2.glStencilMaskSeparate(face, mask);
2068 }
2069
2070 void
2071 _GlStencilOp_2(GLenum fail, GLenum zfail, GLenum zpass)
2072 {
2073         _GLES_CHECK_INTERFACE_VOID_2
2074         _glesImpl2.glStencilOp(fail, zfail, zpass);
2075 }
2076
2077 void
2078 _GlStencilOpSeparate_2(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
2079 {
2080         _GLES_CHECK_INTERFACE_VOID_2
2081         _glesImpl2.glStencilOpSeparate(face, fail, zfail, zpass);
2082 }
2083
2084 void
2085 _GlTexImage2D_2(GLenum target, GLint level, GLenum internalformat,
2086                 GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pPixels)
2087 {
2088         _GLES_CHECK_INTERFACE_VOID_2
2089         _glesImpl2.glTexImage2D(target, level, internalformat, width, height, border, format, type, pPixels);
2090 }
2091
2092 void
2093 _GlTexParameterf_2(GLenum target, GLenum pname, GLfloat param)
2094 {
2095         _GLES_CHECK_INTERFACE_VOID_2
2096         _glesImpl2.glTexParameterf(target, pname, param);
2097 }
2098
2099 void
2100 _GlTexParameterfv_2(GLenum target, GLenum pname, const GLfloat* pParams)
2101 {
2102         _GLES_CHECK_INTERFACE_VOID_2
2103         _glesImpl2.glTexParameterfv(target, pname, pParams);
2104 }
2105
2106 void
2107 _GlTexParameteri_2(GLenum target, GLenum pname, GLint param)
2108 {
2109         _GLES_CHECK_INTERFACE_VOID_2
2110         _glesImpl2.glTexParameteri(target, pname, param);
2111 }
2112
2113 void
2114 _GlTexParameteriv_2(GLenum target, GLenum pname, const GLint* pParams)
2115 {
2116         _GLES_CHECK_INTERFACE_VOID_2
2117         _glesImpl2.glTexParameteriv(target, pname, pParams);
2118 }
2119
2120 void
2121 _GlTexSubImage2D_2(GLenum target, GLint level, GLint xoffset, GLint yoffset,
2122                 GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pPixels)
2123 {
2124         _GLES_CHECK_INTERFACE_VOID_2
2125         _glesImpl2.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pPixels);
2126 }
2127
2128 void
2129 _GlUniform1f_2(GLint location, GLfloat x)
2130 {
2131         _GLES_CHECK_INTERFACE_VOID_2
2132         _glesImpl2.glUniform1f(location, x);
2133 }
2134
2135 void
2136 _GlUniform1fv_2(GLint location, GLsizei count, const GLfloat* pV)
2137 {
2138         _GLES_CHECK_INTERFACE_VOID_2
2139         _glesImpl2.glUniform1fv(location, count, pV);
2140 }
2141
2142 void
2143 _GlUniform1i_2(GLint location, GLint x)
2144 {
2145         _GLES_CHECK_INTERFACE_VOID_2
2146         _glesImpl2.glUniform1i(location, x);
2147 }
2148
2149 void
2150 _GlUniform1iv_2(GLint location, GLsizei count, const GLint* pV)
2151 {
2152         _GLES_CHECK_INTERFACE_VOID_2
2153         _glesImpl2.glUniform1iv(location, count, pV);
2154 }
2155
2156 void
2157 _GlUniform2f_2(GLint location, GLfloat x, GLfloat y)
2158 {
2159         _GLES_CHECK_INTERFACE_VOID_2
2160         _glesImpl2.glUniform2f(location, x, y);
2161 }
2162
2163 void
2164 _GlUniform2fv_2(GLint location, GLsizei count, const GLfloat* pV)
2165 {
2166         _GLES_CHECK_INTERFACE_VOID_2
2167         _glesImpl2.glUniform2fv(location, count, pV);
2168 }
2169
2170 void
2171 _GlUniform2i_2(GLint location, GLint x, GLint y)
2172 {
2173         _GLES_CHECK_INTERFACE_VOID_2
2174         _glesImpl2.glUniform2i(location, x, y);
2175 }
2176
2177 void
2178 _GlUniform2iv_2(GLint location, GLsizei count, const GLint* pV)
2179 {
2180         _GLES_CHECK_INTERFACE_VOID_2
2181         _glesImpl2.glUniform2iv(location, count, pV);
2182 }
2183
2184 void
2185 _GlUniform3f_2(GLint location, GLfloat x, GLfloat y, GLfloat z)
2186 {
2187         _GLES_CHECK_INTERFACE_VOID_2
2188         _glesImpl2.glUniform3f(location, x, y, z);
2189 }
2190
2191 void
2192 _GlUniform3fv_2(GLint location, GLsizei count, const GLfloat* pV)
2193 {
2194         _GLES_CHECK_INTERFACE_VOID_2
2195         _glesImpl2.glUniform3fv(location, count, pV);
2196 }
2197
2198 void
2199 _GlUniform3i_2(GLint location, GLint x, GLint y, GLint z)
2200 {
2201         _GLES_CHECK_INTERFACE_VOID_2
2202         _glesImpl2.glUniform3i(location, x, y, z);
2203 }
2204
2205 void
2206 _GlUniform3iv_2(GLint location, GLsizei count, const GLint* pV)
2207 {
2208         _GLES_CHECK_INTERFACE_VOID_2
2209         _glesImpl2.glUniform3iv(location, count, pV);
2210 }
2211
2212 void
2213 _GlUniform4f_2(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
2214 {
2215         _GLES_CHECK_INTERFACE_VOID_2
2216         _glesImpl2.glUniform4f(location, x, y, z, w);
2217 }
2218
2219 void
2220 _GlUniform4fv_2(GLint location, GLsizei count, const GLfloat* pV)
2221 {
2222         _GLES_CHECK_INTERFACE_VOID_2
2223         _glesImpl2.glUniform4fv(location, count, pV);
2224 }
2225
2226 void
2227 _GlUniform4i_2(GLint location, GLint x, GLint y, GLint z, GLint w)
2228 {
2229         _GLES_CHECK_INTERFACE_VOID_2
2230         _glesImpl2.glUniform4i(location, x, y, z, w);
2231 }
2232
2233 void
2234 _GlUniform4iv_2(GLint location, GLsizei count, const GLint* v)
2235 {
2236         _GLES_CHECK_INTERFACE_VOID_2
2237         _glesImpl2.glUniform4iv(location, count, v);
2238 }
2239
2240 void
2241 _GlUniformMatrix2fv_2(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue)
2242 {
2243         _GLES_CHECK_INTERFACE_VOID_2
2244         _glesImpl2.glUniformMatrix2fv(location, count, transpose, pValue);
2245 }
2246
2247 void
2248 _GlUniformMatrix3fv_2(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue)
2249 {
2250         _GLES_CHECK_INTERFACE_VOID_2
2251         _glesImpl2.glUniformMatrix3fv(location, count, transpose, pValue);
2252 }
2253
2254 void
2255 _GlUniformMatrix4fv_2(GLint location, GLsizei count, GLboolean transpose, const GLfloat* pValue)
2256 {
2257         _GLES_CHECK_INTERFACE_VOID_2
2258         _glesImpl2.glUniformMatrix4fv(location, count, transpose, pValue);
2259 }
2260
2261 void
2262 _GlUseProgram_2(GLuint program)
2263 {
2264         _GLES_CHECK_INTERFACE_VOID_2
2265         _glesImpl2.glUseProgram(program);
2266 }
2267
2268 void
2269 _GlValidateProgram_2(GLuint program)
2270 {
2271         _GLES_CHECK_INTERFACE_VOID_2
2272         _glesImpl2.glValidateProgram(program);
2273 }
2274
2275 void
2276 _GlVertexAttrib1f_2(GLuint indx, GLfloat x)
2277 {
2278         _GLES_CHECK_INTERFACE_VOID_2
2279         _glesImpl2.glVertexAttrib1f(indx, x);
2280 }
2281
2282 void
2283 _GlVertexAttrib1fv_2(GLuint indx, const GLfloat* pValues)
2284 {
2285         _GLES_CHECK_INTERFACE_VOID_2
2286         _glesImpl2.glVertexAttrib1fv(indx, pValues);
2287 }
2288
2289 void
2290 _GlVertexAttrib2f_2(GLuint indx, GLfloat x, GLfloat y)
2291 {
2292         _GLES_CHECK_INTERFACE_VOID_2
2293         _glesImpl2.glVertexAttrib2f(indx, x, y);
2294 }
2295
2296 void
2297 _GlVertexAttrib2fv_2(GLuint indx, const GLfloat* pValues)
2298 {
2299         _GLES_CHECK_INTERFACE_VOID_2
2300         _glesImpl2.glVertexAttrib2fv(indx, pValues);
2301 }
2302
2303 void
2304 _GlVertexAttrib3f_2(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
2305 {
2306         _GLES_CHECK_INTERFACE_VOID_2
2307         _glesImpl2.glVertexAttrib3f(indx, x, y, z);
2308 }
2309
2310 void
2311 _GlVertexAttrib3fv_2(GLuint indx, const GLfloat* pValues)
2312 {
2313         _GLES_CHECK_INTERFACE_VOID_2
2314         _glesImpl2.glVertexAttrib3fv(indx, pValues);
2315 }
2316
2317 void
2318 _GlVertexAttrib4f_2(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
2319 {
2320         _GLES_CHECK_INTERFACE_VOID_2
2321         _glesImpl2.glVertexAttrib4f(indx, x, y, z, w);
2322 }
2323
2324 void
2325 _GlVertexAttrib4fv_2(GLuint indx, const GLfloat* pValues)
2326 {
2327         _GLES_CHECK_INTERFACE_VOID_2
2328         _glesImpl2.glVertexAttrib4fv(indx, pValues);
2329 }
2330
2331 void
2332 _GlVertexAttribPointer_2(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pPtr)
2333 {
2334         _GLES_CHECK_INTERFACE_VOID_2
2335         _glesImpl2.glVertexAttribPointer(indx, size, type, normalized, stride, pPtr);
2336 }
2337
2338 void
2339 _GlViewport_2(GLint x, GLint y, GLsizei width, GLsizei height)
2340 {
2341         _GLES_CHECK_INTERFACE_VOID_2
2342         _glesImpl2.glViewport(x, y, width, height);
2343 }
2344
2345 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
2346 _OSP_LOCAL_ bool
2347 _CreateShader(GLuint& program)
2348 {
2349         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
2350         const char* VERTEX_TEXT =
2351                 "attribute vec4 aPosition;\n"
2352                 "attribute vec2 aTextureCoord;\n"
2353                 "varying vec2 vTextureCoord;\n"
2354                 "\n"
2355                 "void main()\n"
2356                 "{\n"
2357                 "    gl_Position = aPosition;\n"
2358                 "    vTextureCoord = aTextureCoord;\n"
2359                 "}";
2360
2361         const char* FRAGMENT_TEXT =
2362                 "precision highp float;\n"
2363                 "uniform sampler2D uTexture;\n"
2364                 "varying vec2 vTextureCoord;\n"
2365                 "\n"
2366                 "void main (void)\n"
2367                 "{\n"
2368                 "    gl_FragColor = texture2D(uTexture, vTextureCoord);\n"
2369                 "}";
2370
2371         GLint linked = GL_FALSE;
2372         GLint bShaderCompiled = GL_FALSE;
2373         GLuint fragShader = _glesImpl2.glCreateShader(GL_FRAGMENT_SHADER);
2374         GLuint vertShader = _glesImpl2.glCreateShader(GL_VERTEX_SHADER);
2375
2376         _glesImpl2.glShaderSource(fragShader, 1, (const char**)(&FRAGMENT_TEXT), NULL);
2377         _glesImpl2.glCompileShader(fragShader);
2378         _glesImpl2.glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bShaderCompiled);
2379
2380         _glesImpl2.glShaderSource(vertShader, 1, (const char**)&VERTEX_TEXT, NULL);
2381         _glesImpl2.glCompileShader(vertShader);
2382         _glesImpl2.glGetShaderiv(vertShader, GL_COMPILE_STATUS, &bShaderCompiled);
2383
2384         program = _glesImpl2.glCreateProgram();
2385
2386         _glesImpl2.glAttachShader(program, fragShader);
2387         _glesImpl2.glAttachShader(program, vertShader);
2388         _glesImpl2.glLinkProgram(program);
2389         _glesImpl2.glGetProgramiv(program, GL_LINK_STATUS, &linked);
2390
2391         _glesImpl2.glDeleteShader(fragShader);
2392         _glesImpl2.glDeleteShader(vertShader);
2393
2394         if (linked == GL_FALSE)
2395         {
2396                 GLint infoLen = 0;
2397                 _glesImpl2.glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen);
2398                 if (infoLen > 1)
2399                 {
2400                         std::unique_ptr<char[]> autoPtrInfoLog(new (std::nothrow) char[infoLen]);
2401                         _glesImpl2.glGetProgramInfoLog(program, infoLen, NULL, autoPtrInfoLog.get());
2402                         SysLog(NID_GRP, "FBO Program Linking failed. log: %s", autoPtrInfoLog.get());
2403                 }
2404                 return false;
2405         }
2406
2407         return true;
2408 }
2409
2410 _OSP_LOCAL_ void
2411 _GlesFboTerminate_2(GLuint& frameBufferObject, GLuint& depthRenderBuffer
2412                 , GLuint& stencilRenderBuffer, GLuint& textureId, GLuint& program)
2413 {
2414         _GLES_CHECK_INTERFACE_VOID_2
2415         _glesImpl2.glBindFramebuffer(GL_FRAMEBUFFER, 0);
2416
2417         if (frameBufferObject != 0)
2418         {
2419                 _glesImpl2.glDeleteFramebuffers(1, &frameBufferObject);
2420                 frameBufferObject = 0;
2421         }
2422
2423         if (depthRenderBuffer != 0)
2424         {
2425                 _glesImpl2.glDeleteRenderbuffers(1, &depthRenderBuffer);
2426                 depthRenderBuffer = 0;
2427         }
2428
2429         if (stencilRenderBuffer != 0)
2430         {
2431                 _glesImpl2.glDeleteRenderbuffers(1, &depthRenderBuffer);
2432                 depthRenderBuffer = 0;
2433         }
2434
2435         if (textureId != 0)
2436         {
2437                 _glesImpl2.glDeleteTextures(1, &textureId);
2438                 textureId = 0;
2439         }
2440
2441         if (program != 0)
2442         {
2443                 _glesImpl2.glDeleteProgram(program);
2444                 program = 0;
2445         }
2446 }
2447
2448 _OSP_LOCAL_ bool
2449 _GlesFboInitialize_2(const int fboWidth, const int fboHeight, GLuint& frameBufferObject
2450                 , GLuint& depthRenderBuffer, GLuint& stencilRenderBuffer, GLuint colorSize
2451                 , GLuint depthSize, GLuint stencilSize, GLuint& textureId, GLuint& program)
2452 {
2453         _GLES_CHECK_INTERFACE_GLBOOLEAN_2
2454         if (!_CreateShader(program))
2455         {
2456                 return false;
2457         }
2458
2459         GLint maxSize = 0;
2460         _glesImpl2.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxSize);
2461         if (fboWidth > maxSize || fboHeight > maxSize)
2462         {
2463                 SysLog(NID_GRP, "FBO Incompatible size");
2464                 return false;
2465         }
2466
2467         _glesImpl2.glActiveTexture(GL_TEXTURE0);
2468
2469         _glesImpl2.glGenFramebuffers(1, &frameBufferObject);
2470         _glesImpl2.glGenRenderbuffers(1, &depthRenderBuffer);
2471         _glesImpl2.glGenRenderbuffers(1, &stencilRenderBuffer);
2472         _glesImpl2.glGenTextures(1, &textureId);
2473         if (frameBufferObject == 0 || depthRenderBuffer == 0 || stencilRenderBuffer == 0 || textureId == 0)
2474         {
2475                 SysLog(NID_GRP, "FBO generating failed! fbo:%d depth:%d stencil:%d tex:%d"
2476                                 , frameBufferObject, depthRenderBuffer, stencilRenderBuffer, textureId);
2477                 _GlesFboTerminate_2(frameBufferObject, depthRenderBuffer, stencilRenderBuffer, textureId, program);
2478         }
2479
2480         _glesImpl2.glBindTexture(GL_TEXTURE_2D, textureId);
2481         if (colorSize > 16)
2482         {
2483                 _glesImpl2.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fboWidth, fboHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
2484         }
2485         else
2486         {
2487                 _glesImpl2.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fboWidth, fboHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
2488         }
2489         _glesImpl2.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2490         _glesImpl2.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2491         _glesImpl2.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2492         _glesImpl2.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2493
2494         const char* pString = (const char*)_glesImpl2.glGetString(GL_EXTENSIONS);
2495         String extensions(pString);
2496
2497         if (depthSize > 0)
2498         {
2499                 GLenum internalFormat = GL_DEPTH_COMPONENT16;
2500
2501                 if (depthSize > 24)
2502                 {
2503                         if (extensions.Contains(L"GL_OES_depth32"))
2504                         {
2505                                 internalFormat = GL_DEPTH_COMPONENT32_OES;
2506                         }
2507                 }
2508                 else if (depthSize > 16)
2509                 {
2510                         if (extensions.Contains(L"GL_OES_depth24"))
2511                         {
2512                                 internalFormat = GL_DEPTH_COMPONENT24_OES;
2513                         }
2514                 }
2515
2516                 _glesImpl2.glBindRenderbuffer(GL_RENDERBUFFER, depthRenderBuffer);
2517                 _glesImpl2.glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, fboWidth, fboHeight);
2518         }
2519
2520         if (stencilSize > 0)
2521         {
2522                 GLenum internalFormat = GL_STENCIL_INDEX8;
2523
2524                 if (stencilSize == 1)
2525                 {
2526                         if (extensions.Contains(L"GL_OES_stencil1"))
2527                         {
2528                                 internalFormat = GL_STENCIL_INDEX1_OES;
2529                         }
2530                 }
2531                 else if (stencilSize <= 4)
2532                 {
2533                         if (extensions.Contains(L"GL_OES_stencil4"))
2534                         {
2535                                 internalFormat = GL_STENCIL_INDEX4_OES;
2536                         }
2537                 }
2538
2539                 _glesImpl2.glBindRenderbuffer(GL_RENDERBUFFER, stencilRenderBuffer);
2540                 _glesImpl2.glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, fboWidth, fboHeight);
2541         }
2542
2543         _glesImpl2.glBindFramebuffer(GL_FRAMEBUFFER, frameBufferObject);
2544         _glesImpl2.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0);
2545         if (depthSize != 0)
2546         {
2547                 _glesImpl2.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderBuffer);
2548         }
2549
2550         _glesImpl2.glBindTexture(GL_TEXTURE_2D, 0);
2551
2552         GLenum ret = _glesImpl2.glCheckFramebufferStatus(GL_FRAMEBUFFER);
2553         if (ret != GL_FRAMEBUFFER_COMPLETE)
2554         {
2555                 _GlesFboTerminate_2(frameBufferObject, depthRenderBuffer, stencilRenderBuffer, textureId, program);
2556                 SysLog(NID_GRP, "FBO glCheckFramebufferStatus failed! %#x", (unsigned int)ret);
2557                 return false;
2558         }
2559
2560         return true;
2561 }
2562
2563 _OSP_LOCAL_ void
2564 _GlesFboBinding_2(const GLuint frameBufferObject)
2565 {
2566         _GLES_CHECK_INTERFACE_VOID_2
2567         _glesImpl2.glBindFramebuffer(GL_FRAMEBUFFER, frameBufferObject);
2568 }
2569
2570 _OSP_LOCAL_ void
2571 _GlesFboSwapBuffers_2(const Frame* pFrame, const GLuint frameBufferObject
2572                 , const GLuint textureId, const GLuint program)
2573 {
2574         _GLES_CHECK_INTERFACE_VOID_2
2575         GLboolean isEnabledCullFace = GL_FALSE;
2576         GLboolean isEnabledStencil = GL_FALSE;
2577         GLboolean isEnabledDepth = GL_FALSE;
2578         GLboolean isEnabledScissor = GL_FALSE;
2579         GLboolean isEnabledBlend = GL_FALSE;
2580
2581         isEnabledCullFace = _glesImpl2.glIsEnabled(GL_CULL_FACE);
2582         isEnabledStencil = _glesImpl2.glIsEnabled(GL_STENCIL_TEST);
2583         isEnabledDepth = _glesImpl2.glIsEnabled(GL_DEPTH_TEST);
2584         isEnabledScissor = _glesImpl2.glIsEnabled(GL_SCISSOR_TEST);
2585         isEnabledBlend = _glesImpl2.glIsEnabled(GL_BLEND);
2586         _glesImpl2.glDisable(GL_CULL_FACE);
2587         _glesImpl2.glDisable(GL_STENCIL_TEST);
2588         _glesImpl2.glDisable(GL_DEPTH_TEST);
2589         _glesImpl2.glDisable(GL_SCISSOR_TEST);
2590         _glesImpl2.glDisable(GL_BLEND);
2591
2592         GLint previousTextureId = 0;
2593         GLint previousArrayBuffer = 0;
2594         GLint previousElementArrayBuffer = 0;
2595         GLint previousViewport[4] = {0,};
2596         GLint previousProgram = 0;
2597         _glesImpl2.glGetIntegerv(GL_TEXTURE_BINDING_2D, &previousTextureId);
2598         _glesImpl2.glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &previousArrayBuffer);
2599         _glesImpl2.glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &previousElementArrayBuffer);
2600         _glesImpl2.glGetIntegerv(GL_VIEWPORT, previousViewport);
2601         _glesImpl2.glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
2602
2603         _glesImpl2.glUseProgram(program);
2604         int indexTexture = 0;
2605         int indexAttribPosition = 0;
2606         int indexAttribTextureCoord = 0;
2607         indexTexture = _glesImpl2.glGetUniformLocation(program, "uTexture");
2608         indexAttribPosition = _glesImpl2.glGetAttribLocation(program, "aPosition");
2609         indexAttribTextureCoord = _glesImpl2.glGetAttribLocation(program, "aTextureCoord");
2610
2611         _glesImpl2.glBindFramebuffer(GL_FRAMEBUFFER, 0);
2612         _glesImpl2.glBindTexture( GL_TEXTURE_2D, textureId);
2613
2614         int x = 0;
2615         int y = 0;
2616         int width = 0;
2617         int height = 0;
2618         pFrame->GetBounds(x, y, width, height);
2619
2620         GLfloat ratioX1 = 0.0f;
2621         GLfloat ratioX2 = 1.0f;
2622         GLfloat ratioY1 = 0.0f;
2623         GLfloat ratioY2 = 1.0f;
2624
2625         GLfloat texture[] = {
2626                         ratioX1, ratioY1,
2627                         ratioX2, ratioY1,
2628                         ratioX1, ratioY2,
2629                         ratioX2, ratioY2,
2630         };
2631
2632         OrientationStatus orientationStatus = pFrame->GetOrientationStatus();
2633         switch(orientationStatus)
2634         {
2635                 default:
2636                 case ORIENTATION_STATUS_NONE:
2637                 case ORIENTATION_STATUS_PORTRAIT:
2638                         _glesImpl2.glViewport(0, 0, width, height);
2639                 break;
2640
2641                 case ORIENTATION_STATUS_LANDSCAPE:
2642                         texture[0] = ratioX2;
2643                         texture[1] = ratioY1;
2644                         texture[2] = ratioX2;
2645                         texture[3] = ratioY2;
2646                         texture[4] = ratioX1;
2647                         texture[5] = ratioY1;
2648                         texture[6] = ratioX1;
2649                         texture[7] = ratioY2;
2650                         _glesImpl2.glViewport(0, 0, height, width);
2651                 break;
2652
2653                 case ORIENTATION_STATUS_PORTRAIT_REVERSE:
2654                         texture[0] = ratioX2;
2655                         texture[1] = ratioY2;
2656                         texture[2] = ratioX1;
2657                         texture[3] = ratioY2;
2658                         texture[4] = ratioX2;
2659                         texture[5] = ratioY1;
2660                         texture[6] = ratioX1;
2661                         texture[7] = ratioY1;
2662                         _glesImpl2.glViewport(0, 0, width, height);
2663                 break;
2664
2665                 case ORIENTATION_STATUS_LANDSCAPE_REVERSE:
2666                         texture[0] = ratioX1;
2667                         texture[1] = ratioY2;
2668                         texture[2] = ratioX1;
2669                         texture[3] = ratioY1;
2670                         texture[4] = ratioX2;
2671                         texture[5] = ratioY2;
2672                         texture[6] = ratioX2;
2673                         texture[7] = ratioY1;
2674                         _glesImpl2.glViewport(0, 0, height, width);
2675                 break;
2676         }
2677
2678         _glesImpl2.glUniform1i(indexTexture, 0);
2679
2680         _glesImpl2.glEnableVertexAttribArray(indexAttribPosition);
2681         _glesImpl2.glEnableVertexAttribArray(indexAttribTextureCoord);
2682
2683         GLfloat vertex[] = {
2684                         -1.0f, -1.0f,
2685                          1.0f, -1.0f,
2686                         -1.0f,  1.0f,
2687                          1.0f,  1.0f,
2688         };
2689
2690         _glesImpl2.glBindBuffer(GL_ARRAY_BUFFER, 0);
2691         _glesImpl2.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
2692
2693         _glesImpl2.glVertexAttribPointer(indexAttribPosition, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), vertex);
2694         _glesImpl2.glVertexAttribPointer(indexAttribTextureCoord, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), texture);
2695
2696         _glesImpl2.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
2697
2698         _glesImpl2.glBindFramebuffer(GL_FRAMEBUFFER, frameBufferObject);
2699         _glesImpl2.glUseProgram((GLuint)previousProgram);
2700         if (isEnabledCullFace)
2701         {
2702                 _glesImpl2.glEnable(GL_CULL_FACE);
2703         }
2704         if (isEnabledStencil)
2705         {
2706                 _glesImpl2.glEnable(GL_STENCIL_TEST);
2707         }
2708         if (isEnabledDepth)
2709         {
2710                 _glesImpl2.glEnable(GL_DEPTH_TEST);
2711         }
2712         if (isEnabledScissor)
2713         {
2714                 _glesImpl2.glEnable(GL_SCISSOR_TEST);
2715         }
2716         if (isEnabledBlend)
2717         {
2718                 _glesImpl2.glEnable(GL_BLEND);
2719         }
2720
2721         _glesImpl2.glBindTexture( GL_TEXTURE_2D, previousTextureId);
2722         _glesImpl2.glBindBuffer(GL_ARRAY_BUFFER, previousArrayBuffer);
2723         _glesImpl2.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, previousElementArrayBuffer);
2724         _glesImpl2.glViewport(previousViewport[0], previousViewport[1], previousViewport[2], previousViewport[3]);
2725 }
2726
2727 #endif //#if defined(FGRAPHICS_INTERNAL_USE_FBO)
2728
2729 #ifdef __cplusplus
2730 }
2731 #endif
2732
2733 #endif //#if !defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
2734
2735 } // Opengl
2736
2737 }} // Tizen::Graphics