| Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -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 |  | 
|  | 17 | #include <stdlib.h> | 
|  | 18 | #include <stdio.h> | 
|  | 19 | #include <stdint.h> | 
|  | 20 |  | 
|  | 21 | #include "GLExtensions.h" | 
|  | 22 |  | 
|  | 23 | namespace android { | 
|  | 24 | // --------------------------------------------------------------------------- | 
|  | 25 |  | 
|  | 26 | ANDROID_SINGLETON_STATIC_INSTANCE( GLExtensions ) | 
|  | 27 |  | 
|  | 28 | GLExtensions::GLExtensions() | 
|  | 29 | : mHaveTextureExternal(false), | 
|  | 30 | mHaveNpot(false), | 
|  | 31 | mHaveDirectTexture(false) | 
|  | 32 | { | 
|  | 33 | } | 
|  | 34 |  | 
|  | 35 | void GLExtensions::initWithGLStrings( | 
|  | 36 | GLubyte const* vendor, | 
|  | 37 | GLubyte const* renderer, | 
|  | 38 | GLubyte const* version, | 
|  | 39 | GLubyte const* extensions, | 
|  | 40 | char const* egl_vendor, | 
|  | 41 | char const* egl_version, | 
|  | 42 | char const* egl_extensions) | 
|  | 43 | { | 
|  | 44 | mVendor     = (char const*)vendor; | 
|  | 45 | mRenderer   = (char const*)renderer; | 
|  | 46 | mVersion    = (char const*)version; | 
|  | 47 | mExtensions = (char const*)extensions; | 
|  | 48 | mEglVendor     = egl_vendor; | 
|  | 49 | mEglVersion    = egl_version; | 
|  | 50 | mEglExtensions = egl_extensions; | 
|  | 51 |  | 
|  | 52 | char const* curr = (char const*)extensions; | 
|  | 53 | char const* head = curr; | 
|  | 54 | do { | 
|  | 55 | head = strchr(curr, ' '); | 
|  | 56 | String8 s(curr, head ? head-curr : strlen(curr)); | 
|  | 57 | if (s.length()) { | 
|  | 58 | mExtensionList.add(s); | 
|  | 59 | } | 
|  | 60 | curr = head+1; | 
|  | 61 | } while (head); | 
|  | 62 |  | 
|  | 63 | curr = egl_extensions; | 
|  | 64 | head = curr; | 
|  | 65 | do { | 
|  | 66 | head = strchr(curr, ' '); | 
|  | 67 | String8 s(curr, head ? head-curr : strlen(curr)); | 
|  | 68 | if (s.length()) { | 
|  | 69 | mExtensionList.add(s); | 
|  | 70 | } | 
|  | 71 | curr = head+1; | 
|  | 72 | } while (head); | 
|  | 73 |  | 
|  | 74 | #ifdef EGL_ANDROID_image_native_buffer | 
|  | 75 | if (hasExtension("GL_OES_EGL_image") && | 
|  | 76 | (hasExtension("EGL_KHR_image_base") || hasExtension("EGL_KHR_image")) && | 
|  | 77 | hasExtension("EGL_ANDROID_image_native_buffer")) | 
|  | 78 | { | 
|  | 79 | mHaveDirectTexture = true; | 
|  | 80 | } | 
|  | 81 | #else | 
|  | 82 | #warning "EGL_ANDROID_image_native_buffer not supported" | 
|  | 83 | #endif | 
|  | 84 |  | 
|  | 85 | if (hasExtension("GL_ARB_texture_non_power_of_two")) { | 
|  | 86 | mHaveNpot = true; | 
|  | 87 | } | 
|  | 88 |  | 
| Michael I. Gold | 7f198b6 | 2010-09-15 15:46:24 -0700 | [diff] [blame] | 89 | if (hasExtension("GL_OES_EGL_image_external")) { | 
| Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 90 | mHaveTextureExternal = true; | 
|  | 91 | } else if (strstr(mRenderer.string(), "Adreno")) { | 
|  | 92 | // hack for Adreno 200 | 
|  | 93 | mHaveTextureExternal = true; | 
|  | 94 | } | 
| Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 95 |  | 
|  | 96 | if (hasExtension("GL_OES_framebuffer_object")) { | 
|  | 97 | mHaveFramebufferObject = true; | 
|  | 98 | } | 
| Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
|  | 101 | bool GLExtensions::hasExtension(char const* extension) const | 
|  | 102 | { | 
|  | 103 | const String8 s(extension); | 
|  | 104 | return mExtensionList.indexOf(s) >= 0; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | char const* GLExtensions::getVendor() const { | 
|  | 108 | return mVendor.string(); | 
|  | 109 | } | 
|  | 110 |  | 
|  | 111 | char const* GLExtensions::getRenderer() const { | 
|  | 112 | return mRenderer.string(); | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | char const* GLExtensions::getVersion() const { | 
|  | 116 | return mVersion.string(); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | char const* GLExtensions::getExtension() const { | 
|  | 120 | return mExtensions.string(); | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | char const* GLExtensions::getEglVendor() const { | 
|  | 124 | return mEglVendor.string(); | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | char const* GLExtensions::getEglVersion() const { | 
|  | 128 | return mEglVersion.string(); | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | char const* GLExtensions::getEglExtension() const { | 
|  | 132 | return mEglExtensions.string(); | 
|  | 133 | } | 
|  | 134 |  | 
|  | 135 |  | 
|  | 136 | // --------------------------------------------------------------------------- | 
|  | 137 | }; // namespace android |