Skip to content

Commit 981ee5b

Browse files
committed
Mipmaps, refactor.
1 parent c6bb318 commit 981ee5b

15 files changed

Lines changed: 172 additions & 210 deletions

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
*.o
2+
GLIDE3X.DXE
3+
glide3x.dxe
4+
*.mrr
5+
*.MRR
6+
SETTINGS.DAT
7+
settings.dat
8+
interm
9+
interm.exe
10+
interm2
11+
interm2.exe
12+
openmrac.dat
13+
openmrac.exe
14+
set3dfx.exe
15+
glide3drv.h
16+
*.pro.user

src/Makefile.djgpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ OBJS := $(shell ls *.cpp | grep -v set3dfx.cpp | sed 's/.cpp/.djgpp.o/g' | tr
3232
all: $(TARGET) $(TARGET2)
3333

3434
clean:
35-
rm -f *.o $(TARGET) $(INTERM).exe $(INTERM) $(INTERM2).exe $(INTERM2) glide3drv_h/glide3drv.h $(TARGET_SET_3DFX)
35+
rm -f *.o $(TARGET) $(INTERM).exe $(INTERM) $(INTERM2).exe $(INTERM2) glide3drv_h/glide3drv.h $(TARGET2)
3636

3737
%.djgpp.o: %.cpp *.h
3838
$(CXX) -c $(CFLAGS) -o $@ $<

src/gamemng.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ void Gamemng::init(const char* maps_def, const char* objs_def, const char* cars_
518518
pictsmoke.loadpng(gbuff_in.fbuffptr(), gbuff_in.fbuffsz());
519519
gbuff_in.fclose();
520520
pictsmoke.r2a();
521-
pictsmoke.pack16();
522521
p_smoketex = load_texture(pictsmoke, false);
523522
}
524523
unsigned int fontsize[2] = {16, 6};
@@ -535,7 +534,6 @@ void Gamemng::init(const char* maps_def, const char* objs_def, const char* cars_
535534
gbuff_in.fclose();
536535
pictfont_rgba.r2a(pictfont_a);
537536
pictfont_rgba.scale(256, 256);
538-
pictfont_rgba.pack16();
539537
p_fonttex = load_texture(pictfont_rgba);
540538
p_glfont.set_texture(p_fonttex); // kvůli render_c();
541539

@@ -583,6 +581,7 @@ void Gamemng::init(const char* maps_def, const char* objs_def, const char* cars_
583581
p_ghostNew = new Ghost[4];
584582

585583
p_particles = new Particles[4];
584+
// p_particles = 0; // use this instead to disable smoke particles
586585
}
587586

588587
void Gamemng::input(unsigned char keys[4*4])
@@ -918,7 +917,7 @@ void Gamemng::render_frame()
918917
}
919918

920919
// smoke generation
921-
for (unsigned int i = 0; i != p_players; ++i)
920+
for (unsigned int i = 0; p_particles && i != p_players; ++i)
922921
{
923922
if (p_carrendermng[i].isVisible())
924923
{
@@ -1228,7 +1227,7 @@ void Gamemng::restart()
12281227

12291228
p_ghost_time = 0.f;
12301229

1231-
for (int i = 0; i != 4; ++i)
1230+
for (int i = 0; p_particles && i != 4; ++i)
12321231
{
12331232
p_particles[i].clear();
12341233
}

src/gamemng_frame.cpp

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -375,48 +375,51 @@ void Gamemng::frame(float deltaT)
375375

376376
}
377377

378-
while (p_particleTimesync.step()) // po částech času (0.01 s) se přepočítají částice
378+
if (p_particles)
379379
{
380-
MA_periodicStream();
381-
// přepočet částic postupně u všech hráčů (tzn. aut)
382-
for (unsigned int i = 0; i != p_players; ++i)
380+
while (p_particleTimesync.step()) // po částech času (0.01 s) se přepočítají částice
383381
{
384-
p_particles[i].step(p_timesync.p_T);
385-
int randValue = rand();
386-
bool generateNewParticle = false;
387-
bool lessParticles = !p_car2dp[i].p_b_acc;
388-
if (lessParticles)
389-
{
390-
generateNewParticle =
391-
//p_particles[i].m_stepCounter % 10 == 0;
392-
randValue < RAND_MAX * 0.1f;
393-
}
394-
else
382+
MA_periodicStream();
383+
// přepočet částic postupně u všech hráčů (tzn. aut)
384+
for (unsigned int i = 0; i != p_players; ++i)
395385
{
396-
generateNewParticle =
397-
p_particles[i].m_stepCounter % 5 == 0;
386+
p_particles[i].step(p_timesync.p_T);
387+
int randValue = rand();
388+
bool generateNewParticle = false;
389+
bool lessParticles = !p_car2dp[i].p_b_acc;
390+
if (lessParticles)
391+
{
392+
generateNewParticle =
393+
//p_particles[i].m_stepCounter % 10 == 0;
394+
randValue < RAND_MAX * 0.1f;
395+
}
396+
else
397+
{
398+
generateNewParticle =
399+
p_particles[i].m_stepCounter % 5 == 0;
398400
//randValue < RAND_MAX * 0.2f;
399-
}
400-
if (generateNewParticle)
401-
{
402-
glPushMatrix(); checkGL();
403-
glLoadIdentity(); checkGL();
404-
glRotatef(p_car2do[i].p_ax*57.29577951308232, 0, 1, 0); checkGL();
405-
float mdl_mtrx[16];
406-
glGetFloatv(GL_MODELVIEW_MATRIX, mdl_mtrx); checkGL();
407-
glPopMatrix(); checkGL();
408-
float exhaustPosition[3];
409-
multMatPos(exhaustPosition, mdl_mtrx, p_cars[p_cars_sel[i]].exhaust_position);
410-
float exhaustDirection[3];
411-
multMatDir(exhaustDirection, mdl_mtrx, p_cars[p_cars_sel[i]].exhaust_direction);
412-
float exhaustExitSpeed = lessParticles ? 0.9f : 1.1f;
413-
float densityMultiplier = lessParticles ? 0.5f : 1.f;
414-
p_particles[i].newParticle(Particle(exhaustPosition[0], exhaustPosition[1], exhaustPosition[2],
415-
exhaustDirection[0]*exhaustExitSpeed - 0.1f + 0.2f*static_cast<float>(rand())/RAND_MAX,
416-
exhaustDirection[1]*exhaustExitSpeed - 0.1f + 0.2f*static_cast<float>(rand())/RAND_MAX,
417-
exhaustDirection[2]*exhaustExitSpeed - 0.1f + 0.2f*static_cast<float>(rand())/RAND_MAX,
418-
rand() % 4, 0.04, 0.3,
419-
(0.55 + 0.1f*static_cast<float>(rand())/RAND_MAX) * densityMultiplier, 0.6 * densityMultiplier));
401+
}
402+
if (generateNewParticle)
403+
{
404+
glPushMatrix(); checkGL();
405+
glLoadIdentity(); checkGL();
406+
glRotatef(p_car2do[i].p_ax*57.29577951308232, 0, 1, 0); checkGL();
407+
float mdl_mtrx[16];
408+
glGetFloatv(GL_MODELVIEW_MATRIX, mdl_mtrx); checkGL();
409+
glPopMatrix(); checkGL();
410+
float exhaustPosition[3];
411+
multMatPos(exhaustPosition, mdl_mtrx, p_cars[p_cars_sel[i]].exhaust_position);
412+
float exhaustDirection[3];
413+
multMatDir(exhaustDirection, mdl_mtrx, p_cars[p_cars_sel[i]].exhaust_direction);
414+
float exhaustExitSpeed = lessParticles ? 0.9f : 1.1f;
415+
float densityMultiplier = lessParticles ? 0.5f : 1.f;
416+
p_particles[i].newParticle(Particle(exhaustPosition[0], exhaustPosition[1], exhaustPosition[2],
417+
exhaustDirection[0]*exhaustExitSpeed - 0.1f + 0.2f*static_cast<float>(rand())/RAND_MAX,
418+
exhaustDirection[1]*exhaustExitSpeed - 0.1f + 0.2f*static_cast<float>(rand())/RAND_MAX,
419+
exhaustDirection[2]*exhaustExitSpeed - 0.1f + 0.2f*static_cast<float>(rand())/RAND_MAX,
420+
rand() % 4, 0.04, 0.3,
421+
(0.55 + 0.1f*static_cast<float>(rand())/RAND_MAX) * densityMultiplier, 0.6 * densityMultiplier));
422+
}
420423
}
421424
}
422425
}
@@ -435,7 +438,6 @@ void Gamemng::frame(float deltaT)
435438
p_mapobjs[i].rbo->update(false);
436439
}
437440

438-
439441
if (p_state == 0)
440442
{
441443
p_state0_time += deltaT;

src/gamemng_load.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ bool Gamemng::load(int players_sel, const int* cars_sel, const int* cars_tex_sel
4646
pict.loadpng(gbuff_in.fbuffptr(), gbuff_in.fbuffsz());
4747
gbuff_in.fclose();
4848
pict.scale(256, 256);
49-
pict.pack16();
5049
GLuint skytex = load_texture(pict);
5150
glBindTexture(GL_TEXTURE_2D, skytex); checkGL();
5251
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); checkGL(); // vertikálně se textura neopakuje
@@ -218,7 +217,10 @@ bool Gamemng::load(int players_sel, const int* cars_sel, const int* cars_tex_sel
218217
p_sound_car[i].init(p_sound_game_static.p_engine0_stream[i], p_sound_game_static.p_engine1_stream[i], p_cars[cars_sel[i]].engine1_pitch, p_sound_game_static.p_skid_stream[i], i, p_players);
219218

220219
// částice
221-
p_particles[i].clear();
220+
if (p_particles)
221+
{
222+
p_particles[i].clear();
223+
}
222224
}
223225

224226
p_car2do = new RBSolver[p_players];

src/load_texture.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <cstdio>
55

66
unsigned int g_texture_memory_usage = 0;
7-
8-
extern int g_textureFiltering;
7+
int g_textureFiltering = 0; // 0 - bilinear, 1 - trilinear, 2 - aniso
8+
int g_textureMipmaps = 0; // 0 - off, 1 - on
99

1010
static const GLint textureWrap = GL_REPEAT;
1111

@@ -18,42 +18,58 @@ void subMem(int w, int h)
1818
memory -= w * h * 2;
1919
}
2020

21-
GLuint load_texture(const Pict2& pict, bool /*bmipmap*/)
21+
GLuint load_texture(Pict2 pict, bool bmipmap)
2222
{
23+
pict.cropNpotH();
24+
2325
memory += pict.w() * pict.h() * 2;
2426
//printf("texmem usage: %u\n", memory); fflush(stdout);
2527

26-
if (bits_count(pict.w()) != 1)
27-
return 0;
28-
if (bits_count(pict.h()) != 1 && bits_count(pict.h()+1) != 1)
28+
if (g_textureMipmaps == 0)
29+
{
30+
bmipmap = false;
31+
}
32+
GLint packAlignment;
33+
glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
34+
35+
pict.pack16(packAlignment);
36+
37+
if (bits_count(pict.w()) != 1 || bits_count(pict.h()) != 1)
2938
return 0;
39+
/*if (bits_count(pict.h()) != 1 && bits_count(pict.h()+1) != 1)
40+
return 0;*/
3041
{
3142
GLuint textura;
3243
glGenTextures(1, &textura); checkGL();
3344
glBindTexture(GL_TEXTURE_2D, textura); checkGL();
34-
//if (!bmipmap) // no mipmaps
35-
{
36-
unsigned int pict_h = pict.h();
37-
if (bits_count(pict.h()) != 1 && bits_count(pict.h()+1) == 1) // předpřipravené mipmapy
38-
pict_h = (pict.h()+1)/2;
3945

40-
if (pict.packed565)
46+
for (int level = 0;;++level)
47+
{
48+
unsigned int pict_h = bits_crop_npot(pict.h());
49+
g_texture_memory_usage += 4*pict.w()*pict_h;
50+
if (pict.p_hasAlpha)
4151
{
42-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pict.w(), pict_h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pict.c_px()); checkGL();
52+
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, pict.w(), pict_h, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pict.c_ppx()); checkGL();
4353
}
4454
else
4555
{
46-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pict.w(), pict_h, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pict.c_px()); checkGL();
56+
glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, pict.w(), pict_h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pict.c_ppx()); checkGL();
4757
}
58+
if (!bmipmap || (pict_h == 1 && pict.w() == 1)) break;
59+
int newW = pict.w() >> 1;
60+
int newH = pict_h >> 1;
61+
if (newW == 0) newW = 1;
62+
if (newH == 0) newH = 1;
63+
pict.scale(newW, newH);
64+
pict.pack16(packAlignment);
65+
}
4866

