comparison TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp @ 137:6cf991f28c6c

SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Fri, 28 Nov 2008 10:07:48 +0900
parents
children 2284efc89f63
comparison
equal deleted inserted replaced
136:802e6e75c052 137:6cf991f28c6c
1 /**
2 * SceneGraph が増えてくると動かなくなるかもしれない。
3 * 一応 mainMem とかで動くようになるとは思うけど。
4 * だめだったら、そこら辺が怪しいと思うべき
5 */
6
7 #include "CreatePolygonFromSceneGraph.h"
8 #include "polygon_pack.h"
9 #include "scene_graph_pack.h"
10
11 SchedDefineTask(CreatePolygonFromSceneGraph);
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 CreatePolygonFromSceneGraph::run(void *rbuf, void *wbuf)
39 {
40 float xyz1[4], xyz2[4], xyz3[4];
41
42 SceneGraphPtr sg_top = (SceneGraphPtr)smanager->get_param(0);
43 SceneGraphPtr sg = sg_top;
44
45 PolygonPackPtr pp
46 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack));
47 PolygonPackPtr send_pp
48 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack));
49 PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(1);
50 PolygonPackPtr tmp_pp;
51
52 pp->init();
53 send_pp->init();
54
55 while (sg) {
56 for (int i = 0; i < sg->size; i += 3) {
57 if (pp->info.size >= MAX_SIZE_TRIANGLE) {
58 PolygonPackPtr next;
59
60 smanager->mainMem_alloc(0, sizeof(PolygonPack));
61 smanager->mainMem_wait();
62 next = (PolygonPackPtr)smanager->mainMem_get(0);
63
64 pp->next = next;
65
66 tmp_pp = pp;
67 pp = send_pp;
68 send_pp = tmp_pp;
69
70 smanager->dma_wait(PP_STORE);
71 smanager->dma_store(send_pp, (uint32)pp_addr,
72 sizeof(PolygonPack), PP_STORE);
73
74 pp_addr = next;
75
76 smanager->dma_wait(PP_LOAD);
77 smanager->dma_load(pp, (uint32)pp_addr,
78 sizeof(PolygonPack), PP_LOAD);
79 smanager->dma_wait(PP_LOAD);
80 pp->init();
81 }
82
83 TrianglePack *triangle = &pp->tri[pp->info.size++];
84
85 xyz1[0] = sg->data[(i+0)*3];
86 xyz1[1] = sg->data[(i+0)*3+1];
87 xyz1[2] = sg->data[(i+0)*3+2]*-1;
88 xyz1[3] = 1;
89 xyz2[0] = sg->data[(i+1)*3];
90 xyz2[1] = sg->data[(i+1)*3+1];
91 xyz2[2] = sg->data[(i+1)*3+2]*-1;
92 xyz2[3] = 1;
93 xyz3[0] = sg->data[(i+2)*3];
94 xyz3[1] = sg->data[(i+2)*3+1];
95 xyz3[2] = sg->data[(i+2)*3+2]*-1;
96 xyz3[3] = 1;
97
98 rotate(xyz1, sg->matrix);
99 rotate(xyz2, sg->matrix);
100 rotate(xyz3, sg->matrix);
101
102 triangle->ver1.x = xyz1[0];
103 triangle->ver1.y = xyz1[1];
104 triangle->ver1.z = xyz1[2];
105 triangle->ver1.tex_x = sg->data[(i+0)*3 + sg->size*6];
106 triangle->ver1.tex_y = sg->data[(i+0)*3 + sg->size*6+1];
107
108 triangle->ver2.x = xyz2[0];
109 triangle->ver2.y = xyz2[1];
110 triangle->ver2.z = xyz2[2];
111 triangle->ver2.tex_x = sg->data[(i+1)*3 + sg->size*6];
112 triangle->ver2.tex_y = sg->data[(i+1)*3 + sg->size*6+1];
113
114 triangle->ver3.x = xyz3[0];
115 triangle->ver3.y = xyz3[1];
116 triangle->ver3.z = xyz3[2];
117 triangle->ver3.tex_x = sg->data[(i+2)*3 + sg->size*6];
118 triangle->ver3.tex_y = sg->data[(i+2)*3 + sg->size*6+1];
119
120 //triangle->tex_addr = sg->texture_image->pixels;
121 triangle->tex_width = sg->texture_image->w;
122 triangle->tex_height = sg->texture_image->h;
123 }
124
125
126 if (sg->children != NULL) {
127 sg = sg->children;
128 } else if (sg->brother != NULL) {
129 sg = sg->brother;
130 } else {
131 while (sg) {
132 if (sg->brother != NULL) {
133 sg = sg->brother;
134 break;
135 } else {
136 if (sg->parent == NULL) {
137 sg = NULL;
138 break;
139 } else {
140 sg = sg->parent;
141 }
142 }
143 }
144 }
145 }
146
147 smanager->dma_wait(PP_STORE);
148 smanager->dma_store(pp, (uint32)pp_addr,
149 sizeof(PolygonPack), PP_STORE);
150 smanager->dma_wait(PP_STORE);
151
152 free(pp);
153 free(send_pp);
154
155 return 0;
156 }