[Tizen] Support MultiSampling FrameBuffer
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / gl-extensions-support.cpp
1 /*
2  * Copyright (c) 2022 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-support.h>
20
21 // EXTERNAL HEADER
22 #include <GLES2/gl2.h>
23 #include <GLES2/gl2ext.h>
24 #include <GLES3/gl3.h>
25
26 #include <algorithm> // for std::find_if
27 #include <sstream>
28 #include <string>
29 #include <string_view>
30 #include <utility> // for std::pair
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace Adaptor
37 {
38 namespace
39 {
40 static constexpr const char* KHR_BLEND_EQUATION_ADVANCED        = "GL_KHR_blend_equation_advanced";
41 static constexpr const char* EXT_MULTISAMPLED_RENDER_TO_TEXTURE = "GL_EXT_multisampled_render_to_texture";
42
43 } // namespace
44
45 namespace GlExtensionCache
46 {
47 void GlExtensionSupportedCacheList::EnsureGlExtensionSupportedCheck()
48 {
49   // Note that this function calls at most one time.
50   // But the number of GL_EXTENSIONS itmes are so vairous.
51   // We need to reduce extension checkup
52
53   const char* const  extensionStr = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
54   std::istringstream stream(extensionStr);
55   std::string        currentExtension;
56
57   // Create expected string-to-checkertype convertor.
58   using StringTypePair = std::pair<std::string_view, GlExtensionCheckerType>;
59   // clang-format off
60   std::vector<StringTypePair> extensionStringToTypeList
61   {
62     {KHR_BLEND_EQUATION_ADVANCED,        GlExtensionCheckerType::BLEND_EQUATION_ADVANCED       },
63
64 #ifndef DALI_PROFILE_UBUNTU
65     // @todo : Current ubuntu profile's multisamples FBO make crash when eglDestroyContext.
66     // Invalidate multisampled render to texture feature hardly.
67     {EXT_MULTISAMPLED_RENDER_TO_TEXTURE, GlExtensionCheckerType::MULTISAMPLED_RENDER_TO_TEXTURE},
68 #endif //DALI_PROFILE_UBUNTU
69
70     ///< Append additional extension checker type here.
71   };
72   // clang-format on
73
74   while(!extensionStringToTypeList.empty() && std::getline(stream, currentExtension, ' '))
75   {
76     auto findResult = std::find_if(extensionStringToTypeList.begin(),
77                                    extensionStringToTypeList.end(),
78                                    [&currentExtension](const StringTypePair& value) {
79                                      return value.first == currentExtension;
80                                    });
81     if(findResult != extensionStringToTypeList.end())
82     {
83       auto type = findResult->second;
84
85       // Mark as True.
86       SetSupported(type, true);
87
88       // Remove from list. we don't need to check this extension.
89       extensionStringToTypeList.erase(findResult);
90     }
91   }
92
93   // Set supported as false if extension keyword not exist.
94   SetAllUncachedAsNotSupported();
95 }
96 } // namespace GlExtensionCache
97 } // namespace Adaptor
98 } // namespace Internal
99 } // namespace Dali