67+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, bmipmap ? (g_textureFiltering == 0 ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR) : GL_LINEAR); checkGL();
68+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); checkGL();
4969

50-
g_texture_memory_usage += 4*pict.w()*pict_h;
51-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); checkGL();
52-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); checkGL();
70+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, textureWrap); checkGL();
71+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, textureWrap); checkGL();
5372

54-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, textureWrap); checkGL();
55-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, textureWrap); checkGL();
56-
}
5773
glBindTexture(GL_TEXTURE_2D, 0); checkGL();
5874
return textura;
5975
}

src/load_texture.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#include <GL/gl.h>
55
#include "pict2.h"
66

7-
GLuint load_texture(const Pict2& pict, bool bmipmap = false);
7+
GLuint load_texture(Pict2 pict, bool bmipmap = false);
88

99
void subMem(int w, int h);
1010

1111
extern unsigned int g_texture_memory_usage;
12+
extern int g_textureFiltering;
13+
extern int g_textureMipmaps;
1214

1315
#endif

src/main.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,10 @@ static uint8_t cntNow = 0;
7676

7777
float getdeltaT()
7878
{
79-
//if (cntPrev == cntNow) return 0.01f;
80-
//return 0.01f;
81-
//return 1.0/60.0;
82-
8379
cntNow = intCounter;
8480
uint8_t diff = cntNow - cntPrev;
8581
cntPrev = cntNow;
8682
return diff * 0.01f;
87-
88-
//return 0.01f;
8983
}
9084

