- Work in progress.
This guide and trouble shoot for AI model and code review. As the module is broken up for vulkan to setup custom module.
To point out the area needed to setup.
This script will handle config and build.
This will check if libaray dll exist to not rebuild dll. If not exist rebuild or compile new dll.
- https://www.flecs.dev/flecs/log_8h_source.html#l00376
- ECS_INTERNAL_ERROR
- https://www.flecs.dev/flecs/group__c__addons__log.html#gadb59e689daa4a653f4723cf6f098932b
- ECS_INVALID_OPERATION
- add and remove entity mesh.
- struct components for transform for 2D, 3D and mesh data.
- log
- event
- add
- remove
- query
- observers
- perfabs
- relationships
- entity
- component
- system function
Work in progress.
There are still some hard code on world context variables. Reason is the vulkan needed to be test for setup and render correctly. Flecs struct component has not been added to as entity yet. As there some need to correct way to handle entity id system.
Vulkan and SDL setup variable have world context for easy access from flecs without needs of component. It might change later depend on the way code correctly.
Flecs have predfine phase that being used for on Start and Pre Update phase.
The setup module phase is SetupModulePhase when vulkan graphic finished setup.
ecs_system_init(world, &(ecs_system_desc_t){
.entity = ecs_entity(world, {
.name = "Name_SetupSystem",
.add = ecs_ids(ecs_dependson(GlobalPhases.SetupModulePhase))
}),
.callback = Name_SetupSystem
});
Those are hard code and later remove for flecs component build.
// Vulkan Core
SDL_Window *window; // SDL Window
VkInstance instance; // Vulkan instance
VkDebugUtilsMessengerEXT debugMessenger; // Vulkan debug messenger
VkSurfaceKHR surface; // Vulkan surface from SDL
VkPhysicalDevice physicalDevice; // Vulkan physical device
VkDevice device; // Vulkan logical device
VkQueue graphicsQueue; // Vulkan graphics queue
VkQueue presentQueue; // Vulkan present queue
uint32_t graphicsFamily; // Graphics queue family index
uint32_t presentFamily; // Present queue family index
VkSwapchainKHR swapchain; // Vulkan swapchain
VkImage *swapchainImages; // Vulkan swapchain images
VkImageView *swapchainImageViews; // Vulkan swapchain image views
uint32_t imageCount; // Number of swapchain images
VkExtent2D swapchainExtent; // Swapchain dimensions
VkRenderPass renderPass; // Vulkan render pass (shared)
VkFramebuffer *framebuffers; // Vulkan framebuffers
VkCommandPool commandPool; // Vulkan command pool
VkCommandBuffer commandBuffer; // Vulkan command buffer
VkSemaphore imageAvailableSemaphore; // Sync: acquire image
VkSemaphore renderFinishedSemaphore; // Sync: rendering complete
VkFence renderFinishedFence; // Sync: fence for render completion
uint32_t imageIndex; // Current swapchain image index
VkFence inFlightFence; // Sync: fence for frame in flight
uint32_t width; // Window width (from swapchain)
uint32_t height; // Window height (from swapchain)
bool shouldQuit; // SDL quit flag
bool hasError; // Error flag
const char *errorMessage; // Error message
// Triangle Mesh
VkBuffer triVertexBuffer; // Triangle vertex buffer
VkDeviceMemory triVertexBufferMemory; // Triangle vertex buffer memory
VkBuffer triIndexBuffer; // Triangle index buffer
VkDeviceMemory triIndexBufferMemory; // Triangle index buffer memory
VkPipelineLayout triPipelineLayout; // Triangle pipeline layout
VkPipeline triGraphicsPipeline; // Triangle graphics pipeline
// Text Rendering
VkBuffer textVertexBuffer; // Text vertex buffer
VkDeviceMemory textVertexBufferMemory; // Text vertex buffer memory
VkBuffer textIndexBuffer; // Text index buffer
VkDeviceMemory textIndexBufferMemory; // Text index buffer memory
VkDescriptorPool textDescriptorPool; // Text descriptor pool
VkDescriptorSet textDescriptorSet; // Text descriptor set
VkDescriptorSetLayout textDescriptorSetLayout; // Text descriptor set layout
VkPipelineLayout textPipelineLayout; // Text pipeline layout
VkPipeline textPipeline; // Text pipeline
VkImage textFontImage; // Font atlas texture
VkDeviceMemory textFontImageMemory; // Font atlas memory
VkImageView textFontImageView; // Font atlas image view
VkSampler textFontSampler; // Font texture sampler
void *textGlyphs; // Metrics for ASCII 32-126
int textAtlasWidth; // Font atlas width
int textAtlasHeight; // Font atlas height
// ImGui
VkDescriptorPool imguiDescriptorPool; // ImGui descriptor pool
ImGuiContext* imguiContext; // ImGui context
bool isImGuiInitialized; // ImGui initialization flag
Note missing some variables but it those ideas base on AI model build and refs. As it still need to use vulkan ref variables to access different area.
Note that it need to setup in order to on start and loop render.
typedef struct {
// loop order render
ecs_entity_t LogicUpdatePhase;
ecs_entity_t BeginRenderPhase;
ecs_entity_t BeginCMDBufferPhase;
ecs_entity_t CMDBufferPhase;
ecs_entity_t EndCMDBufferPhase;
ecs_entity_t EndRenderPhase;
// setup once
ecs_entity_t SetupPhase;
ecs_entity_t InstanceSetupPhase;
ecs_entity_t SurfaceSetupPhase;
ecs_entity_t DeviceSetupPhase;
ecs_entity_t SwapchainSetupPhase;
ecs_entity_t RenderPassSetupPhase;
ecs_entity_t FramebufferSetupPhase;
ecs_entity_t CommandPoolSetupPhase;
ecs_entity_t CommandBufferSetupPhase;
ecs_entity_t PipelineSetupPhase;
ecs_entity_t SyncSetupPhase;
ecs_entity_t SetupModulePhase;
} FlecsPhases;
It use EcsDependsOn on the call once start. Only use single EcsDependsOn.
- InstanceSetupSystem -> SurfaceSetupSystem -> DeviceSetupSystem -> SwapchainSetupSystem -> TriangleBufferSetupSystem -> RenderPassSetupSystem -> FramebufferSetupSystem -> CommandPoolSetupSystem -> CommandBufferSetupSystem -> PipelineSetupSystem -> SyncSetupSystem -> SetUpLogicSystem (modules init)
- LogicUpdatePhase: (empty for now)
- BeginRenderPhase: BeginRenderSystem (acquire image)
- BeginCMDBufferPhase: BeginCMDBufferSystem (start command buffer and render pass)
- CMDBufferPhase: TriangleRenderBufferSystem -> TextRenderSystem -> ImGuiRenderSystem
- EndCMDBufferPhase: EndCMDBufferSystem (end render pass and command buffer)
- EndRenderPhase: EndRenderSystem (submit and present)
Work in progres. It required some setup in font text for position and render to screen in 2D world.
- https://github.com/freetype/freetype
- https://freetype.org/freetype2/docs/tutorial/step1.html#section-7
There are couple steps need to render text.
- create plane or quad triangle mesh.
- load font
- text data
- create text into image with freetype format.
- apply texture to mesh and shader.
Just a guess need to look into.
TriangleBufferSetupSystem
TriangleRenderBufferSystem > ecs_dependson > BeginCMDBufferPhase
Note it still need to setup shader as well. frag.spv.h and vert.spv.h
Need to review code area.
Note it use vulkan set up to warp into the imgui to create vulkan api.
ImGuiSetupSystem > ecs_dependson > SetupModulePhase
Vulkan setup every things when finish call the next SetupModulePhase.
ImGuiCMDBufferSystem > ecs_dependson > BeginCMDBufferPhase
- Grok 3 AI Model
- SDL 3.x Github
- Flecs 4.x Github