11f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian/* 21f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * Copyright (C) 2010 The Android Open Source Project 31f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * 41f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 51f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * you may not use this file except in compliance with the License. 61f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * You may obtain a copy of the License at 71f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * 81f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 91f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * 101f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * Unless required by applicable law or agreed to in writing, software 111f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 121f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * See the License for the specific language governing permissions and 141f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * limitations under the License. 151f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian */ 161f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 171f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian#include <stdlib.h> 181f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian#include <stdio.h> 191f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian#include <stdint.h> 201f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 211f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian#include "GLExtensions.h" 221f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 231f7bec634f19c123410a5155c8d282e177c01930Mathias Agopiannamespace android { 241f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian// --------------------------------------------------------------------------- 251f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 261f7bec634f19c123410a5155c8d282e177c01930Mathias AgopianANDROID_SINGLETON_STATIC_INSTANCE( GLExtensions ) 271f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 281f7bec634f19c123410a5155c8d282e177c01930Mathias AgopianGLExtensions::GLExtensions() 291f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian : mHaveTextureExternal(false), 301f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mHaveNpot(false), 311f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mHaveDirectTexture(false) 321f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian{ 331f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 341f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 351f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianvoid GLExtensions::initWithGLStrings( 361f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian GLubyte const* vendor, 371f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian GLubyte const* renderer, 381f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian GLubyte const* version, 391f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian GLubyte const* extensions, 401f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian char const* egl_vendor, 411f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian char const* egl_version, 421f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian char const* egl_extensions) 431f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian{ 441f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mVendor = (char const*)vendor; 451f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mRenderer = (char const*)renderer; 461f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mVersion = (char const*)version; 471f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mExtensions = (char const*)extensions; 481f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mEglVendor = egl_vendor; 491f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mEglVersion = egl_version; 501f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mEglExtensions = egl_extensions; 511f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 521f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian char const* curr = (char const*)extensions; 531f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian char const* head = curr; 541f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian do { 551f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian head = strchr(curr, ' '); 561f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian String8 s(curr, head ? head-curr : strlen(curr)); 571f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian if (s.length()) { 581f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mExtensionList.add(s); 591f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian } 601f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian curr = head+1; 611f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian } while (head); 621f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 631f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian curr = egl_extensions; 641f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian head = curr; 651f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian do { 661f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian head = strchr(curr, ' '); 671f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian String8 s(curr, head ? head-curr : strlen(curr)); 681f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian if (s.length()) { 691f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mExtensionList.add(s); 701f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian } 711f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian curr = head+1; 721f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian } while (head); 731f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 741f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian#ifdef EGL_ANDROID_image_native_buffer 751f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian if (hasExtension("GL_OES_EGL_image") && 761f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian (hasExtension("EGL_KHR_image_base") || hasExtension("EGL_KHR_image")) && 771f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian hasExtension("EGL_ANDROID_image_native_buffer")) 781f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian { 791f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mHaveDirectTexture = true; 801f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian } 811f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian#else 821f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian#warning "EGL_ANDROID_image_native_buffer not supported" 831f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian#endif 841f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 851f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian if (hasExtension("GL_ARB_texture_non_power_of_two")) { 861f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mHaveNpot = true; 871f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian } 881f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 897f198b6bff54af3c8e8ac32b83ffc6488e773ac1Michael I. Gold if (hasExtension("GL_OES_EGL_image_external")) { 901f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mHaveTextureExternal = true; 911f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian } else if (strstr(mRenderer.string(), "Adreno")) { 921f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian // hack for Adreno 200 931f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian mHaveTextureExternal = true; 941f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian } 951b0b30d04304392748a8a4ab5a69e52a19f51b3aMathias Agopian 961b0b30d04304392748a8a4ab5a69e52a19f51b3aMathias Agopian if (hasExtension("GL_OES_framebuffer_object")) { 971b0b30d04304392748a8a4ab5a69e52a19f51b3aMathias Agopian mHaveFramebufferObject = true; 981b0b30d04304392748a8a4ab5a69e52a19f51b3aMathias Agopian } 991f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1001f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1011f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianbool GLExtensions::hasExtension(char const* extension) const 1021f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian{ 1031f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian const String8 s(extension); 1041f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian return mExtensionList.indexOf(s) >= 0; 1051f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1061f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1071f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianchar const* GLExtensions::getVendor() const { 1081f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian return mVendor.string(); 1091f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1101f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1111f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianchar const* GLExtensions::getRenderer() const { 1121f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian return mRenderer.string(); 1131f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1141f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1151f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianchar const* GLExtensions::getVersion() const { 1161f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian return mVersion.string(); 1171f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1181f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1191f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianchar const* GLExtensions::getExtension() const { 1201f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian return mExtensions.string(); 1211f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1221f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1231f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianchar const* GLExtensions::getEglVendor() const { 1241f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian return mEglVendor.string(); 1251f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1261f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1271f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianchar const* GLExtensions::getEglVersion() const { 1281f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian return mEglVersion.string(); 1291f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1301f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1311f7bec634f19c123410a5155c8d282e177c01930Mathias Agopianchar const* GLExtensions::getEglExtension() const { 1321f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian return mEglExtensions.string(); 1331f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian} 1341f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1351f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 1361f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian// --------------------------------------------------------------------------- 1371f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian}; // namespace android 138