Skip to content

Commit c752671

Browse files
author
elect-gombe
committed
バッファを複数行用意し高速化
1 parent 7358f20 commit c752671

File tree

6 files changed

+1024
-448
lines changed

6 files changed

+1024
-448
lines changed

main/3dmain.cpp

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "texturepoly.hpp"
1010
#include "lcd.h"
1111
#include <algorithm>
12+
#include "3dconfig.hpp"
1213

1314
#define ZSORT 0
1415

@@ -27,8 +28,11 @@ extern "C"{
2728
#define POINTNUM int(sizeof(pointvec)/sizeof(pointvec[0]))
2829
#define WIRENUM int(sizeof(wireframe)/sizeof(wireframe[0]))
2930

31+
#define MAXPROC_POLYNUM (POLYNUM*3/5)
32+
3033
vector3 pv[12][3];
3134

35+
3236
//-----------------------------------------------------------------------------
3337
// Read CCOUNT register.
3438
//-----------------------------------------------------------------------------
@@ -81,21 +85,29 @@ struct draworder_t{
8185
int draworder;
8286
int zdata;
8387
};
84-
draworder_t draworder[POLYNUM];
88+
draworder_t draworder[MAXPROC_POLYNUM];
8589
#endif
8690

91+
uint16_t *drawbuff[2];
92+
93+
float *zlinebuf;
94+
8795

8896
int main3d(void){
8997
Matrix4 m;
9098
Matrix4 projection;
9199
Matrix4 obj;
100+
int lastbuff = 0;
92101

93-
uint16_t drawbuff[2][window_width];
94-
95-
float zlinebuf[window_width];
96-
texturetriangle *t[POLYNUM];
102+
drawbuff[0] = new uint16_t[window_width*DRAW_NLINES];
103+
drawbuff[1] = new uint16_t[window_width*DRAW_NLINES];
104+
zlinebuf = new float[window_width*DRAW_NLINES];
105+
106+
texturetriangle *t[MAXPROC_POLYNUM];
97107

98-
for(int i=0;i<POLYNUM*3/4;i++){
108+
for(int i=0;i<MAXPROC_POLYNUM;i++){
109+
printf("%d\n",i);
110+
fflush(stdout);
99111
t[i] = new texturetriangle;
100112
}
101113

@@ -110,7 +122,7 @@ int main3d(void){
110122
fvector2 np = fvector2(440.f,0);
111123
vector2 pnp;
112124
bool clicking = false;
113-
float average = 20.f;
125+
float average = 0.f;
114126

115127
fvector4 vo[3];
116128
fvector4 v[3];
@@ -121,15 +133,20 @@ int main3d(void){
121133
uint32_t prev = 0;
122134

123135
veye = fvector3(0,0,-15.5f);
124-
obj = obj*magnify(2);
125-
send_first(0);
136+
obj = obj*magnify(0.995);
126137
while(1){
127138
{
128139
esp_task_wdt_feed(); // if(hogec!=0)
129140
// send_aline_finish();
130141
if(1){
131-
average = average *0.995+0.005*240000000.f/(xos_get_ccount()-prev);
132-
printf("%f %.2f fps/%.2f :%dface\n",np.x,240000000.f/(xos_get_ccount()-prev),average,tnum);
142+
if(prev){
143+
if(0&&average){
144+
average = average *0.9+0.1*240000000.f/(xos_get_ccount()-prev);
145+
}else{
146+
average = 240000000.f/(xos_get_ccount()-prev);
147+
}
148+
printf("%.2ffps tri:%d\n",average,tnum);
149+
}
133150
prev = xos_get_ccount();
134151
}
135152
tnum=0;
@@ -138,16 +155,16 @@ int main3d(void){
138155
np.x+=2.f; //camera rotation
139156
//視点計算
140157
#if MODEL == 1
141-
dist = 3.f + 1.4f*cosf(np.x/150.f*3.14159265358979324f);
158+
dist = 2.0f;// + 1.4f*cosf(np.x/150.f*3.14159265358979324f);
142159
#else
143-
dist = 5.f + 2.5f*cosf(np.x/150.f*3.14159265358979324f);
160+
dist = 3.5f + 1.5f*cosf(np.x/150.f*3.14159265358979324f);
144161
#endif
145162
veye = -fvector3(cosf(np.x/300.f*3.14159265f)*cosf(np.y/300.f*3.14159265f),sinf(np.y/300.f*3.14159265f),sinf(np.x/300.f*3.14159265f)*cosf(np.y/300.f*3.14159265f));
146163
//透視投影行列とカメラ行列の合成
147164
#if MODEL <= 3
148-
m=projection*lookat(fvector3(0,0,0),veye*dist)*obj;//*translation(fvector3(0,0,-0.7));
165+
m=projection*lookat(fvector3(0,0,0),veye*dist)*obj*translation(fvector3(0,-0.3,0));
149166
#else
150-
m=projection*lookat(fvector3(0,0,0),veye*dist)*obj*translation(fvector3(0,0,-0.7));
167+
m=projection*lookat(fvector3(0,0,0),veye*dist)*obj*translation(fvector3(0,0.3,-0.7));
151168
#endif
152169
//頂点データを変換
153170
for(int j=0;j<POINTNUM;j++){
@@ -201,25 +218,28 @@ int main3d(void){
201218

202219
#endif
203220
//ラインごとに描画しLCDに転送
204-
for(int y=0;y<window_height;y++){
205-
for(int i=0;i<window_width;i++){
221+
for(int y=0;y<window_height/DRAW_NLINES;y++){
222+
for(int i=0;i<window_width*DRAW_NLINES;i++){
206223
zlinebuf[i]=1.f;
207-
drawbuff[y&1][i]=0x0020;/*RGB*/
224+
drawbuff[lastbuff][i]=0x0020;/*RGB*/
208225
}
209226
for(int i=0;i<tnum;i++){
210227
#if ZSORT
211228
if(t[draworder[i].draworder]->ymin < y&&t[draworder[i].draworder]->ymax >= y){
212-
t[draworder[i].draworder]->draw(zlinebuf,drawbuff[y&1]);
229+
t[draworder[i].draworder]->draw(zlinebuf,drawbuff[lastbuff],y*DRAW_NLINES);
230+
}
213231
#else
214-
if(t[i]->ymin < y&&t[i]->ymax >= y){
215-
t[i]->draw(zlinebuf,drawbuff[y&1]);
216-
#endif
232+
233+
if(t[i]->ymin < (y*DRAW_NLINES)+DRAW_NLINES&&t[i]->ymax >= y*DRAW_NLINES){
234+
t[i]->draw(zlinebuf,drawbuff[lastbuff],y*DRAW_NLINES);
217235
}
236+
#endif
218237
}
219-
send_line(y,drawbuff[y&1]);
238+
send_line(y*DRAW_NLINES,drawbuff[lastbuff]);
239+
lastbuff = 1-lastbuff;
220240
}
221241
}
222-
for(int i=0;i<POLYNUM;i++){
242+
for(int i=0;i<MAXPROC_POLYNUM;i++){
223243
delete[] t[i];
224244
}
225245
}

main/graphiclib.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@
77
#include "vector2.hpp"
88
#include "fvector3.hpp"
99
#include <assert.h>
10-
10+
#include "3dconfig.hpp"
1111
#undef assert
1212
#define assert(x) (void)(x)
1313

1414
#ifndef __GRAPHICLIB_H
1515
#define __GRAPHICLIB_H
1616

1717
extern int frame;
18-
const static int window_width = 160;
19-
const static int window_height = 128;
20-
21-
extern const int window_width;
22-
extern const int window_height;
2318

2419
template <typename T>
2520
T min(T v1 , T v2) {

main/poly.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70367,3 +70367,4 @@ const uint16_t stonetex[65536] = {
7036770367
0x0000,
7036870368
0x0000
7036970369
};
70370+

0 commit comments

Comments
 (0)