Git Product home page Git Product logo

Comments (7)

ScrappyCocco avatar ScrappyCocco commented on May 25, 2024

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 called flip_flop to swap the two CB i mentioned before. The important part for you is that for 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:
    1. vkCmdBindPipeline(...)
    2. vkCmdBindVertexBuffers(...)
    3. vkCmdBindIndexBuffer(...)
    4. vkCmdBindDescriptorSets(...)
    5. 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.

RMTT avatar RMTT commented on May 25, 2024

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 the command_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.

ScrappyCocco avatar ScrappyCocco commented on May 25, 2024

HHello again!

So, about the main CB:

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:

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.

RMTT avatar RMTT commented on May 25, 2024

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.

ScrappyCocco avatar ScrappyCocco commented on May 25, 2024

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.

RMTT avatar RMTT commented on May 25, 2024

all right, but thanks, i will do more learning.By the way, maybe you can provide a cmake version : )

from scrapengine.

ScrappyCocco avatar ScrappyCocco commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.