2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/graphics/gles/gl-extensions.h>
22 #include <dali/internal/graphics/common/egl-include.h>
25 #include <dali/integration-api/debug.h>
33 GlExtensions::GlExtensions()
35 #ifdef GL_EXT_discard_framebuffer
36 mGlDiscardFramebuffer(nullptr),
38 #ifdef GL_OES_get_program_binary
39 mGlGetProgramBinaryOES(nullptr),
40 mGlProgramBinaryOES(nullptr),
42 #ifdef GL_KHR_blend_equation_advanced
43 mBlendBarrierKHR(nullptr),
45 #ifdef GL_EXT_multisampled_render_to_texture
46 mGlRenderbufferStorageMultisampleEXT(nullptr),
47 mGlFramebufferTexture2DMultisampleEXT(nullptr),
53 GlExtensions::~GlExtensions()
57 void GlExtensions::DiscardFrameBuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
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))
66 #ifdef GL_EXT_discard_framebuffer
67 if(mGlDiscardFramebuffer)
69 mGlDiscardFramebuffer(target, numAttachments, attachments);
73 DALI_LOG_ERROR("Error: glDiscardFramebufferEXT extension is not available\n");
78 void GlExtensions::GetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
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))
87 #ifdef GL_OES_get_program_binary
88 if(mGlGetProgramBinaryOES)
90 mGlGetProgramBinaryOES(program, bufSize, length, binaryFormat, binary);
94 DALI_LOG_ERROR("Error: glGetProgramBinaryOES extension is not available\n");
100 void GlExtensions::ProgramBinaryOES(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLint length)
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))
109 #ifdef GL_OES_get_program_binary
110 if(mGlProgramBinaryOES)
112 mGlProgramBinaryOES(program, binaryFormat, binary, length);
116 DALI_LOG_ERROR("Error: glProgramBinaryOES extension is not available\n");
117 DALI_ASSERT_DEBUG(0);
122 bool GlExtensions::BlendBarrierKHR()
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))
131 #ifdef GL_KHR_blend_equation_advanced
143 void GlExtensions::RenderbufferStorageMultisampleEXT(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
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))
152 #ifdef GL_EXT_multisampled_render_to_texture
153 if(mGlRenderbufferStorageMultisampleEXT)
155 mGlRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, height);
159 DALI_LOG_ERROR("Error: glRenderbufferStorageMultisampleEXT extension is not available\n");
160 DALI_ASSERT_DEBUG(0);
165 void GlExtensions::FramebufferTexture2DMultisampleEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples)
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))
174 #ifdef GL_EXT_multisampled_render_to_texture
175 if(mGlFramebufferTexture2DMultisampleEXT)
177 mGlFramebufferTexture2DMultisampleEXT(target, attachment, textarget, texture, level, samples);
181 DALI_LOG_ERROR("Error: glFramebufferTexture2DMultisampleEXT extension is not available\n");
182 DALI_ASSERT_DEBUG(0);
187 void GlExtensions::Initialize()
191 #ifdef GL_EXT_discard_framebuffer
192 mGlDiscardFramebuffer = reinterpret_cast<PFNGLDISCARDFRAMEBUFFEREXTPROC>(eglGetProcAddress("glDiscardFramebufferEXT"));
195 #ifdef GL_OES_get_program_binary
196 mGlGetProgramBinaryOES = reinterpret_cast<PFNGLGETPROGRAMBINARYOESPROC>(eglGetProcAddress("glGetProgramBinaryOES"));
197 mGlProgramBinaryOES = reinterpret_cast<PFNGLPROGRAMBINARYOESPROC>(eglGetProcAddress("glProgramBinaryOES"));
200 #ifdef GL_KHR_blend_equation_advanced
201 mBlendBarrierKHR = reinterpret_cast<PFNGLBLENDBARRIERKHRPROC>(eglGetProcAddress("glBlendBarrierKHR"));
204 #ifdef GL_EXT_multisampled_render_to_texture
205 mGlRenderbufferStorageMultisampleEXT = reinterpret_cast<PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC>(eglGetProcAddress("glRenderbufferStorageMultisampleEXT"));
206 mGlFramebufferTexture2DMultisampleEXT = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC>(eglGetProcAddress("glFramebufferTexture2DMultisampleEXT"));
210 } // namespace Adaptor
212 } // namespace Internal