Skip to content

Commit 35911ac

Browse files
authored
Added uniform frequency. (#3485)
* Added uniform frequency. * Cleanup. * Cleanup.
1 parent 8a9bc3e commit 35911ac

File tree

25 files changed

+1296
-119
lines changed

25 files changed

+1296
-119
lines changed

bindings/bf/bgfx.bf

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,27 @@ public static class bgfx
18471847
Count
18481848
}
18491849

1850+
[AllowDuplicates]
1851+
public enum UniformFreq : uint32
1852+
{
1853+
/// <summary>
1854+
/// Changing per draw call.
1855+
/// </summary>
1856+
Draw,
1857+
1858+
/// <summary>
1859+
/// Changing per view.
1860+
/// </summary>
1861+
View,
1862+
1863+
/// <summary>
1864+
/// Changing per frame.
1865+
/// </summary>
1866+
Frame,
1867+
1868+
Count
1869+
}
1870+
18501871
[AllowDuplicates]
18511872
public enum BackbufferRatio : uint32
18521873
{
@@ -3432,6 +3453,41 @@ public static class bgfx
34323453
[LinkName("bgfx_create_uniform")]
34333454
public static extern UniformHandle create_uniform(char8* _name, UniformType _type, uint16 _num);
34343455

3456+
/// <summary>
3457+
/// Create shader uniform parameter.
3458+
/// @remarks
3459+
/// 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
3460+
/// multiple times with the same uniform name. The library will always
3461+
/// return the same handle, but the handle reference count will be
3462+
/// incremented. This means that the same number of `bgfx::destroyUniform`
3463+
/// must be called to properly destroy the uniform.
3464+
/// 2. Predefined uniforms (declared in `bgfx_shader.sh`):
3465+
/// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
3466+
/// view, in pixels.
3467+
/// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
3468+
/// width and height
3469+
/// - `u_view mat4` - view matrix
3470+
/// - `u_invView mat4` - inverted view matrix
3471+
/// - `u_proj mat4` - projection matrix
3472+
/// - `u_invProj mat4` - inverted projection matrix
3473+
/// - `u_viewProj mat4` - concatenated view projection matrix
3474+
/// - `u_invViewProj mat4` - concatenated inverted view projection matrix
3475+
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
3476+
/// - `u_modelView mat4` - concatenated model view matrix, only first
3477+
/// model matrix from array is used.
3478+
/// - `u_invModelView mat4` - inverted concatenated model view matrix.
3479+
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
3480+
/// - `u_alphaRef float` - alpha reference value for alpha test.
3481+
/// </summary>
3482+
///
3483+
/// <param name="_name">Uniform name in shader.</param>
3484+
/// <param name="_freq">Uniform change frequency (See: `bgfx::UniformFreq`).</param>
3485+
/// <param name="_type">Type of uniform (See: `bgfx::UniformType`).</param>
3486+
/// <param name="_num">Number of elements in array.</param>
3487+
///
3488+
[LinkName("bgfx_create_uniform_with_freq")]
3489+
public static extern UniformHandle create_uniform_with_freq(char8* _name, UniformFreq _freq, UniformType _type, uint16 _num);
3490+
34353491
/// <summary>
34363492
/// Retrieve uniform info.
34373493
/// </summary>
@@ -3804,6 +3860,31 @@ public static class bgfx
38043860
[LinkName("bgfx_encoder_set_uniform")]
38053861
public static extern void encoder_set_uniform(Encoder* _this, UniformHandle _handle, void* _value, uint16 _num);
38063862

3863+
/// <summary>
3864+
/// Set shader uniform parameter for view.
3865+
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
3866+
/// </summary>
3867+
///
3868+
/// <param name="_id">View id.</param>
3869+
/// <param name="_handle">Uniform.</param>
3870+
/// <param name="_value">Pointer to uniform data.</param>
3871+
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
3872+
///
3873+
[LinkName("bgfx_set_view_uniform")]
3874+
public static extern void set_view_uniform(ViewId _id, UniformHandle _handle, void* _value, uint16 _num);
3875+
3876+
/// <summary>
3877+
/// Set shader uniform parameter for frame.
3878+
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
3879+
/// </summary>
3880+
///
3881+
/// <param name="_handle">Uniform.</param>
3882+
/// <param name="_value">Pointer to uniform data.</param>
3883+
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
3884+
///
3885+
[LinkName("bgfx_set_frame_uniform")]
3886+
public static extern void set_frame_uniform(UniformHandle _handle, void* _value, uint16 _num);
3887+
38073888
/// <summary>
38083889
/// Set index buffer for draw primitive.
38093890
/// </summary>

bindings/c3/bgfx.c3

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,20 @@ enum UniformType : uint
11851185
COUNT
11861186
}
11871187

