chromium/ui/gl/gl_bindings.h

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GL_GL_BINDINGS_H_
#define UI_GL_GL_BINDINGS_H_

#include "base/memory/raw_ptr.h"
#include "build/build_config.h"

// Includes the platform independent and platform dependent GL headers.

// GL headers may include inttypes.h and so we need to ensure that
// __STDC_FORMAT_MACROS is defined in order for //base/format_macros.h to
// function correctly. See comment and #error message in //base/format_macros.h
// for details.
#if BUILDFLAG(IS_POSIX) && !defined(__STDC_FORMAT_MACROS)
#define __STDC_FORMAT_MACROS
#endif

#include <GL/gl.h>
#include <GL/glext.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <stdint.h>

#include "base/logging.h"
#include "build/build_config.h"
#include "ui/gfx/extension_set.h"
#include "ui/gl/gl_export.h"

// GLES2 defines not part of Desktop GL
// Shader Precision-Specified Types
#define GL_LOW_FLOAT
#define GL_MEDIUM_FLOAT
#define GL_HIGH_FLOAT
#define GL_LOW_INT
#define GL_MEDIUM_INT
#define GL_HIGH_INT
#define GL_IMPLEMENTATION_COLOR_READ_TYPE
#define GL_IMPLEMENTATION_COLOR_READ_FORMAT
#define GL_MAX_FRAGMENT_UNIFORM_VECTORS
#define GL_MAX_VERTEX_UNIFORM_VECTORS
#define GL_MAX_VARYING_VECTORS
#define GL_SHADER_BINARY_FORMATS
#define GL_NUM_SHADER_BINARY_FORMATS
#define GL_SHADER_COMPILER
#define GL_RGB565
#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
#define GL_RGB8_OES
#define GL_RGBA8_OES
#define GL_HALF_FLOAT_OES

// GL_OES_EGL_image_external
#define GL_TEXTURE_EXTERNAL_OES
#define GL_SAMPLER_EXTERNAL_OES
#define GL_TEXTURE_BINDING_EXTERNAL_OES
#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES

// GL_ANGLE_texture_rectangle
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE
#define GL_TEXTURE_RECTANGLE_ANGLE
#define GL_TEXTURE_BINDING_RECTANGLE_ANGLE
#define GL_SAMPLER_2D_RECT_ANGLE

// GL_ANGLE_translated_shader_source
#define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE

#define GL_UNPACK_COLORSPACE_CONVERSION_CHROMIUM
#define GL_BIND_GENERATES_RESOURCE_CHROMIUM

// GL_ANGLE_texture_usage
#define GL_TEXTURE_USAGE_ANGLE
#define GL_FRAMEBUFFER_ATTACHMENT_ANGLE

// GL_ANGLE_renderability_validation
#define GL_RENDERABILITY_VALIDATION_ANGLE

// GL_EXT_texture_storage
#define GL_TEXTURE_IMMUTABLE_FORMAT_EXT
#define GL_ALPHA8_EXT
#define GL_LUMINANCE8_EXT
#define GL_LUMINANCE8_ALPHA8_EXT
#define GL_RGB10_A2_EXT
#define GL_RGBA32F_EXT
#define GL_RGB32F_EXT
#define GL_ALPHA32F_EXT
#define GL_LUMINANCE32F_EXT
#define GL_LUMINANCE_ALPHA32F_EXT
#define GL_RGBA16F_EXT
#define GL_RGB16F_EXT
#define GL_RG16F_EXT
#define GL_R16F_EXT
#define GL_ALPHA16F_EXT
#define GL_LUMINANCE16F_EXT
#define GL_LUMINANCE_ALPHA16F_EXT
#define GL_R32F_EXT
#define GL_RG32F_EXT
#define GL_BGRA8_EXT

// GL_ANGLE_instanced_arrays
#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE

// GL_ANGLE_client_arrays
#define GL_CLIENT_ARRAYS_ANGLE

// GL_ANGLE_robust_resource_initialization
#define GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE
#define GL_RESOURCE_INITIALIZED_ANGLE

