Merge "Add last clear color API in test gl abstraction." 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 namespace ECoreX
37 {
38
39 GlExtensions::GlExtensions()
40 :
41 #ifdef GL_EXT_discard_framebuffer
42   mGlDiscardFramebuffer( NULL ),
43 #endif
44 #ifdef GL_OES_get_program_binary
45   mGlGetProgramBinaryOES( NULL ),
46   mGlProgramBinaryOES( NULL ),
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 void GlExtensions::Initialize()
122 {
123   mInitialized = true;
124
125 #ifdef GL_EXT_discard_framebuffer
126   mGlDiscardFramebuffer = reinterpret_cast< PFNGLDISCARDFRAMEBUFFEREXTPROC >( eglGetProcAddress("glDiscardFramebufferEXT") );
127 #endif
128
129 #ifdef GL_OES_get_program_binary
130   mGlGetProgramBinaryOES = reinterpret_cast< PFNGLGETPROGRAMBINARYOESPROC >( eglGetProcAddress("glGetProgramBinaryOES") );
131   mGlProgramBinaryOES = reinterpret_cast< PFNGLPROGRAMBINARYOESPROC >( eglGetProcAddress("glProgramBinaryOES") );
132 #endif
133 }
134
135 } // namespace ECoreX
136
137 } // namespace Adaptor
138
139 } // namespace Internal
140
141 } // namespace Dali