comparison Renderer/Engine/spe/CreatePolygon.cc @ 507:735f76483bb2

Reorganization..
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 12 Oct 2009 09:39:35 +0900
parents
children
comparison
equal deleted inserted replaced
506:1d4a8a86f26b 507:735f76483bb2
1 /**
2 * SceneGraph が増えてくると動かなくなるかもしれない。
3 * 一応 mainMem とかで動くようになるとは思うけど。
4 * だめだったら、そこら辺が怪しいと思うべき
5 */
6
7 // #define DEBUG
8 #include "error.h"
9
10 #include "CreatePolygon.h"
11 #include "polygon_pack.h"
12 #include "scene_graph_pack.h"
13
14 SchedDefineTask(CreatePolygon);
15
16 #define SG_PACK_LOAD 10
17 #define SG_NODE_LOAD 11
18 #define PP_LOAD 12
19 #define PP_STORE 13
20
21 /**
22 * あとで直す
23 */
24 static void
25 rotate(float *xyz, float *matrix)
26 {
27 float abc[4];
28
29 abc[0] = xyz[0];
30 abc[1] = xyz[1];
31 abc[2] = xyz[2];
32 abc[3] = xyz[3];
33
34 for(int i=0; i<4; i++)
35 {
36 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12];
37 }
38 }
39
40 static int
41 run(SchedTask *smanager,void *rbuf, void *wbuf)
42 {
43 smanager->__debug_spe("CreatePolygon\n");
44
45 float xyz1[4],xyz2[4],xyz3[4];
46
47 SceneGraphPackPtr sgp = (SceneGraphPack*)smanager->get_input(0);
48 SceneGraphPackPtr next_sgp =
49 (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack));
50 SceneGraphPackPtr free_sgp = next_sgp;
51 SceneGraphPackPtr tmp_sgp;
52
53 SceneGraphNodePtr node;
54 SceneGraphNodePtr next_node
55 = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode));
56 SceneGraphNodePtr free_node = next_node;
57 SceneGraphNodePtr tmp_node;
58
59 PolygonPackPtr pp
60 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack));
61 PolygonPackPtr send_pp
62 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack));
63 PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(0);
64 PolygonPackPtr tmp_pp;
65
66 pp->init();
67 send_pp->init();
68
69 do {
70 if (sgp->next != NULL) {
71 smanager->dma_load(next_sgp, (uint32)sgp->next,
72 sizeof(SceneGraphPack), SG_PACK_LOAD);
73 } else {
74 next_sgp = NULL;
75 }
76
77 for (int i = 0; i < sgp->info.size; i++) {
78 node = &sgp->node[i];
79
80 do {
81 if (node->next != NULL) {
82 smanager->dma_load(next_node, (uint32)node->next,
83 sizeof(SceneGraphNode), SG_NODE_LOAD);
84 } else {
85 next_node = NULL;
86 }
87
88 for (int n = 0, nt = 0; n < node->size*3; n+=9, nt+=6) {
89
90 if (pp->info.size >= MAX_SIZE_TRIANGLE) {
91 PolygonPackPtr next;
92
93 // smanager から Task を作る、0 ではなく PolygonPack->task_id が良い
94 smanager->mainMem_alloc(0, sizeof(PolygonPack));
95 smanager->mainMem_wait();
96 next = (PolygonPackPtr)smanager->mainMem_get(0);
97
98 pp->next = next; // この部分は TaskManager 側でやるべき
99
100 tmp_pp = pp;
101 pp = send_pp;
102 send_pp = tmp_pp;
103
104 smanager->dma_wait(PP_STORE);
105 smanager->dma_store(send_pp, (uint32)pp_addr,
106 sizeof(PolygonPack), PP_STORE);
107
108 pp_addr = next;
109
110 smanager->dma_wait(PP_LOAD); // 多分不要
111 smanager->dma_load(pp, (uint32)pp_addr,
112 sizeof(PolygonPack), PP_LOAD);
113 // 次の dma_wait のコストが高いのでパイプラインで隠す必要がある
114
115 smanager->dma_wait(PP_LOAD);
116 pp->init();
117
118 }
119
120 TrianglePack *triangle = &pp->tri[pp->info.size++];
121
122 xyz1[0] = node->vertex[n];
123 xyz1[1] = node->vertex[n+1];
124 xyz1[2] = node->vertex[n+2]*-1;
125 xyz1[3] = 1;
126 xyz2[0] = node->vertex[n+3];
127 xyz2[1] = node->vertex[n+3+1];
128 xyz2[2] = node->vertex[n+3+2]*-1;
129 xyz2[3] = 1;
130 xyz3[0] = node->vertex[n+6];
131 xyz3[1] = node->vertex[n+6+1];
132 xyz3[2] = node->vertex[n+6+2]*-1;
133 xyz3[3] = 1;
134
135 rotate(xyz1, node->translation);
136 rotate(xyz2, node->translation);
137 rotate(xyz3, node->translation);
138
139 triangle->ver1.x = xyz1[0];
140 triangle->ver1.y = xyz1[1];
141 triangle->ver1.z = xyz1[2];
142 triangle->ver1.tex_x = node->texture[nt];
143 triangle->ver1.tex_y = node->texture[nt+1];
144
145 triangle->ver2.x = xyz2[0];
146 triangle->ver2.y = xyz2[1];
147 triangle->ver2.z = xyz2[2];
148 triangle->ver2.tex_x = node->texture[nt+2];
149 triangle->ver2.tex_y = node->texture[nt+2+1];
150
151 triangle->ver3.x = xyz3[0];
152 triangle->ver3.y = xyz3[1];
153 triangle->ver3.z = xyz3[2];
154 triangle->ver3.tex_x = node->texture[nt+4];
155 triangle->ver3.tex_y = node->texture[nt+4+1];
156
157 #if 1
158 triangle->tex_info.addr = node->tex_addr;
159 triangle->tex_info.width = node->tex_width;
160 triangle->tex_info.height = node->tex_height;
161 #else
162 triangle->tex_info.addr = node->texture_info.pixels;
163 triangle->tex_info.width = node->texture_info.t_w;
164 triangle->tex_info.height = node->texture_info.t_h;
165 #endif
166 }
167
168 smanager->dma_wait(SG_NODE_LOAD);
169
170 tmp_node = node;
171 node = next_node;
172 next_node = tmp_node;
173 } while (node);
174
175 next_node = free_node;
176 }
177
178 smanager->dma_wait(SG_PACK_LOAD);
179
180 tmp_sgp = sgp;
181 sgp = next_sgp;
182 next_sgp = tmp_sgp;
183 } while (sgp);
184
185 smanager->dma_wait(PP_STORE);
186 smanager->dma_store(pp, (uint32)pp_addr,
187 sizeof(PolygonPack), PP_STORE);
188 smanager->dma_wait(PP_STORE);
189
190 free(pp);
191 free(send_pp);
192 free(free_node);
193 free(free_sgp);
194
195 return 0;
196 }