"""
This module contains hard-coded hexadecimal enum values for OpenGL and WebGL values.
Only enums which are present in both OpenGL and WebGL are included, all of these enums,
based on the specifications, are the same.

We are storing them here, so that we do not rely on importing the common subset of them from any
particular backend implementation's library(e.g. pyglet, JS via pyodide, etc).
"""

NONE = 0
NEVER = 0x0200
LESS = 0x0201
EQUAL = 0x0202
LEQUAL = 0x0203
GREATER = 0x0204
NOTEQUAL = 0x0205
GEQUAL = 0x0206
ALWAYS = 0x0207

# Get Parameters
VENDOR = 0x1F00
RENDERER = 0x1F01
VERSION = 0x1F02
SAMPLE_BUFFERS = 0x80A8
SUBPIXEL_BITS = 0x0D50
UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34
MAX_ARRAY_TEXTURE_LAYERS = 0x88FF
MAX_3D_TEXTURE_SIZE = 0x8073
MAX_COLOR_ATTACHMENTS = 0x8CDF
MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = 0x8A31
MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = 0x8A33
MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D
MAX_COMBINED_UNIFORM_BLOCKS = 0x8A2E
MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C
MAX_DRAW_BUFFERS = 0x8824
MAX_ELEMENTS_VERTICES = 0x80E8
MAX_ELEMENTS_INDICES = 0x80E9
MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125
MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49
MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD
MAX_FRAGMENT_UNIFORM_BLOCKS = 0x8A2D
MAX_SAMPLES = 0x8D57
MAX_RENDERBUFFER_SIZE = 0x84E8
MAX_UNIFORM_BUFFER_BINDINGS = 0x8A2F
MAX_TEXTURE_SIZE = 0x0D33
MAX_UNIFORM_BLOCK_SIZE = 0x8A30
MAX_VARYING_VECTORS = 0x8DFC
MAX_VERTEX_ATTRIBS = 0x8869
MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C
MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A
MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB
MAX_VERTEX_UNIFORM_BLOCKS = 0x8A2B
MAX_VERTEX_OUTPUT_COMPONENTS = 0x9122
MAX_TEXTURE_IMAGE_UNITS = 0x8872

# Technically comes from EXT_texture_filter_anisotropic in WebGL, but it's widely available
MAX_TEXTURE_MAX_ANISOTROPY = 0x84FF

MAX_VIEWPORT_DIMS = 0x0D3A
MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 0x8C8B

# Enable Flags
BLEND = 0x0BE2
DEPTH_TEST = 0x0B71
CULL_FACE = 0x0B44

# Texture min/mag filters
NEAREST = 0x2600
LINEAR = 0x2601
NEAREST_MIPMAP_NEAREST = 0x2700
LINEAR_MIPMAP_NEAREST = 0x2701
NEAREST_MIPMAP_LINEAR = 0x2702
LINEAR_MIPMAP_LINEAR = 0x2703

# Texture wrapping
REPEAT = 0x2901
CLAMP_TO_EDGE = 0x812F
MIRRORED_REPEAT = 0x8370

# Blend functions
ZERO = 0x0000
ONE = 0x0001
SRC_COLOR = 0x0300
ONE_MINUS_SRC_COLOR = 0x0301
SRC_ALPHA = 0x0302
ONE_MINUS_SRC_ALPHA = 0x0303
DST_ALPHA = 0x0304
ONE_MINUS_DST_ALPHA = 0x0305
DST_COLOR = 0x0306
ONE_MINUS_DST_COLOR = 0x0307

# Blend equations

FUNC_ADD = 0x8006
"""source + destination"""

FUNC_SUBTRACT = 0x800A
"""source - destination"""

FUNC_REVERSE_SUBTRACT = 0x800B
"""destination - source"""

MIN = 0x8007
"""Minimum of source and destination"""

MAX = 0x8008
"""Maximum of source and destination"""

BLEND_DEFAULT = SRC_ALPHA, ONE_MINUS_SRC_ALPHA
BLEND_ADDITIVE = ONE, ONE
BLEND_PREMULTIPLIED_ALPHA = SRC_ALPHA, ONE

# VertexArray: Primitives
POINTS = 0
LINES = 1
LINE_LOOP = 2
LINE_STRIP = 3
TRIANGLES = 4
TRIANGLE_STRIP = 5
TRIANGLE_FAN = 6
LINES_ADJACENCY = 10
LINE_STRIP_ADJACENCY = 11
TRIANGLES_ADJACENCY = 12
TRIANGLE_STRIP_ADJACENCY = 13
PATCHES = 14