9185
// odkazy na různá místa projektu:
@@ -125,7 +119,6 @@ int g_ghost_w = 0;
125119
int g_ghost_h = 0;
126120

127121
//int g_multisampleMode = 0; // 0 - 0ff, 1 - 2x, 2 - 4x
128-
int g_textureFiltering = 0; // 0 - bilinear, 1 - trilinear, 2 - aniso
129122

130123
void saveTgaScreenshot()
131124
{
@@ -312,11 +305,8 @@ int my_main (int argc, char** argv)
312305
SDL_JoystickEventState(SDL_ENABLE);
313306
}
314307
}
315-
316308
initializeParametersIndices(joystickDevices);*/
317309

318-
319-
320310
gfx_dos_init_impl(settings.get("screen_x"), settings.get("screen_y"));
321311

322312
glClearColor(0, 0, 0, 0);
@@ -426,6 +416,8 @@ int my_main (int argc, char** argv)
426416
gamemng.init_sound();
427417

428418
g_hq_textures = settings.get("hq_textures");
419+
g_textureFiltering = settings.get("texture_filter");
420+
g_textureMipmaps = settings.get("mipmaps");
429421

430422
MainMenu menu;
431423
menu.init(&gamemng, &settings);

src/mainmenu.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -363,26 +363,16 @@ void MainMenu::menu()
363363
// tady načíst všechny textury
364364

