annotate TaskManager/Test/test_render/spe/CreatePolygon.cpp @ 131:805d27efafd8

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