4
4
| -------------------------------------------------------------------------| --------------------------------------------------------------------| -------------------------------------------------------------------| -----------------------------------------------------------------|
5
5
| ![ Hello Triangle on Windows] ( Screenshots/HelloTriangleWinDirectX12.jpg ) | ![ Hello Triangle on Linux] ( Screenshots/HelloTriangleLinVulkan.jpg ) | ![ Hello Triangle on MacOS] ( Screenshots/HelloTriangleMacMetal.jpg ) | ![ Hello Triangle on iOS] ( Screenshots/HelloTriangleIOSMetal.jpg ) |
6
6
7
- This tutorial demonstrates colored triangle rendering implemented in just 130 lines of code using Methane Kit:
7
+ This tutorial demonstrates how to render a colored triangle in just 130 lines of code using Methane Kit:
8
8
- [ HelloTriangleApp.cpp] ( HelloTriangleApp.cpp )
9
9
- [ Shaders/HelloTriangle.hlsl] ( Shaders/HelloTriangle.hlsl )
10
10
11
- Tutorial demonstrates the following Methane Kit features and techniques:
12
- - Use base graphics application class for deferred frames rendering with triple buffering.
13
- - Load shaders, creating program and render state .
14
- - Use render command lists for encoding draw commands.
15
- - Execute command lists on GPU and presenting frame buffers on screen.
16
- - Configure cross-platform application build with shaders compilation to embedded resources.
11
+ The tutorial covers the following Methane Kit features and techniques:
12
+ - Using the base graphics application class for deferred frame rendering with triple buffering.
13
+ - Loading shaders, creating programs, and setting render states .
14
+ - Using render command lists to encode draw commands.
15
+ - Executing command lists on the GPU and presenting frame buffers on the screen.
16
+ - Configuring cross-platform application builds with shaders compiled into embedded resources.
17
17
18
18
## Application Controls
19
19
@@ -23,14 +23,14 @@ Common keyboard controls are enabled by the `Platform` and `Graphics` applicatio
23
23
24
24
## Application and Frame Class Definitions
25
25
26
- Application class ` HelloTriangleApp ` is derived from the base template class [ Graphics::App<HelloTriangleFrame >] ( /Modules/Graphics/App )
27
- which implements base platform and graphics application infrastructure with support of deferred frames rendering.
26
+ The ` HelloTriangleApp ` application class is derived from the base template class [ Graphics::App<HelloTriangleFrame >] ( /Modules/Graphics/App ) ,
27
+ which implements the base platform and graphics application infrastructure with support for deferred frame rendering.
28
28
29
- Application frame class ` HelloTriangleFrame ` is derived from the base class ` Graphics::AppFrame ` and extends it
30
- with render command list ` render_cmd_list_ptr ` and command list set ` execute_cmd_list_set_ptr ` submitted
31
- for rendering to frame buffer ` index ` . Application is initialized with default settings using ` Graphics::AppSettings ` structure,
32
- which is initialized with helper function ` Tutorials::GetGraphicsTutorialAppSettings(...) ` .
33
- Destroying of application along with its resources is delayed until all rendering is completed on GPU.
29
+ The ` HelloTriangleFrame ` class is derived from the base class ` Graphics::AppFrame ` and extends it with a render command list
30
+ ` render_cmd_list_ptr ` and a command list set ` execute_cmd_list_set_ptr ` submitted for rendering to the frame buffer ` index ` .
31
+ The application is initialized with default settings using the ` Graphics::AppSettings ` structure, which is initialized
32
+ with the helper function ` Tutorials::GetGraphicsTutorialAppSettings(...) ` . The destruction of the application and its
33
+ resources is delayed until all rendering is completed on the GPU.
34
34
35
35
``` cpp
36
36
#include < Methane/Kit.h>
@@ -75,31 +75,32 @@ public:
75
75
76
76
## Graphics Resources Initialization
77
77
78
- Application class ` HelloTriangleApp ` keeps frame independent resources in private class members.
79
- In this tutorial it is only render state ` m_render_state ` which is initialized in ` HelloTriangleApp::Init ` method.
80
- Render state is created with ` GetRenderContext().CreateRenderState(...) ` factory method of the render context, which encapsulate
81
- program created inline with ` GetRenderContext().CreateProgram(...) ` . Program is created with a set of vertex and pixel shaders
82
- created by ` Rhi::Program::ShaderSet ` shaders set description which takes ` Data::IProvider ` and
83
- ` IShader::EntryPoint ` structure consisting of file and function names. Compiled shader data is embedded in executable resources
84
- and is accessed via shader data provider singleton available with ` Data::ShaderProvider::Get() ` .
85
- Program also defines input buffer layout using argument semantic names from HLSL shaders. Methane graphics abstraction
86
- uses shader reflection to automatically identify argument types and offset sizes to build underlying DirectX, Metal or Vulkan
87
- layout description. Render target color formats ` GetScreenRenderPattern().GetAttachmentFormats() ` are also required for program creation,
88
- these formats are taken from ` Rhi::RenderPattern ` object provided by the base class ` Graphics::App ` and describing general
89
- configuration of color/ depth/ stencil attachments used for final drawing to window on screen.
90
- ` RenderState::Settings ` requires ` Rhi::RenderPattern ` object and also contains settings of rasterizer, depth, stencil,
91
- blending states which are skipped with default values for simplicity of this tutorial.
92
-
93
- Render command lists are created from the rendering command queue ` cmd_queue ` acquired from render context
94
- ` GetRenderContext().GetRenderCommandKit().GetQueue() ` . Command lists ` frame.render_cmd_list ` are created for each frame using
95
- ` cmd_queue.CreateRenderCommandList(frame.screen_pass) ` factory method of the ` Rhi::CommandQueue ` taking ` Rhi::RenderPass ` as an argument.
96
- So the created command list can be used for rendering only to that particular render pass. Command lists are executed as a
97
- part of command list sets ` Rhi::CommandListSet ` which include only one command list in this example and are also created for each frame
98
- ` frame.execute_cmd_list_set ` .
99
-
100
- Finally, at the end of ` Init() ` function ` GraphicsApp::CompleteInitialization() ` is called to complete graphics
78
+ The ` HelloTriangleApp ` class keeps frame- independent resources in private class members. In this tutorial, it is only
79
+ the render state ` m_render_state ` , which is initialized in the ` HelloTriangleApp::Init ` method. The render state is
80
+ created with the ` GetRenderContext().CreateRenderState(...) ` factory method of the render context, which encapsulates
81
+ the program created inline with ` GetRenderContext().CreateProgram(...) ` . The program is created with a set of vertex and
82
+ pixel shaders described by the ` Rhi::Program::ShaderSet ` structure, which takes ` Data::IProvider ` and ` IShader::EntryPoint `
83
+ structures consisting of file and function names. Compiled shader data is embedded in executable resources and accessed
84
+ via the shader data provider singleton available with ` Data::ShaderProvider::Get() ` . The program also defines the input
85
+ buffer layout using argument semantic names from HLSL shaders. Methane graphics abstraction uses shader reflection to
86
+ automatically identify argument types and offset sizes to build the underlying DirectX, Metal, or Vulkan layout description.
87
+ Render target color formats ` GetScreenRenderPattern().GetAttachmentFormats() ` are also required for program creation.
88
+ These formats are taken from the ` Rhi::RenderPattern ` object provided by the base class ` Graphics::App ` , which describes
89
+ the general configuration of color, depth, and stencil attachments used for final drawing to the window on the screen.
90
+ ` RenderState::Settings ` requires an ` Rhi::RenderPattern ` object and also contains settings for rasterizer, depth, stencil,
91
+ and blending states, which are skipped with default values for simplicity in this tutorial.
92
+
93
+ Render command lists are created from the rendering command queue ` cmd_queue ` acquired from the render context
94
+ ` GetRenderContext().GetRenderCommandKit().GetQueue() ` . Command lists ` frame.render_cmd_list ` are created for each frame
95
+ using the ` cmd_queue.CreateRenderCommandList(frame.screen_pass) ` factory method of the ` Rhi::CommandQueue ` , taking
96
+ ` Rhi::RenderPass ` as an argument. The created command list can be used for rendering only to that particular render pass.
97
+ Command lists are executed as part of command list sets ` Rhi::CommandListSet ` , which include only one command list in
98
+ this example and are also created for each frame ` frame.execute_cmd_list_set ` .
99
+
100
+ Finally, at the end of the ` Init() ` function, ` GraphicsApp::CompleteInitialization() ` is called to complete graphics
101
101
resources initialization and prepare for rendering.
102
102
103
+
103
104
``` cpp
104
105
class HelloTriangleApp final : public GraphicsApp
105
106
{
@@ -151,21 +152,23 @@ public:
151
152
152
153
## Frame Rendering Cycle
153
154
154
- Rendering is implemented in overridden ` HelloTriangleApp::Render ` method. Base graphics application
155
- rendering is executed first with ` GraphicsApp::Render() ` and rendering is continued only when it succeedes,
156
- it waits for previous iteration of rendering cycle completion and availability of all frame resources.
157
- Then current frame resources are requested with ` GraphicsApp::GetCurrentFrame() ` and used for render commands encoding.
155
+ ## Frame Rendering Cycle
156
+
157
+ Rendering is implemented in the overridden ` HelloTriangleApp::Render ` method. Base graphics application rendering is executed
158
+ first with ` GraphicsApp::Render() ` , and rendering continues only when it succeeds. It waits for the previous iteration of the
159
+ rendering cycle to complete and for the availability of all frame resources. Then, current frame resources are requested with
160
+ ` GraphicsApp::GetCurrentFrame() ` and used for render commands encoding.
158
161
159
- To begin encoding, command list has to be reset with render state using ` Rhi::RenderCommandList::Reset(...) ` method.
160
- Default view state is set with full frame viewport and scissor rect using ` Rhi::RenderCommandList::SetViewState(...) ` .
161
- Drawing of 3 vertices is submitted as ` Rhi::RenderPrimitive::Triangle ` primitive using ` Rhi::RenderCommandList::Draw(...) ` call.
162
- Vertex buffers are not used for simplification, so the vertex shader will receive only ` vertex_id ` and
163
- will need to provide vertex coordinates based on that. Finally, ` ICommandList::Commit ` method is called
164
- to complete render commands encoding.
162
+ To begin encoding, the command list has to be reset with the render state using the ` Rhi::RenderCommandList::Reset(...) ` method.
163
+ The default view state is set with a full frame viewport and scissor rect using the ` Rhi::RenderCommandList::SetViewState(...) `
164
+ method. Drawing of 3 vertices is submitted as the ` Rhi::RenderPrimitive::Triangle ` primitive using the
165
+ ` Rhi::RenderCommandList::Draw(...) ` call. Vertex buffers are not used for simplification, so the vertex shader will receive only
166
+ ` vertex_id ` and will need to provide vertex coordinates based on that. Finally, the ` ICommandList::Commit ` method is called to
167
+ complete render commands encoding.
165
168
166
- Execution of GPU rendering is started with ` ICommandQueue::Execute(...) ` method called on the same command queue
167
- which was used to create the command list submitted for execution. Frame buffer with the result image is presented by
168
- swap-chain with ` RenderContext::Present() ` method call.
169
+ Execution of GPU rendering is started with the ` ICommandQueue::Execute(...) ` method called on the same command queue which was
170
+ used to create the command list submitted for execution. The frame buffer with the result image is presented by the swap-chain
171
+ with the ` RenderContext::Present() ` method call.
169
172
170
173
``` cpp
171
174
class HelloTriangleApp final : public GraphicsApp
@@ -191,7 +194,8 @@ class HelloTriangleApp final : public GraphicsApp
191
194
};
192
195
```
193
196
194
- Graphics render loop is started from ` main(...) ` entry function using ` GraphicsApp::Run(...) ` method which is also parsing command line arguments.
197
+ Graphics render loop is started from ` main(...) ` entry function using ` GraphicsApp::Run(...) ` method which is
198
+ also parsing command line arguments.
195
199
196
200
``` cpp
197
201
int main (int argc, const char* argv[ ] )
@@ -203,7 +207,7 @@ int main(int argc, const char* argv[])
203
207
## Colored Triangle Shaders
204
208
205
209
This tutorial uses simple HLSL shader [Shaders/Triangle.hlsl](Shaders/Triangle.hlsl) which is taking vertex positions
206
- and colors from inline constant arrays based on vertex_id argument passed to vertex shader.
210
+ and colors from inline constant arrays based on ` vertex_id` argument passed to vertex shader.
207
211
208
212
```cpp
209
213
struct PSInput
@@ -240,7 +244,7 @@ float4 TrianglePS(PSInput input) : SV_TARGET
240
244
241
245
## CMake Build Configuration
242
246
243
- Finally CMake build configuration [ CMakeLists.txt] ( CMakeLists.txt ) of the application
247
+ Finally, CMake build configuration [ CMakeLists.txt] ( CMakeLists.txt ) of the application
244
248
is powered by the included Methane CMake modules:
245
249
- [ MethaneApplications.cmake] ( /CMake/MethaneApplications.cmake ) - defines function ` add_methane_application `
246
250
- [ MethaneShaders.cmake] ( /CMake/MethaneShaders.cmake ) - defines functions ` add_methane_shaders_source ` and ` add_methane_shaders_library `
0 commit comments