// GL_ANGLE_request_extension
#define GL_REQUESTABLE_EXTENSIONS_ANGLE
#define GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE

// GL_ANGLE_memory_size
#define GL_MEMORY_SIZE_ANGLE

// GL_ANGLE_rgbx_internal_format
#define GL_RGBX8_ANGLE

// GL_ANGLE_shader_pixel_local_storage
#define GL_MAX_PIXEL_LOCAL_STORAGE_PLANES_ANGLE
#define GL_MAX_COLOR_ATTACHMENTS_WITH_ACTIVE_PIXEL_LOCAL_STORAGE_ANGLE
#define GL_MAX_COMBINED_DRAW_BUFFERS_AND_PIXEL_LOCAL_STORAGE_PLANES_ANGLE
#define GL_PIXEL_LOCAL_STORAGE_ACTIVE_PLANES_ANGLE
#define GL_LOAD_OP_ZERO_ANGLE
#define GL_LOAD_OP_CLEAR_ANGLE
#define GL_LOAD_OP_LOAD_ANGLE
#define GL_STORE_OP_STORE_ANGLE
#define GL_PIXEL_LOCAL_FORMAT_ANGLE
#define GL_PIXEL_LOCAL_TEXTURE_NAME_ANGLE
#define GL_PIXEL_LOCAL_TEXTURE_LEVEL_ANGLE
#define GL_PIXEL_LOCAL_TEXTURE_LAYER_ANGLE
#define GL_PIXEL_LOCAL_CLEAR_VALUE_FLOAT_ANGLE
#define GL_PIXEL_LOCAL_CLEAR_VALUE_INT_ANGLE
#define GL_PIXEL_LOCAL_CLEAR_VALUE_UNSIGNED_INT_ANGLE

// GL_EXT_occlusion_query_boolean
#define GL_ANY_SAMPLES_PASSED_EXT
#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT
#define GL_CURRENT_QUERY_EXT
#define GL_QUERY_RESULT_EXT
#define GL_QUERY_RESULT_AVAILABLE_EXT

// GL_ARB_occlusion_query
#define GL_SAMPLES_PASSED_ARB

// GL_CHROMIUM_command_buffer_query
#define GL_COMMANDS_ISSUED_CHROMIUM
#define GL_COMMANDS_ISSUED_TIMESTAMP_CHROMIUM

/* GL_CHROMIUM_get_error_query */
#define GL_GET_ERROR_QUERY_CHROMIUM

/* GL_CHROMIUM_program_completion_query */
#define GL_PROGRAM_COMPLETION_QUERY_CHROMIUM

/* GL_CHROMIUM_async_pixel_transfers */
#define GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM

// GL_CHROMIUM_sync_query
#define GL_COMMANDS_COMPLETED_CHROMIUM

// GL_CHROMIUM_subscribe_uniforms
#define GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM
#define GL_MOUSE_POSITION_CHROMIUM

// GL_OES_texure_3D
#define GL_SAMPLER_3D_OES

// GL_OES_depth24
#define GL_DEPTH_COMPONENT24_OES

// GL_OES_depth32
#define GL_DEPTH_COMPONENT32_OES

// GL_OES_packed_depth_stencil
#ifndef GL_DEPTH24_STENCIL8_OES
#define GL_DEPTH24_STENCIL8_OES
#endif

#ifndef GL_DEPTH24_STENCIL8
#define GL_DEPTH24_STENCIL8
#endif

// GL_OES_compressed_ETC1_RGB8_texture
#define GL_ETC1_RGB8_OES

// GL_OES_compressed_ETC2_RGB8_texture
#define GL_COMPRESSED_RGB8_ETC2

// GL_AMD_compressed_ATC_texture
#define GL_ATC_RGB_AMD
#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD

// GL_IMG_texture_compression_pvrtc
#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG

// GL_EXT_texture_compression_bptc
#define GL_COMPRESSED_RGBA_BPTC_UNORM_EXT
#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT
#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT
#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT

