### Install Libjpeg Programs and Man Pages (Makefile) Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/install.txt Use 'make install' to install executable files and man pages to standard locations. Requires root privileges. Use 'make -n install' to preview changes. ```bash make install ``` ```bash make -n install ``` -------------------------------- ### Example Quantization Table File Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/wizard.txt This is an example text file format for specifying custom quantization tables. Comments start with '#'. Tables are comma-separated and in normal array order, not zigzag. ```text # Quantization tables given in JPEG spec, section K.1 # This is table 0 (the luminance table): 16 11 10 16 24 40 51 61 12 12 14 19 26 58 60 55 14 13 16 24 40 57 69 56 14 17 22 29 51 87 80 62 18 22 37 56 68 109 103 77 24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 100 103 99 # This is table 1 (the chrominance table): 17 18 24 47 99 99 99 99 18 21 26 66 99 99 99 99 24 26 56 99 99 99 99 99 47 66 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 ``` -------------------------------- ### Example Command Line Usage Source: https://github.com/diligentgraphics/diligenttools/blob/master/RenderStatePackager/README.md This example demonstrates how to use the Render State Packager with multiple input files, a configuration file, and specifies Vulkan and DirectX 12 as target devices. ```sh Diligent-RenderStatePackager.exe -o Archive.bin --vulkan --dx12 -c Config.json -s . -i SamplePSO_0.drsn -i SamplePSO_1.drsn ``` -------------------------------- ### Install Libjpeg Library Files Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/install.txt Install the IJG library by placing header files and the library archive into their respective system directories. Use 'make install-lib' if a configure-generated Makefile is present. ```bash make install-lib ``` -------------------------------- ### Install Imgui Tools Library Source: https://github.com/diligentgraphics/diligenttools/blob/master/Imgui/CMakeLists.txt Conditionally installs the Diligent-Imgui library if the DILIGENT_INSTALL_TOOLS option is enabled. ```cmake if(DILIGENT_INSTALL_TOOLS) install_tools_lib(Diligent-Imgui) endif() ``` -------------------------------- ### CopyPixels and PremultiplyAlpha Example Source: https://context7.com/diligentgraphics/diligenttools/llms.txt Demonstrates converting RGB8 to RGBA8 with vertical flipping using CopyPixels, and then premultiplying alpha for sRGB data in-place using PremultiplyAlpha. Ensure correct component counts and sizes are specified for the source and destination. ```cpp #include "TextureLoader/interface/TextureUtilities.h" // --- CopyPixels: convert RGB8 → RGBA8, flipping vertically --- std::vector src(512 * 512 * 3); // RGB source std::vector dst(512 * 512 * 4); // RGBA destination Diligent::CopyPixelsAttribs cpAttribs; cpAttribs.Width = 512; cpAttribs.Height = 512; cpAttribs.SrcComponentSize = 1; // Uint8 cpAttribs.pSrcPixels = src.data(); cpAttribs.SrcStride = 512 * 3; cpAttribs.SrcCompCount = 3; cpAttribs.pDstPixels = dst.data(); cpAttribs.DstComponentSize = 1; cpAttribs.DstStride = 512 * 4; cpAttribs.DstCompCount = 4; // alpha will be set to 255 cpAttribs.FlipVertically = true; Diligent::CopyPixels(cpAttribs); // --- PremultiplyAlpha: premultiply sRGB RGBA8 in-place --- Diligent::PremultiplyAlphaAttribs pmAttribs; pmAttribs.Width = 512; pmAttribs.Height = 512; pmAttribs.pPixels = dst.data(); pmAttribs.Stride = 512 * 4; pmAttribs.ComponentCount = 4; pmAttribs.ComponentType = Diligent::VT_UINT8; pmAttribs.IsSRGB = true; Diligent::PremultiplyAlpha(pmAttribs); ``` -------------------------------- ### DRSN Example: Full Render State Definition Source: https://github.com/diligentgraphics/diligenttools/blob/master/RenderStatePackager/README.md This example demonstrates a complete DRSN file structure, including resource signatures, shader definitions, and pipeline state objects (PSOs). Use this for defining all components of a render state in a single file. ```json { "ResourceSignatures": [ { "Name": "Signature0", "Resources": [ { "Name": "Constants", "ShaderStages": [ "VERTEX", "PIXEL" ], "VarType": "DYNAMIC", "ResourceType": "CONSTANT_BUFFER", "Flags": ["NO_DYNAMIC_BUFFERS"] } ], "ImmutableSamplers": [ { "ShaderStages": ["PIXEL"], "SamplerOrTextureName": "LinearSampler", "Desc": { "BorderColor" : [1.0, 1.0, 1.0, 1.0] } } ] } ], "Shaders": [ { "Desc": { "Name": "My vertex shader", "ShaderType": "VERTEX" }, "SourceLanguage": "HLSL", "FilePath": "VertexShader.vsh", "EntryPoint": "VSmain", "UseCombinedTextureSamplers": true, "Macros": [ {"Name": "MY_MACRO_0", "Definition": "0"} ] }, { "Desc": { "Name": "My pixel shader", "ShaderType": "PIXEL" }, "SourceLanguage": "HLSL", "FilePath": "MyPixelShader.psh", "EntryPoint": "PSmain", "UseCombinedTextureSamplers": true } ], "Pipelines": [ { "PSODesc": { "Name": "My PSO 0", "PipelineType": "GRAPHICS" }, "GraphicsPipeline": { "DepthStencilDesc": { "DepthEnable": false }, "InputLayout": { "LayoutElements": [ { "NumComponents": 3 }, { "InputIndex": 1, "NumComponents": 4 } ] }, "NumRenderTargets": 1, "RTVFormats": { "0": "RGBA8_UNORM_SRGB" }, "RasterizerDesc": { "CullMode": "FRONT" }, "BlendDesc": { "RenderTargets": { "0": { "BlendEnable": true } } } }, "ppResourceSignatures": [ "Signature0" ], "pVS": "My vertex shader", "pPS": "My pixel shader" } ] } ``` -------------------------------- ### Render State Packager Command Line Usage Source: https://github.com/diligentgraphics/diligenttools/blob/master/RenderStatePackager/README.md Command line example for using the Diligent-RenderStatePackager executable. It shows how to specify shader directories, render state search paths, input files, and enable Vulkan support. ```sh Diligent-RenderStatePackager.exe -s ./Shaders -r ./RenderStates -i RenderStatesLib.drsn --vulkan ``` -------------------------------- ### Configure Render State Packager Source: https://github.com/diligentgraphics/diligenttools/blob/master/RenderStatePackager/README.md Configure the render state packager by mirroring the fields of the SerializationDeviceCreateInfo struct. This example shows basic Vulkan and Metal configurations. ```json { "Vulkan": { "Version": { "Major": 1, "Minor": 2 }, "SupportsSpirv14": true, "DxCompilerPath": "PATH_TO_COMPILER" }, "Metal": { "MslPreprocessorCmd": "PREPROCESSOR_CMD" } } ``` -------------------------------- ### Start JPEG Compression Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt Initiates a compression cycle, initializing state and writing the JPEG datastream header. The TRUE parameter ensures a complete interchange datastream. ```c jpeg_start_compress(&cinfo, TRUE); ``` -------------------------------- ### DRSN Import Feature Example Source: https://github.com/diligentgraphics/diligenttools/blob/master/RenderStatePackager/README.md This example illustrates how to use the 'Imports' feature in DRSN files to include definitions from other DRSN files, enabling modularity and sharing of common render states. ```json // RenderStatesLib.json { "Imports": [ "RenderState0.json", "RenderState1.json", .... "RenderStateN.json" ] ... } ``` -------------------------------- ### Initialize and Render with ImGuiImplDiligent Source: https://context7.com/diligentgraphics/diligenttools/llms.txt Sets up the Diligent ImGui renderer and integrates it into the application's render loop. Platform-specific subclasses handle input events. Ensure ImGui context is created before the renderer. ```cpp #include "Imgui/interface/ImGuiImplDiligent.hpp" #include "Imgui/interface/ImGuiImplWin32.hpp" // for Win32 #include // Create ImGui context (once at app startup): ImGui::CreateContext(); // Create the Diligent ImGui renderer: Diligent::ImGuiDiligentCreateInfo imguiCI; imguiCI.pDevice = pDevice; imguiCI.BackBufferFmt = pSwapChain->GetDesc().ColorBufferFormat; imguiCI.DepthBufferFmt = pSwapChain->GetDesc().DepthBufferFormat; // Platform-specific class provides input event handling: auto pImgui = std::make_unique(hWnd, imguiCI); // Per-frame render loop: { const Diligent::SwapChainDesc& scDesc = pSwapChain->GetDesc(); pImgui->NewFrame(scDesc.Width, scDesc.Height, scDesc.PreTransform); // Build ImGui UI: ImGui::Begin("Debug"); ImGui::Text("Frame time: %.2f ms", elapsedMs); static float roughness = 0.5f; ImGui::SliderFloat("Roughness", &roughness, 0.0f, 1.0f); ImGui::End(); // Render all ImGui draw commands: ImGui::Render(); pImgui->Render(pContext); pImgui->EndFrame(); } // On device reset: pImgui->InvalidateDeviceObjects(); // ... recreate swap chain ... pImgui->CreateDeviceObjects(); ``` -------------------------------- ### DRSN Example: Inline Shader Definitions in PSO Source: https://github.com/diligentgraphics/diligenttools/blob/master/RenderStatePackager/README.md This example shows how to define shaders inline within a pipeline state object (PSO) description when a shader is used by only one pipeline. This is useful for simplifying definitions for single-use shaders. ```json { "Pipelines": [ { "PSODesc": { "Name": "My PSO 1", }, "GraphicsPipeline": { "RTVFormats": { "0": "RGBA8_UNORM_SRGB" }, }, "pVS": { "Desc": { "Name": "My vertex shader" }, "FilePath": "VertexShader.vsh", "EntryPoint": "VSmain" }, "pPS": { "Desc": { "Name": "My pixel shader" }, "FilePath": "PixelShader.psh", "EntryPoint": "PSmain" } } ] } ``` -------------------------------- ### Creating Abbreviated Image Datastreams Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt Instructions on how to configure the compressor and call `jpeg_start_compress` to create abbreviated image datastreams. ```APIDOC ## Creating Abbreviated Images To create an abbreviated image datastream: 1. **Suppress Tables**: Optionally call `jpeg_suppress_tables(&cinfo, TRUE)` after constructing all tables if you want a "pure" abbreviated image file with no tables. 2. **Set `sent_table` flags**: For partial table suppression, set the `sent_table` field of individual table structures to TRUE before calling `jpeg_start_compress`. 3. **Call `jpeg_start_compress`**: Call `jpeg_start_compress(&cinfo, FALSE)`. Passing FALSE as the second parameter is crucial; passing TRUE would reset all `sent_table` flags to FALSE, preventing abbreviated image creation. ``` -------------------------------- ### Write a COM Marker Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt Use jpeg_write_marker to insert a COM marker after starting compression but before writing scanlines. Ensure comment_text points to valid data. ```c jpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text)); ``` -------------------------------- ### Typical JPEG Compression Workflow Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt This outlines the general steps for performing JPEG compression using the IJG library. It involves initializing a compression object, setting parameters, writing scanlines, and finishing the compression process. ```c Allocate and initialize a JPEG compression object Specify the destination for the compressed data (eg, a file) Set parameters for compression, including image size & colorspace jpeg_start_compress(...); while (scan lines remain to be written) jpeg_write_scanlines(...); jpeg_finish_compress(...); Release the JPEG compression object ``` -------------------------------- ### Start JPEG Compression for Abbreviated Image Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt When creating an abbreviated image, call jpeg_start_compress with the second parameter set to FALSE. This prevents the function from resetting the sent_table flags. ```c jpeg_start_compress(&cinfo, FALSE); ``` -------------------------------- ### Function Definition Style Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/coderules.txt Function definitions must begin with LOCAL(type), GLOBAL(type), or METHODDEF(type) macros. The function name must start in column 1 to be compatible with the ansi2knr.c tool. ```c LOCAL(int *) function_name (int a, char *b) { code... } ``` -------------------------------- ### Source Manager Methods Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt Details the five essential methods for a custom data source manager: initialization, buffer filling, and termination. These are invoked by libjpeg during decompression. ```c init_source (j_decompress_ptr cinfo) Initialize source. This is called by jpeg_read_header() before any data is actually read. Unlike init_destination(), it may leave bytes_in_buffer set to 0 (in which case a fill_input_buffer() call will occur immediately). fill_input_buffer (j_decompress_ptr cinfo) This is called whenever bytes_in_buffer has reached zero and more ``` -------------------------------- ### Create RenderStateNotationLoader - C++ Source: https://context7.com/diligentgraphics/diligenttools/llms.txt Instantiate IRenderStateNotationLoader to create GPU objects like IPipelineState and IShader from parsed notation. Optional modify-callbacks allow runtime patching of descriptors before object creation. ```cpp #include "RenderStateNotation/interface/RenderStateNotationLoader.h" Diligent::RenderStateNotationLoaderCreateInfo loaderCI; loaderCI.pDevice = pDevice; loaderCI.pParser = pParser; // previously created parser loaderCI.pStreamFactory = pStreamFactory; // shader source stream factory loaderCI.pStateCache = pStateCache; // optional render-state cache Diligent::IRenderStateNotationLoader* pLoader = nullptr; Diligent::CreateRenderStateNotationLoader(loaderCI, &pLoader); // Load a graphics pipeline state: Diligent::LoadPipelineStateInfo psoLI; psoLI.Name = "GBufferPass"; psoLI.PipelineType = Diligent::PIPELINE_TYPE_GRAPHICS; psoLI.AddToCache = true; // Optional: patch the render target format at load time: psoLI.ModifyPipeline = [](Diligent::PipelineStateCreateInfo& CI, void*) { auto& gfxCI = static_cast(CI); gfxCI.GraphicsPipeline.RTVFormats[0] = Diligent::TEX_FORMAT_RGBA16_FLOAT; gfxCI.GraphicsPipeline.NumRenderTargets = 1; }; Diligent::IPipelineState* pPSO = nullptr; pLoader->LoadPipelineState(psoLI, &pPSO); // Load a standalone shader: Diligent::LoadShaderInfo shaderLI; shaderLI.Name = "FullscreenVS"; Diligent::IShader* pVS = nullptr; pLoader->LoadShader(shaderLI, &pVS); // Hot-reload all GPU objects (shaders and PSOs): bool ok = pLoader->Reload(); pLoader->Release(); pPSO->Release(); pVS->Release(); ``` -------------------------------- ### Define Progressive JPEG Scan with Successive Approximation Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/wizard.txt This script creates a progressive JPEG file using successive approximation. It defines multiple scans to progressively transmit coefficient bits, starting with the lowest bits and progressing to the highest. ```text # Initial DC scan for Y,Cb,Cr (lowest bit not sent) 0,1,2: 0-0, 0, 1 ; # First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits: 0: 1-5, 0, 2 ; # Send all Cr,Cb AC coefficients, minus lowest bit: # (chroma data is usually too small to be worth subdividing further; # but note we send Cr first since eye is least sensitive to Cb) 2: 1-63, 0, 1 ; 1: 1-63, 0, 1 ; # Send remaining Y AC coefficients, minus 2 lowest bits: 0: 6-63, 0, 2 ; # Send next-to-lowest bit of all Y AC coefficients: 0: 1-63, 2, 1 ; # At this point we've sent all but the lowest bit of all coefficients. # Send lowest bit of DC coefficients 0,1,2: 0-0, 1, 0 ; # Send lowest bit of AC coefficients 2: 1-63, 1, 0 ; 1: 1-63, 1, 0 ; # Y AC lowest bit scan is last; it's usually the largest scan 0: 1-63, 1, 0 ; ``` -------------------------------- ### Test Binary I/O with djpeg (Unix Style) Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/install.txt Verify binary I/O through stdin/stdout works correctly by comparing output from piped and file-based operations. This is crucial for non-Unix systems. ```bash djpeg out.ppm ``` ```bash djpeg -outfile out.ppm testorig.jpg ``` -------------------------------- ### Start Decompression Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt Call jpeg_start_decompress() to initialize decompression after setting parameters. This function allocates working memory and prepares for data output. For multi-pass modes, this call may take longer. After this call, final output dimensions and colormap information are available. ```c jpeg_start_decompress(&cinfo); ``` -------------------------------- ### Platform Specific Configuration - Linux Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Finds and links X11 and optionally OpenGL libraries. Sets public include directories and links XCB library if Vulkan is supported. ```cmake find_package(X11 REQUIRED) target_link_libraries(Diligent-NativeAppBase PRIVATE X11::X11 ) if(GL_SUPPORTED) find_package(OpenGL REQUIRED) target_link_libraries(Diligent-NativeAppBase PRIVATE OpenGL::GL OpenGL::GLX ) endif() target_include_directories(Diligent-NativeAppBase PUBLIC include/Linux ) if(VULKAN_SUPPORTED) find_library(XCB_LIBRARY xcb) target_link_libraries(Diligent-NativeAppBase PRIVATE ${XCB_LIBRARY} ) endif() ``` -------------------------------- ### Universal Windows Platform (UWP) Application Target Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Configures build for UWP, including common source files and linking dxgi.lib. Note that Windows Runtime types cannot be included into static libraries. ```cmake set(SOURCE src/UWP/dummy.cpp ) set(INCLUDE include/UWP/UWPAppBase.hpp ) # Windows Runtime types cannot be included into static libraries # https://social.msdn.microsoft.com/Forums/en-US/269db513-64ef-4817-a025-43954f614eb3/lnk4264-why-are-static-libraries-not-recommended-when-authoring-windows-runtime-types?forum=winappswithnativecode # So as a workaround, we will include all source files into the target app project function(add_uwp_app TARGET_NAME SOURCE INCLUDE ASSETS) get_target_property(NATIVE_APP_SOURCE_DIR Diligent-NativeAppBase SOURCE_DIR) set(UWP_SOURCE ${NATIVE_APP_SOURCE_DIR}/src/UWP/Common/DeviceResources.cpp ${NATIVE_APP_SOURCE_DIR}/src/UWP/App.cpp ${NATIVE_APP_SOURCE_DIR}/src/UWP/UWPAppBase.cpp ) set(UWP_INCLUDE ${NATIVE_APP_SOURCE_DIR}/src/UWP/Common/DeviceResources.h ${NATIVE_APP_SOURCE_DIR}/src/UWP/Common/DirectXHelper.h ${NATIVE_APP_SOURCE_DIR}/src/UWP/App.h ${NATIVE_APP_SOURCE_DIR}/include/UWP/UWPAppBase.hpp ${NATIVE_APP_SOURCE_DIR}/src/UWP/Common/StepTimer.h ) add_executable(${TARGET_NAME} WIN32 ${SOURCE} ${INCLUDE} ${ASSETS} ${UWP_SOURCE} ${UWP_INCLUDE}) set_source_files_properties(${ASSETS} PROPERTIES VS_DEPLOYMENT_CONTENT 1) target_include_directories(${TARGET_NAME} PUBLIC ${NATIVE_APP_SOURCE_DIR}/Src/UWP ) target_link_libraries(${TARGET_NAME} PRIVATE dxgi.lib) source_group("UWP Common\src" FILES ${UWP_SOURCE}) source_group("UWP Common\include" FILES ${UWP_INCLUDE}) endfunction(add_uwp_app) function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS) add_uwp_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}") endfunction() ``` -------------------------------- ### Create and Use RenderStateNotationParser Source: https://context7.com/diligentgraphics/diligenttools/llms.txt Parses JSON files describing render states, shaders, and pipeline configurations. Supports hot-reloading for dynamic updates. Use the parser to inspect and retrieve state descriptions by name. ```cpp #include "RenderStateNotation/interface/RenderStateNotationParser.h" // Create parser (with reload support for hot-reload workflows): Diligent::RenderStateNotationParserCreateInfo parserCI; parserCI.EnableReload = true; Diligent::IRenderStateNotationParser* pParser = nullptr; Diligent::CreateRenderStateNotationParser(parserCI, &pParser); // Parse a notation file (stream factory resolves relative shader paths): pParser->ParseFile("assets/RenderStates/GBuffer.json", pStreamFactory); // Inspect counts: const auto& info = pParser->GetInfo(); // info.ShaderCount, info.PipelineStateCount, info.RenderPassCount ... // Look up a pipeline state description by name: const Diligent::PipelineStateNotation* pPSONotation = pParser->GetPipelineStateByName("GBufferPass", Diligent::PIPELINE_TYPE_GRAPHICS); if (pPSONotation) { // Cast to graphics-specific notation: const auto* pGfx = static_cast(pPSONotation); // pGfx->pVSName, pGfx->pPSName, pGfx->Desc ... } // Hot-reload all states (requires EnableReload = true): bool reloaded = pParser->Reload(); pParser->Release(); ``` -------------------------------- ### Image Decoding and Encoding Source: https://context7.com/diligentgraphics/diligenttools/llms.txt Demonstrates how to decode image files (like PNG) into CPU pixel data using `CreateImageFromFile` and encode raw pixel data back into image formats (like JPEG) using `Image::Encode`. ```APIDOC ## Image — Decode image files to CPU pixel data `CreateImageFromFile` and `CreateImageFromMemory` decode image files into an `Image` object that exposes raw pixel bytes via `GetData()`. `Image::Encode` performs the reverse: serialises raw pixel data to JPEG, PNG, or other formats. ```cpp #include "TextureLoader/interface/Image.h" // Decode PNG from file: Diligent::Image* pImage = nullptr; Diligent::IDataBlob* pRawData = nullptr; Diligent::IMAGE_FILE_FORMAT fmt = Diligent::CreateImageFromFile("screenshot.png", &pImage, &pRawData); if (pImage) { const Diligent::ImageDesc& d = pImage->GetDesc(); // d.Width, d.Height, d.NumComponents, d.ComponentType, d.RowStride const void* pPixels = pImage->GetData()->GetDataPtr(); // Process pixels ... pImage->Release(); } // Encode raw RGBA8 pixels back to JPEG: Diligent::Image::EncodeInfo encInfo; encInfo.Width = 1920; encInfo.Height = 1080; encInfo.TexFormat = Diligent::TEX_FORMAT_RGBA8_UNORM; encInfo.pData = myPixelBuffer; encInfo.Stride = 1920 * 4; encInfo.FileFormat = Diligent::IMAGE_FILE_FORMAT_JPEG; encInfo.JpegQuality = 90; encInfo.KeepAlpha = false; Diligent::IDataBlob* pEncoded = nullptr; Diligent::Image::Encode(encInfo, &pEncoded); // pEncoded->GetDataPtr() points to JPEG bytes, pEncoded->GetSize() is the byte count. pEncoded->Release(); ``` ``` -------------------------------- ### CreateRenderStateNotationLoader Source: https://context7.com/diligentgraphics/diligenttools/llms.txt Instantiates a render state notation loader which can create GPU objects from parsed notation. It takes an IRenderStateNotationParser and an IRenderDevice, and optionally accepts modify-callbacks for runtime descriptor patching. ```APIDOC ## CreateRenderStateNotationLoader — Instantiate GPU objects from parsed notation `IRenderStateNotationLoader` takes an `IRenderStateNotationParser` and a live `IRenderDevice` and creates real GPU `IPipelineState`, `IShader`, `IRenderPass`, and `IPipelineResourceSignature` objects. Optional modify-callbacks allow runtime patching of descriptors before object creation. ```cpp #include "RenderStateNotation/interface/RenderStateNotationLoader.h" Diligent::RenderStateNotationLoaderCreateInfo loaderCI; loaderCI.pDevice = pDevice; loaderCI.pParser = pParser; // previously created parser loaderCI.pStreamFactory = pStreamFactory; // shader source stream factory loaderCI.pStateCache = pStateCache; // optional render-state cache Diligent::IRenderStateNotationLoader* pLoader = nullptr; Diligent::CreateRenderStateNotationLoader(loaderCI, &pLoader); // Load a graphics pipeline state: Diligent::LoadPipelineStateInfo psoLI; psoLI.Name = "GBufferPass"; psoLI.PipelineType = Diligent::PIPELINE_TYPE_GRAPHICS; psoLI.AddToCache = true; // Optional: patch the render target format at load time: psoLI.ModifyPipeline = [](Diligent::PipelineStateCreateInfo& CI, void*) { auto& gfxCI = static_cast(CI); gfxCI.GraphicsPipeline.RTVFormats[0] = Diligent::TEX_FORMAT_RGBA16_FLOAT; gfxCI.GraphicsPipeline.NumRenderTargets = 1; }; Diligent::IPipelineState* pPSO = nullptr; pLoader->LoadPipelineState(psoLI, &pPSO); // Load a standalone shader: Diligent::LoadShaderInfo shaderLI; shaderLI.Name = "FullscreenVS"; Diligent::IShader* pVS = nullptr; pLoader->LoadShader(shaderLI, &pVS); // Hot-reload all GPU objects (shaders and PSOs): bool ok = pLoader->Reload(); pLoader->Release(); pPSO->Release(); pVS->Release(); ``` ``` -------------------------------- ### Destination Manager Methods Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt Outlines the three essential methods for a custom data destination manager: initialization, buffer emptying, and termination. These methods are called by the libjpeg compression functions. ```c init_destination (j_compress_ptr cinfo) Initialize destination. This is called by jpeg_start_compress() before any data is actually written. It must initialize next_output_byte and free_in_buffer. free_in_buffer must be initialized to a positive value. empty_output_buffer (j_compress_ptr cinfo) This is called whenever the buffer has filled (free_in_buffer reaches zero). In typical applications, it should write out the *entire* buffer (use the saved start address and buffer length; ignore the current state of next_output_byte and free_in_buffer). Then reset the pointer & count to the start of the buffer, and return TRUE indicating that the buffer has been dumped. free_in_buffer must be set to a positive value when TRUE is returned. A FALSE return should only be used when I/O suspension is desired (this operating mode is discussed in the next section). term_destination (j_compress_ptr cinfo) Terminate destination --- called by jpeg_finish_compress() after all data has been written. In most applications, this must flush any data remaining in the buffer. Use either next_output_byte or free_in_buffer to determine how much data is in the buffer. ``` -------------------------------- ### Initialize JPEG Compression Object Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt Initializes the JPEG compression object and error handler. The error handler must be set up before creating the compression object, as it can exit on fatal errors. ```c struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; ... cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); ``` -------------------------------- ### Load Custom Quantization Table Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/libjpeg.txt Allocates and fills a quantization table slot. Ensure the table is allocated if it's NULL, and copy your custom table values into the allocated structure. ```c if (cinfo.quant_tbl_ptrs[n] == NULL) cinfo.quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) &cinfo); quant_ptr = cinfo.quant_tbl_ptrs[n]; /* quant_ptr is JQUANT_TBL* */ for (i = 0; i < 64; i++) { /* Qtable[] is desired quantization table, in natural array order */ quant_ptr->quantval[i] = Qtable[i]; } ``` -------------------------------- ### Define XCBKeySyms Library Build Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/Linux/CMakeLists.txt Configures the build for the XCBKeySyms static library, specifying source and interface files and setting common properties. ```cmake cmake_minimum_required (VERSION 3.10) project(XCBKeySyms C) set(INTERFACE xcb_keysyms/xcb_keysyms.h ) set(SOURCE xcb_keysyms/xcb_keysyms.c ) add_library(XCBKeySyms STATIC ${SOURCE} ${INTERFACE}) set_common_target_properties(XCBKeySyms) target_include_directories(XCBKeySyms PUBLIC .) source_group("source" FILES ${SOURCE}) source_group("interface" FILES ${INTERFACE}) find_library(XCB_LIBRARY xcb) target_link_libraries(XCBKeySyms PRIVATE Diligent-BuildSettings ${XCB_LIBRARY} ) set_target_properties(XCBKeySyms PROPERTIES FOLDER Common ) ``` -------------------------------- ### Platform Specific Include Directories - tvOS Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Sets the public include directory for tvOS builds. ```cmake target_include_directories(Diligent-NativeAppBase PUBLIC include/TVOS ) ``` -------------------------------- ### Add Emscripten Application Target Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Sets up source and include files for an Emscripten (Web) build. Includes options for initial memory allocation. ```cmake set(SOURCE src/Emscripten/EmscriptenAppBase.cpp src/Emscripten/EmscriptenMain.cpp ) set(INCLUDE include/Emscripten/EmscriptenAppBase.hpp ) function(add_emscripten_app TARGET_NAME SOURCE INCLUDE ASSETS) add_executable(${TARGET_NAME} ${SOURCE} ${INCLUDE} ${ASSETS}) # The initial amount of memory to use. Using more memory than this will cause us to expand the heap, # which can be costly with typed arrays. If ALLOW_MEMORY_GROWTH is set, this initial amount of memory can # increase later; if not, then it is the final and total amount of memory. #target_link_options(${TARGET_NAME} PRIVATE "SHELL: -s INITIAL_MEMORY=32MB") # If false, the app is aborted with an error if it tries to allocate more memory than INITIAL_MEMORY. ``` -------------------------------- ### Configure Native App Glue Library Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/Android/CMakeLists.txt Adds the native_app_glue library, links it with the log library, and sets its include directories. This is essential for using Android's native activity APIs. ```cmake cmake_minimum_required (VERSION 3.10) add_library(native_app_glue ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) target_link_libraries(native_app_glue log) target_include_directories(native_app_glue INTERFACE ${ANDROID_NDK}/sources/android/native_app_glue) set_common_target_properties(native_app_glue) ``` -------------------------------- ### Platform Specific Configuration - Android Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Links NDKHelper, native_app_glue, and the android library. Sets the public include directory for Android builds. ```cmake target_link_libraries(Diligent-NativeAppBase PUBLIC NDKHelper native_app_glue PRIVATE android) target_include_directories(Diligent-NativeAppBase PUBLIC include/Android ) ``` -------------------------------- ### Platform Specific Include Directories - UWP Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Sets the public include directories for Universal Windows Platform (UWP) builds. ```cmake target_include_directories(Diligent-NativeAppBase PUBLIC include/UWP src/UWP ) ``` -------------------------------- ### cjpeg -progressive Switch Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/usage.txt Create a progressive JPEG file. Progressive JPEGs display gradually as they download. ```bash cjpeg -progressive [options] [inputfile] ``` -------------------------------- ### macOS Application Source and Include Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Sets the source and include files for macOS application builds. ```cmake set(SOURCE src/macOS/MacOSAppBase.cpp ) set(INCLUDE ``` -------------------------------- ### Emscripten Linker Options for Memory Growth Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Enables dynamic memory growth at runtime for Emscripten builds. Related settings include MEMORY_GROWTH_GEOMETRIC_STEP, MEMORY_GROWTH_GEOMETRIC_CAP, and MEMORY_GROWTH_LINEAR_STEP. ```cmake target_link_options(${TARGET_NAME} PRIVATE "SHELL: -s ALLOW_MEMORY_GROWTH=1") ``` -------------------------------- ### Platform Specific Include Directories - visionOS Source: https://github.com/diligentgraphics/diligenttools/blob/master/NativeApp/CMakeLists.txt Sets the public include directory for visionOS builds. ```cmake target_include_directories(Diligent-NativeAppBase PUBLIC include/VisionOS ) ``` -------------------------------- ### Configure DiligentTools IncludeTest Library Source: https://github.com/diligentgraphics/diligenttools/blob/master/Tests/IncludeTest/CMakeLists.txt Sets up the CMake build for the DiligentTools IncludeTest library. It finds all C++ and C source files, creates a static library, and configures include directories and link libraries. ```cmake cmake_minimum_required (VERSION 3.10) project(DiligentTools-IncludeTest) file(GLOB_RECURSE SOURCE LIST_DIRECTORIES false *.cpp *.c) add_library(DiligentTools-IncludeTest ${SOURCE}) target_include_directories(DiligentTools-IncludeTest PRIVATE ../..) target_link_libraries(DiligentTools-IncludeTest PRIVATE Diligent-BuildSettings) set_common_target_properties(DiligentTools-IncludeTest) ``` -------------------------------- ### Enable Progress Reporting Source: https://github.com/diligentgraphics/diligenttools/blob/master/ThirdParty/libjpeg-9e/install.txt Define PROGRESS_REPORT in jconfig.h to enable percent-done progress reports. The default implementation prints percentages to stderr. ```c #define PROGRESS_REPORT ```