DEADSOFTWARE

render: move gfx-once objects into render code
[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 procedure r_Render_Load;
25 procedure r_Render_Free;
27 procedure r_Render_Apply;
29 implementation
31 uses
32 {$INCLUDE ../../nogl/noGLuses.inc}
33 SysUtils, Classes, Math,
34 e_log, g_system,
35 g_game, g_options, g_console,
36 r_window, r_graphics, r_console, r_playermodel,
37 r_weapons, r_items, r_gfx
38 ;
40 var
41 LoadedGL: Boolean = false;
43 procedure LoadGL;
44 begin
45 if LoadedGL = false then
46 begin
47 {$IFDEF NOGL_INIT}
48 nogl_Init;
49 if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
50 begin
51 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
52 glRenderToFBO := false
53 end;
54 {$ELSE}
55 if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then
56 begin
57 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
58 glRenderToFBO := false
59 end;
60 {$ENDIF}
61 LoadedGL := true
62 end
63 end;
65 procedure FreeGL;
66 begin
67 if LoadedGL = true then
68 begin
69 {$IFDEF NOGL_INIT}
70 nogl_Quit;
71 {$ENDIF}
72 LoadedGL := false
73 end
74 end;
76 procedure r_Render_Load;
77 begin
78 r_Weapon_Load;
79 r_Items_Load;
80 r_GFX_Load;
81 end;
83 procedure r_Render_Free;
84 begin
85 r_GFX_Free;
86 r_Items_Free;
87 r_Weapon_Free;
88 end;
90 procedure r_Render_Initialize;
91 begin
92 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then
93 raise Exception.Create('Failed to set videomode on startup.');
94 LoadGL;
95 r_Window_Initialize;
96 r_Console_Init;
97 r_PlayerModel_Initialize;
98 end;
100 procedure r_Render_Finalize;
101 begin
102 FreeGL;
103 r_PlayerModel_Finalize;
104 e_ReleaseEngine
105 end;
107 procedure r_Render_Resize (w, h: Integer);
108 begin
109 LoadGL;
110 gWinSizeX := w;
111 gWinSizeY := h;
112 gRC_Width := w;
113 gRC_Height := h;
114 if glRenderToFBO then
115 begin
116 // store real window size in gWinSize, downscale resolution now
117 w := round(w / r_pixel_scale);
118 h := round(h / r_pixel_scale);
119 if not e_ResizeFramebuffer(w, h) then
120 begin
121 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
122 glRenderToFBO := False;
123 w := gWinSizeX;
124 h := gWinSizeY;
125 end;
126 end;
127 gScreenWidth := w;
128 gScreenHeight := h;
129 e_ResizeWindow(w, h);
130 e_InitGL
131 end;
133 procedure r_Render_Apply;
134 begin
135 if sys_SetDisplayMode(Max(1, gRC_Width), Max(1, gRC_Height), Max(1, gBPP), gRC_FullScreen, gRC_Maximized) then
136 e_LogWriteln('resolution changed')
137 else
138 e_LogWriteln('resolution not changed');
139 sys_EnableVSync(gVSync)
140 end;
142 end.