- All scopes should be start next line of the statement.
- ex)
if (condition) { // ... }
- If it is a single line comment in
*.cppfiles, use// - If it is a single line comment in
*.hfiles, use/**/ - If it is a multi line comment, follow below format
- ex)
/** * Comment something */
- If it is a instruction commnet, follow below format
- ex)
int num = 0; // assign 0 to num variable
- All of API specific class should be named with a prefix 'MK' to distinguish from vulkan class.
- ex)
class MKInstance { // ... };
- On the other hand, Any other class can be named without prefix.
- ex)
class Allocator { // ... };
- private member A private member should be prefixed with '_' (underscore)
- ex)
private: doulbe _privateMember;
- vulkan prefix All of class members should be prefixed with 'vk'
- ex)
private: VkInstance _vkInstance;
- murakano class prefix An instance of Murakano-specific class should be prefixed with 'mk'
- ex)
private: MKInstance _mkInstance;
Functions should be named in camel case with the first letter being uppercase.
- ex)
public: void CreateInstance();
But there are some exceptions. First, If it is a function to get a proxy address of extension function and return it, i'm going to follow the naming convention of vulkan.
- ex)
public: PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR(...);
-
If there is a need to specify the role of certain group of members, follow below convention
-
ex)
/* states */ bool isValid; int count;
- If a function has number of parameters less than three, write the signature in one line.
- If a function has number of parameters more than three, Follow below formats
void MKCommandService::SubmitCommandBufferToQueue( uint32_t currentFrame, VkSemaphore waitSemaphores[], VkPipelineStageFlags waitStages[], VkSemaphore signalSemaphores[], VkQueue loadedQueue, VkFence fence = nullptr );
-
When there are multiple members under an access modifier, a space of longest type name has a single space between type and its identifier. The rest of members follow the space of the member whose type name is the longest.
-
ex)
class MKCommandService { public: VkCommandbuffer _commandBuffer; VkCommandPool _commandPool; };
-
function spacing follow same rules, but the rule applied on each category. If a group of function is const, there should be space mathcing of them either.
-
ex)
/* getters */ VkSwapchainKHR GetSwapchain() const { return _vkSwapchain; } VkFormat GetSwapchainImageFormat() const { return _vkSwapchainImageFormat; } VkExtent2D GetSwapchainExtent() const { return _vkSwapchainExtent; } VkFramebuffer GetFramebuffer(uint32_t imageIndex) const { return _vkSwapchainFramebuffers[imageIndex]; } VkRenderPass RequestRenderPass() const { return _mkRenderPassPtr->GetRenderPass(); } /* setters */ void SetFrameBufferResized(bool isResized) { _framebufferResized = isResized; }
- If a member function can be implemented in a single line, implement it in header file.
- ex)
/* getters */ VkSwapchainKHR GetSwapchain() const { return _vkSwapchain; }
- If not, implement the function in separate cpp file which included the header file holding the signature of it.
- namespaces in Murakano project should be used to group utility functions if and only if the functions shares similar role.
- ex)
namespace mk { namespace vk { void CreateImage(); void CreateImageView(); } }
- All of the namespace should be scoped inside 'mk' namespace
- ex)
namespace mk { // ... namespace image { //... image uitilites } }
- All of the enum definition should starts with capital letter with a prefix 'E'.
- ex)
enum EResult { SUCCESS, FAIL, };
- Variants of enum should be named in uppercase and separated by underscore.
- ex)
enum ERayTracingShaderType { RAYGEN, MISS, CLOSEST_HIT, ANY_HIT, };
- All of name of the global objects should starts with a prefix 'G'
- ex)
class Allocator { /* some code */} Allocator* GAllocator; // starts with prefix 'G'