blob: 493122d878f7ac27517a338db14c0b375872c738 [file] [log] [blame]
Mathias Agopian1f7bec62010-06-25 18:02:21 -07001/*
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
23namespace android {
24// ---------------------------------------------------------------------------
25
26ANDROID_SINGLETON_STATIC_INSTANCE( GLExtensions )
27
28GLExtensions::GLExtensions()
29 : mHaveTextureExternal(false),
30 mHaveNpot(false),
31 mHaveDirectTexture(false)
32{
33}
34
35void 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. Gold7f198b62010-09-15 15:46:24 -070089 if (hasExtension("GL_OES_EGL_image_external")) {
Mathias Agopian1f7bec62010-06-25 18:02:21 -070090 mHaveTextureExternal = true;
91 } else if (strstr(mRenderer.string(), "Adreno")) {
92 // hack for Adreno 200
93 mHaveTextureExternal = true;
94 }
Mathias Agopian1b0b30d2010-09-24 11:26:58 -070095
96 if (hasExtension("GL_OES_framebuffer_object")) {
97 mHaveFramebufferObject = true;
98 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -070099}
100
101bool GLExtensions::hasExtension(char const* extension) const
102{
103 const String8 s(extension);
104 return mExtensionList.indexOf(s) >= 0;
105}
106
107char const* GLExtensions::getVendor() const {
108 return mVendor.string();
109}
110
111char const* GLExtensions::getRenderer() const {
112 return mRenderer.string();
113}
114
115char const* GLExtensions::getVersion() const {
116 return mVersion.string();
117}
118
119char const* GLExtensions::getExtension() const {
120 return mExtensions.string();
121}
122
123char const* GLExtensions::getEglVendor() const {
124 return mEglVendor.string();
125}
126
127char const* GLExtensions::getEglVersion() const {
128 return mEglVersion.string();
129}
130
131char const* GLExtensions::getEglExtension() const {
132 return mEglExtensions.string();
133}
134
135
136// ---------------------------------------------------------------------------
137}; // namespace android