Comments (7)
Hello and nice to meet you!
First of all, remember that I'm not an expert in Vulkan, so if you need help or want to learn more, consider joining the Vulkan Discord Server or the Vulkan Discord Server.
I suppose you're new to Vulkan and that you did or saw a tutorial that only render a single mesh, so I'll try to explain how to render more than one mesh.
The light rendering is a more advanced topic, that I still don't know well, and you probably want to study how to implement a Forward Rendering or a Deferred Rendering structure.
(Remember that this engine in its current state only render the sun directional light in a Forward Rendering way)
So, first of all, everything that you want the GPU to draw must be in a Command Buffer.
The Command Buffer (I'll call it CB) contains commands that can be submitted to a Queue (and so to the GPU).
The example you have seen probably has a small CB, that's built only one time and load only one mesh.
This because if you want to add/remove stuff to draw, you must rebuild the CB.
This engine, use two command buffers (see wiki): one is the one currently being drawn, and another is being rebuilt in background, to allow meshes to be added/removed anytime.
It's completely up to you when or how frequently rebuilt the CB, depending of what you need to achieve, because remember that's an heavy operation.
(Note: In fact, you should only render meshes that are on screen, with a tecnique called Occlusion Culling).
So, about my engine: the parts you want to see are probably these:
- RenderManager.cpp#L457: this is the function
create_command_buffer()
that rebuild the CB at runtime, it use a variable calledflip_flop
to swap the two CB i mentioned before. The important part for you is thatfor
cycle, for every mesh, it submit it to the CB to render it; - StandardCommandBuffer.cpp#L219: this is the main CB class i use. Remember it also contains commands to draw shadows above the linked function, so the important part for you is the one i sent: to draw a mesh you (usually) must call:
vkCmdBindPipeline(...)
vkCmdBindVertexBuffers(...)
vkCmdBindIndexBuffer(...)
vkCmdBindDescriptorSets(...)
vkCmdDrawIndexed(...)
Remember that mine is like command_buffers[i].bindPipeline(...)
because i use the C++ API.
Remember also that you need to call CB functions such as vkBeginCommandBuffer()
and vkCmdBeginRenderPass()
.
You can read about submitting a mesh in this tutorial section.
Hope this helped you, please tell me if you have more questions about this.
Summary of important things:
- Everything you want to draw must be in a command in a Command Buffer;
- The command buffer must be in the Recording state to submit commands to it, and in the Executable state to be executed.
(See the Vulkan Doc page to read more...)
from scrapengine.
Thanks you reply! There is my understanding about how to render multiple objects from your code:
- create vertex buffer and index buffer for every obj
- using one commandbuffer to draw every object at one time
i can find thecommand_buffers_[index].command_buffer->end_command_buffer_render_pass();
but cannot find the begin of render pass.
And the gui render, i found you are using ImGui::Render();
, i'm not familiar with imgui, is this using a specified commandbuffer?
from scrapengine.
HHello again!
So, about the main CB:
- It begin here to be in Recording state: RenderManager.cpp#L437
- Note that general functions are in the parent class, and most of them are called from
create_command_buffer
, such as: - The RenderPass begin in the
init_command_buffer
function: StandardCommandBuffer.cpp#L159
The UI is a bit different, because again, when the UI change the Command Buffer may change. If you want to note how it works, this Sascha example contains the minimal stuff to draw the UI, and you can see stuff better in there.
That example use a single CB and rebuild it every frame, my engine use a third CD that's rebuilt on background (in a thread) every frame (see wiki).
The basic concept is this, for every frame:
- Read UI commands that are between
ImGui::NewFrame();
andImGui::Render();
, in my engine this are defined by the user, for example here in the game (MainMenu.cpp); - When the commands are recorded, generate buffers data;
- Add the UI buffers to the CB, in my case GuiCommandBuffer::load_ui.
Then, as i said, i use three CB: two for the meshes and one for the GUI, so for one frame i submit both the meshes-CB and the UI-CB to the Queue.
Again, this is totally up to you, you can use a single CB for everything or 100 different CB.
The example i linked above for the UI (that i really suggest you to look at) use a single CB but do exactly the same steps mentioned above here.
Hope this helps you to understand the basics, do not make too many steps at time because it's very confusing, do small things every steps and you will understand better.
from scrapengine.
Thanks again! i'm creating my own game engine now for understand the vulkan, maybe we can talking on the telegram or icq, because my phone cannot register the Discord : (
from scrapengine.
Sorry but i don't provide personal support on Telegram or similar 😅
I suggest you to use Discord on pc downloading it or on Browser, both Discord and Slack runs in any pc browser if you don't want to download them.
from scrapengine.
all right, but thanks, i will do more learning.By the way, maybe you can provide a cmake version : )
from scrapengine.
Good luck then!
I know, sorry, i don't know cmake well enough to move the project to cmake but that's something i could do sooner or later ^^
from scrapengine.
Related Issues (11)
- The engine may crash because the vector cleanup is not synced
- Rotations are broken HOT 1
- Gameobject parent-child rotation have broken values
- Port memory allocation to VulkanMemoryAllocator HOT 1
- Forward declarations
- Compile failed with VS2017 HOT 6
- About light module HOT 2
- How to link an external git repo as a library in github. HOT 2
- Use premake to make the engine development compatible across Windows and Linux HOT 3
- Assimp with vs2017 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scrapengine.