127 lines
2.8 KiB
C++
127 lines
2.8 KiB
C++
#include "RuntimeModule.h"
|
|
#include "Globals.h"
|
|
#include "RenderModule.h"
|
|
|
|
struct Renderer;
|
|
|
|
//
|
|
// Module
|
|
//
|
|
struct module_state {
|
|
Renderer *renderer;
|
|
};
|
|
|
|
static struct module_state *module_init() {
|
|
gLog ("%s %s called", __FILE__, __FUNCTION__);
|
|
assert (gWindow != nullptr && "Cannot initialize renderer module without gWindow!");
|
|
|
|
module_state *state = (module_state*) malloc(sizeof(*state));
|
|
state->renderer = new Renderer();
|
|
assert (state->renderer != nullptr);
|
|
|
|
return state;
|
|
}
|
|
|
|
template <typename Serializer>
|
|
static void module_serialize (
|
|
struct module_state *state,
|
|
Serializer* serializer) {
|
|
// // get the state from the serializer
|
|
// Camera* camera = &gRenderer->cameras[gRenderer->activeCameraIndex];
|
|
// assert (camera != nullptr);
|
|
|
|
// SerializeBool (*serializer, "protot.RenderModule.draw_floor", gRenderer->drawFloor);
|
|
// SerializeBool (*serializer, "protot.RenderModule.draw_skybox", gRenderer->drawSkybox);
|
|
// SerializeBool (*serializer, "protot.RenderModule.debug_enabled", gRenderer->drawDebug);
|
|
// SerializeVec3 (*serializer, "protot.RenderModule.camera.eye", camera->eye);
|
|
// SerializeVec3 (*serializer, "protot.RenderModule.camera.poi", camera->poi);
|
|
}
|
|
|
|
static void module_finalize(struct module_state *state) {
|
|
gLog ("%s %s called (state %p)", __FILE__, __FUNCTION__, state);
|
|
|
|
assert (state->renderer != nullptr);
|
|
delete state->renderer;
|
|
|
|
free(state);
|
|
}
|
|
|
|
static void module_reload(struct module_state *state, void *read_serializer) {
|
|
gLog ("%s %s called (state %p)", __FILE__, __FUNCTION__, state);
|
|
assert (gWindow != nullptr);
|
|
|
|
gLog ("Renderer initialize");
|
|
assert (state != nullptr);
|
|
state->renderer->Initialize(100, 100);
|
|
gRenderer = state->renderer;
|
|
|
|
// load the state of the module
|
|
if (read_serializer != nullptr) {
|
|
module_serialize(state, static_cast<ReadSerializer*>(read_serializer));
|
|
}
|
|
}
|
|
|
|
static void module_unload(struct module_state *state, void* write_serializer) {
|
|
// serialize the state of the module
|
|
if (write_serializer != nullptr) {
|
|
module_serialize(state, static_cast<WriteSerializer*>(write_serializer));
|
|
}
|
|
|
|
gRenderer = nullptr;
|
|
state->renderer->Shutdown();
|
|
|
|
gLog ("RenderModule unload called");
|
|
}
|
|
|
|
static bool module_step(struct module_state *state, float dt) {
|
|
int width, height;
|
|
assert (gWindow != nullptr);
|
|
state->renderer->RenderGui();
|
|
state->renderer->RenderGl();
|
|
|
|
return true;
|
|
}
|
|
|
|
extern "C" {
|
|
|
|
const struct module_api MODULE_API = {
|
|
.init = module_init,
|
|
.reload = module_reload,
|
|
.step = module_step,
|
|
.unload = module_unload,
|
|
.finalize = module_finalize
|
|
};
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Camera
|
|
//
|
|
void Camera::updateMatrices() {
|
|
assert(false);
|
|
}
|
|
|
|
|
|
//
|
|
// Camera
|
|
//
|
|
void Renderer::Initialize(int width, int height) {
|
|
assert(false);
|
|
}
|
|
|
|
void Renderer::Shutdown() {
|
|
assert(false);
|
|
}
|
|
void Renderer::RenderGl() {
|
|
assert(false);
|
|
}
|
|
|
|
void Renderer::RenderGui() {
|
|
assert(false);
|
|
}
|
|
|
|
void Renderer::Resize (int width, int height) {
|
|
assert(false);
|
|
}
|