365365
Pict2 pictlogo_rgba;
366-
bool pictlogoPng = gbuff_in.f_open("logo-silver-d.png", "rb");
367-
if (pictlogoPng)
368-
{
369-
pictlogo_rgba.loadpng(gbuff_in.fbuffptr(), gbuff_in.fbuffsz());
370-
gbuff_in.fclose();
366+
gbuff_in.f_open("logo-silver-d.png", "rb");
367+
pictlogo_rgba.loadpng(gbuff_in.fbuffptr(), gbuff_in.fbuffsz());
368+
gbuff_in.fclose();
371369

372-
Pict2 pictlogo_a;
373-
gbuff_in.f_open("logo-silver-a.png", "rb");
374-
pictlogo_a.loadpng(gbuff_in.fbuffptr(), gbuff_in.fbuffsz());
375-
gbuff_in.fclose();
376-
pictlogo_rgba.r2a(pictlogo_a);
377-
pictlogo_rgba.scale(256, 256);
378-
pictlogo_rgba.pack16();
379-
}
380-
else
381-
{
382-
gbuff_in.f_open("logo-silver.omg", "rb");
383-
pictlogo_rgba.loadomg(gbuff_in.fbuffptr(), gbuff_in.fbuffsz());
384-
gbuff_in.fclose();
385-
}
370+
Pict2 pictlogo_a;
371+
gbuff_in.f_open("logo-silver-a.png", "rb");
372+
pictlogo_a.loadpng(gbuff_in.fbuffptr(), gbuff_in.fbuffsz());
373+
gbuff_in.fclose();
374+
pictlogo_rgba.r2a(pictlogo_a);
375+
pictlogo_rgba.scale(256, 256);
386376

387377
p_logo_textura = load_texture(pictlogo_rgba);
388378

@@ -403,7 +393,6 @@ void MainMenu::menu()
403393
{
404394
pict_th.scale(128, 128);
405395
}
406-
pict_th.pack16();
407396
p_gamemng->p_cars[i].pict_tex[j].tex = load_texture(pict_th);
408397
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); checkGL(); // textura se neopakuje
409398
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); checkGL(); // textura se neopakuje
@@ -423,7 +412,6 @@ void MainMenu::menu()
423412
{
424413
pict_th.scale(128, 128);
425414
}
426-
pict_th.pack16();
427415
p_gamemng->p_maps[i].pict_tex = load_texture(pict_th);
428416
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); checkGL(); // textura se neopakuje
429417
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); checkGL(); // textura se neopakuje

0 commit comments

Comments
 (0)