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

do -- C Definitions
  ffi.cdef [[
    Mesh*   Mesh_Create            ();
    void    Mesh_Acquire           (Mesh*);
    void    Mesh_Free              (Mesh*);
    Mesh*   Mesh_Load              (cstr name);
    Mesh*   Mesh_Clone             (Mesh*);
    Bytes*  Mesh_ToBytes           (Mesh*);
    Mesh*   Mesh_FromBytes         (Bytes*);
    Mesh*   Mesh_FromObj           (cstr);
    Mesh*   Mesh_FromSDF           (SDF*);
    void    Mesh_AddIndex          (Mesh*, int);
    void    Mesh_AddMesh           (Mesh*, Mesh*);
    void    Mesh_AddQuad           (Mesh*, int, int, int, int);
    void    Mesh_AddTri            (Mesh*, int, int, int);
    void    Mesh_AddVertex         (Mesh*, float px, float py, float pz, float nx, float ny, float nz, float u, float v);
    void    Mesh_AddVertexRaw      (Mesh*, Vertex const*);
    uint64  Mesh_GetVersion        (Mesh*);
    void    Mesh_IncVersion        (Mesh*);
    void    Mesh_GetBound          (Mesh*, Box3f* out);
    void    Mesh_GetCenter         (Mesh*, Vec3f* out);
    int     Mesh_GetIndexCount     (Mesh*);
    int*    Mesh_GetIndexData      (Mesh*);
    float   Mesh_GetRadius         (Mesh*);
    Vertex* Mesh_GetVertex         (Mesh*, int);
    int     Mesh_GetVertexCount    (Mesh*);
    Vertex* Mesh_GetVertexData     (Mesh*);
    void    Mesh_ReserveIndexData  (Mesh*, int capacity);
    void    Mesh_ReserveVertexData (Mesh*, int capacity);
    Error   Mesh_Validate          (Mesh*);
    void    Mesh_Draw              (Mesh*);
    void    Mesh_DrawBind          (Mesh*);
    void    Mesh_DrawBound         (Mesh*);
    void    Mesh_DrawUnbind        (Mesh*);
    void    Mesh_DrawNormals       (Mesh*, float scale);
    Mesh*   Mesh_Center            (Mesh*);
    Mesh*   Mesh_Invert            (Mesh*);
    Mesh*   Mesh_RotateX           (Mesh*, float rads);
    Mesh*   Mesh_RotateY           (Mesh*, float rads);
    Mesh*   Mesh_RotateZ           (Mesh*, float rads);
    Mesh*   Mesh_RotateYPR         (Mesh*, float yaw, float pitch, float roll);
    Mesh*   Mesh_Scale             (Mesh*, float x, float y, float z);
    Mesh*   Mesh_ScaleUniform      (Mesh*, float);
    Mesh*   Mesh_Transform         (Mesh*, Matrix*);
    Mesh*   Mesh_Translate         (Mesh*, float x, float y, float z);
    void    Mesh_ComputeAO         (Mesh*, float radius);
    void    Mesh_ComputeOcclusion  (Mesh*, Tex3D* sdf, float radius);
    void    Mesh_ComputeNormals    (Mesh*);
    void    Mesh_SplitNormals      (Mesh*, float minDot);
    Mesh*   Mesh_Box               (int res);
    Mesh*   Mesh_BoxSphere         (int res);
    Mesh*   Mesh_Plane             (Vec3f origin, Vec3f du, Vec3f dv, int resU, int resV);
  ]]
end

