109
|
1 /**
|
|
2 * SceneGraph が増えてくると動かなくなるかもしれない。
|
|
3 * 一応 mainMem とかで動くようになるとは思うけど。
|
|
4 * だめだったら、そこら辺が怪しいと思うべき
|
|
5 */
|
|
6
|
|
7 #include "CreatePolygon.h"
|
|
8 #include "polygon_pack.h"
|
|
9 #include "scene_graph_pack.h"
|
|
10
|
|
11 SchedDefineTask(CreatePolygon);
|
|
12
|
|
13 #define SG_PACK_LOAD 10
|
|
14 #define SG_NODE_LOAD 11
|
|
15 #define PP_LOAD 12
|
|
16 #define PP_STORE 13
|
|
17
|
|
18 /**
|
|
19 * あとで直す
|
|
20 */
|
|
21 static void
|
|
22 rotate(float *xyz, float *matrix)
|
|
23 {
|
|
24 float abc[4];
|
|
25
|
|
26 abc[0] = xyz[0];
|
|
27 abc[1] = xyz[1];
|
|
28 abc[2] = xyz[2];
|
|
29 abc[3] = xyz[3];
|
|
30
|
|
31 for(int i=0; i<4; i++)
|
|
32 {
|
|
33 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12];
|
|
34 }
|
|
35 }
|
|
36
|
|
37 int
|
|
38 CreatePolygon::run(void *rbuf, void *wbuf)
|
|
39 {
|
|
40 float xyz1[4],xyz2[4],xyz3[4];
|
|
41
|
|
42 SceneGraphPackPtr sgp = (SceneGraphPack*)smanager->get_input(0);
|
|
43 SceneGraphPackPtr next_sgp =
|
|
44 (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack));
|
|
45 SceneGraphPackPtr free_sgp = next_sgp;
|
|
46 SceneGraphPackPtr tmp_sgp;
|
|
47
|
|
48 SceneGraphNodePtr node;
|
|
49 SceneGraphNodePtr next_node
|
|
50 = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode));
|
|
51 SceneGraphNodePtr free_node = next_node;
|
|
52 SceneGraphNodePtr tmp_node;
|
|
53
|
|
54 PolygonPackPtr pp
|
|
55 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack));
|
|
56 PolygonPackPtr send_pp
|
|
57 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack));
|
|
58 PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(0);
|
|
59 PolygonPackPtr tmp_pp;
|
|
60
|
|
61 pp->init();
|
|
62 send_pp->init();
|
|
63
|
|
64 do {
|
|
65 if (sgp->next != NULL) {
|
|
66 smanager->dma_load(next_sgp, (uint32)sgp->next,
|
|
67 sizeof(SceneGraphPack), SG_PACK_LOAD);
|
|
68 } else {
|
|
69 next_sgp = NULL;
|
|
70 }
|
|
71
|
|
72 for (int i = 0; i < sgp->info.size; i++) {
|
|
73 node = &sgp->node[i];
|
|
74
|
|
75 do {
|
|
76 if (node->next != NULL) {
|
|
77 smanager->dma_load(next_node, (uint32)node->next,
|
|
78 sizeof(SceneGraphNode), SG_NODE_LOAD);
|
|
79 } else {
|
|
80 next_node = NULL;
|
|
81 }
|
|
82
|
|
83 for (int n = 0, nt = 0; n < node->size*3; n+=9, nt+=6) {
|
|
84
|
|
85 if (pp->info.size >= MAX_SIZE_TRIANGLE) {
|
|
86 PolygonPackPtr next;
|
|
87
|
|
88 smanager->mainMem_alloc(0, sizeof(PolygonPack));
|
|
89 smanager->mainMem_wait();
|
|
90 next = (PolygonPackPtr)smanager->mainMem_get(0);
|
|
91
|
|
92 pp->next = next;
|
|
93
|
|
94 tmp_pp = pp;
|
|
95 pp = send_pp;
|
|
96 send_pp = tmp_pp;
|
|
97
|
|
98 smanager->dma_wait(PP_STORE);
|
|
99 smanager->dma_store(send_pp, (uint32)pp_addr,
|
|
100 sizeof(PolygonPack), PP_STORE);
|
|
101
|
|
102 pp_addr = next;
|
|
103
|
|
104 smanager->dma_wait(PP_LOAD);
|
|
105 smanager->dma_load(pp, (uint32)pp_addr,
|
|
106 sizeof(PolygonPack), PP_LOAD);
|
|
107 smanager->dma_wait(PP_LOAD);
|
|
108 pp->init();
|
|
109
|
|
110 }
|
|
111
|
|
112 TrianglePack *triangle = &pp->tri[pp->info.size++];
|
|
113
|
|
114 xyz1[0] = node->vertex[n];
|
|
115 xyz1[1] = node->vertex[n+1];
|
|
116 xyz1[2] = node->vertex[n+2]*-1;
|
|
117 xyz1[3] = 1;
|
|
118 xyz2[0] = node->vertex[n+3];
|
|
119 xyz2[1] = node->vertex[n+3+1];
|
|
120 xyz2[2] = node->vertex[n+3+2]*-1;
|
|
121 xyz2[3] = 1;
|
|
122 xyz3[0] = node->vertex[n+6];
|
|
123 xyz3[1] = node->vertex[n+6+1];
|
|
124 xyz3[2] = node->vertex[n+6+2]*-1;
|
|
125 xyz3[3] = 1;
|
|
126
|
|
127 rotate(xyz1, node->translation);
|
|
128 rotate(xyz2, node->translation);
|
|
129 rotate(xyz3, node->translation);
|
|
130
|
|
131 triangle->ver1.x = xyz1[0];
|
|
132 triangle->ver1.y = xyz1[1];
|
|
133 triangle->ver1.z = xyz1[2];
|
|
134 triangle->ver1.tex_x = node->texture[nt];
|
|
135 triangle->ver1.tex_y = node->texture[nt+1];
|
|
136
|
|
137 triangle->ver2.x = xyz2[0];
|
|
138 triangle->ver2.y = xyz2[1];
|
|
139 triangle->ver2.z = xyz2[2];
|
|
140 triangle->ver2.tex_x = node->texture[nt+2];
|
|
141 triangle->ver2.tex_y = node->texture[nt+2+1];
|
|
142
|
|
143 triangle->ver3.x = xyz3[0];
|
|
144 triangle->ver3.y = xyz3[1];
|
|
145 triangle->ver3.z = xyz3[2];
|
|
146 triangle->ver3.tex_x = node->texture[nt+4];
|
|
147 triangle->ver3.tex_y = node->texture[nt+4+1];
|
|
148
|
|
149 triangle->tex_addr = node->tex_addr;
|
|
150 triangle->tex_width = node->tex_width;
|
|
151 triangle->tex_height = node->tex_height;
|
|
152 }
|
|
153
|
|
154 smanager->dma_wait(SG_NODE_LOAD);
|
|
155
|
|
156 tmp_node = node;
|
|
157 node = next_node;
|
|
158 next_node = tmp_node;
|
|
159 } while (node);
|
|
160
|
|
161 next_node = free_node;
|
|
162 }
|
|
163
|
|
164 smanager->dma_wait(SG_PACK_LOAD);
|
|
165
|
|
166 tmp_sgp = sgp;
|
|
167 sgp = next_sgp;
|
|
168 next_sgp = tmp_sgp;
|
|
169 } while (sgp);
|
|
170
|
|
171 smanager->dma_wait(PP_STORE);
|
|
172 smanager->dma_store(pp, (uint32)pp_addr,
|
|
173 sizeof(PolygonPack), PP_STORE);
|
|
174 smanager->dma_wait(PP_STORE);
|
|
175
|
|
176 free(pp);
|
|
177 free(send_pp);
|
|
178 free(free_node);
|
|
179 free(free_sgp);
|
|
180
|
|
181 return 0;
|
|
182 }
|