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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user