DEADSOFTWARE

c424e51771c8efddda4b51d51fa391f053d6ad8b
[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
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 end;
82 procedure r_Render_Free;
83 begin
84 r_Items_Free;
85 r_Weapon_Free;
86 end;
88 procedure r_Render_Initialize;
89 begin
90 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then
91 raise Exception.Create('Failed to set videomode on startup.');
92 LoadGL;
93 r_Window_Initialize;
94 r_Console_Init;
95 r_PlayerModel_Initialize;
96 end;
98 procedure r_Render_Finalize;
99 begin
100 FreeGL;
101 r_PlayerModel_Finalize;
102 e_ReleaseEngine
103 end;
105 procedure r_Render_Resize (w, h: Integer);
106 begin
107 LoadGL;
108 gWinSizeX := w;
109 gWinSizeY := h;
110 gRC_Width := w;
111 gRC_Height := h;
112 if glRenderToFBO then
113 begin
114 // store real window size in gWinSize, downscale resolution now
115 w := round(w / r_pixel_scale);
116 h := round(h / r_pixel_scale);
117 if not e_ResizeFramebuffer(w, h) then
118 begin
119 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
120 glRenderToFBO := False;
121 w := gWinSizeX;
122 h := gWinSizeY;
123 end;
124 end;
125 gScreenWidth := w;
126 gScreenHeight := h;
127 e_ResizeWindow(w, h);
128 e_InitGL
129 end;
131 procedure r_Render_Apply;
132 begin
133 if sys_SetDisplayMode(Max(1, gRC_Width), Max(1, gRC_Height), Max(1, gBPP), gRC_FullScreen, gRC_Maximized) then
134 e_LogWriteln('resolution changed')
135 else
136 e_LogWriteln('resolution not changed');
137 sys_EnableVSync(gVSync)
138 end;
140 end.