1 /*
2 * Copyright (C) 2011 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 #include "OpenGLESDispatch/GLESv2Dispatch.h"
17
18 #include "OpenGLESDispatch/EGLDispatch.h"
19 #include "OpenGLESDispatch/StaticDispatch.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #define DEFAULT_GLES_V2_LIB EMUGL_LIBNAME("GLES_V2_translator")
26
27 // An unimplemented function which prints out an error message.
28 // To make it consistent with the guest, all GLES2 functions not supported by
29 // the driver should be redirected to this function.
30
gles2_unimplemented()31 void gles2_unimplemented() {
32 fprintf(stderr, "Called unimplemented GLES API\n");
33 }
34
35 #define LOOKUP_SYMBOL_STATIC(return_type,function_name,signature,callargs) \
36 dispatch_table-> function_name = reinterpret_cast< function_name ## _t >( \
37 translator::gles2::function_name); \
38 if ((!dispatch_table-> function_name) && s_egl.eglGetProcAddress) \
39 dispatch_table-> function_name = reinterpret_cast< function_name ## _t >( \
40 s_egl.eglGetProcAddress(#function_name)); \
41
gles2_dispatch_init(GLESv2Dispatch * dispatch_table)42 bool gles2_dispatch_init(GLESv2Dispatch* dispatch_table) {
43 if (dispatch_table->initialized) return true;
44
45 LIST_GLES2_FUNCTIONS(LOOKUP_SYMBOL_STATIC,LOOKUP_SYMBOL_STATIC)
46
47 dispatch_table->initialized = true;
48 return true;
49 }
50
51
gles2_dispatch_get_proc_func(const char * name,void * userData)52 void *gles2_dispatch_get_proc_func(const char *name, void *userData)
53 {
54 void* func = NULL;
55 func = gles2_dispatch_get_proc_func_static(name);
56
57 // To make it consistent with the guest, redirect any unsupported functions
58 // to gles2_unimplemented.
59 if (!func) {
60 func = (void *)gles2_unimplemented;
61 }
62 return func;
63 }
64