Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/spe/CreatePolygon.cpp @ 266:5c9dbd54cd51
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 04 Jun 2009 00:00:09 +0900 |
parents | 559b48b69b76 |
children | 59c3b9df3c67 |
rev | line source |
---|---|
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 | |
146 | 149 #if 1 |
174
559b48b69b76
getScale()、getTapestry から、span->length に適切なテクスチャの選択に成功
gongo@localhost.localdomain
parents:
146
diff
changeset
|
150 triangle->tex_info.addr = node->tex_addr; |
559b48b69b76
getScale()、getTapestry から、span->length に適切なテクスチャの選択に成功
gongo@localhost.localdomain
parents:
146
diff
changeset
|
151 triangle->tex_info.width = node->tex_width; |
559b48b69b76
getScale()、getTapestry から、span->length に適切なテクスチャの選択に成功
gongo@localhost.localdomain
parents:
146
diff
changeset
|
152 triangle->tex_info.height = node->tex_height; |
141 | 153 #else |
174
559b48b69b76
getScale()、getTapestry から、span->length に適切なテクスチャの選択に成功
gongo@localhost.localdomain
parents:
146
diff
changeset
|
154 triangle->tex_info.addr = node->texture_info.pixels; |
559b48b69b76
getScale()、getTapestry から、span->length に適切なテクスチャの選択に成功
gongo@localhost.localdomain
parents:
146
diff
changeset
|
155 triangle->tex_info.width = node->texture_info.t_w; |
559b48b69b76
getScale()、getTapestry から、span->length に適切なテクスチャの選択に成功
gongo@localhost.localdomain
parents:
146
diff
changeset
|
156 triangle->tex_info.height = node->texture_info.t_h; |
141 | 157 #endif |
109 | 158 } |
159 | |
160 smanager->dma_wait(SG_NODE_LOAD); | |
161 | |
162 tmp_node = node; | |
163 node = next_node; | |
164 next_node = tmp_node; | |
165 } while (node); | |
166 | |
167 next_node = free_node; | |
168 } | |
169 | |
170 smanager->dma_wait(SG_PACK_LOAD); | |
171 | |
172 tmp_sgp = sgp; | |
173 sgp = next_sgp; | |
174 next_sgp = tmp_sgp; | |
175 } while (sgp); | |
176 | |
177 smanager->dma_wait(PP_STORE); | |
178 smanager->dma_store(pp, (uint32)pp_addr, | |
179 sizeof(PolygonPack), PP_STORE); | |
180 smanager->dma_wait(PP_STORE); | |
181 | |
182 free(pp); | |
183 free(send_pp); | |
184 free(free_node); | |
185 free(free_sgp); | |
186 | |
187 return 0; | |
188 } |