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