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/GLESv1Dispatch.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 DEBUG 0
26
27 #if DEBUG
28 #define DPRINT(...) do { \
29 if (!VERBOSE_CHECK(gles1emu)) VERBOSE_ENABLE(gles1emu); \
30 VERBOSE_PRINT(gles1emu, __VA_ARGS__); \
31 } while (0)
32 #else
33 #define DPRINT(...)
34 #endif
35
36 // An unimplemented function which prints out an error message.
37 // To make it consistent with the guest, all GLES1 functions not supported by
38 // the guest driver should be redirected to this function.
39
gles1_unimplemented()40 void gles1_unimplemented() {
41 fprintf(stderr, "Called unimplemented GLESv1 API\n");
42 }
43
44 #define DEFAULT_GLES_CM_LIB EMUGL_LIBNAME("GLES_CM_translator")
45 #define DEFAULT_UNDERLYING_GLES_V2_LIB EMUGL_LIBNAME("GLES_V2_translator")
46
47 // This section of code (also in GLDispatch.cpp)
48 // initializes all GLESv1 functions to dummy ones;
49 // that is, in case we are using a library that doesn't
50 // have GLESv1, we will still have stubs available to
51 // signal that they are unsupported on the host.
52
53 #define RETURN_void return
54 #define RETURN_GLboolean return GL_FALSE
55 #define RETURN_GLint return 0
56 #define RETURN_GLuint return 0U
57 #define RETURN_GLenum return 0
58 #define RETURN_int return 0
59 #define RETURN_GLconstubyteptr return NULL
60 #define RETURN_voidptr return NULL
61
62 #define RETURN_(x) RETURN_ ## x
63
64 #define DUMMY_MSG "Call to %s: host OpenGL driver does not support OpenGL ES v1. Skipping."
65
66 #ifdef _WIN32
67
68 #define DEFINE_DUMMY_FUNCTION(return_type, func_name, signature, args) \
69 static return_type __stdcall gles1_dummy_##func_name signature { \
70 fprintf(stderr, DUMMY_MSG, #func_name); \
71 RETURN_(return_type); \
72 }
73
74 #define DEFINE_DUMMY_EXTENSION_FUNCTION(return_type, func_name, signature, args) \
75 static return_type __stdcall gles1_dummy_##func_name signature { \
76 fprintf(stderr, DUMMY_MSG, #func_name); \
77 RETURN_(return_type); \
78 }
79
80 #else
81
82 #define DEFINE_DUMMY_FUNCTION(return_type, func_name, signature, args) \
83 static return_type gles1_dummy_##func_name signature { \
84 fprintf(stderr, DUMMY_MSG, #func_name); \
85 RETURN_(return_type); \
86 }
87
88 #define DEFINE_DUMMY_EXTENSION_FUNCTION(return_type, func_name, signature, args) \
89 static return_type gles1_dummy_##func_name signature { \
90 fprintf(stderr, DUMMY_MSG, #func_name); \
91 RETURN_(return_type); \
92 }
93
94 #endif
95
96 //
97 // This function is called only once during initialiation before
98 // any thread has been created - hence it should NOT be thread safe.
99 //
100
101 // macro to assign from static library
102 #define ASSIGN_GLES1_STATIC(return_type,function_name,signature,callargs)\
103 dispatch_table-> function_name = reinterpret_cast< function_name ## _t >( \
104 translator::gles1::function_name); \
105 if ((!dispatch_table-> function_name) && s_egl.eglGetProcAddress) \
106 dispatch_table-> function_name = reinterpret_cast< function_name ## _t >( \
107 s_egl.eglGetProcAddress(#function_name)); \
108
gles1_dispatch_init(GLESv1Dispatch * dispatch_table)109 bool gles1_dispatch_init(GLESv1Dispatch* dispatch_table) {
110 if (dispatch_table->initialized) return true;
111
112 LIST_GLES1_FUNCTIONS(ASSIGN_GLES1_STATIC, ASSIGN_GLES1_STATIC);
113
114 dispatch_table->initialized = true;
115 return true;
116 }
117
gles1_dispatch_get_proc_func(const char * name,void * userData)118 void *gles1_dispatch_get_proc_func(const char *name, void *userData)
119 {
120 void* func = NULL;
121 func = gles1_dispatch_get_proc_func_static(name);
122
123 // To make it consistent with the guest, redirect any unsupported functions
124 // to gles1_unimplemented.
125 if (!func) {
126 func = (void *)gles1_unimplemented;
127 }
128 return func;
129 }
130