Shaders improved
This commit is contained in:
@ -58,14 +58,14 @@ namespace Dawn {
|
||||
*
|
||||
* @param renderFlags Render flags to use.
|
||||
*/
|
||||
virtual void setRenderFlags(flag_t renderFlags) = 0;
|
||||
virtual void setRenderFlags(const flag_t renderFlags) = 0;
|
||||
|
||||
/**
|
||||
* Initialize / Start the Render Manager.
|
||||
*
|
||||
* @param game Game instance this render manager belongs to.
|
||||
*/
|
||||
virtual void init(std::weak_ptr<DawnGame> game) = 0;
|
||||
virtual void init(const std::weak_ptr<DawnGame> game) = 0;
|
||||
|
||||
/**
|
||||
* Perform a synchronous frame update on the render manager.
|
||||
|
@ -174,7 +174,7 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr<Scene> scene, std::shared
|
||||
);
|
||||
|
||||
// Now we've sorted everything! Let's actually start rendering.
|
||||
Shader *boundShader = nullptr;
|
||||
std::shared_ptr<Shader> boundShader;
|
||||
std::map<textureslot_t, Texture*> boundTextures;
|
||||
std::map<shaderbufferlocation_t, shaderbufferslot_t> boundBuffers;
|
||||
shaderbufferslot_t slot;
|
||||
|
@ -13,9 +13,4 @@ ShaderManager::ShaderManager() {
|
||||
}
|
||||
|
||||
ShaderManager::~ShaderManager() {
|
||||
auto it = this->shaders.begin();
|
||||
while(it != this->shaders.end()) {
|
||||
delete it->second;
|
||||
++it;
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace Dawn {
|
||||
private:
|
||||
int32_t nextId;
|
||||
shaderlock_t nextLock;
|
||||
std::map<shaderid_t, Shader*> shaders;
|
||||
std::map<shaderid_t, std::shared_ptr<Shader>> shaders;
|
||||
std::map<shaderlock_t, shaderid_t> shaderLocks;
|
||||
std::map<shaderid_t, std::vector<shaderlock_t>> shaderLocksByShader;
|
||||
|
||||
@ -28,7 +28,7 @@ namespace Dawn {
|
||||
shaderid_t getShaderId() {
|
||||
auto it = shaders.begin();
|
||||
while(it != shaders.end()) {
|
||||
auto asT = dynamic_cast<T*>(it->second);
|
||||
auto asT = std::dynamic_pointer_cast<T>(it->second);
|
||||
if(asT != nullptr) return asT->shaderId;
|
||||
++it;
|
||||
}
|
||||
@ -52,7 +52,7 @@ namespace Dawn {
|
||||
shaderlock_t lockShader() {
|
||||
auto shaderId = this->getShaderId<T>();
|
||||
if(shaderId == -1) {
|
||||
T* shader = new T();
|
||||
auto shader = std::make_shared<T>();
|
||||
shader->compile();
|
||||
shader->shaderId = this->nextId++;
|
||||
this->shaders[shader->shaderId] = shader;
|
||||
@ -72,9 +72,9 @@ namespace Dawn {
|
||||
* @return The shader for the given lock.
|
||||
*/
|
||||
template<class T>
|
||||
T * getShader(shaderlock_t lock) {
|
||||
std::shared_ptr<T> getShader(shaderlock_t lock) {
|
||||
auto shaderId = this->shaderLocks[lock];
|
||||
return (T*)this->shaders[shaderId];
|
||||
return std::static_pointer_cast<T>(this->shaders[shaderId]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,8 +94,6 @@ namespace Dawn {
|
||||
|
||||
if(locks.size() == 0) {
|
||||
this->shaderLocksByShader.erase(shaderId);
|
||||
auto shader = (T*)this->shaders[shaderId];
|
||||
delete shader;
|
||||
this->shaders.erase(shaderId);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace Dawn {
|
||||
struct ShaderPassItem;
|
||||
|
||||
struct ShaderPassItem {
|
||||
Shader *shader = nullptr;
|
||||
std::shared_ptr<Shader> shader;
|
||||
int32_t priority = 0;
|
||||
std::vector<struct ShaderPassItem>::iterator index;
|
||||
|
||||
|
@ -9,7 +9,7 @@ using namespace Dawn;
|
||||
|
||||
DawnGame::DawnGame(const std::weak_ptr<DawnHost> host) :
|
||||
host(host),
|
||||
inputManager(this),
|
||||
inputManager(),
|
||||
saveManager(this)
|
||||
{
|
||||
renderManager = std::make_shared<RenderManager>();
|
||||
|
@ -71,7 +71,7 @@ namespace Dawn {
|
||||
* @param delta How much time has passed (in seconds) since the last tick.
|
||||
* @return A status code, refer to DAWN_HOST_UPDATE_RESULT_{} definitions.
|
||||
*/
|
||||
int32_t update(std::shared_ptr<DawnGame> game, float_t delta);
|
||||
int32_t update(std::shared_ptr<DawnGame> game, const float_t delta);
|
||||
|
||||
/**
|
||||
* Request the host to be unloaded. This is a bit different from dispose
|
||||
|
@ -31,16 +31,9 @@ namespace Dawn {
|
||||
virtual float_t getInputValue(T axis) = 0;
|
||||
|
||||
public:
|
||||
DawnGame *game;
|
||||
|
||||
StateEvent<inputbind_t> eventBindPressed;
|
||||
StateEvent<inputbind_t> eventBindReleased;
|
||||
|
||||
IInputManager(DawnGame *game) {
|
||||
assertNotNull(game, "IInputManager::IInputManager: Game cannot be null");
|
||||
this->game = game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds an axis to a bind.
|
||||
*
|
||||
|
@ -8,10 +8,6 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
InputManager::InputManager(DawnGame *game) : IInputManager<int32_t>(game) {
|
||||
|
||||
}
|
||||
|
||||
float_t InputManager::getInputValue(int32_t axis) {
|
||||
auto exist = this->rawInputValues.find(axis);
|
||||
if(exist == this->rawInputValues.end()) return 0.0f;
|
||||
|
@ -17,7 +17,5 @@ namespace Dawn {
|
||||
|
||||
public:
|
||||
std::map<int32_t, float_t> rawInputValues;
|
||||
|
||||
InputManager(DawnGame *game);
|
||||
};
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "dawnopengl.hpp"
|
||||
#include "assert/assertgl.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "display/RenderManager.hpp"
|
||||
|
||||
@ -15,11 +16,13 @@ RenderManager::RenderManager() : IRenderManager() {
|
||||
backBuffer = std::make_shared<BackBufferRenderTarget>(*this);
|
||||
}
|
||||
|
||||
void RenderManager::init(std::weak_ptr<DawnGame> game) {
|
||||
void RenderManager::init(const std::weak_ptr<DawnGame> game) {
|
||||
this->game = game;
|
||||
|
||||
// Init the render pipeline
|
||||
renderPipeline->init(std::static_pointer_cast<RenderManager>(shared_from_this()));
|
||||
renderPipeline->init(
|
||||
std::static_pointer_cast<RenderManager>(shared_from_this())
|
||||
);
|
||||
|
||||
// Lock the common shaders
|
||||
lockSimpleTextured = shaderManager->lockShader<SimpleTexturedShader>();
|
||||
@ -62,7 +65,7 @@ std::shared_ptr<ShaderManager> RenderManager::getShaderManager() {
|
||||
return shaderManager;
|
||||
}
|
||||
|
||||
void RenderManager::setRenderFlags(flag_t flags) {
|
||||
void RenderManager::setRenderFlags(const flag_t flags) {
|
||||
renderFlags = flags;
|
||||
|
||||
if((flags & RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST) == 0) {
|
||||
|
@ -4,7 +4,6 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "assert/assertgl.hpp"
|
||||
#include "display/BackBufferRenderTarget.hpp"
|
||||
#include "display/shader/ShaderManager.hpp"
|
||||
#include "display/shader/shaders/SimpleTexturedShader.hpp"
|
||||
@ -23,9 +22,9 @@ namespace Dawn {
|
||||
|
||||
public:
|
||||
std::shared_ptr<BackBufferRenderTarget> backBuffer;
|
||||
SimpleTexturedShader *simpleTexturedShader = nullptr;
|
||||
UIShader *uiShader = nullptr;
|
||||
FontShader *fontShader = nullptr;
|
||||
std::shared_ptr<SimpleTexturedShader> simpleTexturedShader;
|
||||
std::shared_ptr<UIShader> uiShader;
|
||||
std::shared_ptr<FontShader> fontShader;
|
||||
|
||||
/**
|
||||
* Construct a new RenderManager for a game instance.
|
||||
@ -35,8 +34,8 @@ namespace Dawn {
|
||||
std::shared_ptr<RenderTarget> getBackBuffer() override;
|
||||
std::shared_ptr<RenderPipeline> getRenderPipeline() override;
|
||||
std::shared_ptr<ShaderManager> getShaderManager() override;
|
||||
void setRenderFlags(flag_t renderFlags) override;
|
||||
void init(std::weak_ptr<DawnGame> game) override;
|
||||
void setRenderFlags(const flag_t renderFlags) override;
|
||||
void init(const std::weak_ptr<DawnGame> game) override;
|
||||
void update() override;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user