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}
27 procedure r_Render_Initialize
;
28 procedure r_Render_Finalize
;
30 procedure r_Render_Load
;
31 procedure r_Render_Free
;
33 procedure r_Render_LoadTextures
;
34 procedure r_Render_FreeTextures
;
36 procedure r_Render_Update
;
37 procedure r_Render_Draw
;
39 procedure r_Render_Resize (w
, h
: Integer);
40 procedure r_Render_Apply
;
42 function r_Render_WriteScreenShot (filename
: String): Boolean;
45 function r_Render_GetGibRect (m
, id
: Integer): TRectWH
;
49 procedure r_Render_QueueEffect (AnimType
, X
, Y
: Integer);
53 // touch screen button location and size
54 procedure r_Render_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
58 procedure r_Render_GetControlSize (ctrl
: TGUIControl
; out w
, h
: Integer);
59 procedure r_Render_GetLogoSize (out w
, h
: Integer);
60 procedure r_Render_GetMaxFontSize (BigFont
: Boolean; out w
, h
: Integer);
61 procedure r_Render_GetStringSize (BigFont
: Boolean; str
: String; out w
, h
: Integer);
64 procedure r_Render_DrawLoading (force
: Boolean); // !!! remove it
69 {$INCLUDE ../../nogl/noGLuses.inc}
76 {$IFDEF ENABLE_SYSTEM}
82 SysUtils
, Classes
, Math
,
84 g_game
, g_options
, g_console
,
85 r_window
, r_graphics
, r_console
, r_playermodel
, r_textures
, r_animations
,
86 r_weapons
, r_items
, r_monsters
, r_map
, r_player
, r_game
90 LoadedGL
: Boolean = false;
92 function GLExtensionList (): SSArray
;
93 var s
: PChar; i
, j
, num
: GLint
;
96 s
:= glGetString(GL_EXTENSIONS
);
102 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
103 while (s
[i
] <> #0) do
105 while (s
[i
] <> #0) and (s
[i
] <> ' ') do Inc(i
);
106 SetLength(result
, num
+1);
107 result
[num
] := Copy(s
, j
+1, i
-j
);
108 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
115 function GLExtensionSupported (ext
: AnsiString): Boolean;
119 Result
:= nogl_ExtensionSupported(ext
);
122 for e
in GLExtensionList() do
124 if strEquCI1251(e
, ext
) then
133 function HaveNPOTSupport (): Boolean;
135 Result
:= GLExtensionSupported('GL_ARB_texture_non_power_of_two') or
136 GLExtensionSupported('GL_OES_texture_npot')
139 function HaveFBOSupport (): Boolean;
141 Result
:= GLExtensionSupported('GL_ARB_framebuffer_object') or
142 GLExtensionSupported('GL_OES_framebuffer_object')
145 procedure PrintGLSupportedExtensions
;
147 e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR
)]);
148 e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER
)]);
149 e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION
)]);
150 e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION
)]);
151 e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS
)]);
154 procedure r_Window_Initialize
;
156 {$IFNDEF USE_SYSSTUB}
157 PrintGLSupportedExtensions
;
158 glLegacyNPOT
:= not HaveNPOTSupport();
160 glLegacyNPOT
:= False;
161 glRenderToFBO
:= False;
163 if glNPOTOverride
and glLegacyNPOT
then
165 glLegacyNPOT
:= true;
166 e_logWriteln('NPOT texture emulation: FORCED')
171 e_logWriteln('NPOT texture emulation: enabled')
173 e_logWriteln('NPOT texture emulation: disabled')
178 var fboload
: Boolean;
180 if LoadedGL
= false then
185 if glRenderToFBO
then
189 fboload
:= True; // !!! but if not?
191 fboload
:= Load_GL_ARB_framebuffer_object();
193 if (fboload
= False) or (HaveFBOSupport() = False) or (HaveNPOTSupport() = False) then
195 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
196 glRenderToFBO
:= false
205 if LoadedGL
= true then
214 procedure r_Render_LoadTextures
;
220 procedure r_Render_FreeTextures
;
226 procedure r_Render_Load
;
228 r_Game_Load
; // load first!
243 procedure r_Render_Free
;
262 procedure r_Render_Initialize
;
264 {$IFDEF ENABLE_SYSTEM}
265 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = False then
266 raise Exception
.Create('Failed to set videomode on startup.');
271 r_PlayerModel_Initialize
;
275 procedure r_Render_Finalize
;
278 r_PlayerModel_Finalize
;
283 procedure r_Render_Update
;
289 r_PlayerModel_Update
;
293 procedure r_Render_Draw
;
296 {$IFDEF ENABLE_TOUCH}
301 procedure r_Render_Resize (w
, h
: Integer);
308 if glRenderToFBO
then
310 // store real window size in gWinSize, downscale resolution now
311 w
:= round(w
/ r_pixel_scale
);
312 h
:= round(h
/ r_pixel_scale
);
313 if not e_ResizeFramebuffer(w
, h
) then
315 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
316 glRenderToFBO
:= False;
323 e_ResizeWindow(w
, h
);
325 r_Game_SetupScreenSize
;
328 procedure r_Render_Apply
;
330 {$IFDEF ENABLE_SYSTEM}
331 if sys_SetDisplayMode(Max(1, gRC_Width
), Max(1, gRC_Height
), Max(1, gBPP
), gRC_FullScreen
, gRC_Maximized
) then
332 e_LogWriteln('resolution changed')
334 e_LogWriteln('resolution not changed');
335 sys_EnableVSync(gVSync
)
339 function r_Render_WriteScreenShot (filename
: String): Boolean;
344 s
:= CreateDiskFile(filename
);
346 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
357 function r_Render_GetGibRect (m
, id
: Integer): TRectWH
;
359 Result
:= r_PlayerModel_GetGibRect(m
, id
)
364 procedure r_Render_QueueEffect (AnimType
, X
, Y
: Integer);
366 r_GFX_OnceAnim(AnimType
, X
, Y
)
370 {$IFDEF ENABLE_TOUCH}
371 procedure r_Render_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
373 r_Touch_GetKeyRect (key
, x
, y
, w
, h
, founded
)
378 procedure r_Render_GetControlSize (ctrl
: TGUIControl
; out w
, h
: Integer);
380 r_GUI_GetSize(ctrl
, w
, h
)
383 procedure r_Render_GetLogoSize (out w
, h
: Integer);
385 r_GUI_GetLogoSize(w
, h
)
388 procedure r_Render_GetMaxFontSize (BigFont
: Boolean; out w
, h
: Integer);
390 r_GUI_GetMaxFontSize(BigFont
, w
, h
)
393 procedure r_Render_GetStringSize (BigFont
: Boolean; str
: String; out w
, h
: Integer);
395 r_GUI_GetStringSize(BigFont
, str
, w
, h
)
399 procedure r_Render_DrawLoading (force
: Boolean);
401 r_Window_DrawLoading(force
)