do -- Global Symbol Table
  Mesh = {
    Create            = libphx.Mesh_Create,
    Acquire           = libphx.Mesh_Acquire,
    Free              = libphx.Mesh_Free,
    Load              = libphx.Mesh_Load,
    Clone             = libphx.Mesh_Clone,
    ToBytes           = libphx.Mesh_ToBytes,
    FromBytes         = libphx.Mesh_FromBytes,
    FromObj           = libphx.Mesh_FromObj,
    FromSDF           = libphx.Mesh_FromSDF,
    AddIndex          = libphx.Mesh_AddIndex,
    AddMesh           = libphx.Mesh_AddMesh,
    AddQuad           = libphx.Mesh_AddQuad,
    AddTri            = libphx.Mesh_AddTri,
    AddVertex         = libphx.Mesh_AddVertex,
    AddVertexRaw      = libphx.Mesh_AddVertexRaw,
    GetVersion        = libphx.Mesh_GetVersion,
    IncVersion        = libphx.Mesh_IncVersion,
    GetBound          = libphx.Mesh_GetBound,
    GetCenter         = libphx.Mesh_GetCenter,
    GetIndexCount     = libphx.Mesh_GetIndexCount,
    GetIndexData      = libphx.Mesh_GetIndexData,
    GetRadius         = libphx.Mesh_GetRadius,
    GetVertex         = libphx.Mesh_GetVertex,
    GetVertexCount    = libphx.Mesh_GetVertexCount,
    GetVertexData     = libphx.Mesh_GetVertexData,
    ReserveIndexData  = libphx.Mesh_ReserveIndexData,
    ReserveVertexData = libphx.Mesh_ReserveVertexData,
    Validate          = libphx.Mesh_Validate,
    Draw              = libphx.Mesh_Draw,
    DrawBind          = libphx.Mesh_DrawBind,
    DrawBound         = libphx.Mesh_DrawBound,
    DrawUnbind        = libphx.Mesh_DrawUnbind,
    DrawNormals       = libphx.Mesh_DrawNormals,
    Center            = libphx.Mesh_Center,
    Invert            = libphx.Mesh_Invert,
    RotateX           = libphx.Mesh_RotateX,
    RotateY           = libphx.Mesh_RotateY,
    RotateZ           = libphx.Mesh_RotateZ,
    RotateYPR         = libphx.Mesh_RotateYPR,
    Scale             = libphx.Mesh_Scale,
    ScaleUniform      = libphx.Mesh_ScaleUniform,
    Transform         = libphx.Mesh_Transform,
    Translate         = libphx.Mesh_Translate,
    ComputeAO         = libphx.Mesh_ComputeAO,
    ComputeOcclusion  = libphx.Mesh_ComputeOcclusion,
    ComputeNormals    = libphx.Mesh_ComputeNormals,
    SplitNormals      = libphx.Mesh_SplitNormals,
    Box               = libphx.Mesh_Box,
    BoxSphere         = libphx.Mesh_BoxSphere,
    Plane             = libphx.Mesh_Plane,
  }

  if onDef_Mesh then onDef_Mesh(Mesh, mt) end
  Mesh = setmetatable(Mesh, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Mesh')
  local mt = {
    __index = {
      managed           = function (self) return ffi.gc(self, libphx.Mesh_Free) end,
      acquire           = libphx.Mesh_Acquire,
      free              = libphx.Mesh_Free,
      clone             = libphx.Mesh_Clone,
      toBytes           = libphx.Mesh_ToBytes,
      addIndex          = libphx.Mesh_AddIndex,
      addMesh           = libphx.Mesh_AddMesh,
      addQuad           = libphx.Mesh_AddQuad,
      addTri            = libphx.Mesh_AddTri,
      addVertex         = libphx.Mesh_AddVertex,
      addVertexRaw      = libphx.Mesh_AddVertexRaw,
      getVersion        = libphx.Mesh_GetVersion,
      incVersion        = libphx.Mesh_IncVersion,
      getBound          = libphx.Mesh_GetBound,
      getCenter         = libphx.Mesh_GetCenter,
      getIndexCount     = libphx.Mesh_GetIndexCount,
      getIndexData      = libphx.Mesh_GetIndexData,
      getRadius         = libphx.Mesh_GetRadius,
      getVertex         = libphx.Mesh_GetVertex,
      getVertexCount    = libphx.Mesh_GetVertexCount,
      getVertexData     = libphx.Mesh_GetVertexData,
      reserveIndexData  = libphx.Mesh_ReserveIndexData,
      reserveVertexData = libphx.Mesh_ReserveVertexData,
      validate          = libphx.Mesh_Validate,
      draw              = libphx.Mesh_Draw,
      drawBind          = libphx.Mesh_DrawBind,
      drawBound         = libphx.Mesh_DrawBound,
      drawUnbind        = libphx.Mesh_DrawUnbind,
      drawNormals       = libphx.Mesh_DrawNormals,
      center            = libphx.Mesh_Center,
      invert            = libphx.Mesh_Invert,
      rotateX           = libphx.Mesh_RotateX,
      rotateY           = libphx.Mesh_RotateY,
      rotateZ           = libphx.Mesh_RotateZ,
      rotateYPR         = libphx.Mesh_RotateYPR,
      scale             = libphx.Mesh_Scale,
      scaleUniform      = libphx.Mesh_ScaleUniform,
      transform         = libphx.Mesh_Transform,
      translate         = libphx.Mesh_Translate,
      computeAO         = libphx.Mesh_ComputeAO,
      computeOcclusion  = libphx.Mesh_ComputeOcclusion,
      computeNormals    = libphx.Mesh_ComputeNormals,
      splitNormals      = libphx.Mesh_SplitNormals,
    },
  }

  if onDef_Mesh_t then onDef_Mesh_t(t, mt) end
  Mesh_t = ffi.metatype(t, mt)
end

return Mesh


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

do -- C Definitions
  ffi.cdef [[
    uint32 Hash_FNV32             (void const* buf, int len);
    uint64 Hash_FNV64             (void const* buf, int len);
    uint32 Hash_FNVStr32          (cstr);
    uint64 Hash_FNVStr64          (cstr);
    uint64 Hash_FNV64_Init        ();
    uint64 Hash_FNV64_Incremental (uint64, void const* buf, int len);
    uint32 Hash_Murmur3           (void const* buf, int len);
    uint64 Hash_XX64              (void const* buf, int len, uint64 seed);
  ]]
end

do -- Global Symbol Table
  Hash = {
    FNV32             = libphx.Hash_FNV32,
    FNV64             = libphx.Hash_FNV64,
    FNVStr32          = libphx.Hash_FNVStr32,
    FNVStr64          = libphx.Hash_FNVStr64,
    FNV64_Init        = libphx.Hash_FNV64_Init,
    FNV64_Incremental = libphx.Hash_FNV64_Incremental,
    Murmur3           = libphx.Hash_Murmur3,
    XX64              = libphx.Hash_XX64,
  }

  if onDef_Hash then onDef_Hash(Hash, mt) end
  Hash = setmetatable(Hash, mt)
end

return Hash

repo_name: JoshParnell/libphx

repo_language: C

mime_type: text/x-c++


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

do -- C Definitions
  ffi.cdef [[
    void BlendMode_Pop              ();
    void BlendMode_Push             (BlendMode);
    void BlendMode_PushAdditive     ();
    void BlendMode_PushAlpha        ();
    void BlendMode_PushDisabled     ();
    void BlendMode_PushPreMultAlpha ();
  ]]
end

do -- Global Symbol Table
  BlendMode = {
    Additive     = 0,
    Alpha        = 1,
    Disabled     = 2,
    PreMultAlpha = 3,
    Pop              = libphx.BlendMode_Pop,
    Push             = libphx.BlendMode_Push,
    PushAdditive     = libphx.BlendMode_PushAdditive,
    PushAlpha        = libphx.BlendMode_PushAlpha,
    PushDisabled     = libphx.BlendMode_PushDisabled,
    PushPreMultAlpha = libphx.BlendMode_PushPreMultAlpha,
  }

  if onDef_BlendMode then onDef_BlendMode(BlendMode, mt) end
  BlendMode = setmetatable(BlendMode, mt)
end

return BlendMode


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

do -- Global Symbol Table
  CollisionMask = {
  }

  if onDef_CollisionMask then onDef_CollisionMask(CollisionMask, mt) end
  CollisionMask = setmetatable(CollisionMask, mt)
end

return CollisionMask


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

do -- C Definitions
  ffi.cdef [[
    HashGrid*     HashGrid_Create     (float cellSize, uint32 cellCount);
    void          HashGrid_Free       (HashGrid*);
    HashGridElem* HashGrid_Add        (HashGrid*, void* object, Box3f const*);
    void          HashGrid_Clear      (HashGrid*);
    void          HashGrid_Remove     (HashGrid*, HashGridElem*);
    void          HashGrid_Update     (HashGrid*, HashGridElem*, Box3f const*);
    void**        HashGrid_GetResults (HashGrid*);
    int           HashGrid_QueryBox   (HashGrid*, Box3f const*);
    int           HashGrid_QueryPoint (HashGrid*, Vec3f const*);
  ]]
end

do -- Global Symbol Table
  HashGrid = {
    Create     = libphx.HashGrid_Create,
    Free       = libphx.HashGrid_Free,
    Add        = libphx.HashGrid_Add,
    Clear      = libphx.HashGrid_Clear,
    Remove     = libphx.HashGrid_Remove,
    Update     = libphx.HashGrid_Update,
    GetResults = libphx.HashGrid_GetResults,
    QueryBox   = libphx.HashGrid_QueryBox,
    QueryPoint = libphx.HashGrid_QueryPoint,
  }

  if onDef_HashGrid then onDef_HashGrid(HashGrid, mt) end
  HashGrid = setmetatable(HashGrid, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('HashGrid')
  local mt = {
    __index = {
      managed    = function (self) return ffi.gc(self, libphx.HashGrid_Free) end,
      free       = libphx.HashGrid_Free,
      add        = libphx.HashGrid_Add,
      clear      = libphx.HashGrid_Clear,
      remove     = libphx.HashGrid_Remove,
      update     = libphx.HashGrid_Update,
      getResults = libphx.HashGrid_GetResults,
      queryBox   = libphx.HashGrid_QueryBox,
      queryPoint = libphx.HashGrid_QueryPoint,
    },
  }

  if onDef_HashGrid_t then onDef_HashGrid_t(t, mt) end
  HashGrid_t = ffi.metatype(t, mt)
end

return HashGrid


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

do -- C Definitions
  ffi.cdef [[
    HashMap* HashMap_Create  (uint32 keySize, uint32 capacity);
    void     HashMap_Free    (HashMap*);
    void     HashMap_Foreach (HashMap*, ValueForeach, void* userData);
    void*    HashMap_Get     (HashMap*, void const* key);
    void*    HashMap_GetRaw  (HashMap*, uint64 keyHash);
    void     HashMap_Resize  (HashMap*, uint32 capacity);
    void     HashMap_Set     (HashMap*, void const* key, void* value);
    void     HashMap_SetRaw  (HashMap*, uint64 keyHash, void* value);
  ]]
end

do -- Global Symbol Table
  HashMap = {
    Create  = libphx.HashMap_Create,
    Free    = libphx.HashMap_Free,
    Foreach = libphx.HashMap_Foreach,
    Get     = libphx.HashMap_Get,
    GetRaw  = libphx.HashMap_GetRaw,
    Resize  = libphx.HashMap_Resize,
    Set     = libphx.HashMap_Set,
    SetRaw  = libphx.HashMap_SetRaw,
  }

  if onDef_HashMap then onDef_HashMap(HashMap, mt) end
  HashMap = setmetatable(HashMap, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('HashMap')
  local mt = {
    __index = {
      managed = function (self) return ffi.gc(self, libphx.HashMap_Free) end,
      free    = libphx.HashMap_Free,
      foreach = libphx.HashMap_Foreach,
      get     = libphx.HashMap_Get,
      getRaw  = libphx.HashMap_GetRaw,
      resize  = libphx.HashMap_Resize,
      set     = libphx.HashMap_Set,
      setRaw  = libphx.HashMap_SetRaw,
    },
  }

  if onDef_HashMap_t then onDef_HashMap_t(t, mt) end
  HashMap_t = ffi.metatype(t, mt)
end

return HashMap


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

do -- C Definitions
  ffi.cdef [[
    Trigger*   Trigger_CreateBox        (Vec3f* halfExtents);
    void       Trigger_Free             (Trigger*);
    void       Trigger_Attach           (Trigger*, RigidBody*, Vec3f*);
    void       Trigger_Detach           (Trigger*, RigidBody*);
    void       Trigger_GetBoundingBox   (Trigger*, Box3f*);
    int        Trigger_GetContentsCount (Trigger*);
    RigidBody* Trigger_GetContents      (Trigger*, int);
    void       Trigger_SetCollisionMask (Trigger*, int);
    void       Trigger_SetPos           (Trigger*, Vec3f*);
    void       Trigger_SetPosLocal      (Trigger*, Vec3f*);
  ]]
end

do -- Global Symbol Table
  Trigger = {
    CreateBox        = libphx.Trigger_CreateBox,
    Free             = libphx.Trigger_Free,
    Attach           = libphx.Trigger_Attach,
    Detach           = libphx.Trigger_Detach,
    GetBoundingBox   = libphx.Trigger_GetBoundingBox,
    GetContentsCount = libphx.Trigger_GetContentsCount,
    GetContents      = libphx.Trigger_GetContents,
    SetCollisionMask = libphx.Trigger_SetCollisionMask,
    SetPos           = libphx.Trigger_SetPos,
    SetPosLocal      = libphx.Trigger_SetPosLocal,
  }

  if onDef_Trigger then onDef_Trigger(Trigger, mt) end
  Trigger = setmetatable(Trigger, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Trigger')
  local mt = {
    __index = {
      managed          = function (self) return ffi.gc(self, libphx.Trigger_Free) end,
      free             = libphx.Trigger_Free,
      attach           = libphx.Trigger_Attach,
      detach           = libphx.Trigger_Detach,
      getBoundingBox   = libphx.Trigger_GetBoundingBox,
      getContentsCount = libphx.Trigger_GetContentsCount,
      getContents      = libphx.Trigger_GetContents,
      setCollisionMask = libphx.Trigger_SetCollisionMask,
      setPos           = libphx.Trigger_SetPos,
      setPosLocal      = libphx.Trigger_SetPosLocal,
    },
  }

  if onDef_Trigger_t then onDef_Trigger_t(t, mt) end
  Trigger_t = ffi.metatype(t, mt)
end

return Trigger


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

do -- C Definitions
  ffi.cdef [[
    Timer* Timer_Create      ();
    void   Timer_Free        (Timer*);
    double Timer_GetAndReset (Timer*);
    double Timer_GetElapsed  (Timer*);
    void   Timer_Reset       (Timer*);
  ]]
end

do -- Global Symbol Table
  Timer = {
    Create      = libphx.Timer_Create,
    Free        = libphx.Timer_Free,
    GetAndReset = libphx.Timer_GetAndReset,
    GetElapsed  = libphx.Timer_GetElapsed,
    Reset       = libphx.Timer_Reset,
  }

  if onDef_Timer then onDef_Timer(Timer, mt) end
  Timer = setmetatable(Timer, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Timer')
  local mt = {
    __index = {
      managed     = function (self) return ffi.gc(self, libphx.Timer_Free) end,
      free        = libphx.Timer_Free,
      getAndReset = libphx.Timer_GetAndReset,
      getElapsed  = libphx.Timer_GetElapsed,
      reset       = libphx.Timer_Reset,
    },
  }

  if onDef_Timer_t then onDef_Timer_t(t, mt) end
  Timer_t = ffi.metatype(t, mt)
end

return Timer


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

do -- C Definitions
  ffi.cdef [[
    void Draw_Clear        (float r, float g, float b, float a);
    void Draw_ClearDepth   (float d);
    void Draw_Color        (float r, float g, float b, float a);
    void Draw_Flush        ();
    void Draw_LineWidth    (float width);
    void Draw_PointSize    (float size);
    void Draw_PushAlpha    (float a);
    void Draw_PopAlpha     ();
    void Draw_SmoothLines  (bool);
    void Draw_SmoothPoints (bool);
    void Draw_Border       (float s, float x, float y, float w, float h);
    void Draw_Line         (float x1, float y1, float x2, float y2);
    void Draw_Point        (float x, float y);
    void Draw_Poly         (Vec2f const* points, int count);
    void Draw_Quad         (Vec2f const* p1, Vec2f const* p2, Vec2f const* p3, Vec2f const* p4);
    void Draw_Rect         (float x, float y, float sx, float sy);
    void Draw_Tri          (Vec2f const* p1, Vec2f const* p2, Vec2f const* p3);
    void Draw_Axes         (Vec3f const* pos, Vec3f const* x, Vec3f const* y, Vec3f const* z, float scale, float alpha);
    void Draw_Box3         (Box3f const* box);
    void Draw_Line3        (Vec3f const* p1, Vec3f const* p2);
    void Draw_Plane        (Vec3f const* p, Vec3f const* n, float scale);
    void Draw_Point3       (float x, float y, float z);
    void Draw_Poly3        (Vec3f const* points, int count);
    void Draw_Quad3        (Vec3f const* p1, Vec3f const* p2, Vec3f const* p3, Vec3f const* p4);
    void Draw_Sphere       (Vec3f const* p, float r);
    void Draw_Tri3         (Vec3f const* p1, Vec3f const* p2, Vec3f const* p3);
  ]]
end

do -- Global Symbol Table
  Draw = {
    Clear        = libphx.Draw_Clear,
    ClearDepth   = libphx.Draw_ClearDepth,
    Color        = libphx.Draw_Color,
    Flush        = libphx.Draw_Flush,
    LineWidth    = libphx.Draw_LineWidth,
    PointSize    = libphx.Draw_PointSize,
    PushAlpha    = libphx.Draw_PushAlpha,
    PopAlpha     = libphx.Draw_PopAlpha,
    SmoothLines  = libphx.Draw_SmoothLines,
    SmoothPoints = libphx.Draw_SmoothPoints,
    Border       = libphx.Draw_Border,
    Line         = libphx.Draw_Line,
    Point        = libphx.Draw_Point,
    Poly         = libphx.Draw_Poly,
    Quad         = libphx.Draw_Quad,
    Rect         = libphx.Draw_Rect,
    Tri          = libphx.Draw_Tri,
    Axes         = libphx.Draw_Axes,
    Box3         = libphx.Draw_Box3,
    Line3        = libphx.Draw_Line3,
    Plane        = libphx.Draw_Plane,
    Point3       = libphx.Draw_Point3,
    Poly3        = libphx.Draw_Poly3,
    Quad3        = libphx.Draw_Quad3,
    Sphere       = libphx.Draw_Sphere,
    Tri3         = libphx.Draw_Tri3,
  }

  if onDef_Draw then onDef_Draw(Draw, mt) end
  Draw = setmetatable(Draw, mt)
end

return Draw


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

do -- C Definitions
  ffi.cdef [[
    int        DataFormat_GetSize (DataFormat);
    DataFormat DataFormat_U8;
    DataFormat DataFormat_I8;
    DataFormat DataFormat_U16;
    DataFormat DataFormat_I16;
    DataFormat DataFormat_U32;
    DataFormat DataFormat_I32;
    DataFormat DataFormat_Float;
  ]]
end

do -- Global Symbol Table
  DataFormat = {
    U8    = libphx.DataFormat_U8,
    I8    = libphx.DataFormat_I8,
    U16   = libphx.DataFormat_U16,
    I16   = libphx.DataFormat_I16,
    U32   = libphx.DataFormat_U32,
    I32   = libphx.DataFormat_I32,
    Float = libphx.DataFormat_Float,
    GetSize = libphx.DataFormat_GetSize,
  }

  if onDef_DataFormat then onDef_DataFormat(DataFormat, mt) end
  DataFormat = setmetatable(DataFormat, mt)
end

return DataFormat


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

do -- C Definitions
  ffi.cdef [[
    Directory* Directory_Open       (cstr path);
    void       Directory_Close      (Directory*);
    cstr       Directory_GetNext    (Directory*);
    bool       Directory_Change     (cstr cwd);
    bool       Directory_Create     (cstr path);
    cstr       Directory_GetCurrent ();
    bool       Directory_Remove     (cstr path);
  ]]
end

do -- Global Symbol Table
  Directory = {
    Open       = libphx.Directory_Open,
    Close      = libphx.Directory_Close,
    GetNext    = libphx.Directory_GetNext,
    Change     = libphx.Directory_Change,
    Create     = libphx.Directory_Create,
    GetCurrent = libphx.Directory_GetCurrent,
    Remove     = libphx.Directory_Remove,
  }

  if onDef_Directory then onDef_Directory(Directory, mt) end
  Directory = setmetatable(Directory, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Directory')
  local mt = {
    __index = {
      close      = libphx.Directory_Close,
      getNext    = libphx.Directory_GetNext,
    },
  }

  if onDef_Directory_t then onDef_Directory_t(t, mt) end
  Directory_t = ffi.metatype(t, mt)
end

return Directory


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

do -- C Definitions
  ffi.cdef [[
    void* ShaderVar_Get         (cstr, ShaderVarType);
    void  ShaderVar_PushFloat   (cstr, float);
    void  ShaderVar_PushFloat2  (cstr, float, float);
    void  ShaderVar_PushFloat3  (cstr, float, float, float);
    void  ShaderVar_PushFloat4  (cstr, float, float, float, float);
    void  ShaderVar_PushInt     (cstr, int);
    void  ShaderVar_PushMatrix  (cstr, Matrix*);
    void  ShaderVar_PushTex1D   (cstr, Tex1D*);
    void  ShaderVar_PushTex2D   (cstr, Tex2D*);
    void  ShaderVar_PushTex3D   (cstr, Tex3D*);
    void  ShaderVar_PushTexCube (cstr, TexCube*);
    void  ShaderVar_Pop         (cstr);
  ]]
end

do -- Global Symbol Table
  ShaderVar = {
    Get         = libphx.ShaderVar_Get,
    PushFloat   = libphx.ShaderVar_PushFloat,
    PushFloat2  = libphx.ShaderVar_PushFloat2,
    PushFloat3  = libphx.ShaderVar_PushFloat3,
    PushFloat4  = libphx.ShaderVar_PushFloat4,
    PushInt     = libphx.ShaderVar_PushInt,
    PushMatrix  = libphx.ShaderVar_PushMatrix,
    PushTex1D   = libphx.ShaderVar_PushTex1D,
    PushTex2D   = libphx.ShaderVar_PushTex2D,
    PushTex3D   = libphx.ShaderVar_PushTex3D,
    PushTexCube = libphx.ShaderVar_PushTexCube,
    Pop         = libphx.ShaderVar_Pop,
  }

  if onDef_ShaderVar then onDef_ShaderVar(ShaderVar, mt) end
  ShaderVar = setmetatable(ShaderVar, mt)
end

return ShaderVar


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

do -- Global Symbol Table
  Vec2f = {
  }

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

  if onDef_Vec2f then onDef_Vec2f(Vec2f, mt) end
  Vec2f = setmetatable(Vec2f, mt)
end

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

  if onDef_Vec2f_t then onDef_Vec2f_t(t, mt) end
  Vec2f_t = ffi.metatype(t, mt)
end

return Vec2f


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

do -- Global Symbol Table
  Vec4d = {
  }

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

  if onDef_Vec4d then onDef_Vec4d(Vec4d, mt) end
  Vec4d = setmetatable(Vec4d, mt)
end

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

  if onDef_Vec4d_t then onDef_Vec4d_t(t, mt) end
  Vec4d_t = ffi.metatype(t, mt)
end

return Vec4d


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

do -- C Definitions
  ffi.cdef [[
    void       Input_LoadGamepadDatabase     (cstr filepath);
    bool       Input_GetPressed              (Button);
    bool       Input_GetDown                 (Button);
    bool       Input_GetReleased             (Button);
    float      Input_GetValue                (Button);
    float      Input_GetIdleTime             ();
    void       Input_GetActiveDevice         (Device*);
    DeviceType Input_GetActiveDeviceType     ();
    uint32     Input_GetActiveDeviceID       ();
    float      Input_GetActiveDeviceIdleTime ();
    bool       Input_GetDevicePressed        (Device*, Button);
    bool       Input_GetDeviceDown           (Device*, Button);
    bool       Input_GetDeviceReleased       (Device*, Button);
    float      Input_GetDeviceValue          (Device*, Button);
    float      Input_GetDeviceIdleTime       (Device*);
    void       Input_GetMouseDelta           (Vec2i*);
    float      Input_GetMouseIdleTime        ();
    void       Input_GetMousePosition        (Vec2i*);
    void       Input_GetMouseScroll          (Vec2i*);
    void       Input_SetMousePosition        (Vec2i*);
    void       Input_SetMouseScroll          (Vec2i*);
    void       Input_SetMouseVisible         (bool);
    void       Input_SetMouseVisibleAuto     ();
    float      Input_GetKeyboardIdleTime     ();
    bool       Input_GetKeyboardMod          (Modifier);
    bool       Input_GetKeyboardAlt          ();
    bool       Input_GetKeyboardCtrl         ();
    bool       Input_GetKeyboardShift        ();
    float      Input_GetGamepadIdleTime      (uint32 id);
    bool       Input_GetGamepadPressed       (uint32 id, Button);
    bool       Input_GetGamepadDown          (uint32 id, Button);
    bool       Input_GetGamepadReleased      (uint32 id, Button);
    float      Input_GetGamepadValue         (uint32 id, Button);
    int32      Input_GetEventCount           ();
    bool       Input_GetNextEvent            (InputEvent*);
  ]]
end

do -- Global Symbol Table
  Input = {
    LoadGamepadDatabase     = libphx.Input_LoadGamepadDatabase,
    GetPressed              = libphx.Input_GetPressed,
    GetDown                 = libphx.Input_GetDown,
    GetReleased             = libphx.Input_GetReleased,
    GetValue                = libphx.Input_GetValue,
    GetIdleTime             = libphx.Input_GetIdleTime,
    GetActiveDevice         = libphx.Input_GetActiveDevice,
    GetActiveDeviceType     = libphx.Input_GetActiveDeviceType,
    GetActiveDeviceID       = libphx.Input_GetActiveDeviceID,
    GetActiveDeviceIdleTime = libphx.Input_GetActiveDeviceIdleTime,
    GetDevicePressed        = libphx.Input_GetDevicePressed,
    GetDeviceDown           = libphx.Input_GetDeviceDown,
    GetDeviceReleased       = libphx.Input_GetDeviceReleased,
    GetDeviceValue          = libphx.Input_GetDeviceValue,
    GetDeviceIdleTime       = libphx.Input_GetDeviceIdleTime,
    GetMouseDelta           = libphx.Input_GetMouseDelta,
    GetMouseIdleTime        = libphx.Input_GetMouseIdleTime,
    GetMousePosition        = libphx.Input_GetMousePosition,
    GetMouseScroll          = libphx.Input_GetMouseScroll,
    SetMousePosition        = libphx.Input_SetMousePosition,
    SetMouseScroll          = libphx.Input_SetMouseScroll,
    SetMouseVisible         = libphx.Input_SetMouseVisible,
    SetMouseVisibleAuto     = libphx.Input_SetMouseVisibleAuto,
    GetKeyboardIdleTime     = libphx.Input_GetKeyboardIdleTime,
    GetKeyboardMod          = libphx.Input_GetKeyboardMod,
    GetKeyboardAlt          = libphx.Input_GetKeyboardAlt,
    GetKeyboardCtrl         = libphx.Input_GetKeyboardCtrl,
    GetKeyboardShift        = libphx.Input_GetKeyboardShift,
    GetGamepadIdleTime      = libphx.Input_GetGamepadIdleTime,
    GetGamepadPressed       = libphx.Input_GetGamepadPressed,
    GetGamepadDown          = libphx.Input_GetGamepadDown,
    GetGamepadReleased      = libphx.Input_GetGamepadReleased,
    GetGamepadValue         = libphx.Input_GetGamepadValue,
    GetEventCount           = libphx.Input_GetEventCount,
    GetNextEvent            = libphx.Input_GetNextEvent,
  }

  if onDef_Input then onDef_Input(Input, mt) end
  Input = setmetatable(Input, mt)
end

return Input


text:
local ffi = require('ffi')
local jit = require('jit')

local libphx = {}
do -- Basic Typedefs
  ffi.cdef [[
    typedef unsigned long  ulong;
    typedef unsigned int   uint;
    typedef unsigned short ushort;
    typedef unsigned char  uchar;
    typedef char const*    cstr;
    typedef int8_t         int8;
    typedef int16_t        int16;
    typedef int32_t        int32;
    typedef int64_t        int64;
    typedef uint8_t        uint8;
    typedef uint16_t       uint16;
    typedef uint32_t       uint32;
    typedef uint64_t       uint64;
    typedef int32          BlendMode;
    typedef uint8          BSPNodeRel;
    typedef int32          Button;
    typedef int32          CollisionGroup;
    typedef int32          CollisionMask;
    typedef int32          CubeFace;
    typedef int32          CullFace;
    typedef int32          DataFormat;
    typedef int32          DeviceType;
    typedef uint32         Error;
    typedef int32          Metric;
    typedef int32          Modifier;
    typedef int32          PixelFormat;
    typedef uint8          PointClassification;
    typedef uint8          PolygonClassification;
    typedef int32          ResourceType;
    typedef int32          ShaderVarType;
    typedef int32          SocketType;
    typedef int32          State;
    typedef int32          TexFilter;
    typedef int32          TexFormat;
    typedef int32          TexWrapMode;
    typedef uint64         TimeStamp;
    typedef uint32         WindowMode;
    typedef int            WindowPos;
    typedef int32          GamepadAxis;
    typedef int32          GamepadButton;
    typedef int32          HatDir;
    typedef uchar          Key;
    typedef int32          MouseButton;
    typedef uint8          PhysicsType;
    typedef uint8          SoundState;
  ]]
end

do -- Function Pointer Typedefs
  ffi.cdef [[
    typedef void (*ValueForeach) (void* value, void* userData);
    typedef int  (*ThreadFn    ) (void* data);
    typedef int  (*ThreadPoolFn) (int threadIndex, int threadCount, void* data);
  ]]
end

do -- Opaque Structs
  ffi.cdef [[
    typedef struct BSP          {} BSP;
    typedef struct BoxMesh      {} BoxMesh;
    typedef struct BoxTree      {} BoxTree;
    typedef struct Bytes        {} Bytes;
    typedef struct Directory    {} Directory;
    typedef struct File         {} File;
    typedef struct Font         {} Font;
    typedef struct HashGrid     {} HashGrid;
    typedef struct HashGridElem {} HashGridElem;
    typedef struct HashMap      {} HashMap;
    typedef struct InputBinding {} InputBinding;
    typedef struct KDTree       {} KDTree;
    typedef struct LodMesh      {} LodMesh;
    typedef struct MemPool      {} MemPool;
    typedef struct MemStack     {} MemStack;
    typedef struct Mesh         {} Mesh;
    typedef struct MidiDevice   {} MidiDevice;
    typedef struct Octree       {} Octree;
    typedef struct Physics      {} Physics;
    typedef struct RNG          {} RNG;
    typedef struct RigidBody    {} RigidBody;
    typedef struct RmGui        {} RmGui;
    typedef struct SDF          {} SDF;
    typedef struct Shader       {} Shader;
    typedef struct ShaderState  {} ShaderState;
    typedef struct Socket       {} Socket;
    typedef struct Sound        {} Sound;
    typedef struct SoundDesc    {} SoundDesc;
    typedef struct StrBuffer    {} StrBuffer;
    typedef struct StrMap       {} StrMap;
    typedef struct StrMapIter   {} StrMapIter;
    typedef struct Tex1D        {} Tex1D;
    typedef struct Tex2D        {} Tex2D;
    typedef struct Tex3D        {} Tex3D;
    typedef struct TexCube      {} TexCube;
    typedef struct Thread       {} Thread;
    typedef struct ThreadPool   {} ThreadPool;
    typedef struct Timer        {} Timer;
    typedef struct Trigger      {} Trigger;
    typedef struct Window       {} Window;
  ]]

  libphx.Opaques = {
    'BSP',
    'BoxMesh',
    'BoxTree',
    'Bytes',
    'Directory',
    'File',
    'Font',
    'HashGrid',
    'HashGridElem',
    'HashMap',
    'InputBinding',
    'KDTree',
    'LodMesh',
    'MemPool',
    'MemStack',
    'Mesh',
    'MidiDevice',
    'Octree',
    'Physics',
    'RNG',
    'RigidBody',
    'RmGui',
    'SDF',
    'Shader',
    'ShaderState',
    'Socket',
    'Sound',
    'SoundDesc',
    'StrBuffer',
    'StrMap',
    'StrMapIter',
    'Tex1D',
    'Tex2D',
    'Tex3D',
    'TexCube',
    'Thread',
    'ThreadPool',
    'Timer',
    'Trigger',
    'Window',
  }
end

do -- Transparent Structs
  ffi.cdef [[
    typedef struct BSPNodeRef {
      int32 index;
      uint8 triangleCount;
    } BSPNodeRef;

    typedef struct Box3d {
      double lowerx;
      double lowery;
      double lowerz;
      double upperx;
      double uppery;
      double upperz;
    } Box3d;

    typedef struct Box3f {
      float lowerx;
      float lowery;
      float lowerz;
      float upperx;
      float uppery;
      float upperz;
    } Box3f;

    typedef struct Box3i {
      int lowerx;
      int lowery;
      int lowerz;
      int upperx;
      int uppery;
      int upperz;
    } Box3i;

    typedef struct Collision {
      int        index;
      int        count;
      RigidBody* body0;
      RigidBody* body1;
    } Collision;

    typedef struct Device {
      DeviceType type;
      uint32     id;
    } Device;

    typedef struct InputEvent {
      uint32     timestamp;
      DeviceType devicetype;
      uint32     deviceid;
      Button     button;
      float      value;
      State      state;
    } InputEvent;

    typedef struct IntersectSphereProfiling {
      int32                nodes;
      int32                leaves;
      int32                triangles;
      int32                triangleTests_size;
      int32                triangleTests_capacity;
      struct TriangleTest* triangleTests_data;
    } IntersectSphereProfiling;

    typedef struct LineSegment {
      float p0x;
      float p0y;
      float p0z;
      float p1x;
      float p1y;
      float p1z;
    } LineSegment;

    typedef struct Matrix {
      float m[16];
    } Matrix;

    typedef struct Plane {
      float nx;
      float ny;
      float nz;
      float d;
    } Plane;

    typedef struct Polygon {
      int32         vertices_size;
      int32         vertices_capacity;
      struct Vec3f* vertices_data;
    } Polygon;

    typedef struct Quat {
      float x;
      float y;
      float z;
      float w;
    } Quat;

    typedef struct Ray {
      float px;
      float py;
      float pz;
      float dirx;
      float diry;
      float dirz;
      float tMin;
      float tMax;
    } Ray;

    typedef struct RayCastResult {
      RigidBody* body;
      float      normx;
      float      normy;
      float      normz;
      float      posx;
      float      posy;
      float      posz;
      float      t;
    } RayCastResult;

    typedef struct ShapeCastResult {
      int32       hits_size;
      int32       hits_capacity;
      RigidBody** hits_data;
    } ShapeCastResult;

    typedef struct Sphere {
      float px;
      float py;
      float pz;
      float r;
    } Sphere;

    typedef struct Time {
      int second;
      int minute;
      int hour;
      int dayOfWeek;
      int dayOfMonth;
      int dayOfYear;
      int month;
      int year;
    } Time;

    typedef struct Vec3f {
      float x;
      float y;
      float z;
    } Vec3f;

    typedef struct Triangle {
      Vec3f vertices[3];
    } Triangle;

    typedef struct TriangleTest {
      struct Triangle* triangle;
      bool             hit;
    } TriangleTest;

    typedef struct Vec2d {
      double x;
      double y;
    } Vec2d;

    typedef struct Vec2f {
      float x;
      float y;
    } Vec2f;

    typedef struct Vec2i {
      int x;
      int y;
    } Vec2i;

    typedef struct Vec3d {
      double x;
      double y;
      double z;
    } Vec3d;

    typedef struct Vec3i {
      int x;
      int y;
      int z;
    } Vec3i;

    typedef struct Vec4d {
      double x;
      double y;
      double z;
      double w;
    } Vec4d;

    typedef struct Vec4f {
      float x;
      float y;
      float z;
      float w;
    } Vec4f;

    typedef struct Vec4i {
      int x;
      int y;
      int z;
      int w;
    } Vec4i;

    typedef struct Vertex {
      float px;
      float py;
      float pz;
      float nx;
      float ny;
      float nz;
      float uvx;
      float uvy;
    } Vertex;
  ]]

  libphx.Structs = {
    'BSPNodeRef',
    'Box3d',
    'Box3f',
    'Box3i',
    'Collision',
    'Device',
    'InputEvent',
    'IntersectSphereProfiling',
    'LineSegment',
    'Matrix',
    'Plane',
    'Polygon',
    'Quat',
    'Ray',
    'RayCastResult',
    'ShapeCastResult',
    'Sphere',
    'Time',
    'Vec3f',
    'Triangle',
    'TriangleTest',
    'Vec2d',
    'Vec2f',
    'Vec2i',
    'Vec3d',
    'Vec3i',
    'Vec4d',
    'Vec4f',
    'Vec4i',
    'Vertex',
  }
end

do -- Load Library
  local debug = __debug__ and 'd' or ''
  local arch = jit.arch == 'x86' and '32' or '64'
  local path = string.format('libphx%s%s', arch, debug)
  libphx.lib = ffi.load(path, false)
  assert(libphx.lib, 'Failed to load %s', path)
end

return libphx


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

do -- C Definitions
  ffi.cdef [[
    Matrix* Matrix_Clone              (Matrix const*);
    void    Matrix_Free               (Matrix*);
    bool    Matrix_Equal              (Matrix const*, Matrix const*);
    bool    Matrix_ApproximatelyEqual (Matrix const*, Matrix const*);
    Matrix* Matrix_Inverse            (Matrix const*);
    Matrix* Matrix_InverseTranspose   (Matrix const*);
    Matrix* Matrix_Product            (Matrix const*, Matrix const*);
    Matrix* Matrix_Sum                (Matrix const*, Matrix const*);
    Matrix* Matrix_Transpose          (Matrix const*);
    void    Matrix_IInverse           (Matrix*);
    void    Matrix_IScale             (Matrix*, float);
    void    Matrix_ITranspose         (Matrix*);
    Matrix* Matrix_Identity           ();
    Matrix* Matrix_LookAt             (Vec3f const* pos, Vec3f const* at, Vec3f const* up);
    Matrix* Matrix_LookUp             (Vec3f const* pos, Vec3f const* look, Vec3f const* up);
    Matrix* Matrix_Perspective        (float degreesFovY, float aspect, float zNear, float zFar);
    Matrix* Matrix_RotationX          (float rads);
    Matrix* Matrix_RotationY          (float rads);
    Matrix* Matrix_RotationZ          (float rads);
    Matrix* Matrix_Scaling            (float sx, float sy, float sz);
    Matrix* Matrix_SRT                (float sx, float sy, float sz, float ry, float rp, float rr, float tx, float ty, float tz);
    Matrix* Matrix_Translation        (float tx, float ty, float tz);
    Matrix* Matrix_YawPitchRoll       (float yaw, float pitch, float roll);
    void    Matrix_MulBox             (Matrix const*, Box3f* out, Box3f const* in);
    void    Matrix_MulDir             (Matrix const*, Vec3f* out, float x, float y, float z);
    void    Matrix_MulPoint           (Matrix const*, Vec3f* out, float x, float y, float z);
    void    Matrix_MulVec             (Matrix const*, Vec4f* out, float x, float y, float z, float w);
    void    Matrix_GetForward         (Matrix const*, Vec3f* out);
    void    Matrix_GetRight           (Matrix const*, Vec3f* out);
    void    Matrix_GetUp              (Matrix const*, Vec3f* out);
    void    Matrix_GetPos             (Matrix const*, Vec3f* out);
    void    Matrix_GetRow             (Matrix const*, Vec4f* out, int row);
    Matrix* Matrix_FromBasis          (Vec3f const* x, Vec3f const* y, Vec3f const* z);
    Matrix* Matrix_FromPosRot         (Vec3f const*, Quat const*);
    Matrix* Matrix_FromPosRotScale    (Vec3f const*, Quat const*, float);
    Matrix* Matrix_FromPosBasis       (Vec3f const* pos, Vec3f const* x, Vec3f const* y, Vec3f const* z);
    Matrix* Matrix_FromQuat           (Quat const*);
    void    Matrix_ToQuat             (Matrix const*, Quat* out);
    void    Matrix_Print              (Matrix const*);
    cstr    Matrix_ToString           (Matrix const*);
  ]]
end

do -- Global Symbol Table
  Matrix = {
    Clone              = libphx.Matrix_Clone,
    Free               = libphx.Matrix_Free,
    Equal              = libphx.Matrix_Equal,
    ApproximatelyEqual = libphx.Matrix_ApproximatelyEqual,
    Inverse            = libphx.Matrix_Inverse,
    InverseTranspose   = libphx.Matrix_InverseTranspose,
    Product            = libphx.Matrix_Product,
    Sum                = libphx.Matrix_Sum,
    Transpose          = libphx.Matrix_Transpose,
    IInverse           = libphx.Matrix_IInverse,
    IScale             = libphx.Matrix_IScale,
    ITranspose         = libphx.Matrix_ITranspose,
    Identity           = libphx.Matrix_Identity,
    LookAt             = libphx.Matrix_LookAt,
    LookUp             = libphx.Matrix_LookUp,
    Perspective        = libphx.Matrix_Perspective,
    RotationX          = libphx.Matrix_RotationX,
    RotationY          = libphx.Matrix_RotationY,
    RotationZ          = libphx.Matrix_RotationZ,
    Scaling            = libphx.Matrix_Scaling,
    SRT                = libphx.Matrix_SRT,
    Translation        = libphx.Matrix_Translation,
    YawPitchRoll       = libphx.Matrix_YawPitchRoll,
    MulBox             = libphx.Matrix_MulBox,
    MulDir             = libphx.Matrix_MulDir,
    MulPoint           = libphx.Matrix_MulPoint,
    MulVec             = libphx.Matrix_MulVec,
    GetForward         = libphx.Matrix_GetForward,
    GetRight           = libphx.Matrix_GetRight,
    GetUp              = libphx.Matrix_GetUp,
    GetPos             = libphx.Matrix_GetPos,
    GetRow             = libphx.Matrix_GetRow,
    FromBasis          = libphx.Matrix_FromBasis,
    FromPosRot         = libphx.Matrix_FromPosRot,
    FromPosRotScale    = libphx.Matrix_FromPosRotScale,
    FromPosBasis       = libphx.Matrix_FromPosBasis,
    FromQuat           = libphx.Matrix_FromQuat,
    ToQuat             = libphx.Matrix_ToQuat,
    Print              = libphx.Matrix_Print,
    ToString           = libphx.Matrix_ToString,
  }

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

  if onDef_Matrix then onDef_Matrix(Matrix, mt) end
  Matrix = setmetatable(Matrix, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Matrix')
  local mt = {
    __tostring = function (self) return ffi.string(libphx.Matrix_ToString(self)) end,
    __index = {
      clone              = function (x) return Matrix_t(x) end,
      managed            = function (self) return ffi.gc(self, libphx.Matrix_Free) end,
      clone              = libphx.Matrix_Clone,
      free               = libphx.Matrix_Free,
      equal              = libphx.Matrix_Equal,
      approximatelyEqual = libphx.Matrix_ApproximatelyEqual,
      inverse            = libphx.Matrix_Inverse,
      inverseTranspose   = libphx.Matrix_InverseTranspose,
      product            = libphx.Matrix_Product,
      sum                = libphx.Matrix_Sum,
      transpose          = libphx.Matrix_Transpose,
      iInverse           = libphx.Matrix_IInverse,
      iScale             = libphx.Matrix_IScale,
      iTranspose         = libphx.Matrix_ITranspose,
      mulBox             = libphx.Matrix_MulBox,
      mulDir             = libphx.Matrix_MulDir,
      mulPoint           = libphx.Matrix_MulPoint,
      mulVec             = libphx.Matrix_MulVec,
      getForward         = libphx.Matrix_GetForward,
      getRight           = libphx.Matrix_GetRight,
      getUp              = libphx.Matrix_GetUp,
      getPos             = libphx.Matrix_GetPos,
      getRow             = libphx.Matrix_GetRow,
      toQuat             = libphx.Matrix_ToQuat,
      print              = libphx.Matrix_Print,
      toString           = libphx.Matrix_ToString,
    },
  }

  if onDef_Matrix_t then onDef_Matrix_t(t, mt) end
  Matrix_t = ffi.metatype(t, mt)
end

return Matrix


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

do -- C Definitions
  ffi.cdef [[
    TexWrapMode TexWrapMode_Clamp;
    TexWrapMode TexWrapMode_MirrorClamp;
    TexWrapMode TexWrapMode_MirrorRepeat;
    TexWrapMode TexWrapMode_Repeat;
  ]]
end

do -- Global Symbol Table
  TexWrapMode = {
    Clamp        = libphx.TexWrapMode_Clamp,
    MirrorClamp  = libphx.TexWrapMode_MirrorClamp,
    MirrorRepeat = libphx.TexWrapMode_MirrorRepeat,
    Repeat       = libphx.TexWrapMode_Repeat,
  }

  if onDef_TexWrapMode then onDef_TexWrapMode(TexWrapMode, mt) end
  TexWrapMode = setmetatable(TexWrapMode, mt)
end

return TexWrapMode


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

do -- C Definitions
  ffi.cdef [[
    Time Time_GetLocal ();
    Time Time_GetUTC   ();
    uint Time_GetRaw   ();
  ]]
end

do -- Global Symbol Table
  Time = {
    GetLocal = libphx.Time_GetLocal,
    GetUTC   = libphx.Time_GetUTC,
    GetRaw   = libphx.Time_GetRaw,
  }

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

  if onDef_Time then onDef_Time(Time, mt) end
  Time = setmetatable(Time, mt)
end

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

  if onDef_Time_t then onDef_Time_t(t, mt) end
  Time_t = ffi.metatype(t, mt)
end

return Time


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

do -- C Definitions
  ffi.cdef [[
    Tex2D*    Tex2D_Create        (int sx, int sy, TexFormat);
    Tex2D*    Tex2D_Load          (cstr name);
    Tex2D*    Tex2D_ScreenCapture ();
    void      Tex2D_Acquire       (Tex2D*);
    void      Tex2D_Free          (Tex2D*);
    void      Tex2D_Pop           (Tex2D*);
    void      Tex2D_Push          (Tex2D*);
    void      Tex2D_PushLevel     (Tex2D*, int level);
    void      Tex2D_Clear         (Tex2D*, float r, float g, float b, float a);
    Tex2D*    Tex2D_Clone         (Tex2D*);
    void      Tex2D_Draw          (Tex2D*, float x, float y, float sx, float sy);
    void      Tex2D_DrawEx        (Tex2D*, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1);
    void      Tex2D_GenMipmap     (Tex2D*);
    void      Tex2D_GetData       (Tex2D*, void*, PixelFormat, DataFormat);
    Bytes*    Tex2D_GetDataBytes  (Tex2D*, PixelFormat, DataFormat);
    TexFormat Tex2D_GetFormat     (Tex2D*);
    uint      Tex2D_GetHandle     (Tex2D*);
    void      Tex2D_GetSize       (Tex2D*, Vec2i* out);
    void      Tex2D_GetSizeLevel  (Tex2D*, Vec2i* out, int level);
    void      Tex2D_SetAnisotropy (Tex2D*, float);
    void      Tex2D_SetData       (Tex2D*, void const*, PixelFormat, DataFormat);
    void      Tex2D_SetDataBytes  (Tex2D*, Bytes*, PixelFormat, DataFormat);
    void      Tex2D_SetMagFilter  (Tex2D*, TexFilter);
    void      Tex2D_SetMinFilter  (Tex2D*, TexFilter);
    void      Tex2D_SetMipRange   (Tex2D*, int minLevel, int maxLevel);
    void      Tex2D_SetTexel      (Tex2D*, int x, int y, float r, float g, float b, float a);
    void      Tex2D_SetWrapMode   (Tex2D*, TexWrapMode);
    void      Tex2D_Save          (Tex2D*, cstr path);
  ]]
end

do -- Global Symbol Table
  Tex2D = {
    Create        = libphx.Tex2D_Create,
    Load          = libphx.Tex2D_Load,
    ScreenCapture = libphx.Tex2D_ScreenCapture,
    Acquire       = libphx.Tex2D_Acquire,
    Free          = libphx.Tex2D_Free,
    Pop           = libphx.Tex2D_Pop,
    Push          = libphx.Tex2D_Push,
    PushLevel     = libphx.Tex2D_PushLevel,
    Clear         = libphx.Tex2D_Clear,
    Clone         = libphx.Tex2D_Clone,
    Draw          = libphx.Tex2D_Draw,
    DrawEx        = libphx.Tex2D_DrawEx,
    GenMipmap     = libphx.Tex2D_GenMipmap,
    GetData       = libphx.Tex2D_GetData,
    GetDataBytes  = libphx.Tex2D_GetDataBytes,
    GetFormat     = libphx.Tex2D_GetFormat,
    GetHandle     = libphx.Tex2D_GetHandle,
    GetSize       = libphx.Tex2D_GetSize,
    GetSizeLevel  = libphx.Tex2D_GetSizeLevel,
    SetAnisotropy = libphx.Tex2D_SetAnisotropy,
    SetData       = libphx.Tex2D_SetData,
    SetDataBytes  = libphx.Tex2D_SetDataBytes,
    SetMagFilter  = libphx.Tex2D_SetMagFilter,
    SetMinFilter  = libphx.Tex2D_SetMinFilter,
    SetMipRange   = libphx.Tex2D_SetMipRange,
    SetTexel      = libphx.Tex2D_SetTexel,
    SetWrapMode   = libphx.Tex2D_SetWrapMode,
    Save          = libphx.Tex2D_Save,
  }

  if onDef_Tex2D then onDef_Tex2D(Tex2D, mt) end
  Tex2D = setmetatable(Tex2D, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Tex2D')
  local mt = {
    __index = {
      managed       = function (self) return ffi.gc(self, libphx.Tex2D_Free) end,
      acquire       = libphx.Tex2D_Acquire,
      free          = libphx.Tex2D_Free,
      pop           = libphx.Tex2D_Pop,
      push          = libphx.Tex2D_Push,
      pushLevel     = libphx.Tex2D_PushLevel,
      clear         = libphx.Tex2D_Clear,
      clone         = libphx.Tex2D_Clone,
      draw          = libphx.Tex2D_Draw,
      drawEx        = libphx.Tex2D_DrawEx,
      genMipmap     = libphx.Tex2D_GenMipmap,
      getData       = libphx.Tex2D_GetData,
      getDataBytes  = libphx.Tex2D_GetDataBytes,
      getFormat     = libphx.Tex2D_GetFormat,
      getHandle     = libphx.Tex2D_GetHandle,
      getSize       = libphx.Tex2D_GetSize,
      getSizeLevel  = libphx.Tex2D_GetSizeLevel,
      setAnisotropy = libphx.Tex2D_SetAnisotropy,
      setData       = libphx.Tex2D_SetData,
      setDataBytes  = libphx.Tex2D_SetDataBytes,
      setMagFilter  = libphx.Tex2D_SetMagFilter,
      setMinFilter  = libphx.Tex2D_SetMinFilter,
      setMipRange   = libphx.Tex2D_SetMipRange,
      setTexel      = libphx.Tex2D_SetTexel,
      setWrapMode   = libphx.Tex2D_SetWrapMode,
      save          = libphx.Tex2D_Save,
    },
  }

  if onDef_Tex2D_t then onDef_Tex2D_t(t, mt) end
  Tex2D_t = ffi.metatype(t, mt)
end

return Tex2D


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

do -- C Definitions
  ffi.cdef [[
    int         MidiDevice_GetCount       ();
    MidiDevice* MidiDevice_Open           (int index);
    void        MidiDevice_Close          (MidiDevice*);
    cstr        MidiDevice_GetNameByIndex (int index);
    bool        MidiDevice_HasMessage     (MidiDevice*);
    Vec2i       MidiDevice_PopMessage     (MidiDevice*);
  ]]
end

do -- Global Symbol Table
  MidiDevice = {
    GetCount       = libphx.MidiDevice_GetCount,
    Open           = libphx.MidiDevice_Open,
    Close          = libphx.MidiDevice_Close,
    GetNameByIndex = libphx.MidiDevice_GetNameByIndex,
    HasMessage     = libphx.MidiDevice_HasMessage,
    PopMessage     = libphx.MidiDevice_PopMessage,
  }

  if onDef_MidiDevice then onDef_MidiDevice(MidiDevice, mt) end
  MidiDevice = setmetatable(MidiDevice, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('MidiDevice')
  local mt = {
    __index = {
      close          = libphx.MidiDevice_Close,
      hasMessage     = libphx.MidiDevice_HasMessage,
      popMessage     = libphx.MidiDevice_PopMessage,
    },
  }

  if onDef_MidiDevice_t then onDef_MidiDevice_t(t, mt) end
  MidiDevice_t = ffi.metatype(t, mt)
end

return MidiDevice


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

do -- C Definitions
  ffi.cdef [[
    void ClipRect_Push          (float x, float y, float sx, float sy);
    void ClipRect_PushCombined  (float x, float y, float sx, float sy);
    void ClipRect_PushDisabled  ();
    void ClipRect_PushTransform (float tx, float ty, float sx, float sy);
    void ClipRect_Pop           ();
    void ClipRect_PopTransform  ();
  ]]
end

do -- Global Symbol Table
  ClipRect = {
    Push          = libphx.ClipRect_Push,
    PushCombined  = libphx.ClipRect_PushCombined,
    PushDisabled  = libphx.ClipRect_PushDisabled,
    PushTransform = libphx.ClipRect_PushTransform,
    Pop           = libphx.ClipRect_Pop,
    PopTransform  = libphx.ClipRect_PopTransform,
  }

  if onDef_ClipRect then onDef_ClipRect(ClipRect, mt) end
  ClipRect = setmetatable(ClipRect, mt)
end

return ClipRect


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

do -- C Definitions
  ffi.cdef [[
    void  Viewport_Pop       ();
    void  Viewport_Push      (int x, int y, int sx, int sy, bool isWindow);
    float Viewport_GetAspect ();
    void  Viewport_GetSize   (Vec2i* out);
  ]]
end

do -- Global Symbol Table
  Viewport = {
    Pop       = libphx.Viewport_Pop,
    Push      = libphx.Viewport_Push,
    GetAspect = libphx.Viewport_GetAspect,
    GetSize   = libphx.Viewport_GetSize,
  }

  if onDef_Viewport then onDef_Viewport(Viewport, mt) end
  Viewport = setmetatable(Viewport, mt)
end

return Viewport


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

do -- C Definitions
  ffi.cdef [[
    Physics* Physics_Create                 ();
    void     Physics_Free                   (Physics*);
    void     Physics_AddRigidBody           (Physics*, RigidBody*);
    void     Physics_RemoveRigidBody        (Physics*, RigidBody*);
    void     Physics_AddTrigger             (Physics*, Trigger*);
    void     Physics_RemoveTrigger          (Physics*, Trigger*);
    bool     Physics_GetNextCollision       (Physics*, Collision*);
    void     Physics_Update                 (Physics*, float dt);
    void     Physics_RayCast                (Physics*, Ray*, RayCastResult*);
    void     Physics_SphereCast             (Physics*, Sphere*, ShapeCastResult*);
    void     Physics_BoxCast                (Physics*, Vec3f* pos, Quat* rot, Vec3f* halfExtents, ShapeCastResult*);
    bool     Physics_SphereOverlap          (Physics*, Sphere*);
    bool     Physics_BoxOverlap             (Physics*, Vec3f* pos, Quat* rot, Vec3f* halfExtents);
    void     Physics_PrintProfiling         (Physics*);
    void     Physics_DrawBoundingBoxesLocal (Physics*);
    void     Physics_DrawBoundingBoxesWorld (Physics*);
    void     Physics_DrawTriggers           (Physics*);
    void     Physics_DrawWireframes         (Physics*);
  ]]
end

do -- Global Symbol Table
  Physics = {
    Create                 = libphx.Physics_Create,
    Free                   = libphx.Physics_Free,
    AddRigidBody           = libphx.Physics_AddRigidBody,
    RemoveRigidBody        = libphx.Physics_RemoveRigidBody,
    AddTrigger             = libphx.Physics_AddTrigger,
    RemoveTrigger          = libphx.Physics_RemoveTrigger,
    GetNextCollision       = libphx.Physics_GetNextCollision,
    Update                 = libphx.Physics_Update,
    RayCast                = libphx.Physics_RayCast,
    SphereCast             = libphx.Physics_SphereCast,
    BoxCast                = libphx.Physics_BoxCast,
    SphereOverlap          = libphx.Physics_SphereOverlap,
    BoxOverlap             = libphx.Physics_BoxOverlap,
    PrintProfiling         = libphx.Physics_PrintProfiling,
    DrawBoundingBoxesLocal = libphx.Physics_DrawBoundingBoxesLocal,
    DrawBoundingBoxesWorld = libphx.Physics_DrawBoundingBoxesWorld,
    DrawTriggers           = libphx.Physics_DrawTriggers,
    DrawWireframes         = libphx.Physics_DrawWireframes,
  }

  if onDef_Physics then onDef_Physics(Physics, mt) end
  Physics = setmetatable(Physics, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Physics')
  local mt = {
    __index = {
      managed                = function (self) return ffi.gc(self, libphx.Physics_Free) end,
      free                   = libphx.Physics_Free,
      addRigidBody           = libphx.Physics_AddRigidBody,
      removeRigidBody        = libphx.Physics_RemoveRigidBody,
      addTrigger             = libphx.Physics_AddTrigger,
      removeTrigger          = libphx.Physics_RemoveTrigger,
      getNextCollision       = libphx.Physics_GetNextCollision,
      update                 = libphx.Physics_Update,
      rayCast                = libphx.Physics_RayCast,
      sphereCast             = libphx.Physics_SphereCast,
      boxCast                = libphx.Physics_BoxCast,
      sphereOverlap          = libphx.Physics_SphereOverlap,
      boxOverlap             = libphx.Physics_BoxOverlap,
      printProfiling         = libphx.Physics_PrintProfiling,
      drawBoundingBoxesLocal = libphx.Physics_DrawBoundingBoxesLocal,
      drawBoundingBoxesWorld = libphx.Physics_DrawBoundingBoxesWorld,
      drawTriggers           = libphx.Physics_DrawTriggers,
      drawWireframes         = libphx.Physics_DrawWireframes,
    },
  }

  if onDef_Physics_t then onDef_Physics_t(t, mt) end
  Physics_t = ffi.metatype(t, mt)
end

return Physics


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

do -- Global Symbol Table
  Vec3d = {
  }

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

  if onDef_Vec3d then onDef_Vec3d(Vec3d, mt) end
  Vec3d = setmetatable(Vec3d, mt)
end

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

  if onDef_Vec3d_t then onDef_Vec3d_t(t, mt) end
  Vec3d_t = ffi.metatype(t, mt)
end

return Vec3d


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

do -- C Definitions
  ffi.cdef [[
    cstr  State_ToString (State);
    State State_Null;
    State State_Changed;
    State State_Pressed;
    State State_Down;
    State State_Released;
  ]]
end

do -- Global Symbol Table
  State = {
    Null     = libphx.State_Null,
    Changed  = libphx.State_Changed,
    Pressed  = libphx.State_Pressed,
    Down     = libphx.State_Down,
    Released = libphx.State_Released,
    ToString = libphx.State_ToString,
  }

  if onDef_State then onDef_State(State, mt) end
  State = setmetatable(State, mt)
end

return State


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

do -- Global Symbol Table
  CollisionGroup = {
  }

  if onDef_CollisionGroup then onDef_CollisionGroup(CollisionGroup, mt) end
  CollisionGroup = setmetatable(CollisionGroup, mt)
end

return CollisionGroup


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

do -- Global Symbol Table
  Box3f = {
  }

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

  if onDef_Box3f then onDef_Box3f(Box3f, mt) end
  Box3f = setmetatable(Box3f, mt)
end

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

  if onDef_Box3f_t then onDef_Box3f_t(t, mt) end
  Box3f_t = ffi.metatype(t, mt)
end

return Box3f


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

do -- C Definitions
  ffi.cdef [[
    cstr OS_GetClipboard   ();
    int  OS_GetCPUCount    ();
    cstr OS_GetVideoDriver ();
    void OS_SetClipboard   (cstr text);
  ]]
end

do -- Global Symbol Table
  OS = {
    GetClipboard   = libphx.OS_GetClipboard,
    GetCPUCount    = libphx.OS_GetCPUCount,
    GetVideoDriver = libphx.OS_GetVideoDriver,
    SetClipboard   = libphx.OS_SetClipboard,
  }

  if onDef_OS then onDef_OS(OS, mt) end
  OS = setmetatable(OS, mt)
end

return OS


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

do -- C Definitions
  ffi.cdef [[
    RNG*   RNG_Create          (uint64 seed);
    RNG*   RNG_FromStr         (cstr);
    RNG*   RNG_FromTime        ();
    void   RNG_Free            (RNG*);
    void   RNG_Rewind          (RNG*);
    bool   RNG_Chance          (RNG*, double probability);
    int32  RNG_Get31           (RNG*);
    uint32 RNG_Get32           (RNG*);
    uint64 RNG_Get64           (RNG*);
    double RNG_GetAngle        (RNG*);
    double RNG_GetErlang       (RNG*, int k);
    double RNG_GetExp          (RNG*);
    double RNG_GetGaussian     (RNG*);
    int    RNG_GetInt          (RNG*, int lower, int upper);
    RNG*   RNG_GetRNG          (RNG*);
    double RNG_GetSign         (RNG*);
    double RNG_GetUniform      (RNG*);
    double RNG_GetUniformRange (RNG*, double lower, double upper);
    void   RNG_GetAxis2        (RNG*, Vec2f* out);
    void   RNG_GetAxis3        (RNG*, Vec3f* out);
    void   RNG_GetDir2         (RNG*, Vec2f* out);
    void   RNG_GetDir3         (RNG*, Vec3f* out);
    void   RNG_GetDisc         (RNG*, Vec2f* out);
    void   RNG_GetSphere       (RNG*, Vec3f* out);
    void   RNG_GetVec2         (RNG*, Vec2f* out, double lower, double upper);
    void   RNG_GetVec3         (RNG*, Vec3f* out, double lower, double upper);
    void   RNG_GetVec4         (RNG*, Vec4f* out, double lower, double upper);
    void   RNG_GetQuat         (RNG*, Quat* out);
  ]]
end

do -- Global Symbol Table
  RNG = {
    Create          = libphx.RNG_Create,
    FromStr         = libphx.RNG_FromStr,
    FromTime        = libphx.RNG_FromTime,
    Free            = libphx.RNG_Free,
    Rewind          = libphx.RNG_Rewind,
    Chance          = libphx.RNG_Chance,
    Get31           = libphx.RNG_Get31,
    Get32           = libphx.RNG_Get32,
    Get64           = libphx.RNG_Get64,
    GetAngle        = libphx.RNG_GetAngle,
    GetErlang       = libphx.RNG_GetErlang,
    GetExp          = libphx.RNG_GetExp,
    GetGaussian     = libphx.RNG_GetGaussian,
    GetInt          = libphx.RNG_GetInt,
    GetRNG          = libphx.RNG_GetRNG,
    GetSign         = libphx.RNG_GetSign,
    GetUniform      = libphx.RNG_GetUniform,
    GetUniformRange = libphx.RNG_GetUniformRange,
    GetAxis2        = libphx.RNG_GetAxis2,
    GetAxis3        = libphx.RNG_GetAxis3,
    GetDir2         = libphx.RNG_GetDir2,
    GetDir3         = libphx.RNG_GetDir3,
    GetDisc         = libphx.RNG_GetDisc,
    GetSphere       = libphx.RNG_GetSphere,
    GetVec2         = libphx.RNG_GetVec2,
    GetVec3         = libphx.RNG_GetVec3,
    GetVec4         = libphx.RNG_GetVec4,
    GetQuat         = libphx.RNG_GetQuat,
  }

  if onDef_RNG then onDef_RNG(RNG, mt) end
  RNG = setmetatable(RNG, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('RNG')
  local mt = {
    __index = {
      managed         = function (self) return ffi.gc(self, libphx.RNG_Free) end,
      free            = libphx.RNG_Free,
      rewind          = libphx.RNG_Rewind,
      chance          = libphx.RNG_Chance,
      get31           = libphx.RNG_Get31,
      get32           = libphx.RNG_Get32,
      get64           = libphx.RNG_Get64,
      getAngle        = libphx.RNG_GetAngle,
      getErlang       = libphx.RNG_GetErlang,
      getExp          = libphx.RNG_GetExp,
      getGaussian     = libphx.RNG_GetGaussian,
      getInt          = libphx.RNG_GetInt,
      getRNG          = libphx.RNG_GetRNG,
      getSign         = libphx.RNG_GetSign,
      getUniform      = libphx.RNG_GetUniform,
      getUniformRange = libphx.RNG_GetUniformRange,
      getAxis2        = libphx.RNG_GetAxis2,
      getAxis3        = libphx.RNG_GetAxis3,
      getDir2         = libphx.RNG_GetDir2,
      getDir3         = libphx.RNG_GetDir3,
      getDisc         = libphx.RNG_GetDisc,
      getSphere       = libphx.RNG_GetSphere,
      getVec2         = libphx.RNG_GetVec2,
      getVec3         = libphx.RNG_GetVec3,
      getVec4         = libphx.RNG_GetVec4,
      getQuat         = libphx.RNG_GetQuat,
    },
  }

  if onDef_RNG_t then onDef_RNG_t(t, mt) end
  RNG_t = ffi.metatype(t, mt)
end

return RNG


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

do -- C Definitions
  ffi.cdef [[
    void Error_Print (Error);
  ]]
end

do -- Global Symbol Table
  Error = {
    None         = 0x00000000,
    Null         = 0x00000001,
    Invalid      = 0x00000002,
    Overflow     = 0x00000004,
    Underflow    = 0x00000008,
    Empty        = 0x00000010,
    NaN          = 0x00000020,
    Degenerate   = 0x00000040,
    BadCount     = 0x00000080,
    Input        = 0x00000100,
    Intermediate = 0x00000200,
    Output       = 0x00000400,
    Stack        = 0x00010000,
    Heap         = 0x00020000,
    Buffer       = 0x00040000,
    Path         = 0x00080000,
    Index        = 0x00100000,
    Vertex       = 0x00200000,
    VertPos      = 0x00400000,
    VertNorm     = 0x00800000,
    VertUV       = 0x01000000,
    Print = libphx.Error_Print,
  }

  if onDef_Error then onDef_Error(Error, mt) end
  Error = setmetatable(Error, mt)
end

return Error


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

do -- C Definitions
  ffi.cdef [[
    void DepthTest_Pop          ();
    void DepthTest_Push         (bool);
    void DepthTest_PushDisabled ();
    void DepthTest_PushEnabled  ();
  ]]
end

do -- Global Symbol Table
  DepthTest = {
    Pop          = libphx.DepthTest_Pop,
    Push         = libphx.DepthTest_Push,
    PushDisabled = libphx.DepthTest_PushDisabled,
    PushEnabled  = libphx.DepthTest_PushEnabled,
  }

  if onDef_DepthTest then onDef_DepthTest(DepthTest, mt) end
  DepthTest = setmetatable(DepthTest, mt)
end

return DepthTest


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

do -- Global Symbol Table
  TriangleTest = {
  }

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

  if onDef_TriangleTest then onDef_TriangleTest(TriangleTest, mt) end
  TriangleTest = setmetatable(TriangleTest, mt)
end

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

  if onDef_TriangleTest_t then onDef_TriangleTest_t(t, mt) end
  TriangleTest_t = ffi.metatype(t, mt)
end

return TriangleTest


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

do -- C Definitions
  ffi.cdef [[
    DeviceType DeviceType_FromButton (Button);
    cstr       DeviceType_ToString   (DeviceType);
    DeviceType DeviceType_Null;
    DeviceType DeviceType_Mouse;
    DeviceType DeviceType_Keyboard;
    DeviceType DeviceType_Gamepad;
  ]]
end

do -- Global Symbol Table
  DeviceType = {
    Null     = libphx.DeviceType_Null,
    Mouse    = libphx.DeviceType_Mouse,
    Keyboard = libphx.DeviceType_Keyboard,
    Gamepad  = libphx.DeviceType_Gamepad,
    COUNT    = 4,
    FromButton = libphx.DeviceType_FromButton,
    ToString   = libphx.DeviceType_ToString,
  }

  if onDef_DeviceType then onDef_DeviceType(DeviceType, mt) end
  DeviceType = setmetatable(DeviceType, mt)
end

return DeviceType


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

do -- C Definitions
  ffi.cdef [[
    StrBuffer* StrBuffer_Create    (uint32 capacity);
    StrBuffer* StrBuffer_FromStr   (cstr);
    void       StrBuffer_Free      (StrBuffer*);
    void       StrBuffer_Append    (StrBuffer*, StrBuffer*);
    void       StrBuffer_AppendStr (StrBuffer*, cstr);
    void       StrBuffer_Set       (StrBuffer*, cstr format, ...);
    StrBuffer* StrBuffer_Clone     (StrBuffer*);
    cstr       StrBuffer_GetData   (StrBuffer*);
  ]]
end

do -- Global Symbol Table
  StrBuffer = {
    Create    = libphx.StrBuffer_Create,
    FromStr   = libphx.StrBuffer_FromStr,
    Free      = libphx.StrBuffer_Free,
    Append    = libphx.StrBuffer_Append,
    AppendStr = libphx.StrBuffer_AppendStr,
    Set       = libphx.StrBuffer_Set,
    Clone     = libphx.StrBuffer_Clone,
    GetData   = libphx.StrBuffer_GetData,
  }

  if onDef_StrBuffer then onDef_StrBuffer(StrBuffer, mt) end
  StrBuffer = setmetatable(StrBuffer, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('StrBuffer')
  local mt = {
    __index = {
      managed   = function (self) return ffi.gc(self, libphx.StrBuffer_Free) end,
      free      = libphx.StrBuffer_Free,
      append    = libphx.StrBuffer_Append,
      appendStr = libphx.StrBuffer_AppendStr,
      set       = libphx.StrBuffer_Set,
      clone     = libphx.StrBuffer_Clone,
      getData   = libphx.StrBuffer_GetData,
    },
  }

  if onDef_StrBuffer_t then onDef_StrBuffer_t(t, mt) end
  StrBuffer_t = ffi.metatype(t, mt)
end

return StrBuffer


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

do -- C Definitions
  ffi.cdef [[
    bool Device_Equal    (Device*, Device*);
    cstr Device_ToString (Device*);
  ]]
end

do -- Global Symbol Table
  Device = {
    Equal    = libphx.Device_Equal,
    ToString = libphx.Device_ToString,
  }

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

  if onDef_Device then onDef_Device(Device, mt) end
  Device = setmetatable(Device, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Device')
  local mt = {
    __tostring = function (self) return ffi.string(libphx.Device_ToString(self)) end,
    __index = {
      clone    = function (x) return Device_t(x) end,
      equal    = libphx.Device_Equal,
      toString = libphx.Device_ToString,
    },
  }

  if onDef_Device_t then onDef_Device_t(t, mt) end
  Device_t = ffi.metatype(t, mt)
end

return Device


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

do -- C Definitions
  ffi.cdef [[
    Font* Font_Load          (cstr name, int size);
    void  Font_Acquire       (Font*);
    void  Font_Free          (Font*);
    void  Font_Draw          (Font*, cstr text, float x, float y, float r, float g, float b, float a);
    void  Font_DrawShaded    (Font*, cstr text, float x, float y);
    int   Font_GetLineHeight (Font*);
    void  Font_GetSize       (Font*, Vec4i* out, cstr text);
    void  Font_GetSize2      (Font*, Vec2i* out, cstr text);
  ]]
end

do -- Global Symbol Table
  Font = {
    Load          = libphx.Font_Load,
    Acquire       = libphx.Font_Acquire,
    Free          = libphx.Font_Free,
    Draw          = libphx.Font_Draw,
    DrawShaded    = libphx.Font_DrawShaded,
    GetLineHeight = libphx.Font_GetLineHeight,
    GetSize       = libphx.Font_GetSize,
    GetSize2      = libphx.Font_GetSize2,
  }

  if onDef_Font then onDef_Font(Font, mt) end
  Font = setmetatable(Font, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Font')
  local mt = {
    __index = {
      managed       = function (self) return ffi.gc(self, libphx.Font_Free) end,
      acquire       = libphx.Font_Acquire,
      free          = libphx.Font_Free,
      draw          = libphx.Font_Draw,
      drawShaded    = libphx.Font_DrawShaded,
      getLineHeight = libphx.Font_GetLineHeight,
      getSize       = libphx.Font_GetSize,
      getSize2      = libphx.Font_GetSize2,
    },
  }

  if onDef_Font_t then onDef_Font_t(t, mt) end
  Font_t = ffi.metatype(t, mt)
end

return Font


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

do -- C Definitions
  ffi.cdef [[
    void* Memory_Alloc   (size_t);
    void* Memory_Calloc  (size_t n, size_t size);
    void  Memory_Free    (void* ptr);
    void  Memory_MemCopy (void* dst, void const* src, size_t size);
    void  Memory_MemMove (void* dst, void const* src, size_t size);
    void* Memory_Realloc (void* ptr, size_t newSize);
  ]]
end

do -- Global Symbol Table
  Memory = {
    Alloc   = libphx.Memory_Alloc,
    Calloc  = libphx.Memory_Calloc,
    Free    = libphx.Memory_Free,
    MemCopy = libphx.Memory_MemCopy,
    MemMove = libphx.Memory_MemMove,
    Realloc = libphx.Memory_Realloc,
  }

  if onDef_Memory then onDef_Memory(Memory, mt) end
  Memory = setmetatable(Memory, mt)
end

return Memory


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

do -- Global Symbol Table
  Collision = {
  }

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

  if onDef_Collision then onDef_Collision(Collision, mt) end
  Collision = setmetatable(Collision, mt)
end

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

  if onDef_Collision_t then onDef_Collision_t(t, mt) end
  Collision_t = ffi.metatype(t, mt)
end

return Collision


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

do -- C Definitions
  ffi.cdef [[
    Window* Window_Create           (cstr title, WindowPos x, WindowPos y, int sx, int sy, WindowMode mode);
    void    Window_Free             (Window*);
    void    Window_BeginDraw        (Window*);
    void    Window_EndDraw          (Window*);
    void    Window_GetPosition      (Window*, Vec2i* out);
    void    Window_GetSize          (Window*, Vec2i* out);
    cstr    Window_GetTitle         (Window*);
    void    Window_SetFullscreen    (Window*, bool);
    void    Window_SetPosition      (Window*, WindowPos, WindowPos);
    void    Window_SetSize          (Window*, int, int);
    void    Window_SetTitle         (Window*, cstr);
    void    Window_SetVsync         (Window*, bool);
    void    Window_ToggleFullscreen (Window*);
    void    Window_Hide             (Window*);
    void    Window_Show             (Window*);
  ]]
end

do -- Global Symbol Table
  Window = {
    Create           = libphx.Window_Create,
    Free             = libphx.Window_Free,
    BeginDraw        = libphx.Window_BeginDraw,
    EndDraw          = libphx.Window_EndDraw,
    GetPosition      = libphx.Window_GetPosition,
    GetSize          = libphx.Window_GetSize,
    GetTitle         = libphx.Window_GetTitle,
    SetFullscreen    = libphx.Window_SetFullscreen,
    SetPosition      = libphx.Window_SetPosition,
    SetSize          = libphx.Window_SetSize,
    SetTitle         = libphx.Window_SetTitle,
    SetVsync         = libphx.Window_SetVsync,
    ToggleFullscreen = libphx.Window_ToggleFullscreen,
    Hide             = libphx.Window_Hide,
    Show             = libphx.Window_Show,
  }

  if onDef_Window then onDef_Window(Window, mt) end
  Window = setmetatable(Window, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Window')
  local mt = {
    __index = {
      managed          = function (self) return ffi.gc(self, libphx.Window_Free) end,
      free             = libphx.Window_Free,
      beginDraw        = libphx.Window_BeginDraw,
      endDraw          = libphx.Window_EndDraw,
      getPosition      = libphx.Window_GetPosition,
      getSize          = libphx.Window_GetSize,
      getTitle         = libphx.Window_GetTitle,
      setFullscreen    = libphx.Window_SetFullscreen,
      setPosition      = libphx.Window_SetPosition,
      setSize          = libphx.Window_SetSize,
      setTitle         = libphx.Window_SetTitle,
      setVsync         = libphx.Window_SetVsync,
      toggleFullscreen = libphx.Window_ToggleFullscreen,
      hide             = libphx.Window_Hide,
      show             = libphx.Window_Show,
    },
  }

  if onDef_Window_t then onDef_Window_t(t, mt) end
  Window_t = ffi.metatype(t, mt)
end

return Window


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

do -- C Definitions
  ffi.cdef [[
    void UIRenderer_Begin      ();
    void UIRenderer_End        ();
    void UIRenderer_Draw       ();
    void UIRenderer_BeginLayer (float x, float y, float sx, float sy, bool clip);
    void UIRenderer_EndLayer   ();
    void UIRenderer_Image      (Tex2D*, float x, float y, float sx, float sy);
    void UIRenderer_Panel      (float x, float y, float sx, float sy, float r, float g, float b, float a, float bevel, float innerAlpha);
    void UIRenderer_Rect       (float x, float y, float sx, float sy, float r, float g, float b, float a, bool outline);
    void UIRenderer_Text       (Font* font, cstr text, float x, float y, float r, float g, float b, float a);
  ]]
end

do -- Global Symbol Table
  UIRenderer = {
    Begin      = libphx.UIRenderer_Begin,
    End        = libphx.UIRenderer_End,
    Draw       = libphx.UIRenderer_Draw,
    BeginLayer = libphx.UIRenderer_BeginLayer,
    EndLayer   = libphx.UIRenderer_EndLayer,
    Image      = libphx.UIRenderer_Image,
    Panel      = libphx.UIRenderer_Panel,
    Rect       = libphx.UIRenderer_Rect,
    Text       = libphx.UIRenderer_Text,
  }

  if onDef_UIRenderer then onDef_UIRenderer(UIRenderer, mt) end
  UIRenderer = setmetatable(UIRenderer, mt)
end

return UIRenderer


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

do -- Global Symbol Table
  Vec2i = {
  }

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

  if onDef_Vec2i then onDef_Vec2i(Vec2i, mt) end
  Vec2i = setmetatable(Vec2i, mt)
end

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

  if onDef_Vec2i_t then onDef_Vec2i_t(t, mt) end
  Vec2i_t = ffi.metatype(t, mt)
end

return Vec2i


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

do -- C Definitions
  ffi.cdef [[
    LodMesh* LodMesh_Create  ();
    void     LodMesh_Acquire (LodMesh*);
    void     LodMesh_Free    (LodMesh*);
    void     LodMesh_Add     (LodMesh*, Mesh*, float distMin, float distMax);
    void     LodMesh_Draw    (LodMesh*, float distanceSquared);
    Mesh*    LodMesh_Get     (LodMesh*, float distanceSquared);
  ]]
end

do -- Global Symbol Table
  LodMesh = {
    Create  = libphx.LodMesh_Create,
    Acquire = libphx.LodMesh_Acquire,
    Free    = libphx.LodMesh_Free,
    Add     = libphx.LodMesh_Add,
    Draw    = libphx.LodMesh_Draw,
    Get     = libphx.LodMesh_Get,
  }

  if onDef_LodMesh then onDef_LodMesh(LodMesh, mt) end
  LodMesh = setmetatable(LodMesh, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('LodMesh')
  local mt = {
    __index = {
      managed = function (self) return ffi.gc(self, libphx.LodMesh_Free) end,
      acquire = libphx.LodMesh_Acquire,
      free    = libphx.LodMesh_Free,
      add     = libphx.LodMesh_Add,
      draw    = libphx.LodMesh_Draw,
      get     = libphx.LodMesh_Get,
    },
  }

  if onDef_LodMesh_t then onDef_LodMesh_t(t, mt) end
  LodMesh_t = ffi.metatype(t, mt)
end

return LodMesh


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

do -- C Definitions
  ffi.cdef [[
    int         PixelFormat_Components      (PixelFormat);
    PixelFormat PixelFormat_Red;
    PixelFormat PixelFormat_RG;
    PixelFormat PixelFormat_RGB;
    PixelFormat PixelFormat_BGR;
    PixelFormat PixelFormat_RGBA;
    PixelFormat PixelFormat_BGRA;
    PixelFormat PixelFormat_Depth_Component;
  ]]
end

do -- Global Symbol Table
  PixelFormat = {
    Red  = libphx.PixelFormat_Red,
    RG   = libphx.PixelFormat_RG,
    RGB  = libphx.PixelFormat_RGB,
    BGR  = libphx.PixelFormat_BGR,
    RGBA = libphx.PixelFormat_RGBA,
    BGRA = libphx.PixelFormat_BGRA,
    Depth = {
      Component = libphx.PixelFormat_Depth_Component,
    },
    Components = libphx.PixelFormat_Components,
  }

  if onDef_PixelFormat then onDef_PixelFormat(PixelFormat, mt) end
  PixelFormat = setmetatable(PixelFormat, mt)
end

return PixelFormat


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

do -- C Definitions
  ffi.cdef [[
    CubeFace CubeFace_Get (int index);
    CubeFace CubeFace_PX;
    CubeFace CubeFace_NX;
    CubeFace CubeFace_PY;
    CubeFace CubeFace_NY;
    CubeFace CubeFace_PZ;
    CubeFace CubeFace_NZ;
  ]]
end

do -- Global Symbol Table
  CubeFace = {
    PX = libphx.CubeFace_PX,
    NX = libphx.CubeFace_NX,
    PY = libphx.CubeFace_PY,
    NY = libphx.CubeFace_NY,
    PZ = libphx.CubeFace_PZ,
    NZ = libphx.CubeFace_NZ,
    Get = libphx.CubeFace_Get,
  }

  if onDef_CubeFace then onDef_CubeFace(CubeFace, mt) end
  CubeFace = setmetatable(CubeFace, mt)
end

return CubeFace


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

do -- C Definitions
  ffi.cdef [[
    void LineSegment_ToRay    (LineSegment const*, Ray*);
    void LineSegment_FromRay  (Ray const*, LineSegment*);
    cstr LineSegment_ToString (LineSegment*);
  ]]
end

do -- Global Symbol Table
  LineSegment = {
    ToRay    = libphx.LineSegment_ToRay,
    FromRay  = libphx.LineSegment_FromRay,
    ToString = libphx.LineSegment_ToString,
  }

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

  if onDef_LineSegment then onDef_LineSegment(LineSegment, mt) end
  LineSegment = setmetatable(LineSegment, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('LineSegment')
  local mt = {
    __tostring = function (self) return ffi.string(libphx.LineSegment_ToString(self)) end,
    __index = {
      clone    = function (x) return LineSegment_t(x) end,
      toRay    = libphx.LineSegment_ToRay,
      toString = libphx.LineSegment_ToString,
    },
  }

  if onDef_LineSegment_t then onDef_LineSegment_t(t, mt) end
  LineSegment_t = ffi.metatype(t, mt)
end

return LineSegment


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

do -- C Definitions
  ffi.cdef [[
    void  Audio_Init              ();
    void  Audio_Free              ();
    void  Audio_AttachListenerPos (Vec3f const* pos, Vec3f const* vel, Vec3f const* fwd, Vec3f const* up);
    void  Audio_Set3DSettings     (float doppler, float scale, float rolloff);
    void  Audio_SetListenerPos    (Vec3f const* pos, Vec3f const* vel, Vec3f const* fwd, Vec3f const* up);
    void  Audio_Update            ();
    int32 Audio_GetLoadedCount    ();
    int32 Audio_GetPlayingCount   ();
    int32 Audio_GetTotalCount     ();
  ]]
end

do -- Global Symbol Table
  Audio = {
    Init              = libphx.Audio_Init,
    Free              = libphx.Audio_Free,
    AttachListenerPos = libphx.Audio_AttachListenerPos,
    Set3DSettings     = libphx.Audio_Set3DSettings,
    SetListenerPos    = libphx.Audio_SetListenerPos,
    Update            = libphx.Audio_Update,
    GetLoadedCount    = libphx.Audio_GetLoadedCount,
    GetPlayingCount   = libphx.Audio_GetPlayingCount,
    GetTotalCount     = libphx.Audio_GetTotalCount,
  }

  if onDef_Audio then onDef_Audio(Audio, mt) end
  Audio = setmetatable(Audio, mt)
end

return Audio


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

do -- Global Symbol Table
  Box3i = {
  }

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

  if onDef_Box3i then onDef_Box3i(Box3i, mt) end
  Box3i = setmetatable(Box3i, mt)
end

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

  if onDef_Box3i_t then onDef_Box3i_t(t, mt) end
  Box3i_t = ffi.metatype(t, mt)
end

return Box3i


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

do -- Global Symbol Table
  PolygonClassification = {
    InFront    = 1,
    Behind     = 2,
    Coplanar   = 3,
    Straddling = 4,
  }

  if onDef_PolygonClassification then onDef_PolygonClassification(PolygonClassification, mt) end
  PolygonClassification = setmetatable(PolygonClassification, mt)
end

return PolygonClassification


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

do -- C Definitions
  ffi.cdef [[
    void CullFace_Pop       ();
    void CullFace_Push      (CullFace);
    void CullFace_PushNone  ();
    void CullFace_PushBack  ();
    void CullFace_PushFront ();
  ]]
end

do -- Global Symbol Table
  CullFace = {
    None  = 0,
    Back  = 1,
    Front = 2,
    Pop       = libphx.CullFace_Pop,
    Push      = libphx.CullFace_Push,
    PushNone  = libphx.CullFace_PushNone,
    PushBack  = libphx.CullFace_PushBack,
    PushFront = libphx.CullFace_PushFront,
  }

  if onDef_CullFace then onDef_CullFace(CullFace, mt) end
  CullFace = setmetatable(CullFace, mt)
end

return CullFace


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

do -- C Definitions
  ffi.cdef [[
    void  Polygon_ToPlane           (Polygon*, Plane*);
    void  Polygon_ToPlaneFast       (Polygon*, Plane*);
    void  Polygon_Split             (Polygon*, Plane splitPlane, Polygon* back, Polygon* front);
    void  Polygon_SplitSafe         (Polygon*, Plane splitPlane, Polygon* back, Polygon* front);
    void  Polygon_GetCentroid       (Polygon*, Vec3f*);
    void  Polygon_ConvexToTriangles (Polygon*, int32* triangles_capacity, int32* triangles_size, Triangle** triangles_data);
    Error Polygon_Validate          (Polygon*);
  ]]
end

do -- Global Symbol Table
  Polygon = {
    ToPlane           = libphx.Polygon_ToPlane,
    ToPlaneFast       = libphx.Polygon_ToPlaneFast,
    Split             = libphx.Polygon_Split,
    SplitSafe         = libphx.Polygon_SplitSafe,
    GetCentroid       = libphx.Polygon_GetCentroid,
    ConvexToTriangles = libphx.Polygon_ConvexToTriangles,
    Validate          = libphx.Polygon_Validate,
  }

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

  if onDef_Polygon then onDef_Polygon(Polygon, mt) end
  Polygon = setmetatable(Polygon, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Polygon')
  local mt = {
    __index = {
      clone             = function (x) return Polygon_t(x) end,
      toPlane           = libphx.Polygon_ToPlane,
      toPlaneFast       = libphx.Polygon_ToPlaneFast,
      split             = libphx.Polygon_Split,
      splitSafe         = libphx.Polygon_SplitSafe,
      getCentroid       = libphx.Polygon_GetCentroid,
      convexToTriangles = libphx.Polygon_ConvexToTriangles,
      validate          = libphx.Polygon_Validate,
    },
  }

  if onDef_Polygon_t then onDef_Polygon_t(t, mt) end
  Polygon_t = ffi.metatype(t, mt)
end

return Polygon


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

do -- C Definitions
  ffi.cdef [[
    void  HmGui_Begin            (float sx, float sy);
    void  HmGui_End              ();
    void  HmGui_Draw             ();
    void  HmGui_BeginGroupX      ();
    void  HmGui_BeginGroupY      ();
    void  HmGui_BeginGroupStack  ();
    void  HmGui_EndGroup         ();
    void  HmGui_BeginScroll      (float maxSize);
    void  HmGui_EndScroll        ();
    void  HmGui_BeginWindow      (cstr title);
    void  HmGui_EndWindow        ();
    bool  HmGui_Button           (cstr);
    bool  HmGui_Checkbox         (cstr label, bool value);
    float HmGui_Slider           (float lower, float upper, float value);
    void  HmGui_Rect             (float sx, float sy, float r, float g, float b, float a);
    void  HmGui_Image            (Tex2D*);
    void  HmGui_Text             (cstr text);
    void  HmGui_TextColored      (cstr text, float r, float g, float b, float a);
    void  HmGui_TextEx           (Font* font, cstr text, float r, float g, float b, float a);
    void  HmGui_SetAlign         (float ax, float ay);
    void  HmGui_SetPadding       (float px, float py);
    void  HmGui_SetPaddingEx     (float left, float top, float right, float bottom);
    void  HmGui_SetPaddingLeft   (float);
    void  HmGui_SetPaddingTop    (float);
    void  HmGui_SetPaddingRight  (float);
    void  HmGui_SetPaddingBottom (float);
    void  HmGui_SetSpacing       (float);
    void  HmGui_SetStretch       (float x, float y);
    bool  HmGui_GroupHasFocus    (int type);
    void  HmGui_PushStyle        ();
    void  HmGui_PushFont         (Font*);
    void  HmGui_PushTextColor    (float r, float g, float b, float a);
    void  HmGui_PopStyle         (int depth);
  ]]
end

do -- Global Symbol Table
  HmGui = {
    Begin            = libphx.HmGui_Begin,
    End              = libphx.HmGui_End,
    Draw             = libphx.HmGui_Draw,
    BeginGroupX      = libphx.HmGui_BeginGroupX,
    BeginGroupY      = libphx.HmGui_BeginGroupY,
    BeginGroupStack  = libphx.HmGui_BeginGroupStack,
    EndGroup         = libphx.HmGui_EndGroup,
    BeginScroll      = libphx.HmGui_BeginScroll,
    EndScroll        = libphx.HmGui_EndScroll,
    BeginWindow      = libphx.HmGui_BeginWindow,
    EndWindow        = libphx.HmGui_EndWindow,
    Button           = libphx.HmGui_Button,
    Checkbox         = libphx.HmGui_Checkbox,
    Slider           = libphx.HmGui_Slider,
    Rect             = libphx.HmGui_Rect,
    Image            = libphx.HmGui_Image,
    Text             = libphx.HmGui_Text,
    TextColored      = libphx.HmGui_TextColored,
    TextEx           = libphx.HmGui_TextEx,
    SetAlign         = libphx.HmGui_SetAlign,
    SetPadding       = libphx.HmGui_SetPadding,
    SetPaddingEx     = libphx.HmGui_SetPaddingEx,
    SetPaddingLeft   = libphx.HmGui_SetPaddingLeft,
    SetPaddingTop    = libphx.HmGui_SetPaddingTop,
    SetPaddingRight  = libphx.HmGui_SetPaddingRight,
    SetPaddingBottom = libphx.HmGui_SetPaddingBottom,
    SetSpacing       = libphx.HmGui_SetSpacing,
    SetStretch       = libphx.HmGui_SetStretch,
    GroupHasFocus    = libphx.HmGui_GroupHasFocus,
    PushStyle        = libphx.HmGui_PushStyle,
    PushFont         = libphx.HmGui_PushFont,
    PushTextColor    = libphx.HmGui_PushTextColor,
    PopStyle         = libphx.HmGui_PopStyle,
  }

  if onDef_HmGui then onDef_HmGui(HmGui, mt) end
  HmGui = setmetatable(HmGui, mt)
end

return HmGui


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

do -- C Definitions
  ffi.cdef [[
    Quat  Quat_Create             (float x, float y, float z, float w);
    void  Quat_GetAxisX           (Quat const*, Vec3f*);
    void  Quat_GetAxisY           (Quat const*, Vec3f*);
    void  Quat_GetAxisZ           (Quat const*, Vec3f*);
    void  Quat_GetForward         (Quat const*, Vec3f*);
    void  Quat_GetRight           (Quat const*, Vec3f*);
    void  Quat_GetUp              (Quat const*, Vec3f*);
    void  Quat_Identity           (Quat*);
    void  Quat_Canonicalize       (Quat const*, Quat* out);
    void  Quat_ICanonicalize      (Quat*);
    float Quat_Dot                (Quat const*, Quat const*);
    bool  Quat_Equal              (Quat const*, Quat const*);
    bool  Quat_ApproximatelyEqual (Quat const*, Quat const*);
    void  Quat_Inverse            (Quat const*, Quat* out);
    void  Quat_IInverse           (Quat*);
    void  Quat_Lerp               (Quat const*, Quat const*, float t, Quat* out);
    void  Quat_ILerp              (Quat*, Quat const*, float t);
    void  Quat_Mul                (Quat const*, Quat const*, Quat* out);
    void  Quat_IMul               (Quat*, Quat const*);
    void  Quat_MulV               (Quat const*, Vec3f const*, Vec3f* out);
    void  Quat_Normalize          (Quat const*, Quat* out);
    void  Quat_INormalize         (Quat*);
    void  Quat_Scale              (Quat const*, float, Quat* out);
    void  Quat_IScale             (Quat*, float);
    void  Quat_Slerp              (Quat const*, Quat const*, float, Quat* out);
    void  Quat_ISlerp             (Quat*, Quat const*, float);
    cstr  Quat_ToString           (Quat const*);
    Error Quat_Validate           (Quat const*);
    void  Quat_FromAxisAngle      (Vec3f const* axis, float radians, Quat*);
    void  Quat_FromBasis          (Vec3f const* x, Vec3f const* y, Vec3f const* z, Quat*);
    void  Quat_FromLookUp         (Vec3f const* look, Vec3f const* up, Quat*);
    void  Quat_FromRotateTo       (Vec3f const* from, Vec3f const* to, Quat*);
  ]]
end

do -- Global Symbol Table
  Quat = {
    Create             = libphx.Quat_Create,
    GetAxisX           = libphx.Quat_GetAxisX,
    GetAxisY           = libphx.Quat_GetAxisY,
    GetAxisZ           = libphx.Quat_GetAxisZ,
    GetForward         = libphx.Quat_GetForward,
    GetRight           = libphx.Quat_GetRight,
    GetUp              = libphx.Quat_GetUp,
    Identity           = libphx.Quat_Identity,
    Canonicalize       = libphx.Quat_Canonicalize,
    ICanonicalize      = libphx.Quat_ICanonicalize,
    Dot                = libphx.Quat_Dot,
    Equal              = libphx.Quat_Equal,
    ApproximatelyEqual = libphx.Quat_ApproximatelyEqual,
    Inverse            = libphx.Quat_Inverse,
    IInverse           = libphx.Quat_IInverse,
    Lerp               = libphx.Quat_Lerp,
    ILerp              = libphx.Quat_ILerp,
    Mul                = libphx.Quat_Mul,
    IMul               = libphx.Quat_IMul,
    MulV               = libphx.Quat_MulV,
    Normalize          = libphx.Quat_Normalize,
    INormalize         = libphx.Quat_INormalize,
    Scale              = libphx.Quat_Scale,
    IScale             = libphx.Quat_IScale,
    Slerp              = libphx.Quat_Slerp,
    ISlerp             = libphx.Quat_ISlerp,
    ToString           = libphx.Quat_ToString,
    Validate           = libphx.Quat_Validate,
    FromAxisAngle      = libphx.Quat_FromAxisAngle,
    FromBasis          = libphx.Quat_FromBasis,
    FromLookUp         = libphx.Quat_FromLookUp,
    FromRotateTo       = libphx.Quat_FromRotateTo,
  }

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

  if onDef_Quat then onDef_Quat(Quat, mt) end
  Quat = setmetatable(Quat, mt)
end

do -- Metatype for class instances
  local t  = ffi.typeof('Quat')
  local mt = {
    __tostring = function (self) return ffi.string(libphx.Quat_ToString(self)) end,
    __index = {
      clone              = function (x) return Quat_t(x) end,
      getAxisX           = libphx.Quat_GetAxisX,
      getAxisY           = libphx.Quat_GetAxisY,
      getAxisZ           = libphx.Quat_GetAxisZ,
      getForward         = libphx.Quat_GetForward,
      getRight           = libphx.Quat_GetRight,
      getUp              = libphx.Quat_GetUp,
      identity           = libphx.Quat_Identity,
      canonicalize       = libphx.Quat_Canonicalize,
      iCanonicalize      = libphx.Quat_ICanonicalize,
      dot                = libphx.Quat_Dot,
      equal              = libphx.Quat_Equal,
      approximatelyEqual = libphx.Quat_ApproximatelyEqual,
      inverse            = libphx.Quat_Inverse,
      iInverse           = libphx.Quat_IInverse,
      lerp               = libphx.Quat_Lerp,
      iLerp              = libphx.Quat_ILerp,
      mul                = libphx.Quat_Mul,
      iMul               = libphx.Quat_IMul,
      mulV               = libphx.Quat_MulV,
      normalize          = libphx.Quat_Normalize,
      iNormalize         = libphx.Quat_INormalize,
      scale              = libphx.Quat_Scale,
      iScale             = libphx.Quat_IScale,
      slerp              = libphx.Quat_Slerp,
      iSlerp             = libphx.Quat_ISlerp,
      toString           = libphx.Quat_ToString,
      validate           = libphx.Quat_Validate,
    },
  }

  if onDef_Quat_t then onDef_Quat_t(t, mt) end
  Quat_t = ffi.metatype(t, mt)
end

return Quat