text:
local libphx = require('ffi.libphx').lib

function onDef_Quat (t, mt)
  function t.FromAxisAngle (axis, angle) local out = Quat() libphx.Quat_FromAxisAngle(axis, angle, out) return out end
  function t.FromBasis (x, y, z)         local out = Quat() libphx.Quat_FromBasis(x, y, z, out)         return out end
  function t.Identity ()                 local out = Quat() libphx.Quat_Identity(out)                   return out end
  function t.FromLookUp (look, up)       local out = Quat() libphx.Quat_FromLookUp(look, up, out)       return out end
  function t.FromRotateTo (from, to)     local out = Quat() libphx.Quat_FromRotateTo(from, to, out)     return out end
end

function onDef_Quat_t (t, mt)
  function mt.__mul (a, b)             local out = Quat()  libphx.Quat_Mul(a, b, out)       return out end
  function mt.__index.canonicalize (q) local out = Quat()  libphx.Quat_Canonicalize(q, out) return out end
  function mt.__index.getAxisX (q)     local out = Vec3f() libphx.Quat_GetAxisX(q, out)     return out end
  function mt.__index.getAxisY (q)     local out = Vec3f() libphx.Quat_GetAxisY(q, out)     return out end
  function mt.__index.getAxisZ (q)     local out = Vec3f() libphx.Quat_GetAxisZ(q, out)     return out end
  function mt.__index.getRight (q)     local out = Vec3f() libphx.Quat_GetRight(q, out)     return out end
  function mt.__index.getUp (q)        local out = Vec3f() libphx.Quat_GetUp(q, out)        return out end
  function mt.__index.getForward (q)   local out = Vec3f() libphx.Quat_GetForward(q, out)   return out end
  function mt.__index.inverse (q)      local out = Quat()  libphx.Quat_Inverse(q, out)      return out end
  function mt.__index.lerp (a, b, t)   local out = Quat()  libphx.Quat_Lerp(a, b, y, out)   return out end
  function mt.__index.mul (a, b)       local out = Quat()  libphx.Quat_Mul(a, b, out)       return out end
  function mt.__index.mulV (q, v)      local out = Vec3f() libphx.Quat_MulV(q, v, out)      return out end
  function mt.__index.normalize (q)    local out = Quat()  libphx.Quat_Normalize(q, out)    return out end
  function mt.__index.scale (q, scale) local out = Quat()  libphx.Quat_Scale(q, scale, out) return out end
  function mt.__index.slerp (a, b, t)  local out = Quat()  libphx.Quat_Slerp(a, b, t, out)  return out end
end


text:
local libphx = require('ffi.libphx').lib

function onDef_Tex3D_t (t, mt)
  mt.__index.getSize      = function (self)        local v = Vec3i() libphx.Tex3D_GetSize(self, v)             return v end
  mt.__index.getSizeLevel = function (self, level) local v = Vec3i() libphx.Tex3D_GetSizeLevel(self, v, level) return v end
end

repo_name: JoshParnell/libphx

repo_language: C

mime_type: text/x-c++


text:
local libphx = require('ffi.libphx').lib

function onDef_BSP (t, mt)
  t.Create = function (...)
    local e = libphx.Mesh_Validate(...)
    if e ~= 0 then
      print('BSP Incoming Mesh Error:')
      libphx.Error_Print(e)
    end
    local result = libphx.BSP_Create(...)
    return result
  end
end


text:
local libphx = require('ffi.libphx').lib

local function defineVec4_t (t, mt)
  local Vec4 = t

  function mt.__add (a, b)
    return (Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w))
  end

  function mt.__div (a, b)
    return (Vec4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w))
  end

  function mt.__mul (a, b)
    return (Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w))
  end

  function mt.__pow (a, b)
    return (Vec4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w))
  end

  function mt.__sub (a, b)
    return (Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w))
  end

  function mt.__unm (v)
    return (Vec4(-v.x, -v.y, -v.z, -v.w))
  end

  function mt.__index.iadd (a, b)
    a.x = a.x + b.x
    a.y = a.y + b.y
    a.z = a.z + b.z
    a.w = a.w + b.w
  end

  function mt.__index.idiv (a, b)
    a.x = a.x / b.x
    a.y = a.y / b.y
    a.z = a.z / b.z
    a.w = a.w / b.w
  end

  function mt.__index.idivs (a, s)
    a.x = a.x / s
    a.y = a.y / s
    a.z = a.z / s
    a.w = a.w / s
  end

  function mt.__index.divs (a, s)
    return (Vec4(a.x / s, a.y / s, a.z / s, a.w / s))
  end

  function mt.__index.imadds (a, b, s)
    a.x = a.x + s * b.x
    a.y = a.y + s * b.y
    a.z = a.z + s * b.z
    a.w = a.w + s * b.w
  end

  function mt.__index.imul (a, b)
    a.x = a.x * b.x
    a.y = a.y * b.y
    a.z = a.z * b.z
    a.w = a.w * b.w
  end

  function mt.__index.imuls (a, s)
    a.x = a.x * s
    a.y = a.y * s
    a.z = a.z * s
    a.w = a.w * s
  end

  function mt.__index.muls (a, s)
    return (Vec4(a.x * s, a.y * s, a.z * s, a.w * s))
  end

  function mt.__index.isub (a, b)
    a.x = a.x - b.x
    a.y = a.y - b.y
    a.z = a.z - b.z
    a.w = a.w - b.w
  end

  function mt.__index.abs (v)
    return (Vec4(math.abs(v.x), math.abs(v.y), math.abs(v.z), math.abs(v.w)))
  end

  function mt.__index.clamp (v, lower, upper)
    return (Vec4(
      math.max(lower.x, math.min(upper.x, v.x)),
      math.max(lower.y, math.min(upper.y, v.y)),
      math.max(lower.z, math.min(upper.z, v.z)),
      math.max(lower.w, math.min(upper.w, v.w))))
  end

  function mt.__index.iclampLength (v, clamp)
    local lenSq = v:lengthSquared()
    if lenSq > clamp*clamp then
      v:iscale(clamp / sqrt(lenSq))
    end
  end

  function mt.__index.clampLength (v, clamp)
    local result = v:clone()
    local lenSq = v:lengthSquared()
    if lenSq > clamp*clamp then
      result:iscale(clamp / sqrt(lenSq))
    end
    return result
  end

  function mt.__index.dot (a, b)
    return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w
  end

  function mt.__index.approximatelyEqual (a, b)
    return abs(a.x - b.x) < 1e-3
       and abs(a.y - b.y) < 1e-3
       and abs(a.z - b.z) < 1e-3
       and abs(a.w - b.w) < 1e-3
  end

  function mt.__index.equal (a, b)
    return a.x == b.x
       and a.y == b.y
       and a.z == b.z
       and a.w == b.w
  end

  function mt.__index.isZero (v)
    return v.x == 0 and v.y == 0 and v.z == 0 and v.w == 0
  end

  function mt.__index.length (v)
    return (sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w))
  end

  function mt.__index.lengthSquared (v)
    return v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w
  end

  function mt.__index.ilerp (a, b, t)
    a.x = a.x + (b.x - a.x) * t
    a.y = a.y + (b.y - a.y) * t
    a.z = a.z + (b.z - a.z) * t
    a.w = a.w + (b.w - a.w) * t
  end

  function mt.__index.lerp (a, b, t)
    return (Vec4(
      a.x + (b.x - a.x) * t,
      a.y + (b.y - a.y) * t,
      a.z + (b.z - a.z) * t,
      a.w + (b.w - a.w) * t))
  end

  function mt.__index.normalize (v)
    local l = sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w)
    assert(l > 1e-12, 'Attempting to normalize vector with near-zero length')
    return (Vec4(v.x / l, v.y / l, v.z / l, v.w / l))
  end
end

local function defineVec4i_t (t, mt)
  function mt.__index.toVec4f (v)
    return Vec4f(v.x, v.y, v.z, v.w)
  end

  function mt.__index.toVec4d (v)
    return Vec4d(v.x, v.y, v.z, v.w)
  end

  function mt.__index.toVec2i (v)
    return Vec2i(v.x, v.y)
  end

  function mt.__index.toVec3i (v)
    return Vec3i(v.x, v.y, v.z)
  end

  function mt.__tostring (v)
    return string.format('(%i, %i, %i, %i)', v.x, v.y, v.z, v.w)
  end
end

local function defineVec4f_t (t, mt)
  function mt.__index.toVec4i (v)
    return Vec4i(v.x, v.y, v.z, v.w)
  end

  function mt.__index.toVec4d (v)
    return Vec4d(v.x, v.y, v.z, v.w)
  end

  function mt.__index.toVec2f (v)
    return Vec2f(v.x, v.y)
  end

  function mt.__index.toVec3f (v)
    return Vec3f(v.x, v.y, v.z)
  end

  function mt.__tostring (v)
    return string.format('(%.4f, %.4f, %.4f, %.4f)', v.x, v.y, v.z, v.w)
  end
end

local function defineVec4d_t (t, mt)
  function mt.__index.toVec4i (v)
    return Vec4i(v.x, v.y, v.z, v.w)
  end

  function mt.__index.toVec4f (v)
    return Vec4f(v.x, v.y, v.z, v.w)
  end

  function mt.__index.toVec2d (v)
    return Vec2d(v.x, v.y)
  end

  function mt.__index.toVec3d (v)
    return Vec3d(v.x, v.y, v.z)
  end

  function mt.__tostring (v)
    return string.format('(%.4f, %.4f, %.4f, %.4f)', v.x, v.y, v.z, v.w)
  end
end

onDef_Vec4i_t = function (t, mt) defineVec4_t(t, mt) defineVec4i_t(t, mt) end
onDef_Vec4f_t = function (t, mt) defineVec4_t(t, mt) defineVec4f_t(t, mt) end
onDef_Vec4d_t = function (t, mt) defineVec4_t(t, mt) defineVec4d_t(t, mt) end


text:
-- Ray -------------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Ray

do -- C Definitions
  ffi.cdef [[
    void Ray_GetPoint                      (Ray const*, float t, Vec3f* out);
    bool Ray_IntersectPlane                (Ray const*, Plane const*, Vec3f* pHit);
    bool Ray_IntersectTriangle_Barycentric (Ray const*, Triangle const*, float tEpsilon, float* tHit);
    bool Ray_IntersectTriangle_Moller1     (Ray const*, Triangle const*, float* tHit);
    bool Ray_IntersectTriangle_Moller2     (Ray const*, Triangle const*, float* tHit);
    void Ray_ToLineSegment                 (Ray const*, LineSegment*);
    void Ray_FromLineSegment               (LineSegment const*, Ray*);
  ]]
end

