Cleaned some of the render pass stuff
This commit is contained in:
		@@ -4,133 +4,11 @@
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "game/Game.hpp"
 | 
			
		||||
#include "scene/Scene.hpp"
 | 
			
		||||
#include "display/pass/RenderPass.hpp"
 | 
			
		||||
#include "display/pass/RenderPassContext.hpp"
 | 
			
		||||
#include "display/mesh/Mesh.hpp"
 | 
			
		||||
#include "display/shader/Shader.hpp"
 | 
			
		||||
#include "component/display/Camera.hpp"
 | 
			
		||||
#include "component/display/MeshRenderer.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  class IRenderPass {
 | 
			
		||||
    public:
 | 
			
		||||
      std::shared_ptr<Mesh> mesh;
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Binds the shader for this render pass.
 | 
			
		||||
       */
 | 
			
		||||
      virtual void bind() = 0;
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Sets the data for this render pass to the shader.
 | 
			
		||||
       */
 | 
			
		||||
      virtual void setData() = 0;
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Uploads the data to the GPU.
 | 
			
		||||
       */
 | 
			
		||||
      virtual void upload() = 0;
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Draws the mesh for this render pass.
 | 
			
		||||
       */
 | 
			
		||||
      virtual void draw() = 0;
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Cleans up the render pass.
 | 
			
		||||
       */
 | 
			
		||||
      virtual ~IRenderPass() {
 | 
			
		||||
      }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  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 {
 | 
			
		||||
      }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  struct RenderPassContext {
 | 
			
		||||
    std::shared_ptr<Game> game;
 | 
			
		||||
    std::shared_ptr<Scene> scene;
 | 
			
		||||
    std::shared_ptr<Camera> camera;
 | 
			
		||||
    std::shared_ptr<RenderTarget> renderTarget;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  class IRenderableComponent {
 | 
			
		||||
    public:
 | 
			
		||||
      /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user