annotate TaskManager/Test/test_render/spe/DrawSpan.cpp @ 147:3ecf43bd1a35

fix
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Tue, 02 Dec 2008 15:47:25 +0900
parents 435e0d24db39
children 9642aeef298d
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
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
11 #define TILE_INFO_LOAD 2
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13 SchedDefineTask(DrawSpan);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
15 static const int hashsize = 263;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
16
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
17 static TilePtr hash_table[hashsize] = {NULL};
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
18
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
19 unsigned short PRIME[8] = {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
20 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
21 };
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
22
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
23 static TileListPtr tileList;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
24
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
25 static int
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
26 hash(uint32 data)
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
27 {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
28 int value = 0;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
29 int n = 0;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
30 int key;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
31
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
32 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
33 key = data & 0xf;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
34 value += key * PRIME[n++];
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
35 data >>= 4;
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
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
38 return value % hashsize;
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
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
41 static int
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
42 put(void *key, TilePtr data)
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
43 {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
44 int hashval = hash((uint32)key);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
45
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
46 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
47 int index = (hashval + i*i)%hashsize;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
48
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
49 if (hash_table[index] == 0) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
50 hash_table[index] = data;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
51 return index;
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
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
55 return -1;
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
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
58 static TilePtr
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
59 get(void *key)
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
60 {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
61 int hashval = hash((uint32)key);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
62
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
63 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
64 int index = (hashval + i*i)%hashsize;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
65
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
66 if (hash_table[index] != NULL &&
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
67 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
68 return hash_table[index];
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
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
72 return NULL;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
73 }
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
74
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 void
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 DrawSpan::linebuf_init(int *buf, int x, int rgb)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 for (int i = 0; i < x; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 buf[i] = rgb;
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
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 float*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84 DrawSpan::zRow_init(int w, int h)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86 float *zRow = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 float z = 65535.0f;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88 int length = w*h;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90 zRow = (float*)smanager->allocate(sizeof(float)*length);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
92 for (int i = 0; i < length; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
93 zRow[i] = z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 return zRow;
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
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
100 char*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
101 DrawSpan::get_pixel(int tx, int ty, void *texture_image)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
102 {
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
103 return (char*)texture_image+(4*((TEXTURE_SPLIT_PIXEL)*ty+tx));
109
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 Uint32
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
107 DrawSpan::get_rgb(int tx, int ty, int tw, int th, void *texture)
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
108 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
109 Uint8 red, green, blue, alpha;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
110
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
111 if (tx<0) tx = 0;
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
112 if (tw-1< tx) tx = tw-1 ;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
113 if (ty<0) ty = 0;
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
114 if (th-1< ty) ty = th-1 ;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
115
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
116 void *texture_addr;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
117
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
118 int blockX = tx / TEXTURE_SPLIT_PIXEL;
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
119 int blockY = ty / TEXTURE_SPLIT_PIXEL;
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
120 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
121 TilePtr tile;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
122
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
123 texture_addr = addrList[blockX + (tw/TEXTURE_SPLIT_PIXEL)*blockY];
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
124
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
125 /**
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
126 * get,put ϥ֥(HashȤ)äƥ뤫
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
127 */
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
128 tile = get(texture_addr);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
129 if (tile == NULL) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
130 if (tileList->size >= MAX_TILE) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
131 tileList->init();
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
132 bzero(hash_table, sizeof(TilePtr)*hashsize);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
133 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
134
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
135 tile = &tileList->tile[tileList->size];
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
136 tile->texture_addr = texture_addr;
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
137
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
138 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
139 sizeof(uint32)*64, TEX_LOAD);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
140
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
141 int index = put(tile->texture_addr, tile);
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
142
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
143 /**
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
144 * TODO:
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 */
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
148 if (index < 0) {
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
149 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
150 return 0xff0000;
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
151 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
152
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
153 tileList->size++;
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 smanager->dma_wait(TEX_LOAD);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
156 }
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
157
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
158 char *p = get_pixel(tx%TEXTURE_SPLIT_PIXEL,
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
159 ty%TEXTURE_SPLIT_PIXEL, tile->pixel);
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
160
126
7635f223fc7d fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
161 alpha = 255;
7635f223fc7d fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
162 red = (Uint8) p[0];
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
163 green = (Uint8) p[1];
126
7635f223fc7d fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
164 blue = (Uint8) p[2];
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
165
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
166 return (red & 0xff) * 0x10000 + (green & 0xff) * 0x100
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
167 + (blue & 0xff) + (alpha << 24);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
168 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
169
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
170 int
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
171 DrawSpan::run(void *rbuf, void *wbuf)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
172 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
173 SpanPack *sp = (SpanPack*)smanager->get_input(0);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
174 SpanPack *next_sp =
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
175 (SpanPack*)smanager->allocate(sizeof(SpanPack));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
176 SpanPack *free_sp = next_sp; // next_sp free()
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
177 SpanPack *tmp_sp = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
178 Span *span;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
179
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
180 TileInfoListPtr tilist =
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
181 (TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
182 TileInfoListPtr next_tilist =
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
183 (TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
184 TileInfoListPtr tmp_tilist = NULL;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
185 TileInfoPtr tinfo;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
186
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
187
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
188 tileList = (TileListPtr)smanager->allocate(sizeof(TileList));
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
189 tileList->init();
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
190
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
191 int render_y = sp->info.y_top;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
192 void *texture_image = global_get(TEXTURE_ID);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
193
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
194 int rangex_start = get_param(0); // Υô x ϰϤλ
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
195 int rangex_end = get_param(1); // (start <= x <= end)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
196 int rangey = get_param(2); // y ϰ (render_y + rangey - 1)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
197 int rangex = rangex_end - rangex_start + 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
198
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
199 float *zRow = zRow_init(rangex, rangey);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
200
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
201 int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
202
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
203 for (int i = 0; i < rangey; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
204 linebuf[i] = (int*)smanager->get_output(i);
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
205 linebuf_init(linebuf[i], rangex, 0xffffff);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
206 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
207
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
208 bzero(hash_table, sizeof(TilePtr)*hashsize);
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
209
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
210 do {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
211 /**
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
212 * SpanPack->next ¸ߤ硢
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
213 * ߤ SpanPack Ƥ֤
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
214 * SpanPack DMA žԤ
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
215 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
216 if (sp->next != NULL) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
217 smanager->dma_load(next_sp, (uint32)sp->next,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
218 sizeof(SpanPack), SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
219 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
220 next_sp = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
221 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
222
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
223 for (int t = 0; t < sp->info.size; t++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
224 span = &sp->span[t];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
225
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
226 smanager->dma_load(tilist, (uint32)span->tilelist,
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
227 sizeof(TileInfoList), TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
228
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
229 Uint32 rgb = 0x00ff00;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
230 float tex1 = span->tex_x1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
231 float tex2 = span->tex_x2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
232 float tey1 = span->tex_y1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
233 float tey2 = span->tex_y2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
234 int tex_xpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
235 int tex_ypos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
236 int tex_zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
237 int x = span->x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
238 int y = span->y;
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
239 int x_len = span->length_x;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
240 float z = span->start_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
241 float zpos = span->end_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
242
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
243 // ɸ [0 .. split_screen_w-1] 褦 x,y -1
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
244 int localx = getLocalX(x-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
245 int localy = getLocalY(y-1);
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
246
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
247 smanager->dma_wait(TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
248
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
249 if (x_len == 1) {
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
250 if (x < rangex_start || rangex_end < x) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
251 continue;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
252 }
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
253 tex_xpos = (int)((span->tex_width-1) * tex1);
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
254 tex_ypos = (int)((span->tex_height-1) * tey1);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
255 tex_zpos = (int)z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
256
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
257 if (zpos < zRow[localx + (rangex * localy)]) {
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
258 rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width,
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
259 span->tex_height, texture_image);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
260 zRow[localx + (rangex * localy)] = zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
261 linebuf[localy][localx] = rgb;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
262 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
263 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
264 int js = (x < rangex_start) ? rangex_start - x : 0;
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
265 int je = (x + x_len > rangex_end) ? rangex_end - x : x_len;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
266
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
267 if (js > je) continue;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
268
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
269 int cur_x = 0;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
270 int max_x = je;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
271 int len;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
272
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
273 while (cur_x + MAX_TILE_LIST < js) {
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
274 smanager->dma_wait(TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
275 smanager->dma_load(tilist, (uint32)tilist->next,
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
276 sizeof(TileInfoList), TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
277 cur_x += MAX_TILE_LIST;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
278 }
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
279
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
280 cur_x = js;
133
435e0d24db39 DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
281
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
282 while (cur_x < max_x) {
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
283 smanager->dma_wait(TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
284
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
285 if (cur_x + MAX_TILE_LIST < max_x) {
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
286 smanager->dma_load(next_tilist, (uint32)tilist->next,
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
287 sizeof(TileInfoList), TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
288 len = MAX_TILE_LIST;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
289 } else {
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
290 len = max_x - cur_x;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
291 }
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
292
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
293 float tex_x, tex_y, tex_z;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
294
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
295 for (int j = cur_x; j <= cur_x + len; j++) {
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
296 localx = getLocalX(x-1+j);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
297
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
298 tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
299
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
300 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
301 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
302 if (tex_x > 1) tex_x = 1;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
303 if (tex_y > 1) tex_y = 1;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
304 tex_xpos = (int)((span->tex_width-1) * tex_x);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
305 tex_ypos = (int)((span->tex_height-1) * tex_y);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
306
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
307 if (tex_z < zRow[localx + (rangex*localy)]) {
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
308 rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width,
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
309 span->tex_height, texture_image);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
310 zRow[localx + (rangex*localy)] = tex_z;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
311 linebuf[localy][localx] = rgb;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
312 }
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
313 }
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
314
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
315 smanager->dma_wait(TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
316
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
317 TileInfoListPtr tmp = tilist;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
318 tilist = next_tilist;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
319 next_tilist = tmp;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
320
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
321 cur_x += MAX_TILE_LIST;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
322 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
323 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
324 }
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
325
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
326 smanager->dma_wait(SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
327
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
328 tmp_sp = sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
329 sp = next_sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
330 next_sp = tmp_sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
331 } while (sp);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
332
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
333 free(free_sp);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
334 free(linebuf);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
335 free(zRow);
128
776eca0daa02 texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
336 free(tileList);
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
337 free(tilist);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
338 free(next_tilist);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
339
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
340 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
341 }