blob: e5fb083a81a06645b0e16de25af3606cd2a0e960 [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),
Mathias Agopian8171aec2013-03-28 17:52:36 -070031 mHaveDirectTexture(false),
32 mHaveFramebufferObject(false)
Mathias Agopian1f7bec62010-06-25 18:02:21 -070033{
34}
35
36void 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
Mathias Agopianca088332013-03-28 17:44:13 -070083#error "EGL_ANDROID_image_native_buffer not supported"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070084#endif
85
86 if (hasExtension("GL_ARB_texture_non_power_of_two")) {
87 mHaveNpot = true;
88 }
89
Michael I. Gold7f198b62010-09-15 15:46:24 -070090 if (hasExtension("GL_OES_EGL_image_external")) {
Mathias Agopian1f7bec62010-06-25 18:02:21 -070091 mHaveTextureExternal = true;
92 } else if (strstr(mRenderer.string(), "Adreno")) {
93 // hack for Adreno 200
94 mHaveTextureExternal = true;
95 }
Mathias Agopian1b0b30d2010-09-24 11:26:58 -070096
97 if (hasExtension("GL_OES_framebuffer_object")) {
98 mHaveFramebufferObject = true;
99 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700100}
101
102bool GLExtensions::hasExtension(char const* extension) const
103{
104 const String8 s(extension);
105 return mExtensionList.indexOf(s) >= 0;
106}
107
108char const* GLExtensions::getVendor() const {
109 return mVendor.string();
110}
111
112char const* GLExtensions::getRenderer() const {
113 return mRenderer.string();
114}
115
116char const* GLExtensions::getVersion() const {
117 return mVersion.string();
118}
119
120char const* GLExtensions::getExtension() const {
121 return mExtensions.string();
122}
123
124char const* GLExtensions::getEglVendor() const {
125 return mEglVendor.string();
126}
127
128char const* GLExtensions::getEglVersion() const {
129 return mEglVersion.string();
130}
131
132char const* GLExtensions::getEglExtension() const {
133 return mEglExtensions.string();
134}
135
136
137// ---------------------------------------------------------------------------
138}; // namespace android