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