1188+
enum UniformFreq : uint
1189+
{
1190+
// Changing per draw call.
1191+
DRAW,
1192+
1193+
// Changing per view.
1194+
VIEW,
1195+
1196+
// Changing per frame.
1197+
FRAME,
1198+
1199+
COUNT
1200+
}
1201+
11881202
enum BackbufferRatio : uint
11891203
{
11901204
// Equal to backbuffer.
@@ -2452,6 +2466,36 @@ extern fn void destroy_frame_buffer(FrameBufferHandle _handle) @extern("bgfx_des
24522466
// _num : `Number of elements in array.`
24532467
extern fn UniformHandle create_uniform(ZString _name, UniformType _type, ushort _num) @extern("bgfx_create_uniform");
24542468

2469+
// Create shader uniform parameter.
2470+
// @remarks
2471+
// 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
2472+
// multiple times with the same uniform name. The library will always
2473+
// return the same handle, but the handle reference count will be
2474+
// incremented. This means that the same number of `bgfx::destroyUniform`
2475+
// must be called to properly destroy the uniform.
2476+
// 2. Predefined uniforms (declared in `bgfx_shader.sh`):
2477+
// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
2478+
// view, in pixels.
2479+
// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
2480+
// width and height
2481+
// - `u_view mat4` - view matrix
2482+
// - `u_invView mat4` - inverted view matrix
2483+
// - `u_proj mat4` - projection matrix
2484+
// - `u_invProj mat4` - inverted projection matrix
2485+
// - `u_viewProj mat4` - concatenated view projection matrix
2486+
// - `u_invViewProj mat4` - concatenated inverted view projection matrix
2487+
// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
2488+
// - `u_modelView mat4` - concatenated model view matrix, only first
2489+
// model matrix from array is used.
2490+
// - `u_invModelView mat4` - inverted concatenated model view matrix.
2491+
// - `u_modelViewProj mat4` - concatenated model view projection matrix.
2492+
// - `u_alphaRef float` - alpha reference value for alpha test.
2493+
// _name : `Uniform name in shader.`
2494+
// _freq : `Uniform change frequency (See: `bgfx::UniformFreq`).`
2495+
// _type : `Type of uniform (See: `bgfx::UniformType`).`
2496+
// _num : `Number of elements in array.`
2497+
extern fn UniformHandle create_uniform_with_freq(ZString _name, UniformFreq _freq, UniformType _type, ushort _num) @extern("bgfx_create_uniform_with_freq");
2498+
24552499
// Retrieve uniform info.
24562500
// _handle : `Handle to uniform object.`
24572501
// _info : `Uniform info.`
@@ -2666,6 +2710,21 @@ extern fn uint encoder_alloc_transform(Encoder* _this, Transform* _transform, us
26662710
// _num : `Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.`
26672711
extern fn void encoder_set_uniform(Encoder* _this, UniformHandle _handle, void* _value, ushort _num) @extern("bgfx_encoder_set_uniform");
26682712

2713+
// Set shader uniform parameter for view.
2714+
// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
2715+
// _id : `View id.`
2716+
// _handle : `Uniform.`
2717+
// _value : `Pointer to uniform data.`
2718+
// _num : `Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.`
2719+
extern fn void set_view_uniform(ushort _id, UniformHandle _handle, void* _value, ushort _num) @extern("bgfx_set_view_uniform");
2720+
2721+
// Set shader uniform parameter for frame.
2722+
// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
2723+
// _handle : `Uniform.`
2724+
// _value : `Pointer to uniform data.`
2725+
// _num : `Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.`
2726+
extern fn void set_frame_uniform(UniformHandle _handle, void* _value, ushort _num) @extern("bgfx_set_frame_uniform");
2727+
26692728
// Set index buffer for draw primitive.
26702729
// _handle : `Index buffer.`
26712730
// _firstIndex : `First index to render.`

bindings/cs/bgfx.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,26 @@ public enum UniformType
18391839
Count
18401840
}
18411841

1842+
public enum UniformFreq
1843+
{
1844+
/// <summary>
1845+
/// Changing per draw call.
1846+
/// </summary>
1847+
Draw,
1848+
1849+
/// <summary>
1850+
/// Changing per view.
1851+
/// </summary>
1852+
View,
1853+
1854+
/// <summary>
1855+
/// Changing per frame.
1856+
/// </summary>
1857+
Frame,
1858+
1859+
Count
1860+
}
1861+
18421862
public enum BackbufferRatio
18431863
{
18441864
/// <summary>
@@ -3386,6 +3406,41 @@ public struct VertexLayoutHandle {
33863406
[DllImport(DllName, EntryPoint="bgfx_create_uniform", CallingConvention = CallingConvention.Cdecl)]
33873407
public static extern unsafe UniformHandle create_uniform([MarshalAs(UnmanagedType.LPStr)] string _name, UniformType _type, ushort _num);
33883408

3409+
/// <summary>
3410+
/// Create shader uniform parameter.
3411+
/// @remarks
3412+
/// 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
3413+
/// multiple times with the same uniform name. The library will always
3414+
/// return the same handle, but the handle reference count will be
3415+
/// incremented. This means that the same number of `bgfx::destroyUniform`
3416+
/// must be called to properly destroy the uniform.
3417+
/// 2. Predefined uniforms (declared in `bgfx_shader.sh`):
3418+
/// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
3419+
/// view, in pixels.
3420+
/// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
3421+
/// width and height
3422+
/// - `u_view mat4` - view matrix
3423+
/// - `u_invView mat4` - inverted view matrix
3424+
/// - `u_proj mat4` - projection matrix
3425+
/// - `u_invProj mat4` - inverted projection matrix
3426+
/// - `u_viewProj mat4` - concatenated view projection matrix
3427+
/// - `u_invViewProj mat4` - concatenated inverted view projection matrix
3428+
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
3429+
/// - `u_modelView mat4` - concatenated model view matrix, only first
3430+
/// model matrix from array is used.
3431+
/// - `u_invModelView mat4` - inverted concatenated model view matrix.
3432+
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
3433+
/// - `u_alphaRef float` - alpha reference value for alpha test.
3434+
/// </summary>
3435+
///
3436+
/// <param name="_name">Uniform name in shader.</param>
3437+
/// <param name="_freq">Uniform change frequency (See: `bgfx::UniformFreq`).</param>
3438+
/// <param name="_type">Type of uniform (See: `bgfx::UniformType`).</param>
3439+
/// <param name="_num">Number of elements in array.</param>
3440+
///
3441+
[DllImport(DllName, EntryPoint="bgfx_create_uniform_with_freq", CallingConvention = CallingConvention.Cdecl)]
3442+
public static extern unsafe UniformHandle create_uniform_with_freq([MarshalAs(UnmanagedType.LPStr)] string _name, UniformFreq _freq, UniformType _type, ushort _num);
3443+
33893444
/// <summary>
33903445
/// Retrieve uniform info.
33913446
/// </summary>
@@ -3758,6 +3813,31 @@ public struct VertexLayoutHandle {
37583813
[DllImport(DllName, EntryPoint="bgfx_encoder_set_uniform", CallingConvention = CallingConvention.Cdecl)]
37593814
public static extern unsafe void encoder_set_uniform(Encoder* _this, UniformHandle _handle, void* _value, ushort _num);
37603815

3816+
/// <summary>
3817+
/// Set shader uniform parameter for view.
3818+
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
3819+
/// </summary>
3820+
///
3821+
/// <param name="_id">View id.</param>
3822+
/// <param name="_handle">Uniform.</param>
3823+
/// <param name="_value">Pointer to uniform data.</param>
3824+
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
3825+
///
3826+
[DllImport(DllName, EntryPoint="bgfx_set_view_uniform", CallingConvention = CallingConvention.Cdecl)]
3827+
public static extern unsafe void set_view_uniform(ushort _id, UniformHandle _handle, void* _value, ushort _num);
3828+
3829+
/// <summary>
3830+
/// Set shader uniform parameter for frame.
3831+
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
3832+
/// </summary>
3833+
///
3834+
/// <param name="_handle">Uniform.</param>
3835+
/// <param name="_value">Pointer to uniform data.</param>
3836+
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
3837+
///
3838+
[DllImport(DllName, EntryPoint="bgfx_set_frame_uniform", CallingConvention = CallingConvention.Cdecl)]
3839+
public static extern unsafe void set_frame_uniform(UniformHandle _handle, void* _value, ushort _num);
3840+
37613841
/// <summary>
37623842
/// Set index buffer for draw primitive.
37633843
/// </summary>

bindings/d/impl.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ extern(C++, "bgfx") package final abstract class UniformType{
5454
sampler,end,vec4,mat3,mat4,count
5555
}
5656
}
57+
extern(C++, "bgfx") package final abstract class UniformFreq{
58+
enum Enum{
59+
draw,view,frame,count
60+
}
61+
}
5762
extern(C++, "bgfx") package final abstract class BackbufferRatio{
5863
enum Enum{
5964
equal,half,quarter,eighth,sixteenth,double_,count

bindings/d/package.d

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import bindbc.common.types: c_int64, c_uint64, va_list;
99
import bindbc.bgfx.config;
1010
static import bgfx.impl;
1111

12-
enum uint apiVersion = 133;
12+
enum uint apiVersion = 134;
1313

1414
alias ViewID = ushort;
1515

@@ -771,6 +771,14 @@ enum UniformType: bgfx.impl.UniformType.Enum{
771771
count = bgfx.impl.UniformType.Enum.count,
772772
}
773773

774+
///Uniform frequency enum.
775+
enum UniformFreq: bgfx.impl.UniformFreq.Enum{
776+
draw = bgfx.impl.UniformFreq.Enum.draw,
777+
view = bgfx.impl.UniformFreq.Enum.view,
778+
frame = bgfx.impl.UniformFreq.Enum.frame,
779+
count = bgfx.impl.UniformFreq.Enum.count,
780+
}
781+
774782
///Backbuffer ratio enum.
775783
enum BackbufferRatio: bgfx.impl.BackbufferRatio.Enum{
776784
equal = bgfx.impl.BackbufferRatio.Enum.equal,
@@ -2848,6 +2856,39 @@ mixin(joinFnBinds((){
28482856
*/
28492857
{q{UniformHandle}, q{createUniform}, q{const(char)* name, bgfx.impl.UniformType.Enum type, ushort num=1}, ext: `C++, "bgfx"`},
28502858

2859+
/**
2860+
* Create shader uniform parameter.
2861+
* Remarks:
2862+
* 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
2863+
* multiple times with the same uniform name. The library will always
2864+
* return the same handle, but the handle reference count will be
2865+
* incremented. This means that the same number of `bgfx::destroyUniform`
2866+
* must be called to properly destroy the uniform.
2867+
* 2. Predefined uniforms (declared in `bgfx_shader.sh`):
2868+
* - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
2869+
* view, in pixels.
2870+
* - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
2871+
* width and height
2872+
* - `u_view mat4` - view matrix
2873+
* - `u_invView mat4` - inverted view matrix
2874+
* - `u_proj mat4` - projection matrix
2875+
* - `u_invProj mat4` - inverted projection matrix
2876+
* - `u_viewProj mat4` - concatenated view projection matrix
2877+
* - `u_invViewProj mat4` - concatenated inverted view projection matrix
2878+
* - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
2879+
* - `u_modelView mat4` - concatenated model view matrix, only first
2880+
* model matrix from array is used.
2881+
* - `u_invModelView mat4` - inverted concatenated model view matrix.
2882+
* - `u_modelViewProj mat4` - concatenated model view projection matrix.
2883+
* - `u_alphaRef float` - alpha reference value for alpha test.
2884+
Params:
2885+
name = Uniform name in shader.
2886+
freq = Uniform change frequency (See: `bgfx::UniformFreq`).
2887+
type = Type of uniform (See: `bgfx::UniformType`).
2888+
num = Number of elements in array.
2889+
*/
2890+
{q{UniformHandle}, q{createUniform}, q{const(char)* name, bgfx.impl.UniformFreq.Enum freq, bgfx.impl.UniformType.Enum type, ushort num=1}, ext: `C++, "bgfx"`},
2891+
28512892
/**
28522893
* Retrieve uniform info.
28532894
Params:
@@ -3065,6 +3106,29 @@ mixin(joinFnBinds((){
30653106
*/
30663107
{q{void}, q{end}, q{Encoder* encoder}, ext: `C++, "bgfx"`},
30673108

3109+
/**
3110+
* Set shader uniform parameter for view.
3111+
* Attention: Uniform must be created with `bgfx::UniformFreq::View` argument.
3112+
Params:
3113+
id = View id.
3114+
handle = Uniform.
3115+
value = Pointer to uniform data.
3116+
num = Number of elements. Passing `UINT16_MAX` will
3117+
use the _num passed on uniform creation.
3118+
*/
3119+
{q{void}, q{setViewUniform}, q{ViewID id, UniformHandle handle, const(void)* value, ushort num=1}, ext: `C++, "bgfx"`},
3120+
3121+
/**
3122+
* Set shader uniform parameter for frame.
3123+
* Attention: Uniform must be created with `bgfx::UniformFreq::View` argument.
3124+
Params:
3125+
handle = Uniform.
3126+
value = Pointer to uniform data.
3127+
num = Number of elements. Passing `UINT16_MAX` will
3128+
use the _num passed on uniform creation.
3129+
*/
3130+
{q{void}, q{setFrameUniform}, q{UniformHandle handle, const(void)* value, ushort num=1}, ext: `C++, "bgfx"`},
3131+
30683132
/**
30693133
* Request screen shot of window back buffer.
30703134
* Remarks:

0 commit comments

Comments
 (0)