// GL_EXT_texture_compression_rgtc
#define GL_COMPRESSED_RED_RGTC1_EXT
#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT
#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT

// GL_OES_vertex_array_object
#define GL_VERTEX_ARRAY_BINDING_OES

// GL_CHROMIUM_pixel_transfer_buffer_object
#define GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM
#define GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM
#define GL_PIXEL_PACK_TRANSFER_BUFFER_BINDING_CHROMIUM
#define GL_PIXEL_UNPACK_TRANSFER_BUFFER_BINDING_CHROMIUM

/* GL_EXT_discard_framebuffer */
#ifndef GL_EXT_discard_framebuffer
#define GL_COLOR_EXT
#define GL_DEPTH_EXT
#define GL_STENCIL_EXT
#endif

// GL_EXT_sRGB
#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT

// GL_ARB_get_program_binary
#define PROGRAM_BINARY_RETRIEVABLE_HINT
// GL_OES_get_program_binary
#define GL_PROGRAM_BINARY_LENGTH_OES
#define GL_NUM_PROGRAM_BINARY_FORMATS_OES
#define GL_PROGRAM_BINARY_FORMATS_OES

#ifndef GL_EXT_multisampled_render_to_texture
#define GL_RENDERBUFFER_SAMPLES_EXT
#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT
#define GL_MAX_SAMPLES_EXT
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT
#endif

#ifndef GL_IMG_multisampled_render_to_texture
#define GL_RENDERBUFFER_SAMPLES_IMG
#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG
#define GL_MAX_SAMPLES_IMG
#define GL_TEXTURE_SAMPLES_IMG
#endif

#ifndef GL_CHROMIUM_path_rendering
#define GL_CHROMIUM_path_rendering
// These match the corresponding values in NV_path_rendering
// extension, eg tokens with CHROMIUM replaced with NV.
#define GL_PATH_MODELVIEW_MATRIX_CHROMIUM
#define GL_PATH_PROJECTION_MATRIX_CHROMIUM
#define GL_PATH_MODELVIEW_CHROMIUM
#define GL_PATH_PROJECTION_CHROMIUM
#define GL_FLAT_CHROMIUM
#define GL_CLOSE_PATH_CHROMIUM
#define GL_MOVE_TO_CHROMIUM
#define GL_LINE_TO_CHROMIUM
#define GL_QUADRATIC_CURVE_TO_CHROMIUM
#define GL_CUBIC_CURVE_TO_CHROMIUM
#define GL_CONIC_CURVE_TO_CHROMIUM
#define GL_EYE_LINEAR_CHROMIUM
#define GL_OBJECT_LINEAR_CHROMIUM
#define GL_CONSTANT_CHROMIUM
#define GL_PATH_STROKE_WIDTH_CHROMIUM
#define GL_PATH_END_CAPS_CHROMIUM
#define GL_PATH_JOIN_STYLE_CHROMIUM
#define GL_PATH_MITER_LIMIT_CHROMIUM
#define GL_PATH_STROKE_BOUND_CHROMIUM
#define GL_COUNT_UP_CHROMIUM
#define GL_COUNT_DOWN_CHROMIUM
#define GL_CONVEX_HULL_CHROMIUM
#define GL_BOUNDING_BOX_CHROMIUM
#define GL_TRANSLATE_X_CHROMIUM
#define GL_TRANSLATE_Y_CHROMIUM
#define GL_TRANSLATE_2D_CHROMIUM
#define GL_TRANSLATE_3D_CHROMIUM
#define GL_AFFINE_2D_CHROMIUM
#define GL_AFFINE_3D_CHROMIUM
#define GL_TRANSPOSE_AFFINE_2D_CHROMIUM
#define GL_TRANSPOSE_AFFINE_3D_CHROMIUM
#define GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM
#define GL_SQUARE_CHROMIUM
#define GL_ROUND_CHROMIUM
#define GL_BEVEL_CHROMIUM
#define GL_MITER_REVERT_CHROMIUM
#define GL_PATH_STENCIL_FUNC_CHROMIUM
#define GL_PATH_STENCIL_REF_CHROMIUM
#define GL_PATH_STENCIL_VALUE_MASK_CHROMIUM
#endif

