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

fix
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Tue, 25 Nov 2008 17:24:18 +0900
parents 6ba88fa28df6
children 435e0d24db39
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 #include "CreateSpan.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include "viewer_types.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 static const int SPAN_PACK_LOAD = 5;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 static const int SPAN_PACK_STORE = 6;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 static const int POLYGON_PACK_LOAD = 7;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8 static SpanPackPtr spack = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 static SpanPackPtr send_spack = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10 static int prev_index = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12 SchedDefineTask(CreateSpan);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14 static float
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15 calc(float f1, float f2,int i, float base)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
16 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17 float ans;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18 ans = f1/f2*i + base;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 return ans;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 /**
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24 * TrianglePack から、vMin, vMid, vMax を求める
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25 *
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 * @param [triPack] TrianglePack
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27 * @param [vMin] [vMid] [vMax]
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
28 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29 static void
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30 make_vertex(TrianglePack *triPack,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33 if (triPack->ver1.y <= triPack->ver2.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 if (triPack->ver2.y <= triPack->ver3.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 *vMin = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 *vMid = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37 *vMax = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 } else if (triPack->ver3.y <= triPack->ver1.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 *vMin = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40 *vMid = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41 *vMax = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43 *vMin = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
44 *vMid = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45 *vMax = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48 if (triPack->ver1.y <= triPack->ver3.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 *vMin = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 *vMid = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51 *vMax = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 } else if (triPack->ver3.y <= triPack->ver2.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53 *vMin = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 *vMid = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 *vMax = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 *vMin = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58 *vMid = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 *vMax = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64 static void
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65 make_vMid10(VertexPack *v, VertexPack *vMin,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 VertexPack *vMid, VertexPack *vMax)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 int d, d1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 d = (int)(vMax->y - vMin->y);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71 d1 = (int)(vMid->y - vMin->y);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
72
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
73 v->tex_x = calc(vMax->tex_x - vMin->tex_x, d, d1, vMin->tex_x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74 v->tex_y = calc(vMax->tex_y - vMin->tex_y, d, d1, vMin->tex_y);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 v->x = calc(vMax->x - vMin->x, d, d1, vMin->x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 v->y = vMid->y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 v->z = calc(vMax->z - vMin->z, d, d1, vMin->z);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80 void
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81 CreateSpan::half_triangle(SpanPackPtr *spackList,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82 int charge_y_top, int charge_y_end,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 long *tex_addr, long tex_width, long tex_height,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84 VertexPack *vMin,VertexPack *vMid,VertexPack *vMid10)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86 float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 float tmp_xpos,tmp_end,tmp_zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88 float start_z, end_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89 float start_tex_x, end_tex_x, start_tex_y, end_tex_y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90 int x, y, length;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
92 int start_y = (int)vMid->y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
93 int end_y = (int)vMin->y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94 float div_y = start_y - end_y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95 int k = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 int l = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
97
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
98 SpanPackPtr tmp_spack;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
99
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
100 if (div_y < 0) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
101 div_y = -div_y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
102 k = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
103 l = -1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
104 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
105
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
106 for (int i = k; i < div_y+1; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
107 y = (int)vMin->y + i*l;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
108
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
109 /**
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
110 * 担当 y 範囲内
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
111 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
112 if (charge_y_top <= y && y <= charge_y_end) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
113 // 1..8 を index0, 9..16 を index1 にするために y を -1
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
114 int index = (y-1) / split_screen_h;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
115
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
116 /**
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
117 * 違う SpanPack を扱う場合、
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
118 * 現在の SpanPack をメインメモリに送り、
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
119 * 新しい SpanPack を取ってくる
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
120 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
121 if (index != prev_index) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
122 tmp_spack = spack;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
123 spack = send_spack;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
124 send_spack = tmp_spack;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
125
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
126 smanager->dma_wait(SPAN_PACK_STORE);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
127 smanager->dma_store(send_spack, (uint32)spackList[prev_index],
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
128 sizeof(SpanPack), SPAN_PACK_STORE);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
129
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
130 smanager->dma_load(spack, (uint32)spackList[index],
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
131 sizeof(SpanPack), SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
132 prev_index = index;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
133 smanager->dma_wait(SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
134 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
135
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
136 /**
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
137 * 書き込む SpanPack が満杯だったら
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
138 * メインメモリで allocate した領域 (next) を持ってきて
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
139 * 現在の spack->next につなぎ、next を次の spack とする。
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
140 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
141 if (spack->info.size >= MAX_SIZE_SPAN) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
142 SpanPackPtr next;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
143
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
144 mainMem_alloc(0, sizeof(SpanPack));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
145 mainMem_wait();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
146 next = (SpanPackPtr)mainMem_get(0);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
147
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
148 spack->next = next;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
149
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
150 tmp_spack = spack;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
151 spack = send_spack;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
152 send_spack = tmp_spack;
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(SPAN_PACK_STORE);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
155 smanager->dma_store(send_spack, (uint32)spackList[index],
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
156 sizeof(SpanPack), SPAN_PACK_STORE);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
157
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
158 spackList[index] = next;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
159
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
160 smanager->dma_load(spack, (uint32)spackList[index],
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
161 sizeof(SpanPack), SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
162 smanager->dma_wait(SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
163 spack->init((index+1)*split_screen_h);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
164 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
165 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
166 /**
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
167 * 担当範囲外だったら無視
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
168 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
169 continue;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
170 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
171
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
172 tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
173 tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
174 tmp_z = calc(vMid10->z - vMin->z ,div_y, i, vMin->z);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
175 tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
176
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
177 tmp_tex1 =((i/(div_y)) * vMid10->tex_x) +
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
178 ( ((div_y - i)/(div_y)) * vMin->tex_x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
179 tmp_tex2 =( (i/(div_y)) * vMid->tex_x) +
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
180 ( ((div_y - i)/(div_y)) * vMin->tex_x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
181
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
182 tmp_tey1 =( (i/(div_y)) * vMid10->tex_y) +
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
183 ( ((div_y - i)/(div_y)) * vMin->tex_y);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
184 tmp_tey2 =( (i/(div_y)) * vMid->tex_y) +
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
185 ( ((div_y - i)/(div_y)) * vMin->tex_y);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
186
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
187 if (tmp_xpos > tmp_end) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
188 x = (int)tmp_end;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
189 length = (int)(tmp_xpos)-(int)(tmp_end)+1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
190 start_z = tmp_zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
191 end_z = tmp_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
192 start_tex_x = tmp_tex2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
193 end_tex_x = tmp_tex1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
194 start_tex_y = tmp_tey2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
195 end_tex_y = tmp_tey1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
196 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
197 x = (int)tmp_xpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
198 length = (int)(tmp_end)-(int)(tmp_xpos)+1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
199 start_z = tmp_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
200 end_z = tmp_zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
201 start_tex_x = tmp_tex1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
202 end_tex_x = tmp_tex2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
203 start_tex_y = tmp_tey1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
204 end_tex_y = tmp_tey2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
205 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
206
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
207 smanager->dma_wait(SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
208
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
209 Span *span = &spack->span[spack->info.size++];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
210
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
211 span->tex_addr = tex_addr;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
212 span->tex_width = tex_width;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
213 span->tex_height = tex_height;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
214 span->x = x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
215 span->y = y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
216 span->length_x = length;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
217 span->start_z = start_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
218 span->end_z = end_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
219 span->tex_x1 = start_tex_x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
220 span->tex_x2 = end_tex_x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
221 span->tex_y1 = start_tex_y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
222 span->tex_y2 = end_tex_y;
113
6ba88fa28df6 Define New Texture Data Structure
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 109
diff changeset
223
6ba88fa28df6 Define New Texture Data Structure
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 109
diff changeset
224 // TilePtr の計算
6ba88fa28df6 Define New Texture Data Structure
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 109
diff changeset
225 // tix, tiy (Tile 内での x, y)
6ba88fa28df6 Define New Texture Data Structure
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 109
diff changeset
226 //
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
227 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
228 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
229
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
230
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
231 int
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
232 CreateSpan::run(void *rbuf, void *wbuf)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
233 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
234 PolygonPack *pp = (PolygonPack*)smanager->get_input(0);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
235 PolygonPack *next_pp =
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
236 (PolygonPack*)smanager->allocate(sizeof(PolygonPack));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
237 PolygonPack *free_pp = next_pp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
238 PolygonPack *tmp_pp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
239
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
240 TrianglePackPtr triPack;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
241 VertexPackPtr vMin, vMid, vMax;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
242 VertexPackPtr vMid10
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
243 = (VertexPackPtr)smanager->allocate(sizeof(VertexPack));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
244
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
245 SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
246 spack = (SpanPackPtr)smanager->get_input(2);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
247 send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
248 prev_index = get_param(0);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
249
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
250 // spack と send_spack は swap しながら DMA を繰り返すので
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
251 // 自分で allocate した send_spack を覚えてないといけない
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
252 SpanPackPtr free_spack = send_spack;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
253
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
254 int charge_y_top = get_param(1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
255 int charge_y_end = get_param(2);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
256
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
257 do {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
258 if (pp->next != NULL) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
259 smanager->dma_load(next_pp, (uint32)pp->next,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
260 sizeof(PolygonPack), POLYGON_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
261 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
262 next_pp = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
263 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
264
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
265 for (int i = 0; i < pp->info.size; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
266 triPack = &pp->tri[i];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
267
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
268 #if 0
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
269 make_vertex(triPack, &vMin, &vMid, &vMax);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
270 #else
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
271 if (triPack->ver1.y <= triPack->ver2.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
272 if (triPack->ver2.y <= triPack->ver3.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
273 vMin = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
274 vMid = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
275 vMax = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
276 } else if (triPack->ver3.y <= triPack->ver1.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
277 vMin = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
278 vMid = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
279 vMax = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
280 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
281 vMin = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
282 vMid = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
283 vMax = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
284 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
285 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
286 if (triPack->ver1.y <= triPack->ver3.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
287 vMin = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
288 vMid = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
289 vMax = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
290 } else if (triPack->ver3.y <= triPack->ver2.y) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
291 vMin = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
292 vMid = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
293 vMax = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
294 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
295 vMin = &triPack->ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
296 vMid = &triPack->ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
297 vMax = &triPack->ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
298 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
299 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
300 #endif
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
301 make_vMid10(vMid10, vMin, vMid, vMax);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
302
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
303 half_triangle(spackList, charge_y_top, charge_y_end,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
304 triPack->tex_addr, triPack->tex_width,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
305 triPack->tex_height, vMin, vMid, vMid10);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
306 half_triangle(spackList, charge_y_top, charge_y_end,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
307 pp->tri[0].tex_addr, pp->tri[0].tex_width,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
308 pp->tri[0].tex_height, vMax, vMid, vMid10);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
309 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
310
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
311 smanager->dma_wait(POLYGON_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
312
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
313 tmp_pp = pp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
314 pp = next_pp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
315 next_pp = tmp_pp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
316 } while (pp);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
317
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
318 smanager->dma_wait(SPAN_PACK_STORE);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
319 smanager->dma_store(spack, (uint32)spackList[prev_index],
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
320 sizeof(SpanPack), SPAN_PACK_STORE);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
321 smanager->dma_wait(SPAN_PACK_STORE);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
322
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
323 free(free_pp);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
324 free(free_spack);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
325 free(vMid10);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
326
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
327 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
328 }