2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "OpenGLESDispatch/GLESv2Dispatch.h"
17 #include "OpenGLESDispatch/EGLDispatch.h"
22 #include "emugl/common/shared_library.h"
24 extern EGLDispatch s_egl;
26 static emugl::SharedLibrary *s_gles2_lib = NULL;
29 constexpr const char *glesv2_lib_env_var{"ANDROID_GLESv2_LIB"};
32 // An unimplemented function which prints out an error message.
33 // To make it consistent with the guest, all GLES2 functions not supported by
34 // the driver should be redirected to this function.
36 static void gles2_unimplemented() {
37 fprintf(stderr, "Called unimplemented GLESv2 API\n");
41 // This function is called only once during initialiation before
42 // any thread has been created - hence it should NOT be thread safe.
44 bool gles2_dispatch_init(const char *path, GLESv2Dispatch *dispatch_table)
46 const char *libName = getenv(glesv2_lib_env_var);
53 s_gles2_lib = emugl::SharedLibrary::open(libName, error, sizeof(error));
55 fprintf(stderr, "%s: Could not load %s [%s]\n", __FUNCTION__,
61 // init the GLES dispatch table
63 #define LOOKUP_SYMBOL(return_type,function_name,signature,callargs) \
64 dispatch_table-> function_name = reinterpret_cast< function_name ## _t >( \
65 s_gles2_lib->findSymbol(#function_name));
67 #define LOOKUP_EXT_SYMBOL(return_type,function_name,signature,callargs) \
68 dispatch_table-> function_name = reinterpret_cast< function_name ## _t >( \
69 s_egl.eglGetProcAddress(#function_name));
71 LIST_GLES2_FUNCTIONS(LOOKUP_SYMBOL,LOOKUP_EXT_SYMBOL)
73 dispatch_table->initialized = true;
79 // This function is called only during initialization before
80 // any thread has been created - hence it should NOT be thread safe.
82 void *gles2_dispatch_get_proc_func(const char *name, void *userData)
86 if (s_gles2_lib && !func) {
87 func = (void *)s_gles2_lib->findSymbol(name);
91 func = (void *)s_egl.eglGetProcAddress(name);
94 // To make it consistent with the guest, redirect any unsupported functions
95 // to gles2_unimplemented.
97 func = (void *)gles2_unimplemented;