summaryrefslogtreecommitdiffstats
path: root/ppapi/lib/gl/gles2/gl2ext_ppapi.c
blob: e5872b506c00bca24a6fba434ea047a0e3adb5a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/lib/gl/gles2/gl2ext_ppapi.h"

#include <stddef.h>

#ifndef GL_FALSE
#define GL_FALSE 0
#endif  // GL_FALSE

#ifndef GL_TRUE
#define GL_TRUE 1
#endif  // GL_TRUE

#if defined(__GNUC__) && !defined(__APPLE__) && !defined(ANDROID)
#define PP_TLS __thread
#elif defined(_MSC_VER)
#define PP_TLS __declspec(thread)
#else
// TODO(alokp): Fix all other platforms.
#define PP_TLS
#endif

// TODO(alokp): This will need to be thread-safe if we build gles2 as a
// shared library.
static const struct PPB_OpenGLES2* g_gles2_interface = NULL;
static const struct PPB_OpenGLES2InstancedArrays*
    g_gles2_instanced_arrays_interface = NULL;
static const struct PPB_OpenGLES2FramebufferBlit*
    g_gles2_framebuffer_blit_interface = NULL;
static const struct PPB_OpenGLES2FramebufferMultisample*
    g_gles2_framebuffer_multisample_interface = NULL;
static const struct PPB_OpenGLES2ChromiumEnableFeature*
    g_gles2_chromium_enable_feature_interface = NULL;
static const struct PPB_OpenGLES2ChromiumMapSub*
    g_gles2_chromium_map_sub_interface = NULL;
static const struct PPB_OpenGLES2Query*
    g_gles2_query_interface = NULL;
static const struct PPB_OpenGLES2DrawBuffers_Dev*
    g_gles2_draw_buffers_interface = NULL;

// TODO(alokp): Make sure PP_TLS works on all supported platforms.
static PP_TLS PP_Resource g_current_context = 0;

GLboolean GL_APIENTRY glInitializePPAPI(
    PPB_GetInterface get_browser_interface) {
  if (!g_gles2_interface) {
    g_gles2_interface = get_browser_interface(PPB_OPENGLES2_INTERFACE);
  }
  if (!g_gles2_instanced_arrays_interface) {
    g_gles2_instanced_arrays_interface =
        get_browser_interface(PPB_OPENGLES2_INSTANCEDARRAYS_INTERFACE);
  }
  if (!g_gles2_framebuffer_blit_interface) {
    g_gles2_framebuffer_blit_interface =
        get_browser_interface(PPB_OPENGLES2_FRAMEBUFFERBLIT_INTERFACE);
  }
  if (!g_gles2_framebuffer_multisample_interface) {
    g_gles2_framebuffer_multisample_interface =
        get_browser_interface(
            PPB_OPENGLES2_FRAMEBUFFERMULTISAMPLE_INTERFACE);
  }
  if (!g_gles2_chromium_enable_feature_interface) {
    g_gles2_chromium_enable_feature_interface =
        get_browser_interface(
            PPB_OPENGLES2_CHROMIUMENABLEFEATURE_INTERFACE);
  }
  if (!g_gles2_chromium_map_sub_interface) {
    g_gles2_chromium_map_sub_interface =
        get_browser_interface(PPB_OPENGLES2_CHROMIUMMAPSUB_INTERFACE);
  }
  if (!g_gles2_query_interface) {
    g_gles2_query_interface =
        get_browser_interface(PPB_OPENGLES2_QUERY_INTERFACE);
  }
  if (!g_gles2_draw_buffers_interface) {
    g_gles2_draw_buffers_interface =
        get_browser_interface(PPB_OPENGLES2_DRAWBUFFERS_DEV_INTERFACE);
  }
  return g_gles2_interface ? GL_TRUE : GL_FALSE;
}

GLboolean GL_APIENTRY glTerminatePPAPI(void) {
  g_gles2_interface = NULL;
  return GL_TRUE;
}

void GL_APIENTRY glSetCurrentContextPPAPI(PP_Resource context) {
  g_current_context = context;
}

PP_Resource GL_APIENTRY glGetCurrentContextPPAPI(void) {
  return g_current_context;
}

const struct PPB_OpenGLES2* GL_APIENTRY glGetInterfacePPAPI(void) {
  return g_gles2_interface;
}

const struct PPB_OpenGLES2InstancedArrays* GL_APIENTRY
    glGetInstancedArraysInterfacePPAPI(void) {
  return g_gles2_instanced_arrays_interface;
}

const struct PPB_OpenGLES2FramebufferBlit* GL_APIENTRY
    glGetFramebufferBlitInterfacePPAPI(void) {
  return g_gles2_framebuffer_blit_interface;
}

const struct PPB_OpenGLES2FramebufferMultisample* GL_APIENTRY
    glGetFramebufferMultisampleInterfacePPAPI(void) {
  return g_gles2_framebuffer_multisample_interface;
}

const struct PPB_OpenGLES2ChromiumEnableFeature* GL_APIENTRY
    glGetChromiumEnableFeatureInterfacePPAPI(void) {
  return g_gles2_chromium_enable_feature_interface;
}

const struct PPB_OpenGLES2ChromiumMapSub* GL_APIENTRY
    glGetChromiumMapSubInterfacePPAPI(void) {
  return g_gles2_chromium_map_sub_interface;
}

const struct PPB_OpenGLES2Query* GL_APIENTRY
    glGetQueryInterfacePPAPI(void) {
  return g_gles2_query_interface;
}

const struct PPB_OpenGLES2DrawBuffers_Dev* GL_APIENTRY
    glGetDrawBuffersInterfacePPAPI(void) {
  return g_gles2_draw_buffers_interface;
}