Even more shared pointers.
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
struct Color Color::fromString(std::string str) {
|
struct Color Color::fromString(const std::string str) {
|
||||||
// Convert to lowercase
|
// Convert to lowercase
|
||||||
auto lower = stringToLowercase(str);
|
auto lower = stringToLowercase(str);
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace Dawn {
|
|||||||
* @param str String to parse.
|
* @param str String to parse.
|
||||||
* @return Color parsed.
|
* @return Color parsed.
|
||||||
*/
|
*/
|
||||||
static struct Color fromString(std::string str);
|
static struct Color fromString(const std::string str);
|
||||||
|
|
||||||
float_t r, g, b, a;
|
float_t r, g, b, a;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ namespace Dawn {
|
|||||||
class ShaderManager;
|
class ShaderManager;
|
||||||
class RenderTarget;
|
class RenderTarget;
|
||||||
|
|
||||||
class IRenderManager {
|
class IRenderManager : public std::enable_shared_from_this<IRenderManager> {
|
||||||
protected:
|
protected:
|
||||||
flag_t renderFlags = 0;
|
flag_t renderFlags = 0;
|
||||||
|
|
||||||
@ -44,14 +44,14 @@ namespace Dawn {
|
|||||||
*
|
*
|
||||||
* @return Reference to the currently active main scene render pipeline.
|
* @return Reference to the currently active main scene render pipeline.
|
||||||
*/
|
*/
|
||||||
virtual RenderPipeline * getRenderPipeline() = 0;
|
virtual std::shared_ptr<RenderPipeline> getRenderPipeline() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the shader manager that this render manager uses.
|
* Returns the shader manager that this render manager uses.
|
||||||
*
|
*
|
||||||
* @return Reference to the shader manager.
|
* @return Reference to the shader manager.
|
||||||
*/
|
*/
|
||||||
virtual ShaderManager * getShaderManager() = 0;
|
virtual std::shared_ptr<ShaderManager> getShaderManager() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the render flags for the render manager to use.
|
* Sets the render flags for the render manager to use.
|
||||||
|
@ -13,32 +13,35 @@
|
|||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
RenderPipeline::RenderPipeline(RenderManager *renderManager) {
|
RenderPipeline::RenderPipeline() {
|
||||||
assertNotNull(renderManager, "RenderPipeline::RenderPipeline: RenderManager cannot be null");
|
|
||||||
this->renderManager = renderManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPipeline::init() {
|
void RenderPipeline::init(const std::weak_ptr<RenderManager> renderManager) {
|
||||||
this->shaderBuffer.init();
|
this->renderManager = renderManager;
|
||||||
|
shaderBuffer.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPipeline::render() {
|
void RenderPipeline::render() {
|
||||||
auto game = this->renderManager->game.lock();
|
auto rm = renderManager.lock();
|
||||||
|
assertNotNull(rm, "RenderPipeline::render: RenderManager cannot be null");
|
||||||
|
auto game = rm->game.lock();
|
||||||
assertNotNull(game, "RenderPipeline::render: Game cannot be null");
|
assertNotNull(game, "RenderPipeline::render: Game cannot be null");
|
||||||
|
|
||||||
if(game->scene != nullptr) {
|
if(game->scene != nullptr) {
|
||||||
this->renderScene(game->scene);
|
renderScene(game->scene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPipeline::renderScene(Scene *scene) {
|
void RenderPipeline::renderScene(std::shared_ptr<Scene> scene) {
|
||||||
assertNotNull(scene, "RenderPipeline::renderScene: Scene cannot be null");
|
assertNotNull(scene, "RenderPipeline::renderScene: Scene cannot be null");
|
||||||
|
auto rm = renderManager.lock();
|
||||||
|
assertNotNull(rm, "RenderPipeline::renderScene: RenderManager cannot be null");
|
||||||
|
|
||||||
// Render subscenes first.
|
// Render subscenes first.
|
||||||
auto subSceneControllers = scene->findComponents<SubSceneController>();
|
auto subSceneControllers = scene->findComponents<SubSceneController>();
|
||||||
auto itSubScene = subSceneControllers.begin();
|
auto itSubScene = subSceneControllers.begin();
|
||||||
while(itSubScene != subSceneControllers.end()) {
|
while(itSubScene != subSceneControllers.end()) {
|
||||||
Scene *subScene = (Scene *)((*itSubScene)->subScene);
|
auto subScene = (*itSubScene)->subScene;
|
||||||
if(subScene == nullptr) {
|
if(subScene == nullptr) {
|
||||||
++itSubScene;
|
++itSubScene;
|
||||||
continue;
|
continue;
|
||||||
@ -49,12 +52,12 @@ void RenderPipeline::renderScene(Scene *scene) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->renderScene(subScene);
|
renderScene(subScene);
|
||||||
++itSubScene;
|
++itSubScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now render backbuffers.
|
// Now render backbuffers.
|
||||||
auto backBuffer = this->renderManager->getBackBuffer();
|
auto backBuffer = rm->getBackBuffer();
|
||||||
auto cameras = scene->findComponents<Camera>();
|
auto cameras = scene->findComponents<Camera>();
|
||||||
Camera *backBufferCamera = nullptr;
|
Camera *backBufferCamera = nullptr;
|
||||||
|
|
||||||
@ -71,7 +74,7 @@ void RenderPipeline::renderScene(Scene *scene) {
|
|||||||
} else if(cameraTarget == backBuffer) {
|
} else if(cameraTarget == backBuffer) {
|
||||||
backBufferCamera = *it;
|
backBufferCamera = *it;
|
||||||
} else {
|
} else {
|
||||||
this->renderSceneCamera(scene, *it);
|
renderSceneCamera(&(*scene), *it);
|
||||||
}
|
}
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
@ -79,10 +82,13 @@ void RenderPipeline::renderScene(Scene *scene) {
|
|||||||
|
|
||||||
// Now render the backbuffer camera.
|
// Now render the backbuffer camera.
|
||||||
if(backBufferCamera == nullptr) return;
|
if(backBufferCamera == nullptr) return;
|
||||||
this->renderSceneCamera(scene, backBufferCamera);
|
renderSceneCamera(&(*scene), backBufferCamera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
||||||
|
auto rm = renderManager.lock();
|
||||||
|
assertNotNull(rm, "RenderPipeline::renderSceneCamera: RenderManager cannot be null");
|
||||||
|
|
||||||
std::vector<struct ShaderPassItem>::iterator itPassItem;
|
std::vector<struct ShaderPassItem>::iterator itPassItem;
|
||||||
|
|
||||||
assertNotNull(scene, "RenderPipeline::renderSceneCamera: Scene cannot be null");
|
assertNotNull(scene, "RenderPipeline::renderSceneCamera: Scene cannot be null");
|
||||||
@ -90,7 +96,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
|
|
||||||
// Create a new render ID. Long story short this is a really dirty way of
|
// Create a new render ID. Long story short this is a really dirty way of
|
||||||
// not sending parameters to shaders more than we need.
|
// not sending parameters to shaders more than we need.
|
||||||
this->renderId--;
|
renderId--;
|
||||||
|
|
||||||
// Get the render target.
|
// Get the render target.
|
||||||
auto renderTarget = camera->getRenderTarget();
|
auto renderTarget = camera->getRenderTarget();
|
||||||
@ -100,7 +106,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
struct RenderPipelineShaderBufferData shaderBufferData;
|
struct RenderPipelineShaderBufferData shaderBufferData;
|
||||||
shaderBufferData.projection = camera->getProjection();
|
shaderBufferData.projection = camera->getProjection();
|
||||||
shaderBufferData.view = camera->transform->getWorldTransform();
|
shaderBufferData.view = camera->transform->getWorldTransform();
|
||||||
this->shaderBuffer.buffer(&shaderBufferData);
|
shaderBuffer.buffer(&shaderBufferData);
|
||||||
|
|
||||||
// Prepare a render context. This is just a nice way of letting renderables
|
// Prepare a render context. This is just a nice way of letting renderables
|
||||||
// know a bit about what is happening, they can choose to use this data to
|
// know a bit about what is happening, they can choose to use this data to
|
||||||
@ -137,7 +143,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
&lineMesh,
|
&lineMesh,
|
||||||
&lineIndex,
|
&lineIndex,
|
||||||
camera,
|
camera,
|
||||||
this->renderManager->simpleTexturedShader
|
renderManager->simpleTexturedShader
|
||||||
);
|
);
|
||||||
shaderPassItems.push_back(item);
|
shaderPassItems.push_back(item);
|
||||||
itDebugLine = scene->debugLines.erase(itDebugLine);
|
itDebugLine = scene->debugLines.erase(itDebugLine);
|
||||||
@ -260,7 +266,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set Render flags
|
// Set Render flags
|
||||||
this->renderManager->setRenderFlags(item.renderFlags);
|
rm->setRenderFlags(item.renderFlags);
|
||||||
|
|
||||||
// Thank god that's done, now just draw the damn mesh.
|
// Thank god that's done, now just draw the damn mesh.
|
||||||
item.mesh->draw(item.drawMode, item.start, item.count);
|
item.mesh->draw(item.drawMode, item.start, item.count);
|
||||||
|
@ -18,22 +18,22 @@ namespace Dawn {
|
|||||||
int_fast16_t renderId = -1;
|
int_fast16_t renderId = -1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenderManager *renderManager;
|
std::weak_ptr<RenderManager> renderManager;
|
||||||
RenderPipelineShaderBuffer shaderBuffer;
|
RenderPipelineShaderBuffer shaderBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new RenderPipeline. Render Pipelines are my attempt to
|
* Constructs a new RenderPipeline. Render Pipelines are my attempt to
|
||||||
* create both a flexible, but standard way to allow the individual games
|
* create both a flexible, but standard way to allow the individual games
|
||||||
* to decide how they want to render the common scene-item models.
|
* to decide how they want to render the common scene-item models.
|
||||||
*
|
|
||||||
* @param renderManager Parent render manager this pipeline belongs to.
|
|
||||||
*/
|
*/
|
||||||
RenderPipeline(RenderManager *renderManager);
|
RenderPipeline();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the render pipeline.
|
* Initialize the render pipeline.
|
||||||
|
*
|
||||||
|
* @param renderManager Parent render manager this pipeline belongs to.
|
||||||
*/
|
*/
|
||||||
virtual void init();
|
virtual void init(const std::weak_ptr<RenderManager> renderManager);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the games' currently active scene, and all of its' cameras.
|
* Renders the games' currently active scene, and all of its' cameras.
|
||||||
@ -46,7 +46,7 @@ namespace Dawn {
|
|||||||
*
|
*
|
||||||
* @param scene Scene to render.
|
* @param scene Scene to render.
|
||||||
*/
|
*/
|
||||||
virtual void renderScene(Scene *scene);
|
virtual void renderScene(std::shared_ptr<Scene> scene);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a specific camera on a specific scene.
|
* Render a specific camera on a specific scene.
|
||||||
|
@ -9,15 +9,15 @@ using namespace Dawn;
|
|||||||
|
|
||||||
DawnGame::DawnGame(const std::weak_ptr<DawnHost> host) :
|
DawnGame::DawnGame(const std::weak_ptr<DawnHost> host) :
|
||||||
host(host),
|
host(host),
|
||||||
renderManager(),
|
|
||||||
inputManager(this),
|
inputManager(this),
|
||||||
saveManager(this)
|
saveManager(this)
|
||||||
{
|
{
|
||||||
|
renderManager = std::make_shared<RenderManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t DawnGame::init() {
|
int32_t DawnGame::init() {
|
||||||
this->assetManager.init();
|
this->assetManager.init();
|
||||||
this->renderManager.init(weak_from_this());
|
this->renderManager->init(weak_from_this());
|
||||||
|
|
||||||
this->scene = dawnGameGetInitialScene(this);
|
this->scene = dawnGameGetInitialScene(this);
|
||||||
|
|
||||||
@ -31,10 +31,9 @@ int32_t DawnGame::update(float_t delta) {
|
|||||||
|
|
||||||
if(this->scene != nullptr) this->scene->update();
|
if(this->scene != nullptr) this->scene->update();
|
||||||
|
|
||||||
this->renderManager.update();
|
this->renderManager->update();
|
||||||
|
|
||||||
if(this->sceneToCutTo != nullptr) {
|
if(this->sceneToCutTo != nullptr) {
|
||||||
delete this->scene;
|
|
||||||
this->scene = nullptr;
|
this->scene = nullptr;
|
||||||
this->scene = this->sceneToCutTo;
|
this->scene = this->sceneToCutTo;
|
||||||
this->sceneToCutTo = nullptr;
|
this->sceneToCutTo = nullptr;
|
||||||
@ -47,7 +46,7 @@ int32_t DawnGame::update(float_t delta) {
|
|||||||
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
|
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DawnGame::sceneCutover(Scene *scene) {
|
void DawnGame::sceneCutover(std::shared_ptr<Scene> scene) {
|
||||||
if(scene == nullptr) scene = this->scene;
|
if(scene == nullptr) scene = this->scene;
|
||||||
this->sceneToCutTo = scene;
|
this->sceneToCutTo = scene;
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,15 @@ namespace Dawn {
|
|||||||
|
|
||||||
class DawnGame : public std::enable_shared_from_this<DawnGame> {
|
class DawnGame : public std::enable_shared_from_this<DawnGame> {
|
||||||
private:
|
private:
|
||||||
Scene *sceneToCutTo = nullptr;
|
std::shared_ptr<Scene> sceneToCutTo;
|
||||||
bool_t closeRequested = false;
|
bool_t closeRequested = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const std::weak_ptr<DawnHost> host;
|
const std::weak_ptr<DawnHost> host;
|
||||||
Scene *scene = nullptr;
|
std::shared_ptr<Scene> scene;
|
||||||
AssetManager assetManager;
|
AssetManager assetManager;
|
||||||
TimeManager timeManager;
|
TimeManager timeManager;
|
||||||
RenderManager renderManager;
|
std::shared_ptr<RenderManager> renderManager;
|
||||||
InputManager inputManager;
|
InputManager inputManager;
|
||||||
SaveManager saveManager;
|
SaveManager saveManager;
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ namespace Dawn {
|
|||||||
*
|
*
|
||||||
* @param scene Scene to cut over to.
|
* @param scene Scene to cut over to.
|
||||||
*/
|
*/
|
||||||
void sceneCutover(Scene *scene);
|
void sceneCutover(std::shared_ptr<Scene> scene);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gracefully requests that the game should be closed as soon as possible.
|
* Gracefully requests that the game should be closed as soon as possible.
|
||||||
@ -90,5 +90,5 @@ namespace Dawn {
|
|||||||
* @param game Game that is requesting this scene.
|
* @param game Game that is requesting this scene.
|
||||||
* @return Pointer to a scene that you wish to have as the default scene.
|
* @return Pointer to a scene that you wish to have as the default scene.
|
||||||
*/
|
*/
|
||||||
Scene * dawnGameGetInitialScene(DawnGame *game);
|
std::shared_ptr<Scene> dawnGameGetInitialScene(DawnGame *game);
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ using namespace Dawn;
|
|||||||
|
|
||||||
Camera::Camera(SceneItem *item) :
|
Camera::Camera(SceneItem *item) :
|
||||||
SceneItemComponent(item),
|
SceneItemComponent(item),
|
||||||
renderTarget(item->scene->game->renderManager.getBackBuffer()),
|
renderTarget(item->scene->game->renderManager->getBackBuffer()),
|
||||||
fov(0.785398f),// 45 degrees,
|
fov(0.785398f),// 45 degrees,
|
||||||
type(CAMERA_TYPE_PERSPECTIVE),
|
type(CAMERA_TYPE_PERSPECTIVE),
|
||||||
orthoLeft(-0.5f),
|
orthoLeft(-0.5f),
|
||||||
|
@ -12,5 +12,5 @@ Material::Material(SceneItem *item) : SceneItemComponent(item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShaderManager & Material::getShaderManager() {
|
ShaderManager & Material::getShaderManager() {
|
||||||
return *this->getGame()->renderManager.getShaderManager();
|
return *this->getGame()->renderManager->getShaderManager();
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ namespace Dawn {
|
|||||||
class SubSceneController : public SceneItemComponent {
|
class SubSceneController : public SceneItemComponent {
|
||||||
public:
|
public:
|
||||||
// @optional
|
// @optional
|
||||||
Scene *subScene = nullptr;
|
std::shared_ptr<Scene> subScene = nullptr;
|
||||||
// @optional
|
// @optional
|
||||||
bool_t onlyUpdateUnpaused = false;
|
bool_t onlyUpdateUnpaused = false;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ float_t UIBorder::getChildOffsetY() {
|
|||||||
|
|
||||||
std::vector<struct ShaderPassItem> UIBorder::getUIRenderPasses() {
|
std::vector<struct ShaderPassItem> UIBorder::getUIRenderPasses() {
|
||||||
struct ShaderPassItem item;
|
struct ShaderPassItem item;
|
||||||
auto shader = getGame()->renderManager.uiShader;
|
auto shader = getGame()->renderManager->uiShader;
|
||||||
item.shader = shader;
|
item.shader = shader;
|
||||||
item.colorValues[shader->paramColor] = COLOR_WHITE;
|
item.colorValues[shader->paramColor] = COLOR_WHITE;
|
||||||
item.parameterBuffers[shader->bufferUiCanvas] = &this->getCanvas()->shaderBuffer;
|
item.parameterBuffers[shader->bufferUiCanvas] = &this->getCanvas()->shaderBuffer;
|
||||||
|
@ -14,9 +14,12 @@ UIComponentRenderable::UIComponentRenderable(SceneItem *i) : UIComponent(i) {
|
|||||||
std::vector<struct ShaderPassItem> UIComponentRenderable::getRenderPasses(
|
std::vector<struct ShaderPassItem> UIComponentRenderable::getRenderPasses(
|
||||||
struct IRenderableContext &context
|
struct IRenderableContext &context
|
||||||
) {
|
) {
|
||||||
|
auto renderManager = context.renderPipeline->renderManager.lock();
|
||||||
|
assertNotNull(renderManager, "RenderManager cannot be null");
|
||||||
|
|
||||||
if(
|
if(
|
||||||
context.camera->getRenderTarget() !=
|
context.camera->getRenderTarget() !=
|
||||||
context.renderPipeline->renderManager->getBackBuffer()
|
renderManager->getBackBuffer()
|
||||||
) {
|
) {
|
||||||
auto canvas = this->getCanvas();
|
auto canvas = this->getCanvas();
|
||||||
if(canvas->drawType == UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE) return {};
|
if(canvas->drawType == UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE) return {};
|
||||||
|
@ -28,7 +28,7 @@ float_t UIImage::getContentHeight() {
|
|||||||
|
|
||||||
std::vector<struct ShaderPassItem> UIImage::getUIRenderPasses() {
|
std::vector<struct ShaderPassItem> UIImage::getUIRenderPasses() {
|
||||||
struct ShaderPassItem item;
|
struct ShaderPassItem item;
|
||||||
auto shader = getGame()->renderManager.uiShader;
|
auto shader = getGame()->renderManager->uiShader;
|
||||||
item.shader = shader;
|
item.shader = shader;
|
||||||
item.colorValues[shader->paramColor] = this->color;
|
item.colorValues[shader->paramColor] = this->color;
|
||||||
item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
|
item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
|
||||||
|
@ -27,7 +27,7 @@ float_t UIMesh::getContentHeight() {
|
|||||||
|
|
||||||
std::vector<struct ShaderPassItem> UIMesh::getUIRenderPasses() {
|
std::vector<struct ShaderPassItem> UIMesh::getUIRenderPasses() {
|
||||||
struct ShaderPassItem item;
|
struct ShaderPassItem item;
|
||||||
auto shader = getGame()->renderManager.uiShader;
|
auto shader = getGame()->renderManager->uiShader;
|
||||||
item.shader = shader;
|
item.shader = shader;
|
||||||
item.colorValues[shader->paramColor] = this->color;
|
item.colorValues[shader->paramColor] = this->color;
|
||||||
item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
|
item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
|
||||||
|
@ -87,7 +87,7 @@ std::vector<struct ShaderPassItem> UILabel::getUIRenderPasses() {
|
|||||||
if(this->textsBuffered.empty()) return {};
|
if(this->textsBuffered.empty()) return {};
|
||||||
|
|
||||||
auto canvas = this->getCanvas();
|
auto canvas = this->getCanvas();
|
||||||
auto shader = getGame()->renderManager.fontShader;
|
auto shader = getGame()->renderManager->fontShader;
|
||||||
|
|
||||||
// Translate
|
// Translate
|
||||||
glm::mat4 model = transform->getWorldTransform();
|
glm::mat4 model = transform->getWorldTransform();
|
||||||
|
@ -65,9 +65,9 @@ int32_t DawnHost::init(std::shared_ptr<DawnGame> game) {
|
|||||||
assertTrue(fbWidth > 0, "Detected framebuffer height is too small?");
|
assertTrue(fbWidth > 0, "Detected framebuffer height is too small?");
|
||||||
assertTrue(windowWidth > 0, "Detected window width is too small?");
|
assertTrue(windowWidth > 0, "Detected window width is too small?");
|
||||||
assertTrue(windowHeight > 0, "Detected window height is too small?");
|
assertTrue(windowHeight > 0, "Detected window height is too small?");
|
||||||
game->renderManager.backBuffer->setSize(fbWidth, fbHeight);
|
game->renderManager->backBuffer->setSize(fbWidth, fbHeight);
|
||||||
game->renderManager.backBuffer->scale = ((float_t)fbWidth) / ((float_t)windowWidth);
|
game->renderManager->backBuffer->scale = ((float_t)fbWidth) / ((float_t)windowWidth);
|
||||||
assertTrue(game->renderManager.backBuffer->scale > 0, "Back buffer scale is invalid");
|
assertTrue(game->renderManager->backBuffer->scale > 0, "Back buffer scale is invalid");
|
||||||
assertNoGLError();
|
assertNoGLError();
|
||||||
|
|
||||||
// Default keybinds
|
// Default keybinds
|
||||||
@ -184,16 +184,16 @@ void glfwOnResize(GLFWwindow *window, int32_t w, int32_t h) {
|
|||||||
if(!host) return;
|
if(!host) return;
|
||||||
assertTrue(window == host->data->window, "glfwOnResize: Window mismatch");
|
assertTrue(window == host->data->window, "glfwOnResize: Window mismatch");
|
||||||
|
|
||||||
auto backBuffer = ((BackBufferRenderTarget*)&host->game->renderManager.backBuffer);
|
auto bb = host->game->renderManager->backBuffer;
|
||||||
assertNotNull(backBuffer, "glfwOnResize: Back buffer is not valid");
|
assertNotNull(bb, "glfwOnResize: Back buffer is not valid");
|
||||||
|
|
||||||
int32_t windowWidth, windowHeight;
|
int32_t windowWidth, windowHeight;
|
||||||
glfwGetWindowSize(window, &windowWidth, &windowHeight);
|
glfwGetWindowSize(window, &windowWidth, &windowHeight);
|
||||||
|
|
||||||
// TODO: I may throttle this, it calls for every frame the window's resized.
|
// TODO: I may throttle this, it calls for every frame the window's resized.
|
||||||
backBuffer->setSize((float_t)w, (float_t)h);
|
bb->setSize((float_t)w, (float_t)h);
|
||||||
backBuffer->scale = ((float_t)w) / ((float_t)windowWidth);
|
bb->scale = ((float_t)w) / ((float_t)windowWidth);
|
||||||
assertTrue(backBuffer->scale > 0, "glfwOnResize: Back buffer scale is invalid");
|
assertTrue(bb->scale > 0, "glfwOnResize: Back buffer scale is invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwOnKey(
|
void glfwOnKey(
|
||||||
@ -225,11 +225,11 @@ void glfwOnCursor(GLFWwindow* window, double xpos, double ypos) {
|
|||||||
if(host == nullptr) return;
|
if(host == nullptr) return;
|
||||||
|
|
||||||
host->game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_X] = mathClamp<float_t>(
|
host->game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_X] = mathClamp<float_t>(
|
||||||
(float_t)(xpos / host->game->renderManager.backBuffer->getWidth()),
|
(float_t)(xpos / host->game->renderManager->backBuffer->getWidth()),
|
||||||
0, 1
|
0, 1
|
||||||
);
|
);
|
||||||
host->game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_Y] = mathClamp<float_t>(
|
host->game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_Y] = mathClamp<float_t>(
|
||||||
(float_t)(ypos / host->game->renderManager.backBuffer->getHeight()),
|
(float_t)(ypos / host->game->renderManager->backBuffer->getHeight()),
|
||||||
0, 1
|
0, 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) {
|
std::shared_ptr<Scene> Dawn::dawnGameGetInitialScene(DawnGame *game) {
|
||||||
return new HelloWorldScene(game);
|
return std::make_shared<HelloWorldScene>(game);
|
||||||
}
|
}
|
@ -9,28 +9,29 @@
|
|||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
RenderManager::RenderManager() :
|
RenderManager::RenderManager() : IRenderManager() {
|
||||||
IRenderManager(),
|
renderPipeline = std::make_shared<RenderPipeline>();
|
||||||
renderPipeline(this)
|
shaderManager = std::make_shared<ShaderManager>();
|
||||||
{
|
|
||||||
backBuffer = std::make_shared<BackBufferRenderTarget>(*this);
|
backBuffer = std::make_shared<BackBufferRenderTarget>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderManager::init(std::weak_ptr<DawnGame> game) {
|
void RenderManager::init(std::weak_ptr<DawnGame> game) {
|
||||||
this->game = game;
|
this->game = game;
|
||||||
|
|
||||||
|
// Init the render pipeline
|
||||||
|
renderPipeline->init(std::static_pointer_cast<RenderManager>(shared_from_this()));
|
||||||
|
|
||||||
// Lock the common shaders
|
// Lock the common shaders
|
||||||
lockSimpleTextured = shaderManager.lockShader<SimpleTexturedShader>();
|
lockSimpleTextured = shaderManager->lockShader<SimpleTexturedShader>();
|
||||||
simpleTexturedShader = shaderManager.getShader<SimpleTexturedShader>(
|
simpleTexturedShader = shaderManager->getShader<SimpleTexturedShader>(
|
||||||
lockSimpleTextured
|
lockSimpleTextured
|
||||||
);
|
);
|
||||||
|
|
||||||
lockUIShaderProgram = shaderManager.lockShader<UIShader>();
|
lockUIShaderProgram = shaderManager->lockShader<UIShader>();
|
||||||
uiShader = shaderManager.getShader<UIShader>(lockUIShaderProgram);
|
uiShader = shaderManager->getShader<UIShader>(lockUIShaderProgram);
|
||||||
|
|
||||||
lockFontShader = shaderManager.lockShader<FontShader>();
|
lockFontShader = shaderManager->lockShader<FontShader>();
|
||||||
fontShader = shaderManager.getShader<FontShader>(lockFontShader);
|
fontShader = shaderManager->getShader<FontShader>(lockFontShader);
|
||||||
renderPipeline.init();
|
|
||||||
assertNoGLError();
|
assertNoGLError();
|
||||||
|
|
||||||
// Prepare the initial values
|
// Prepare the initial values
|
||||||
@ -53,12 +54,12 @@ std::shared_ptr<RenderTarget> RenderManager::getBackBuffer() {
|
|||||||
return backBuffer;
|
return backBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderPipeline * RenderManager::getRenderPipeline() {
|
std::shared_ptr<RenderPipeline> RenderManager::getRenderPipeline() {
|
||||||
return &renderPipeline;
|
return renderPipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderManager * RenderManager::getShaderManager() {
|
std::shared_ptr<ShaderManager> RenderManager::getShaderManager() {
|
||||||
return &shaderManager;
|
return shaderManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderManager::setRenderFlags(flag_t flags) {
|
void RenderManager::setRenderFlags(flag_t flags) {
|
||||||
@ -84,7 +85,7 @@ void RenderManager::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RenderManager::~RenderManager() {
|
RenderManager::~RenderManager() {
|
||||||
shaderManager.releaseShader<SimpleTexturedShader>(lockSimpleTextured);
|
shaderManager->releaseShader<SimpleTexturedShader>(lockSimpleTextured);
|
||||||
shaderManager.releaseShader<UIShader>(lockUIShaderProgram);
|
shaderManager->releaseShader<UIShader>(lockUIShaderProgram);
|
||||||
shaderManager.releaseShader<FontShader>(lockFontShader);
|
shaderManager->releaseShader<FontShader>(lockFontShader);
|
||||||
}
|
}
|
@ -15,8 +15,8 @@
|
|||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class RenderManager : public IRenderManager {
|
class RenderManager : public IRenderManager {
|
||||||
private:
|
private:
|
||||||
RenderPipeline renderPipeline;
|
std::shared_ptr<RenderPipeline> renderPipeline;
|
||||||
ShaderManager shaderManager;
|
std::shared_ptr<ShaderManager> shaderManager;
|
||||||
shaderlock_t lockSimpleTextured = -1;
|
shaderlock_t lockSimpleTextured = -1;
|
||||||
shaderlock_t lockUIShaderProgram = -1;
|
shaderlock_t lockUIShaderProgram = -1;
|
||||||
shaderlock_t lockFontShader = -1;
|
shaderlock_t lockFontShader = -1;
|
||||||
@ -33,8 +33,8 @@ namespace Dawn {
|
|||||||
RenderManager();
|
RenderManager();
|
||||||
|
|
||||||
std::shared_ptr<RenderTarget> getBackBuffer() override;
|
std::shared_ptr<RenderTarget> getBackBuffer() override;
|
||||||
RenderPipeline * getRenderPipeline() override;
|
std::shared_ptr<RenderPipeline> getRenderPipeline() override;
|
||||||
ShaderManager * getShaderManager() override;
|
std::shared_ptr<ShaderManager> getShaderManager() override;
|
||||||
void setRenderFlags(flag_t renderFlags) override;
|
void setRenderFlags(flag_t renderFlags) override;
|
||||||
void init(std::weak_ptr<DawnGame> game) override;
|
void init(std::weak_ptr<DawnGame> game) override;
|
||||||
void update() override;
|
void update() override;
|
||||||
|
Reference in New Issue
Block a user