Merge "Fix coverity issue : Adaptor available check in async task manager" into devel...
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / gl-extensions.cpp
1 /*
2  * Copyright (c) 2022 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 namespace Internal
30 {
31 namespace Adaptor
32 {
33 GlExtensions::GlExtensions()
34 :
35 #ifdef GL_EXT_discard_framebuffer
36   mGlDiscardFramebuffer(nullptr),
37 #endif
38 #ifdef GL_OES_get_program_binary
39   mGlGetProgramBinaryOES(nullptr),
40   mGlProgramBinaryOES(nullptr),
41 #endif
42 #ifdef GL_KHR_blend_equation_advanced
43   mBlendBarrierKHR(nullptr),
44 #endif
45 #ifdef GL_EXT_multisampled_render_to_texture
46   mGlRenderbufferStorageMultisampleEXT(nullptr),
47   mGlFramebufferTexture2DMultisampleEXT(nullptr),
48 #endif
49   mInitialized(false)
50 {
51 }
52
53 GlExtensions::~GlExtensions()
54 {
55 }
56
57 void GlExtensions::DiscardFrameBuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
58 {
59   // initialize extension on first use as on some hw platforms a context
60   // has to be bound for the extensions to return correct pointer
61   if(DALI_UNLIKELY(!mInitialized))
62   {
63     Initialize();
64   }
65
66 #ifdef GL_EXT_discard_framebuffer
67   if(mGlDiscardFramebuffer)
68   {
69     mGlDiscardFramebuffer(target, numAttachments, attachments);
70   }
71   else
72   {
73     DALI_LOG_ERROR("Error: glDiscardFramebufferEXT extension is not available\n");
74   }
75 #endif
76 }
77
78 void GlExtensions::GetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
79 {
80   // initialize extension on first use as on some hw platforms a context
81   // has to be bound for the extensions to return correct pointer
82   if(DALI_UNLIKELY(!mInitialized))
83   {
84     Initialize();
85   }
86
87 #ifdef GL_OES_get_program_binary
88   if(mGlGetProgramBinaryOES)
89   {
90     mGlGetProgramBinaryOES(program, bufSize, length, binaryFormat, binary);
91   }
92   else
93   {
94     DALI_LOG_ERROR("Error: glGetProgramBinaryOES extension is not available\n");
95     DALI_ASSERT_DEBUG(0);
96   }
97 #endif
98 }
99
100 void GlExtensions::ProgramBinaryOES(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLint length)
101 {
102   // initialize extension on first use as on some hw platforms a context
103   // has to be bound for the extensions to return correct pointer
104   if(DALI_UNLIKELY(!mInitialized))
105   {
106     Initialize();
107   }
108
109 #ifdef GL_OES_get_program_binary
110   if(mGlProgramBinaryOES)
111   {
112     mGlProgramBinaryOES(program, binaryFormat, binary, length);
113   }
114   else
115   {
116     DALI_LOG_ERROR("Error: glProgramBinaryOES extension is not available\n");
117     DALI_ASSERT_DEBUG(0);
118   }
119 #endif
120 }
121
122 bool GlExtensions::BlendBarrierKHR()
123 {
124   // initialize extension on first use as on some hw platforms a context
125   // has to be bound for the extensions to return correct pointer
126   if(DALI_UNLIKELY(!mInitialized))
127   {
128     Initialize();
129   }
130
131 #ifdef GL_KHR_blend_equation_advanced
132   if(mBlendBarrierKHR)
133   {
134     mBlendBarrierKHR();
135     return true;
136   }
137   return false;
138 #endif
139
140   return false;
141 }
142
143 void GlExtensions::RenderbufferStorageMultisampleEXT(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
144 {
145   // initialize extension on first use as on some hw platforms a context
146   // has to be bound for the extensions to return correct pointer
147   if(DALI_UNLIKELY(!mInitialized))
148   {
149     Initialize();
150   }
151
152 #ifdef GL_EXT_multisampled_render_to_texture
153   if(mGlRenderbufferStorageMultisampleEXT)
154   {
155     mGlRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, height);
156   }
157   else
158   {
159     DALI_LOG_ERROR("Error: glRenderbufferStorageMultisampleEXT extension is not available\n");
160     DALI_ASSERT_DEBUG(0);
161   }
162 #endif
163 }
164
165 void GlExtensions::FramebufferTexture2DMultisampleEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples)
166 {
167   // initialize extension on first use as on some hw platforms a context
168   // has to be bound for the extensions to return correct pointer
169   if(DALI_UNLIKELY(!mInitialized))
170   {
171     Initialize();
172   }
173
174 #ifdef GL_EXT_multisampled_render_to_texture
175   if(mGlFramebufferTexture2DMultisampleEXT)
176   {
177     mGlFramebufferTexture2DMultisampleEXT(target, attachment, textarget, texture, level, samples);
178   }
179   else
180   {
181     DALI_LOG_ERROR("Error: glFramebufferTexture2DMultisampleEXT extension is not available\n");
182     DALI_ASSERT_DEBUG(0);
183   }
184 #endif
185 }
186
187 void GlExtensions::Initialize()
188 {
189   mInitialized = true;
190
191 #ifdef GL_EXT_discard_framebuffer
192   mGlDiscardFramebuffer = reinterpret_cast<PFNGLDISCARDFRAMEBUFFEREXTPROC>(eglGetProcAddress("glDiscardFramebufferEXT"));
193 #endif
194
195 #ifdef GL_OES_get_program_binary
196   mGlGetProgramBinaryOES = reinterpret_cast<PFNGLGETPROGRAMBINARYOESPROC>(eglGetProcAddress("glGetProgramBinaryOES"));
197   mGlProgramBinaryOES    = reinterpret_cast<PFNGLPROGRAMBINARYOESPROC>(eglGetProcAddress("glProgramBinaryOES"));
198 #endif
199
200 #ifdef GL_KHR_blend_equation_advanced
201   mBlendBarrierKHR = reinterpret_cast<PFNGLBLENDBARRIERKHRPROC>(eglGetProcAddress("glBlendBarrierKHR"));
202 #endif
203
204 #ifdef GL_EXT_multisampled_render_to_texture
205   mGlRenderbufferStorageMultisampleEXT  = reinterpret_cast<PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC>(eglGetProcAddress("glRenderbufferStorageMultisampleEXT"));
206   mGlFramebufferTexture2DMultisampleEXT = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC>(eglGetProcAddress("glFramebufferTexture2DMultisampleEXT"));
207 #endif
208 }
209
210 } // namespace Adaptor
211
212 } // namespace Internal
213
214 } // namespace Dali