diff --git a/scripts/bgfx-codegen.lua b/scripts/bgfx-codegen.lua index ed2cfbbec..6b253e31f 100644 --- a/scripts/bgfx-codegen.lua +++ b/scripts/bgfx-codegen.lua @@ -20,6 +20,7 @@ local func_actions = { local type_actions = { + cflags = "\n", enums = "\n", cenums = "\n", structs = "\n", @@ -173,6 +174,12 @@ function typegen.cenums(typedef) end end +function typegen.cflags(typedef) + if typedef.flag then + return add_doxygen(typedef, codegen.gen_flag_cdefine(typedef), true) + end +end + function typegen.structs(typedef) if typedef.struct and not typedef.namespace then local methods = typedef.methods @@ -255,6 +262,8 @@ local function codes() temp[k] = table.concat(temp[k], indent) end + temp.version = string.format("#define BGFX_API_VERSION UINT32_C(%d)", idl._version or 0) + return temp end diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index 3c03acb0f..ec7e79a1a 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -1,6 +1,8 @@ -- vim: syntax=lua -- bgfx interface +version(99) + typedef "bool" typedef "char" typedef "float" @@ -25,6 +27,393 @@ funcptr.ReleaseFn .ptr "void*" --- Pointer to allocated data. .userData "void*" --- User defined data if needed. +--- Color RGB/alpha/depth write. When it's not specified write will be disabled. +flag.StateWrite { bits = 64 , base = 1 } + .R --- Enable R write. + .G --- Enable G write. + .B --- Enable B write. + .A --- Enable alpha write. + .Z ( 39 ) --- Enable depth write. + .Rgb { "R", "G", "B" } --- Enable RGB write. + .Mask { "Rgb", "A", "Z" } --- Write all channels mask. + +--- Depth test state. When `BGFX_STATE_DEPTH_` is not specified depth test will be disabled. +flag.StateDepthTest { bits = 64, shift = 4, range = 4, base = 1 , desc = "Depth test state" } + .Less --- Enable depth test, less. + .Lequal --- Enable depth test, less or equal. + .Equal --- Enable depth test, equal. + .Gequal --- Enable depth test, greater or equal. + .Greater --- Enable depth test, greater. + .Notequal --- Enable depth test, not equal. + .Never --- Enable depth test, never. + .Always --- Enable depth test, always. + () + +--- Use BGFX_STATE_BLEND_FUNC(_src, _dst) or BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA) +--- helper macros. +flag.StateBlend { bits = 64, shift = 12, range = 16, base = 1, desc = "Blend state" } + .Zero --- 0, 0, 0, 0 + .One --- 1, 1, 1, 1 + .SrcColor --- Rs, Gs, Bs, As + .InvSrcColor --- 1-Rs, 1-Gs, 1-Bs, 1-As + .SrcAlpha --- As, As, As, As + .InvSrcAlpha --- 1-As, 1-As, 1-As, 1-As + .DstAlpha --- Ad, Ad, Ad, Ad + .InvDstAlpha --- 1-Ad, 1-Ad, 1-Ad ,1-Ad + .DstColor --- Rd, Gd, Bd, Ad + .InvDstColor --- 1-Rd, 1-Gd, 1-Bd, 1-Ad + .SrcAlphaSat --- f, f, f, 1; f = min(As, 1-Ad) + .Factor --- Blend factor + .Inv_Factor --- 1-Blend factor + () + +--- Use BGFX_STATE_BLEND_EQUATION(_equation) or BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA) +--- helper macros. +flag.StateBlendEquation { bits = 64, shift = 28, range = 6, base = 0, desc = "Blend equation" } + .Add --- Blend add: src + dst. + .Sub --- Blend subtract: src - dst. + .Revsub --- Blend reverse subtract: dst - src. + .Min --- Blend min: min(src, dst). + .Max --- Blend max: max(src, dst). + () + +--- Cull state. When `BGFX_STATE_CULL_*` is not specified culling will be disabled. +flag.StateCull { bits = 64, shift = 36, range = 2, base = 1, desc = "Culling mode" } + .Cw --- Cull clockwise triangles. + .Ccw --- Cull counter-clockwise triangles. + () + +--- Alpha reference value. +flag.StateAlphaRef { bits = 64, shift = 40, range = 8, desc = "Alpha reference", "helper" } + +flag.StatePt { bits = 64, shift = 48, range = 3, desc = "Primitive type" } + .Tristrip --- Tristrip. + .Lines --- Lines. + .Linestrip --- Line strip. + .Points --- Points. + () + +--- Point size value. +flag.StatePointSize { bits = 64, shift = 52, range = 4, desc = "Point size", "helper" } + +--- Enable MSAA write when writing into MSAA frame buffer. +--- This flag is ignored when not writing into MSAA frame buffer. +flag.State { bits = 64 , range = 64 , desc = "State" } + .Msaa (57) --- Enable MSAA rasterization. + .Lineaa (58) --- Enable line AA rasterization. + .ConservativeRaster (59) --- Enable conservative rasterization. + .None (0) --- No state. + .BlendIndependent(35) --- Enable blend independent. + .BlendAlphaToCoverage (36) --- Enable alpha to coverage. + .Default { "WriteRgb", "WriteA", "WriteZ", "DepthTestLess", "CullCw", "Msaa" } + --- Default state is write to RGB, alpha, and depth with depth test less enabled, with clockwise + --- culling and MSAA (when writing into MSAA frame buffer, otherwise this flag is ignored). + + +--- Do not use! +flag.StateReserved { bits = 64, shift = 61, range = 3 } + +--- Set stencil ref value. +flag.StencilFuncRef { bits = 32, shift = 0, range = 8, "helper" } + +--- Set stencil rmask value. +flag.StencilFuncRmask { bits = 32, shift = 8, range = 8, "helper" } + +flag.Stencil { bits = 32, const } + .None (0x00000000) + .Mask (0xffffffff) + .Default (0x00000000) + +flag.StencilTest { bits = 32, shift = 16, range = 4 , base = 1, desc = "Stencil test" } + .Less --- Enable stencil test, less. + .Lequal --- Enable stencil test, less or equal. + .Equal --- Enable stencil test, equal. + .Gequal --- Enable stencil test, greater or equal. + .Greater --- Enable stencil test, greater. + .Notequal --- Enable stencil test, not equal. + .Never --- Enable stencil test, never. + .Always --- Enable stencil test, always. + () + +flag.StencilOpFailS { bits = 32, shift = 20, range = 4, base = 0, desc = "Stencil operation fail" } + .Zero --- Zero. + .Keep --- Keep. + .Replace --- Replace. + .Incr --- Increment and wrap. + .Incrsat --- Increment and clamp. + .Decr --- Decrement and wrap. + .Decrsat --- Decrement and clamp. + .Invert --- Invert. + () + +flag.StencilOpFailZ { bits = 32, shift = 24, range = 4, base = 0, desc = "Stencil operation depth fail" } + .Zero --- Zero. + .Keep --- Keep. + .Replace --- Replace. + .Incr --- Increment and wrap. + .Incrsat --- Increment and clamp. + .Decr --- Decrement and wrap. + .Decrsat --- Decrement and clamp. + .Invert --- Invert. + () + +flag.StencilOpPassZ { bits = 32, shift = 28, range = 4 , base = 0, desc = "Stencil operation depth pass" } + .Zero --- Zero. + .Keep --- Keep. + .Replace --- Replace. + .Incr --- Increment and wrap. + .Incrsat --- Increment and clamp. + .Decr --- Decrement and wrap. + .Decrsat --- Decrement and clamp. + .Invert --- Invert. + () + +flag.Clear { bits = 16 } + .None --- No clear flags. + .Color --- Clear color. + .Depth --- Clear depth. + .Stencil --- Clear stencil. + .DiscardColor0 --- Discard frame buffer attachment 0. + .DiscardColor1 --- Discard frame buffer attachment 1. + .DiscardColor2 --- Discard frame buffer attachment 2. + .DiscardColor3 --- Discard frame buffer attachment 3. + .DiscardColor4 --- Discard frame buffer attachment 4. + .DiscardColor5 --- Discard frame buffer attachment 5. + .DiscardColor6 --- Discard frame buffer attachment 6. + .DiscardColor7 --- Discard frame buffer attachment 7. + .DiscardDepth --- Discard frame buffer depth attachment. + .DiscardStencil --- Discard frame buffer stencil attachment. + .DiscardColorMask { + "DiscardColor0", + "DiscardColor1", + "DiscardColor2", + "DiscardColor3", + "DiscardColor4", + "DiscardColor5", + "DiscardColor6", + "DiscardColor7" + } + .DiscardMask { + "DiscardColorMask", + "DiscardDepth", + "DiscardStencil" + } + +flag.Debug { bits = 32 } + .None --- No debug. + .Wireframe --- Enable wireframe for all primitives. + .Ifh --- Enable infinitely fast hardware test. No draw calls will be submitted to driver. It’s useful when profiling to quickly assess bottleneck between CPU and GPU. + .Stats --- Enable statistics display. + .Text --- Enable debug text display. + .Profiler --- Enable profiler. + () + +flag.BufferComputeFormat { bits = 16, shift = 0, range = 4, base = 1 } + ["8x1"] --- 1 8-bit value + ["8x2"] --- 2 8-bit values + ["8x4"] --- 4 8-bit values + ["16x1"] --- 1 16-bit value + ["16x2"] --- 2 16-bit values + ["16x4"] --- 4 16-bit values + ["32x1"] --- 1 32-bit value + ["32x2"] --- 2 32-bit values + ["32x4"] --- 4 32-bit values + () + +flag.BufferComputeType { bits = 16, shift = 4, range = 2, base = 1 } + .Int --- Type `int`. + .Uint --- Type `uint`. + .Float --- Type `float`. + () + +flag.Buffer { bits = 16, base = 8 } + .None(0) + .ComputeRead --- Buffer will be read by shader. + .ComputeWrite --- Buffer will be used for writing. + .DrawIndirect --- Buffer will be used for storing draw indirect commands. + .AllowResize --- Allow dynamic index/vertex buffer resize during update. + .Index32 { cname = "INDEX32" } --- Index buffer contains 32-bit indices. + .ComputeReadWrite { "ComputeRead" , "ComputeWrite" } + () + +flag.Texture { bits = 64 } + .None (0) + .MsaaSample (36) --- Texture will be used for MSAA sampling. + .Rt (37) --- Render target no MSAA. + .ComputeWrite (45) --- Texture will be used for compute write. + .Srgb (46) --- Sample texture as sRGB. + .BlitDst (47) --- Texture will be used as blit destination. + .ReadBack (48) --- Texture will be used for read back from GPU. + () + +flag.TextureRtMsaa { bits = 64, shift = 36, range = 3 , base = 2 } + .X2 --- Render target MSAAx2 mode. + .X4 --- Render target MSAAx4 mode. + .X8 --- Render target MSAAx8 mode. + .X16 --- Render target MSAAx16 mode. + () + +flag.TextureRt { bits = 64, shift = 36, range = 4 } + .WriteOnly (9) --- Render target will be used for writing + +--- Sampler flags. +flag.SamplerU { bits = 32, shift = 0, range = 2, base = 1 } + .Mirror --- Wrap U mode: Mirror + .Clamp --- Wrap U mode: Clamp + .Border --- Wrap U mode: Border + () + +flag.SamplerV { bits = 32, shift = 2, range = 2, base = 1 } + .Mirror --- Wrap V mode: Mirror + .Clamp --- Wrap V mode: Clamp + .Border --- Wrap V mode: Border + () + +flag.SamplerW { bits = 32, shift = 4, range = 2, base = 1 } + .Mirror --- Wrap W mode: Mirror + .Clamp --- Wrap W mode: Clamp + .Border --- Wrap W mode: Border + () + +flag.SamplerMin { bits = 32, shift = 6, range = 2, base = 1 } + .Point --- Min sampling mode: Point + .Anisotropic --- Min sampling mode: Anisotropic + () + +flag.SamplerMag { bits = 32, shift = 8, range = 2, base = 1 } + .Point --- Mag sampling mode: Point + .Anisotropic --- Mag sampling mode: Anisotropic + () + +flag.SamplerMip { bits = 32, shift = 10, range = 1, base = 1 } + .Point --- Mip sampling mode: Point + () + +flag.SamplerCompare { bits = 32 , shift = 16, range = 4, base = 1 } + .Less --- Compare when sampling depth texture: less. + .Lequal --- Compare when sampling depth texture: less or equal. + .Equal --- Compare when sampling depth texture: equal. + .Gequal --- Compare when sampling depth texture: greater or equal. + .Greater --- Compare when sampling depth texture: greater. + .Notequal --- Compare when sampling depth texture: not equal. + .Never --- Compare when sampling depth texture: never. + .Always --- Compare when sampling depth texture: always. + () + +flag.SamplerBorderColor { bits = 32, shift = 24, range = 4, "helper" } +flag.SamplerReserved { bits = 32, shift = 28, range = 4 } + +flag.Sampler { bits = 32 } + .None + .SampleStencil (21) --- Sample stencil instead of depth. + .Point { "MinPoint", "MagPoint", "MipPoint" } + .UvwMirror { "UMirror", "VMirror", "WMirror" } + .UvwClamp { "UClamp", "VClamp", "WClamp" } + .UvwBorder { "UBorder", "VBorder", "WBorder" } + .BitsMask { "UMask", "VMask", "WMask", "MinMask", "MagMask", "MipMask", "CompareMask" } + () + +flag.ResetFullscreen { bits = 32, shift = 0, range = 1, base = 1 } + .Fullscreen --- Not supported yet. + () + +flag.ResetMsaa { bits = 32, shift = 4, range = 3, base = 1 } + .X2 --- Enable 2x MSAA. + .X4 --- Enable 4x MSAA. + .X8 --- Enable 8x MSAA. + .X16 --- Enable 16x MSAA. + () + + +flag.Reset { bits = 32 } + .None (0) --- No reset flags. + .Vsync (8) --- Enable V-Sync. + .Maxanisotropy (9) --- Turn on/off max anisotropy. + .Capture (10) --- Begin screen capture. + .FlushAfterRender (14) --- Flush rendering after submitting to GPU. + .FlipAfterRender (15) --- This flag specifies where flip occurs. Default behavior is that flip occurs before rendering new frame. This flag only has effect when `BGFX_CONFIG_MULTITHREADED=0`. + .SrgbBackbuffer (16) --- Enable sRGB backbuffer. + .Hdr10 (17) --- Enable HDR10 rendering. + .Hidpi (18) --- Enable HiDPI rendering. + .DepthClamp (19) --- Enable depth clamp. + .Suspend (20) --- Suspend rendering. + () + +flag.ResetReserved { bits = 32, shift = 31, range = 1 , desc = "Internal" } + +flag.Caps { bits = 64, base = 1, name = "Caps" } + .AlphaToCoverage --- Alpha to coverage is supported. + .BlendIndependent --- Blend independent is supported. + .Compute --- Compute shaders are supported. + .ConservativeRaster --- Conservative rasterization is supported. + .DrawIndirect --- Draw indirect is supported. + .FragmentDepth --- Fragment depth is accessible in fragment shader. + .FragmentOrdering --- Fragment ordering is available in fragment shader. + .FramebufferRw --- Read/Write frame buffer attachments are supported. + .GraphicsDebugger --- Graphics debugger is present. + .Reserved + .Hdr10 { cname = "HDR10" } --- HDR10 rendering is supported. + .Hidpi --- HiDPI rendering is supported. + .Index32 { cname = "INDEX32" } --- 32-bit indices are supported. + .Instancing --- Instancing is supported. + .OcclusionQuery --- Occlusion query is supported. + .RendererMultithreaded --- Renderer is on separate thread. + .SwapChain --- Multiple windows are supported. + .Texture2dArray --- 2D texture array is supported. + .Texture3d --- 3D textures are supported. + .TextureBlit --- Texture blit is supported. + .TextureCompareReserved --- All texture compare modes are supported. + .TextureCompareLequal --- Texture compare less equal mode is supported. + .TextureCubeArray --- Cubemap texture array is supported. + .TextureDirectAccess --- CPU direct access to GPU texture memory. + .TextureReadBack --- Read-back texture is supported. + .VertexAttribHalf --- Vertex attribute half-float is supported. + .VertexAttribUint10 { cname = "VERTEX_ATTRIB_UINT10" } --- Vertex attribute 10_10_10_2 is supported. + .VertexId --- Rendering with VertexID only is supported. + .TextureCompareAll { "TextureCompareReserved", "TextureCompareLequal" } --- All texture compare modes are supported. + () + +flag.CapsFormat { bits = 16 } + .TextureNone --- Texture format is not supported. + .Texture2d --- Texture format is supported. + .Texture2dSrgb --- Texture as sRGB format is supported. + .Texture2dEmulated --- Texture format is emulated. + .Texture3d --- Texture format is supported. + .Texture3dSrgb --- Texture as sRGB format is supported. + .Texture3dEmulated --- Texture format is emulated. + .TextureCube --- Texture format is supported. + .TextureCubeSrgb --- Texture as sRGB format is supported. + .TextureCubeEmulated --- Texture format is emulated. + .TextureVertex --- Texture format can be used from vertex shader. + .TextureImage --- Texture format can be used as image from compute shader. + .TextureFramebuffer --- Texture format can be used as frame buffer. + .TextureFramebufferMsaa --- Texture format can be used as MSAA frame buffer. + .TextureMsaa --- Texture can be sampled as MSAA. + .TextureMipAutogen --- Texture format supports auto-generated mips. + () + +flag.Resolve { bits = 8 } + .None --- No resolve flags. + .AutoGenMips --- Auto-generate mip maps on resolve. + () + +flag.PciId { bits = 16 , const } + .None (0x0000) --- Autoselect adapter. + .SoftwareRasterizer (0x0001) --- Software rasterizer. + .Amd (0x1002) --- AMD adapter. + .Intel (0x8086) --- Intel adapter. + .Nvidia (0x10de) --- nVidia adapter. + () + +flag.CubeMap { bits = 8, const } + .PositiveX (0x00) --- Cubemap +x. + .NegativeX (0x01) --- Cubemap -x. + .PositiveY (0x02) --- Cubemap +y. + .NegativeY (0x03) --- Cubemap -y. + .PositiveZ (0x04) --- Cubemap +z. + .NegativeZ (0x05) --- Cubemap -z. + () + --- Fatal error enum. enum.Fatal { underscore, comment = "" } .DebugCheck diff --git a/scripts/codegen.lua b/scripts/codegen.lua index a54901617..5e0f12916 100644 --- a/scripts/codegen.lua +++ b/scripts/codegen.lua @@ -221,7 +221,9 @@ function codegen.nameconversion(all_types, all_funcs) v.cname = name end end - if cname then + if v.flag then + v.cname = "BGFX_" .. cname:upper() + elseif cname then if v.namespace then cname = camelcase_to_underscorecase(v.namespace) .. "_" .. cname end @@ -238,8 +240,9 @@ function codegen.nameconversion(all_types, all_funcs) if not v.namespace then if all_types[v.name] then error ("Duplicate type " .. v.name) + elseif not v.flag then + all_types[v.name] = v end - all_types[v.name] = v end end @@ -661,6 +664,129 @@ function codegen.gen_enum_cdefine(enum) return (cenum_temp:gsub("$(%u+)", temp)) end +local function flag_format(flag) + if not flag.format then + flag.format = "%0" .. (flag.bits // 4) .. "x" + end +end + +function codegen.gen_flag_cdefine(flag) + assert(type(flag.flag) == "table", "Not a flag") + flag_format(flag) + local s = {} + local shift = flag.shift + local base = flag.base or 0 + local cap = 1 << (flag.range or 0) + for index, item in ipairs(flag.flag) do + local name + if item.cname then + name = flag.cname .. "_" .. item.cname + else + name = flag.cname .. "_" .. camelcase_to_underscorecase(item.name):upper() + end + local value = item.value + if flag.const then + -- use value directly + elseif shift then + if value then + if value > 0 then + value = value - 1 + end + else + value = index + base - 1 + end + if value >= cap then + error (string.format("Out of range for %s (%d/%d)", name, value, cap)) + end + value = value << shift + elseif #item == 0 then + if value then + if value > 0 then + value = 1 << (value - 1) + end + else + local s = index + base - 2 + if s >= 0 then + value = 1 << s + else + value = 0 + end + end + end + + if value == nil then + if item.comment then + if type(item.comment) == "table" then + for _, c in ipairs(item.comment) do + s[#s+1] = "/// " .. c + end + else + s[#s+1] = "/// " .. item.comment + end + end + local sets = { "" } + for _, v in ipairs(item) do + sets[#sets+1] = flag.cname .. "_" .. camelcase_to_underscorecase(v):upper() + end + s[#s+1] = string.format("#define %s (0%s \\\n\t)\n", name, table.concat(sets, " \\\n\t| ")) + else + local comment = "" + if item.comment then + comment = " //!< " .. item.comment + end + value = string.format(flag.format, value) + local code = string.format("#define %s %sUINT%d_C(0x%s)%s", + name, namealign(name, 35), flag.bits, value, comment) + s[#s+1] = code + end + end + + local mask + if flag.range then + if flag.range == 64 then + mask = "ffffffffffffffff" + else + mask = string.format(flag.format, ((1 << flag.range) - 1) << shift) + end + mask = string.format("UINT%d_C(0x%s)", flag.bits, mask) + end + + if shift then + local name = flag.cname .. "_SHIFT" + local comment = flag.desc or "" + local shift_align = tostring(shift) + shift_align = shift_align .. namealign(shift_align, #mask) + local comment = "" + if flag.desc then + comment = string.format(" //!< %s bit shift", flag.desc) + end + local code = string.format("#define %s %s%s%s", name, namealign(name, 35), shift_align, comment) + s[#s+1] = code + end + if flag.range then + local name = flag.cname .. "_MASK" + local comment = "" + if flag.desc then + comment = string.format(" //!< %s bit mask", flag.desc) + end + local code = string.format("#define %s %s%s%s", name, namealign(name, 35), mask, comment) + s[#s+1] = code + end + + if flag.helper then + s[#s+1] = string.format( + "#define %s(v) ( ( (uint%d_t)(v)<<%s )&%s)", + flag.cname, + flag.bits, + (flag.cname .. "_SHIFT"), + (flag.cname .. "_MASK")) + end + + s[#s+1] = "" + + return table.concat(s, "\n") +end + local function text_with_comments(items, item, cstyle, is_classmember) local name = item.name if item.array then diff --git a/scripts/genie.lua b/scripts/genie.lua index d75b476f7..2e9d0b635 100644 --- a/scripts/genie.lua +++ b/scripts/genie.lua @@ -64,6 +64,7 @@ newaction { generate("temp.bgfx.h" , "../include/bgfx/c99/bgfx.h", " ") generate("temp.bgfx.idl.inl", "../src/bgfx.idl.inl", "\t") +-- generate("temp.defines.h", "../include/bgfx/defines.h", "\t") os.exit() end diff --git a/scripts/idl.lua b/scripts/idl.lua index 536e2a986..fc85f129a 100644 --- a/scripts/idl.lua +++ b/scripts/idl.lua @@ -12,13 +12,15 @@ end local all_types = {} local function copy_attribs(to, from) - assert(type(from) == "table", "Attribs should be a table") - for k, v in pairs(from) do - if type(k) == "number" then - to[v] = true - else + if type(from) == "table" then + for k, v in pairs(from) do + if type(k) == "number" then + to[v] = true + end to[k] = v end + else + to.value = from end end @@ -78,33 +80,38 @@ local function add_comment(item, comment) end end -local function enumdef(_, typename) - local t = new_type(typename) - t.enum = {} +local function enumdef(what) + local function deffunc (_, typename) + local t = new_type(typename) + t[what] = {} - local function enum_attrib(obj, attribs) - copy_attribs(t, attribs) - return obj - end - - local function new_enum_item(_, itemname) - local item = { name = itemname } - t.enum[#t.enum + 1] = item - local function add_attrib_or_comment(obj , attribs) - if type(attribs) == "string" then - add_comment(item, attribs) - elseif attribs then - copy_attribs(item, attribs) - end + local function enum_attrib(obj, attribs) + copy_attribs(t, attribs) return obj end - return setmetatable({}, { __index = new_enum_item, __call = add_attrib_or_comment }) + + local function new_enum_item(_, itemname) + local item = { name = itemname } + t[what][#t[what] + 1] = item + local function add_attrib_or_comment(obj , attribs) + if type(attribs) == "string" then + add_comment(item, attribs) + elseif attribs then + copy_attribs(item, attribs) + end + return obj + end + return setmetatable({}, { __index = new_enum_item, __call = add_attrib_or_comment }) + end + + return setmetatable({}, { __index = new_enum_item , __call = enum_attrib }) end - return setmetatable({}, { __index = new_enum_item , __call = enum_attrib }) + return setmetatable({} , { __index = deffunc , __call = deffunc }) end -idl.enum = setmetatable({} , { __index = enumdef, __call = enumdef }) +idl.enum = enumdef "enum" +idl.flag = enumdef "flag" local function structdef(_, typename) local t = new_type(typename) @@ -220,6 +227,10 @@ idl.funcptr = setmetatable({}, { __index = func(all_types) }) idl.func = setmetatable({}, { __index = func(all_funcs) }) idl.funcs = all_funcs +function idl.version(v) + rawset(idl, "_version", v) +end + idl.vararg = "vararg" idl.out = "out" idl.inout = "inout" diff --git a/scripts/temp.defines.h b/scripts/temp.defines.h new file mode 100644 index 000000000..4437bfa78 --- /dev/null +++ b/scripts/temp.defines.h @@ -0,0 +1,94 @@ +/* + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#ifndef BGFX_DEFINES_H_HEADER_GUARD +#define BGFX_DEFINES_H_HEADER_GUARD + +$version + +$cflags + +/// Blend function separate. +#define BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA) (UINT64_C(0) \ + | ( ( (uint64_t)(_srcRGB)|( (uint64_t)(_dstRGB)<<4) ) ) \ + | ( ( (uint64_t)(_srcA )|( (uint64_t)(_dstA )<<4) )<<8) \ + ) + +/// Blend equation separate. +#define BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA) ( (uint64_t)(_equationRGB)|( (uint64_t)(_equationA)<<3) ) + +/// Blend function. +#define BGFX_STATE_BLEND_FUNC(_src, _dst) BGFX_STATE_BLEND_FUNC_SEPARATE(_src, _dst, _src, _dst) + +/// Blend equation. +#define BGFX_STATE_BLEND_EQUATION(_equation) BGFX_STATE_BLEND_EQUATION_SEPARATE(_equation, _equation) + +/// Utility predefined blend modes. + +/// Additive blending. +#define BGFX_STATE_BLEND_ADD (0 \ + | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE) \ + ) + +/// Alpha blend. +#define BGFX_STATE_BLEND_ALPHA (0 \ + | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) \ + ) + +/// Selects darker color of blend. +#define BGFX_STATE_BLEND_DARKEN (0 \ + | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE) \ + | BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_MIN) \ + ) + +/// Selects lighter color of blend. +#define BGFX_STATE_BLEND_LIGHTEN (0 \ + | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE) \ + | BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_MAX) \ + ) + +/// Multiplies colors. +#define BGFX_STATE_BLEND_MULTIPLY (0 \ + | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO) \ + ) + +/// Opaque pixels will cover the pixels directly below them without any math or algorithm applied to them. +#define BGFX_STATE_BLEND_NORMAL (0 \ + | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_ALPHA) \ + ) + +/// Multiplies the inverse of the blend and base colors. +#define BGFX_STATE_BLEND_SCREEN (0 \ + | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_COLOR) \ + ) + +/// Decreases the brightness of the base color based on the value of the blend color. +#define BGFX_STATE_BLEND_LINEAR_BURN (0 \ + | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_INV_DST_COLOR) \ + | BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_SUB) \ + ) + +/// +#define BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) (0 \ + | ( (uint32_t)( (_src)>>BGFX_STATE_BLEND_SHIFT) \ + | ( (uint32_t)( (_dst)>>BGFX_STATE_BLEND_SHIFT)<<4) ) \ + ) + +/// +#define BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation) (0 \ + | BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) \ + | ( (uint32_t)( (_equation)>>BGFX_STATE_BLEND_EQUATION_SHIFT)<<8) \ + ) + +#define BGFX_STATE_BLEND_FUNC_RT_1(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<< 0) +#define BGFX_STATE_BLEND_FUNC_RT_2(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<<11) +#define BGFX_STATE_BLEND_FUNC_RT_3(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<<22) + +#define BGFX_STATE_BLEND_FUNC_RT_1E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<< 0) +#define BGFX_STATE_BLEND_FUNC_RT_2E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<<11) +#define BGFX_STATE_BLEND_FUNC_RT_3E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<<22) + + +#endif // BGFX_DEFINES_H_HEADER_GUARD