# Errors
NO_ERROR = 0
INVALID_ENUM = 0x0500
INVALID_VALUE = 0x0501
INVALID_OPERATION = 0x0502
INVALID_FRAMEBUFFER_OPERATION = 0x0506
OUT_OF_MEMORY = 0x0505

FRONT = 0x0404
BACK = 0x0405
FRONT_AND_BACK = 0x0408

RED = 0x1903
RG = 0x8227
RGB = 0x1907
RGBA = 0x1908
RED_INTEGER = 0x8D94
RG_INTEGER = 0x8228
RGB_INTEGER = 0x8D98
RGBA_INTEGER = 0x8D99

R8 = 0x8229
RG8 = 0x822B
RGB8 = 0x8051
RGBA8 = 0x8058
R16F = 0x822D
RG16F = 0x822F
RGB16F = 0x881B
RGBA16F = 0x881A
R32F = 0x822E
RG32F = 0x8230
RGB32F = 0x8815
RGBA32F = 0x8814
R8I = 0x8231
RG8I = 0x8237
RGB8I = 0x8D8F
RGBA8I = 0x8D8E
R16I = 0x8233
RG16I = 0x8239
RGB16I = 0x8D89
RGBA16I = 0x8D88
R32I = 0x8235
RG32I = 0x823B
RGB32I = 0x8D83
RGBA32I = 0x8D82
R8UI = 0x8232
RG8UI = 0x8238
RGB8UI = 0x8D7D
RGBA8UI = 0x8D7C
R16UI = 0x8234
RG16UI = 0x823A
RGB16UI = 0x8D77
RGBA16UI = 0x8D76
R32UI = 0x8236
RG32UI = 0x823C
RGB32UI = 0x8D71
RGBA32UI = 0x8D70

BYTE = 0x1400
UNSIGNED_BYTE = 0x1401
SHORT = 0x1402
UNSIGNED_SHORT = 0x1403
INT = 0x1404
UNSIGNED_INT = 0x1405
FLOAT = 0x1406
HALF_FLOAT = 0x140B
DOUBLE = 0x140A  # Not supported in WebGL, but left in common to make implementation easier

FLOAT_VEC2 = 0x8B50
FLOAT_VEC3 = 0x8B51
FLOAT_VEC4 = 0x8B52
INT_VEC2 = 0x8B53
INT_VEC3 = 0x8B54
INT_VEC4 = 0x8B55
BOOL = 0x8B56
BOOL_VEC2 = 0x8B57
BOOL_VEC3 = 0x8B58
BOOL_VEC4 = 0x8B59
UNSIGNED_INT_VEC2 = 0x8DC6
UNSIGNED_INT_VEC3 = 0x8DC7
UNSIGNED_INT_VEC4 = 0x8DC8
FLOAT_MAT2 = 0x8B5A
FLOAT_MAT3 = 0x8B5B
FLOAT_MAT4 = 0x8B5C
FLOAT_MAT2x3 = 0x8B65
FLOAT_MAT2x4 = 0x8B66
FLOAT_MAT3x2 = 0x8B67
FLOAT_MAT3x4 = 0x8B68
FLOAT_MAT4x2 = 0x8B69
FLOAT_MAT4x3 = 0x8B6A

# Double Vectors - Unsupported by WebGL
DOUBLE_VEC2 = 0x8FFC
DOUBLE_VEC3 = 0x8FFD
DOUBLE_VEC4 = 0x8FFE

# Double Matrices - Unsupported by WebGL
DOUBLE_MAT2 = 0x8F46
DOUBLE_MAT3 = 0x8F47
DOUBLE_MAT4 = 0x8F48
DOUBLE_MAT2x3 = 0x8F49
DOUBLE_MAT2x4 = 0x8F4A
DOUBLE_MAT3x2 = 0x8F4B
DOUBLE_MAT3x4 = 0x8F4C
DOUBLE_MAT4x2 = 0x8F4D
DOUBLE_MAT4x3 = 0x8F4E

VERTEX_SHADER = 0x8B31
FRAGMENT_SHADER = 0x8B30
GEOMETRY_SHADER = 0x8DD9  # Not supported in WebGL
TESS_CONTROL_SHADER = 0x8E88  # Not supported in WebGL
TESS_EVALUATION_SHADER = 0x8E87  # Not supported in WebGL
