DEADSOFTWARE

render: use only r_render to access render
[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 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;
33 procedure r_Render_Resize (w, h: Integer);
34 procedure r_Render_Apply;
36 function r_Render_WriteScreenShot (filename: String): Boolean;
38 function r_Render_GetGibRect (m, id: Integer): TRectWH;
39 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
41 procedure r_Render_DrawLoading (force: Boolean); // !!! remove it
43 implementation
45 uses
46 {$INCLUDE ../../nogl/noGLuses.inc}
47 SysUtils, Classes, Math,
48 e_log, g_system, utils,
49 g_game, g_options, g_console,
50 r_window, r_graphics, r_console, r_playermodel, r_textures, r_animations,
51 r_weapons, r_items, r_gfx, r_monsters, r_map, r_player, r_game
52 ;
54 var
55 LoadedGL: Boolean = false;
57 procedure LoadGL;
58 begin
59 if LoadedGL = false then
60 begin
61 {$IFDEF NOGL_INIT}
62 nogl_Init;
63 if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
64 begin
65 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
66 glRenderToFBO := false
67 end;
68 {$ELSE}
69 if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then
70 begin
71 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
72 glRenderToFBO := false
73 end;
74 {$ENDIF}
75 LoadedGL := true
76 end
77 end;
79 procedure FreeGL;
80 begin
81 if LoadedGL = true then
82 begin
83 {$IFDEF NOGL_INIT}
84 nogl_Quit;
85 {$ENDIF}
86 LoadedGL := false
87 end
88 end;
90 procedure r_Render_LoadTextures;
91 begin
92 r_Game_LoadTextures;
93 r_Map_LoadTextures;
94 end;
96 procedure r_Render_FreeTextures;
97 begin
98 r_Map_FreeTextures;
99 r_Game_FreeTextures;
100 end;
102 procedure r_Render_Load;
103 begin
104 r_Game_Load; // load first!
105 r_Player_Load;
106 r_Map_Load;
107 r_PlayerModel_Load;
108 r_Monsters_Load;
109 r_Weapon_Load;
110 r_Items_Load;
111 r_GFX_Load;
112 end;
114 procedure r_Render_Free;
115 begin
116 r_GFX_Free;
117 r_Items_Free;
118 r_Weapon_Free;
119 r_Monsters_Free;
120 r_PlayerModel_Free;
121 r_Map_Free;
122 r_Player_Free;
123 r_Game_Free;
124 g_Texture_DeleteAll;
125 g_Frames_DeleteAll;
126 end;
128 procedure r_Render_Initialize;
129 begin
130 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then
131 raise Exception.Create('Failed to set videomode on startup.');
132 LoadGL;
133 r_Window_Initialize;
134 r_Console_Init;
135 r_PlayerModel_Initialize;
136 r_Map_Initialize;
137 end;
139 procedure r_Render_Finalize;
140 begin
141 r_Map_Finalize;
142 r_PlayerModel_Finalize;
143 FreeGL;
144 e_ReleaseEngine
145 end;
147 procedure r_Render_Update;
148 begin
149 r_GFX_Update;
150 r_Map_Update;
151 r_PlayerModel_Update;
152 r_Console_Update;
153 end;
155 procedure r_Render_Resize (w, h: Integer);
156 begin
157 LoadGL;
158 gWinSizeX := w;
159 gWinSizeY := h;
160 gRC_Width := w;
161 gRC_Height := h;
162 if glRenderToFBO then
163 begin
164 // store real window size in gWinSize, downscale resolution now
165 w := round(w / r_pixel_scale);
166 h := round(h / r_pixel_scale);
167 if not e_ResizeFramebuffer(w, h) then
168 begin
169 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
170 glRenderToFBO := False;
171 w := gWinSizeX;
172 h := gWinSizeY;
173 end;
174 end;
175 gScreenWidth := w;
176 gScreenHeight := h;
177 e_ResizeWindow(w, h);
178 e_InitGL;
179 r_Game_SetupScreenSize;
180 end;
182 procedure r_Render_Apply;
183 begin
184 if sys_SetDisplayMode(Max(1, gRC_Width), Max(1, gRC_Height), Max(1, gBPP), gRC_FullScreen, gRC_Maximized) then
185 e_LogWriteln('resolution changed')
186 else
187 e_LogWriteln('resolution not changed');
188 sys_EnableVSync(gVSync)
189 end;
191 function r_Render_WriteScreenShot (filename: String): Boolean;
192 var s: TStream;
193 begin
194 Result := False;
195 try
196 s := CreateDiskFile(filename);
197 try
198 e_MakeScreenshot(s, gWinSizeX, gWinSizeX);
199 Result := True;
200 except
201 DeleteFile(filename)
202 end;
203 s.Free;
204 finally
205 end
206 end;
208 function r_Render_GetGibRect (m, id: Integer): TRectWH;
209 begin
210 Result := r_PlayerModel_GetGibRect(m, id)
211 end;
213 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
214 begin
215 r_GFX_OnceAnim(AnimType, X, Y)
216 end;
218 procedure r_Render_DrawLoading (force: Boolean);
219 begin
220 r_Window_DrawLoading(force)
221 end;
223 end.