Merge "Track ActiveTexture calls" into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / common / gl / gl-extensions.cpp
1 /*
2  * Copyright (c) 2014 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 "gl-extensions.h"
20
21 // EXTERNAL INCLUDES
22 #include <EGL/egl.h>
23 #include <EGL/eglext.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/integration-api/debug.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace Adaptor
35 {
36
37 namespace ECoreX
38 {
39
40 GlExtensions::GlExtensions()
41   : mInitialized( false )
42 {
43 }
44
45 GlExtensions::~GlExtensions()
46 {
47 }
48
49 #if DALI_GLES_VERSION < 30
50
51 void GlExtensions::DiscardFrameBuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
52 {
53   // initialize extension on first use as on some hw platforms a context
54   // has to be bound for the extensions to return correct pointer
55   if( !mInitialized )
56   {
57     Initialize();
58   }
59
60 #ifdef GL_EXT_discard_framebuffer
61   if( mGlDiscardFramebuffer )
62   {
63     mGlDiscardFramebuffer(target, numAttachments, attachments);
64   }
65   else
66   {
67     DALI_LOG_ERROR("Error: glDiscardFramebufferEXT extension is not available\n");
68   }
69 #endif
70 }
71
72 void GlExtensions::GetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary)
73 {
74   // initialize extension on first use as on some hw platforms a context
75   // has to be bound for the extensions to return correct pointer
76   if( !mInitialized )
77   {
78     Initialize();
79   }
80
81 #ifdef GL_OES_get_program_binary
82   if (mGlGetProgramBinaryOES)
83   {
84     mGlGetProgramBinaryOES(program, bufSize, length, binaryFormat, binary);
85   }
86   else
87   {
88     DALI_LOG_ERROR("Error: glGetProgramBinaryOES extension is not available\n");
89     DALI_ASSERT_DEBUG(0);
90   }
91 #endif
92 }
93
94 void GlExtensions::ProgramBinaryOES(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length)
95 {
96   // initialize extension on first use as on some hw platforms a context
97   // has to be bound for the extensions to return correct pointer
98   if( !mInitialized )
99   {
100     Initialize();
101   }
102
103 #ifdef GL_OES_get_program_binary
104   if (mGlProgramBinaryOES)
105   {
106     mGlProgramBinaryOES(program, binaryFormat, binary, length);
107   }
108   else
109   {
110     DALI_LOG_ERROR("Error: glProgramBinaryOES extension is not available\n");
111     DALI_ASSERT_DEBUG(0);
112   }
113 #endif
114 }
115
116 void GlExtensions::Initialize()
117 {
118   mInitialized = true;
119
120 #ifdef GL_EXT_discard_framebuffer
121   mGlDiscardFramebuffer = (PFNGLDISCARDFRAMEBUFFEREXTPROC) eglGetProcAddress("glDiscardFramebufferEXT");
122 #endif
123
124 #ifdef GL_OES_get_program_binary
125   mGlGetProgramBinaryOES = (PFNGLGETPROGRAMBINARYOESPROC) eglGetProcAddress("glGetProgramBinaryOES");
126   mGlProgramBinaryOES = (PFNGLPROGRAMBINARYOESPROC) eglGetProcAddress("glProgramBinaryOES");
127 #endif
128 }
129
130 #endif // DALI_GLES_VERSION < 30
131
132 } // namespace ECoreX
133
134 } // namespace Adaptor
135
136 } // namespace Internal
137
138 } // namespace Dali