DEADSOFTWARE

render: move more texture load code into render
[d2df-sdl.git] / src / game / opengl / r_window.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../shared/a_modes.inc}
16 unit r_window;
18 interface
20 procedure r_Window_DrawLoading (forceUpdate: Boolean);
21 procedure r_Window_Initialize;
23 implementation
25 uses
26 {$INCLUDE ../nogl/noGLuses.inc}
27 SysUtils, Classes,
28 e_log, utils,
29 r_graphics, r_game, r_console, g_system,
30 g_options, g_game, g_console,
31 xprofiler
32 ;
34 const
35 ProgressUpdateMSecs = 35; //1;//100;
37 var
38 prevLoadingUpdateTime: UInt64;
40 procedure r_Window_DrawLoading (forceUpdate: Boolean);
41 var stt: UInt64;
42 begin
43 if e_NoGraphics = False then
44 begin
45 if not forceUpdate then
46 begin
47 stt := getTimeMilli();
48 forceUpdate := (stt < prevLoadingUpdateTime) or (stt-prevLoadingUpdateTime >= ProgressUpdateMSecs);
49 end;
51 if forceUpdate then
52 begin
53 e_SetRendertarget(True);
54 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
56 r_Game_DrawMenuBackground('INTER');
57 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
58 r_Game_DrawLoadingStat();
59 r_Console_Draw(True);
61 e_SetRendertarget(False);
62 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
63 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
65 sys_Repaint;
66 prevLoadingUpdateTime := getTimeMilli();
67 end;
68 end;
69 end;
71 function GLExtensionList (): SSArray;
72 var s: PChar; i, j, num: GLint;
73 begin
74 result := nil;
75 s := glGetString(GL_EXTENSIONS);
76 if s <> nil then
77 begin
78 num := 0;
79 i := 0;
80 j := 0;
81 while (s[i] <> #0) and (s[i] = ' ') do Inc(i);
82 while (s[i] <> #0) do
83 begin
84 while (s[i] <> #0) and (s[i] <> ' ') do Inc(i);
85 SetLength(result, num+1);
86 result[num] := Copy(s, j+1, i-j);
87 while (s[i] <> #0) and (s[i] = ' ') do Inc(i);
88 j := i;
89 Inc(num)
90 end
91 end
92 end;
94 function GLExtensionSupported (ext: AnsiString): Boolean;
95 var e: AnsiString;
96 begin
97 result := false;
98 for e in GLExtensionList() do
99 begin
100 if strEquCI1251(e, ext) then
101 begin
102 result := true;
103 exit
104 end
105 end
106 end;
108 procedure PrintGLSupportedExtensions;
109 begin
110 e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR)]);
111 e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER)]);
112 e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION)]);
113 e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION)]);
114 e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS)]);
115 end;
117 procedure r_Window_Initialize;
118 begin
119 {$IFNDEF USE_SYSSTUB}
120 PrintGLSupportedExtensions;
121 glLegacyNPOT := not (GLExtensionSupported('GL_ARB_texture_non_power_of_two') or GLExtensionSupported('GL_OES_texture_npot'));
122 {$ELSE}
123 glLegacyNPOT := False;
124 glRenderToFBO := False;
125 {$ENDIF}
126 if glNPOTOverride and glLegacyNPOT then
127 begin
128 glLegacyNPOT := true;
129 e_logWriteln('NPOT texture emulation: FORCED')
130 end
131 else
132 begin
133 if glLegacyNPOT then
134 e_logWriteln('NPOT texture emulation: enabled')
135 else
136 e_logWriteln('NPOT texture emulation: disabled')
137 end
138 end;
140 end.