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 static const struct PPB_OpenGLES2VertexArrayObject* 42 g_gles2_vertex_array_object_interface = NULL; 43 static const struct PPB_OpenGLES2DrawBuffers_Dev* 44 g_gles2_draw_buffers_interface = NULL; 45 46 // TODO(alokp): Make sure PP_TLS works on all supported platforms. 47 static PP_TLS PP_Resource g_current_context = 0; 48 glInitializePPAPI(PPB_GetInterface get_browser_interface)49GLboolean GL_APIENTRY glInitializePPAPI( 50 PPB_GetInterface get_browser_interface) { 51 if (!g_gles2_interface) { 52 g_gles2_interface = get_browser_interface(PPB_OPENGLES2_INTERFACE); 53 } 54 if (!g_gles2_instanced_arrays_interface) { 55 g_gles2_instanced_arrays_interface = 56 get_browser_interface(PPB_OPENGLES2_INSTANCEDARRAYS_INTERFACE); 57 } 58 if (!g_gles2_framebuffer_blit_interface) { 59 g_gles2_framebuffer_blit_interface = 60 get_browser_interface(PPB_OPENGLES2_FRAMEBUFFERBLIT_INTERFACE); 61 } 62 if (!g_gles2_framebuffer_multisample_interface) { 63 g_gles2_framebuffer_multisample_interface = 64 get_browser_interface( 65 PPB_OPENGLES2_FRAMEBUFFERMULTISAMPLE_INTERFACE); 66 } 67 if (!g_gles2_chromium_enable_feature_interface) { 68 g_gles2_chromium_enable_feature_interface = 69 get_browser_interface( 70 PPB_OPENGLES2_CHROMIUMENABLEFEATURE_INTERFACE); 71 } 72 if (!g_gles2_chromium_map_sub_interface) { 73 g_gles2_chromium_map_sub_interface = 74 get_browser_interface(PPB_OPENGLES2_CHROMIUMMAPSUB_INTERFACE); 75 } 76 if (!g_gles2_query_interface) { 77 g_gles2_query_interface = 78 get_browser_interface(PPB_OPENGLES2_QUERY_INTERFACE); 79 } 80 if (!g_gles2_vertex_array_object_interface) { 81 g_gles2_vertex_array_object_interface = 82 get_browser_interface(PPB_OPENGLES2_VERTEXARRAYOBJECT_INTERFACE); 83 } 84 if (!g_gles2_draw_buffers_interface) { 85 g_gles2_draw_buffers_interface = 86 get_browser_interface(PPB_OPENGLES2_DRAWBUFFERS_DEV_INTERFACE); 87 } 88 return g_gles2_interface ? GL_TRUE : GL_FALSE; 89 } 90 glTerminatePPAPI(void)91GLboolean GL_APIENTRY glTerminatePPAPI(void) { 92 g_gles2_interface = NULL; 93 return GL_TRUE; 94 } 95 glSetCurrentContextPPAPI(PP_Resource context)96void GL_APIENTRY glSetCurrentContextPPAPI(PP_Resource context) { 97 g_current_context = context; 98 } 99 glGetCurrentContextPPAPI(void)100PP_Resource GL_APIENTRY glGetCurrentContextPPAPI(void) { 101 return g_current_context; 102 } 103 glGetInterfacePPAPI(void)104const struct PPB_OpenGLES2* GL_APIENTRY glGetInterfacePPAPI(void) { 105 return g_gles2_interface; 106 } 107 108 const struct PPB_OpenGLES2InstancedArrays* GL_APIENTRY glGetInstancedArraysInterfacePPAPI(void)109 glGetInstancedArraysInterfacePPAPI(void) { 110 return g_gles2_instanced_arrays_interface; 111 } 112 113 const struct PPB_OpenGLES2FramebufferBlit* GL_APIENTRY glGetFramebufferBlitInterfacePPAPI(void)114 glGetFramebufferBlitInterfacePPAPI(void) { 115 return g_gles2_framebuffer_blit_interface; 116 } 117 118 const struct PPB_OpenGLES2FramebufferMultisample* GL_APIENTRY glGetFramebufferMultisampleInterfacePPAPI(void)119 glGetFramebufferMultisampleInterfacePPAPI(void) { 120 return g_gles2_framebuffer_multisample_interface; 121 } 122 123 const struct PPB_OpenGLES2ChromiumEnableFeature* GL_APIENTRY glGetChromiumEnableFeatureInterfacePPAPI(void)124 glGetChromiumEnableFeatureInterfacePPAPI(void) { 125 return g_gles2_chromium_enable_feature_interface; 126 } 127 128 const struct PPB_OpenGLES2ChromiumMapSub* GL_APIENTRY glGetChromiumMapSubInterfacePPAPI(void)129 glGetChromiumMapSubInterfacePPAPI(void) { 130 return g_gles2_chromium_map_sub_interface; 131 } 132 133 const struct PPB_OpenGLES2Query* GL_APIENTRY glGetQueryInterfacePPAPI(void)134 glGetQueryInterfacePPAPI(void) { 135 return g_gles2_query_interface; 136 } 137 138 const struct PPB_OpenGLES2VertexArrayObject* GL_APIENTRY glGetVertexArrayObjectInterfacePPAPI(void)139 glGetVertexArrayObjectInterfacePPAPI(void) { 140 return g_gles2_vertex_array_object_interface; 141 } 142 143 const struct PPB_OpenGLES2DrawBuffers_Dev* GL_APIENTRY glGetDrawBuffersInterfacePPAPI(void)144 glGetDrawBuffersInterfacePPAPI(void) { 145 return g_gles2_draw_buffers_interface; 146 } 147