#ifndef GL_EXT_multisample_compatibility
#define GL_EXT_multisample_compatibility
#define GL_MULTISAMPLE_EXT
#define GL_SAMPLE_ALPHA_TO_ONE_EXT
#endif /* GL_EXT_multisample_compatibility */

#ifndef GL_KHR_blend_equation_advanced
#define GL_KHR_blend_equation_advanced
#define GL_COLORBURN_KHR
#define GL_COLORDODGE_KHR
#define GL_DARKEN_KHR
#define GL_DIFFERENCE_KHR
#define GL_EXCLUSION_KHR
#define GL_HARDLIGHT_KHR
#define GL_HSL_COLOR_KHR
#define GL_HSL_HUE_KHR
#define GL_HSL_LUMINOSITY_KHR
#define GL_HSL_SATURATION_KHR
#define GL_LIGHTEN_KHR
#define GL_MULTIPLY_KHR
#define GL_OVERLAY_KHR
#define GL_SCREEN_KHR
#define GL_SOFTLIGHT_KHR
#endif /* GL_KHR_blend_equation_advanced */

#ifndef GL_KHR_blend_equation_advanced_coherent
#define GL_KHR_blend_equation_advanced_coherent
#define GL_BLEND_ADVANCED_COHERENT_KHR
#endif /* GL_KHR_blend_equation_advanced_coherent */

#ifndef GL_EXT_disjoint_timer_query
#define GL_EXT_disjoint_timer_query
#define GL_QUERY_COUNTER_BITS_EXT
#define GL_TIME_ELAPSED_EXT
#define GL_TIMESTAMP_EXT
#define GL_GPU_DISJOINT_EXT
#endif

#ifndef GL_KHR_robustness
#define GL_KHR_robustness
#define GL_CONTEXT_ROBUST_ACCESS_KHR
#define GL_LOSE_CONTEXT_ON_RESET_KHR
#define GL_GUILTY_CONTEXT_RESET_KHR
#define GL_INNOCENT_CONTEXT_RESET_KHR
#define GL_UNKNOWN_CONTEXT_RESET_KHR
#define GL_RESET_NOTIFICATION_STRATEGY_KHR
#define GL_NO_RESET_NOTIFICATION_KHR
#define GL_CONTEXT_LOST_KHR
#endif /* GL_KHR_robustness */

#ifndef GL_EXT_texture_norm16
#define GL_EXT_texture_norm16
#define GL_R16_EXT
#define GL_RG16_EXT
#define GL_RGBA16_EXT
#define GL_RGB16_EXT
#define GL_R16_SNORM_EXT
#define GL_RG16_SNORM_EXT
#define GL_RGBA16_SNORM_EXT
#define GL_RGB16_SNORM_EXT
#endif /* GL_EXT_texture_norm16 */

#ifndef GL_EXT_texture_rg
#define GL_EXT_texture_rg
#define GL_RED_EXT
#define GL_RG_EXT
#define GL_R8_EXT
#define GL_RG8_EXT
#endif /* GL_EXT_texture_rg */

// This is from NV_path_rendering, but the GL header is not up to date with the
// most recent version of the extension. This definition could be removed once
// glext.h r27498 or later is imported.
#ifndef GL_FRAGMENT_INPUT_NV
#define GL_FRAGMENT_INPUT_NV
#endif

#ifndef GL_EXT_blend_func_extended
#define GL_EXT_blend_func_extended
#define GL_SRC_ALPHA_SATURATE_EXT
#define GL_SRC1_ALPHA_EXT
#define GL_SRC1_COLOR_EXT
#define GL_ONE_MINUS_SRC1_COLOR_EXT
#define GL_ONE_MINUS_SRC1_ALPHA_EXT
#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT
#endif /* GL_EXT_blend_func_extended */

