Merge "Use existing callback ID for recurring callbacks" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / gl-extensions.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/graphics/gles/gl-extensions.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/internal/graphics/common/egl-include.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/integration-api/debug.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35
36 GlExtensions::GlExtensions()
37 :
38 #ifdef GL_EXT_discard_framebuffer
39   mGlDiscardFramebuffer( NULL ),
40 #endif
41 #ifdef GL_OES_get_program_binary
42   mGlGetProgramBinaryOES( NULL ),
43   mGlProgramBinaryOES( NULL ),
44 #endif
45   mInitialized( false )
46 {
47 }
48
49 GlExtensions::~GlExtensions()
50 {
51 }
52
53 void GlExtensions::DiscardFrameBuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
54 {
55   // initialize extension on first use as on some hw platforms a context
56   // has to be bound for the extensions to return correct pointer
57   if( !mInitialized )
58   {
59     Initialize();
60   }
61
62 #ifdef GL_EXT_discard_framebuffer
63   if( mGlDiscardFramebuffer )
64   {
65     mGlDiscardFramebuffer(target, numAttachments, attachments);
66   }
67   else
68   {
69     DALI_LOG_ERROR("Error: glDiscardFramebufferEXT extension is not available\n");
70   }
71 #endif
72 }
73
74 void GlExtensions::GetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary)
75 {
76   // initialize extension on first use as on some hw platforms a context
77   // has to be bound for the extensions to return correct pointer
78   if( !mInitialized )
79   {
80     Initialize();
81   }
82
83 #ifdef GL_OES_get_program_binary
84   if (mGlGetProgramBinaryOES)
85   {
86     mGlGetProgramBinaryOES(program, bufSize, length, binaryFormat, binary);
87   }
88   else
89   {
90     DALI_LOG_ERROR("Error: glGetProgramBinaryOES extension is not available\n");
91     DALI_ASSERT_DEBUG(0);
92   }
93 #endif
94 }
95
96 void GlExtensions::ProgramBinaryOES(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length)
97 {
98   // initialize extension on first use as on some hw platforms a context
99   // has to be bound for the extensions to return correct pointer
100   if( !mInitialized )
101   {
102     Initialize();
103   }
104
105 #ifdef GL_OES_get_program_binary
106   if (mGlProgramBinaryOES)
107   {
108     mGlProgramBinaryOES(program, binaryFormat, binary, length);
109   }
110   else
111   {
112     DALI_LOG_ERROR("Error: glProgramBinaryOES extension is not available\n");
113     DALI_ASSERT_DEBUG(0);
114   }
115 #endif
116 }
117
118 bool GlExtensions::BlendBarrierKHR()
119 {
120   // initialize extension on first use as on some hw platforms a context
121   // has to be bound for the extensions to return correct pointer
122   if( !mInitialized )
123   {
124     Initialize();
125   }
126
127 #ifdef GL_KHR_blend_equation_advanced
128   if (mBlendBarrierKHR)
129   {
130     mBlendBarrierKHR();
131     return true;
132   }
133   return false;
134 #endif
135
136   return false;
137 }
138
139 void GlExtensions::Initialize()
140 {
141   mInitialized = true;
142
143 #ifdef GL_EXT_discard_framebuffer
144   mGlDiscardFramebuffer = reinterpret_cast< PFNGLDISCARDFRAMEBUFFEREXTPROC >( eglGetProcAddress("glDiscardFramebufferEXT") );
145 #endif
146
147 #ifdef GL_OES_get_program_binary
148   mGlGetProgramBinaryOES = reinterpret_cast< PFNGLGETPROGRAMBINARYOESPROC >( eglGetProcAddress("glGetProgramBinaryOES") );
149   mGlProgramBinaryOES = reinterpret_cast< PFNGLPROGRAMBINARYOESPROC >( eglGetProcAddress("glProgramBinaryOES") );
150 #endif
151
152 #ifdef GL_KHR_blend_equation_advanced
153   mBlendBarrierKHR = reinterpret_cast< PFNGLBLENDBARRIERKHRPROC >( eglGetProcAddress("glBlendBarrierKHR") );
154 #endif
155 }
156
157 } // namespace Adaptor
158
159 } // namespace Internal
160
161 } // namespace Dali