Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/spe/CreatePolygonFromSceneGraph.cc @ 1026:55f3c5976959
create_pp_task fix.
author | tkaito |
---|---|
date | Tue, 09 Nov 2010 18:14:28 +0900 |
parents | 736a833db108 |
children |
rev | line source |
---|---|
1013 | 1 /** |
2 * SceneGraph が増えてくると動かなくなるかもしれない。 | |
3 * 一応 mainMem とかで動くようになるとは思うけど。 | |
4 * だめだったら、そこら辺が怪しいと思うべき | |
5 */ | |
6 | |
7 #include "CreatePolygonFromSceneGraph.h" | |
8 #include "polygon_pack.h" | |
9 #include "scene_graph_pack.h" | |
10 | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
11 SchedDefineTask1(CreatePolygonFromSceneGraph, createPolygonFromSceneGraph); |
1013 | 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 * @param[out] v vector (float[4]) | |
21 * @param[in] m matrix (float[16]) | |
22 */ | |
23 static void | |
24 ApplyMatrix(float *v, float *m) | |
25 { | |
26 float t[4]; | |
27 | |
28 t[0] = v[0]; | |
29 t[1] = v[1]; | |
30 t[2] = v[2]; | |
31 t[3] = v[3]; | |
32 | |
33 for (int i = 0; i < 4; i++) { | |
34 v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12]; | |
35 } | |
36 } | |
37 | |
38 static void | |
39 ApplyNormalMatrix(float *v, float *m) | |
40 { | |
41 float t[4]; | |
42 | |
43 t[0] = v[0]; | |
44 t[1] = v[1]; | |
45 t[2] = v[2]; | |
46 | |
47 for (int i = 0; i < 3; i++) { | |
48 v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8]; | |
49 } | |
50 } | |
51 | |
52 static int | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
53 createPolygonFromSceneGraph(SchedTask *smanager, void *rbuf, void *wbuf) |
1013 | 54 { |
55 float xyz1[4], xyz2[4], xyz3[4]; | |
56 float normal1[4],normal2[4],normal3[4]; | |
57 | |
58 //coord_xyz, coord_tex, normal, matrix, real_matrix を受け取る | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
59 float *coord_xyz = (float*)smanager->get_input(rbuf, 0); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
60 float *coord_tex = (float*)smanager->get_input(rbuf, 1); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
61 float *normal = (float*)smanager->get_input(rbuf, 2); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
62 float *matrix = (float*)smanager->get_input(rbuf, 3); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
63 float *real_matrix = (float*)smanager->get_input(rbuf, 4); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
64 uint32 *pixels = (uint32*)smanager->get_input(rbuf, 5); |
1013 | 65 |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
66 int sg_size = (int)smanager->get_param(0); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
67 int width = (int)smanager->get_param(1); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
68 int height = (int)smanager->get_param(2); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
69 int scale_max = (int)smanager->get_param(3); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
70 |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
71 // triangle を書き戻す |
1026 | 72 //TrianglePackPtr triangle = (TrianglePackPtr)smanager->get_output(wbuf, 0); |
73 | |
74 PolygonPackPtr pp | |
75 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); | |
76 PolygonPackPtr send_pp | |
77 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); | |
78 PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(1); | |
79 PolygonPackPtr tmp_pp; | |
80 | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
81 |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
82 for (int i = 0; i < sg_size; i += 3) { |
1026 | 83 if (pp->info.size >= MAX_SIZE_TRIANGLE) { |
84 PolygonPackPtr next; | |
85 | |
86 smanager->mainMem_alloc(0, sizeof(PolygonPack)); | |
87 smanager->mainMem_wait(); | |
88 next = (PolygonPackPtr)smanager->mainMem_get(0); | |
89 | |
90 pp->next = next; | |
91 | |
92 tmp_pp = pp; | |
93 pp = send_pp; | |
94 send_pp = tmp_pp; | |
95 | |
96 smanager->dma_wait(PP_STORE); | |
97 smanager->dma_store(send_pp, (memaddr)pp_addr, | |
98 sizeof(PolygonPack), PP_STORE); | |
99 | |
100 pp_addr = next; | |
101 | |
102 smanager->dma_wait(PP_LOAD); | |
103 smanager->dma_load(pp, (memaddr)pp_addr, | |
104 sizeof(PolygonPack), PP_LOAD); | |
105 smanager->dma_wait(PP_LOAD); | |
106 pp->init(); | |
107 } | |
1013 | 108 |
109 xyz1[0] = coord_xyz[(i+0)*3]; | |
110 xyz1[1] = coord_xyz[(i+0)*3+1]; | |
111 xyz1[2] = coord_xyz[(i+0)*3+2]*-1.0f; | |
112 xyz1[3] = 1.0f; | |
113 | |
114 xyz2[0] = coord_xyz[(i+1)*3]; | |
115 xyz2[1] = coord_xyz[(i+1)*3+1]; | |
116 xyz2[2] = coord_xyz[(i+1)*3+2]*-1.0f; | |
117 xyz2[3] = 1.0f; | |
118 | |
119 xyz3[0] = coord_xyz[(i+2)*3]; | |
120 xyz3[1] = coord_xyz[(i+2)*3+1]; | |
121 xyz3[2] = coord_xyz[(i+2)*3+2]*-1.0f; | |
122 xyz3[3] = 1.0f; | |
123 | |
124 // matrix = 回転行列*透視変換行列 | |
125 ApplyMatrix(xyz1, matrix); | |
126 ApplyMatrix(xyz2, matrix); | |
127 ApplyMatrix(xyz3, matrix); | |
128 | |
129 xyz1[0] /= xyz1[2]; | |
130 xyz1[1] /= xyz1[2]; | |
131 xyz2[0] /= xyz2[2]; | |
132 xyz2[1] /= xyz2[2]; | |
133 xyz3[0] /= xyz3[2]; | |
134 xyz3[1] /= xyz3[2]; | |
135 | |
1026 | 136 TrianglePack *triangle = &pp->tri[pp->info.size++]; |
137 | |
1013 | 138 triangle->ver1.x = xyz1[0]; |
139 triangle->ver1.y = xyz1[1]; | |
140 triangle->ver1.z = xyz1[2]; | |
141 triangle->ver1.tex_x = coord_tex[(i+0)*3]; | |
142 triangle->ver1.tex_y = coord_tex[(i+0)*3+1]; | |
143 | |
144 triangle->ver2.x = xyz2[0]; | |
145 triangle->ver2.y = xyz2[1]; | |
146 triangle->ver2.z = xyz2[2]; | |
147 triangle->ver2.tex_x = coord_tex[(i+1)*3]; | |
148 triangle->ver2.tex_y = coord_tex[(i+1)*3+1]; | |
149 | |
150 triangle->ver3.x = xyz3[0]; | |
151 triangle->ver3.y = xyz3[1]; | |
152 triangle->ver3.z = xyz3[2]; | |
153 triangle->ver3.tex_x = coord_tex[(i+2)*3]; | |
154 triangle->ver3.tex_y = coord_tex[(i+2)*3+1]; | |
155 | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
156 normal1[0] = normal[(i+0)*3]; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
157 normal1[1] = normal[(i+0)*3+1]; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
158 normal1[2] = normal[(i+0)*3+2]*-1.0f; |
1013 | 159 //normal1[3] = 1.0f; |
160 normal1[3] = 0.0f; | |
161 | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
162 normal2[0] = normal[(i+1)*3]; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
163 normal2[1] = normal[(i+1)*3+1]; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
164 normal2[2] = normal[(i+1)*3+2]*-1.0f; |
1013 | 165 //normal2[3] = 1.0f; |
166 normal2[3] = 0.0f; | |
167 | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
168 normal3[0] = normal[(i+2)*3]; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
169 normal3[1] = normal[(i+2)*3+1]; |
1013 | 170 normal3[2] = normal[(i+2)*3+2]*-1.0f; |
171 //normal3[3] = 1.0f; | |
172 normal3[3] = 0.0f; | |
173 | |
174 ApplyNormalMatrix(normal1,real_matrix); | |
175 ApplyNormalMatrix(normal2,real_matrix); | |
176 ApplyNormalMatrix(normal3,real_matrix); | |
177 | |
178 normal1[0] /= normal1[2]; | |
179 normal1[1] /= normal1[2]; | |
180 | |
181 normal2[0] /= normal2[2]; | |
182 normal2[1] /= normal2[2]; | |
183 | |
184 normal3[0] /= normal3[2]; | |
185 normal3[1] /= normal3[2]; | |
186 | |
187 triangle->normal1.x = normal1[0]; | |
188 triangle->normal1.y = normal1[1]; | |
189 triangle->normal1.z = normal1[2]; | |
190 | |
191 triangle->normal2.x = normal2[0]; | |
192 triangle->normal2.y = normal2[1]; | |
193 triangle->normal2.z = normal2[2]; | |
194 | |
195 triangle->normal3.x = normal3[0]; | |
196 triangle->normal3.y = normal3[1]; | |
197 triangle->normal3.z = normal3[2]; | |
198 | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
199 triangle->tex_info.addr = pixels; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
200 triangle->tex_info.width = width; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
201 triangle->tex_info.height = height; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
202 triangle->tex_info.scale_max = scale_max; |
1013 | 203 } |
1026 | 204 smanager->dma_wait(PP_STORE); |
205 smanager->dma_store(pp, (memaddr)pp_addr, | |
206 sizeof(PolygonPack), PP_STORE); | |
207 smanager->dma_wait(PP_STORE); | |
208 | |
209 free(pp); | |
210 free(send_pp); | |
211 | |
1013 | 212 return 0; |
213 } |