1 (* Copyright (C) Doom 2D: Forever Developers
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.
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.
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/>.
15 {$INCLUDE ../../shared/a_modes.inc}
20 uses g_base
; // TRectWH
22 procedure r_Render_Initialize
;
23 procedure r_Render_Finalize
;
25 procedure r_Render_Load
;
26 procedure r_Render_Free
;
28 procedure r_Render_LoadTextures
;
29 procedure r_Render_FreeTextures
;
31 procedure r_Render_Update
;
32 procedure r_Render_Draw
;
34 procedure r_Render_Resize (w
, h
: Integer);
35 procedure r_Render_Apply
;
37 function r_Render_WriteScreenShot (filename
: String): Boolean;
39 function r_Render_GetGibRect (m
, id
: Integer): TRectWH
;
42 procedure r_Render_QueueEffect (AnimType
, X
, Y
: Integer);
46 // touch screen button location and size
47 procedure r_Render_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
50 procedure r_Render_DrawLoading (force
: Boolean); // !!! remove it
55 {$INCLUDE ../../nogl/noGLuses.inc}
62 SysUtils
, Classes
, Math
,
63 e_log
, g_system
, utils
,
64 g_game
, g_options
, g_console
,
65 r_window
, r_graphics
, r_console
, r_playermodel
, r_textures
, r_animations
,
66 r_weapons
, r_items
, r_monsters
, r_map
, r_player
, r_game
70 LoadedGL
: Boolean = false;
72 function GLExtensionList (): SSArray
;
73 var s
: PChar; i
, j
, num
: GLint
;
76 s
:= glGetString(GL_EXTENSIONS
);
82 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
85 while (s
[i
] <> #0) and (s
[i
] <> ' ') do Inc(i
);
86 SetLength(result
, num
+1);
87 result
[num
] := Copy(s
, j
+1, i
-j
);
88 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
95 function GLExtensionSupported (ext
: AnsiString): Boolean;
99 Result
:= nogl_ExtensionSupported(ext
);
102 for e
in GLExtensionList() do
104 if strEquCI1251(e
, ext
) then
113 function HaveNPOTSupport (): Boolean;
115 Result
:= GLExtensionSupported('GL_ARB_texture_non_power_of_two') or
116 GLExtensionSupported('GL_OES_texture_npot')
119 function HaveFBOSupport (): Boolean;
121 Result
:= GLExtensionSupported('GL_ARB_framebuffer_object') or
122 GLExtensionSupported('GL_OES_framebuffer_object')
125 procedure PrintGLSupportedExtensions
;
127 e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR
)]);
128 e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER
)]);
129 e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION
)]);
130 e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION
)]);
131 e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS
)]);
134 procedure r_Window_Initialize
;
136 {$IFNDEF USE_SYSSTUB}
137 PrintGLSupportedExtensions
;
138 glLegacyNPOT
:= not HaveNPOTSupport();
140 glLegacyNPOT
:= False;
141 glRenderToFBO
:= False;
143 if glNPOTOverride
and glLegacyNPOT
then
145 glLegacyNPOT
:= true;
146 e_logWriteln('NPOT texture emulation: FORCED')
151 e_logWriteln('NPOT texture emulation: enabled')
153 e_logWriteln('NPOT texture emulation: disabled')
158 var fboload
: Boolean;
160 if LoadedGL
= false then
165 if glRenderToFBO
then
169 fboload
:= True; // !!! but if not?
171 fboload
:= Load_GL_ARB_framebuffer_object();
173 if (fboload
= False) or (HaveFBOSupport() = False) or (HaveNPOTSupport() = False) then
175 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
176 glRenderToFBO
:= false
185 if LoadedGL
= true then
194 procedure r_Render_LoadTextures
;
200 procedure r_Render_FreeTextures
;
206 procedure r_Render_Load
;
208 r_Game_Load
; // load first!
220 procedure r_Render_Free
;
236 procedure r_Render_Initialize
;
238 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = False then
239 raise Exception
.Create('Failed to set videomode on startup.');
243 r_PlayerModel_Initialize
;
247 procedure r_Render_Finalize
;
250 r_PlayerModel_Finalize
;
255 procedure r_Render_Update
;
261 r_PlayerModel_Update
;
265 procedure r_Render_Draw
;
268 {$IFDEF ENABLE_TOUCH}
273 procedure r_Render_Resize (w
, h
: Integer);
280 if glRenderToFBO
then
282 // store real window size in gWinSize, downscale resolution now
283 w
:= round(w
/ r_pixel_scale
);
284 h
:= round(h
/ r_pixel_scale
);
285 if not e_ResizeFramebuffer(w
, h
) then
287 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
288 glRenderToFBO
:= False;
295 e_ResizeWindow(w
, h
);
297 r_Game_SetupScreenSize
;
300 procedure r_Render_Apply
;
302 if sys_SetDisplayMode(Max(1, gRC_Width
), Max(1, gRC_Height
), Max(1, gBPP
), gRC_FullScreen
, gRC_Maximized
) then
303 e_LogWriteln('resolution changed')
305 e_LogWriteln('resolution not changed');
306 sys_EnableVSync(gVSync
)
309 function r_Render_WriteScreenShot (filename
: String): Boolean;
314 s
:= CreateDiskFile(filename
);
316 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
326 function r_Render_GetGibRect (m
, id
: Integer): TRectWH
;
328 Result
:= r_PlayerModel_GetGibRect(m
, id
)
332 procedure r_Render_QueueEffect (AnimType
, X
, Y
: Integer);
334 r_GFX_OnceAnim(AnimType
, X
, Y
)
338 {$IFDEF ENABLE_TOUCH}
339 procedure r_Render_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
341 r_Touch_GetKeyRect (key
, x
, y
, w
, h
, founded
)
345 procedure r_Render_DrawLoading (force
: Boolean);
347 r_Window_DrawLoading(force
)