DEADSOFTWARE

render: player punch TAnimation -> TAnimationState
[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;
23 procedure r_Render_Resize (w, h: Integer);
25 procedure r_Render_Load;
26 procedure r_Render_Free;
28 procedure r_Render_Update;
30 procedure r_Render_Apply;
32 implementation
34 uses
35 {$INCLUDE ../../nogl/noGLuses.inc}
36 SysUtils, Classes, Math,
37 e_log, g_system,
38 g_game, g_options, g_console,
39 r_window, r_graphics, r_console, r_playermodel,
40 r_weapons, r_items, r_gfx, r_monsters, r_map, r_player
41 ;
43 var
44 LoadedGL: Boolean = false;
46 procedure LoadGL;
47 begin
48 if LoadedGL = false then
49 begin
50 {$IFDEF NOGL_INIT}
51 nogl_Init;
52 if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
53 begin
54 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
55 glRenderToFBO := false
56 end;
57 {$ELSE}
58 if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then
59 begin
60 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
61 glRenderToFBO := false
62 end;
63 {$ENDIF}
64 LoadedGL := true
65 end
66 end;
68 procedure FreeGL;
69 begin
70 if LoadedGL = true then
71 begin
72 {$IFDEF NOGL_INIT}
73 nogl_Quit;
74 {$ENDIF}
75 LoadedGL := false
76 end
77 end;
79 procedure r_Render_Load;
80 begin
81 r_Player_Load;
82 r_Map_Load;
83 r_PlayerModel_Load;
84 r_Monsters_Load;
85 r_Weapon_Load;
86 r_Items_Load;
87 r_GFX_Load;
88 end;
90 procedure r_Render_Free;
91 begin
92 r_GFX_Free;
93 r_Items_Free;
94 r_Weapon_Free;
95 r_Monsters_Free;
96 r_PlayerModel_Free;
97 r_Map_Free;
98 r_Player_Free;
99 end;
101 procedure r_Render_Initialize;
102 begin
103 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then
104 raise Exception.Create('Failed to set videomode on startup.');
105 LoadGL;
106 r_Window_Initialize;
107 r_Console_Init;
108 r_PlayerModel_Initialize;
109 r_Map_Initialize;
110 end;
112 procedure r_Render_Finalize;
113 begin
114 r_Map_Finalize;
115 r_PlayerModel_Finalize;
116 FreeGL;
117 e_ReleaseEngine
118 end;
120 procedure r_Render_Update;
121 begin
122 r_Map_Update;
123 r_PlayerModel_Update;
124 end;
126 procedure r_Render_Resize (w, h: Integer);
127 begin
128 LoadGL;
129 gWinSizeX := w;
130 gWinSizeY := h;
131 gRC_Width := w;
132 gRC_Height := h;
133 if glRenderToFBO then
134 begin
135 // store real window size in gWinSize, downscale resolution now
136 w := round(w / r_pixel_scale);
137 h := round(h / r_pixel_scale);
138 if not e_ResizeFramebuffer(w, h) then
139 begin
140 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
141 glRenderToFBO := False;
142 w := gWinSizeX;
143 h := gWinSizeY;
144 end;
145 end;
146 gScreenWidth := w;
147 gScreenHeight := h;
148 e_ResizeWindow(w, h);
149 e_InitGL
150 end;
152 procedure r_Render_Apply;
153 begin
154 if sys_SetDisplayMode(Max(1, gRC_Width), Max(1, gRC_Height), Max(1, gBPP), gRC_FullScreen, gRC_Maximized) then
155 e_LogWriteln('resolution changed')
156 else
157 e_LogWriteln('resolution not changed');
158 sys_EnableVSync(gVSync)
159 end;
161 end.