94 lines
2.5 KiB
C++
94 lines
2.5 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#include "game/Game.hpp"
|
|
#include "display/pass/IRenderPass.hpp"
|
|
#include "display/shader/Shader.hpp"
|
|
#include "display/Texture.hpp"
|
|
#include "component/display/MeshRenderer.hpp"
|
|
|
|
namespace Dawn {
|
|
template<class S, typename D>
|
|
class RenderPass : public IRenderPass {
|
|
private:
|
|
std::shared_ptr<S> shader;
|
|
const std::unordered_map<
|
|
shadertexturebinding_t, std::shared_ptr<Texture>
|
|
> textures;
|
|
std::shared_ptr<Mesh> mesh;
|
|
const enum MeshDrawMode drawMode;
|
|
const int32_t indiceStart;
|
|
const int32_t indiceCount;
|
|
const D data;
|
|
|
|
public:
|
|
/**
|
|
* Constructs a new RenderPass.
|
|
*
|
|
* @param self Self component instance that is creating this render pass.
|
|
* @param d The data to use for this render pass.
|
|
* @param mesh The mesh to use for this render pass.
|
|
* @param drawMode The draw mode to use for this render pass.
|
|
* @param indiceStart The indice to start drawing from.
|
|
* @param indiceCount The number of indices to draw.
|
|
*/
|
|
RenderPass(
|
|
SceneComponent &self,
|
|
const D d,
|
|
const std::unordered_map<
|
|
shadertexturebinding_t, std::shared_ptr<Texture>
|
|
> textures,
|
|
const std::shared_ptr<Mesh> mesh,
|
|
const enum MeshDrawMode drawMode,
|
|
const int32_t indiceStart,
|
|
const int32_t indiceCount
|
|
) :
|
|
data(d),
|
|
textures(textures),
|
|
mesh(mesh),
|
|
drawMode(drawMode),
|
|
indiceStart(indiceStart),
|
|
indiceCount(indiceCount)
|
|
{
|
|
//Get the shader
|
|
shader = (
|
|
self.getGame()->renderHost.shaderManager.getShader<S>()
|
|
);
|
|
assertNotNull(shader, "Shader cannot be null!");
|
|
|
|
// Need mesh?
|
|
if(!this->mesh) {
|
|
auto meshRenderer = self.getItem()->getComponent<MeshRenderer>();
|
|
if(meshRenderer) this->mesh = meshRenderer->mesh;
|
|
}
|
|
}
|
|
|
|
void bind() override {
|
|
shader->bind();
|
|
}
|
|
|
|
void setData() override {
|
|
shader->setData(data);
|
|
}
|
|
|
|
void upload() override {
|
|
for(auto &pair : textures) {
|
|
if(!pair.second->isReady()) continue;
|
|
pair.second->bind(pair.first);
|
|
}
|
|
shader->upload();
|
|
}
|
|
|
|
void draw() override {
|
|
if(mesh) {
|
|
mesh->draw(drawMode, indiceStart, indiceCount);
|
|
}
|
|
}
|
|
|
|
~RenderPass() override {
|
|
}
|
|
};
|
|
} |