Hello,
I have the option to change multisampling configuration in the game.
I didn't want to be like those "lame" games that said: "You have to restart the game if you want to change this option"
So when the user changes the multisampling option, I destroy all bitmaps, fonts and display and create it again:
Shut down:
and create it again:
#SelectExpand
1 if (!al_init())
2 throw std::runtime_error
("failed to initialize allegro!");
3 al_set_new_display_flags(ALLEGRO_RESIZABLE
);
4 al_set_new_display_option(ALLEGRO_VSYNC,
1, ALLEGRO_SUGGEST
);
5 if (global->graphicsSettings->getMultisamplingLevel
() != 0)
6 {
7 al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR
| ALLEGRO_MAG_LINEAR
| ALLEGRO_VIDEO_BITMAP
);
8 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS,
1, ALLEGRO_SUGGEST
);
9 al_set_new_display_option(ALLEGRO_SAMPLES, global->graphicsSettings->getMultisamplingLevel
(), ALLEGRO_SUGGEST
);
10 }
11 else
12 {
13 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP
);
14 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS,
0, ALLEGRO_SUGGEST
);
15 al_set_new_display_option(ALLEGRO_SAMPLES,
0, ALLEGRO_SUGGEST
);
16 }
17
18 al_set_new_window_position(global->properties.get
<int>
("screen.x",
100),
19 global->properties.get
<int>
("screen.y",
100));
20
21 this->display
= al_create_display(global->properties.get
<int>
("screen.width",
800),
22 global->properties.get
<int>
("screen.height",
600));
23 if (!this->display
)
24 throw std::runtime_error
("failed to create display!");
25
26 if (!al_init_image_addon())
27 throw std::runtime_error
("Failed to initialize al_init_image_addon!");
28 if (!al_install_keyboard())
29 throw std::runtime_error
("failed to initialize the keyboard!");
30 if (!al_install_mouse())
31 throw std::runtime_error
("failed to initialize the mouse!");
32 al_init_font_addon();
33 if (!al_init_ttf_addon())
34 throw std::runtime_error
("failed to initialize the ttf addon!");
35 this->font
= al_load_ttf_font((global->resourcePath
/ "cm_ss_2012.ttf").string
().c_str
(),
22, ALLEGRO_TTF_RENDER_BORDER
);
36 if (!Display::font
)
37 throw std::runtime_error
("Could not load 'cm_ss_2012.ttf'.");
38 al_set_ttf_border
(this->font,
1,
al_map_rgb(0,
0,
100));
39 Display::itemCountFont
= al_load_ttf_font((global->resourcePath
/ "cm_ss_2012.ttf").string
().c_str
(),
16, ALLEGRO_TTF_RENDER_BORDER
);
40 if (!Display::itemCountFont
)
41 throw std::runtime_error
("Could not load 'cm_ss_2012.ttf'.");
42 al_set_ttf_border_color
(this->itemCountFont,
al_map_rgb(60,
60,
60));
43 if (!al_init_primitives_addon())
44 throw std::runtime_error
("failed to load primitives addon!");
45 if (!al_install_audio())
46 throw std::runtime_error
("Failed to install audio!");
47 if (!al_init_acodec_addon())
48 throw std::runtime_error
("Failed to initialize audio codecs!");
49 if (!al_reserve_samples(50))
50 throw std::runtime_error
("Failed to reserve samples!");
(I hope that calling something even when it wasn't shut down, like al_init, or al_install_audio isn't problem)
Anyway, when I change the multisampling option and restart graphics this way, everything works, just the VSYNC works on 1/2 of normal speed (30 fps instead of 60)
Any idea why is this happening?
PS. I'm making sure that the reason isn't performance, the game spends 10% of available time in the game loop rest in waiting for vsync.