Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfApplication.h
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20#ifndef _SOURCE_RENDERING_TFAPPLICATION_H_
21#define _SOURCE_RENDERING_TFAPPLICATION_H_
22
23#include <TissueForge.h>
24#include <TissueForge_private.h>
25#include <tfSimulator.h>
26#include <Magnum/GL/Context.h>
27#include <GLFW/glfw3.h>
28#include "tfImageConverters.h"
29
30
31namespace TissueForge::rendering {
32
33
34 enum WindowAttributes {
35 TF_FOCUSED = GLFW_FOCUSED,
36 TF_ICONIFIED = GLFW_ICONIFIED,
37 TF_RESIZABLE = GLFW_RESIZABLE,
38 TF_VISIBLE = GLFW_VISIBLE,
39 TF_DECORATED = GLFW_DECORATED,
40 TF_AUTO_ICONIFY = GLFW_AUTO_ICONIFY,
41 TF_FLOATING = GLFW_FLOATING,
42 TF_MAXIMIZED = GLFW_MAXIMIZED,
43 TF_CENTER_CURSOR = GLFW_CENTER_CURSOR,
44 TF_TRANSPARENT_FRAMEBUFFER = GLFW_TRANSPARENT_FRAMEBUFFER,
45 TF_HOVERED = GLFW_HOVERED,
46 TF_FOCUS_ON_SHOW = GLFW_FOCUS_ON_SHOW,
47 TF_RED_BITS = GLFW_RED_BITS,
48 TF_GREEN_BITS = GLFW_GREEN_BITS,
49 TF_BLUE_BITS = GLFW_BLUE_BITS,
50 TF_ALPHA_BITS = GLFW_ALPHA_BITS,
51 TF_DEPTH_BITS = GLFW_DEPTH_BITS,
52 TF_STENCIL_BITS = GLFW_STENCIL_BITS,
53 TF_ACCUM_RED_BITS = GLFW_ACCUM_RED_BITS,
54 TF_ACCUM_GREEN_BITS = GLFW_ACCUM_GREEN_BITS,
55 TF_ACCUM_BLUE_BITS = GLFW_ACCUM_BLUE_BITS,
56 TF_ACCUM_ALPHA_BITS = GLFW_ACCUM_ALPHA_BITS,
57 TF_AUX_BUFFERS = GLFW_AUX_BUFFERS,
58 TF_STEREO = GLFW_STEREO,
59 TF_SAMPLES = GLFW_SAMPLES,
60 TF_SRGB_CAPABLE = GLFW_SRGB_CAPABLE,
61 TF_REFRESH_RATE = GLFW_REFRESH_RATE,
62 TF_DOUBLEBUFFER = GLFW_DOUBLEBUFFER,
63 TF_CLIENT_API = GLFW_CLIENT_API,
64 TF_CONTEXT_VERSION_MAJOR = GLFW_CONTEXT_VERSION_MAJOR,
65 TF_CONTEXT_VERSION_MINOR = GLFW_CONTEXT_VERSION_MINOR,
66 TF_CONTEXT_REVISION = GLFW_CONTEXT_REVISION,
67 TF_CONTEXT_ROBUSTNESS = GLFW_CONTEXT_ROBUSTNESS,
68 TF_OPENGL_FORWARD_COMPAT = GLFW_OPENGL_FORWARD_COMPAT,
69 TF_OPENGL_DEBUG_CONTEXT = GLFW_OPENGL_DEBUG_CONTEXT,
70 TF_OPENGL_PROFILE = GLFW_OPENGL_PROFILE,
71 TF_CONTEXT_RELEASE_BEHAVIOR = GLFW_CONTEXT_RELEASE_BEHAVIOR,
72 TF_CONTEXT_NO_ERROR = GLFW_CONTEXT_NO_ERROR,
73 TF_CONTEXT_CREATION_API = GLFW_CONTEXT_CREATION_API,
74 TF_SCALE_TO_MONITOR = GLFW_SCALE_TO_MONITOR,
75 TF_COCOA_RETINA_FRAMEBUFFER = GLFW_COCOA_RETINA_FRAMEBUFFER,
76 TF_COCOA_FRAME_NAME = GLFW_COCOA_FRAME_NAME,
77 TF_COCOA_GRAPHICS_SWITCHING = GLFW_COCOA_GRAPHICS_SWITCHING,
78 TF_X11_CLASS_NAME = GLFW_X11_CLASS_NAME,
79 TF_X11_INSTANCE_NAME = GLFW_X11_INSTANCE_NAME
80 };
81
82
87 public:
94 None = 0,
95 Fullscreen = 1 << 0,
96 Resizable = 1 << 1,
97 Hidden = 1 << 2,
98
99
100 Maximized = 1 << 3,
101
102
103 Minimized = 1 << 4,
104 Floating = 1 << 5,
105
110 AutoIconify = 1 << 6,
111
112 Focused = 1 << 7,
113
114
125 Contextless = 1 << 8
126 };
127
128 unsigned windowFlag = 0;
129
130
182 };
183
184 struct UniverseRenderer;
185 struct GlfwWindow;
186
187
188 struct CAPI_EXPORT Application
189 {
190 public:
191
195 std::vector<GlfwWindow*> windows;
196
197 virtual ~Application() {};
198
199 //virtual HRESULT createContext(const class Simulator::Config &conf) = 0;
200
201
212 virtual HRESULT pollEvents () = 0;
213
230 virtual HRESULT waitEvents () = 0;
231
251
252 virtual HRESULT waitEventsTimeout(double timeout) = 0;
253
254
259 virtual HRESULT postEmptyEvent() = 0;
260
261
262 virtual HRESULT mainLoopIteration(double timeout)= 0;
263
264
265 virtual HRESULT setSwapInterval(int si) = 0;
266
267
268 // temporary hack until we setup events correctly
269 virtual struct GlfwWindow *getWindow() = 0;
270
271 virtual int windowAttribute(WindowAttributes attr) = 0;
272
273 virtual HRESULT setWindowAttribute(WindowAttributes attr, int val) = 0;
274
275 virtual HRESULT createContext(const Simulator::Config &conf) = 0;
276
277 virtual UniverseRenderer *getRenderer() = 0;
278
283 virtual HRESULT redraw() = 0;
284
285 virtual HRESULT run(double et);
286
287
288 // soft hide the window
289 virtual HRESULT close() = 0;
290
291 // hard window close
292 virtual HRESULT destroy() = 0;
293
294 // display the window if closed.
295 virtual HRESULT show() = 0;
296
297 virtual HRESULT simulationStep();
298
299 virtual HRESULT messageLoop(double et) = 0;
300
301 virtual Magnum::GL::AbstractFramebuffer& framebuffer() = 0;
302
303
304 virtual bool contextMakeCurrent() = 0;
305
306 virtual bool contextHasCurrent() = 0;
307
308 virtual bool contextRelease() = 0;
309
310
311 protected:
312 bool _dynamicBoundary = true;
313
314
315 Magnum::Float _boundaryOffset = 0.0f; /* For boundary animation */
316
317 int currentStep = 0;
318
319
320 };
321
322 Corrade::Containers::Array<char> JpegImageData();
323 Corrade::Containers::Array<char> BMPImageData();
324 Corrade::Containers::Array<char> HDRImageData();
325 Corrade::Containers::Array<char> PNGImageData();
326 Corrade::Containers::Array<char> TGAImageData();
327
328 std::tuple<char*, size_t> framebufferImageData();
329
336 HRESULT screenshot(const std::string &filePath);
337
338};
339
340#endif // _SOURCE_RENDERING_TFAPPLICATION_H_
Tissue Forge rendering and visualization.
Definition tfAngle.h:38
HRESULT screenshot(const std::string &filePath)
Save a screenshot of the current scene.
Definition tfSimulator.h:368
Definition tfApplication.h:86
WindowFlag
Window flag.
Definition tfApplication.h:93
@ Floating
Definition tfApplication.h:104
@ Fullscreen
Definition tfApplication.h:95
@ Resizable
Definition tfApplication.h:96
@ AutoIconify
Definition tfApplication.h:110
@ Focused
Definition tfApplication.h:112
@ Contextless
Definition tfApplication.h:125
@ Minimized
Definition tfApplication.h:103
@ Hidden
Definition tfApplication.h:97
DpiScalingPolicy
DPI scaling policy.
Definition tfApplication.h:139
Definition tfApplication.h:189
virtual HRESULT waitEventsTimeout(double timeout)=0
std::vector< GlfwWindow * > windows
Definition tfApplication.h:195
virtual HRESULT postEmptyEvent()=0
Definition tfGlfwWindow.h:38
Definition tfUniverseRenderer.h:115
int32_t HRESULT
Definition tf_port.h:255