annotate TaskManager/Test/test_render/spe/DrawSpan.cpp @ 161:18c42658e0e7 draft fullHD_omedetou

texture の座標がマイナスになったあと、それを 0 にし忘れてた
author gongo@localhost.localdomain
date Mon, 08 Dec 2008 16:37:02 +0900
parents 16c3cbbbfc50
children dc7d10ae7460
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <stdlib.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <string.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include "DrawSpan.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include "polygon_pack.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "SpanPack.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 #include "texture.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7 #include "viewer_types.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 #define SPAN_PACK_LOAD 0
120
13b43de5ef5d 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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13 SchedDefineTask(DrawSpan);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14
128
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
15 static const int hashsize = 263;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
16
161
18c42658e0e7 texture の座標がマイナスになったあと、それを 0 にし忘れてた
gongo@localhost.localdomain
parents: 156
diff changeset
17 static TilePtr hash_table[hashsize] = {0};
128
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
18
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
19 unsigned short PRIME[8] = {
95e2046eb46f 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,
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
21 };
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
22
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
23 static TileListPtr tileList;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
24
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
25 static int
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
26 hash(uint32 data)
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
27 {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
28 int value = 0;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
29 int n = 0;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
30 int key;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
31
95e2046eb46f 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 ++) {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
33 key = data & 0xf;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
34 value += key * PRIME[n++];
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
35 data >>= 4;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
36 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
37
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
38 return value % hashsize;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
39 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
40
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
41 static int
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
42 put(void *key, TilePtr data)
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
43 {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
44 int hashval = hash((uint32)key);
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
45
95e2046eb46f 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++) {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
47 int index = (hashval + i*i)%hashsize;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
48
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
49 if (hash_table[index] == 0) {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
50 hash_table[index] = data;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
51 return index;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
52 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
53 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
54
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
55 return -1;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
56 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
57
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
58 static TilePtr
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
59 get(void *key)
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
60 {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
61 int hashval = hash((uint32)key);
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
62
95e2046eb46f 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++) {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
64 int index = (hashval + i*i)%hashsize;
95e2046eb46f 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
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
68 return hash_table[index];
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
69 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
70 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
71
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
72 return NULL;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
73 }
120
13b43de5ef5d fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
74
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 DrawSpan::linebuf_init(int *buf, int x, int rgb)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 for (int i = 0; i < x; i++) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 buf[i] = rgb;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 float*
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84 DrawSpan::zRow_init(int w, int h)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86 float *zRow = NULL;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 float z = 65535.0f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88 int length = w*h;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90 zRow = (float*)smanager->allocate(sizeof(float)*length);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
92 for (int i = 0; i < length; i++) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
93 zRow[i] = z;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 return zRow;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
97 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
98
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
99
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
100 char*
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
101 DrawSpan::get_pixel(int tx, int ty, void *texture_image)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
102 {
133
8f1419174cdf 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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
104 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
105
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
106 Uint32
156
gongo@gendarme.local
parents: 155
diff changeset
107 DrawSpan::get_rgb(int tx, int ty, void *addr)
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
108 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
109 Uint8 red, green, blue, alpha;
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
110 TilePtr tile;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
111
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
112 /**
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
113 * get,put ϥ֥(HashȤ)äƥ뤫
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
114 */
156
gongo@gendarme.local
parents: 155
diff changeset
115 tile = get(addr);
128
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
116 if (tile == NULL) {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
117 if (tileList->size >= MAX_TILE) {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
118 tileList->init();
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
119 bzero(hash_table, sizeof(TilePtr)*hashsize);
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
120 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
121
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
122 tile = &tileList->tile[tileList->size];
156
gongo@gendarme.local
parents: 155
diff changeset
123 tile->texture_addr = addr;
120
13b43de5ef5d fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
124
156
gongo@gendarme.local
parents: 155
diff changeset
125 smanager->dma_load(tile->pixel, (uint32)addr,
161
18c42658e0e7 texture の座標がマイナスになったあと、それを 0 にし忘れてた
gongo@localhost.localdomain
parents: 156
diff changeset
126 sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD);
128
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
127
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
128 int index = put(tile->texture_addr, tile);
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
129
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
130 /**
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
131 * TODO:
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
132 * ʤäĤ
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
133 * ޤǤΤĤ褷Ƥ³򤹤Ȥ
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
134 */
128
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
135 if (index < 0) {
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
136 printf("[%p] Can't entry\n", tile);
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
137 return 0xff0000;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
138 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
139
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
140 tileList->size++;
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
141
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
142 smanager->dma_wait(TEX_LOAD);
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
143 }
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
144
156
gongo@gendarme.local
parents: 155
diff changeset
145 char *p = get_pixel(tx, ty, tile->pixel);
120
13b43de5ef5d fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
146
126
74d0a70f60e9 fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
147 alpha = 255;
74d0a70f60e9 fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
148 red = (Uint8) p[0];
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
149 green = (Uint8) p[1];
126
74d0a70f60e9 fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 123
diff changeset
150 blue = (Uint8) p[2];
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
151
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
152 return (red & 0xff) * 0x10000 + (green & 0xff) * 0x100
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
153 + (blue & 0xff) + (alpha << 24);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
154 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
155
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
156 int
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
157 DrawSpan::run(void *rbuf, void *wbuf)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
158 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
159 SpanPack *sp = (SpanPack*)smanager->get_input(0);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
160 SpanPack *next_sp =
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
161 (SpanPack*)smanager->allocate(sizeof(SpanPack));
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
162 SpanPack *free_sp = next_sp; // next_sp free()
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
163 SpanPack *tmp_sp = NULL;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
164 Span *span;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
165
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
166 TileInfoListPtr tilist =
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
167 (TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
168 TileInfoListPtr next_tilist =
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
169 (TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
170
128
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
171 tileList = (TileListPtr)smanager->allocate(sizeof(TileList));
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
172 tileList->init();
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
173
161
18c42658e0e7 texture の座標がマイナスになったあと、それを 0 にし忘れてた
gongo@localhost.localdomain
parents: 156
diff changeset
174 void *texture_image = global_get(TEXTURE_ID);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
175 int rangex_start = get_param(0); // Υô x ϰϤλ
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
176 int rangex_end = get_param(1); // (start <= x <= end)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
177 int rangey = get_param(2); // y ϰ (render_y + rangey - 1)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
178 int rangex = rangex_end - rangex_start + 1;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
179
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
180 float *zRow = zRow_init(rangex, rangey);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
181
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
182 int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
183
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
184 for (int i = 0; i < rangey; i++) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
185 linebuf[i] = (int*)smanager->get_output(i);
133
8f1419174cdf DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
186 linebuf_init(linebuf[i], rangex, 0xffffff);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
187 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
188
128
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
189 bzero(hash_table, sizeof(TilePtr)*hashsize);
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
190
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
191 do {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
192 /**
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
193 * SpanPack->next ¸ߤ硢
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
194 * ߤ SpanPack Ƥ֤
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
195 * SpanPack DMA žԤ
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
196 */
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
197 if (sp->next != NULL) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
198 smanager->dma_load(next_sp, (uint32)sp->next,
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
199 sizeof(SpanPack), SPAN_PACK_LOAD);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
200 } else {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
201 next_sp = NULL;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
202 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
203
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
204 for (int t = 0; t < sp->info.size; t++) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
205 span = &sp->span[t];
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
206
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
207 smanager->dma_load(tilist, (uint32)span->tilelist,
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
208 sizeof(TileInfoList), TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
209
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
210 Uint32 rgb = 0x00ff00;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
211 int tex_xpos;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
212 int tex_ypos;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
213 int tex_zpos;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
214 int x = span->x;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
215 int y = span->y;
133
8f1419174cdf DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
216 int x_len = span->length_x;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
217 float z = span->start_z;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
218 float zpos = span->end_z;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
219
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
220 // ɸ [0 .. split_screen_w-1] 褦 x,y -1
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
221 int localx = getLocalX(x-1);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
222 int localy = getLocalY(y-1);
131
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 128
diff changeset
223
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
224 smanager->dma_wait(TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
225
133
8f1419174cdf DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
226 if (x_len == 1) {
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
227 if (x < rangex_start || rangex_end < x) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
228 continue;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
229 }
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
230
156
gongo@gendarme.local
parents: 155
diff changeset
231 tex_xpos = tilist->tileinfo[0].tix;
gongo@gendarme.local
parents: 155
diff changeset
232 tex_ypos = tilist->tileinfo[0].tiy;
161
18c42658e0e7 texture の座標がマイナスになったあと、それを 0 にし忘れてた
gongo@localhost.localdomain
parents: 156
diff changeset
233 tex_zpos = (int)z;
156
gongo@gendarme.local
parents: 155
diff changeset
234 texture_image = tilist->tileinfo[0].tile;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
235
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
236 if (zpos < zRow[localx + (rangex * localy)]) {
156
gongo@gendarme.local
parents: 155
diff changeset
237 rgb = get_rgb(tex_xpos, tex_ypos, texture_image);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
238 zRow[localx + (rangex * localy)] = zpos;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
239 linebuf[localy][localx] = rgb;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
240 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
241 } else {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
242 int js = (x < rangex_start) ? rangex_start - x : 0;
133
8f1419174cdf DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
243 int je = (x + x_len > rangex_end) ? rangex_end - x : x_len;
155
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
244
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
245 if (js > je) continue;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
246
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
247 int cur_x = 0;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
248 int max_x = je;
155
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
249 int len = 0;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
250
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
251 /**
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
252 * Span ɽʤϰ([js..je]) TileInfoList
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
253 * äƤΤǡФ
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
254 */
155
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
255 while (cur_x + MAX_TILE_LIST <= js) {
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
256 smanager->dma_load(next_tilist, (uint32)tilist->next,
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
257 sizeof(TileInfoList), TILE_INFO_LOAD);
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
258 smanager->dma_wait(TILE_INFO_LOAD);
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
259
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
260 TileInfoListPtr tmp = tilist;
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
261 tilist = next_tilist;
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
262 next_tilist = tmp;
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
263
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
264 cur_x += MAX_TILE_LIST;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
265 }
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
266
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
267 cur_x = js;
133
8f1419174cdf DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 131
diff changeset
268
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
269 while (cur_x <= max_x) {
155
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
270 /**
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
271 * TileInfoList 30 ĤǶڤƤΤ
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
272 * cur_x TileInfoList 椫ϤޤäƤ
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
273 * MAX_TILE_LIST ˼ޤͤ
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
274 * (ex.)
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
275 * cur_x (=js) 0 Ϥޤä硢
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
276 * cur_x = 0, len = 29
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
277 * cur_x (=js) 15 Ϥޤä硢
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
278 * cur_x = 15, len = 14 ˤʤ
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
279 */
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
280 int cur_x_diff = MAX_TILE_LIST - (cur_x % MAX_TILE_LIST);
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
281
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
282 if (cur_x + cur_x_diff - 1 < max_x) {
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
283 smanager->dma_load(next_tilist, (uint32)tilist->next,
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
284 sizeof(TileInfoList),
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
285 TILE_INFO_LOAD);
155
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
286 len = cur_x_diff - 1;
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
287 } else {
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
288 len = max_x - cur_x;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
289 }
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
290
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
291 for (int j = cur_x; j <= cur_x + len; j++) {
156
gongo@gendarme.local
parents: 155
diff changeset
292 TileInfoPtr tinfo = &tilist->tileinfo[j%MAX_TILE_LIST];
161
18c42658e0e7 texture の座標がマイナスになったあと、それを 0 にし忘れてた
gongo@localhost.localdomain
parents: 156
diff changeset
293 float tex_z
18c42658e0e7 texture の座標がマイナスになったあと、それを 0 にし忘れてた
gongo@localhost.localdomain
parents: 156
diff changeset
294 = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1);
18c42658e0e7 texture の座標がマイナスになったあと、それを 0 にし忘れてた
gongo@localhost.localdomain
parents: 156
diff changeset
295
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
296 localx = getLocalX(x-1+j);
156
gongo@gendarme.local
parents: 155
diff changeset
297
gongo@gendarme.local
parents: 155
diff changeset
298 tex_xpos = tinfo->tix;
gongo@gendarme.local
parents: 155
diff changeset
299 tex_ypos = tinfo->tiy;
gongo@gendarme.local
parents: 155
diff changeset
300 texture_image = tinfo->tile;
148
74341c8bf935 Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 147
diff changeset
301
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
302 if (tex_z < zRow[localx + (rangex*localy)]) {
156
gongo@gendarme.local
parents: 155
diff changeset
303 rgb = get_rgb(tex_xpos, tex_ypos, texture_image);
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
304 zRow[localx + (rangex*localy)] = tex_z;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
305 linebuf[localy][localx] = rgb;
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 }
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
308
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
309 smanager->dma_wait(TILE_INFO_LOAD);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
310
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
311 TileInfoListPtr tmp = tilist;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
312 tilist = next_tilist;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
313 next_tilist = tmp;
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
314
155
79ded2ad7236 TextureInfoList がずれてたのを修正
gongo@gendarme.local
parents: 148
diff changeset
315 cur_x += cur_x_diff;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
316 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
317 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
318 }
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
319
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
320 smanager->dma_wait(SPAN_PACK_LOAD);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
321
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
322 tmp_sp = sp;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
323 sp = next_sp;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
324 next_sp = tmp_sp;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
325 } while (sp);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
326
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
327 free(free_sp);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
328 free(linebuf);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
329 free(zRow);
128
95e2046eb46f texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 126
diff changeset
330 free(tileList);
147
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
331 free(tilist);
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 133
diff changeset
332 free(next_tilist);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
333
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
334 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
335 }