-- Copied and converted from pspgu.h
GU_POINTS = 0
GU_LINES = 1
GU_LINE_STRIP = 2
GU_TRIANGLES = 3
GU_TRIANGLE_STRIP = 4
GU_TRIANGLE_FAN = 5
GU_SPRITES = 6

-- States
GU_ALPHA_TEST = 0
GU_DEPTH_TEST = 1
GU_SCISSOR_TEST = 2
GU_STENCIL_TEST = 3
GU_BLEND = 4
GU_CULL_FACE = 5
GU_DITHER = 6
GU_FOG = 7
GU_CLIP_PLANES = 8
GU_TEXTURE_2D = 9
GU_LIGHTING = 10
GU_LIGHT = 11
GU_LIGHT = 12
GU_LIGHT = 13
GU_LIGHT = 14
GU_LINE_SMOOTH = 15
GU_PATCH_CULL_FACE = 16
GU_COLOR_TEST = 17
GU_COLOR_LOGIC_OP = 18
GU_FACE_NORMAL_REVERSE = 19
GU_PATCH_FACE = 20
GU_FRAGMENT_2X = 21

-- Matrix modes
GU_PROJECTION = 0
GU_VIEW = 1
GU_MODEL = 2
GU_TEXTURE = 3

-- Vertex Declarations Begin
GU_TEXTURE_SHIFT = function(n) return n end
GU_TEXTURE_8BIT = GU_TEXTURE_SHIFT(1)
GU_TEXTURE_16BIT = GU_TEXTURE_SHIFT(2)
GU_TEXTURE_32BITF = GU_TEXTURE_SHIFT(3)
GU_TEXTURE_BITS = GU_TEXTURE_SHIFT(3)

GU_COLOR_SHIFT = function(n) return SHIFT(n, 2) end
GU_COLOR_5650 = GU_COLOR_SHIFT(4)
GU_COLOR_5551 = GU_COLOR_SHIFT(5)
GU_COLOR_4444 = GU_COLOR_SHIFT(6)
GU_COLOR_8888 = GU_COLOR_SHIFT(7)
GU_COLOR_BITS = GU_COLOR_SHIFT(7)

GU_NORMAL_SHIFT = function(n) return SHIFT(n, 5) end
GU_NORMAL_8BIT = GU_NORMAL_SHIFT(1)
GU_NORMAL_16BIT = GU_NORMAL_SHIFT(2)
GU_NORMAL_32BITF = GU_NORMAL_SHIFT(3)
GU_NORMAL_BITS = GU_NORMAL_SHIFT(3)

GU_VERTEX_SHIFT = function(n) return SHIFT(n, 7) end
GU_VERTEX_8BIT = GU_VERTEX_SHIFT(1)
GU_VERTEX_16BIT = GU_VERTEX_SHIFT(2)
GU_VERTEX_32BITF = GU_VERTEX_SHIFT(3)
GU_VERTEX_BITS = GU_VERTEX_SHIFT(3)

GU_WEIGHT_SHIFT = function(n) return SHIFT(n, 9) end
GU_WEIGHT_8BIT = GU_WEIGHT_SHIFT(1)
GU_WEIGHT_16BIT = GU_WEIGHT_SHIFT(2)
GU_WEIGHT_32BITF = GU_WEIGHT_SHIFT(3)
GU_WEIGHT_BITS = GU_WEIGHT_SHIFT(3)

GU_INDEX_SHIFT = function(n) return SHIFT(n, 11) end
GU_INDEX_8BIT = GU_INDEX_SHIFT(1)
GU_INDEX_16BIT = GU_INDEX_SHIFT(2)
GU_INDEX_BITS = GU_INDEX_SHIFT(3)

GU_WEIGHTS = function(n) return SHIFT(AND((n - 1), 7), 14) end
GU_WEIGHTS_BITS = GU_WEIGHTS(8)

GU_VERTICES = function(n) return SHIFT(AND((n - 1), 7), 18) end
GU_VERTICES_BITS = GU_VERTICES(8)

GU_TRANSFORM_SHIFT = function(n) return SHIFT(n, 23) end
GU_TRANSFORM_3D = GU_TRANSFORM_SHIFT(0)
GU_TRANSFORM_2D = GU_TRANSFORM_SHIFT(1)
GU_TRANSFORM_BITS = GU_TRANSFORM_SHIFT(1)
-- Vertex Declarations End

-- Pixel Formats
GU_PSM_5650 = 0 -- Display, Texture, Palette
GU_PSM_5551 = 1 -- Display, Texture, Palette
GU_PSM_4444 = 2 -- Display, Texture, Palette
GU_PSM_8888 = 3 -- Display, Texture, Palette
GU_PSM_T4 = 4 -- Texture
GU_PSM_T8 = 5 -- Texture
GU_PSM_T16 = 6 -- Texture
GU_PSM_T32 = 7 -- Texture
GU_PSM_DXT1 = 8 -- Texture
GU_PSM_DXT3 = 9 -- Texture
GU_PSM_DXT5 = 10 -- Texture

