Source browser

examples/export_shader.cpp

Read the complete file below or download its original bytes. Line numbers provide stable links to a declaration or processing step.

File fingerprint
1#include "shdr.h" // Include shdr.h declarations.
2#include <iostream> // Include iostream declarations.
3#include <stdexcept> // Include stdexcept declarations.
4#include <string> // Include string declarations.
5
6/// Export a shader as standalone GLSL for the selected standards-compliant profile.
7int main(int argc, char** argv) { // Run this example and validate its results.
8    try { // Run the operation while retaining the error handling below.
9        if (argc != 3) // Check this condition before entering the following branch.
10            throw std::invalid_argument("usage: export_shader KERNEL PROFILE"); // Report usage: export_shader KERNEL PROFILE.
11        const std::string name(argv[2]); // Construct name with these initial values.
12        shdr::profile profile; // Declare profile for the following calculation.
13        if (name == "es31") // Check this condition before entering the following branch.
14            profile = shdr::profile::es31; // Set profile from this expression.
15        else if (name == "es32") // Select the GLES 3.2 source profile.
16            profile = shdr::profile::es32; // Set profile from this expression.
17        else if (name == "gl43") // Select the desktop GL 4.3 source profile.
18            profile = shdr::profile::gl43; // Set profile from this expression.
19        else if (name == "gl45") // Select the desktop GL 4.5 source profile.
20            profile = shdr::profile::gl45; // Set profile from this expression.
21        else if (name == "gl46") // Select the desktop GL 4.6 source profile.
22            profile = shdr::profile::gl46; // Set profile from this expression.
23        else // Reject profile names outside the supported list.
24            throw std::invalid_argument("unknown profile: " + name); // Report unknown profile: .
25        std::cout << shdr::make_kernel(argv[1])->glsl(profile); // Create the linked shader instance.
26        return 0; // Report successful completion.
27    } catch (const std::exception& error) { // Report the exception from the preceding operation.
28        std::cerr << error.what() << "\n"; // Write this part of the example result or diagnostic.
29        return 1; // Report a failed check or operation.
30    } // End this block.
31} // End this block.