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