### Install dependencies on Ubuntu Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/auto/doc/build.html Install required packages for building GLEW on Ubuntu using apt-get. ```bash sudo apt-get install libXmu-dev libXi-dev libgl-dev dos2unix git wget ``` -------------------------------- ### Build GLEW with MSYS/Mingw Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Build and install GLEW using MSYS/Mingw. The 'install.all' target installs all components. ```bash $ mingw32-make $ mingw32-make install $ mingw32-make install.all ``` -------------------------------- ### Header file include order example (DeviceContextD3D12Impl.hpp) Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/CodingGuidelines.md Shows the required include order for a Diligent Engine header file: system/standard headers, interface headers, base object header, object implementation headers, and other headers. The example uses DeviceContextD3D12Impl.hpp and lists the specific headers for each group. ```cpp // DeviceContextD3D12Impl.hpp // 1 - System includes and standard headers #include #include // 2 - System includes and standard headers #include "DeviceContextD3D12.h" // 3 - Header for the base object implementation #include "DeviceContextNextGenBase.hpp" // 4 - Headers of the object implementations #include "BufferD3D12Impl.hpp" #include "TextureD3D12Impl.hpp" #include "QueryD3D12Impl.hpp" #include "FramebufferD3D12Impl.hpp" #include "RenderPassD3D12Impl.hpp" #include "PipelineStateD3D12Impl.hpp" #include "D3D12DynamicHeap.hpp" #include "BottomLevelASD3D12Impl.hpp" #include "TopLevelASD3D12Impl.hpp" // 5 - Other headers #include "D3D12DynamicHeap.hpp" ``` -------------------------------- ### Source file include order example (DeviceContextD3D12Impl.cpp) Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/CodingGuidelines.md Shows the required include order for a Diligent Engine source file: precompiled header, the source file's header, system/standard headers, interface headers, object implementation headers, and other headers. The example uses DeviceContextD3D12Impl.cpp and notes that RenderDeviceD3D12Impl.hpp always goes first in the implementation group. ```cpp // DeviceContextD3D12Impl.cpp // 1 - Precompiled header #include "pch.h" // 2 - The source file's header #include "DeviceContextD3D12Impl.hpp" // 3 - System includes and standard headers #include // 4 - Interface headers #include "RenderDeviceD3D12.hpp" #include "DeviceContextD3D12.hpp" // 5 - Headers of the object implementations #include "RenderDeviceD3D12Impl.hpp" // Render device always goes first, if any #include "PipelineStateD3D12Impl.hpp" #include "TextureD3D12Impl.hpp" #include "BufferD3D12Impl.hpp" #include "FenceD3D12Impl.hpp" #include "ShaderBindingTableD3D12Impl.hpp" #include "ShaderResourceBindingD3D12Impl.hpp" #include "CommandListD3D12Impl.hpp" // 6 - Other headers required by this source file #include "CommandContext.hpp" #include "D3D12TypeConversions.hpp" #include "d3dx12_win.h" #include "D3D12DynamicHeap.hpp" #include "DXGITypeConversions.hpp" ``` -------------------------------- ### GLEW include examples: glew.h before glut.h and shared-library usage Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/doc/install.html These are the three include examples from the 'Building Your Project with GLEW' section. The first shows the recommended order when using GLEW with GLUT: include glew.h before glut.h. The second and third show the shared-library usage, replacing with . GLEW warns with a preprocessor error if gl.h, glext.h, or glATI.h is included before glew.h. ```cpp #include #include ``` ```cpp #include #include ``` ```cpp #include ``` -------------------------------- ### Build GLEW with MSYS2/Mingw-w64 Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Build and install GLEW using MSYS2/Mingw-w64. The 'install.all' target installs all components. ```bash $ make $ make install $ make install.all ``` -------------------------------- ### glewinfo output example Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Example output from the glewinfo command-line tool, showing GLEW version, OpenGL version, and extension support status. Useful for understanding the format of glewinfo output when reporting bugs. ```text --------------------------- GLEW Extension Info --------------------------- GLEW version 2.0.0 Reporting capabilities of pixelformat 3 Running on a Intel(R) HD Graphics 3000 from Intel OpenGL version 3.1.0 - Build 9.17.10.4229 is supported GL_VERSION_1_1: OK --------------- GL_VERSION_1_2: OK --------------- glCopyTexSubImage3D: OK glDrawRangeElements: OK glTexImage3D: OK glTexSubImage3D: OK ... ``` -------------------------------- ### Setup ImGuiImplSDL with SDL window Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Include the ImGuiImplSDL.hpp header and create the ImGui implementation object after creating the swapchain. Store the result in a unique_ptr for later use. ```cpp #include "Imgui/interface/ImGuiImplSDL.hpp" // Store somewhere std::unique_ptr imgui_impl{}; // Create swapchain... // Create the ImGui implementation object using the device and swapchain description auto CI = ImGuiDiligentCreateInfo{*device, SCDesc}; imgui_impl = ImGui::ImplSDL::Create(CI, sdl_window); ``` -------------------------------- ### Install MSYS2/Mingw-w64 dependencies Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Install required packages for building GLEW with MSYS2/Mingw-w64. ```bash $ pacman -S gcc make mingw-w64-i686-gcc mingw-w64-x86_64-gcc ``` -------------------------------- ### Install build tools on Debian/Ubuntu/Mint Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Install required packages for building GLEW with GNU Make on Debian-based systems. ```bash $ sudo apt-get install build-essential libxmu-dev libxi-dev libgl-dev libosmesa-dev ``` -------------------------------- ### Install dependencies on Fedora Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/auto/doc/build.html Install required packages for building GLEW on Fedora using yum. ```bash sudo yum install libXmu-devel libXi-devel libGL-devel dos2unix git wget ``` -------------------------------- ### Install build tools on RedHat/CentOS/Fedora Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Install required packages for building GLEW with GNU Make on RedHat-based systems. ```bash $ sudo yum install libXmu-devel libXi-devel libGL-devel ``` -------------------------------- ### OpenGLES Setup with SDL2 Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Configures SDL2 attributes for OpenGLES, creates a window and GL context, and creates a swapchain. Required for initializing Diligent Engine with OpenGLES on SDL2. ```cpp const auto color_size = 8; const auto depth_size = 24; SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, color_size); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, color_size); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, color_size); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, color_size); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depth_size); SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); flags = flags | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_FULLSCREEN; // ... // Create the window auto window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, flags); // ... // Create the gl context auto gl_context = SDL_GL_CreateContext(window); // Create the opengl swapchain. Note that the android native window pointer is not required. // ... ``` -------------------------------- ### Handle SDL input events for ImGui Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Call HandleSDLEvent at the start of the main event loop and filter events using ImGui's io.WantCaptureKeyboard and io.WantCaptureMouse flags. The example shows handling keyboard, mouse, and gamepad events. ```cpp SDL_Event event{}; auto& io = ImGui::GetIO(); // Set flags you want io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; while (true) { dynamic_cast(imgui_impl.get())->HandleSDLEvent(&event); // ... } ``` ```cpp switch(event) { case SDL_KeyDown: if (!io.WantCaptureKeyboard) { // Do your normal non-imgui logic here } break; case SDL_KeyUp: // ... break; case SDL_MOUSEMOTION: if (!io.WantCaptureMouse) { // Do your normal non-imgui logic here } break; case SDL_MOUSEBUTTONDOWN: // ... break; case SDL_MOUSEBUTTONUP: // ... break; case SDL_MOUSEWHEEL: // ... break; } ``` -------------------------------- ### Install build tools for CMake on Debian/Ubuntu/Mint Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Install required packages for building GLEW with CMake on Debian-based systems. ```bash $ sudo apt-get install build-essential libXmu-dev libXi-dev libgl-dev cmake ``` -------------------------------- ### tasks.json - StartServer task Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/WASMDebugging.md Creates a VSCode task that starts a live preview server using the livePreview.runServerLoggingTask command. This task is referenced by the launch configuration as a preLaunchTask. ```json { "version": "2.0.0", "tasks": [ { "label": "StartServer", "type": "process", "command": "${input:startServer}" } ], "inputs": [ { "id": "startServer", "type": "command", "command": "livePreview.runServerLoggingTask" } ] } ``` -------------------------------- ### Install build tools for CMake on RedHat/CentOS/Fedora Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Install required packages for building GLEW with CMake on RedHat-based systems. ```bash $ sudo yum install libXmu-devel libXi-devel libGL-devel cmake ``` -------------------------------- ### Old API: Shader creation and pipeline state setup Source: https://github.com/diligentgraphics/diligentcore/blob/master/ReleaseHistory.md Shows the deprecated API for creating a vertex shader and setting up a pipeline state with static samplers. Use this to understand the previous pattern before migrating to the new API. ```cpp RefCntAutoPtr pVS; { CreationAttribs.Desc.ShaderType = SHADER_TYPE_VERTEX; CreationAttribs.EntryPoint = "main"; CreationAttribs.Desc.Name = "Cube VS"; CreationAttribs.FilePath = "cube.vsh"; pDevice->CreateShader(CreationAttribs, &pVS); pVS->GetShaderVariable("Constants")->Set(m_VSConstants); } RefCntAutoPtr pPS; { CreationAttribs.Desc.ShaderType = SHADER_TYPE_PIXEL; CreationAttribs.EntryPoint = "main"; CreationAttribs.Desc.Name = "Cube PS"; CreationAttribs.FilePath = "cube.psh"; ShaderVariableDesc Vars[] = { {"g_Texture", SHADER_VARIABLE_TYPE_MUTABLE} }; CreationAttribs.Desc.VariableDesc = Vars; CreationAttribs.Desc.NumVariables = _countof(Vars); SamplerDesc SamLinearClampDesc( FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR, TEXTURE_ADDRESS_CLAMP, TEXTURE_ADDRESS_CLAMP, TEXTURE_ADDRESS_CLAMP); StaticSamplerDesc StaticSamplers[] = { {"g_Texture", SamLinearClampDesc} }; CreationAttribs.Desc.StaticSamplers = StaticSamplers; CreationAttribs.Desc.NumStaticSamplers = _countof(StaticSamplers); pDevice->CreateShader(CreationAttribs, &pPS); } // ... pDevice->CreatePipelineState(PSODesc, &m_pPSO); ``` -------------------------------- ### Render ImGui frame with NewFrame and Render Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Call NewFrame before beginning ImGui drawing, and Render at the end of the frame. The example shows how to obtain the swapchain description and pass it to NewFrame. ```cpp auto SCDesc = swapchain->GetDesc(); // You may want to check here if the render size given by SDL is different than // the swapchain's. For example if the window was just resized and the values // given by SDL_Vulkan_GetDrawableSize() don't match the swapchain's, you might // want to return early for this frame, otherwise ImGui may assert. imgui_impl->NewFrame(SCDesc.Width, SCDesc.Height, SCDesc.PreTransform); // Begin drawing with ImGui ImGui::Begin("Debug Menu"); ``` ```cpp imgui_impl->Render(immediate_context); // Finish rendering swapchain->Present(); ``` -------------------------------- ### New API: Shader creation and pipeline state setup Source: https://github.com/diligentgraphics/diligentcore/blob/master/ReleaseHistory.md Shows the new API for creating shaders and configuring pipeline state with static samplers. Use this to migrate from the old API, noting the use of ShaderCI and PSODesc.ResourceLayout. ```cpp RefCntAutoPtr pVS; { ShaderCI.Desc.ShaderType = SHADER_TYPE_VERTEX; ShaderCI.EntryPoint = "main"; ShaderCI.Desc.Name = "Cube VS"; ShaderCI.FilePath = "cube.vsh"; pDevice->CreateShader(ShaderCI, &pVS); } RefCntAutoPtr pVS; { ShaderCI.Desc.ShaderType = SHADER_TYPE_VERTEX; ShaderCI.EntryPoint = "main"; ShaderCI.Desc.Name = "Cube VS"; ShaderCI.FilePath = "cube.vsh"; pDevice->CreateShader(ShaderCI, &pVS); } // ... ShaderResourceVariableDesc Vars[] = { {SHADER_TYPE_PIXEL, "g_Texture", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} }; PSODesc.ResourceLayout.Variables = Vars; PSODesc.ResourceLayout.NumVariables = _countof(Vars); // Define static sampler for g_Texture. Static samplers should be used whenever possible SamplerDesc SamLinearClampDesc( FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR, TEXTURE_ADDRESS_CLAMP, TEXTURE_ADDRESS_CLAMP, TEXTURE_ADDRESS_CLAMP); StaticSamplerDesc StaticSamplers[] = { {SHADER_TYPE_PIXEL, "g_Texture", SamLinearClampDesc} }; PSODesc.ResourceLayout.StaticSamplers = StaticSamplers; PSODesc.ResourceLayout.NumStaticSamplers = _countof(StaticSamplers); pDevice->CreatePipelineState(PSODesc, &m_pPSO); m_pPSO->GetStaticShaderVariable(SHADER_TYPE_VERTEX, "Constants")->Set(m_VSConstants); ``` -------------------------------- ### Install Python dependencies for NuGet build Source: https://github.com/diligentgraphics/diligentcore/blob/master/README.md Run this command to install the required Python packages listed in the requirements.txt file before building the NuGet package. ```bash python -m pip install -r ./BuildTools/.NET/requirements.txt ``` -------------------------------- ### Format files in place with clang-format Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/code_formatting.md Run clang-format with the -i flag to format source files in place. The example formats all .cpp files in src and all .h files in include. ```bash clang-format -i src/*.cpp include/*.h ``` -------------------------------- ### Build GLEW with GNU Make Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/README.md Build, install, and clean GLEW using GNU Make. The 'make clean' target removes build artifacts. ```bash $ make $ sudo make install $ make clean ``` -------------------------------- ### Initialize SDL2 and Set Window Flags Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Initializes SDL2 and creates a window flags variable with default dimensions. Use this as the starting point for any SDL2-based Diligent application. ```cpp SDL_Init(SDL_INIT_EVERYTHING); SDL_WindowFlags flags{}; auto window_width = 1280; auto window_height = 720; ``` -------------------------------- ### Create shader with IRenderDevice::CreateShader Source: https://github.com/diligentgraphics/diligentcore/blob/master/README.md Complete example of creating a pixel shader. Sets shader name, file path, entry point, type, source language, and source stream factory before calling CreateShader. ```cpp ShaderCreateInfo ShaderCI; ShaderCI.Desc.Name = "MyPixelShader"; ShaderCI.FilePath = "MyShaderFile.fx"; ShaderCI.EntryPoint = "MyPixelShader"; ShaderCI.Desc.ShaderType = SHADER_TYPE_PIXEL; ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; const auto* SearchDirectories = "shaders;shaders\\inc;"; RefCntAutoPtr pShaderSourceFactory; m_pEngineFactory->CreateDefaultShaderSourceStreamFactory(SearchDirectories, &pShaderSourceFactory); ShaderCI.pShaderSourceStreamFactory = pShaderSourceFactory; RefCntAutoPtr pShader; m_pDevice->CreateShader(ShaderCI, &pShader); ``` -------------------------------- ### Graphics pipeline initialization: old vs new API Source: https://github.com/diligentgraphics/diligentcore/blob/master/ReleaseHistory.md Shows the old and new API for graphics pipeline initialization. The old API uses PipelineStateCreateInfo and CreatePipelineState, while the new API uses GraphicsPipelineStateCreateInfo and CreateGraphicsPipelineState. Note that the old example assigns pPS to pVS (likely a typo in the source). ```cpp PipelineStateCreateInfo PSOCreateInfo; PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; PSODesc.GraphicsPipeline.pVS = pVS; PSODesc.GraphicsPipeline.pPS = pVS; // ... Device->CreatePipelineState(PSOCreateInfo, &pPSO); ``` ```cpp GraphicsPipelineStateCreateInfo PSOCreateInfo; // ... PSOCreateInfo.pVS = pVS; PSOCreateInfo.pPS = pVS; Device->CreateGraphicsPipelineState(PSOCreateInfo, &pPSO); ``` -------------------------------- ### Recreate Vulkan swapchain when app regains focus Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md When the app regains focus, recreate the swapchain using the saved SCDesc. The example shows the pattern; the actual creation call is in the comment. ```cpp if (device->GetDeviceInfo().IsVulkanDevice()) { auto *pFactoryVk = GetEngineFactoryVk(); // ... // Reuse the SCDesc from the original pFactoryVk->CreateSwapChainVk(*device, *immediate_context, SCDesc, native_window, swapchain); } ``` -------------------------------- ### HLSL combined sampler error example Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/TextureSamplers.md Illustrates that every sampler must be combined with a texture. A sampler without a corresponding texture is an error. ```hlsl Texture2D g_Texture; SamplerState g_Texture_sampler; // Combined with g_Texture SamplerState g_Sampler; // Error - not combined with any texture ``` -------------------------------- ### Unsupported macro defining language keyword Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md Defining language keywords with macros is not allowed. The example shows #define TEXTURE2D Texture2D and then using it, which is unsupported. ```hlsl #define TEXTURE2D Texture2D TEXTURE2D MacroTex2D; ``` -------------------------------- ### Using predefined comparison functions for vectors Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md To work around GLSL's lack of vector relational operators, predefined functions like Less and GreaterEqual are provided. The examples show replacing direct comparisons with these functions. ```glsl bool2 b = x < y; ``` ```glsl b = Less(x, y); ``` ```glsl all(p>=q) ``` ```glsl all( GreaterEqual(p,q) ) ``` -------------------------------- ### Create Pipeline Resource Signature with Combined Texture Samplers Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/TextureSamplers.md Configure a pipeline resource signature to use combined texture samplers by setting UseCombinedTextureSamplers to true and defining resources with the default CombinedSamplerSuffix "_sampler". The example creates a signature with static, mutable, and dynamic texture SRVs. ```cpp PipelineResourceSignatureDesc PRSDesc; PRSDesc.UseCombinedTextureSamplers = true; PipelineResourceDesc Resources[] { {SHADER_TYPE_PIXEL, "g_Tex2D_Static", 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_STATIC}, {SHADER_TYPE_PIXEL, "g_Tex2D_Mut", 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE}, {SHADER_TYPE_PIXEL, "g_Tex2D_Dyn", 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC} }; PRSDesc.Resources = Resources; PRSDesc.NumResources = _countof(Resources); pDevice->CreatePipelineResourceSignature(PRSDesc, &pPRS); ``` -------------------------------- ### Vulkan Native Combined Sampler with Separate Resources Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/TextureSamplers.md Vulkan example mixing separate texture and sampler resources with a native combined image sampler using PIPELINE_RESOURCE_FLAG_COMBINED_SAMPLER. The separate pair can be accessed as a combined sampler when UseCombinedTextureSamplers is true, or individually when false. Using the flag for an emulated combined sampler is an error in Vulkan. ```cpp PipelineResourceDesc Resources[] { {SHADER_TYPE_PIXEL, "g_Tex", 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_STATIC}, {SHADER_TYPE_PIXEL, "g_Tex_sampler", 1, SHADER_RESOURCE_TYPE_SAMPLER, SHADER_RESOURCE_VARIABLE_TYPE_STATIC}, {SHADER_TYPE_PIXEL, "g_Tex2", 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_STATIC | PIPELINE_RESOURCE_FLAG_COMBINED_SAMPLER} }; ``` -------------------------------- ### Initialize GLEW with glewInit() Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/auto/doc/basic.html Initialize GLEW after creating a valid OpenGL context. Check the return value of glewInit() against GLEW_OK; on failure, use glewGetErrorString to report the error. On success, print the GLEW version with glewGetString(GLEW_VERSION). ```c #include #include ... glutInit(&argc, argv); glutCreateWindow("GLEW Test"); GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); ... } fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); ``` -------------------------------- ### Initialize Diligent Engine on Win32 Source: https://github.com/diligentgraphics/diligentcore/blob/master/README.md Shows how to create a device and swap chain for D3D11, D3D12, OpenGL, or Vulkan on Windows. The function takes a native window handle and uses the appropriate factory based on the selected device type. Requires including the engine factory headers and enabling the Diligent namespace. ```cpp void InitializeDiligentEngine(HWND NativeWindowHandle) { SwapChainDesc SCDesc; // RefCntAutoPtr m_pDevice; // RefCntAutoPtr m_pImmediateContext; // RefCntAutoPtr m_pSwapChain; switch (m_DeviceType) { case RENDER_DEVICE_TYPE_D3D11: { EngineD3D11CreateInfo EngineCI; // Load the dll and get the factory auto* pFactoryD3D11 = LoadAndGetEngineFactoryD3D11(); pFactoryD3D11->CreateDeviceAndContextsD3D11(EngineCI, &m_pDevice, &m_pImmediateContext); Win32NativeWindow Window{hWnd}; pFactoryD3D11->CreateSwapChainD3D11(m_pDevice, m_pImmediateContext, SCDesc, FullScreenModeDesc{}, Window, &m_pSwapChain); } break; case RENDER_DEVICE_TYPE_D3D12: { EngineD3D12CreateInfo EngineCI; // Load the dll and get the factory auto* pFactoryD3D12 = LoadAndGetEngineFactoryD3D12(); pFactoryD3D12->CreateDeviceAndContextsD3D12(EngineCI, &m_pDevice, &m_pImmediateContext); Win32NativeWindow Window{hWnd}; pFactoryD3D12->CreateSwapChainD3D12(m_pDevice, m_pImmediateContext, SCDesc, FullScreenModeDesc{}, Window, &m_pSwapChain); } break; case RENDER_DEVICE_TYPE_GL: { // Load the dll and get the factory auto* pFactoryOpenGL = LoadAndGetEngineFactoryOpenGL(); EngineGLCreateInfo EngineCI; EngineCI.Window.hWnd = hWnd; pFactoryOpenGL->CreateDeviceAndSwapChainGL(EngineCI, &m_pDevice, &m_pImmediateContext, SCDesc, &m_pSwapChain); } break; case RENDER_DEVICE_TYPE_VULKAN: { EngineVkCreateInfo EngineCI; // Load the dll and get the factory auto* pFactoryVk = LoadAndGetEngineFactoryVk(); pFactoryVk->CreateDeviceAndContextsVk(EngineCI, &m_pDevice, &m_pImmediateContext); Win32NativeWindow Window{hWnd}; pFactoryVk->CreateSwapChainVk(m_pDevice, m_pImmediateContext, SCDesc, Window, &m_pSwapChain); } break; default: std::cerr << "Unknown device type"; } } ``` -------------------------------- ### Include GL/glew.h with GL/glut.h for shared library Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/auto/doc/install.html Use this include order when linking against the GLEW shared library. Replace with and link with glew32.lib, glu32.lib, and opengl32.lib on Windows or -lGLEW -lGLU -lGL on Unix. ```cpp #include #include ``` -------------------------------- ### Enable Diligent Namespace Source: https://github.com/diligentgraphics/diligentcore/blob/master/README.md Adds the Diligent namespace so that types and functions can be used without the Diligent:: prefix. This is required for the code in the initialization example to compile. ```cpp using namespace Diligent; ``` -------------------------------- ### Create and bind separate sampler Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/TextureSamplers.md Shows how to create a sampler and bind it to static and mutable shader variables when using separate samplers. ```cpp RefCntAutoPtr pSampler; pDevice->CreateSampler(SamDesc, &pSampler); // ... pPSO->GetStaticVariableByName(SHADER_TYPE_PIXEL, "g_StaticSampler")->Set(pSampler); pSRB->GetVariableByName(SHADER_TYPE_PIXEL, "g_MutableSampler")->Set(pSampler); ``` -------------------------------- ### Check WGL extension with WGLEW_ARB_pbuffer Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/auto/doc/basic.html Check for a platform-specific WGL extension by including and testing the WGLEW_{extension_name} variable. This example checks WGLEW_ARB_pbuffer. ```c #include if (WGLEW_ARB_pbuffer) { /* OK, we can use pbuffers. */ } else { /* Sorry, pbuffers will not work on this platform. */ } ``` -------------------------------- ### Create SDL2 Vulkan window with resizable and fullscreen flags Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Create an SDL2 window with Vulkan support, resizable, and fullscreen. Use SDL_WINDOW_VULKAN, SDL_WINDOW_RESIZABLE, and SDL_WINDOW_FULLSCREEN flags. ```cpp auto window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_FULLSCREEN); ``` -------------------------------- ### Check OpenGL version support with GLEW_VERSION_1_3 Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/auto/doc/basic.html Check for core OpenGL version support using the GLEW_VERSION_{version} variable. This example checks for OpenGL 1.3. ```c if (GLEW_VERSION_1_3) { /* Yay! OpenGL 1.3 is supported! */ } ``` -------------------------------- ### Compute pipeline initialization: old vs new API Source: https://github.com/diligentgraphics/diligentcore/blob/master/ReleaseHistory.md Shows the old and new API for compute pipeline initialization. The old API uses PipelineStateCreateInfo and CreatePipelineState, while the new API uses ComputePipelineStateCreateInfo and CreateComputePipelineState. ```cpp PipelineStateCreateInfo PSOCreateInfo; PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; PSODesc.ComputePipeline.pCS = pCS; // ... Device->CreatePipelineState(PSOCreateInfo, &pPSO); ``` ```cpp ComputePipelineStateCreateInfo PSOCreateInfo; PSOCreateInfo.pCS = pCS; Device->CreateComputePipelineState(PSOCreateInfo, &pPSO); ``` -------------------------------- ### Allowed macro usage inside function body Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md Macros can be used within function bodies. The example shows conditional compilation inside a function, which is allowed. ```hlsl VSOut VSTes(...) { #ifdef SOME_MACRO // OK #else // OK #endif } ``` -------------------------------- ### launch.json - Chrome launch target Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/WASMDebugging.md Adds a Chrome launch configuration that opens the Tutorial01_HelloTriangle_Emscripten HTML file served at localhost:3000. It uses the StartServer task as a preLaunchTask to ensure the server is running before launching. ```json { "name": "Tutorial01_HelloTriangle_Emscripten", "type": "chrome", "request": "launch", "url": "http://localhost:3000/build/Emscripten/DiligentSamples/Tutorials/Tutorial01_HelloTriangle/Tutorial01_HelloTriangle.html", "preLaunchTask": "StartServer", } ``` -------------------------------- ### Web OpenGL Device and Swap Chain Creation (C++) Source: https://github.com/diligentgraphics/diligentcore/blob/master/README.md Initializes an OpenGL device and swap chain on the Web platform. Requires the canvas element ID to be passed as the native window handle. If using SDL or GLFW with an existing context, pass nullptr as the window handle. ```cpp //You need to pass the id of the canvas to NativeWindow auto* pFactoryOpenGL = GetEngineFactoryOpenGL(); EngineGLCreateInfo EngineCI = {}; EngineCI.Window = NativeWindow{"#canvas"}; pFactoryOpenGL->CreateDeviceAndSwapChainGL(EngineCI, &m_pDevice, &m_pContext, SCDesc, &m_pSwapChain); ``` -------------------------------- ### Initialize ShaderCreateInfo structure Source: https://github.com/diligentgraphics/diligentcore/blob/master/README.md Declares a ShaderCreateInfo object, the first step in creating a shader. ```cpp ShaderCreateInfo ShaderCI; ``` -------------------------------- ### Vector relational operations error in GLSL Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md GLSL does not support relational and boolean operations on vector types. The example shows that comparing float2 vectors with < and using all() on the result are errors. ```glsl float2 p = float2(1.0, 2.0), q = float2(3.0, 4.0); bool2 b = p < q; // Error all(p < q); // Error ``` -------------------------------- ### Unsupported macro usage in inter-stage struct definition Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md Macros cannot be used in structures that pass data between shader stages. The example shows conditional compilation inside a struct definition, which is not supported. ```hlsl struct VSInput { in float3 f3PosWS : ATTRIB0; #ifdef SOME_MACRO in float2 f2UV : ATTRIB1; #else in float4 f4UV : ATTRIB1; #endif uint VertexID : SV_VertexID; }; ``` -------------------------------- ### Get Native Window Handle for Windows Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Retrieves the native window handle on Windows using SDL_SysWMinfo and assigns it to the Diligent NativeWindow struct. Use this when the platform requires the native handle. ```cpp SDL_SysWMinfo info; SDL_VERSION(&info.version); SDL_GetWindowWMInfo(window, &info); NativeWindow native_window; native_window.hWnd = info.info.win.window; ``` -------------------------------- ### Configure GLEW test executable with Conan Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/build/conan/test_package/CMakeLists.txt Sets up a CMake project that uses Conan's generated build information to compile and link a test executable for GLEW. It includes the conanbuildinfo.cmake file, calls conan_basic_setup(), and defines the testGlew target with compile definitions, libraries, and linker flags from Conan variables. ```cmake project(GlewTest) cmake_minimum_required(VERSION 3.0.0) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(testGlew main.c) target_compile_definitions(testGlew PUBLIC "${CONAN_DEFINES}") target_link_libraries(testGlew PUBLIC "${CONAN_LIBS}") set_target_properties(testGlew PROPERTIES LINK_FLAGS "${CONAN_EXE_LINKER_FLAGS}") ``` -------------------------------- ### Check extension support with GLEW_ARB_vertex_program Source: https://github.com/diligentgraphics/diligentcore/blob/master/ThirdParty/glew/auto/doc/basic.html Check for a specific extension by testing the global variable GLEW_{extension_name}. The example checks GLEW_ARB_vertex_program before using glGenProgramsARB. This mechanism applies from GLEW 1.1.0 onward. ```c if (GLEW_ARB_vertex_program) { /* It is safe to use the ARB_vertex_program extension here. */ glGenProgramsARB(...); } ``` -------------------------------- ### Run NuGet package build script Source: https://github.com/diligentgraphics/diligentcore/blob/master/README.md Executes the dotnet-build-package.py script with a Debug configuration and the current directory as the root. Use the -c and -d flags to specify configuration and root directory. ```bash python ./BuildTools/.NET/dotnet-build-package.py -c Debug -d ./ ``` -------------------------------- ### GLES strict type conversion error example Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md GLES is strict about type conversions; float4(0, 0, 0, 0) causes a compiler error and must be written with decimal points. ```glsl float4(0, 0, 0, 0) ``` ```glsl float4(0.0, 0.0, 0.0, 0.0) ``` -------------------------------- ### Unsupported macro usage in shader entry point declaration Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md The converter does not expand macros, so using preprocessor directives in entry point declarations is not supported. The example shows conditional compilation inside the parameter list. ```hlsl VSOut TestVS ( #ifdef SOME_MACRO in VSInput0 VSInput #else in VSInput1 VSInput #endif ) ``` -------------------------------- ### GLSL separate sampler syntax (Vulkan only) Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/TextureSamplers.md Shows GLSL syntax for separate samplers, which is supported only in Vulkan. ```glsl uniform sampler uSampler; uniform texture2D uTexture; // ... vec4 Color = texture(sampler2D(uTexture, uSampler), UV); ``` -------------------------------- ### Create Vulkan swapchain with Diligent Engine Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Create a Vulkan swapchain using the Diligent Engine factory. Keep the swapchain description (SCDesc) for later reuse. ```cpp auto *pFactoryVk = GetEngineFactoryVk(); // ... // Keep the SCDesc to be reused pFactoryVk->CreateSwapChainVk(*device, *immediate_context, SCDesc, native_window, swapchain); ``` -------------------------------- ### IEngineFactoryD3D12::AttachToD3D12Device Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/GraphicsEngineD3D12/readme.md Initializes the Diligent Engine by attaching to an existing D3D12 device. ```APIDOC ## [POST] /IEngineFactoryD3D12/AttachToD3D12Device ### Description Initializes the Diligent Engine by attaching to an existing D3D12 device. The method takes a pointer to the native D3D12 device, initialization parameters, and returns the Diligent Engine device and contexts. ### Method POST ### Endpoint /IEngineFactoryD3D12/AttachToD3D12Device ### Parameters #### Request Body - **pd3d12NativeDevice** (void*) - Required - Pointer to the native D3D12 device. - **CommandQueueCount** (Uint32) - Required - Number of command queues. - **ppCommandQueues** (ICommandQueueD3D12**) - Required - Array of command queue objects implementing ICommandQueueD3D12. - **EngineCI** (EngineD3D12CreateInfo) - Required - Initialization parameters. - **ppDevice** (IRenderDevice**) - Required - Pointer to the memory location where the IRenderDevice interface pointer will be written. - **ppContexts** (IDeviceContext**) - Required - Pointer to the memory location where the IDeviceContext interface pointers will be written. Immediate contexts go first, then deferred contexts if any. ### Request Example { "pd3d12NativeDevice": "void*", "CommandQueueCount": 1, "ppCommandQueues": ["ICommandQueueD3D12*"], "EngineCI": { "NumDeferredContexts": 0 }, "ppDevice": "IRenderDevice**", "ppContexts": "IDeviceContext**" } ### Response #### Success Response (200) - **device** (IRenderDevice*) - The Diligent Engine device. - **contexts** (IDeviceContext*) - The device contexts. #### Response Example { "device": "IRenderDevice*", "contexts": ["IDeviceContext*"] } ``` -------------------------------- ### Implicit type conversion fixes for GLSL Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md GLSL does not support most implicit type conversions. These examples show required modifications: use float4(0.0, ...) instead of 0, add .0 to floats, and use 0u for uint. ```hlsl float4 vec = 0; ``` ```glsl float4 vec = float4(0.0, 0.0, 0.0, 0.0); ``` ```hlsl float x = 0; ``` ```glsl float x = 0.0; ``` ```hlsl uint x = 0; ``` ```glsl uint x = 0u; ``` -------------------------------- ### Struct with matrix passed to function (GLSL issue) Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md GLSL compilers do not handle structs passed as function arguments correctly. The example shows a struct containing a matrix and a function that multiplies by it, which will not work. Avoid passing structs to functions. ```hlsl struct MyStruct { matrix Matr; } void Func(in MyStruct S) { ... mul(f4PosWS, S.Matr); // This will not work!!! } ``` -------------------------------- ### Create uniform buffer with BufferDesc Source: https://github.com/diligentgraphics/diligentcore/blob/master/README.md Populate BufferDesc and call IRenderDevice::CreateBuffer to create a dynamic uniform buffer. Requires a device pointer and a ShaderConstants structure size. ```cpp BufferDesc BuffDesc; BuffDesc.Name = "Uniform buffer"; BuffDesc.BindFlags = BIND_UNIFORM_BUFFER; BuffDesc.Usage = USAGE_DYNAMIC; BuffDesc.uiSizeInBytes = sizeof(ShaderConstants); BuffDesc.CPUAccessFlags = CPU_ACCESS_WRITE; m_pDevice->CreateBuffer(BuffDesc, nullptr, &m_pConstantBuffer); ``` -------------------------------- ### Resume Swapchain on Focus Gain Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Calls Resume on the swapchain when focus is resumed, passing nullptr as the native window pointer. Only for GL devices. ```cpp if (device->GetDeviceInfo().IsGLDevice()) { static_cast(device.RawPtr())->Resume(nullptr); } ``` -------------------------------- ### New API: CreatePipelineState with PipelineStateCreateInfo Source: https://github.com/diligentgraphics/diligentcore/blob/master/ReleaseHistory.md Shows the updated API for creating a pipeline state using PipelineStateCreateInfo. Use this when targeting API version 240056 or later. ```cpp PipelineStateCreateInfo PSOCreateInfo; PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; // ... pRenderDevice->CreatePipelineState(PSOCreateInfo, &pPSO); ``` -------------------------------- ### Create OpenGL Context Source: https://github.com/diligentgraphics/diligentcore/blob/master/doc/SDL2.md Creates an OpenGL context for the window. Check for success before using the context. ```cpp auto gl_context = SDL_GL_CreateContext(window); // Check if succeeded, etc. ``` -------------------------------- ### CMake configuration for Diligent-AndroidPlatform Source: https://github.com/diligentgraphics/diligentcore/blob/master/Platforms/Android/CMakeLists.txt CMake configuration for the Diligent-AndroidPlatform library. Defines the interface and source file sets, creates the library target, sets include directories, links against Android system libraries (log, android) and Diligent dependencies, organizes source groups, and optionally installs the library and Linux interface headers when DILIGENT_INSTALL_CORE is enabled. ```cmake cmake_minimum_required (VERSION 3.10) project(Diligent-AndroidPlatform CXX) set(INTERFACE interface/AndroidDebug.hpp interface/AndroidFileSystem.hpp interface/AndroidPlatformDefinitions.h interface/AndroidPlatformMisc.hpp interface/AndroidNativeWindow.h interface/JNIMiniHelper.hpp interface/JNIWrappers.hpp ../Linux/interface/LinuxPlatformMisc.hpp ) set(SOURCE src/AndroidDebug.cpp src/AndroidFileSystem.cpp src/AndroidPlatformMisc.cpp ../Linux/src/LinuxFileSystem.cpp ) add_library(Diligent-AndroidPlatform ${SOURCE} ${INTERFACE} ${PLATFORM_INTERFACE_HEADERS}) set_common_target_properties(Diligent-AndroidPlatform) target_include_directories(Diligent-AndroidPlatform PUBLIC interface ) target_link_libraries(Diligent-AndroidPlatform PRIVATE log android Diligent-BuildSettings PUBLIC Diligent-PlatformInterface Diligent-BasicPlatform ) source_group("src" FILES ${SOURCE}) source_group("interface\\android" FILES ${INTERFACE}) source_group("interface\\common" FILES ${PLATFORM_INTERFACE_HEADERS}) set_target_properties(Diligent-AndroidPlatform PROPERTIES FOLDER DiligentCore/Platforms ) if(DILIGENT_INSTALL_CORE) install_core_lib(Diligent-AndroidPlatform) get_target_relative_dir(Diligent-AndroidPlatform RELATIVE_PATH) install(DIRECTORY ../Linux/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${RELATIVE_PATH}/../Linux" ) endif() ``` -------------------------------- ### IRenderDeviceVk::CreateBLASFromVulkanResource Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/GraphicsEngineVulkan/readme.md Creates a Diligent Engine bottom-level acceleration structure from a native Vulkan handle. ```APIDOC ## IRenderDeviceVk::CreateBLASFromVulkanResource ### Description Creates a Diligent Engine bottom-level acceleration structure from the native Vulkan handle. ### Method CreateBLASFromVulkanResource ### Parameters - **VulkanBLASHandle** (VkAccelerationStructureKHR) - Required - The native Vulkan bottom-level acceleration structure handle. ### Returns A Diligent Engine bottom-level acceleration structure object. ``` -------------------------------- ### HLSL shader declarations with ATTRIBn semantics and input/output ordering Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/HLSL2GLSLConverterLib/readme.md Example of supported HLSL shader declarations for vertex and pixel shaders. Vertex shader inputs should use ATTRIBn semantics for GLSL location mapping. Inputs of subsequent stages must match output order of previous stage; unused arguments must still be declared. Semantics are case-insensitive. ```hlsl struct VSInput { // It is recommended (though not required) to assign // ATTRIBn semantics to inputs from input assembler in float3 f3PosWS : ATTRIB0; in float2 f2UV : ATTRIB1; uint VertexID : SV_VertexID; }; struct VSOutput { float2 UV : TEX_COORDINATES; float3 Normal : NORMAL; float4 f4PosPS : SV_Position; }; VSOutput VertexShader ( in VSInput VSIn, in float3 f3UV : ATTRIB2, uint InstID : SV_InstanceID, out float3 f3Tangent : TANGENT ) { VSOutput VSOut; // Body elided f3Tangent = ... return VSOut; } float4 PixelShader ( // Pixel shader inputs must be declared in exact same order // as outputs of the vertex shader VSOutput PSIn, in float3 f3Tangent : TaNgEnT // Semantics are case-insensitive out float3 Color2 : SV_Target2 ) : SV_Target { // Body elided } ``` -------------------------------- ### IRenderDeviceVk::CreateTLASFromVulkanResource Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/GraphicsEngineVulkan/readme.md Creates a Diligent Engine top-level acceleration structure from a native Vulkan handle. ```APIDOC ## IRenderDeviceVk::CreateTLASFromVulkanResource ### Description Creates a Diligent Engine top-level acceleration structure from the native Vulkan handle. ### Method CreateTLASFromVulkanResource ### Parameters - **VulkanTLASHandle** (VkAccelerationStructureKHR) - Required - The native Vulkan top-level acceleration structure handle. ### Returns A Diligent Engine top-level acceleration structure object. ``` -------------------------------- ### IRenderDeviceVk::CreateFenceFromVulkanResource Source: https://github.com/diligentgraphics/diligentcore/blob/master/Graphics/GraphicsEngineVulkan/readme.md Creates a Diligent Engine fence from a native Vulkan fence handle. ```APIDOC ## IRenderDeviceVk::CreateFenceFromVulkanResource ### Description Creates a Diligent Engine fence from the native Vulkan handle. ### Method CreateFenceFromVulkanResource ### Parameters - **VulkanFenceHandle** (VkFence) - Required - The native Vulkan fence handle. ### Returns A Diligent Engine fence object. ```