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