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;
40 function r_Render_GetGibRect (m
, id
: Integer): TRectWH
;
44 procedure r_Render_QueueEffect (AnimType
, X
, Y
: Integer);
48 // touch screen button location and size
49 procedure r_Render_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
52 procedure r_Render_DrawLoading (force
: Boolean); // !!! remove it
57 {$INCLUDE ../../nogl/noGLuses.inc}
64 {$IFDEF ENABLE_SYSTEM}
70 SysUtils
, Classes
, Math
,
72 g_game
, g_options
, g_console
,
73 r_window
, r_graphics
, r_console
, r_playermodel
, r_textures
, r_animations
,
74 r_weapons
, r_items
, r_monsters
, r_map
, r_player
, r_game
78 LoadedGL
: Boolean = false;
80 function GLExtensionList (): SSArray
;
81 var s
: PChar; i
, j
, num
: GLint
;
84 s
:= glGetString(GL_EXTENSIONS
);
90 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
93 while (s
[i
] <> #0) and (s
[i
] <> ' ') do Inc(i
);
94 SetLength(result
, num
+1);
95 result
[num
] := Copy(s
, j
+1, i
-j
);
96 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
103 function GLExtensionSupported (ext
: AnsiString): Boolean;
107 Result
:= nogl_ExtensionSupported(ext
);
110 for e
in GLExtensionList() do
112 if strEquCI1251(e
, ext
) then
121 function HaveNPOTSupport (): Boolean;
123 Result
:= GLExtensionSupported('GL_ARB_texture_non_power_of_two') or
124 GLExtensionSupported('GL_OES_texture_npot')
127 function HaveFBOSupport (): Boolean;
129 Result
:= GLExtensionSupported('GL_ARB_framebuffer_object') or
130 GLExtensionSupported('GL_OES_framebuffer_object')
133 procedure PrintGLSupportedExtensions
;
135 e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR
)]);
136 e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER
)]);
137 e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION
)]);
138 e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION
)]);
139 e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS
)]);
142 procedure r_Window_Initialize
;
144 {$IFNDEF USE_SYSSTUB}
145 PrintGLSupportedExtensions
;
146 glLegacyNPOT
:= not HaveNPOTSupport();
148 glLegacyNPOT
:= False;
149 glRenderToFBO
:= False;
151 if glNPOTOverride
and glLegacyNPOT
then
153 glLegacyNPOT
:= true;
154 e_logWriteln('NPOT texture emulation: FORCED')
159 e_logWriteln('NPOT texture emulation: enabled')
161 e_logWriteln('NPOT texture emulation: disabled')
166 var fboload
: Boolean;
168 if LoadedGL
= false then
173 if glRenderToFBO
then
177 fboload
:= True; // !!! but if not?
179 fboload
:= Load_GL_ARB_framebuffer_object();
181 if (fboload
= False) or (HaveFBOSupport() = False) or (HaveNPOTSupport() = False) then
183 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
184 glRenderToFBO
:= false
193 if LoadedGL
= true then
202 procedure r_Render_LoadTextures
;
208 procedure r_Render_FreeTextures
;
214 procedure r_Render_Load
;
216 r_Game_Load
; // load first!
231 procedure r_Render_Free
;
250 procedure r_Render_Initialize
;
252 {$IFDEF ENABLE_SYSTEM}
253 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = False then
254 raise Exception
.Create('Failed to set videomode on startup.');
259 r_PlayerModel_Initialize
;
263 procedure r_Render_Finalize
;
266 r_PlayerModel_Finalize
;
271 procedure r_Render_Update
;
277 r_PlayerModel_Update
;
281 procedure r_Render_Draw
;
284 {$IFDEF ENABLE_TOUCH}
289 procedure r_Render_Resize (w
, h
: Integer);
296 if glRenderToFBO
then
298 // store real window size in gWinSize, downscale resolution now
299 w
:= round(w
/ r_pixel_scale
);
300 h
:= round(h
/ r_pixel_scale
);
301 if not e_ResizeFramebuffer(w
, h
) then
303 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
304 glRenderToFBO
:= False;
311 e_ResizeWindow(w
, h
);
313 r_Game_SetupScreenSize
;
316 procedure r_Render_Apply
;
318 {$IFDEF ENABLE_SYSTEM}
319 if sys_SetDisplayMode(Max(1, gRC_Width
), Max(1, gRC_Height
), Max(1, gBPP
), gRC_FullScreen
, gRC_Maximized
) then
320 e_LogWriteln('resolution changed')
322 e_LogWriteln('resolution not changed');
323 sys_EnableVSync(gVSync
)
327 function r_Render_WriteScreenShot (filename
: String): Boolean;
332 s
:= CreateDiskFile(filename
);
334 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
345 function r_Render_GetGibRect (m
, id
: Integer): TRectWH
;
347 Result
:= r_PlayerModel_GetGibRect(m
, id
)
352 procedure r_Render_QueueEffect (AnimType
, X
, Y
: Integer);
354 r_GFX_OnceAnim(AnimType
, X
, Y
)
358 {$IFDEF ENABLE_TOUCH}
359 procedure r_Render_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
361 r_Touch_GetKeyRect (key
, x
, y
, w
, h
, founded
)
365 procedure r_Render_DrawLoading (force
: Boolean);
367 r_Window_DrawLoading(force
)