Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 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 | |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_UI_EXTENSIONS_H |
| 18 | #define ANDROID_UI_EXTENSIONS_H |
| 19 | |
| 20 | #include <utils/SortedVector.h> |
| 21 | #include <utils/String8.h> |
| 22 | |
| 23 | #include <GLES2/gl2.h> |
| 24 | #include <GLES2/gl2ext.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame^] | 29 | /////////////////////////////////////////////////////////////////////////////// |
| 30 | // Defines |
| 31 | /////////////////////////////////////////////////////////////////////////////// |
| 32 | |
| 33 | // Debug |
| 34 | #define DEBUG_EXTENSIONS 0 |
| 35 | |
| 36 | // Debug |
| 37 | #if DEBUG_EXTENSIONS |
| 38 | #define EXT_LOGD(...) LOGD(__VA_ARGS__) |
| 39 | #else |
| 40 | #define EXT_LOGD(...) |
| 41 | #endif |
| 42 | |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 43 | class Extensions { |
| 44 | public: |
| 45 | Extensions() { |
| 46 | const char* buffer = (const char*) glGetString(GL_EXTENSIONS); |
| 47 | const char* current = buffer; |
| 48 | const char* head = current; |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame^] | 49 | EXT_LOGD("Available GL extensions:"); |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 50 | do { |
| 51 | head = strchr(current, ' '); |
| 52 | String8 s(current, head ? head - current : strlen(current)); |
| 53 | if (s.length()) { |
| 54 | mExtensionList.add(s); |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame^] | 55 | EXT_LOGD(" %s", s.string()); |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 56 | } |
| 57 | current = head + 1; |
| 58 | } while (head); |
| 59 | |
| 60 | mHasNPot = hasExtension("GL_OES_texture_npot"); |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 61 | mHasDrawPath = hasExtension("GL_NV_draw_path"); |
| 62 | mHasCoverageSample = hasExtension("GL_NV_coverage_sample"); |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame^] | 63 | mHasFramebufferFetch = hasExtension("GL_NV_shader_framebuffer_fetch"); |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 64 | |
| 65 | mExtensions = buffer; |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | inline bool hasNPot() const { return mHasNPot; } |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 69 | inline bool hasDrawPath() const { return mHasDrawPath; } |
| 70 | inline bool hasCoverageSample() const { return mHasCoverageSample; } |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame^] | 71 | inline bool hasFramebufferFetch() const { return mHasFramebufferFetch; } |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 72 | |
| 73 | bool hasExtension(const char* extension) const { |
| 74 | const String8 s(extension); |
| 75 | return mExtensionList.indexOf(s) >= 0; |
| 76 | } |
| 77 | |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 78 | void dump() { |
| 79 | LOGD("Supported extensions:\n%s", mExtensions); |
| 80 | } |
| 81 | |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 82 | private: |
| 83 | SortedVector<String8> mExtensionList; |
| 84 | |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 85 | const char* mExtensions; |
| 86 | |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 87 | bool mHasNPot; |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 88 | bool mHasDrawPath; |
| 89 | bool mHasCoverageSample; |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame^] | 90 | bool mHasFramebufferFetch; |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 91 | }; // class Extensions |
| 92 | |
| 93 | }; // namespace uirenderer |
| 94 | }; // namespace android |
| 95 | |
| 96 | #endif // ANDROID_UI_EXTENSIONS_H |