Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ppapi / lib / gl / gles2 / gl2ext_ppapi.c
blobc37f41a15e32c3b8bc48ee2a1a4d95896625d5ed
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.
5 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h"
7 #include <stddef.h>
9 #ifndef GL_FALSE
10 #define GL_FALSE 0
11 #endif // GL_FALSE
13 #ifndef GL_TRUE
14 #define GL_TRUE 1
15 #endif // GL_TRUE
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
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;
46 // TODO(alokp): Make sure PP_TLS works on all supported platforms.
47 static PP_TLS PP_Resource g_current_context = 0;
49 GLboolean GL_APIENTRY glInitializePPAPI(
50 PPB_GetInterface get_browser_interface) {
51 if (!g_gles2_interface) {
52 g_gles2_interface = get_browser_interface(PPB_OPENGLES2_INTERFACE);
54 if (!g_gles2_instanced_arrays_interface) {
55 g_gles2_instanced_arrays_interface =
56 get_browser_interface(PPB_OPENGLES2_INSTANCEDARRAYS_INTERFACE);
58 if (!g_gles2_framebuffer_blit_interface) {
59 g_gles2_framebuffer_blit_interface =
60 get_browser_interface(PPB_OPENGLES2_FRAMEBUFFERBLIT_INTERFACE);
62 if (!g_gles2_framebuffer_multisample_interface) {
63 g_gles2_framebuffer_multisample_interface =
64 get_browser_interface(
65 PPB_OPENGLES2_FRAMEBUFFERMULTISAMPLE_INTERFACE);
67 if (!g_gles2_chromium_enable_feature_interface) {
68 g_gles2_chromium_enable_feature_interface =
69 get_browser_interface(
70 PPB_OPENGLES2_CHROMIUMENABLEFEATURE_INTERFACE);
72 if (!g_gles2_chromium_map_sub_interface) {
73 g_gles2_chromium_map_sub_interface =
74 get_browser_interface(PPB_OPENGLES2_CHROMIUMMAPSUB_INTERFACE);
76 if (!g_gles2_query_interface) {
77 g_gles2_query_interface =
78 get_browser_interface(PPB_OPENGLES2_QUERY_INTERFACE);
80 if (!g_gles2_vertex_array_object_interface) {
81 g_gles2_vertex_array_object_interface =
82 get_browser_interface(PPB_OPENGLES2_VERTEXARRAYOBJECT_INTERFACE);
84 if (!g_gles2_draw_buffers_interface) {
85 g_gles2_draw_buffers_interface =
86 get_browser_interface(PPB_OPENGLES2_DRAWBUFFERS_DEV_INTERFACE);
88 return g_gles2_interface ? GL_TRUE : GL_FALSE;
91 GLboolean GL_APIENTRY glTerminatePPAPI(void) {
92 g_gles2_interface = NULL;
93 return GL_TRUE;
96 void GL_APIENTRY glSetCurrentContextPPAPI(PP_Resource context) {
97 g_current_context = context;
100 PP_Resource GL_APIENTRY glGetCurrentContextPPAPI(void) {
101 return g_current_context;
104 const struct PPB_OpenGLES2* GL_APIENTRY glGetInterfacePPAPI(void) {
105 return g_gles2_interface;
108 const struct PPB_OpenGLES2InstancedArrays* GL_APIENTRY
109 glGetInstancedArraysInterfacePPAPI(void) {
110 return g_gles2_instanced_arrays_interface;
113 const struct PPB_OpenGLES2FramebufferBlit* GL_APIENTRY
114 glGetFramebufferBlitInterfacePPAPI(void) {
115 return g_gles2_framebuffer_blit_interface;
118 const struct PPB_OpenGLES2FramebufferMultisample* GL_APIENTRY
119 glGetFramebufferMultisampleInterfacePPAPI(void) {
120 return g_gles2_framebuffer_multisample_interface;
123 const struct PPB_OpenGLES2ChromiumEnableFeature* GL_APIENTRY
124 glGetChromiumEnableFeatureInterfacePPAPI(void) {
125 return g_gles2_chromium_enable_feature_interface;
128 const struct PPB_OpenGLES2ChromiumMapSub* GL_APIENTRY
129 glGetChromiumMapSubInterfacePPAPI(void) {
130 return g_gles2_chromium_map_sub_interface;
133 const struct PPB_OpenGLES2Query* GL_APIENTRY
134 glGetQueryInterfacePPAPI(void) {
135 return g_gles2_query_interface;
138 const struct PPB_OpenGLES2VertexArrayObject* GL_APIENTRY
139 glGetVertexArrayObjectInterfacePPAPI(void) {
140 return g_gles2_vertex_array_object_interface;
143 const struct PPB_OpenGLES2DrawBuffers_Dev* GL_APIENTRY
144 glGetDrawBuffersInterfacePPAPI(void) {
145 return g_gles2_draw_buffers_interface;