DEADSOFTWARE

render: system: move gl related code from system driver
[d2df-sdl.git] / src / game / opengl / r_render.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_render;
18 interface
20 procedure r_Render_Initialize;
21 procedure r_Render_Finalize;
22 procedure r_Render_Resize (w, h: Integer);
24 implementation
26 uses
27 {$INCLUDE ../../nogl/noGLuses.inc}
28 SysUtils, Classes,
29 e_log, g_system,
30 g_game, g_options, r_window, r_graphics, r_console, r_playermodel
31 ;
33 var
34 LoadedGL: Boolean = false;
36 procedure LoadGL;
37 begin
38 if LoadedGL = false then
39 begin
40 {$IFDEF NOGL_INIT}
41 nogl_Init;
42 if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
43 begin
44 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
45 glRenderToFBO := false
46 end;
47 {$ELSE}
48 if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then
49 begin
50 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
51 glRenderToFBO := false
52 end;
53 {$ENDIF}
54 LoadedGL := true
55 end
56 end;
58 procedure FreeGL;
59 begin
60 if LoadedGL = true then
61 begin
62 {$IFDEF NOGL_INIT}
63 nogl_Quit
64 {$ENDIF}
65 LoadedGL := false
66 end
67 end;
69 procedure r_Render_Initialize;
70 begin
71 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then
72 raise Exception.Create('Failed to set videomode on startup.');
73 LoadGL;
74 r_Window_Initialize;
75 r_Console_Init;
76 r_PlayerModel_Initialize;
77 end;
79 procedure r_Render_Finalize;
80 begin
81 FreeGL;
82 r_PlayerModel_Finalize;
83 e_ReleaseEngine
84 end;
86 procedure r_Render_Resize (w, h: Integer);
87 begin
88 LoadGL;
89 gWinSizeX := w;
90 gWinSizeY := h;
91 gRC_Width := w;
92 gRC_Height := h;
93 if glRenderToFBO then
94 begin
95 // store real window size in gWinSize, downscale resolution now
96 w := round(w / r_pixel_scale);
97 h := round(h / r_pixel_scale);
98 if not e_ResizeFramebuffer(w, h) then
99 begin
100 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
101 glRenderToFBO := False;
102 w := gWinSizeX;
103 h := gWinSizeY;
104 end;
105 end;
106 gScreenWidth := w;
107 gScreenHeight := h;
108 e_ResizeWindow(w, h);
109 e_InitGL
110 end;
112 end.