Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | pmbaty | 1 | #include "dbsetup.h" |
2 | |||
3 | #include "CORE/FW/brbegin.h" |
||
4 | #include "CORE/FW/devsetup.h" |
||
5 | #include "CORE/FW/diag.h" |
||
6 | #include "CORE/FW/register.h" |
||
7 | #include "CORE/FW/resource.h" |
||
8 | #include "CORE/FW/resreg.h" |
||
9 | #include "CORE/STD/brstdlib.h" |
||
10 | #include "CORE/V1DB/def_mat.h" |
||
11 | #include "CORE/V1DB/def_mdl.h" |
||
12 | #include "CORE/V1DB/def_otab.h" |
||
13 | #include "CORE/V1DB/prepmap.h" |
||
14 | #include "CORE/V1DB/prepmatl.h" |
||
15 | #include "CORE/V1DB/prepmesh.h" |
||
16 | #include "CORE/V1DB/preptab.h" |
||
17 | #include "CORE/V1DB/regsupt.h" |
||
18 | #include "harness/hooks.h" |
||
19 | #include "harness/trace.h" |
||
20 | #include <stdio.h> |
||
21 | #include <string.h> |
||
22 | |||
23 | br_resource_class v1db_resourceClasses[14] = { |
||
24 | { 0u, "VERTICES", BR_MEMORY_VERTICES, NULL, 0u }, |
||
25 | { 0u, "FACES", BR_MEMORY_FACES, NULL, 0u }, |
||
26 | { 0u, "MODEL", BR_MEMORY_MODEL, NULL, 0u }, |
||
27 | { 0u, "MATERIAL", BR_MEMORY_MATERIAL, NULL, 0u }, |
||
28 | { 0u, "MATERIAL_INDEX", BR_MEMORY_MATERIAL_INDEX, NULL, 0u }, |
||
29 | { 0u, "ACTOR", BR_MEMORY_ACTOR, NULL, 0u }, |
||
30 | { 0u, "LIGHT", BR_MEMORY_LIGHT, NULL, 0u }, |
||
31 | { 0u, "CAMERA", BR_MEMORY_CAMERA, NULL, 0u }, |
||
32 | { 0u, "BOUNDS", BR_MEMORY_BOUNDS, NULL, 0u }, |
||
33 | { 0u, "CLIP_PLANE", BR_MEMORY_CLIP_PLANE, NULL, 0u }, |
||
34 | { 0u, "TRANSFORM", BR_MEMORY_TRANSFORM, NULL, 0u }, |
||
35 | { 0u, "ENABLED_ACTORS", BR_MEMORY_ENABLED_ACTORS, NULL, 0u }, |
||
36 | { 0u, "PREPARED_MODEL", BR_MEMORY_PREPARED_MODEL, NULL, 32u }, |
||
37 | { 0u, "ORDER_TABLE", BR_MEMORY_ORDER_TABLE, NULL, 32u } |
||
38 | }; |
||
39 | |||
40 | br_v1db_state v1db; |
||
41 | |||
42 | // IDA: br_error __cdecl BrV1dbBegin() |
||
43 | br_error BrV1dbBegin(void) { |
||
44 | //char* devstr; // Pierre-Marie Baty -- unused variable |
||
45 | //br_size_t s; // Pierre-Marie Baty -- unused variable |
||
46 | int i; |
||
47 | |||
48 | if (v1db.active) { |
||
49 | return 4103; |
||
50 | } |
||
51 | |||
52 | BrMemSet(&v1db, 0, sizeof(br_v1db_state)); |
||
53 | v1db.active = 1; |
||
54 | BrRegistryNew(&v1db.reg_models); |
||
55 | BrRegistryNew(&v1db.reg_materials); |
||
56 | BrRegistryNew(&v1db.reg_textures); |
||
57 | BrRegistryNew(&v1db.reg_tables); |
||
58 | v1db.res = BrResAllocate(NULL, 0, BR_MEMORY_ANCHOR); |
||
59 | |||
60 | for (i = 0; i < BR_ASIZE(v1db_resourceClasses); i++) { |
||
61 | BrResClassAdd(&v1db_resourceClasses[i]); |
||
62 | } |
||
63 | |||
64 | v1db.default_model = BrResAllocate(v1db.res, sizeof(br_model), BR_MEMORY_MODEL); |
||
65 | memcpy(v1db.default_model, &_BrDefaultModel, sizeof(br_model)); |
||
66 | v1db.default_material = SetupDefaultMaterial(); |
||
67 | v1db.enabled_lights.max = 16; |
||
68 | v1db.enabled_lights.type = BR_ACTOR_LIGHT; |
||
69 | v1db.enabled_lights.name = "light"; |
||
70 | v1db.enabled_clip_planes.max = 6; |
||
71 | v1db.enabled_clip_planes.type = BR_ACTOR_CLIP_PLANE; |
||
72 | v1db.enabled_clip_planes.name = "clip plane"; |
||
73 | v1db.enabled_horizon_planes.max = 6; |
||
74 | v1db.enabled_horizon_planes.type = BR_ACTOR_HORIZONTAL_PLANE; |
||
75 | v1db.enabled_horizon_planes.name = "horizon plane"; |
||
76 | return 0; |
||
77 | } |
||
78 | |||
79 | // IDA: br_error __cdecl BrV1dbEnd() |
||
80 | br_error BrV1dbEnd(void) { |
||
81 | //br_device* dev; // Pierre-Marie Baty -- unused variable |
||
82 | LOG_TRACE("()"); |
||
83 | |||
84 | if (v1db.active == 0) { |
||
85 | return 4102; |
||
86 | } |
||
87 | v1db.active = 0; |
||
88 | BrResFree(v1db.res); |
||
89 | BrMemSet(&v1db, 0, sizeof(v1db)); |
||
90 | return 0; |
||
91 | } |
||
92 | |||
93 | // IDA: br_uint_32 __cdecl updateTable(br_pixelmap *item, void *arg) |
||
94 | br_uint_32 updateTable(br_pixelmap* item, void* arg) { |
||
95 | LOG_TRACE("(%p, %p)", item, arg); |
||
96 | |||
97 | BrTableUpdate(item, BR_TABU_ALL); |
||
98 | return 0; // Pierre-Marie Baty -- function must return a value |
||
99 | } |
||
100 | |||
101 | // IDA: br_uint_32 __cdecl updateMap(br_pixelmap *item, void *arg) |
||
102 | br_uint_32 updateMap(br_pixelmap* item, void* arg) { |
||
103 | LOG_TRACE("(%p, %p)", item, arg); |
||
104 | |||
105 | BrMapUpdate(item, BR_MAPU_ALL); |
||
106 | return 0; // Pierre-Marie Baty -- function must return a value |
||
107 | } |
||
108 | |||
109 | // IDA: br_uint_32 __cdecl updateMaterial(br_material *item, void *arg) |
||
110 | br_uint_32 updateMaterial(br_material* item, void* arg) { |
||
111 | LOG_TRACE("(%p, %p)", item, arg); |
||
112 | |||
113 | BrMaterialUpdate(item, BR_MATU_ALL); |
||
114 | return 0; // Pierre-Marie Baty -- function must return a value |
||
115 | } |
||
116 | |||
117 | // IDA: br_uint_32 __cdecl updateModel(br_model *item, void *arg) |
||
118 | br_uint_32 updateModel(br_model* item, void* arg) { |
||
119 | LOG_TRACE("(%p, %p)", item, arg); |
||
120 | NOT_IMPLEMENTED(); |
||
121 | return 0; // Pierre-Marie Baty -- function must return a value |
||
122 | } |
||
123 | |||
124 | // IDA: br_uint_32 __cdecl clearTable(br_pixelmap *item, void *arg) |
||
125 | br_uint_32 clearTable(br_pixelmap* item, void* arg) { |
||
126 | LOG_TRACE("(%p, %p)", item, arg); |
||
127 | |||
128 | BrBufferClear(item); |
||
129 | return 0; // Pierre-Marie Baty -- function must return a value |
||
130 | } |
||
131 | |||
132 | // IDA: br_uint_32 __cdecl clearMap(br_pixelmap *item, void *arg) |
||
133 | br_uint_32 clearMap(br_pixelmap* item, void* arg) { |
||
134 | LOG_TRACE("(%p, %p)", item, arg); |
||
135 | |||
136 | BrBufferClear(item); |
||
137 | return 0; // Pierre-Marie Baty -- function must return a value |
||
138 | } |
||
139 | |||
140 | // IDA: br_uint_32 __cdecl clearMaterial(br_material *item, void *arg) |
||
141 | br_uint_32 clearMaterial(br_material* item, void* arg) { |
||
142 | LOG_TRACE("(%p, %p)", item, arg); |
||
143 | |||
144 | BrMaterialClear(item); |
||
145 | return 0; // Pierre-Marie Baty -- function must return a value |
||
146 | } |
||
147 | |||
148 | // IDA: br_uint_32 __cdecl clearModel(br_model *item, void *arg) |
||
149 | br_uint_32 clearModel(br_model* item, void* arg) { |
||
150 | LOG_TRACE("(%p, %p)", item, arg); |
||
151 | |||
152 | BrModelClear(item); |
||
153 | return 0; // Pierre-Marie Baty -- function must return a value |
||
154 | } |
||
155 | |||
156 | // IDA: br_error __cdecl BrV1dbRendererBegin(br_device_pixelmap *destination, br_renderer *renderer) |
||
157 | br_error BrV1dbRendererBegin(br_device_pixelmap* destination, br_renderer* renderer) { |
||
158 | br_renderer_facility* renderer_facility; |
||
159 | br_error r; |
||
160 | br_token_value tv[2]; |
||
161 | LOG_TRACE("(%p, %p)", destination, renderer); |
||
162 | |||
163 | Harness_Hook_BrV1dbRendererBegin(&v1db); |
||
164 | return 0; |
||
165 | |||
166 | // FIXME: use this logic once the clouds clear up |
||
167 | renderer_facility = NULL; |
||
168 | tv[0].t = 0; |
||
169 | tv[0].v.u32 = 0; |
||
170 | tv[1].t = 0; |
||
171 | tv[1].v.u32 = 0; |
||
172 | |||
173 | if (renderer == NULL) { |
||
174 | r = BrRendererFacilityFind(&renderer_facility, destination, BRT_FLOAT); |
||
175 | if (r != 0) { |
||
176 | return r; |
||
177 | } |
||
178 | if (destination != NULL) { |
||
179 | tv[0].t = BRT_DESTINATION_O; |
||
180 | tv[0].v.o = (br_object*)destination; |
||
181 | } |
||
182 | r = (*(br_renderer_facility_dispatch**)renderer_facility)->_rendererNew(renderer_facility, &renderer, tv); |
||
183 | if (r != 0) { |
||
184 | return r; |
||
185 | } |
||
186 | } |
||
187 | v1db.renderer = renderer; |
||
188 | r = BrGeometryFormatFind(&v1db.format_model, renderer, renderer_facility, BRT_FLOAT, BRT_GEOMETRY_V1_MODEL); |
||
189 | if (r != 0) { |
||
190 | return r; |
||
191 | } |
||
192 | r = BrGeometryFormatFind(&v1db.format_buckets, renderer, renderer_facility, BRT_FLOAT, BRT_GEOMETRY_V1_BUCKETS); |
||
193 | if (r != 0) { |
||
194 | return r; |
||
195 | } |
||
196 | r = BrGeometryFormatFind((br_geometry**)&v1db.format_lighting, renderer, renderer_facility, BRT_FLOAT, BRT_GEOMETRY_LIGHTING); |
||
197 | if (r != 0) { |
||
198 | return r; |
||
199 | } |
||
200 | BrModelUpdate(v1db.default_model, BR_MODU_ALL); |
||
201 | v1db.default_order_table = &_BrDefaultOrderTable; |
||
202 | v1db.primary_order_table = NULL; |
||
203 | BrTableEnum(NULL, updateTable, NULL); |
||
204 | BrMapEnum(NULL, updateMap, NULL); |
||
205 | BrMaterialEnum(NULL, updateMaterial, NULL); |
||
206 | BrMaterialUpdate(v1db.default_material, BR_MATU_ALL); |
||
207 | BrMaterialUpdate(v1db.default_material, BR_MATU_ALL); |
||
208 | return 0; |
||
209 | } |
||
210 | |||
211 | // IDA: br_renderer* __cdecl BrV1dbRendererQuery() |
||
212 | br_renderer* BrV1dbRendererQuery(void) { |
||
213 | LOG_TRACE("()"); |
||
214 | |||
215 | return v1db.renderer; |
||
216 | } |
||
217 | |||
218 | // IDA: br_error __cdecl BrV1dbRendererEnd() |
||
219 | br_error BrV1dbRendererEnd(void) { |
||
220 | LOG_TRACE("()"); |
||
221 | |||
222 | BrTableEnum(NULL, clearTable, NULL); |
||
223 | BrMapEnum(NULL, clearMap, NULL); |
||
224 | BrMaterialEnum(NULL, clearMaterial, NULL); |
||
225 | BrModelEnum(NULL, clearModel, NULL); |
||
226 | BrMaterialClear(v1db.default_material); |
||
227 | BrModelClear(v1db.default_model); |
||
228 | v1db.default_order_table = NULL; |
||
229 | v1db.default_render_data = NULL; |
||
230 | v1db.primary_order_table = NULL; |
||
231 | v1db.format_model = NULL; |
||
232 | v1db.renderer->dispatch->_free((br_object*)v1db.renderer); |
||
233 | v1db.renderer = NULL; |
||
234 | return 0; // Pierre-Marie Baty -- function must return a value |
||
235 | } |
||
236 | |||
237 | // IDA: void __cdecl BrZbBegin(br_uint_8 colour_type, br_uint_8 depth_type) |
||
238 | void BrZbBegin(br_uint_8 colour_type, br_uint_8 depth_type) { |
||
239 | LOG_TRACE("(%d, %d)", colour_type, depth_type); |
||
240 | |||
241 | if (v1db.zs_active == 0 && v1db.zb_active == 0) { |
||
242 | if (BrV1dbRendererBegin((br_device_pixelmap*)BrDevLastBeginQuery(), NULL) != 0) { |
||
243 | BrFailure("Failed to load renderer\n"); |
||
244 | } |
||
245 | } |
||
246 | v1db.zb_active = 1; |
||
247 | } |
||
248 | |||
249 | // IDA: void __cdecl BrZsBegin(br_uint_8 colour_type, void *primitive, br_uint_32 size) |
||
250 | void BrZsBegin(br_uint_8 colour_type, void* primitive, br_uint_32 size) { |
||
251 | LOG_TRACE("(%d, %p, %d)", colour_type, primitive, size); |
||
252 | |||
253 | if (v1db.zs_active == 0 && v1db.zb_active == 0) { |
||
254 | if (BrV1dbRendererBegin((br_device_pixelmap*)BrDevLastBeginQuery(), NULL) != 0) { |
||
255 | BrFailure("Failed to load renderer\n"); |
||
256 | } |
||
257 | } |
||
258 | v1db.zs_active = 1; |
||
259 | v1db.heap.base = primitive; |
||
260 | v1db.heap.size = size; |
||
261 | } |
||
262 | |||
263 | // IDA: void __cdecl BrZbEnd() |
||
264 | void BrZbEnd(void) { |
||
265 | LOG_TRACE("()"); |
||
266 | |||
267 | v1db.zb_active = 0; |
||
268 | if (v1db.zs_active == 0 && v1db.renderer != NULL) { |
||
269 | BrV1dbRendererEnd(); |
||
270 | } |
||
271 | } |
||
272 | |||
273 | // IDA: void __cdecl BrZsEnd() |
||
274 | void BrZsEnd(void) { |
||
275 | LOG_TRACE("()"); |
||
276 | |||
277 | v1db.zs_active = 0; |
||
278 | if (v1db.zb_active == 0 && v1db.renderer != NULL) { |
||
279 | BrV1dbRendererEnd(); |
||
280 | } |
||
281 | } |
||
282 | |||
283 | // IDA: void __cdecl BrV1dbBeginWrapper_Float() |
||
284 | void BrV1dbBeginWrapper_Float(void) { |
||
285 | BrBegin(); |
||
286 | BrV1dbBegin(); |
||
287 | } |
||
288 | |||
289 | // IDA: void __cdecl BrV1dbEndWrapper() |
||
290 | void BrV1dbEndWrapper(void) { |
||
291 | LOG_TRACE("()"); |
||
292 | NOT_IMPLEMENTED(); |
||
293 | } |