(SVACE Issues Fix) Initialise uninitialised member variables
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / gl-extensions.cpp
1 /*
2  * Copyright (c) 2020 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( nullptr ),
40 #endif
41 #ifdef GL_OES_get_program_binary
42   mGlGetProgramBinaryOES( nullptr ),
43   mGlProgramBinaryOES( nullptr ),
44 #endif
45 #ifdef GL_KHR_blend_equation_advanced
46   mBlendBarrierKHR( nullptr ),
47 #endif
48   mInitialized( false )
49 {
50 }
51
52 GlExtensions::~GlExtensions()
53 {
54 }
55
56 void GlExtensions::DiscardFrameBuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
57 {
58   // initialize extension on first use as on some hw platforms a context
59   // has to be bound for the extensions to return correct pointer
60   if( !mInitialized )
61   {
62     Initialize();
63   }
64
65 #ifdef GL_EXT_discard_framebuffer
66   if( mGlDiscardFramebuffer )
67   {
68     mGlDiscardFramebuffer(target, numAttachments, attachments);
69   }
70   else
71   {
72     DALI_LOG_ERROR("Error: glDiscardFramebufferEXT extension is not available\n");
73   }
74 #endif
75 }
76
77 void GlExtensions::GetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary)
78 {
79   // initialize extension on first use as on some hw platforms a context
80   // has to be bound for the extensions to return correct pointer
81   if( !mInitialized )
82   {
83     Initialize();
84   }
85
86 #ifdef GL_OES_get_program_binary
87   if (mGlGetProgramBinaryOES)
88   {
89     mGlGetProgramBinaryOES(program, bufSize, length, binaryFormat, binary);
90   }
91   else
92   {
93     DALI_LOG_ERROR("Error: glGetProgramBinaryOES extension is not available\n");
94     DALI_ASSERT_DEBUG(0);
95   }
96 #endif
97 }
98
99 void GlExtensions::ProgramBinaryOES(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length)
100 {
101   // initialize extension on first use as on some hw platforms a context
102   // has to be bound for the extensions to return correct pointer
103   if( !mInitialized )
104   {
105     Initialize();
106   }
107
108 #ifdef GL_OES_get_program_binary
109   if (mGlProgramBinaryOES)
110   {
111     mGlProgramBinaryOES(program, binaryFormat, binary, length);
112   }
113   else
114   {
115     DALI_LOG_ERROR("Error: glProgramBinaryOES extension is not available\n");
116     DALI_ASSERT_DEBUG(0);
117   }
118 #endif
119 }
120
121 bool GlExtensions::BlendBarrierKHR()
122 {
123   // initialize extension on first use as on some hw platforms a context
124   // has to be bound for the extensions to return correct pointer
125   if( !mInitialized )
126   {
127     Initialize();
128   }
129
130 #ifdef GL_KHR_blend_equation_advanced
131   if (mBlendBarrierKHR)
132   {
133     mBlendBarrierKHR();
134     return true;
135   }
136   return false;
137 #endif
138
139   return false;
140 }
141
142 void GlExtensions::Initialize()
143 {
144   mInitialized = true;
145
146 #ifdef GL_EXT_discard_framebuffer
147   mGlDiscardFramebuffer = reinterpret_cast< PFNGLDISCARDFRAMEBUFFEREXTPROC >( eglGetProcAddress("glDiscardFramebufferEXT") );
148 #endif
149
150 #ifdef GL_OES_get_program_binary
151   mGlGetProgramBinaryOES = reinterpret_cast< PFNGLGETPROGRAMBINARYOESPROC >( eglGetProcAddress("glGetProgramBinaryOES") );
152   mGlProgramBinaryOES = reinterpret_cast< PFNGLPROGRAMBINARYOESPROC >( eglGetProcAddress("glProgramBinaryOES") );
153 #endif
154
155 #ifdef GL_KHR_blend_equation_advanced
156   mBlendBarrierKHR = reinterpret_cast< PFNGLBLENDBARRIERKHRPROC >( eglGetProcAddress("glBlendBarrierKHR") );
157 #endif
158 }
159
160 } // namespace Adaptor
161
162 } // namespace Internal
163
164 } // namespace Dali