Skip to content

Commit 55b9432

Browse files
committed
Moved bgfx stuff into renderer
1 parent ab0dfb1 commit 55b9432

File tree

5 files changed

+82
-52
lines changed

5 files changed

+82
-52
lines changed

igneous/include/igneous/core/igneous.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ class Application
4343
bx::AllocatorI * allocator = NULL
4444
);
4545

46-
void reset(uint32_t flags = 0);
47-
4846
virtual void initialize(int _argc, char** _argv) {};
4947
virtual void update(float dt) {};
5048
virtual void render() {};
@@ -60,7 +58,6 @@ class Application
6058
virtual void onScroll(double xoffset, double yoffset) {}
6159
virtual void onDrop(int count, const char** paths) {}
6260
virtual void onWindowSize(int width, int height) {}
63-
uint32_t mReset;
6461
};
6562
} // end namespace igneous
6663

igneous/include/igneous/renderer/renderer.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace igneous {
1212
namespace renderer
1313
{
14-
void init();
14+
void init(bgfx::Init init);
1515
std::string getSupportedRenderers();
1616
std::string getGpuInfo();
1717

@@ -29,6 +29,13 @@ namespace renderer
2929
bool isRecording();
3030
void setDebugOverlay(bool debugOverlay);
3131

32+
void reset();
33+
34+
void setFlag(uint32_t flag, bool value);
35+
bool getFlag(uint32_t newFlags);
36+
void setFlags(uint32_t flags);
37+
uint32_t getFlags();
38+
3239
void shutdown();
3340

3441
extern std::map<std::string, Model*> models;

igneous/src/core/igneous.cpp

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,9 @@
1111
#include <bgfx/platform.h>
1212
#include <imgui/imgui.h>
1313

14-
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
15-
# define GLFW_EXPOSE_NATIVE_X11
16-
# define GLFW_EXPOSE_NATIVE_GLX
17-
#elif BX_PLATFORM_OSX
18-
# define GLFW_EXPOSE_NATIVE_COCOA
19-
# define GLFW_EXPOSE_NATIVE_NSGL
20-
#elif BX_PLATFORM_WINDOWS
21-
# define GLFW_EXPOSE_NATIVE_WIN32
22-
# define GLFW_EXPOSE_NATIVE_WGL
23-
#endif // BX_PLATFORM_
24-
#include <GLFW/glfw3native.h>
25-
2614
namespace igneous {
2715
// Application
2816
Application::Application(const char* title, uint32_t width, uint32_t height)
29-
: mReset(BGFX_RESET_NONE)
3017
{
3118
input::width = width;
3219
input::height = height;
@@ -37,30 +24,10 @@ Application::Application(const char* title, uint32_t width, uint32_t height)
3724
int Application::run(int argc, char** argv, bgfx::Init init)
3825
{
3926
IG_CORE_INFO("Initializing Engine");
40-
input::init();
41-
42-
// Setup bgfx
43-
IG_CORE_INFO("Initializing bgfx");
44-
bgfx::PlatformData platformData;
45-
memset(&platformData, 0, sizeof(platformData));
46-
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
47-
platformData.nwh = (void*)(uintptr_t)glfwGetX11Window(input::window);
48-
platformData.ndt = glfwGetX11Display();
49-
#elif BX_PLATFORM_OSX
50-
platformData.nwh = glfwGetCocoaWindow(input::window);
51-
#elif BX_PLATFORM_WINDOWS
52-
platformData.nwh = glfwGetWin32Window(input::window);
53-
#endif // BX_PLATFORM_
54-
bgfx::setPlatformData(platformData);
55-
56-
// Init bgfx
57-
bgfx::init(init);
58-
IG_CORE_INFO("bgfx Initializied");
59-
6027
IG_CORE_INFO("Initializing Services");
61-
reset();
28+
input::init();
6229
console::init();
63-
renderer::init();
30+
renderer::init(init);
6431
gui::init();
6532
audio::init();
6633
console::runFile("startup.cmd");
@@ -99,7 +66,6 @@ int Application::run(int argc, char** argv, bgfx::Init init)
9966

10067
// Initialize the application
10168
IG_CORE_INFO("Initializing Application");
102-
reset();
10369
initialize(argc, argv);
10470
IG_CONSOLE_INFO("Application Initialized");
10571

@@ -149,14 +115,6 @@ int Application::run(int argc, char** argv, bgfx::RendererType::Enum type, uint1
149115
return run(argc, argv, init);
150116
}
151117

152-
void Application::reset(uint32_t flags)
153-
{
154-
mReset = flags;
155-
bgfx::reset(input::width, input::height, mReset);
156-
gui::reset();
157-
onReset();
158-
}
159-
160118
void Application::onReset()
161119
{
162120
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x000000ff, 1.0f, 0);

igneous/src/core/input.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stb/stb_image.h>
55

66
#include "igneous/core/log.hpp"
7+
#include "igneous/renderer/renderer.hpp"
78

89
namespace igneous {
910
namespace input
@@ -121,7 +122,7 @@ namespace input
121122
Application* app = (Application*)glfwGetWindowUserPointer(window);
122123
input::width = width;
123124
input::height = height;
124-
app->reset(app->mReset);
125+
renderer::reset();
125126
app->onWindowSize(width, height);
126127
}
127128

igneous/src/renderer/renderer.cpp

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,27 @@
55
#include <stb/stb_image.h>
66
#include <bimg/bimg.h>
77
#include <bx/file.h>
8+
#include <bgfx/platform.h>
89

910
#include "igneous/core/log.hpp"
1011
#include "igneous/renderer/vertex.hpp"
1112
#include "splash_assets.h"
1213
#include "igneous/ecs/components/transformationComponent.hpp"
1314
#include "igneous/console/console.hpp"
1415
#include "igneous/core/input.hpp"
16+
#include "igneous/gui/gui.hpp"
17+
18+
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
19+
# define GLFW_EXPOSE_NATIVE_X11
20+
# define GLFW_EXPOSE_NATIVE_GLX
21+
#elif BX_PLATFORM_OSX
22+
# define GLFW_EXPOSE_NATIVE_COCOA
23+
# define GLFW_EXPOSE_NATIVE_NSGL
24+
#elif BX_PLATFORM_WINDOWS
25+
# define GLFW_EXPOSE_NATIVE_WIN32
26+
# define GLFW_EXPOSE_NATIVE_WGL
27+
#endif // BX_PLATFORM_
28+
#include <GLFW/glfw3native.h>
1529

1630
namespace igneous {
1731
namespace renderer
@@ -21,6 +35,7 @@ namespace renderer
2135
std::map<std::string, Model*> models;
2236

2337
static bgfx::TextureHandle checkerBoard;
38+
static uint32_t flags = BGFX_RESET_NONE;
2439

2540
void screenshotCallback(const std::string& name, const arg_list& args)
2641
{
@@ -29,7 +44,10 @@ namespace renderer
2944

3045
void recordingCallback(float oldValue, float newValue)
3146
{
32-
setRecording(newValue);
47+
if ((bool)oldValue != (bool)newValue)
48+
{
49+
setRecording(newValue);
50+
}
3351
}
3452

3553
void debugCallback(float oldValue, float newValue)
@@ -41,9 +59,28 @@ namespace renderer
4159
static ConVar* debug;
4260
static bgfx::UniformHandle s_tex;
4361

44-
void init()
62+
void init(bgfx::Init init)
4563
{
4664
IG_CORE_INFO("Initializing Renderer");
65+
// Setup bgfx
66+
IG_CORE_INFO("Initializing bgfx");
67+
bgfx::PlatformData platformData;
68+
memset(&platformData, 0, sizeof(platformData));
69+
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
70+
platformData.nwh = (void*)(uintptr_t)glfwGetX11Window(input::window);
71+
platformData.ndt = glfwGetX11Display();
72+
#elif BX_PLATFORM_OSX
73+
platformData.nwh = glfwGetCocoaWindow(input::window);
74+
#elif BX_PLATFORM_WINDOWS
75+
platformData.nwh = glfwGetWin32Window(input::window);
76+
#endif // BX_PLATFORM_
77+
bgfx::setPlatformData(platformData);
78+
79+
// Init bgfx
80+
bgfx::init(init);
81+
IG_CORE_INFO("bgfx Initializied");
82+
83+
reset();
4784
static float s_splashVertices[] =
4885
{
4986
-1.0f, 1.0f, 0.0f, 0.0f,
@@ -234,6 +271,13 @@ namespace renderer
234271
return bgfx::createProgram(loadShader(vsPath), loadShader(fsPath), true);
235272
}
236273

274+
void reset()
275+
{
276+
bgfx::reset(input::width, input::height, flags);
277+
gui::reset();
278+
input::app->onReset();
279+
}
280+
237281
void render(entt::registry& registry)
238282
{
239283
registry.view<ModelHandle, Transformation>().each([&](const auto, auto& model, auto& transformation)
@@ -260,7 +304,8 @@ namespace renderer
260304

261305
void setRecording(bool record)
262306
{
263-
//set reset
307+
setFlag(BGFX_RESET_CAPTURE, record);
308+
//*recording = record;
264309
IG_CORE_INFO("Capture: {}", *recording ? "ON" : "OFF");
265310
}
266311

@@ -275,6 +320,28 @@ namespace renderer
275320
IG_CORE_INFO("Debug Overlay: {}", *debug ? "ON" : "OFF");
276321
}
277322

323+
void setFlag(uint32_t flag, bool value)
324+
{
325+
flags = (value) ? (flags | flag) : (flags & ~flag);
326+
reset();
327+
}
328+
329+
bool getFlag(uint32_t flag)
330+
{
331+
return flags & flag;
332+
}
333+
334+
void setFlags(uint32_t newFlags)
335+
{
336+
flags = newFlags;
337+
reset();
338+
}
339+
340+
uint32_t getFlags()
341+
{
342+
return flags;
343+
}
344+
278345
void shutdown()
279346
{
280347
IG_CORE_INFO("Shutingdown Renderer");

0 commit comments

Comments
 (0)