DEADSOFTWARE

render: fix gles builds
[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_Apply;
26 implementation
28 uses
29 {$INCLUDE ../../nogl/noGLuses.inc}
30 SysUtils, Classes, Math,
31 e_log, g_system,
32 g_game, g_options, g_console,
33 r_window, r_graphics, r_console, r_playermodel
34 ;
36 var
37 LoadedGL: Boolean = false;
39 procedure LoadGL;
40 begin
41 if LoadedGL = false then
42 begin
43 {$IFDEF NOGL_INIT}
44 nogl_Init;
45 if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
46 begin
47 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
48 glRenderToFBO := false
49 end;
50 {$ELSE}
51 if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then
52 begin
53 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
54 glRenderToFBO := false
55 end;
56 {$ENDIF}
57 LoadedGL := true
58 end
59 end;
61 procedure FreeGL;
62 begin
63 if LoadedGL = true then
64 begin
65 {$IFDEF NOGL_INIT}
66 nogl_Quit;
67 {$ENDIF}
68 LoadedGL := false
69 end
70 end;
72 procedure r_Render_Initialize;
73 begin
74 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then
75 raise Exception.Create('Failed to set videomode on startup.');
76 LoadGL;
77 r_Window_Initialize;
78 r_Console_Init;
79 r_PlayerModel_Initialize;
80 end;
82 procedure r_Render_Finalize;
83 begin
84 FreeGL;
85 r_PlayerModel_Finalize;
86 e_ReleaseEngine
87 end;
89 procedure r_Render_Resize (w, h: Integer);
90 begin
91 LoadGL;
92 gWinSizeX := w;
93 gWinSizeY := h;
94 gRC_Width := w;
95 gRC_Height := h;
96 if glRenderToFBO then
97 begin
98 // store real window size in gWinSize, downscale resolution now
99 w := round(w / r_pixel_scale);
100 h := round(h / r_pixel_scale);
101 if not e_ResizeFramebuffer(w, h) then
102 begin
103 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
104 glRenderToFBO := False;
105 w := gWinSizeX;
106 h := gWinSizeY;
107 end;
108 end;
109 gScreenWidth := w;
110 gScreenHeight := h;
111 e_ResizeWindow(w, h);
112 e_InitGL
113 end;
115 procedure r_Render_Apply;
116 begin
117 if sys_SetDisplayMode(Max(1, gRC_Width), Max(1, gRC_Height), Max(1, gBPP), gRC_FullScreen, gRC_Maximized) then
118 e_LogWriteln('resolution changed')
119 else
120 e_LogWriteln('resolution not changed');
121 sys_EnableVSync(gVSync)
122 end;
124 end.