Home | History | Annotate | Download | only in libOpenglRender
      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 #ifdef WITH_GLES2
     17 #include "GL2Dispatch.h"
     18 #include <stdio.h>
     19 #include <stdlib.h>
     20 #include "osDynLibrary.h"
     21 
     22 gl2_decoder_context_t s_gl2;
     23 int                   s_gl2_enabled;
     24 
     25 static osUtils::dynLibrary *s_gles2_lib = NULL;
     26 
     27 #ifdef _WIN32
     28 #define DEFAULT_GLES_V2_LIB "libGLES_V2_translator"
     29 #elif defined(__APPLE__)
     30 #define DEFAULT_GLES_V2_LIB "libGLES_V2_translator.dylib"
     31 #else
     32 #define DEFAULT_GLES_V2_LIB "libGLES_V2_translator.so"
     33 #endif
     34 
     35 //
     36 // This function is called only once during initialiation before
     37 // any thread has been created - hence it should NOT be thread safe.
     38 //
     39 bool init_gl2_dispatch()
     40 {
     41     const char *libName = getenv("ANDROID_GLESv2_LIB");
     42     if (!libName) libName = DEFAULT_GLES_V2_LIB;
     43 
     44     //
     45     // Load the GLES library
     46     //
     47     s_gles2_lib = osUtils::dynLibrary::open(libName);
     48     if (!s_gles2_lib) return false;
     49 
     50     //
     51     // init the GLES dispatch table
     52     //
     53     s_gl2.initDispatchByName( gl2_dispatch_get_proc_func, NULL );
     54     s_gl2_enabled = true;
     55     return true;
     56 }
     57 
     58 //
     59 // This function is called only during initialiation before
     60 // any thread has been created - hence it should NOT be thread safe.
     61 //
     62 void *gl2_dispatch_get_proc_func(const char *name, void *userData)
     63 {
     64     if (!s_gles2_lib) {
     65         return NULL;
     66     }
     67     return (void *)s_gles2_lib->findSymbol(name);
     68 }
     69 
     70 #endif
     71