Holds all informations related to GPU programs, and manages their compilation. More...
Static Public Member Functions | |
static nkMemory::UniquePtr< Program > | create (System *system=nullptr) |
Holds all informations related to GPU programs, and manages their compilation.
See ProgramManager::createOrRetrieve() or Program::create() for instantiation.
|
noexcept |
Constructor.
system | The system the resource should live in. |
|
virtual |
Destructor.
const ProgramCompilationResult& nkGraphics::Program::getLastCompilationResult | ( | ) | const |
bool nkGraphics::Program::isFromFile | ( | ) | const |
bool nkGraphics::Program::isFromMemory | ( | ) | const |
const ProgramSourcesHolder& nkGraphics::Program::getMemory | ( | ) | const |
nkMemory::BufferView<const ProgramSemanticEntry> nkGraphics::Program::getInputSemantics | ( | ) | const |
unsigned int nkGraphics::Program::getId | ( | ) | const |
PROGRAM_TYPE nkGraphics::Program::getType | ( | ) | const |
PROGRAM_COMPILATION_PROFILE nkGraphics::Program::getProfile | ( | ) | const |
|
virtual |
Sets the program from an already loaded memory set.
The memory used will need to fit some constraints for a Program to find back relevant data :
memory | The memory to use. |
|
virtual |
Sets the defines to use within the program. Can be useful to add defines and then load a program from a folder.
memory | The memory to copy de defines from. |
void nkGraphics::Program::setFromFiles | ( | nkMemory::StringView | folder | ) |
Sets the folder from which the program should load its sources. The files that can be loaded are :
With x being the extension set through the setFileExtensions() function, or the default which depends on the type of renderer :
folder | The path of the folder to load from, relative to the working directory. See nkResources::ResourceManager for the path naming conventions. |
void nkGraphics::Program::setFileExtensions | ( | nkMemory::StringView | value | ) |
Sets the extension to search for when parsing the given folder. This allows to override the default behavior of the file seeking algorithm, enabling to put in common files loaded for all type of renderers, for instance.
value | The extension to append to the file names. |
void nkGraphics::Program::setId | ( | unsigned int | id | ) |
Sets the id of the program.
id | The id to use. |
void nkGraphics::Program::setProfile | ( | PROGRAM_COMPILATION_PROFILE | profile | ) |
Sets the profile to use for compilation.
profile | The profile to use. |
void nkGraphics::Program::setActivateCrossCompilerDefines | ( | bool | value | ) |
Activates or not the cross compiler defines feeding. This is a good tool to use if you plan on making your programs work both on DirectX and OpenGL based renderers. Setting this to true will enable keywords within hlsl / glsl sources to ease cross-platform development. By default, this flag is off to lower processing times while loading programs.
If set to on, new keywords will become available to program sources, that will translate correctly into both languages :
Nk keyword | Hlsl translation | Glsl translation | |
---|---|---|---|
Types | |||
nkBool2 | bool2 | bvec2 | |
nkBool3 | bool3 | bvec3 | |
nkBool4 | bool4 | bvec4 | |
nkFloat2 | float2 | vec2 | |
nkFloat3 | float3 | vec3 | |
nkFloat4 | float4 | vec4 | |
nkInt2 | int2 | ivec2 | |
nkInt3 | int3 | ivec3 | |
nkInt4 | int4 | ivec4 | |
nkUint2 | uint2 | uvec2 | |
nkUint3 | uint3 | uvec3 | |
nkUint4 | uint4 | uvec4 | |
nkFloat2x2 | float2x2 | mat2 | |
nkFloat3x3 | float3x3 | mat3 | |
nkFloat4x4 | float4x4 | mat4 | |
nkFloat2x4 | float2x4 | mat2x4 | |
nkTexture2d | Texture2D | sampler2D | |
nkTexture2dArray | Texture2DArray | sampler2DArray | |
nkTexture2dShadow | Texture2D | sampler2DShadow | |
nkTexture3d | Texture3D | sampler3D | |
nkTextureCube | TextureCube | samplerCube | |
nkSampler | SamplerState | bool (no valid translation) | |
nkSamplerComparison | SamplerComparisonState | bool (no valid translation) | |
Textures declarations | |||
nkTexture2dDecl(name, slot) | Texture2D [name] : register(t[slot]) | layout(binding = [slot]) uniform sampler2D [name] | |
nkTexture2dArrayDecl(name, slot) | Texture2DArray [name] : register(t[slot]) | layout(binding = [slot]) uniform sampler2DArray [name] | |
nkTexture2dShadowDecl(name, slot) | Texture2D [name] : register(t[slot]) | layout(binding = [slot]) uniform sampler2DShadow [name] | |
nkTexture3dDecl(name, slot) | Texture3D [name] : register(t[slot]) | layout(binding = [slot]) uniform sampler3D [name] | |
nkTextureCubeDecl(name, slot) | TextureCube [name] : register(t[slot]) | layout(binding = [slot]) uniform samplerCube [name] | |
nkSamplerDecl(name, slot) | SamplerState [name] : register(s[slot]) | bool [name] (no valid translation) | |
nkSamplerComparisonDecl(name, slot) | SamplerComparisonState [name] : register(s[slot]) | bool [name] (no valid translation) | |
Textures functions | |||
nkSample(tex, sampler, uvs) | [tex].Sample([sampler], [uvs]) | texture([tex], [uvs]) | |
nkSampleBias(tex, sampler, uvs, bias) | [tex].SampleBias([sampler], [uvs], [bias]) | texture([tex], [uvs], [bias]) | |
nkSampleLevel(tex, sampler, uvs, level) | [tex].SampleLevel([sampler], [uvs], [level]) | textureLod([tex], [uvs], [level]) | |
nkSampleCompare(tex, sampler, uvs, value) | [tex].SampleCmp([sampler], [uvs], [value]) | texture([tex], vec3([uvs], [level])) | |
nkSampleCompareLevelZero(tex, sampler, uvs, value) | [tex].SampleCmpLevelZero([sampler], [uvs], [value]) | textureLod([tex], vec3([uvs], 0), [level]) | |
nkLoad(tex, texel) | [tex].Load([texel]) | texelFetch([tex], [texel.xy], [texel.z]) | |
nkLoadOffset(tex, texel, offset) | [tex].Load([texel], [offset]) | texelFetchOffset([tex], [texel.xy], [texel.z], [offset]) | |
Constant declarations | |||
nkConstantBuffer(name, slot) | cbuffer [name] : register(b[slot]) | layout(binding = [slot], std140) uniform [name] | |
Comparison functions | |||
nkLessThan(a, b) | ([a] < [b]) | lessThan([a], [b]) | |
General functions | |||
nkMul(a, b) | mul([a], [b]) | ([a] * [b]) | |
nkAtan2(a, b) | atan2([a], [b]) | atan([a], [b]) | |
nkFrac(a) | frac([a]) | fract([a]) | |
nkSaturate(a) | saturate([a]) | clamp([a], 0, 1) | |
nkDdx(a) | ddx([a]) | dFdx([a]) | |
nkDdy(a) | ddy([a]) | dFdy([a]) | |
nkLerp(a, b, c) | lerp([a], [b], [c]) | mix([a], [b], [c]) |
value | Whether the defines should be set (true) or not (false). |
bool nkGraphics::Program::prepareMemoryWithFiles | ( | ) |
If the program is defined from a folder, prepares the memory with the source files content.
|
pure virtual |
Loads the program, from the memory currently set.
|
pure virtual |
Tries to load from a provided memory, and swap the current state with the newly submitted state only on success. If it fails, the program state is not changed.
newMemory | The memory to try to load from. |
|
overridevirtual |
Loads and compiles the program.
When processing the compilation, a program will automatically add some defines to help with cross renderer development :
Allowing to write code that will differentiate between both compilers :
#if defined(NK_HLSL) float4 main (in float4 pos : SV_POSITION) : SV_TARGET { return 1 ; } #elif defined(NK_GLSL) out vec4 color ; void main () { color = vec4(1) ; } #endif
Implements nkGraphics::Resource.
|
overridevirtual |
Unloads and frees the internal resources of the program.
Implements nkGraphics::Resource.
|
overridevirtual |
Exports an item into a tree describing its structure and its data.
rootNode | The node into which the object has to write its related information. |
Implements nkExport::Exportable.
|
overridevirtual |
Imports information from a tree which is supposed to describe its structure and data.
rootNode | The root node of the tree holding the information. |
Implements nkExport::Exportable.
|
static |
Creates a standalone resource, linking it to a system, but no manager. This method can be used to allocate a resource and manually manage its lifetime.
system | The system to create the resource into. If left to nullptr, then the Singleton instance will be used. |