Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | #include "renderer_impl.h" |
2 | #include "include/harness/trace.h" |
||
3 | #include <stddef.h> |
||
4 | |||
5 | // Provides a harness-specific implementation of the Brender br_renderer* interface |
||
6 | |||
7 | extern void* BrResAllocate(void* vparent, br_size_t size, br_uint_8 res_class); |
||
8 | extern void BrMatrix34Mul(br_matrix34* A, br_matrix34* B, br_matrix34* C); |
||
9 | |||
10 | struct state_all default_state = { |
||
11 | NULL, |
||
12 | { { { BR_VECTOR3(1, 0, 0), /* model_to_view */ |
||
13 | BR_VECTOR3(0, 1, 0), |
||
14 | BR_VECTOR3(0, 0, 1), |
||
15 | BR_VECTOR3(0, 0, 0) } }, |
||
16 | |||
17 | { { BR_VECTOR4(1, 0, 0, 0), /* view_to_screen */ |
||
18 | BR_VECTOR4(0, 1, 0, 0), |
||
19 | BR_VECTOR4(0, 0, 1, 0), |
||
20 | BR_VECTOR4(0, 0, 0, 1) } }, |
||
21 | |||
22 | { { BR_VECTOR3(1, 0, 0), /* view_to_environment */ |
||
23 | BR_VECTOR3(0, 1, 0), |
||
24 | BR_VECTOR3(0, 0, 1), |
||
25 | BR_VECTOR3(0, 0, 0) } }, |
||
26 | 0, |
||
27 | |||
28 | }; |
||
29 | |||
30 | static struct br_renderer_dispatch dispatch_table; |
||
31 | |||
32 | br_error StateCopy(struct state_all* dest, struct state_all* src, br_uint_32 copy_mask, void* res) { |
||
33 | if (copy_mask & BR_STATE_MATRIX) { |
||
34 | dest->matrix = src->matrix; |
||
35 | } |
||
36 | return 0; |
||
37 | } |
||
38 | |||
39 | br_error modelMulF(struct br_renderer* r, br_matrix34_f* m) { |
||
40 | harness_br_renderer* self = (harness_br_renderer*)r; |
||
41 | br_matrix34 om = self->state.matrix.model_to_view; |
||
42 | |||
43 | BrMatrix34Mul(&self->state.matrix.model_to_view, (br_matrix34*)m, &om); |
||
44 | |||
45 | // TouchModelToView(self); |
||
46 | return 0; |
||
47 | } |
||
48 | |||
49 | br_error statePush(struct br_renderer* r, br_uint_32 mask) { |
||
50 | harness_br_renderer* self = (harness_br_renderer*)r; |
||
51 | struct state_all* sp; |
||
52 | |||
53 | if (self->stack_top >= MAX_STATE_STACK) { |
||
54 | LOG_PANIC("state stack overflow!"); |
||
55 | } |
||
56 | |||
57 | sp = self->state_stack + self->stack_top; |
||
58 | self->stack_top++; |
||
59 | return StateCopy(sp, &self->state, mask, self); |
||
60 | } |
||
61 | |||
62 | br_error statePop(struct br_renderer* r, br_uint_32 mask) { |
||
63 | harness_br_renderer* self = (harness_br_renderer*)r; |
||
64 | br_error result; |
||
65 | struct state_all* sp; |
||
66 | |||
67 | if (self->stack_top <= 0) { |
||
68 | LOG_PANIC("state stack underflow!"); |
||
69 | } |
||
70 | |||
71 | self->stack_top--; |
||
72 | sp = self->state_stack + self->stack_top; |
||
73 | result = StateCopy(&self->state, sp, mask, self); |
||
74 | return result; |
||
75 | } |
||
76 | |||
77 | br_error stateDefault(struct br_renderer* r, br_uint_32 mask) { |
||
78 | harness_br_renderer* self = (harness_br_renderer*)r; |
||
79 | return StateCopy(&self->state, self->default_state, mask, self); |
||
80 | } |
||
81 | |||
82 | harness_br_renderer* NewHarnessBrRenderer(void) { |
||
83 | |||
84 | harness_br_renderer* self; |
||
85 | |||
86 | self = BrResAllocate(NULL, sizeof(*self), BR_MEMORY_OBJECT); |
||
87 | |||
88 | if (self == NULL) { |
||
89 | return NULL; |
||
90 | } |
||
91 | |||
92 | dispatch_table._modelMulF = &modelMulF; |
||
93 | dispatch_table._statePush = &statePush; |
||
94 | dispatch_table._statePop = &statePop; |
||
95 | |||
96 | self->default_state = &default_state; |
||
97 | stateDefault((br_renderer*)self, BR_STATE_ALL); |
||
98 | |||
99 | self->dispatch = &dispatch_table; |
||
100 | self->identifier = "harness_renderer_state"; |
||
101 | return self; |
||
102 | // self->device = device; |
||
103 | // self->renderer_facility = facility; |
||
104 | } |