Kore
Loading...
Searching...
No Matches
constantbuffer.c.h
1#include "constantbuffer.h"
2
3void kinc_g5_constant_buffer_set_int(kinc_g5_constant_buffer_t *buffer, int offset, int value) {
4 int *ints = (int *)(&buffer->data[offset]);
5 ints[0] = value;
6}
7
8void kinc_g5_constant_buffer_set_int2(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2) {
9 int *ints = (int *)(&buffer->data[offset]);
10 ints[0] = value1;
11 ints[1] = value2;
12}
13
14void kinc_g5_constant_buffer_set_int3(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3) {
15 int *ints = (int *)(&buffer->data[offset]);
16 ints[0] = value1;
17 ints[1] = value2;
18 ints[2] = value3;
19}
20
21void kinc_g5_constant_buffer_set_int4(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3, int value4) {
22 int *ints = (int *)(&buffer->data[offset]);
23 ints[0] = value1;
24 ints[1] = value2;
25 ints[2] = value3;
26 ints[3] = value4;
27}
28
29void kinc_g5_constant_buffer_set_ints(kinc_g5_constant_buffer_t *buffer, int offset, int *values, int count) {
30 int *ints = (int *)(&buffer->data[offset]);
31 for (int i = 0; i < count; ++i) {
32 ints[i] = values[i];
33 }
34}
35
36void kinc_g5_constant_buffer_set_float(kinc_g5_constant_buffer_t *buffer, int offset, float value) {
37 float *floats = (float *)(&buffer->data[offset]);
38 floats[0] = value;
39}
40
41void kinc_g5_constant_buffer_set_float2(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2) {
42 float *floats = (float *)(&buffer->data[offset]);
43 floats[0] = value1;
44 floats[1] = value2;
45}
46
47void kinc_g5_constant_buffer_set_float3(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3) {
48 float *floats = (float *)(&buffer->data[offset]);
49 floats[0] = value1;
50 floats[1] = value2;
51 floats[2] = value3;
52}
53
54void kinc_g5_constant_buffer_set_float4(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3, float value4) {
55 float *floats = (float *)(&buffer->data[offset]);
56 floats[0] = value1;
57 floats[1] = value2;
58 floats[2] = value3;
59 floats[3] = value4;
60}
61
62void kinc_g5_constant_buffer_set_floats(kinc_g5_constant_buffer_t *buffer, int offset, float *values, int count) {
63 float *floats = (float *)(&buffer->data[offset]);
64 for (int i = 0; i < count; ++i) {
65 floats[i] = values[i];
66 }
67}
68
69void kinc_g5_constant_buffer_set_bool(kinc_g5_constant_buffer_t *buffer, int offset, bool value) {
70 int *ints = (int *)(&buffer->data[offset]);
71 ints[0] = value ? 1 : 0;
72}
73
74static void set_matrix3(uint8_t *constants, int offset, kinc_matrix3x3_t *value) {
75 float *floats = (float *)(&constants[offset]);
76 for (int y = 0; y < 3; ++y) {
77 for (int x = 0; x < 3; ++x) {
78 floats[x + y * 4] = kinc_matrix3x3_get(value, x, y);
79 }
80 }
81}
82
83void kinc_g5_constant_buffer_set_matrix3(kinc_g5_constant_buffer_t *buffer, int offset, kinc_matrix3x3_t *value) {
84 if (kinc_g5_transposeMat3) {
85 kinc_matrix3x3_t m = *value;
86 kinc_matrix3x3_transpose(&m);
87 set_matrix3(buffer->data, offset, &m);
88 }
89 else {
90 set_matrix3(buffer->data, offset, value);
91 }
92}
93
94static void set_matrix4(uint8_t *constants, int offset, kinc_matrix4x4_t *value) {
95 float *floats = (float *)(&constants[offset]);
96 for (int y = 0; y < 4; ++y) {
97 for (int x = 0; x < 4; ++x) {
98 floats[x + y * 4] = kinc_matrix4x4_get(value, x, y);
99 }
100 }
101}
102
103void kinc_g5_constant_buffer_set_matrix4(kinc_g5_constant_buffer_t *buffer, int offset, kinc_matrix4x4_t *value) {
104 if (kinc_g5_transposeMat4) {
105 kinc_matrix4x4_t m = *value;
106 kinc_matrix4x4_transpose(&m);
107 set_matrix4(buffer->data, offset, &m);
108 }
109 else {
110 set_matrix4(buffer->data, offset, value);
111 }
112}
Provides support for managing buffers of constant-data for shaders.