#ifndef GL_OES_draw_buffers_indexed
#define GL_OES_draw_buffers_indexed
#define GL_BLEND_EQUATION_RGB
#define GL_BLEND_EQUATION_ALPHA
#define GL_BLEND_SRC_RGB
#define GL_BLEND_SRC_ALPHA
#define GL_BLEND_DST_RGB
#define GL_BLEND_DST_ALPHA
#define GL_COLOR_WRITEMASK
#endif /* GL_OES_draw_buffers_indexed */

#ifndef GL_EXT_window_rectangles
#define GL_EXT_window_rectangles
#define GL_INCLUSIVE_EXT
#define GL_EXCLUSIVE_EXT
#define GL_WINDOW_RECTANGLE_EXT
#define GL_WINDOW_RECTANGLE_MODE_EXT
#define GL_MAX_WINDOW_RECTANGLES_EXT
#define GL_NUM_WINDOW_RECTANGLES_EXT
#endif /* GL_EXT_window_rectangles */

#ifndef GL_CHROMIUM_nonblocking_readback
#define GL_CHROMIUM_nonblocking_readback
#define GL_READBACK_SHADOW_COPIES_UPDATED_CHROMIUM
#endif /* GL_CHROMIUM_nonblocking_readback */

#ifndef GL_MESA_framebuffer_flip_y
#define GL_MESA_framebuffer_flip_y
#define GL_FRAMEBUFFER_FLIP_Y_MESA
#endif /* GL_MESA_framebuffer_flip_y */

#ifndef GL_KHR_parallel_shader_compile
#define GL_KHR_parallel_shader_compile
#define GL_MAX_SHADER_COMPILER_THREADS_KHR
#define GL_COMPLETION_STATUS_KHR
#endif /* GL_KHR_parallel_shader_compile */

#ifndef GL_CHROMIUM_shared_image
#define GL_CHROMIUM_shared_image
#define GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM
#define GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM
#endif /* GL_CHROMIUM_shared_image */

#ifndef GL_NV_internalformat_sample_query
#define GL_MULTISAMPLES_NV
#define GL_SUPERSAMPLE_SCALE_X_NV
#define GL_SUPERSAMPLE_SCALE_Y_NV
#define GL_CONFORMANT_NV
#endif /* GL_NV_internalformat_sample_query */

#ifndef GL_EXT_YUV_target
#define GL_EXT_YUV_target
#define GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT
#endif /* GL_EXT_YUV_target */

#define GL_GLEXT_PROTOTYPES

#if BUILDFLAG(IS_WIN)
#define GL_BINDING_CALL
#else
#define GL_BINDING_CALL
#endif

#if defined(NDEBUG) && !defined(GPU_ENABLE_SERVICE_LOGGING)
#define GL_SERVICE_LOG
#define GL_SERVICE_LOG_CODE_BLOCK
#else
#define GL_SERVICE_LOG(args)
#define GL_SERVICE_LOG_CODE_BLOCK(code)
#endif

// OVR_multiview2 constants.
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR
#define GL_MAX_VIEWS_OVR
#define GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR

#define GL_QUERY_RESULT_AVAILABLE_NO_FLUSH_CHROMIUM_EXT

// EGL_ANGLE_global_fence_sync
#define EGL_SYNC_GLOBAL_FENCE_ANGLE

// Forward declare EGL types.
EGLuint64CHROMIUM;

#include "gl_bindings_autogen_gl.h"
#include "gl_bindings_autogen_egl.h"

namespace gl {

struct GLVersionInfo;

struct GL_EXPORT DriverGL {};

struct GL_EXPORT CurrentGL {};

struct GL_EXPORT DriverEGL {};

// This #define is here to support autogenerated code.
#define g_current_gl_context
#define g_current_gl_driver
#define g_current_gl_version
GL_EXPORT CurrentGL* GetThreadLocalCurrentGL();

GL_EXPORT extern EGLApi* g_current_egl_context;
GL_EXPORT extern DriverEGL g_driver_egl;

}  // namespace gl

#endif  // UI_GL_GL_BINDINGS_H_