From 8cc0b1071987608c1099ed74c141f5e73c37cd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Tue, 12 Mar 2019 10:57:03 -0700 Subject: [PATCH] Updated IDL. --- include/bgfx/c99/bgfx.h | 18 +++++++++--------- include/bgfx/defines.h | 2 +- scripts/bgfx-idl.lua | 22 +++++++++++++--------- scripts/bgfx.idl | 36 ++++++++++++++++++------------------ scripts/codegen.lua | 22 ++++++++++++++++------ scripts/idl.lua | 1 + src/bgfx.idl.inl | 12 ++++++------ 7 files changed, 64 insertions(+), 49 deletions(-) diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 67ef9c27d..dc024fd18 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -680,7 +680,7 @@ typedef struct bgfx_memory_s */ typedef struct bgfx_transient_index_buffer_s { - int8_t* data; /** Pointer to data. */ + uint8_t* data; /** Pointer to data. */ uint32_t size; /** Data size. */ uint32_t startIndex; /** First index. */ bgfx_index_buffer_handle_t handle; /** Index buffer handle. */ @@ -693,7 +693,7 @@ typedef struct bgfx_transient_index_buffer_s */ typedef struct bgfx_transient_vertex_buffer_s { - int8_t* data; /** Pointer to data. */ + uint8_t* data; /** Pointer to data. */ uint32_t size; /** Data size. */ uint32_t startVertex; /** First vertex. */ uint16_t stride; /** Vertex stride. */ @@ -708,7 +708,7 @@ typedef struct bgfx_transient_vertex_buffer_s */ typedef struct bgfx_instance_data_buffer_s { - int8_t* data; /** Pointer to data. */ + uint8_t* data; /** Pointer to data. */ uint32_t size; /** Data size. */ uint32_t offset; /** Offset in vertex buffer. */ uint32_t num; /** Number of instances. */ @@ -887,7 +887,7 @@ BGFX_C_API void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_hand * @param[in] _rendererType * */ -BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _this, bgfx_renderer_type_t _rendererType); +BGFX_C_API bgfx_vertex_decl_t* bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _this, bgfx_renderer_type_t _rendererType); /** * Add attribute to VertexDecl. @@ -905,7 +905,7 @@ BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _this, bgfx_renderer_ * Unpacking code must be implemented inside vertex shader. * */ -BGFX_C_API void bgfx_vertex_decl_add(bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); +BGFX_C_API bgfx_vertex_decl_t* bgfx_vertex_decl_add(bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); /** * Decode attribute. @@ -933,7 +933,7 @@ BGFX_C_API bool bgfx_vertex_decl_has(const bgfx_vertex_decl_t* _this, bgfx_attri * @param[in] _num * */ -BGFX_C_API void bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _this, uint8_t _num); +BGFX_C_API bgfx_vertex_decl_t* bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _this, uint8_t _num); /** * End VertexDecl. @@ -3206,11 +3206,11 @@ BGFX_C_API void bgfx_blit(bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_ struct bgfx_interface_vtbl { void (*attachment_init)(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _mip, uint8_t _resolve); - void (*vertex_decl_begin)(bgfx_vertex_decl_t* _this, bgfx_renderer_type_t _rendererType); - void (*vertex_decl_add)(bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); + bgfx_vertex_decl_t* (*vertex_decl_begin)(bgfx_vertex_decl_t* _this, bgfx_renderer_type_t _rendererType); + bgfx_vertex_decl_t* (*vertex_decl_add)(bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); void (*vertex_decl_decode)(const bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib, uint8_t * _num, bgfx_attrib_type_t * _type, bool * _normalized, bool * _asInt); bool (*vertex_decl_has)(const bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib); - void (*vertex_decl_skip)(bgfx_vertex_decl_t* _this, uint8_t _num); + bgfx_vertex_decl_t* (*vertex_decl_skip)(bgfx_vertex_decl_t* _this, uint8_t _num); void (*vertex_decl_end)(bgfx_vertex_decl_t* _this); void (*vertex_pack)(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_decl_t * _decl, void* _data, uint32_t _index); void (*vertex_unpack)(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_decl_t * _decl, const void* _data, uint32_t _index); diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index d597b1a33..c96891670 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(96) +#define BGFX_API_VERSION UINT32_C(97) /// Color RGB/alpha/depth write. When it's not specified write will be disabled. #define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write. diff --git a/scripts/bgfx-idl.lua b/scripts/bgfx-idl.lua index 5c48528fc..6b63eb38e 100644 --- a/scripts/bgfx-idl.lua +++ b/scripts/bgfx-idl.lua @@ -13,6 +13,8 @@ local func_actions = { interface_import = ",\n\t\t\t", c99_interface = "\n", cpp_interface = "\n", + c99_functionid = "\n\t", + cpp_functionid = "\n\t\t", } local type_actions = { @@ -56,6 +58,8 @@ BGFX_C_API $CRET bgfx_$CFUNCNAME($CARGS) $POSTRETCTOC } ]] +functemp.c99_functionid = "BGFX_FUNCTION_ID_$CFUNCNAMEUPPER," +functemp.cpp_functionid = "$CFUNCNAMECAML," for action,temp in pairs(functemp) do funcgen[action] = cfunc(function(func) @@ -276,15 +280,15 @@ local function genidl(filename, outputfile) out:close() end -function doIdl() - local files = { - ["bgfx.h"] = "../include/bgfx/c99", - ["bgfx.idl.inl"] = "../src", - } - for filename, path in pairs (files) do - genidl(filename, path .. "/" .. filename) - end +local files = { + ["bgfx.h"] = "../include/bgfx/c99", + ["bgfx.idl.inl"] = "../src", +-- ["bgfx.hpp"] = ".", +-- ["bgfx.shim.cpp"] = ".", +} - os.exit() +for filename, path in pairs (files) do + path = (...) or path + genidl(filename, path .. "/" .. filename) end diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index b97c79760..dcb397b4f 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -389,14 +389,14 @@ struct.Memory --- Transient index buffer. struct.TransientIndexBuffer - .data "int8_t*" --- Pointer to data. + .data "uint8_t*" --- Pointer to data. .size "uint32_t" --- Data size. .startIndex "uint32_t" --- First index. .handle "IndexBufferHandle" --- Index buffer handle. --- Transient vertex buffer. struct.TransientVertexBuffer - .data "int8_t*" --- Pointer to data. + .data "uint8_t*" --- Pointer to data. .size "uint32_t" --- Data size. .startVertex "uint32_t" --- First vertex. .stride "uint16_t" --- Vertex stride. @@ -405,7 +405,7 @@ struct.TransientVertexBuffer --- Instance data buffer info. struct.InstanceDataBuffer - .data "int8_t*" --- Pointer to data. + .data "uint8_t*" --- Pointer to data. .size "uint32_t" --- Data size. .offset "uint32_t" --- Offset in vertex buffer. .num "uint32_t" --- Number of instances. @@ -431,7 +431,7 @@ struct.UniformInfo .num "uint16_t" --- Number of elements in array. --- Frame buffer texture attachment info. -struct.Attachment +struct.Attachment { shortname } .access "Access::Enum" --- Attachement access. See `Access::Enum`. .handle "TextureHandle" --- Render target texture handle. .mip "uint16_t" --- Mip level. @@ -549,15 +549,16 @@ handle "VertexDeclHandle" --- Start VertexDecl. func.VertexDecl.begin - "void" + "VertexDecl&" .rendererType "RendererType::Enum" + { default = "RendererType::Noop" } --- Add attribute to VertexDecl. --- --- @remarks Must be called between begin/end. --- func.VertexDecl.add - "void" + "VertexDecl&" .attrib "Attrib::Enum" --- Attribute semantics. See: `bgfx::Attrib` .num "uint8_t" --- Number of elements 1, 2, 3 or 4. .type "AttribType::Enum" --- Element type. @@ -585,7 +586,7 @@ func.VertexDecl.has { const } --- Skip `_num` bytes in vertex stream. func.VertexDecl.skip - "void" + "VertexDecl&" .num "uint8_t" -- Notice: `end` is a keyword in lua. @@ -825,7 +826,7 @@ func.dbgTextClear .attr "uint8_t" --- Background color. { default = 0 } .small "bool" --- Default or 8x8 font. - { dafault = false } + { default = false } --- Print formatted data to internal debug text character-buffer (VGA-compatible text mode). func.dbgTextPrintf { vararg = "dbgTextPrintfVargs" } @@ -2026,7 +2027,6 @@ func.Encoder.blit { cpponly } .dstX "uint16_t" --- Destination texture X position. .dstY "uint16_t" --- Destination texture Y position. .src "TextureHandle" --- Source texture handle. - { default = 0 } .srcX "uint16_t" --- Source texture X position. { default = 0 } .srcY "uint16_t" --- Source texture Y position. @@ -2096,6 +2096,7 @@ func.requestScreenShot func.renderFrame "RenderFrame::Enum" --- Current renderer context state. See: `bgfx::RenderFrame`. .msecs "int32_t" --- Timeout in milliseconds. + { default = -1 } --- Set platform data. --- @@ -2434,9 +2435,9 @@ func.submit .id "ViewId" --- View id. .program "ProgramHandle" --- Program. .depth "uint32_t" --- Depth for sorting. - { default = 0 } + { default = 0 } .preserveState "bool" --- Preserve internal draw state for next draw call submit. - { default = false } + { default = false } --- Submit primitive with occlusion query for rendering. func.submit { cname = "submit_occlusion_query" } @@ -2445,9 +2446,9 @@ func.submit { cname = "submit_occlusion_query" } .program "ProgramHandle" --- Program. .occlusionQuery "OcclusionQueryHandle" --- Occlusion query. .depth "uint32_t" --- Depth for sorting. - { default = 0 } + { default = 0 } .preserveState "bool" --- Preserve internal draw state for next draw call submit. - { default = false } + { default = false } --- Submit primitive for rendering with index and instance data info from --- indirect buffer. @@ -2457,13 +2458,13 @@ func.submit { cname = "submit_indirect" } .program "ProgramHandle" --- Program. .indirectHandle "IndirectBufferHandle" --- Indirect buffer. .start "uint16_t" --- First element in indirect buffer. - { default = 0 } + { default = 0 } .num "uint16_t" --- Number of dispatches. - { default = 1 } + { default = 1 } .depth "uint32_t" --- Depth for sorting. - { default = 0 } + { default = 0 } .preserveState "bool" --- Preserve internal draw state for next draw call submit. - { default = false } + { default = false } --- Set compute index buffer. func.setBuffer { cname = "set_compute_index_buffer" } @@ -2549,7 +2550,6 @@ func.blit { cpponly } .dstX "uint16_t" --- Destination texture X position. .dstY "uint16_t" --- Destination texture Y position. .src "TextureHandle" --- Source texture handle. - { default = 0 } .srcX "uint16_t" --- Source texture X position. { default = 0 } .srcY "uint16_t" --- Source texture Y position. diff --git a/scripts/codegen.lua b/scripts/codegen.lua index 99c8864e2..e18955316 100644 --- a/scripts/codegen.lua +++ b/scripts/codegen.lua @@ -168,8 +168,17 @@ local function gen_ret_conversion(all_types, func) postfix[#postfix+1] = "return handle_ret.c;" postfix_cpp2c[#postfix_cpp2c+1] = "return handle_ret.cpp;" elseif func.ret.fulltype ~= "void" then - local ctype_conversion = ctype.name == ctype.cname and "" or ("(" .. func.ret.ctype .. ")") - local conversion_back = ctype.name == ctype.cname and "" or ("(" .. func.ret.cpptype .. ")") + local ctype_conversion = "" + local conversion_back = "" + if ctype.name ~= ctype.cname then + if func.ret.ref then + ctype_conversion = "(" .. func.ret.ctype .. ")&" + conversion_back = "*(" .. func.ret.ptype .. ")" + else + ctype_conversion = "(" .. func.ret.ctype .. ")" + conversion_back = "(" .. func.ret.cpptype .. ")" + end + end if #postfix > 0 then func.ret_prefix = string.format("%s retValue = %s", func.ret.ctype , ctype_conversion) func.ret_prefix_cpp2c = string.format("%s retValue = %s", func.ret.cpptype , conversion_back) @@ -219,6 +228,7 @@ function codegen.nameconversion(all_types, all_funcs) v.cname = "bgfx_".. cname .. "_t" end if v.enum then + v.typename = v.name v.name = v.name .. "::Enum" end end @@ -379,8 +389,8 @@ local function codetemp(func) if arg.array then name = name .. arg.array end - if arg.default then - name = name .. " = " .. arg.default + if arg.default ~= nil then + name = name .. " = " .. tostring(arg.default) end cargs[#cargs+1] = cname args[#args+1] = name @@ -596,7 +606,7 @@ function codegen.gen_enum_define(enum) comment = "/// " .. enum.comment end local temp = { - NAME = enum.name, + NAME = enum.typename, COMMENT = comment, ITEMS = table.concat(items, "\n\t\t"), } @@ -701,7 +711,7 @@ function codegen.gen_struct_define(struct, methods) assert(type(struct.struct) == "table", "Not a struct") local items = {} for _, item in ipairs(struct.struct) do - text_with_comments(items, item, false, methods ~= nil) + text_with_comments(items, item, false, methods ~= nil and not struct.shortname) end local ctor = {} if struct.ctor then diff --git a/scripts/idl.lua b/scripts/idl.lua index 96aa1c023..5c7d6e724 100644 --- a/scripts/idl.lua +++ b/scripts/idl.lua @@ -229,6 +229,7 @@ idl.cfunc = "cfunc" idl.underscore = "underscore" idl.conly = "conly" idl.cpponly = "cpponly" +idl.shortname = "shortname" idl.NULL = "NULL" idl.UINT16_MAX = "UINT16_MAX" idl.INT32_MAX = "INT32_MAX" diff --git a/src/bgfx.idl.inl b/src/bgfx.idl.inl index cb240dc31..becce7ed9 100644 --- a/src/bgfx.idl.inl +++ b/src/bgfx.idl.inl @@ -15,16 +15,16 @@ BGFX_C_API void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_hand This->init(handle.cpp, (bgfx::Access::Enum)_access, _layer, _mip, _resolve); } -BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _this, bgfx_renderer_type_t _rendererType) +BGFX_C_API bgfx_vertex_decl_t* bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _this, bgfx_renderer_type_t _rendererType) { bgfx::VertexDecl* This = (bgfx::VertexDecl*)_this; - This->begin((bgfx::RendererType::Enum)_rendererType); + return (bgfx_vertex_decl_t*)&This->begin((bgfx::RendererType::Enum)_rendererType); } -BGFX_C_API void bgfx_vertex_decl_add(bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt) +BGFX_C_API bgfx_vertex_decl_t* bgfx_vertex_decl_add(bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt) { bgfx::VertexDecl* This = (bgfx::VertexDecl*)_this; - This->add((bgfx::Attrib::Enum)_attrib, _num, (bgfx::AttribType::Enum)_type, _normalized, _asInt); + return (bgfx_vertex_decl_t*)&This->add((bgfx::Attrib::Enum)_attrib, _num, (bgfx::AttribType::Enum)_type, _normalized, _asInt); } BGFX_C_API void bgfx_vertex_decl_decode(const bgfx_vertex_decl_t* _this, bgfx_attrib_t _attrib, uint8_t * _num, bgfx_attrib_type_t * _type, bool * _normalized, bool * _asInt) @@ -41,10 +41,10 @@ BGFX_C_API bool bgfx_vertex_decl_has(const bgfx_vertex_decl_t* _this, bgfx_attri return This->has((bgfx::Attrib::Enum)_attrib); } -BGFX_C_API void bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _this, uint8_t _num) +BGFX_C_API bgfx_vertex_decl_t* bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _this, uint8_t _num) { bgfx::VertexDecl* This = (bgfx::VertexDecl*)_this; - This->skip(_num); + return (bgfx_vertex_decl_t*)&This->skip(_num); } BGFX_C_API void bgfx_vertex_decl_end(bgfx_vertex_decl_t* _this)