|
This thread is locked; no one can reply to it. |
1
2
|
Quick Question about MSAA |
codetricity
Member #17,059
March 2019
|
I'm working on a game library for Delphi using Allegro5 and have a question about this. Does the window suppose to jiggle like this on startup when MSAA is enabled? Thanks
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Correction, I see it now. The window position noticeably stutters on window creation. Well, never seen that before. Can you post some system details? For instance I don't know what Delphi is. Please post your OS, compiler and version, allegro version, and some code that can demonstrate this. Posting source code is best, but a binary that demonstrates it built in debugging mode might suffice. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
Ok sure:
This is the code I use to open a window and set MSAA: 1procedure TDisplay.Open(aPosX: Integer; aPosY: Integer; aWidth: Integer; aHeight: Integer; aFullscreen: Boolean; aVSync: Boolean; aAntiAlias: Boolean; aTitle: string);
2var
3 value: Integer;
4 flags: Integer;
5 PosX: Integer;
6 PosY: Integer;
7
8 procedure ShowHideWindow(aShow: Boolean);
9 var
10 wh: HWND;
11 begin
12 wh := al_get_win_window_handle(FHandle);
13 if aShow then
14 ShowWindow(wh, SW_SHOW)
15 else
16 ShowWindow(wh, SW_HIDE);
17 end;
18
19begin
20 if FHandle = nil then
21 begin
22 flags := ALLEGRO_PROGRAMMABLE_PIPELINE;
23 FSize.Assign(0, 0, aWidth, aHeight);
24 if aVSync then
25 value := 1
26 else
27 value := 2;
28 al_set_new_display_option(ALLEGRO_VSYNC, value, ALLEGRO_SUGGEST);
29 al_set_new_display_option(ALLEGRO_CAN_DRAW_INTO_BITMAP, 1, ALLEGRO_SUGGEST);
30
31 PosX := gEngine.DefaultWindowPos.X;
32 PosY := gEngine.DefaultWindowPos.Y;
33
34 if aPosX > -1 then
35 PosX := aPosX;
36 if aPosY > -1 then
37 PosY := aPosY;
38
39 al_set_new_window_position(PosX, PosY);
40
41 if not aTitle.IsEmpty then
42 al_set_new_window_title(PAnsiChar(AnsiString(aTitle)));
43 if aFullscreen then
44 flags := flags or ALLEGRO_FULLSCREEN_WINDOW;
45 al_set_new_display_flags(flags);
46 FTitle := aTitle;
47 if aAntiAlias then
48 begin
49 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
50 al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
51 end;
52
53 FHandle := al_create_display(aWidth, aHeight);
54 if FHandle <> nil then
55 begin
56 LoadDefaultIcon;
57 TransformScale(aFullscreen);
58 al_register_event_source(gEngine.Queue, al_get_display_event_source(FHandle));
59 FIsFullscreen := aFullscreen;
60 end;
61 FVSync := aVSync;
62 end;
63
64end;
65
66function TDisplay.TransformScale(aFullscreen: Boolean): Single;
67var
68 screen_x, screen_y: Integer;
69 scale_x, scale_y: Single;
70 clip_x, clip_y: Single;
71 Scale: Single;
72begin
73 Result := 1;
74 if FHandle = nil then
75 Exit;
76
77 screen_x := al_get_display_width(FHandle);
78 screen_y := al_get_display_height(FHandle);
79
80 if aFullscreen then
81 begin
82 scale_x := screen_x / FSize.Width;
83 scale_y := screen_y / FSize.Height;
84 Scale := min(scale_x, scale_y);
85 clip_x := (screen_x - Scale * FSize.Width) / 2;
86 clip_y := (screen_y - Scale * FSize.Height) / 2;
87 // writeln('clip-y: ', clip_y:5:2);
88 al_build_transform(@FTrans, clip_x, clip_y, Scale, Scale, 0);
89 al_use_transform(@FTrans);
90 al_set_clipping_rectangle(Round(clip_x), Round(clip_y),
91 Round(screen_x - 2 * clip_x), Round(screen_y - 2 * clip_y));
92 FTransSize.Assign(clip_x, clip_y, screen_x - 2 * clip_x,
93 screen_y - 2 * clip_y);
94 Result := Scale;
95 FTransScale := Scale;
96
97 end
98 else
99 begin
100 al_identity_transform(@FTrans);
101 al_use_transform(@FTrans);
102 al_set_clipping_rectangle(0, 0, Round(screen_x), Round(screen_y));
103 FTransSize.Assign(0, 0, screen_x, screen_y);
104 FTransScale := 1;
105 end;
106end;
107
108procedure TDisplay.LoadDefaultIcon;
109var
110 wnd: HWND;
111 hnd: THandle;
112 ico: TIcon;
113begin
114 if FHandle = nil then Exit;
115 hnd := GetModuleHandle(nil);
116 if hnd <> 0 then
117 begin
118 if FindResource(hnd, 'MAINICON', RT_GROUP_ICON) <> 0 then
119 begin
120 ico := TIcon.Create;
121 ico.LoadFromResourceName(hnd, 'MAINICON');
122 wnd := al_get_win_window_handle(FHandle);
123 SendMessage(wnd, WM_SETICON, ICON_BIG, ico.Handle);
124 ico.Free;
125 end;
126 end;
127end;
Oh, in my testing, setting ALLEGRO_SAMPLES higher than 3, will result in the window stuttering. Thanks
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
First, let's see if we can replicate it in C alone. Here is some test code that enables multisampling on Windows 10 using MinGW-W64 gcc 8.1 : 1
2
3#include <allegro5/allegro.h>
4#include <allegro5/allegro_color.h>
5#include <allegro5/allegro_primitives.h>
6#include <allegro5/allegro_direct3d.h>
7
8#include <cstdio>
9#include <climits>
10
11int main(int argc, char **argv) {
12
13 if (!al_init()) {return 1;}
14 al_init_primitives_addon();
15 al_install_keyboard();
16
17 ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
18 if (!queue) {return 2;}
19 al_register_event_source(queue , al_get_keyboard_event_source());
20
21 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE);
22 al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
23
24 bool use_opengl = false;
25 if (use_opengl) {
26 al_set_new_display_flags(ALLEGRO_OPENGL);
27 }
28 else {
29 al_set_new_display_flags(ALLEGRO_DIRECT3D);
30 }
31 ALLEGRO_DISPLAY *display = al_create_display(1024, 600);
32 if (!display) {return 2;}
33 if (use_opengl) {
34 al_set_window_title(display , "OpenGL window");
35 }
36 else {
37 al_set_window_title(display , "Direct3D window");
38 }
39 al_register_event_source(queue , al_get_display_event_source(display));
40
41
42 al_clear_to_color(al_color_name("black"));
43 al_draw_circle(500, 300, 200, al_color_name("white"), 5.0);
44 al_draw_line(200, 200, 700, 300, al_color_name("white"), 5.0);
45 al_flip_display();
46
47 bool quit = false;
48 while (!quit) {
49 ALLEGRO_EVENT ev;
50 al_wait_for_event(queue , &ev);
51 if (ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {quit = true;}
52 if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {quit = true;}
53 }
54 return 0;
55}
However, I can't get it to jiggle. The window comes up directly. OpenGL takes longer, but still doesn't flicker. I'm using Allegro 5.2.5 My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
Hmmm. Interesting. Welp, looks likes something weird on my end. I will keep digging around and see what I can find. Thanks so much for the help with this. Respect! Update: If I add al_set_new_display_flags(ALLEGRO_OPENGL) and use OPENGL, I don't get the jiggle at all. Can you try Direct3D on your end? This may be the culprit.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Direct3D works for me with the code I posted above. Try compiling with MinGW first, and then Delphi, to rule out any funny business on Delphi's part. Edit, try this static exe that runs in D3D mode : My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
Hey, thanks for the sample to test. Yes, I get the jiggle with it as well. Maybe it's my NVIDIA drivers? I am using the latest versions, however. Sigh. Weird too that it only happens if it's > 3. Hmmm, looking in the log file, I see some D3D format fails, I wonder if this has anything to do with it? I attached the log.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
If it jiggles on your system and not mine, then it's some kind of difference between the two of our machines. We're both using Windows 10, so that shouldn't be it assuming you are up to date. I've got an older NVIDIA driver. That may be it, and I'm also running an onboard integrated Intel card. By Jove, that's it. I don't get the flicker with my integrated Intel, but I do when I run it with the NVIDIA. EDIT EDIT2 My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
Ahh, ok then. I'm not crazy, hehe. Bro big props to you for your help with this. Thank you. RESPECT!
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I would need to debug this to investigate further, but I've never even looked at the D3D code. It might take me some time to figure out what's going on where. For now, I would ask that you report this as a new issue on Github : My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
Ok, thanks.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
codetricity said: RESPECT! Ah, gratitude is always appreciated, and seldom given. You're welcome. So if you want, you could try debugging with gdb, if you have the knowledge necessary to navigate threads and frames, get a backtrace, print values, go to the 'next' line or 'step' into a function call, set breakpoints, etc... It looks like Delphi comes with a pretty nice Debugger, or was that just Rad? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
Yup, so true. It is what we need more of, especially this day and time — common courtesy and gratitude. The world has certainly changed in the past 20 years. I remember a time when "word was bond." Nowadays, people can be shaking your hand and stabbing you in the back, at the same time, haha! Crazy but true. Yes, Delphi (part of RAD Studio, include C++ Builder also) has a fantastic debugger. C++ Builder can consume Delphi code, and Delphi can consume C++ Builder/Visual Studio C OJB files (to a certain degree), but to use Allegro with Delphi the C headers had to be converted, and I dynamically link to the Allegro DLL (using the 32-bit monolithic one from the release page). I managed to compile the previous version using VS2017, but it was a lot of work and could not get some of the dependencies to compile. I eventually gave up. The reason I tried to compile myself was that at the time, the MinGW version (VS does not include a monolithic version) had some dependencies (something thread and one or two more), even on the monolithic one. I reported it and now seems this is now corrected, and allegro_monolith-5.2.dll in the latest release does not suffer from that problem. Just have to keep the headers updated now. So far, other than this issue, I've got 98% of my library ported from SDL2 (so many DLLs you have to include, 18+, sigh) and managed to fix/include/improve features that I've been looking to do for some time now. I am delighted to be using Allegro5.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
codetricity said: I've got 98% of my library ported from SDL2 ... I am delighted to be using Allegro5. Ah, revenge is sweet. EDIT EDIT2 If I ever manage to fix VS, I'll try to debug it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
Ok cool, thanks. Oh yea, I recently came across that similar issue as well. Ahh, that sucks bro, I know about updating hosing your working install all too well. Sigh.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I got Visual Studio fixed I'll look into this shortly. My laptop power adapter died a week ago and I've been without a computer. EDIT So, there's some funny business going on. The workhorse of d3d device creation is d3d_create_device and it keeps returning D3DERR_INVALIDCALL and I can't figure out why. That's why it flickers, because the window is being created and destroyed multiple times before it succeeds. I've enlisted the aid of Stack Overflow here : Hopefully someone can help me enable debugging output in DirectX because I haven't had any luck so far. EDIT2 Thanks EDIT3 https://github.com/EdgarReynaldo/allegro5 My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
GullRaDriel
Member #3,861
September 2003
|
Wooo Edgar, you finally got it !! "Code is like shit - it only smells if it is not yours" |
codetricity
Member #17,059
March 2019
|
Edgar Reynaldo said: It was due to an off by one error in the format list generation code. It should be fixed shortly after I finish up and make a patch. If anyone wants to help test, you can fork the 'test' branch of my allegro 5 fork here : I can confirm that it works. Many thanks!
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
So the code worked? And it was multisampled? In D3D mode on Nvidia? It's kind of tricky, because to get multisampling, you need D3DMULTISAMPLE_NONMASKABLE instead of D3DMULTISAMPLE_#_SAMPLES, which is really misleading. And quality levels in no way indicates the number of samples afaics, just the number of settings that are possible. :? ? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
Here is a demo: 1. run tbtestbed for no MSAA, run tbtestbed -msaa to enable msaa
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
MultiSamplingAntiAliasing is only good for primitives. Transformed bitmaps are not affected, so that doesn't really work. EDIT Even running them side by side they look pretty dang similar if not the same. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
yes, I understand this. my point is that the fonts rendered on screen are the new scaled change from the other thread. if you do not use -msaa, toggling between window/fullscreen they look good in both is what I'm getting at.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
see my edit - my eyes are not good enough to see a difference - where do you say it's visible? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
codetricity
Member #17,059
March 2019
|
1. run the tbtestbed with and without -msaa
|
GullRaDriel
Member #3,861
September 2003
|
It's crashing when I run it with -msaa in fullscreen. Edit: it's not compiled in debug mode. Or not with something readable for my gdb: Thread 1 received signal SIGSEGV, Segmentation fault. 0x0000002b in ?? () (gdb) bt #0 0x0000002b in ?? () #1 0x09bf8238 in ?? () Backtrace stopped: previous frame inner to this frame (corrupt stack?) The crash occur when I try to use fullscreen mode, when pressing F11. "Code is like shit - it only smells if it is not yours" |
|
1
2
|