Documenting done.
This commit is contained in:
@ -21,6 +21,62 @@ void RenderPipeline::render() {
|
||||
this->renderScene(*this->renderManager.game.scene);
|
||||
}
|
||||
|
||||
void RenderPipeline::renderScene(Scene &scene) {
|
||||
RenderTarget &backBuffer = this->renderManager.getBackBuffer();
|
||||
auto cameras = scene.findComponents<Camera>();
|
||||
std::shared_ptr<Camera> backBufferCamera = nullptr;
|
||||
|
||||
// First, render all non-backbuffer cameras.
|
||||
auto it = cameras.begin();
|
||||
while(it != cameras.end()) {
|
||||
RenderTarget &cameraTarget = (*it)->getRenderTarget();
|
||||
|
||||
// Leave the backbuffer camera(s) to last, so we skip them.
|
||||
if(&cameraTarget == &backBuffer) {
|
||||
backBufferCamera = *it;
|
||||
} else {
|
||||
this->renderSceneCamera(scene, **it);
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
// Now render the backbuffer camera.
|
||||
if(backBufferCamera == nullptr) return;
|
||||
this->renderSceneCamera(scene, *backBufferCamera);
|
||||
}
|
||||
|
||||
void RenderPipeline::renderSceneCamera(Scene &scene, Camera &camera) {
|
||||
RenderTarget &renderTarget = camera.getRenderTarget();
|
||||
renderTarget.bind();
|
||||
renderTarget.clear(
|
||||
RENDER_TARGET_CLEAR_FLAG_DEPTH |
|
||||
RENDER_TARGET_CLEAR_FLAG_COLOR
|
||||
);
|
||||
|
||||
auto meshes = scene.findComponents<MeshRenderer>();
|
||||
auto it = meshes.begin();
|
||||
while(it != meshes.end()) {
|
||||
auto mesh = *it;
|
||||
auto item = mesh->item;
|
||||
auto material = item.getComponent<Material>();
|
||||
|
||||
// TODO: fallback material?
|
||||
if(material == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto shader = material->getShader();
|
||||
shader->bind();
|
||||
shader->setGlobalParameters(camera.projection, camera.item.transform);
|
||||
shader->setMeshParameters(item.transform);
|
||||
material->setShaderParameters();
|
||||
|
||||
mesh->mesh->draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
|
||||
}
|
@ -14,11 +14,44 @@ namespace Dawn {
|
||||
public:
|
||||
RenderManager &renderManager;
|
||||
|
||||
/**
|
||||
* Constructs a new RenderPipeline. Render Pipelines are my attempt to
|
||||
* create both a flexible, but standard way to allow the individual games
|
||||
* to decide how they want to render the common scene-item models.
|
||||
*
|
||||
* @param renderManager Parent render manager this pipeline belongs to.
|
||||
*/
|
||||
RenderPipeline(RenderManager &renderManager);
|
||||
|
||||
/**
|
||||
* Initialize the render pipeline.
|
||||
*/
|
||||
virtual void init();
|
||||
void render();
|
||||
virtual void renderScene(Scene &scene) = 0;
|
||||
|
||||
/**
|
||||
* Renders the games' currently active scene, and all of its' cameras.
|
||||
*/
|
||||
virtual void render();
|
||||
|
||||
/**
|
||||
* Render a specific scene, usually just called for the currently active
|
||||
* scene, but in future this could include sub-scenes.
|
||||
*
|
||||
* @param scene Scene to render.
|
||||
*/
|
||||
virtual void renderScene(Scene &scene);
|
||||
|
||||
/**
|
||||
* Render a specific camera on a specific scene.
|
||||
*
|
||||
* @param scene Scene to render.
|
||||
* @param camera Camera within the scene to render.
|
||||
*/
|
||||
virtual void renderSceneCamera(Scene &scene, Camera &camera) = 0;
|
||||
|
||||
/**
|
||||
* Cleanup a render pipeline that has been initialized.
|
||||
*/
|
||||
virtual ~RenderPipeline();
|
||||
};
|
||||
}
|
@ -13,10 +13,43 @@
|
||||
namespace Dawn {
|
||||
class RenderTarget {
|
||||
public:
|
||||
/**
|
||||
* Return the width of the render target.
|
||||
*
|
||||
* @return The width of the render target.
|
||||
*/
|
||||
virtual float_t getWidth() = 0;
|
||||
|
||||
/**
|
||||
* Return the height of the render target.
|
||||
*
|
||||
* @return The height of the render target.
|
||||
*/
|
||||
virtual float_t getHeight() = 0;
|
||||
|
||||
/**
|
||||
* Sets the clear color of the render target when the clear method for
|
||||
* the color buffer is requested.
|
||||
*
|
||||
* @param color Color to use for the clear operation.
|
||||
*/
|
||||
virtual void setClearColor(struct Color color) = 0;
|
||||
|
||||
/**
|
||||
* Request the existing data in the render target to be cleared out. We
|
||||
* typically assume the render target can support multiple buffer types,
|
||||
* so you can opt to only clear certain buffer types.
|
||||
*
|
||||
* @param clearFlags Flags to request what is going to be cleared.
|
||||
*/
|
||||
virtual void clear(flag8_t clearFlags) = 0;
|
||||
|
||||
/**
|
||||
* Bind the render target for rendering to. The proceeding render requests
|
||||
* will want to render to this render target directly. In future I may
|
||||
* see if we can have multiple render targets bound at once to make this
|
||||
* operation perform faster.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
};
|
||||
}
|
@ -58,7 +58,5 @@ namespace Dawn {
|
||||
* Perform a synchronous frame update on the render manager.
|
||||
*/
|
||||
virtual void update() = 0;
|
||||
|
||||
|
||||
};
|
||||
}
|
@ -24,16 +24,33 @@ namespace Dawn {
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
// virtual void setCamera(glm::mat4 projection, glm::mat4 view) = 0;
|
||||
// virtual void setLocalPosition(glm::mat4 position) = 0;
|
||||
|
||||
/**
|
||||
* Requested by the Material to set the default parameters of the shader.
|
||||
* Each parameter really should have a default value set so that there is
|
||||
* no nullptr's or other issues.
|
||||
*
|
||||
* @param material Material to set the default parameters on to.
|
||||
*/
|
||||
virtual void setDefaultParameters(Material &material) = 0;
|
||||
|
||||
/**
|
||||
* Requested by the render pipeline (typically) to set global level (once
|
||||
* per frame) parameters.
|
||||
*
|
||||
* @param projection Projection matrix of the current viewport.
|
||||
* @param view View matrix of the current viewport.
|
||||
*/
|
||||
virtual void setGlobalParameters(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Requested by the render pipeline (typically) to set mesh-level params.
|
||||
* This may be performed multiple times per frame.
|
||||
*
|
||||
* @param position Matrix of the position of the mesh.
|
||||
*/
|
||||
virtual void setMeshParameters(glm::mat4 position) = 0;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user