|
Kemena3D
|
Wraps a compiled GLSL shader program. More...
#include <kshader.h>
Public Member Functions | |
| kShader () | |
| Constructs an empty shader with no compiled program. | |
| virtual | ~kShader () |
| Destroys the shader, deleting the GPU program if one was compiled. | |
| kString | readFile (const kString filePath) |
| Reads the entire contents of a text file into a string. | |
| void | loadGlslFile (const kString &path) |
| void | loadGlslCode (const kString &src) |
| void | loadShadersFile (const kString vertexShaderPath, const kString fragmentShaderPath) |
| void | loadShadersCode (const char *vertexShaderCode, const char *fragmentShaderCode) |
| void | loadHlslFileDX11 (const kString &path) |
| void | loadHlslCodeDX11 (const kString &src) |
| void | loadHlslFileDX12 (const kString &path) |
| void | loadHlslCodeDX12 (const kString &src) |
| void | loadSpirvFile (const kString &path) |
| void | loadSpirvCode (const kString &src) |
| void | loadSpirvBinary (const std::vector< uint8_t > &vertSpv, const std::vector< uint8_t > &fragSpv) |
| void | loadMetalFile (const kString &path) |
| void | loadMetalCode (const kString &src) |
| void | use () |
| Binds this shader program for subsequent draw calls. | |
| void | unuse () |
| Unbinds the current shader program. | |
| void | setShaderProgram (uint32_t program) |
| Overrides the internal program handle. | |
| uint32_t | getShaderProgram () |
| Returns the underlying program handle. | |
| void | setValue (kString name, std::vector< kMat4 > value) |
| Sets a kMat4 array uniform. | |
| void | setValue (kString name, kMat4 value) |
| Sets a kMat4 uniform. | |
| void | setValue (kString name, kVec4 value) |
| Sets a kVec4 uniform. | |
| void | setValue (kString name, kVec3 value) |
| Sets a kVec3 uniform. | |
| void | setValue (kString name, kVec2 value) |
| Sets a kVec2 uniform. | |
| void | setValue (kString name, float value) |
| Sets a float uniform. | |
| void | setValue (kString name, int value) |
| Sets an integer uniform. | |
| void | setValue (kString name, unsigned int value) |
| Sets an unsigned-integer uniform. | |
| void | setValue (kString name, bool value) |
| Sets a boolean uniform (uploaded as int). | |
Static Public Member Functions | |
| static kShaderSource | splitSource (const kString &src) |
| Splits a combined shader source string into per-stage strings. | |
Wraps a compiled GLSL shader program.
Shaders can be loaded from source files or inline code strings. All GPU operations are dispatched through kDriver::getCurrent(), so no GL headers need to be included in client code.
Example:
| kemena::kShader::kShader | ( | ) |
Constructs an empty shader with no compiled program.
|
virtual |
Destroys the shader, deleting the GPU program if one was compiled.
| uint32_t kemena::kShader::getShaderProgram | ( | ) |
Returns the underlying program handle.
| void kemena::kShader::loadGlslCode | ( | const kString & | src | ) |
Load a combined GLSL source string.
| void kemena::kShader::loadGlslFile | ( | const kString & | path | ) |
Load a combined GLSL source file (vertex + optional geometry + fragment).
| void kemena::kShader::loadHlslCodeDX11 | ( | const kString & | src | ) |
Placeholder: load a combined HLSL source string for a DirectX 11 backend.
| void kemena::kShader::loadHlslCodeDX12 | ( | const kString & | src | ) |
Placeholder: load a combined HLSL source string for a DirectX 12 backend.
| void kemena::kShader::loadHlslFileDX11 | ( | const kString & | path | ) |
Placeholder: load a combined HLSL source file for a DirectX 11 backend.
| void kemena::kShader::loadHlslFileDX12 | ( | const kString & | path | ) |
Placeholder: load a combined HLSL source file for a DirectX 12 backend.
| void kemena::kShader::loadMetalCode | ( | const kString & | src | ) |
Placeholder: load a combined Metal Shading Language source string.
| void kemena::kShader::loadMetalFile | ( | const kString & | path | ) |
Placeholder: load a combined Metal Shading Language source file.
| void kemena::kShader::loadShadersCode | ( | const char * | vertexShaderCode, |
| const char * | fragmentShaderCode ) |
Load separate GLSL source strings (vertex, fragment).
| void kemena::kShader::loadShadersFile | ( | const kString | vertexShaderPath, |
| const kString | fragmentShaderPath ) |
Load separate GLSL source files (vertex, fragment).
| void kemena::kShader::loadSpirvBinary | ( | const std::vector< uint8_t > & | vertSpv, |
| const std::vector< uint8_t > & | fragSpv ) |
Placeholder: load pre-compiled SPIR-V binary blobs for Vulkan 1.3.
| void kemena::kShader::loadSpirvCode | ( | const kString & | src | ) |
Placeholder: load a combined GLSL/HLSL source string for Vulkan 1.3.
| void kemena::kShader::loadSpirvFile | ( | const kString & | path | ) |
Placeholder: load a combined GLSL/HLSL source file for Vulkan 1.3 (compiled to SPIR-V).
Reads the entire contents of a text file into a string.
| filePath | Path to the file to read. |
| void kemena::kShader::setShaderProgram | ( | uint32_t | program | ) |
Overrides the internal program handle.
Use this when the program was compiled externally (e.g. via kDriver).
| program | Compiled program handle. |
| void kemena::kShader::setValue | ( | kString | name, |
| bool | value ) |
Sets a boolean uniform (uploaded as int).
| void kemena::kShader::setValue | ( | kString | name, |
| float | value ) |
Sets a float uniform.
| void kemena::kShader::setValue | ( | kString | name, |
| int | value ) |
Sets an integer uniform.
Sets a kMat4 array uniform.
| void kemena::kShader::setValue | ( | kString | name, |
| unsigned int | value ) |
Sets an unsigned-integer uniform.
|
static |
Splits a combined shader source string into per-stage strings.
Recognised section markers (on their own line): // — VERTEX — (optional; top of file is implicitly vertex) // — GEOMETRY — (optional geometry stage) // — FRAGMENT — (fragment / pixel stage)
| void kemena::kShader::unuse | ( | ) |
Unbinds the current shader program.
| void kemena::kShader::use | ( | ) |
Binds this shader program for subsequent draw calls.