do -- Global Symbol Table
  Ray = {
    GetPoint                      = libphx.Ray_GetPoint,
    IntersectPlane                = libphx.Ray_IntersectPlane,
    IntersectTriangle_Barycentric = libphx.Ray_IntersectTriangle_Barycentric,
    IntersectTriangle_Moller1     = libphx.Ray_IntersectTriangle_Moller1,
    IntersectTriangle_Moller2     = libphx.Ray_IntersectTriangle_Moller2,
    ToLineSegment                 = libphx.Ray_ToLineSegment,
    FromLineSegment               = libphx.Ray_FromLineSegment,
  }

  local mt = {
    __call  = function (t, ...) return Ray_t(...) end,
  }

  if onDef_Ray then onDef_Ray(Ray, mt) end
  Ray = setmetatable(Ray, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Ray')
  local mt = {
    __index = {
      clone                         = function (x) return Ray_t(x) end,
      getPoint                      = libphx.Ray_GetPoint,
      intersectPlane                = libphx.Ray_IntersectPlane,
      intersectTriangle_Barycentric = libphx.Ray_IntersectTriangle_Barycentric,
      intersectTriangle_Moller1     = libphx.Ray_IntersectTriangle_Moller1,
      intersectTriangle_Moller2     = libphx.Ray_IntersectTriangle_Moller2,
      toLineSegment                 = libphx.Ray_ToLineSegment,
    },
  }

  if onDef_Ray_t then onDef_Ray_t(t, mt) end
  Ray_t = ffi.metatype(t, mt)
end

return Ray


text:
-- Octree ----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Octree

do -- C Definitions
  ffi.cdef [[
    Octree* Octree_Create       (Box3f bound);
    Octree* Octree_FromMesh     (Mesh*);
    void    Octree_Free         (Octree*);
    void    Octree_Add          (Octree*, Box3f bound, uint32 id);
    void    Octree_Draw         (Octree*);
    double  Octree_GetAvgLoad   (Octree*);
    int     Octree_GetMaxLoad   (Octree*);
    int     Octree_GetMemory    (Octree*);
    bool    Octree_IntersectRay (Octree*, Matrix*, Vec3f const* ro, Vec3f const* rd);
  ]]
end

do -- Global Symbol Table
  Octree = {
    Create       = libphx.Octree_Create,
    FromMesh     = libphx.Octree_FromMesh,
    Free         = libphx.Octree_Free,
    Add          = libphx.Octree_Add,
    Draw         = libphx.Octree_Draw,
    GetAvgLoad   = libphx.Octree_GetAvgLoad,
    GetMaxLoad   = libphx.Octree_GetMaxLoad,
    GetMemory    = libphx.Octree_GetMemory,
    IntersectRay = libphx.Octree_IntersectRay,
  }

  if onDef_Octree then onDef_Octree(Octree, mt) end
  Octree = setmetatable(Octree, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Octree')
  local mt = {
    __index = {
      managed      = function (self) return ffi.gc(self, libphx.Octree_Free) end,
      free         = libphx.Octree_Free,
      add          = libphx.Octree_Add,
      draw         = libphx.Octree_Draw,
      getAvgLoad   = libphx.Octree_GetAvgLoad,
      getMaxLoad   = libphx.Octree_GetMaxLoad,
      getMemory    = libphx.Octree_GetMemory,
      intersectRay = libphx.Octree_IntersectRay,
    },
  }

  if onDef_Octree_t then onDef_Octree_t(t, mt) end
  Octree_t = ffi.metatype(t, mt)
end

return Octree


text:
-- WindowMode ------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local WindowMode

do -- C Definitions
  ffi.cdef [[
    WindowMode WindowMode_AlwaysOnTop;
    WindowMode WindowMode_Borderless;
    WindowMode WindowMode_Fullscreen;
    WindowMode WindowMode_Hidden;
    WindowMode WindowMode_Maximized;
    WindowMode WindowMode_Minimized;
    WindowMode WindowMode_Resizable;
    WindowMode WindowMode_Shown;
  ]]
end

do -- Global Symbol Table
  WindowMode = {
    AlwaysOnTop = libphx.WindowMode_AlwaysOnTop,
    Borderless  = libphx.WindowMode_Borderless,
    Fullscreen  = libphx.WindowMode_Fullscreen,
    Hidden      = libphx.WindowMode_Hidden,
    Maximized   = libphx.WindowMode_Maximized,
    Minimized   = libphx.WindowMode_Minimized,
    Resizable   = libphx.WindowMode_Resizable,
    Shown       = libphx.WindowMode_Shown,
  }

  if onDef_WindowMode then onDef_WindowMode(WindowMode, mt) end
  WindowMode = setmetatable(WindowMode, mt)
end

return WindowMode


text:
-- ShaderVarType ---------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local ShaderVarType

do -- C Definitions
  ffi.cdef [[
    ShaderVarType ShaderVarType_FromStr     (cstr);
    cstr          ShaderVarType_GetGLSLName (ShaderVarType);
    cstr          ShaderVarType_GetName     (ShaderVarType);
    int           ShaderVarType_GetSize     (ShaderVarType);
  ]]
end

do -- Global Symbol Table
  ShaderVarType = {
    None    = 0x0,
    BEGIN   = 0x1,
    Float   = 0x1,
    Float2  = 0x2,
    Float3  = 0x3,
    Float4  = 0x4,
    Int     = 0x5,
    Int2    = 0x6,
    Int3    = 0x7,
    Int4    = 0x8,
    Matrix  = 0x9,
    Tex1D   = 0xA,
    Tex2D   = 0xB,
    Tex3D   = 0xC,
    TexCube = 0xD,
    END     = 0xD,
    SIZE    = 0xD,
    FromStr     = libphx.ShaderVarType_FromStr,
    GetGLSLName = libphx.ShaderVarType_GetGLSLName,
    GetName     = libphx.ShaderVarType_GetName,
    GetSize     = libphx.ShaderVarType_GetSize,
  }

  if onDef_ShaderVarType then onDef_ShaderVarType(ShaderVarType, mt) end
  ShaderVarType = setmetatable(ShaderVarType, mt)
end

return ShaderVarType


text:
-- Bytes -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Bytes

do -- C Definitions
  ffi.cdef [[
    Bytes* Bytes_Create     (uint32 len);
    Bytes* Bytes_FromData   (void const* data, uint32 len);
    Bytes* Bytes_Load       (cstr path);
    void   Bytes_Free       (Bytes*);
    void*  Bytes_GetData    (Bytes*);
    uint32 Bytes_GetSize    (Bytes*);
    Bytes* Bytes_Compress   (Bytes*);
    Bytes* Bytes_Decompress (Bytes*);
    uint32 Bytes_GetCursor  (Bytes*);
    void   Bytes_Rewind     (Bytes*);
    void   Bytes_SetCursor  (Bytes*, uint32);
    void   Bytes_Read       (Bytes*, void* data, uint32 len);
    uint8  Bytes_ReadU8     (Bytes*);
    uint16 Bytes_ReadU16    (Bytes*);
    uint32 Bytes_ReadU32    (Bytes*);
    uint64 Bytes_ReadU64    (Bytes*);
    int8   Bytes_ReadI8     (Bytes*);
    int16  Bytes_ReadI16    (Bytes*);
    int32  Bytes_ReadI32    (Bytes*);
    int64  Bytes_ReadI64    (Bytes*);
    float  Bytes_ReadF32    (Bytes*);
    double Bytes_ReadF64    (Bytes*);
    void   Bytes_Write      (Bytes*, void const* data, uint32 len);
    void   Bytes_WriteStr   (Bytes*, cstr data);
    void   Bytes_WriteU8    (Bytes*, uint8);
    void   Bytes_WriteU16   (Bytes*, uint16);
    void   Bytes_WriteU32   (Bytes*, uint32);
    void   Bytes_WriteU64   (Bytes*, uint64);
    void   Bytes_WriteI8    (Bytes*, int8);
    void   Bytes_WriteI16   (Bytes*, int16);
    void   Bytes_WriteI32   (Bytes*, int32);
    void   Bytes_WriteI64   (Bytes*, int64);
    void   Bytes_WriteF32   (Bytes*, float);
    void   Bytes_WriteF64   (Bytes*, double);
    void   Bytes_Print      (Bytes*);
    void   Bytes_Save       (Bytes*, cstr path);
  ]]
end

do -- Global Symbol Table
  Bytes = {
    Create     = libphx.Bytes_Create,
    FromData   = libphx.Bytes_FromData,
    Load       = libphx.Bytes_Load,
    Free       = libphx.Bytes_Free,
    GetData    = libphx.Bytes_GetData,
    GetSize    = libphx.Bytes_GetSize,
    Compress   = libphx.Bytes_Compress,
    Decompress = libphx.Bytes_Decompress,
    GetCursor  = libphx.Bytes_GetCursor,
    Rewind     = libphx.Bytes_Rewind,
    SetCursor  = libphx.Bytes_SetCursor,
    Read       = libphx.Bytes_Read,
    ReadU8     = libphx.Bytes_ReadU8,
    ReadU16    = libphx.Bytes_ReadU16,
    ReadU32    = libphx.Bytes_ReadU32,
    ReadU64    = libphx.Bytes_ReadU64,
    ReadI8     = libphx.Bytes_ReadI8,
    ReadI16    = libphx.Bytes_ReadI16,
    ReadI32    = libphx.Bytes_ReadI32,
    ReadI64    = libphx.Bytes_ReadI64,
    ReadF32    = libphx.Bytes_ReadF32,
    ReadF64    = libphx.Bytes_ReadF64,
    Write      = libphx.Bytes_Write,
    WriteStr   = libphx.Bytes_WriteStr,
    WriteU8    = libphx.Bytes_WriteU8,
    WriteU16   = libphx.Bytes_WriteU16,
    WriteU32   = libphx.Bytes_WriteU32,
    WriteU64   = libphx.Bytes_WriteU64,
    WriteI8    = libphx.Bytes_WriteI8,
    WriteI16   = libphx.Bytes_WriteI16,
    WriteI32   = libphx.Bytes_WriteI32,
    WriteI64   = libphx.Bytes_WriteI64,
    WriteF32   = libphx.Bytes_WriteF32,
    WriteF64   = libphx.Bytes_WriteF64,
    Print      = libphx.Bytes_Print,
    Save       = libphx.Bytes_Save,
  }

  if onDef_Bytes then onDef_Bytes(Bytes, mt) end
  Bytes = setmetatable(Bytes, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Bytes')
  local mt = {
    __index = {
      managed    = function (self) return ffi.gc(self, libphx.Bytes_Free) end,
      free       = libphx.Bytes_Free,
      getData    = libphx.Bytes_GetData,
      getSize    = libphx.Bytes_GetSize,
      compress   = libphx.Bytes_Compress,
      decompress = libphx.Bytes_Decompress,
      getCursor  = libphx.Bytes_GetCursor,
      rewind     = libphx.Bytes_Rewind,
      setCursor  = libphx.Bytes_SetCursor,
      read       = libphx.Bytes_Read,
      readU8     = libphx.Bytes_ReadU8,
      readU16    = libphx.Bytes_ReadU16,
      readU32    = libphx.Bytes_ReadU32,
      readU64    = libphx.Bytes_ReadU64,
      readI8     = libphx.Bytes_ReadI8,
      readI16    = libphx.Bytes_ReadI16,
      readI32    = libphx.Bytes_ReadI32,
      readI64    = libphx.Bytes_ReadI64,
      readF32    = libphx.Bytes_ReadF32,
      readF64    = libphx.Bytes_ReadF64,
      write      = libphx.Bytes_Write,
      writeStr   = libphx.Bytes_WriteStr,
      writeU8    = libphx.Bytes_WriteU8,
      writeU16   = libphx.Bytes_WriteU16,
      writeU32   = libphx.Bytes_WriteU32,
      writeU64   = libphx.Bytes_WriteU64,
      writeI8    = libphx.Bytes_WriteI8,
      writeI16   = libphx.Bytes_WriteI16,
      writeI32   = libphx.Bytes_WriteI32,
      writeI64   = libphx.Bytes_WriteI64,
      writeF32   = libphx.Bytes_WriteF32,
      writeF64   = libphx.Bytes_WriteF64,
      print      = libphx.Bytes_Print,
      save       = libphx.Bytes_Save,
    },
  }

  if onDef_Bytes_t then onDef_Bytes_t(t, mt) end
  Bytes_t = ffi.metatype(t, mt)
end

return Bytes


text:
-- TimeStamp -------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local TimeStamp

do -- C Definitions
  ffi.cdef [[
    TimeStamp TimeStamp_Get           ();
    double    TimeStamp_GetDifference (TimeStamp start, TimeStamp end);
    double    TimeStamp_GetElapsed    (TimeStamp start);
    double    TimeStamp_GetElapsedMs  (TimeStamp start);
    TimeStamp TimeStamp_GetFuture     (double seconds);
    TimeStamp TimeStamp_GetRelative   (TimeStamp start, double seconds);
    double    TimeStamp_ToDouble      (TimeStamp);
  ]]
end

do -- Global Symbol Table
  TimeStamp = {
    Get           = libphx.TimeStamp_Get,
    GetDifference = libphx.TimeStamp_GetDifference,
    GetElapsed    = libphx.TimeStamp_GetElapsed,
    GetElapsedMs  = libphx.TimeStamp_GetElapsedMs,
    GetFuture     = libphx.TimeStamp_GetFuture,
    GetRelative   = libphx.TimeStamp_GetRelative,
    ToDouble      = libphx.TimeStamp_ToDouble,
  }

  if onDef_TimeStamp then onDef_TimeStamp(TimeStamp, mt) end
  TimeStamp = setmetatable(TimeStamp, mt)
end

return TimeStamp


text:
-- Vertex ----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Vertex

do -- Global Symbol Table
  Vertex = {
  }

  local mt = {
    __call  = function (t, ...) return Vertex_t(...) end,
  }

  if onDef_Vertex then onDef_Vertex(Vertex, mt) end
  Vertex = setmetatable(Vertex, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Vertex')
  local mt = {
    __index = {
      clone = function (x) return Vertex_t(x) end,
    },
  }

  if onDef_Vertex_t then onDef_Vertex_t(t, mt) end
  Vertex_t = ffi.metatype(t, mt)
end

return Vertex


text:
-- Button ----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Button

do -- C Definitions
  ffi.cdef [[
    DeviceType Button_ToDeviceType         (Button);
    cstr       Button_ToString             (Button);
    Button     Button_Null;
    Button     Button_First;
    Button     Button_Keyboard_First;
    Button     Button_Keyboard_A;
    Button     Button_Keyboard_B;
    Button     Button_Keyboard_C;
    Button     Button_Keyboard_D;
    Button     Button_Keyboard_E;
    Button     Button_Keyboard_F;
    Button     Button_Keyboard_G;
    Button     Button_Keyboard_H;
    Button     Button_Keyboard_I;
    Button     Button_Keyboard_J;
    Button     Button_Keyboard_K;
    Button     Button_Keyboard_L;
    Button     Button_Keyboard_M;
    Button     Button_Keyboard_N;
    Button     Button_Keyboard_O;
    Button     Button_Keyboard_P;
    Button     Button_Keyboard_Q;
    Button     Button_Keyboard_R;
    Button     Button_Keyboard_S;
    Button     Button_Keyboard_T;
    Button     Button_Keyboard_U;
    Button     Button_Keyboard_V;
    Button     Button_Keyboard_W;
    Button     Button_Keyboard_X;
    Button     Button_Keyboard_Y;
    Button     Button_Keyboard_Z;
    Button     Button_Keyboard_N0;
    Button     Button_Keyboard_N1;
    Button     Button_Keyboard_N2;
    Button     Button_Keyboard_N3;
    Button     Button_Keyboard_N4;
    Button     Button_Keyboard_N5;
    Button     Button_Keyboard_N6;
    Button     Button_Keyboard_N7;
    Button     Button_Keyboard_N8;
    Button     Button_Keyboard_N9;
    Button     Button_Keyboard_F1;
    Button     Button_Keyboard_F2;
    Button     Button_Keyboard_F3;
    Button     Button_Keyboard_F4;
    Button     Button_Keyboard_F5;
    Button     Button_Keyboard_F6;
    Button     Button_Keyboard_F7;
    Button     Button_Keyboard_F8;
    Button     Button_Keyboard_F9;
    Button     Button_Keyboard_F10;
    Button     Button_Keyboard_F11;
    Button     Button_Keyboard_F12;
    Button     Button_Keyboard_F13;
    Button     Button_Keyboard_F14;
    Button     Button_Keyboard_F15;
    Button     Button_Keyboard_F16;
    Button     Button_Keyboard_F17;
    Button     Button_Keyboard_F18;
    Button     Button_Keyboard_F19;
    Button     Button_Keyboard_F20;
    Button     Button_Keyboard_F21;
    Button     Button_Keyboard_F22;
    Button     Button_Keyboard_F23;
    Button     Button_Keyboard_F24;
    Button     Button_Keyboard_KP0;
    Button     Button_Keyboard_KP1;
    Button     Button_Keyboard_KP2;
    Button     Button_Keyboard_KP3;
    Button     Button_Keyboard_KP4;
    Button     Button_Keyboard_KP5;
    Button     Button_Keyboard_KP6;
    Button     Button_Keyboard_KP7;
    Button     Button_Keyboard_KP8;
    Button     Button_Keyboard_KP9;
    Button     Button_Keyboard_KPNumLock;
    Button     Button_Keyboard_KPDivide;
    Button     Button_Keyboard_KPMultiply;
    Button     Button_Keyboard_KPSubtract;
    Button     Button_Keyboard_KPAdd;
    Button     Button_Keyboard_KPEnter;
    Button     Button_Keyboard_KPDecimal;
    Button     Button_Keyboard_Backspace;
    Button     Button_Keyboard_Escape;
    Button     Button_Keyboard_Return;
    Button     Button_Keyboard_Space;
    Button     Button_Keyboard_Tab;
    Button     Button_Keyboard_Backtick;
    Button     Button_Keyboard_CapsLock;
    Button     Button_Keyboard_Minus;
    Button     Button_Keyboard_Equals;
    Button     Button_Keyboard_LBracket;
    Button     Button_Keyboard_RBracket;
    Button     Button_Keyboard_Backslash;
    Button     Button_Keyboard_Semicolon;
    Button     Button_Keyboard_Apostrophe;
    Button     Button_Keyboard_Comma;
    Button     Button_Keyboard_Period;
    Button     Button_Keyboard_Slash;
    Button     Button_Keyboard_PrintScreen;
    Button     Button_Keyboard_ScrollLock;
    Button     Button_Keyboard_Pause;
    Button     Button_Keyboard_Insert;
    Button     Button_Keyboard_Delete;
    Button     Button_Keyboard_Home;
    Button     Button_Keyboard_End;
    Button     Button_Keyboard_PageUp;
    Button     Button_Keyboard_PageDown;
    Button     Button_Keyboard_Right;
    Button     Button_Keyboard_Left;
    Button     Button_Keyboard_Down;
    Button     Button_Keyboard_Up;
    Button     Button_Keyboard_LCtrl;
    Button     Button_Keyboard_LShift;
    Button     Button_Keyboard_LAlt;
    Button     Button_Keyboard_LMeta;
    Button     Button_Keyboard_RCtrl;
    Button     Button_Keyboard_RShift;
    Button     Button_Keyboard_RAlt;
    Button     Button_Keyboard_RMeta;
    Button     Button_Keyboard_Last;
    Button     Button_Mouse_First;
    Button     Button_Mouse_Left;
    Button     Button_Mouse_Middle;
    Button     Button_Mouse_Right;
    Button     Button_Mouse_X1;
    Button     Button_Mouse_X2;
    Button     Button_Mouse_X;
    Button     Button_Mouse_Y;
    Button     Button_Mouse_ScrollX;
    Button     Button_Mouse_ScrollY;
    Button     Button_Mouse_Last;
    Button     Button_Gamepad_First;
    Button     Button_Gamepad_Button_First;
    Button     Button_Gamepad_A;
    Button     Button_Gamepad_B;
    Button     Button_Gamepad_X;
    Button     Button_Gamepad_Y;
    Button     Button_Gamepad_Back;
    Button     Button_Gamepad_Guide;
    Button     Button_Gamepad_Start;
    Button     Button_Gamepad_LStick;
    Button     Button_Gamepad_RStick;
    Button     Button_Gamepad_LBumper;
    Button     Button_Gamepad_RBumper;
    Button     Button_Gamepad_Up;
    Button     Button_Gamepad_Down;
    Button     Button_Gamepad_Left;
    Button     Button_Gamepad_Right;
    Button     Button_Gamepad_Button_Last;
    Button     Button_Gamepad_Axis_First;
    Button     Button_Gamepad_LTrigger;
    Button     Button_Gamepad_RTrigger;
    Button     Button_Gamepad_LStickX;
    Button     Button_Gamepad_LStickY;
    Button     Button_Gamepad_RStickX;
    Button     Button_Gamepad_RStickY;
    Button     Button_Gamepad_Axis_Last;
    Button     Button_Gamepad_Last;
    Button     Button_System_First;
    Button     Button_System_Exit;
    Button     Button_System_Last;
    Button     Button_Last;
  ]]
end

do -- Global Symbol Table
  Button = {
    Null  = libphx.Button_Null,
    First = libphx.Button_First,
    Last  = libphx.Button_Last,
    Keyboard = {
      First       = libphx.Button_Keyboard_First,
      A           = libphx.Button_Keyboard_A,
      B           = libphx.Button_Keyboard_B,
      C           = libphx.Button_Keyboard_C,
      D           = libphx.Button_Keyboard_D,
      E           = libphx.Button_Keyboard_E,
      F           = libphx.Button_Keyboard_F,
      G           = libphx.Button_Keyboard_G,
      H           = libphx.Button_Keyboard_H,
      I           = libphx.Button_Keyboard_I,
      J           = libphx.Button_Keyboard_J,
      K           = libphx.Button_Keyboard_K,
      L           = libphx.Button_Keyboard_L,
      M           = libphx.Button_Keyboard_M,
      N           = libphx.Button_Keyboard_N,
      O           = libphx.Button_Keyboard_O,
      P           = libphx.Button_Keyboard_P,
      Q           = libphx.Button_Keyboard_Q,
      R           = libphx.Button_Keyboard_R,
      S           = libphx.Button_Keyboard_S,
      T           = libphx.Button_Keyboard_T,
      U           = libphx.Button_Keyboard_U,
      V           = libphx.Button_Keyboard_V,
      W           = libphx.Button_Keyboard_W,
      X           = libphx.Button_Keyboard_X,
      Y           = libphx.Button_Keyboard_Y,
      Z           = libphx.Button_Keyboard_Z,
      N0          = libphx.Button_Keyboard_N0,
      N1          = libphx.Button_Keyboard_N1,
      N2          = libphx.Button_Keyboard_N2,
      N3          = libphx.Button_Keyboard_N3,
      N4          = libphx.Button_Keyboard_N4,
      N5          = libphx.Button_Keyboard_N5,
      N6          = libphx.Button_Keyboard_N6,
      N7          = libphx.Button_Keyboard_N7,
      N8          = libphx.Button_Keyboard_N8,
      N9          = libphx.Button_Keyboard_N9,
      F1          = libphx.Button_Keyboard_F1,
      F2          = libphx.Button_Keyboard_F2,
      F3          = libphx.Button_Keyboard_F3,
      F4          = libphx.Button_Keyboard_F4,
      F5          = libphx.Button_Keyboard_F5,
      F6          = libphx.Button_Keyboard_F6,
      F7          = libphx.Button_Keyboard_F7,
      F8          = libphx.Button_Keyboard_F8,
      F9          = libphx.Button_Keyboard_F9,
      F10         = libphx.Button_Keyboard_F10,
      F11         = libphx.Button_Keyboard_F11,
      F12         = libphx.Button_Keyboard_F12,
      F13         = libphx.Button_Keyboard_F13,
      F14         = libphx.Button_Keyboard_F14,
      F15         = libphx.Button_Keyboard_F15,
      F16         = libphx.Button_Keyboard_F16,
      F17         = libphx.Button_Keyboard_F17,
      F18         = libphx.Button_Keyboard_F18,
      F19         = libphx.Button_Keyboard_F19,
      F20         = libphx.Button_Keyboard_F20,
      F21         = libphx.Button_Keyboard_F21,
      F22         = libphx.Button_Keyboard_F22,
      F23         = libphx.Button_Keyboard_F23,
      F24         = libphx.Button_Keyboard_F24,
      KP0         = libphx.Button_Keyboard_KP0,
      KP1         = libphx.Button_Keyboard_KP1,
      KP2         = libphx.Button_Keyboard_KP2,
      KP3         = libphx.Button_Keyboard_KP3,
      KP4         = libphx.Button_Keyboard_KP4,
      KP5         = libphx.Button_Keyboard_KP5,
      KP6         = libphx.Button_Keyboard_KP6,
      KP7         = libphx.Button_Keyboard_KP7,
      KP8         = libphx.Button_Keyboard_KP8,
      KP9         = libphx.Button_Keyboard_KP9,
      KPNumLock   = libphx.Button_Keyboard_KPNumLock,
      KPDivide    = libphx.Button_Keyboard_KPDivide,
      KPMultiply  = libphx.Button_Keyboard_KPMultiply,
      KPSubtract  = libphx.Button_Keyboard_KPSubtract,
      KPAdd       = libphx.Button_Keyboard_KPAdd,
      KPEnter     = libphx.Button_Keyboard_KPEnter,
      KPDecimal   = libphx.Button_Keyboard_KPDecimal,
      Backspace   = libphx.Button_Keyboard_Backspace,
      Escape      = libphx.Button_Keyboard_Escape,
      Return      = libphx.Button_Keyboard_Return,
      Space       = libphx.Button_Keyboard_Space,
      Tab         = libphx.Button_Keyboard_Tab,
      Backtick    = libphx.Button_Keyboard_Backtick,
      CapsLock    = libphx.Button_Keyboard_CapsLock,
      Minus       = libphx.Button_Keyboard_Minus,
      Equals      = libphx.Button_Keyboard_Equals,
      LBracket    = libphx.Button_Keyboard_LBracket,
      RBracket    = libphx.Button_Keyboard_RBracket,
      Backslash   = libphx.Button_Keyboard_Backslash,
      Semicolon   = libphx.Button_Keyboard_Semicolon,
      Apostrophe  = libphx.Button_Keyboard_Apostrophe,
      Comma       = libphx.Button_Keyboard_Comma,
      Period      = libphx.Button_Keyboard_Period,
      Slash       = libphx.Button_Keyboard_Slash,
      PrintScreen = libphx.Button_Keyboard_PrintScreen,
      ScrollLock  = libphx.Button_Keyboard_ScrollLock,
      Pause       = libphx.Button_Keyboard_Pause,
      Insert      = libphx.Button_Keyboard_Insert,
      Delete      = libphx.Button_Keyboard_Delete,
      Home        = libphx.Button_Keyboard_Home,
      End         = libphx.Button_Keyboard_End,
      PageUp      = libphx.Button_Keyboard_PageUp,
      PageDown    = libphx.Button_Keyboard_PageDown,
      Right       = libphx.Button_Keyboard_Right,
      Left        = libphx.Button_Keyboard_Left,
      Down        = libphx.Button_Keyboard_Down,
      Up          = libphx.Button_Keyboard_Up,
      LCtrl       = libphx.Button_Keyboard_LCtrl,
      LShift      = libphx.Button_Keyboard_LShift,
      LAlt        = libphx.Button_Keyboard_LAlt,
      LMeta       = libphx.Button_Keyboard_LMeta,
      RCtrl       = libphx.Button_Keyboard_RCtrl,
      RShift      = libphx.Button_Keyboard_RShift,
      RAlt        = libphx.Button_Keyboard_RAlt,
      RMeta       = libphx.Button_Keyboard_RMeta,
      Last        = libphx.Button_Keyboard_Last,
    },
    Mouse = {
      First   = libphx.Button_Mouse_First,
      Left    = libphx.Button_Mouse_Left,
      Middle  = libphx.Button_Mouse_Middle,
      Right   = libphx.Button_Mouse_Right,
      X1      = libphx.Button_Mouse_X1,
      X2      = libphx.Button_Mouse_X2,
      X       = libphx.Button_Mouse_X,
      Y       = libphx.Button_Mouse_Y,
      ScrollX = libphx.Button_Mouse_ScrollX,
      ScrollY = libphx.Button_Mouse_ScrollY,
      Last    = libphx.Button_Mouse_Last,
    },
    Gamepad = {
      First        = libphx.Button_Gamepad_First,
      Button_First = libphx.Button_Gamepad_Button_First,
      A            = libphx.Button_Gamepad_A,
      B            = libphx.Button_Gamepad_B,
      X            = libphx.Button_Gamepad_X,
      Y            = libphx.Button_Gamepad_Y,
      Back         = libphx.Button_Gamepad_Back,
      Guide        = libphx.Button_Gamepad_Guide,
      Start        = libphx.Button_Gamepad_Start,
      LStick       = libphx.Button_Gamepad_LStick,
      RStick       = libphx.Button_Gamepad_RStick,
      LBumper      = libphx.Button_Gamepad_LBumper,
      RBumper      = libphx.Button_Gamepad_RBumper,
      Up           = libphx.Button_Gamepad_Up,
      Down         = libphx.Button_Gamepad_Down,
      Left         = libphx.Button_Gamepad_Left,
      Right        = libphx.Button_Gamepad_Right,
      Button_Last  = libphx.Button_Gamepad_Button_Last,
      Axis_First   = libphx.Button_Gamepad_Axis_First,
      LTrigger     = libphx.Button_Gamepad_LTrigger,
      RTrigger     = libphx.Button_Gamepad_RTrigger,
      LStickX      = libphx.Button_Gamepad_LStickX,
      LStickY      = libphx.Button_Gamepad_LStickY,
      RStickX      = libphx.Button_Gamepad_RStickX,
      RStickY      = libphx.Button_Gamepad_RStickY,
      Axis_Last    = libphx.Button_Gamepad_Axis_Last,
      Last         = libphx.Button_Gamepad_Last,
    },
    System = {
      First = libphx.Button_System_First,
      Exit  = libphx.Button_System_Exit,
      Last  = libphx.Button_System_Last,
    },
    ToDeviceType = libphx.Button_ToDeviceType,
    ToString     = libphx.Button_ToString,
  }

  if onDef_Button then onDef_Button(Button, mt) end
  Button = setmetatable(Button, mt)
end

return Button


text:
-- Triangle --------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Triangle

do -- C Definitions
  ffi.cdef [[
    void  Triangle_ToPlane     (Triangle const*, Plane*);
    void  Triangle_ToPlaneFast (Triangle const*, Plane*);
    float Triangle_GetArea     (Triangle const*);
    Error Triangle_Validate    (Triangle const*);
  ]]
end

do -- Global Symbol Table
  Triangle = {
    ToPlane     = libphx.Triangle_ToPlane,
    ToPlaneFast = libphx.Triangle_ToPlaneFast,
    GetArea     = libphx.Triangle_GetArea,
    Validate    = libphx.Triangle_Validate,
  }

  local mt = {
    __call  = function (t, ...) return Triangle_t(...) end,
  }

  if onDef_Triangle then onDef_Triangle(Triangle, mt) end
  Triangle = setmetatable(Triangle, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Triangle')
  local mt = {
    __index = {
      clone       = function (x) return Triangle_t(x) end,
      toPlane     = libphx.Triangle_ToPlane,
      toPlaneFast = libphx.Triangle_ToPlaneFast,
      getArea     = libphx.Triangle_GetArea,
      validate    = libphx.Triangle_Validate,
    },
  }

  if onDef_Triangle_t then onDef_Triangle_t(t, mt) end
  Triangle_t = ffi.metatype(t, mt)
end

return Triangle


text:
-- Profiler --------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Profiler

do -- C Definitions
  ffi.cdef [[
    void Profiler_Enable     ();
    void Profiler_Disable    ();
    void Profiler_Begin      (cstr);
    void Profiler_End        ();
    void Profiler_SetValue   (cstr, int);
    void Profiler_LoopMarker ();
    void Profiler_Backtrace  ();
  ]]
end

do -- Global Symbol Table
  Profiler = {
    Enable     = libphx.Profiler_Enable,
    Disable    = libphx.Profiler_Disable,
    Begin      = libphx.Profiler_Begin,
    End        = libphx.Profiler_End,
    SetValue   = libphx.Profiler_SetValue,
    LoopMarker = libphx.Profiler_LoopMarker,
    Backtrace  = libphx.Profiler_Backtrace,
  }

  if onDef_Profiler then onDef_Profiler(Profiler, mt) end
  Profiler = setmetatable(Profiler, mt)
end

return Profiler


text:
-- TexFilter -------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local TexFilter

do -- C Definitions
  ffi.cdef [[
    TexFilter TexFilter_Point;
    TexFilter TexFilter_PointMipPoint;
    TexFilter TexFilter_PointMipLinear;
    TexFilter TexFilter_Linear;
    TexFilter TexFilter_LinearMipPoint;
    TexFilter TexFilter_LinearMipLinear;
  ]]
end

do -- Global Symbol Table
  TexFilter = {
    Point           = libphx.TexFilter_Point,
    PointMipPoint   = libphx.TexFilter_PointMipPoint,
    PointMipLinear  = libphx.TexFilter_PointMipLinear,
    Linear          = libphx.TexFilter_Linear,
    LinearMipPoint  = libphx.TexFilter_LinearMipPoint,
    LinearMipLinear = libphx.TexFilter_LinearMipLinear,
  }

  if onDef_TexFilter then onDef_TexFilter(TexFilter, mt) end
  TexFilter = setmetatable(TexFilter, mt)
end

return TexFilter


text:
-- Thread ----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Thread

do -- C Definitions
  ffi.cdef [[
    Thread* Thread_Create (cstr name, ThreadFn, void* data);
    void    Thread_Detach (Thread*);
    void    Thread_Sleep  (uint ms);
    int     Thread_Wait   (Thread*);
  ]]
end

do -- Global Symbol Table
  Thread = {
    Create = libphx.Thread_Create,
    Detach = libphx.Thread_Detach,
    Sleep  = libphx.Thread_Sleep,
    Wait   = libphx.Thread_Wait,
  }

  if onDef_Thread then onDef_Thread(Thread, mt) end
  Thread = setmetatable(Thread, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Thread')
  local mt = {
    __index = {
      detach = libphx.Thread_Detach,
      wait   = libphx.Thread_Wait,
    },
  }

  if onDef_Thread_t then onDef_Thread_t(t, mt) end
  Thread_t = ffi.metatype(t, mt)
end

return Thread


text:
-- RenderTarget ----------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local RenderTarget

do -- C Definitions
  ffi.cdef [[
    void RenderTarget_Push             (int sx, int sy);
    void RenderTarget_Pop              ();
    void RenderTarget_BindTex2D        (Tex2D*);
    void RenderTarget_BindTex2DLevel   (Tex2D*, int level);
    void RenderTarget_BindTex3D        (Tex3D*, int layer);
    void RenderTarget_BindTex3DLevel   (Tex3D*, int layer, int level);
    void RenderTarget_BindTexCube      (TexCube*, CubeFace);
    void RenderTarget_BindTexCubeLevel (TexCube*, CubeFace, int level);
    void RenderTarget_PushTex2D        (Tex2D*);
    void RenderTarget_PushTex2DLevel   (Tex2D*, int level);
    void RenderTarget_PushTex3D        (Tex3D*, int layer);
    void RenderTarget_PushTex3DLevel   (Tex3D*, int layer, int level);
  ]]
end

do -- Global Symbol Table
  RenderTarget = {
    Push             = libphx.RenderTarget_Push,
    Pop              = libphx.RenderTarget_Pop,
    BindTex2D        = libphx.RenderTarget_BindTex2D,
    BindTex2DLevel   = libphx.RenderTarget_BindTex2DLevel,
    BindTex3D        = libphx.RenderTarget_BindTex3D,
    BindTex3DLevel   = libphx.RenderTarget_BindTex3DLevel,
    BindTexCube      = libphx.RenderTarget_BindTexCube,
    BindTexCubeLevel = libphx.RenderTarget_BindTexCubeLevel,
    PushTex2D        = libphx.RenderTarget_PushTex2D,
    PushTex2DLevel   = libphx.RenderTarget_PushTex2DLevel,
    PushTex3D        = libphx.RenderTarget_PushTex3D,
    PushTex3DLevel   = libphx.RenderTarget_PushTex3DLevel,
  }

  if onDef_RenderTarget then onDef_RenderTarget(RenderTarget, mt) end
  RenderTarget = setmetatable(RenderTarget, mt)
end

return RenderTarget


text:
-- ThreadPool ------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local ThreadPool

do -- C Definitions
  ffi.cdef [[
    ThreadPool* ThreadPool_Create (int threads);
    void        ThreadPool_Free   (ThreadPool*);
    void        ThreadPool_Launch (ThreadPool*, ThreadPoolFn, void* data);
    void        ThreadPool_Wait   (ThreadPool*);
  ]]
end

do -- Global Symbol Table
  ThreadPool = {
    Create = libphx.ThreadPool_Create,
    Free   = libphx.ThreadPool_Free,
    Launch = libphx.ThreadPool_Launch,
    Wait   = libphx.ThreadPool_Wait,
  }

  if onDef_ThreadPool then onDef_ThreadPool(ThreadPool, mt) end
  ThreadPool = setmetatable(ThreadPool, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('ThreadPool')
  local mt = {
    __index = {
      managed = function (self) return ffi.gc(self, libphx.ThreadPool_Free) end,
      free   = libphx.ThreadPool_Free,
      launch = libphx.ThreadPool_Launch,
      wait   = libphx.ThreadPool_Wait,
    },
  }

  if onDef_ThreadPool_t then onDef_ThreadPool_t(t, mt) end
  ThreadPool_t = ffi.metatype(t, mt)
end

return ThreadPool


text:
-- Shader ----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Shader

do -- C Definitions
  ffi.cdef [[
    Shader*      Shader_Create        (cstr vertCode, cstr fragCode);
    Shader*      Shader_Load          (cstr vertName, cstr fragName);
    void         Shader_Acquire       (Shader*);
    void         Shader_Free          (Shader*);
    ShaderState* Shader_ToShaderState (Shader*);
    void         Shader_Start         (Shader*);
    void         Shader_Stop          (Shader*);
    uint         Shader_GetHandle     (Shader*);
    int          Shader_GetVariable   (Shader*, cstr);
    bool         Shader_HasVariable   (Shader*, cstr);
    void         Shader_ClearCache    ();
    void         Shader_SetFloat      (cstr, float);
    void         Shader_SetFloat2     (cstr, float, float);
    void         Shader_SetFloat3     (cstr, float, float, float);
    void         Shader_SetFloat4     (cstr, float, float, float, float);
    void         Shader_SetInt        (cstr, int);
    void         Shader_SetMatrix     (cstr, Matrix*);
    void         Shader_SetMatrixT    (cstr, Matrix*);
    void         Shader_SetTex1D      (cstr, Tex1D*);
    void         Shader_SetTex2D      (cstr, Tex2D*);
    void         Shader_SetTex3D      (cstr, Tex3D*);
    void         Shader_SetTexCube    (cstr, TexCube*);
    void         Shader_ISetFloat     (int, float);
    void         Shader_ISetFloat2    (int, float, float);
    void         Shader_ISetFloat3    (int, float, float, float);
    void         Shader_ISetFloat4    (int, float, float, float, float);
    void         Shader_ISetInt       (int, int);
    void         Shader_ISetMatrix    (int, Matrix*);
    void         Shader_ISetMatrixT   (int, Matrix*);
    void         Shader_ISetTex1D     (int, Tex1D*);
    void         Shader_ISetTex2D     (int, Tex2D*);
    void         Shader_ISetTex3D     (int, Tex3D*);
    void         Shader_ISetTexCube   (int, TexCube*);
  ]]
end

do -- Global Symbol Table
  Shader = {
    Create        = libphx.Shader_Create,
    Load          = libphx.Shader_Load,
    Acquire       = libphx.Shader_Acquire,
    Free          = libphx.Shader_Free,
    ToShaderState = libphx.Shader_ToShaderState,
    Start         = libphx.Shader_Start,
    Stop          = libphx.Shader_Stop,
    GetHandle     = libphx.Shader_GetHandle,
    GetVariable   = libphx.Shader_GetVariable,
    HasVariable   = libphx.Shader_HasVariable,
    ClearCache    = libphx.Shader_ClearCache,
    SetFloat      = libphx.Shader_SetFloat,
    SetFloat2     = libphx.Shader_SetFloat2,
    SetFloat3     = libphx.Shader_SetFloat3,
    SetFloat4     = libphx.Shader_SetFloat4,
    SetInt        = libphx.Shader_SetInt,
    SetMatrix     = libphx.Shader_SetMatrix,
    SetMatrixT    = libphx.Shader_SetMatrixT,
    SetTex1D      = libphx.Shader_SetTex1D,
    SetTex2D      = libphx.Shader_SetTex2D,
    SetTex3D      = libphx.Shader_SetTex3D,
    SetTexCube    = libphx.Shader_SetTexCube,
    ISetFloat     = libphx.Shader_ISetFloat,
    ISetFloat2    = libphx.Shader_ISetFloat2,
    ISetFloat3    = libphx.Shader_ISetFloat3,
    ISetFloat4    = libphx.Shader_ISetFloat4,
    ISetInt       = libphx.Shader_ISetInt,
    ISetMatrix    = libphx.Shader_ISetMatrix,
    ISetMatrixT   = libphx.Shader_ISetMatrixT,
    ISetTex1D     = libphx.Shader_ISetTex1D,
    ISetTex2D     = libphx.Shader_ISetTex2D,
    ISetTex3D     = libphx.Shader_ISetTex3D,
    ISetTexCube   = libphx.Shader_ISetTexCube,
  }

  if onDef_Shader then onDef_Shader(Shader, mt) end
  Shader = setmetatable(Shader, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Shader')
  local mt = {
    __index = {
      managed       = function (self) return ffi.gc(self, libphx.Shader_Free) end,
      acquire       = libphx.Shader_Acquire,
      free          = libphx.Shader_Free,
      toShaderState = libphx.Shader_ToShaderState,
      start         = libphx.Shader_Start,
      stop          = libphx.Shader_Stop,
      getHandle     = libphx.Shader_GetHandle,
      getVariable   = libphx.Shader_GetVariable,
      hasVariable   = libphx.Shader_HasVariable,
    },
  }

  if onDef_Shader_t then onDef_Shader_t(t, mt) end
  Shader_t = ffi.metatype(t, mt)
end

return Shader


text:
-- File ------------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local File

do -- C Definitions
  ffi.cdef [[
    File*  File_Create    (cstr path);
    File*  File_Open      (cstr path);
    void   File_Close     (File*);
    bool   File_Exists    (cstr path);
    bool   File_IsDir     (cstr path);
    Bytes* File_ReadBytes (cstr path);
    cstr   File_ReadCstr  (cstr path);
    int64  File_Size      (cstr path);
    void   File_Read      (File*, void* data, uint32 len);
    uint8  File_ReadU8    (File*);
    uint16 File_ReadU16   (File*);
    uint32 File_ReadU32   (File*);
    uint64 File_ReadU64   (File*);
    int8   File_ReadI8    (File*);
    int16  File_ReadI16   (File*);
    int32  File_ReadI32   (File*);
    int64  File_ReadI64   (File*);
    float  File_ReadF32   (File*);
    double File_ReadF64   (File*);
    void   File_Write     (File*, void const* data, uint32 len);
    void   File_WriteStr  (File*, cstr);
    void   File_WriteU8   (File*, uint8);
    void   File_WriteU16  (File*, uint16);
    void   File_WriteU32  (File*, uint32);
    void   File_WriteU64  (File*, uint64);
    void   File_WriteI8   (File*, int8);
    void   File_WriteI16  (File*, int16);
    void   File_WriteI32  (File*, int32);
    void   File_WriteI64  (File*, int64);
    void   File_WriteF32  (File*, float);
    void   File_WriteF64  (File*, double);
  ]]
end

do -- Global Symbol Table
  File = {
    Create    = libphx.File_Create,
    Open      = libphx.File_Open,
    Close     = libphx.File_Close,
    Exists    = libphx.File_Exists,
    IsDir     = libphx.File_IsDir,
    ReadBytes = libphx.File_ReadBytes,
    ReadCstr  = libphx.File_ReadCstr,
    Size      = libphx.File_Size,
    Read      = libphx.File_Read,
    ReadU8    = libphx.File_ReadU8,
    ReadU16   = libphx.File_ReadU16,
    ReadU32   = libphx.File_ReadU32,
    ReadU64   = libphx.File_ReadU64,
    ReadI8    = libphx.File_ReadI8,
    ReadI16   = libphx.File_ReadI16,
    ReadI32   = libphx.File_ReadI32,
    ReadI64   = libphx.File_ReadI64,
    ReadF32   = libphx.File_ReadF32,
    ReadF64   = libphx.File_ReadF64,
    Write     = libphx.File_Write,
    WriteStr  = libphx.File_WriteStr,
    WriteU8   = libphx.File_WriteU8,
    WriteU16  = libphx.File_WriteU16,
    WriteU32  = libphx.File_WriteU32,
    WriteU64  = libphx.File_WriteU64,
    WriteI8   = libphx.File_WriteI8,
    WriteI16  = libphx.File_WriteI16,
    WriteI32  = libphx.File_WriteI32,
    WriteI64  = libphx.File_WriteI64,
    WriteF32  = libphx.File_WriteF32,
    WriteF64  = libphx.File_WriteF64,
  }

  if onDef_File then onDef_File(File, mt) end
  File = setmetatable(File, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('File')
  local mt = {
    __index = {
      close     = libphx.File_Close,
      read      = libphx.File_Read,
      readU8    = libphx.File_ReadU8,
      readU16   = libphx.File_ReadU16,
      readU32   = libphx.File_ReadU32,
      readU64   = libphx.File_ReadU64,
      readI8    = libphx.File_ReadI8,
      readI16   = libphx.File_ReadI16,
      readI32   = libphx.File_ReadI32,
      readI64   = libphx.File_ReadI64,
      readF32   = libphx.File_ReadF32,
      readF64   = libphx.File_ReadF64,
      write     = libphx.File_Write,
      writeStr  = libphx.File_WriteStr,
      writeU8   = libphx.File_WriteU8,
      writeU16  = libphx.File_WriteU16,
      writeU32  = libphx.File_WriteU32,
      writeU64  = libphx.File_WriteU64,
      writeI8   = libphx.File_WriteI8,
      writeI16  = libphx.File_WriteI16,
      writeI32  = libphx.File_WriteI32,
      writeI64  = libphx.File_WriteI64,
      writeF32  = libphx.File_WriteF32,
      writeF64  = libphx.File_WriteF64,
    },
  }

  if onDef_File_t then onDef_File_t(t, mt) end
  File_t = ffi.metatype(t, mt)
end

return File


text:
-- WindowPos -------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local WindowPos

do -- C Definitions
  ffi.cdef [[
    WindowPos WindowPos_Centered;
    WindowPos WindowPos_Default;
  ]]
end

do -- Global Symbol Table
  WindowPos = {
    Centered = libphx.WindowPos_Centered,
    Default  = libphx.WindowPos_Default,
  }

  if onDef_WindowPos then onDef_WindowPos(WindowPos, mt) end
  WindowPos = setmetatable(WindowPos, mt)
end

return WindowPos


text:
-- Math ------------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Math

do -- C Definitions
  ffi.cdef [[
    double Math_Bezier3       (double x, double, double, double);
    double Math_Bezier4       (double x, double, double, double, double);
    double Math_Clamp         (double x, double a, double b);
    double Math_Clamp01       (double x);
    double Math_ClampSafe     (double x, double a, double b);
    double Math_ClampUnit     (double x);
    double Math_ExpMap        (double x, double p);
    double Math_ExpMapSigned  (double x, double p);
    double Math_ExpMap1       (double x);
    double Math_ExpMap1Signed (double x);
    double Math_ExpMap2       (double x);
    double Math_ExpMap2Signed (double x);
    double Math_PowSigned     (double x, double p);
    double Math_Round         (double x);
    double Math_Sign          (double x);
  ]]
end

do -- Global Symbol Table
  Math = {
    Bezier3       = libphx.Math_Bezier3,
    Bezier4       = libphx.Math_Bezier4,
    Clamp         = libphx.Math_Clamp,
    Clamp01       = libphx.Math_Clamp01,
    ClampSafe     = libphx.Math_ClampSafe,
    ClampUnit     = libphx.Math_ClampUnit,
    ExpMap        = libphx.Math_ExpMap,
    ExpMapSigned  = libphx.Math_ExpMapSigned,
    ExpMap1       = libphx.Math_ExpMap1,
    ExpMap1Signed = libphx.Math_ExpMap1Signed,
    ExpMap2       = libphx.Math_ExpMap2,
    ExpMap2Signed = libphx.Math_ExpMap2Signed,
    PowSigned     = libphx.Math_PowSigned,
    Round         = libphx.Math_Round,
    Sign          = libphx.Math_Sign,
  }

  if onDef_Math then onDef_Math(Math, mt) end
  Math = setmetatable(Math, mt)
end

return Math


text:
-- Vec3i -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Vec3i

do -- Global Symbol Table
  Vec3i = {
  }

  local mt = {
    __call  = function (t, ...) return Vec3i_t(...) end,
  }

  if onDef_Vec3i then onDef_Vec3i(Vec3i, mt) end
  Vec3i = setmetatable(Vec3i, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Vec3i')
  local mt = {
    __index = {
      clone = function (x) return Vec3i_t(x) end,
    },
  }

  if onDef_Vec3i_t then onDef_Vec3i_t(t, mt) end
  Vec3i_t = ffi.metatype(t, mt)
end

return Vec3i


text:
-- Plane -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Plane

do -- C Definitions
  ffi.cdef [[
    PointClassification   Plane_ClassifyPoint   (Plane*, Vec3f*);
    PolygonClassification Plane_ClassifyPolygon (Plane*, Polygon*);
    Error                 Plane_Validate        (Plane*);
    void                  Plane_FromPolygon     (Polygon*, Plane*);
    void                  Plane_FromPolygonFast (Polygon*, Plane*);
  ]]
end

do -- Global Symbol Table
  Plane = {
    ClassifyPoint   = libphx.Plane_ClassifyPoint,
    ClassifyPolygon = libphx.Plane_ClassifyPolygon,
    Validate        = libphx.Plane_Validate,
    FromPolygon     = libphx.Plane_FromPolygon,
    FromPolygonFast = libphx.Plane_FromPolygonFast,
  }

  local mt = {
    __call  = function (t, ...) return Plane_t(...) end,
  }

  if onDef_Plane then onDef_Plane(Plane, mt) end
  Plane = setmetatable(Plane, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Plane')
  local mt = {
    __index = {
      clone           = function (x) return Plane_t(x) end,
      classifyPoint   = libphx.Plane_ClassifyPoint,
      classifyPolygon = libphx.Plane_ClassifyPolygon,
      validate        = libphx.Plane_Validate,
    },
  }

  if onDef_Plane_t then onDef_Plane_t(t, mt) end
  Plane_t = ffi.metatype(t, mt)
end

return Plane


text:
-- BSPNodeRef ------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local BSPNodeRef

do -- Global Symbol Table
  BSPNodeRef = {
  }

  local mt = {
    __call  = function (t, ...) return BSPNodeRef_t(...) end,
  }

  if onDef_BSPNodeRef then onDef_BSPNodeRef(BSPNodeRef, mt) end
  BSPNodeRef = setmetatable(BSPNodeRef, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('BSPNodeRef')
  local mt = {
    __index = {
      clone = function (x) return BSPNodeRef_t(x) end,
    },
  }

  if onDef_BSPNodeRef_t then onDef_BSPNodeRef_t(t, mt) end
  BSPNodeRef_t = ffi.metatype(t, mt)
end

return BSPNodeRef


text:
-- KDTree ----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local KDTree

do -- C Definitions
  ffi.cdef [[
    KDTree* KDTree_FromMesh     (Mesh*);
    void    KDTree_Free         (KDTree*);
    void    KDTree_Draw         (KDTree*, int maxDepth);
    int     KDTree_GetMemory    (KDTree*);
    bool    KDTree_IntersectRay (KDTree*, Matrix*, Vec3f const* ro, Vec3f const* rd);
  ]]
end

do -- Global Symbol Table
  KDTree = {
    FromMesh     = libphx.KDTree_FromMesh,
    Free         = libphx.KDTree_Free,
    Draw         = libphx.KDTree_Draw,
    GetMemory    = libphx.KDTree_GetMemory,
    IntersectRay = libphx.KDTree_IntersectRay,
  }

  if onDef_KDTree then onDef_KDTree(KDTree, mt) end
  KDTree = setmetatable(KDTree, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('KDTree')
  local mt = {
    __index = {
      managed      = function (self) return ffi.gc(self, libphx.KDTree_Free) end,
      free         = libphx.KDTree_Free,
      draw         = libphx.KDTree_Draw,
      getMemory    = libphx.KDTree_GetMemory,
      intersectRay = libphx.KDTree_IntersectRay,
    },
  }

  if onDef_KDTree_t then onDef_KDTree_t(t, mt) end
  KDTree_t = ffi.metatype(t, mt)
end

return KDTree


text:
-- BSPDebug --------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local BSPDebug

do -- C Definitions
  ffi.cdef [[
    BSPNodeRef BSPDebug_GetNode                     (BSP*, BSPNodeRef, BSPNodeRel);
    void       BSPDebug_DrawNode                    (BSP*, BSPNodeRef);
    void       BSPDebug_DrawNodeSplit               (BSP*, BSPNodeRef);
    void       BSPDebug_DrawLineSegment             (BSP*, LineSegment*);
    void       BSPDebug_DrawSphere                  (BSP*, Sphere*);
    void       BSPDebug_PrintRayProfilingData       (BSP*, double totalTime);
    void       BSPDebug_PrintSphereProfilingData    (BSP*, double totalTime);
    bool       BSPDebug_GetIntersectSphereTriangles (BSP*, Sphere*, IntersectSphereProfiling* sphereProf);
    BSPNodeRef BSPDebug_GetLeaf                     (BSP*, int32 leafIndex);
  ]]
end

do -- Global Symbol Table
  BSPDebug = {
    GetNode                     = libphx.BSPDebug_GetNode,
    DrawNode                    = libphx.BSPDebug_DrawNode,
    DrawNodeSplit               = libphx.BSPDebug_DrawNodeSplit,
    DrawLineSegment             = libphx.BSPDebug_DrawLineSegment,
    DrawSphere                  = libphx.BSPDebug_DrawSphere,
    PrintRayProfilingData       = libphx.BSPDebug_PrintRayProfilingData,
    PrintSphereProfilingData    = libphx.BSPDebug_PrintSphereProfilingData,
    GetIntersectSphereTriangles = libphx.BSPDebug_GetIntersectSphereTriangles,
    GetLeaf                     = libphx.BSPDebug_GetLeaf,
  }

  if onDef_BSPDebug then onDef_BSPDebug(BSPDebug, mt) end
  BSPDebug = setmetatable(BSPDebug, mt)
end

return BSPDebug


text:
-- StrMap ----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local StrMap

do -- C Definitions
  ffi.cdef [[
    StrMap*     StrMap_Create  (uint32 initCapacity);
    void        StrMap_Free    (StrMap*);
    void        StrMap_FreeEx  (StrMap*, void (*freeFn)(cstr key, void* value));
    void*       StrMap_Get     (StrMap*, cstr key);
    uint32      StrMap_GetSize (StrMap*);
    void        StrMap_Remove  (StrMap*, cstr key);
    void        StrMap_Set     (StrMap*, cstr key, void* val);
    void        StrMap_Dump    (StrMap*);
    StrMapIter* StrMap_Iterate (StrMap*);
  ]]
end

do -- Global Symbol Table
  StrMap = {
    Create  = libphx.StrMap_Create,
    Free    = libphx.StrMap_Free,
    FreeEx  = libphx.StrMap_FreeEx,
    Get     = libphx.StrMap_Get,
    GetSize = libphx.StrMap_GetSize,
    Remove  = libphx.StrMap_Remove,
    Set     = libphx.StrMap_Set,
    Dump    = libphx.StrMap_Dump,
    Iterate = libphx.StrMap_Iterate,
  }

  if onDef_StrMap then onDef_StrMap(StrMap, mt) end
  StrMap = setmetatable(StrMap, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('StrMap')
  local mt = {
    __index = {
      managed = function (self) return ffi.gc(self, libphx.StrMap_Free) end,
      free    = libphx.StrMap_Free,
      freeEx  = libphx.StrMap_FreeEx,
      get     = libphx.StrMap_Get,
      getSize = libphx.StrMap_GetSize,
      remove  = libphx.StrMap_Remove,
      set     = libphx.StrMap_Set,
      dump    = libphx.StrMap_Dump,
      iterate = libphx.StrMap_Iterate,
    },
  }

  if onDef_StrMap_t then onDef_StrMap_t(t, mt) end
  StrMap_t = ffi.metatype(t, mt)
end

return StrMap


text:
-- TexFormat -------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local TexFormat

do -- C Definitions
  ffi.cdef [[
    int       TexFormat_Components (TexFormat);
    int       TexFormat_GetSize    (TexFormat);
    bool      TexFormat_IsColor    (TexFormat);
    bool      TexFormat_IsDepth    (TexFormat);
    bool      TexFormat_IsValid    (TexFormat);
    TexFormat TexFormat_R8;
    TexFormat TexFormat_R16;
    TexFormat TexFormat_R16F;
    TexFormat TexFormat_R32F;
    TexFormat TexFormat_RG8;
    TexFormat TexFormat_RG16;
    TexFormat TexFormat_RG16F;
    TexFormat TexFormat_RG32F;
    TexFormat TexFormat_RGB8;
    TexFormat TexFormat_RGBA8;
    TexFormat TexFormat_RGBA16;
    TexFormat TexFormat_RGBA16F;
    TexFormat TexFormat_RGBA32F;
    TexFormat TexFormat_Depth16;
    TexFormat TexFormat_Depth24;
    TexFormat TexFormat_Depth32F;
  ]]
end

do -- Global Symbol Table
  TexFormat = {
    R8       = libphx.TexFormat_R8,
    R16      = libphx.TexFormat_R16,
    R16F     = libphx.TexFormat_R16F,
    R32F     = libphx.TexFormat_R32F,
    RG8      = libphx.TexFormat_RG8,
    RG16     = libphx.TexFormat_RG16,
    RG16F    = libphx.TexFormat_RG16F,
    RG32F    = libphx.TexFormat_RG32F,
    RGB8     = libphx.TexFormat_RGB8,
    RGBA8    = libphx.TexFormat_RGBA8,
    RGBA16   = libphx.TexFormat_RGBA16,
    RGBA16F  = libphx.TexFormat_RGBA16F,
    RGBA32F  = libphx.TexFormat_RGBA32F,
    Depth16  = libphx.TexFormat_Depth16,
    Depth24  = libphx.TexFormat_Depth24,
    Depth32F = libphx.TexFormat_Depth32F,
    Components = libphx.TexFormat_Components,
    GetSize    = libphx.TexFormat_GetSize,
    IsColor    = libphx.TexFormat_IsColor,
    IsDepth    = libphx.TexFormat_IsDepth,
    IsValid    = libphx.TexFormat_IsValid,
  }

  if onDef_TexFormat then onDef_TexFormat(TexFormat, mt) end
  TexFormat = setmetatable(TexFormat, mt)
end

return TexFormat


text:
-- BoxTree ---------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local BoxTree

do -- C Definitions
  ffi.cdef [[
    BoxTree* BoxTree_Create       ();
    BoxTree* BoxTree_FromMesh     (Mesh*);
    void     BoxTree_Free         (BoxTree*);
    void     BoxTree_Add          (BoxTree*, Box3f bound, void* data);
    void     BoxTree_Draw         (BoxTree*, int maxDepth);
    int      BoxTree_GetMemory    (BoxTree*);
    bool     BoxTree_IntersectRay (BoxTree*, Matrix*, Vec3f const* ro, Vec3f const* rd);
  ]]
end

do -- Global Symbol Table
  BoxTree = {
    Create       = libphx.BoxTree_Create,
    FromMesh     = libphx.BoxTree_FromMesh,
    Free         = libphx.BoxTree_Free,
    Add          = libphx.BoxTree_Add,
    Draw         = libphx.BoxTree_Draw,
    GetMemory    = libphx.BoxTree_GetMemory,
    IntersectRay = libphx.BoxTree_IntersectRay,
  }

  if onDef_BoxTree then onDef_BoxTree(BoxTree, mt) end
  BoxTree = setmetatable(BoxTree, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('BoxTree')
  local mt = {
    __index = {
      managed      = function (self) return ffi.gc(self, libphx.BoxTree_Free) end,
      free         = libphx.BoxTree_Free,
      add          = libphx.BoxTree_Add,
      draw         = libphx.BoxTree_Draw,
      getMemory    = libphx.BoxTree_GetMemory,
      intersectRay = libphx.BoxTree_IntersectRay,
    },
  }

  if onDef_BoxTree_t then onDef_BoxTree_t(t, mt) end
  BoxTree_t = ffi.metatype(t, mt)
end

return BoxTree


text:
-- Sound -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Sound

do -- C Definitions
  ffi.cdef [[
    void   Sound_Acquire               (Sound*);
    void   Sound_Free                  (Sound*);
    Sound* Sound_Load                  (cstr name, bool isLooped, bool is3D);
    Sound* Sound_LoadAsync             (cstr name, bool isLooped, bool is3D);
    Sound* Sound_Clone                 (Sound*);
    void   Sound_ToFile                (Sound*, cstr);
    void   Sound_Pause                 (Sound*);
    void   Sound_Play                  (Sound*);
    void   Sound_Rewind                (Sound*);
    bool   Sound_Get3D                 (Sound*);
    float  Sound_GetDuration           (Sound*);
    bool   Sound_GetLooped             (Sound*);
    cstr   Sound_GetName               (Sound*);
    cstr   Sound_GetPath               (Sound*);
    bool   Sound_IsFinished            (Sound*);
    bool   Sound_IsPlaying             (Sound*);
    void   Sound_Attach3DPos           (Sound*, Vec3f const* pos, Vec3f const* vel);
    void   Sound_Set3DLevel            (Sound*, float);
    void   Sound_Set3DPos              (Sound*, Vec3f const* pos, Vec3f const* vel);
    void   Sound_SetFreeOnFinish       (Sound*, bool);
    void   Sound_SetPan                (Sound*, float);
    void   Sound_SetPitch              (Sound*, float);
    void   Sound_SetPlayPos            (Sound*, float);
    void   Sound_SetVolume             (Sound*, float);
    Sound* Sound_LoadPlay              (cstr name, bool isLooped, bool is3D);
    Sound* Sound_LoadPlayAttached      (cstr name, bool isLooped, bool is3D, Vec3f const* pos, Vec3f const* vel);
    void   Sound_LoadPlayFree          (cstr name, bool isLooped, bool is3D);
    void   Sound_LoadPlayFreeAttached  (cstr name, bool isLooped, bool is3D, Vec3f const* pos, Vec3f const* vel);
    Sound* Sound_ClonePlay             (Sound*);
    Sound* Sound_ClonePlayAttached     (Sound*, Vec3f const* pos, Vec3f const* vel);
    void   Sound_ClonePlayFree         (Sound*);
    void   Sound_ClonePlayFreeAttached (Sound*, Vec3f const* pos, Vec3f const* vel);
  ]]
end

do -- Global Symbol Table
  Sound = {
    Acquire               = libphx.Sound_Acquire,
    Free                  = libphx.Sound_Free,
    Load                  = libphx.Sound_Load,
    LoadAsync             = libphx.Sound_LoadAsync,
    Clone                 = libphx.Sound_Clone,
    ToFile                = libphx.Sound_ToFile,
    Pause                 = libphx.Sound_Pause,
    Play                  = libphx.Sound_Play,
    Rewind                = libphx.Sound_Rewind,
    Get3D                 = libphx.Sound_Get3D,
    GetDuration           = libphx.Sound_GetDuration,
    GetLooped             = libphx.Sound_GetLooped,
    GetName               = libphx.Sound_GetName,
    GetPath               = libphx.Sound_GetPath,
    IsFinished            = libphx.Sound_IsFinished,
    IsPlaying             = libphx.Sound_IsPlaying,
    Attach3DPos           = libphx.Sound_Attach3DPos,
    Set3DLevel            = libphx.Sound_Set3DLevel,
    Set3DPos              = libphx.Sound_Set3DPos,
    SetFreeOnFinish       = libphx.Sound_SetFreeOnFinish,
    SetPan                = libphx.Sound_SetPan,
    SetPitch              = libphx.Sound_SetPitch,
    SetPlayPos            = libphx.Sound_SetPlayPos,
    SetVolume             = libphx.Sound_SetVolume,
    LoadPlay              = libphx.Sound_LoadPlay,
    LoadPlayAttached      = libphx.Sound_LoadPlayAttached,
    LoadPlayFree          = libphx.Sound_LoadPlayFree,
    LoadPlayFreeAttached  = libphx.Sound_LoadPlayFreeAttached,
    ClonePlay             = libphx.Sound_ClonePlay,
    ClonePlayAttached     = libphx.Sound_ClonePlayAttached,
    ClonePlayFree         = libphx.Sound_ClonePlayFree,
    ClonePlayFreeAttached = libphx.Sound_ClonePlayFreeAttached,
  }

  if onDef_Sound then onDef_Sound(Sound, mt) end
  Sound = setmetatable(Sound, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Sound')
  local mt = {
    __index = {
      managed               = function (self) return ffi.gc(self, libphx.Sound_Free) end,
      acquire               = libphx.Sound_Acquire,
      free                  = libphx.Sound_Free,
      clone                 = libphx.Sound_Clone,
      toFile                = libphx.Sound_ToFile,
      pause                 = libphx.Sound_Pause,
      play                  = libphx.Sound_Play,
      rewind                = libphx.Sound_Rewind,
      get3D                 = libphx.Sound_Get3D,
      getDuration           = libphx.Sound_GetDuration,
      getLooped             = libphx.Sound_GetLooped,
      getName               = libphx.Sound_GetName,
      getPath               = libphx.Sound_GetPath,
      isFinished            = libphx.Sound_IsFinished,
      isPlaying             = libphx.Sound_IsPlaying,
      attach3DPos           = libphx.Sound_Attach3DPos,
      set3DLevel            = libphx.Sound_Set3DLevel,
      set3DPos              = libphx.Sound_Set3DPos,
      setFreeOnFinish       = libphx.Sound_SetFreeOnFinish,
      setPan                = libphx.Sound_SetPan,
      setPitch              = libphx.Sound_SetPitch,
      setPlayPos            = libphx.Sound_SetPlayPos,
      setVolume             = libphx.Sound_SetVolume,
      clonePlay             = libphx.Sound_ClonePlay,
      clonePlayAttached     = libphx.Sound_ClonePlayAttached,
      clonePlayFree         = libphx.Sound_ClonePlayFree,
      clonePlayFreeAttached = libphx.Sound_ClonePlayFreeAttached,
    },
  }

  if onDef_Sound_t then onDef_Sound_t(t, mt) end
  Sound_t = ffi.metatype(t, mt)
end

return Sound


text:
-- ImGui -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local ImGui

do -- C Definitions
  ffi.cdef [[
    void  ImGui_Begin              (float sx, float sy);
    void  ImGui_End                ();
    void  ImGui_Draw               ();
    void  ImGui_AlignCursor        (float sx, float sy, float alignX, float alignY);
    float ImGui_GetCursorX         ();
    float ImGui_GetCursorY         ();
    void  ImGui_PushCursor         ();
    void  ImGui_PopCursor          ();
    void  ImGui_SetCursor          (float x, float y);
    void  ImGui_SetCursorX         (float x);
    void  ImGui_SetCursorY         (float y);
    void  ImGui_Indent             ();
    void  ImGui_Undent             ();
    bool  ImGui_Button             (cstr label);
    bool  ImGui_ButtonEx           (cstr label, float sx, float sy);
    bool  ImGui_Checkbox           (bool value);
    void  ImGui_Divider            ();
    bool  ImGui_Selectable         (cstr label);
    void  ImGui_Tex2D              (Tex2D*);
    void  ImGui_Text               (cstr text);
    void  ImGui_TextColored        (cstr text, float r, float g, float b, float a);
    void  ImGui_TextEx             (Font* font, cstr text, float r, float g, float b, float a);
    void  ImGui_BeginGroupX        (float sy);
    void  ImGui_BeginGroupY        (float sx);
    void  ImGui_EndGroup           ();
    void  ImGui_BeginPanel         (float sx, float sy);
    void  ImGui_EndPanel           ();
    void  ImGui_BeginWindow        (cstr title, float sx, float sy);
    void  ImGui_EndWindow          ();
    void  ImGui_BeginScrollFrame   (float sx, float sy);
    void  ImGui_EndScrollFrame     ();
    void  ImGui_PushStyle          ();
    void  ImGui_PushStyleFont      (Font*);
    void  ImGui_PushStylePadding   (float px, float py);
    void  ImGui_PushStyleSpacing   (float sx, float sy);
    void  ImGui_PushStyleTextColor (float r, float g, float b, float a);
    void  ImGui_PopStyle           ();
    void  ImGui_SetFont            (Font*);
    void  ImGui_SetSpacing         (float sx, float sy);
    void  ImGui_SetNextWidth       (float sx);
    void  ImGui_SetNextHeight      (float sy);
  ]]
end

do -- Global Symbol Table
  ImGui = {
    Begin              = libphx.ImGui_Begin,
    End                = libphx.ImGui_End,
    Draw               = libphx.ImGui_Draw,
    AlignCursor        = libphx.ImGui_AlignCursor,
    GetCursorX         = libphx.ImGui_GetCursorX,
    GetCursorY         = libphx.ImGui_GetCursorY,
    PushCursor         = libphx.ImGui_PushCursor,
    PopCursor          = libphx.ImGui_PopCursor,
    SetCursor          = libphx.ImGui_SetCursor,
    SetCursorX         = libphx.ImGui_SetCursorX,
    SetCursorY         = libphx.ImGui_SetCursorY,
    Indent             = libphx.ImGui_Indent,
    Undent             = libphx.ImGui_Undent,
    Button             = libphx.ImGui_Button,
    ButtonEx           = libphx.ImGui_ButtonEx,
    Checkbox           = libphx.ImGui_Checkbox,
    Divider            = libphx.ImGui_Divider,
    Selectable         = libphx.ImGui_Selectable,
    Tex2D              = libphx.ImGui_Tex2D,
    Text               = libphx.ImGui_Text,
    TextColored        = libphx.ImGui_TextColored,
    TextEx             = libphx.ImGui_TextEx,
    BeginGroupX        = libphx.ImGui_BeginGroupX,
    BeginGroupY        = libphx.ImGui_BeginGroupY,
    EndGroup           = libphx.ImGui_EndGroup,
    BeginPanel         = libphx.ImGui_BeginPanel,
    EndPanel           = libphx.ImGui_EndPanel,
    BeginWindow        = libphx.ImGui_BeginWindow,
    EndWindow          = libphx.ImGui_EndWindow,
    BeginScrollFrame   = libphx.ImGui_BeginScrollFrame,
    EndScrollFrame     = libphx.ImGui_EndScrollFrame,
    PushStyle          = libphx.ImGui_PushStyle,
    PushStyleFont      = libphx.ImGui_PushStyleFont,
    PushStylePadding   = libphx.ImGui_PushStylePadding,
    PushStyleSpacing   = libphx.ImGui_PushStyleSpacing,
    PushStyleTextColor = libphx.ImGui_PushStyleTextColor,
    PopStyle           = libphx.ImGui_PopStyle,
    SetFont            = libphx.ImGui_SetFont,
    SetSpacing         = libphx.ImGui_SetSpacing,
    SetNextWidth       = libphx.ImGui_SetNextWidth,
    SetNextHeight      = libphx.ImGui_SetNextHeight,
  }

  if onDef_ImGui then onDef_ImGui(ImGui, mt) end
  ImGui = setmetatable(ImGui, mt)
end

return ImGui


text:
-- Sphere ----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Sphere

do -- Global Symbol Table
  Sphere = {
  }

  local mt = {
    __call  = function (t, ...) return Sphere_t(...) end,
  }

  if onDef_Sphere then onDef_Sphere(Sphere, mt) end
  Sphere = setmetatable(Sphere, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Sphere')
  local mt = {
    __index = {
      clone = function (x) return Sphere_t(x) end,
    },
  }

  if onDef_Sphere_t then onDef_Sphere_t(t, mt) end
  Sphere_t = ffi.metatype(t, mt)
end

return Sphere


text:
-- Intersect -------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Intersect

do -- C Definitions
  ffi.cdef [[
    bool Intersect_PointBox                  (Matrix* t1, Matrix* t2);
    bool Intersect_PointTriangle_Barycentric (Vec3f const*, Triangle const*);
    bool Intersect_RayPlane                  (Ray const*, Plane const*, Vec3f* pHit);
    bool Intersect_RayTriangle_Barycentric   (Ray const*, Triangle const*, float tEpsilon, float* tHit);
    bool Intersect_RayTriangle_Moller1       (Ray const*, Triangle const*, float* tHit);
    bool Intersect_RayTriangle_Moller2       (Ray const*, Triangle const*, float* tHit);
    bool Intersect_LineSegmentPlane          (LineSegment const*, Plane const*, Vec3f* pHit);
    bool Intersect_RectRect                  (Vec4f const*, Vec4f const*);
    bool Intersect_RectRectFast              (Vec4f const*, Vec4f const*);
    bool Intersect_SphereTriangle            (Sphere const*, Triangle const*, Vec3f* pHit);
  ]]
end

do -- Global Symbol Table
  Intersect = {
    PointBox                  = libphx.Intersect_PointBox,
    PointTriangle_Barycentric = libphx.Intersect_PointTriangle_Barycentric,
    RayPlane                  = libphx.Intersect_RayPlane,
    RayTriangle_Barycentric   = libphx.Intersect_RayTriangle_Barycentric,
    RayTriangle_Moller1       = libphx.Intersect_RayTriangle_Moller1,
    RayTriangle_Moller2       = libphx.Intersect_RayTriangle_Moller2,
    LineSegmentPlane          = libphx.Intersect_LineSegmentPlane,
    RectRect                  = libphx.Intersect_RectRect,
    RectRectFast              = libphx.Intersect_RectRectFast,
    SphereTriangle            = libphx.Intersect_SphereTriangle,
  }

  if onDef_Intersect then onDef_Intersect(Intersect, mt) end
  Intersect = setmetatable(Intersect, mt)
end

return Intersect


text:
-- ShaderState -----------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local ShaderState

do -- C Definitions
  ffi.cdef [[
    ShaderState* ShaderState_Create         (Shader*);
    void         ShaderState_Acquire        (ShaderState*);
    void         ShaderState_Free           (ShaderState*);
    ShaderState* ShaderState_FromShaderLoad (cstr vertName, cstr fragName);
    void         ShaderState_SetFloat       (ShaderState*, cstr, float);
    void         ShaderState_SetFloat2      (ShaderState*, cstr, float, float);
    void         ShaderState_SetFloat3      (ShaderState*, cstr, float, float, float);
    void         ShaderState_SetFloat4      (ShaderState*, cstr, float, float, float, float);
    void         ShaderState_SetInt         (ShaderState*, cstr, int);
    void         ShaderState_SetMatrix      (ShaderState*, cstr, Matrix*);
    void         ShaderState_SetTex1D       (ShaderState*, cstr, Tex1D*);
    void         ShaderState_SetTex2D       (ShaderState*, cstr, Tex2D*);
    void         ShaderState_SetTex3D       (ShaderState*, cstr, Tex3D*);
    void         ShaderState_SetTexCube     (ShaderState*, cstr, TexCube*);
    void         ShaderState_Start          (ShaderState*);
    void         ShaderState_Stop           (ShaderState*);
  ]]
end

do -- Global Symbol Table
  ShaderState = {
    Create         = libphx.ShaderState_Create,
    Acquire        = libphx.ShaderState_Acquire,
    Free           = libphx.ShaderState_Free,
    FromShaderLoad = libphx.ShaderState_FromShaderLoad,
    SetFloat       = libphx.ShaderState_SetFloat,
    SetFloat2      = libphx.ShaderState_SetFloat2,
    SetFloat3      = libphx.ShaderState_SetFloat3,
    SetFloat4      = libphx.ShaderState_SetFloat4,
    SetInt         = libphx.ShaderState_SetInt,
    SetMatrix      = libphx.ShaderState_SetMatrix,
    SetTex1D       = libphx.ShaderState_SetTex1D,
    SetTex2D       = libphx.ShaderState_SetTex2D,
    SetTex3D       = libphx.ShaderState_SetTex3D,
    SetTexCube     = libphx.ShaderState_SetTexCube,
    Start          = libphx.ShaderState_Start,
    Stop           = libphx.ShaderState_Stop,
  }

  if onDef_ShaderState then onDef_ShaderState(ShaderState, mt) end
  ShaderState = setmetatable(ShaderState, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('ShaderState')
  local mt = {
    __index = {
      managed        = function (self) return ffi.gc(self, libphx.ShaderState_Free) end,
      acquire        = libphx.ShaderState_Acquire,
      free           = libphx.ShaderState_Free,
      setFloat       = libphx.ShaderState_SetFloat,
      setFloat2      = libphx.ShaderState_SetFloat2,
      setFloat3      = libphx.ShaderState_SetFloat3,
      setFloat4      = libphx.ShaderState_SetFloat4,
      setInt         = libphx.ShaderState_SetInt,
      setMatrix      = libphx.ShaderState_SetMatrix,
      setTex1D       = libphx.ShaderState_SetTex1D,
      setTex2D       = libphx.ShaderState_SetTex2D,
      setTex3D       = libphx.ShaderState_SetTex3D,
      setTexCube     = libphx.ShaderState_SetTexCube,
      start          = libphx.ShaderState_Start,
      stop           = libphx.ShaderState_Stop,
    },
  }

  if onDef_ShaderState_t then onDef_ShaderState_t(t, mt) end
  ShaderState_t = ffi.metatype(t, mt)
end

return ShaderState


text:
-- MemPool ---------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local MemPool

do -- C Definitions
  ffi.cdef [[
    MemPool* MemPool_Create      (uint32 cellSize, uint32 blockSize);
    MemPool* MemPool_CreateAuto  (uint32 elemSize);
    void     MemPool_Free        (MemPool*);
    void*    MemPool_Alloc       (MemPool*);
    void     MemPool_Clear       (MemPool*);
    void     MemPool_Dealloc     (MemPool*, void*);
    uint32   MemPool_GetCapacity (MemPool*);
    uint32   MemPool_GetSize     (MemPool*);
  ]]
end

do -- Global Symbol Table
  MemPool = {
    Create      = libphx.MemPool_Create,
    CreateAuto  = libphx.MemPool_CreateAuto,
    Free        = libphx.MemPool_Free,
    Alloc       = libphx.MemPool_Alloc,
    Clear       = libphx.MemPool_Clear,
    Dealloc     = libphx.MemPool_Dealloc,
    GetCapacity = libphx.MemPool_GetCapacity,
    GetSize     = libphx.MemPool_GetSize,
  }

  if onDef_MemPool then onDef_MemPool(MemPool, mt) end
  MemPool = setmetatable(MemPool, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('MemPool')
  local mt = {
    __index = {
      managed     = function (self) return ffi.gc(self, libphx.MemPool_Free) end,
      free        = libphx.MemPool_Free,
      alloc       = libphx.MemPool_Alloc,
      clear       = libphx.MemPool_Clear,
      dealloc     = libphx.MemPool_Dealloc,
      getCapacity = libphx.MemPool_GetCapacity,
      getSize     = libphx.MemPool_GetSize,
    },
  }

  if onDef_MemPool_t then onDef_MemPool_t(t, mt) end
  MemPool_t = ffi.metatype(t, mt)
end

return MemPool


text:
-- RenderState -----------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local RenderState

do -- C Definitions
  ffi.cdef [[
    void RenderState_PushAllDefaults   ();
    void RenderState_PushBlendMode     (BlendMode);
    void RenderState_PushCullFace      (CullFace);
    void RenderState_PushDepthTest     (bool);
    void RenderState_PushDepthWritable (bool);
    void RenderState_PushWireframe     (bool);
    void RenderState_PopAll            ();
    void RenderState_PopBlendMode      ();
    void RenderState_PopCullFace       ();
    void RenderState_PopDepthTest      ();
    void RenderState_PopDepthWritable  ();
    void RenderState_PopWireframe      ();
  ]]
end

do -- Global Symbol Table
  RenderState = {
    PushAllDefaults   = libphx.RenderState_PushAllDefaults,
    PushBlendMode     = libphx.RenderState_PushBlendMode,
    PushCullFace      = libphx.RenderState_PushCullFace,
    PushDepthTest     = libphx.RenderState_PushDepthTest,
    PushDepthWritable = libphx.RenderState_PushDepthWritable,
    PushWireframe     = libphx.RenderState_PushWireframe,
    PopAll            = libphx.RenderState_PopAll,
    PopBlendMode      = libphx.RenderState_PopBlendMode,
    PopCullFace       = libphx.RenderState_PopCullFace,
    PopDepthTest      = libphx.RenderState_PopDepthTest,
    PopDepthWritable  = libphx.RenderState_PopDepthWritable,
    PopWireframe      = libphx.RenderState_PopWireframe,
  }

  if onDef_RenderState then onDef_RenderState(RenderState, mt) end
  RenderState = setmetatable(RenderState, mt)
end

return RenderState


text:
-- Vec2d -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Vec2d

do -- Global Symbol Table
  Vec2d = {
  }

  local mt = {
    __call  = function (t, ...) return Vec2d_t(...) end,
  }

  if onDef_Vec2d then onDef_Vec2d(Vec2d, mt) end
  Vec2d = setmetatable(Vec2d, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Vec2d')
  local mt = {
    __index = {
      clone = function (x) return Vec2d_t(x) end,
    },
  }

  if onDef_Vec2d_t then onDef_Vec2d_t(t, mt) end
  Vec2d_t = ffi.metatype(t, mt)
end

return Vec2d


text:
-- Vec3f -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Vec3f

do -- Global Symbol Table
  Vec3f = {
  }

  local mt = {
    __call  = function (t, ...) return Vec3f_t(...) end,
  }

  if onDef_Vec3f then onDef_Vec3f(Vec3f, mt) end
  Vec3f = setmetatable(Vec3f, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Vec3f')
  local mt = {
    __index = {
      clone = function (x) return Vec3f_t(x) end,
    },
  }

  if onDef_Vec3f_t then onDef_Vec3f_t(t, mt) end
  Vec3f_t = ffi.metatype(t, mt)
end

return Vec3f


text:
-- StrMapIter ------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local StrMapIter

do -- C Definitions
  ffi.cdef [[
    void  StrMapIter_Advance  (StrMapIter*);
    void  StrMapIter_Free     (StrMapIter*);
    bool  StrMapIter_HasMore  (StrMapIter*);
    cstr  StrMapIter_GetKey   (StrMapIter*);
    void* StrMapIter_GetValue (StrMapIter*);
  ]]
end

do -- Global Symbol Table
  StrMapIter = {
    Advance  = libphx.StrMapIter_Advance,
    Free     = libphx.StrMapIter_Free,
    HasMore  = libphx.StrMapIter_HasMore,
    GetKey   = libphx.StrMapIter_GetKey,
    GetValue = libphx.StrMapIter_GetValue,
  }

  if onDef_StrMapIter then onDef_StrMapIter(StrMapIter, mt) end
  StrMapIter = setmetatable(StrMapIter, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('StrMapIter')
  local mt = {
    __index = {
      managed  = function (self) return ffi.gc(self, libphx.StrMapIter_Free) end,
      advance  = libphx.StrMapIter_Advance,
      free     = libphx.StrMapIter_Free,
      hasMore  = libphx.StrMapIter_HasMore,
      getKey   = libphx.StrMapIter_GetKey,
      getValue = libphx.StrMapIter_GetValue,
    },
  }

  if onDef_StrMapIter_t then onDef_StrMapIter_t(t, mt) end
  StrMapIter_t = ffi.metatype(t, mt)
end

return StrMapIter


text:
-- SDF -------------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local SDF

do -- C Definitions
  ffi.cdef [[
    SDF*  SDF_Create         (int sx, int sy, int sz);
    SDF*  SDF_FromTex3D      (Tex3D*);
    void  SDF_Free           (SDF*);
    Mesh* SDF_ToMesh         (SDF*);
    void  SDF_Clear          (SDF*, float value);
    void  SDF_ComputeNormals (SDF*);
    void  SDF_Set            (SDF*, int x, int y, int z, float value);
    void  SDF_SetNormal      (SDF*, int x, int y, int z, Vec3f const* normal);
  ]]
end

do -- Global Symbol Table
  SDF = {
    Create         = libphx.SDF_Create,
    FromTex3D      = libphx.SDF_FromTex3D,
    Free           = libphx.SDF_Free,
    ToMesh         = libphx.SDF_ToMesh,
    Clear          = libphx.SDF_Clear,
    ComputeNormals = libphx.SDF_ComputeNormals,
    Set            = libphx.SDF_Set,
    SetNormal      = libphx.SDF_SetNormal,
  }

  if onDef_SDF then onDef_SDF(SDF, mt) end
  SDF = setmetatable(SDF, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('SDF')
  local mt = {
    __index = {
      managed        = function (self) return ffi.gc(self, libphx.SDF_Free) end,
      free           = libphx.SDF_Free,
      toMesh         = libphx.SDF_ToMesh,
      clear          = libphx.SDF_Clear,
      computeNormals = libphx.SDF_ComputeNormals,
      set            = libphx.SDF_Set,
      setNormal      = libphx.SDF_SetNormal,
    },
  }

  if onDef_SDF_t then onDef_SDF_t(t, mt) end
  SDF_t = ffi.metatype(t, mt)
end

return SDF


text:
-- MemStack --------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local MemStack

do -- C Definitions
  ffi.cdef [[
    MemStack* MemStack_Create       (uint32 capacity);
    void      MemStack_Free         (MemStack*);
    void*     MemStack_Alloc        (MemStack*, uint32 size);
    void      MemStack_Clear        (MemStack*);
    void      MemStack_Dealloc      (MemStack*, uint32 size);
    bool      MemStack_CanAlloc     (MemStack*, uint32 size);
    uint32    MemStack_GetSize      (MemStack*);
    uint32    MemStack_GetCapacity  (MemStack*);
    uint32    MemStack_GetRemaining (MemStack*);
  ]]
end

do -- Global Symbol Table
  MemStack = {
    Create       = libphx.MemStack_Create,
    Free         = libphx.MemStack_Free,
    Alloc        = libphx.MemStack_Alloc,
    Clear        = libphx.MemStack_Clear,
    Dealloc      = libphx.MemStack_Dealloc,
    CanAlloc     = libphx.MemStack_CanAlloc,
    GetSize      = libphx.MemStack_GetSize,
    GetCapacity  = libphx.MemStack_GetCapacity,
    GetRemaining = libphx.MemStack_GetRemaining,
  }

  if onDef_MemStack then onDef_MemStack(MemStack, mt) end
  MemStack = setmetatable(MemStack, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('MemStack')
  local mt = {
    __index = {
      managed      = function (self) return ffi.gc(self, libphx.MemStack_Free) end,
      free         = libphx.MemStack_Free,
      alloc        = libphx.MemStack_Alloc,
      clear        = libphx.MemStack_Clear,
      dealloc      = libphx.MemStack_Dealloc,
      canAlloc     = libphx.MemStack_CanAlloc,
      getSize      = libphx.MemStack_GetSize,
      getCapacity  = libphx.MemStack_GetCapacity,
      getRemaining = libphx.MemStack_GetRemaining,
    },
  }

  if onDef_MemStack_t then onDef_MemStack_t(t, mt) end
  MemStack_t = ffi.metatype(t, mt)
end

return MemStack


text:
-- SocketType ------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local SocketType

do -- Global Symbol Table
  SocketType = {
    None = 0x0,
    UDP  = 0x1,
    TCP  = 0x2,
  }

  if onDef_SocketType then onDef_SocketType(SocketType, mt) end
  SocketType = setmetatable(SocketType, mt)
end

return SocketType


text:
-- Vec4i -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Vec4i

do -- Global Symbol Table
  Vec4i = {
  }

  local mt = {
    __call  = function (t, ...) return Vec4i_t(...) end,
  }

  if onDef_Vec4i then onDef_Vec4i(Vec4i, mt) end
  Vec4i = setmetatable(Vec4i, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Vec4i')
  local mt = {
    __index = {
      clone = function (x) return Vec4i_t(x) end,
    },
  }

  if onDef_Vec4i_t then onDef_Vec4i_t(t, mt) end
  Vec4i_t = ffi.metatype(t, mt)
end

return Vec4i


text:
-- Tex1D -----------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Tex1D

do -- C Definitions
  ffi.cdef [[
    Tex1D*    Tex1D_Create       (int size, TexFormat);
    void      Tex1D_Acquire      (Tex1D*);
    void      Tex1D_Free         (Tex1D*);
    void      Tex1D_Draw         (Tex1D*, float x, float y, float xs, float ys);
    void      Tex1D_GenMipmap    (Tex1D*);
    void      Tex1D_GetData      (Tex1D*, void*, PixelFormat, DataFormat);
    Bytes*    Tex1D_GetDataBytes (Tex1D*, PixelFormat, DataFormat);
    TexFormat Tex1D_GetFormat    (Tex1D*);
    uint      Tex1D_GetHandle    (Tex1D*);
    uint      Tex1D_GetSize      (Tex1D*);
    void      Tex1D_SetData      (Tex1D*, void const*, PixelFormat, DataFormat);
    void      Tex1D_SetDataBytes (Tex1D*, Bytes*, PixelFormat, DataFormat);
    void      Tex1D_SetMagFilter (Tex1D*, TexFilter);
    void      Tex1D_SetMinFilter (Tex1D*, TexFilter);
    void      Tex1D_SetTexel     (Tex1D*, int x, float r, float g, float b, float a);
    void      Tex1D_SetWrapMode  (Tex1D*, TexWrapMode);
  ]]
end

do -- Global Symbol Table
  Tex1D = {
    Create       = libphx.Tex1D_Create,
    Acquire      = libphx.Tex1D_Acquire,
    Free         = libphx.Tex1D_Free,
    Draw         = libphx.Tex1D_Draw,
    GenMipmap    = libphx.Tex1D_GenMipmap,
    GetData      = libphx.Tex1D_GetData,
    GetDataBytes = libphx.Tex1D_GetDataBytes,
    GetFormat    = libphx.Tex1D_GetFormat,
    GetHandle    = libphx.Tex1D_GetHandle,
    GetSize      = libphx.Tex1D_GetSize,
    SetData      = libphx.Tex1D_SetData,
    SetDataBytes = libphx.Tex1D_SetDataBytes,
    SetMagFilter = libphx.Tex1D_SetMagFilter,
    SetMinFilter = libphx.Tex1D_SetMinFilter,
    SetTexel     = libphx.Tex1D_SetTexel,
    SetWrapMode  = libphx.Tex1D_SetWrapMode,
  }

  if onDef_Tex1D then onDef_Tex1D(Tex1D, mt) end
  Tex1D = setmetatable(Tex1D, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Tex1D')
  local mt = {
    __index = {
      managed      = function (self) return ffi.gc(self, libphx.Tex1D_Free) end,
      acquire      = libphx.Tex1D_Acquire,
      free         = libphx.Tex1D_Free,
      draw         = libphx.Tex1D_Draw,
      genMipmap    = libphx.Tex1D_GenMipmap,
      getData      = libphx.Tex1D_GetData,
      getDataBytes = libphx.Tex1D_GetDataBytes,
      getFormat    = libphx.Tex1D_GetFormat,
      getHandle    = libphx.Tex1D_GetHandle,
      getSize      = libphx.Tex1D_GetSize,
      setData      = libphx.Tex1D_SetData,
      setDataBytes = libphx.Tex1D_SetDataBytes,
      setMagFilter = libphx.Tex1D_SetMagFilter,
      setMinFilter = libphx.Tex1D_SetMinFilter,
      setTexel     = libphx.Tex1D_SetTexel,
      setWrapMode  = libphx.Tex1D_SetWrapMode,
    },
  }

  if onDef_Tex1D_t then onDef_Tex1D_t(t, mt) end
  Tex1D_t = ffi.metatype(t, mt)
end

return Tex1D


text:
-- Resource --------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local Resource

do -- C Definitions
  ffi.cdef [[
    void   Resource_AddPath   (ResourceType, cstr format);
    bool   Resource_Exists    (ResourceType, cstr name);
    cstr   Resource_GetPath   (ResourceType, cstr name);
    Bytes* Resource_LoadBytes (ResourceType, cstr name);
    cstr   Resource_LoadCstr  (ResourceType, cstr name);
  ]]
end

do -- Global Symbol Table
  Resource = {
    AddPath   = libphx.Resource_AddPath,
    Exists    = libphx.Resource_Exists,
    GetPath   = libphx.Resource_GetPath,
    LoadBytes = libphx.Resource_LoadBytes,
    LoadCstr  = libphx.Resource_LoadCstr,
  }

  if onDef_Resource then onDef_Resource(Resource, mt) end
  Resource = setmetatable(Resource, mt)
end

return Resource


text:
-- TexCube ---------------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local TexCube

do -- C Definitions
  ffi.cdef [[
    TexCube*  TexCube_Create       (int size, TexFormat);
    TexCube*  TexCube_Load         (cstr path);
    void      TexCube_Acquire      (TexCube*);
    void      TexCube_Free         (TexCube*);
    void      TexCube_Clear        (TexCube*, float r, float g, float b, float a);
    void      TexCube_Generate     (TexCube*, ShaderState*);
    TexCube*  TexCube_GenIRMap     (TexCube*, int samples);
    void      TexCube_GenMipmap    (TexCube*);
    void      TexCube_GetData      (TexCube*, void*, CubeFace, int level, PixelFormat, DataFormat);
    Bytes*    TexCube_GetDataBytes (TexCube*, CubeFace, int level, PixelFormat, DataFormat);
    TexFormat TexCube_GetFormat    (TexCube*);
    uint      TexCube_GetHandle    (TexCube*);
    int       TexCube_GetSize      (TexCube*);
    void      TexCube_SetData      (TexCube*, void const*, CubeFace, int level, PixelFormat, DataFormat);
    void      TexCube_SetDataBytes (TexCube*, Bytes*, CubeFace, int level, PixelFormat, DataFormat);
    void      TexCube_SetMagFilter (TexCube*, TexFilter);
    void      TexCube_SetMinFilter (TexCube*, TexFilter);
    void      TexCube_Save         (TexCube*, cstr path);
    void      TexCube_SaveLevel    (TexCube*, cstr path, int level);
  ]]
end

do -- Global Symbol Table
  TexCube = {
    Create       = libphx.TexCube_Create,
    Load         = libphx.TexCube_Load,
    Acquire      = libphx.TexCube_Acquire,
    Free         = libphx.TexCube_Free,
    Clear        = libphx.TexCube_Clear,
    Generate     = libphx.TexCube_Generate,
    GenIRMap     = libphx.TexCube_GenIRMap,
    GenMipmap    = libphx.TexCube_GenMipmap,
    GetData      = libphx.TexCube_GetData,
    GetDataBytes = libphx.TexCube_GetDataBytes,
    GetFormat    = libphx.TexCube_GetFormat,
    GetHandle    = libphx.TexCube_GetHandle,
    GetSize      = libphx.TexCube_GetSize,
    SetData      = libphx.TexCube_SetData,
    SetDataBytes = libphx.TexCube_SetDataBytes,
    SetMagFilter = libphx.TexCube_SetMagFilter,
    SetMinFilter = libphx.TexCube_SetMinFilter,
    Save         = libphx.TexCube_Save,
    SaveLevel    = libphx.TexCube_SaveLevel,
  }

  if onDef_TexCube then onDef_TexCube(TexCube, mt) end
  TexCube = setmetatable(TexCube, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('TexCube')
  local mt = {
    __index = {
      managed      = function (self) return ffi.gc(self, libphx.TexCube_Free) end,
      acquire      = libphx.TexCube_Acquire,
      free         = libphx.TexCube_Free,
      clear        = libphx.TexCube_Clear,
      generate     = libphx.TexCube_Generate,
      genIRMap     = libphx.TexCube_GenIRMap,
      genMipmap    = libphx.TexCube_GenMipmap,
      getData      = libphx.TexCube_GetData,
      getDataBytes = libphx.TexCube_GetDataBytes,
      getFormat    = libphx.TexCube_GetFormat,
      getHandle    = libphx.TexCube_GetHandle,
      getSize      = libphx.TexCube_GetSize,
      setData      = libphx.TexCube_SetData,
      setDataBytes = libphx.TexCube_SetDataBytes,
      setMagFilter = libphx.TexCube_SetMagFilter,
      setMinFilter = libphx.TexCube_SetMinFilter,
      save         = libphx.TexCube_Save,
      saveLevel    = libphx.TexCube_SaveLevel,
    },
  }

  if onDef_TexCube_t then onDef_TexCube_t(t, mt) end
  TexCube_t = ffi.metatype(t, mt)
end

return TexCube


text:
-- ShapeCastResult -------------------------------------------------------------
local ffi = require('ffi')
local libphx = require('ffi.libphx').lib
local ShapeCastResult

do -- Global Symbol Table
  ShapeCastResult = {
  }

  local mt = {
    __call  = function (t, ...) return ShapeCastResult_t(...) end,
  }

  if onDef_ShapeCastResult then onDef_ShapeCastResult(ShapeCastResult, mt) end
  ShapeCastResult = setmetatable(ShapeCastResult, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('ShapeCastResult')
  local mt = {
    __index = {
      clone = function (x) return ShapeCastResult_t(x) end,
    },
  }

  if onDef_ShapeCastResult_t then onDef_ShapeCastResult_t(t, mt) end
  ShapeCastResult_t = ffi.metatype(t, mt)
end

return ShapeCastResult