-- Spline Mode
GU_FILL_FILL = 0
GU_OPEN_FILL = 1
GU_FILL_OPEN = 2
GU_OPEN_OPEN = 3

-- Shading Model
GU_FLAT = 0
GU_SMOOTH = 1

-- Logical operation
GU_CLEAR = 0
GU_AND = 1
GU_AND_REVERSE = 2
GU_COPY = 3
GU_AND_INVERTED = 4
GU_NOOP = 5
GU_XOR = 6
GU_OR = 7
GU_NOR = 8
GU_EQUIV = 9
GU_INVERTED = 10
GU_OR_REVERSE = 11
GU_COPY_INVERTED = 12
GU_OR_INVERTED = 13
GU_NAND = 14
GU_SET = 15

-- Texture Filter
GU_NEAREST = 0
GU_LINEAR = 1
GU_NEAREST_MIPMAP_NEAREST = 4
GU_LINEAR_MIPMAP_NEAREST = 5
GU_NEAREST_MIPMAP_LINEAR = 6
GU_LINEAR_MIPMAP_LINEAR = 7

-- Texture Map Mode
GU_TEXTURE_COORDS = 0
GU_TEXTURE_MATRIX = 1
GU_ENVIRONMENT_MAP = 2

-- Texture Level Mode
GU_TEXTURE_AUTO = 0
GU_TEXTURE_CONST = 1
GU_TEXTURE_SLOPE = 2

-- Texture Projection Map Mode
GU_POSITION = 0
GU_UV = 1
GU_NORMALIZED_NORMAL = 2
GU_NORMAL = 3

-- Wrap Mode
GU_REPEAT = 0
GU_CLAMP = 1

-- Front Face Direction
GU_CW = 0
GU_CCW = 1

-- Test Function
GU_NEVER = 0
GU_ALWAYS = 1
GU_EQUAL = 2
GU_NOTEQUAL = 3
GU_LESS = 4
GU_LEQUAL = 5
GU_GREATER = 6
GU_GEQUAL = 7

-- Clear Buffer Mask
GU_COLOR_BUFFER_BIT = 1
GU_STENCIL_BUFFER_BIT = 2
GU_DEPTH_BUFFER_BIT = 4
GU_FAST_CLEAR_BIT = 16

-- Texture Effect
GU_TFX_MODULATE = 0
GU_TFX_DECAL = 1
GU_TFX_BLEND = 2
GU_TFX_REPLACE = 3
GU_TFX_ADD = 4

-- Texture Color Component
GU_TCC_RGB = 0
GU_TCC_RGBA = 1

-- Blending Op
GU_ADD = 0
GU_SUBTRACT = 1
GU_REVERSE_SUBTRACT = 2
GU_MIN = 3
GU_MAX = 4
GU_ABS = 5

-- Blending Factor
GU_SRC_COLOR = 0
GU_ONE_MINUS_SRC_COLOR = 1
GU_SRC_ALPHA = 2
GU_ONE_MINUS_SRC_ALPHA = 3
GU_DST_COLOR = 0
GU_ONE_MINUS_DST_COLOR = 1
GU_DST_ALPHA = 4
GU_ONE_MINUS_DST_ALPHA = 5
GU_FIX = 10

-- Stencil Operations
GU_KEEP = 0
GU_ZERO = 1
GU_REPLACE = 2
GU_INVERT = 3
GU_INCR = 4
GU_DECR = 5

-- Light Components
GU_AMBIENT = 1
GU_DIFFUSE = 2
GU_SPECULAR = 4
GU_AMBIENT_AND_DIFFUSE = 3
GU_DIFFUSE_AND_SPECULAR = 6
GU_UNKNOWN_LIGHT_COMPONENT = 8

-- Light modes
GU_SINGLE_COLOR = 0
GU_SEPARATE_SPECULAR_COLOR = 1

-- Light Type
GU_DIRECTIONAL = 0
GU_POINTLIGHT = 1
GU_SPOTLIGHT = 2

-- Contexts
GU_DIRECT = 0
GU_CALL = 1
GU_SEND = 2

-- List Queue
GU_TAIL = 0
GU_HEAD = 1

-- Sync behavior (mode)
GU_SYNC_FINISH = 0
GU_SYNC_SIGNAL = 1
GU_SYNC_DONE = 2
GU_SYNC_LIST = 3
GU_SYNC_SEND = 4

-- behavior (what)
GU_SYNC_WAIT = 0
GU_SYNC_NOWAIT = 1

-- Sync behavior (what) [see pspge.h]
GU_SYNC_WHAT_DONE = 0
GU_SYNC_WHAT_QUEUED = 1
GU_SYNC_WHAT_DRAW = 2
GU_SYNC_WHAT_STALL = 3
GU_SYNC_WHAT_CANCEL = 4

-- Signals
GU_CALLBACK_SIGNAL = 1
GU_CALLBACK_FINISH = 4

-- Signal behavior
GU_BEHAVIOR_SUSPEND = 1
GU_BEHAVIOR_CONTINUE = 2

-- Colour macros omitted because functions have been changed to take individual
-- R, G, B, A components due to Lua limitations