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

fix
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Tue, 25 Nov 2008 17:24:18 +0900
parents 776eca0daa02
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 <stdlib.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <string.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include "DrawSpan.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include "polygon_pack.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "SpanPack.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 #include "texture.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7 #include "viewer_types.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 #define SPAN_PACK_LOAD 0
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
10 #define TEX_LOAD 1
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12 SchedDefineTask(DrawSpan);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
14 static const int hashsize = 263;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
15
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
16 static TilePtr hash_table[hashsize] = {NULL};
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
17
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
18 unsigned short PRIME[8] = {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
19 0x002, 0x065, 0x0c7, 0x133, 0x191, 0x1f3, 0x259, 0x2bd,
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
20 };
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
21
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
22 static TileListPtr tileList;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
23
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
24 static int
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
25 hash(uint32 data)
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
26 {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
27 int value = 0;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
28 int n = 0;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
29 int key;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
30
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
31 for (int i = 0; i < 8; i ++) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
32 key = data & 0xf;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
33 value += key * PRIME[n++];
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
34 data >>= 4;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
35 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
36
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
37 return value % hashsize;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
38 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
39
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
40 static int
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
41 put(void *key, TilePtr data)
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
42 {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
43 int hashval = hash((uint32)key);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
44
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
45 for (int i = 0; i < hashsize/2; i++) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
46 int index = (hashval + i*i)%hashsize;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
47
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
48 if (hash_table[index] == 0) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
49 hash_table[index] = data;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
50 return index;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
51 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
52 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
53
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
54 return -1;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
55 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
56
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
57 static TilePtr
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
58 get(void *key)
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
59 {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
60 int hashval = hash((uint32)key);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
61
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
62 for (int i = 0; i < hashsize/2; i++) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
63 int index = (hashval + i*i)%hashsize;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
64
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
65 if (hash_table[index] != NULL &&
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
66 hash_table[index]->texture_addr == key) {
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
67 return hash_table[index];
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
68 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
69 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
70
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
71 return NULL;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
72 }
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
73
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74 void
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 DrawSpan::linebuf_init(int *buf, int x, int rgb)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 for (int i = 0; i < x; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 buf[i] = rgb;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82 float*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 DrawSpan::zRow_init(int w, int h)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 float *zRow = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86 float z = 65535.0f;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 int length = w*h;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89 zRow = (float*)smanager->allocate(sizeof(float)*length);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91 for (int i = 0; i < length; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
92 zRow[i] = z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
93 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95 return zRow;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
97
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
98
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
99 char*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
100 DrawSpan::get_pixel(int tx, int ty, void *texture_image)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
101 {
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
102 #if 0
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
103 return (char*)texture_image+(3*((128)*ty+tx));
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
104 #else
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
105 return (char*)texture_image+(4*((8)*ty+tx));
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
106 #endif
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
107 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
108
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
109 Uint32
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
110 DrawSpan::get_rgb(int tx, int ty, int tw, int th, void *texture)
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
111 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
112 Uint8 red, green, blue, alpha;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
113
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
114 if (tx<0) tx = 0;
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
115 if (tw-1< tx) tx = tw-1 ;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
116 if (ty<0) ty = 0;
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
117 if (th-1< ty) ty = th-1 ;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
118
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
119 void *texture_addr;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
120
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
121 int blockX = tx / 8;
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
122 int blockY = ty / 8;
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
123 void** addrList = (void**)global_get(TEXTURE2_ID);
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
124 TilePtr tile;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
125
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
126 texture_addr = addrList[blockX + (tw/8)*blockY];
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
127
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
128 /**
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
129 * get,put はオブジェクト(Hashとか?)を作ってアクセスするかな
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
130 */
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
131 tile = get(texture_addr);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
132 if (tile == NULL) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
133 if (tileList->size >= MAX_TILE) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
134 tileList->init();
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
135 bzero(hash_table, sizeof(TilePtr)*hashsize);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
136 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
137
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
138 tile = &tileList->tile[tileList->size];
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
139 tile->texture_addr = texture_addr;
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
140
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
141 smanager->dma_load(tile->pixel, (uint32)texture_addr,
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
142 sizeof(uint32)*64, TEX_LOAD);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
143
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
144 int index = put(tile->texture_addr, tile);
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
145
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
146 /**
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
147 * TODO:
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
148 * 入らなかったやつは
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
149 * 今までのやつを描画してから続きをするとか
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
150 */
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
151 if (index < 0) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
152 printf("[%p] Can't entry\n", tile);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
153 return 0xff0000;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
154 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
155
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
156 tileList->size++;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
157
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
158 smanager->dma_wait(TEX_LOAD);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
159 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
160
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
161 char *p = get_pixel(tx%8, ty%8, tile->pixel);
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
162
126
7635f223fc7d fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
163 alpha = 255;
7635f223fc7d fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
164 red = (Uint8) p[0];
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
165 green = (Uint8) p[1];
126
7635f223fc7d fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
166 blue = (Uint8) p[2];
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
167
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
168 return (red & 0xff) * 0x10000 + (green & 0xff) * 0x100
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
169 + (blue & 0xff) + (alpha << 24);
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 int
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
173 DrawSpan::run(void *rbuf, void *wbuf)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
174 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
175 SpanPack *sp = (SpanPack*)smanager->get_input(0);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
176 SpanPack *next_sp =
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
177 (SpanPack*)smanager->allocate(sizeof(SpanPack));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
178 SpanPack *free_sp = next_sp; // next_sp の free() 用
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
179 SpanPack *tmp_sp = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
180 Span *span;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
181
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
182 tileList = (TileListPtr)smanager->allocate(sizeof(TileList));
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
183 tileList->init();
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
184
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
185 int render_y = sp->info.y_top;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
186 void *texture_image = global_get(TEXTURE_ID);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
187
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
188 int rangex_start = get_param(0); // このタスクが担当する x の範囲の始点
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
189 int rangex_end = get_param(1); // 終点 (start <= x <= end)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
190 int rangey = get_param(2); // y の範囲 (render_y + rangey - 1)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
191 int rangex = rangex_end - rangex_start + 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
192
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
193 float *zRow = zRow_init(rangex, rangey);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
194
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
195 int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
196
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
197 for (int i = 0; i < rangey; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
198 linebuf[i] = (int*)smanager->get_output(i);
121
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
199 linebuf_init(linebuf[i], rangex, 0);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
200 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
201
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
202 bzero(hash_table, sizeof(TilePtr)*hashsize);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
203
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
204 do {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
205 /**
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
206 * SpanPack->next が存在する場合、
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
207 * 現在の SpanPack を処理してる間に
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
208 * 次の SpanPack の DMA 転送を行う
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
209 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
210 if (sp->next != NULL) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
211 smanager->dma_load(next_sp, (uint32)sp->next,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
212 sizeof(SpanPack), SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
213 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
214 next_sp = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
215 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
216
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
217 for (int t = 0; t < sp->info.size; t++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
218 span = &sp->span[t];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
219
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
220 int end = span->length_x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
221 Uint32 rgb = 0x00ff00;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
222 float tex1 = span->tex_x1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
223 float tex2 = span->tex_x2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
224 float tey1 = span->tex_y1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
225 float tey2 = span->tex_y2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
226 int tex_xpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
227 int tex_ypos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
228 int tex_zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
229 int x = span->x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
230 int y = span->y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
231 float z = span->start_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
232 float zpos = span->end_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
233
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
234 // 座標が [0 .. split_screen_w-1] に入るように x,y を -1
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
235 int localx = getLocalX(x-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
236 int localy = getLocalY(y-1);
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
237
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
238 if (end == 1) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
239 if (x < rangex_start || rangex_end < x) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
240 continue;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
241 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
242 tex_xpos = (int)((span->tex_height-1) * tex1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
243 tex_ypos = (int)((span->tex_width-1) * tey1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
244 tex_zpos = (int)z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
245
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
246 if (zpos < zRow[localx + (rangex * localy)]) {
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
247 rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width,
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
248 span->tex_height, texture_image);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
249 zRow[localx + (rangex * localy)] = zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
250 linebuf[localy][localx] = rgb;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
251 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
252 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
253 float tex_x, tex_y, tex_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
254 int js = (x < rangex_start) ? rangex_start - x : 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
255 int je = (x + end > rangex_end) ? rangex_end - x : end;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
256
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
257 for (int j = js; j <= je; j++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
258 localx = getLocalX(x-1+j);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
259
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
260 tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
261 tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
262 tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
263 if (tex_x > 1) tex_x = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
264 if (tex_y > 1) tex_y = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
265 tex_xpos = (int)((span->tex_height-1) * tex_x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
266 tex_ypos = (int)((span->tex_width-1) * tex_y);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
267
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
268 if (tex_z < zRow[localx + (rangex*localy)]) {
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
269 rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width,
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
270 span->tex_height, texture_image);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
271 zRow[localx + (rangex*localy)] = tex_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
272 linebuf[localy][localx] = rgb;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
273 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
274 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
275 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
276 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
277
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
278 smanager->dma_wait(SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
279
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
280 tmp_sp = sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
281 sp = next_sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
282 next_sp = tmp_sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
283 } while (sp);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
284
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
285 free(free_sp);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
286 free(linebuf);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
287 free(zRow);
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
288 free(tileList);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
289
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
290 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
291 }