1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" 6 7 #include <stddef.h> 8 9 #ifndef GL_FALSE 10 #define GL_FALSE 0 11 #endif // GL_FALSE 12 13 #ifndef GL_TRUE 14 #define GL_TRUE 1 15 #endif // GL_TRUE 16 17 #if defined(__GNUC__) && !defined(__APPLE__) && !defined(ANDROID) 18 #define PP_TLS __thread 19 #elif defined(_MSC_VER) 20 #define PP_TLS __declspec(thread) 21 #else 22 // TODO(alokp): Fix all other platforms. 23 #define PP_TLS 24 #endif 25 26 // TODO(alokp): This will need to be thread-safe if we build gles2 as a 27 // shared library. 28 static const struct PPB_OpenGLES2* g_gles2_interface = NULL; 29 static const struct PPB_OpenGLES2InstancedArrays* 30 g_gles2_instanced_arrays_interface = NULL; 31 static const struct PPB_OpenGLES2FramebufferBlit* 32 g_gles2_framebuffer_blit_interface = NULL; 33 static const struct PPB_OpenGLES2FramebufferMultisample* 34 g_gles2_framebuffer_multisample_interface = NULL; 35 static const struct PPB_OpenGLES2ChromiumEnableFeature* 36 g_gles2_chromium_enable_feature_interface = NULL; 37 static const struct PPB_OpenGLES2ChromiumMapSub* 38 g_gles2_chromium_map_sub_interface = NULL; 39 static const struct PPB_OpenGLES2Query* 40 g_gles2_query_interface = NULL; 41 42 // TODO(alokp): Make sure PP_TLS works on all supported platforms. 43 static PP_TLS PP_Resource g_current_context = 0; 44 45 GLboolean GL_APIENTRY glInitializePPAPI( 46 PPB_GetInterface get_browser_interface) { 47 if (!g_gles2_interface) { 48 g_gles2_interface = get_browser_interface(PPB_OPENGLES2_INTERFACE); 49 } 50 if (!g_gles2_instanced_arrays_interface) { 51 g_gles2_instanced_arrays_interface = 52 get_browser_interface(PPB_OPENGLES2_INSTANCEDARRAYS_INTERFACE); 53 } 54 if (!g_gles2_framebuffer_blit_interface) { 55 g_gles2_framebuffer_blit_interface = 56 get_browser_interface(PPB_OPENGLES2_FRAMEBUFFERBLIT_INTERFACE); 57 } 58 if (!g_gles2_framebuffer_multisample_interface) { 59 g_gles2_framebuffer_multisample_interface = 60 get_browser_interface( 61 PPB_OPENGLES2_FRAMEBUFFERMULTISAMPLE_INTERFACE); 62 } 63 if (!g_gles2_chromium_enable_feature_interface) { 64 g_gles2_chromium_enable_feature_interface = 65 get_browser_interface( 66 PPB_OPENGLES2_CHROMIUMENABLEFEATURE_INTERFACE); 67 } 68 if (!g_gles2_chromium_map_sub_interface) { 69 g_gles2_chromium_map_sub_interface = 70 get_browser_interface(PPB_OPENGLES2_CHROMIUMMAPSUB_INTERFACE); 71 } 72 if (!g_gles2_query_interface) { 73 g_gles2_query_interface = 74 get_browser_interface(PPB_OPENGLES2_QUERY_INTERFACE); 75 } 76 return g_gles2_interface ? GL_TRUE : GL_FALSE; 77 } 78 79 GLboolean GL_APIENTRY glTerminatePPAPI(void) { 80 g_gles2_interface = NULL; 81 return GL_TRUE; 82 } 83 84 void GL_APIENTRY glSetCurrentContextPPAPI(PP_Resource context) { 85 g_current_context = context; 86 } 87 88 PP_Resource GL_APIENTRY glGetCurrentContextPPAPI(void) { 89 return g_current_context; 90 } 91 92 const struct PPB_OpenGLES2* GL_APIENTRY glGetInterfacePPAPI(void) { 93 return g_gles2_interface; 94 } 95 96 const struct PPB_OpenGLES2InstancedArrays* GL_APIENTRY 97 glGetInstancedArraysInterfacePPAPI(void) { 98 return g_gles2_instanced_arrays_interface; 99 } 100 101 const struct PPB_OpenGLES2FramebufferBlit* GL_APIENTRY 102 glGetFramebufferBlitInterfacePPAPI(void) { 103 return g_gles2_framebuffer_blit_interface; 104 } 105 106 const struct PPB_OpenGLES2FramebufferMultisample* GL_APIENTRY 107 glGetFramebufferMultisampleInterfacePPAPI(void) { 108 return g_gles2_framebuffer_multisample_interface; 109 } 110 111 const struct PPB_OpenGLES2ChromiumEnableFeature* GL_APIENTRY 112 glGetChromiumEnableFeatureInterfacePPAPI(void) { 113 return g_gles2_chromium_enable_feature_interface; 114 } 115 116 const struct PPB_OpenGLES2ChromiumMapSub* GL_APIENTRY 117 glGetChromiumMapSubInterfacePPAPI(void) { 118 return g_gles2_chromium_map_sub_interface; 119 } 120 121 const struct PPB_OpenGLES2Query* GL_APIENTRY 122 glGetQueryInterfacePPAPI(void) { 123 return g_gles2_query_interface; 124 } 125