Stuff I've fixed so far.

This commit is contained in:
2023-01-19 20:24:43 -08:00
parent 77cf0e574d
commit 2dacb6f904
12 changed files with 72 additions and 43 deletions

View File

@ -78,7 +78,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
// Create a new render ID. Long story short this is a really dirty way of // Create a new render ID. Long story short this is a really dirty way of
// not sending parameters to shaders more than we need. // not sending parameters to shaders more than we need.
this->renderId++; this->renderId--;
// Get the list of things to render first. // Get the list of things to render first.
std::vector<struct RenderPipelineItem> pipelineItems; std::vector<struct RenderPipelineItem> pipelineItems;
@ -106,6 +106,9 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
item.mesh = mesh; item.mesh = mesh;
item.pass = *itPass; item.pass = *itPass;
// Validate the pass
assertNotNull(item.pass.shaderProgram);
// Do we need to get the W Vector? // Do we need to get the W Vector?
if(item.pass.needsW) { if(item.pass.needsW) {
assertUnreachable();// TODO: Add distance from camera for W vector. assertUnreachable();// TODO: Add distance from camera for W vector.
@ -169,13 +172,16 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
// Bind the program. // Bind the program.
if(boundProgram != item.pass.shaderProgram) { if(boundProgram != item.pass.shaderProgram) {
boundProgram->bind();
boundProgram = item.pass.shaderProgram; boundProgram = item.pass.shaderProgram;
boundProgram->bind();
} }
// Bind the textures to the slots // Bind the textures to the slots
auto itTextureSlot = item.pass.textureSlots.begin(); auto itTextureSlot = item.pass.textureSlots.begin();
while(itTextureSlot != item.pass.textureSlots.end()) { while(itTextureSlot != item.pass.textureSlots.end()) {
// Assert texture isn't null, just don't include it.
assertNotNull(itTextureSlot->second);
if(boundTextures[itTextureSlot->first] != itTextureSlot->second) { if(boundTextures[itTextureSlot->first] != itTextureSlot->second) {
itTextureSlot->second->bind(itTextureSlot->first); itTextureSlot->second->bind(itTextureSlot->first);
boundTextures[itTextureSlot->first] = itTextureSlot->second; boundTextures[itTextureSlot->first] = itTextureSlot->second;

View File

@ -22,7 +22,7 @@ namespace Dawn {
class RenderPipeline { class RenderPipeline {
private: private:
int_fast16_t renderId; int_fast16_t renderId = -1;
public: public:
RenderManager *renderManager; RenderManager *renderManager;

View File

@ -52,14 +52,6 @@ namespace Dawn {
*/ */
virtual RenderPipeline * getRenderPipeline() = 0; virtual RenderPipeline * getRenderPipeline() = 0;
/**
* Returns the default shader, the default shader will be applied to the
* materials first.
*
* @return Reference to the default shader.
*/
virtual Shader * getDefaultShader() = 0;
/** /**
* Returns the UI Shader used by the game's UI engine. * Returns the UI Shader used by the game's UI engine.
* *

View File

@ -11,9 +11,9 @@ namespace Dawn {
class Material; class Material;
struct ShaderPass { struct ShaderPass {
ShaderProgram *shaderProgram; ShaderProgram *shaderProgram = nullptr;
int32_t orderShader; int32_t orderShader = 0;
bool_t needsW; bool_t needsW = false;
// Parameters // Parameters
std::map<shaderparameter_t, struct Color> colorValues; std::map<shaderparameter_t, struct Color> colorValues;
@ -29,7 +29,7 @@ namespace Dawn {
class Shader { class Shader {
public: public:
int_fast16_t renderId; int_fast16_t renderId = 0;
/** /**
* Compile all programs for this shader. This amy not remain forever as I * Compile all programs for this shader. This amy not remain forever as I

View File

@ -8,6 +8,7 @@
#include "game/DawnGame.hpp" #include "game/DawnGame.hpp"
#include "scene/components/display/MeshRenderer.hpp" #include "scene/components/display/MeshRenderer.hpp"
#include "display/mesh/CubeMesh.hpp" #include "display/mesh/CubeMesh.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
using namespace Dawn; using namespace Dawn;
@ -17,7 +18,7 @@ SceneItem * ExampleSpin::create(Scene *scene) {
mr->mesh = new Mesh(); mr->mesh = new Mesh();
mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT); mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0); CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0);
auto mat = item->addComponent<Material>(); auto mat = item->addComponent<SimpleTexturedMaterial>();
item->addComponent<ExampleSpin>(); item->addComponent<ExampleSpin>();
return item; return item;

View File

@ -14,13 +14,12 @@ RenderManager::RenderManager(DawnGame *game) :
backBuffer(*this), backBuffer(*this),
renderPipeline(this) renderPipeline(this)
{ {
this->simpleShader = new SimpleTexturedShader();
this->uiShader = new UIShader(); this->uiShader = new UIShader();
} }
void RenderManager::init() { void RenderManager::init() {
this->renderPipeline.init(); this->renderPipeline.init();
this->simpleShader->compile(); this->simpleShader.compile();
this->uiShader->compile(); this->uiShader->compile();
// Prepare the initial values // Prepare the initial values
@ -38,10 +37,6 @@ RenderPipeline * RenderManager::getRenderPipeline() {
return &this->renderPipeline; return &this->renderPipeline;
} }
Shader * RenderManager::getDefaultShader() {
return this->simpleShader;
}
UIShader * RenderManager::getUIShader() { UIShader * RenderManager::getUIShader() {
return this->uiShader; return this->uiShader;
} }
@ -67,6 +62,5 @@ void RenderManager::update() {
} }
RenderManager::~RenderManager() { RenderManager::~RenderManager() {
delete this->simpleShader;
delete this->uiShader; delete this->uiShader;
} }

View File

@ -16,7 +16,7 @@ namespace Dawn {
public: public:
BackBufferRenderTarget backBuffer; BackBufferRenderTarget backBuffer;
SimpleTexturedShader *simpleShader; SimpleTexturedShader simpleShader;
UIShader *uiShader; UIShader *uiShader;
/** /**
@ -26,7 +26,6 @@ namespace Dawn {
RenderTarget * getBackBuffer() override; RenderTarget * getBackBuffer() override;
RenderPipeline * getRenderPipeline() override; RenderPipeline * getRenderPipeline() override;
Shader * getDefaultShader() override;
UIShader * getUIShader() override; UIShader * getUIShader() override;
void setRenderFlags(renderflag_t renderFlags) override; void setRenderFlags(renderflag_t renderFlags) override;
void init() override; void init() override;

View File

@ -0,0 +1,43 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SimpleTexturedShader.hpp"
using namespace Dawn;
void SimpleTexturedShader::compile() {
this->program.compile();
}
std::vector<struct ShaderPass> SimpleTexturedShader::getItemPasses(
MeshRenderer *mesh, Material *material
) {
SimpleTexturedMaterial *simpleMaterial = dynamic_cast<SimpleTexturedMaterial*>(material);
assertNotNull(simpleMaterial);
struct ShaderPass onlyPass;
onlyPass.shaderProgram = &program;
onlyPass.colorValues[program.paramColor] = simpleMaterial->color;
onlyPass.matrixValues[program.paramModel] = mesh->transform->getWorldTransform();
if(simpleMaterial->texture != nullptr) {
onlyPass.boolValues[program.paramHasTexture] = true;
onlyPass.textureSlots[0] = simpleMaterial->texture;
onlyPass.textureValues[program.paramTexture] = 0;
} else {
onlyPass.boolValues[program.paramHasTexture] = false;
}
std::vector<struct ShaderPass> passes;
passes.push_back(onlyPass);
return passes;
}
void SimpleTexturedShader::setGlobalParameters(
glm::mat4 cameraProjection, glm::mat4 cameraView
) {
this->program.setMatrix(this->program.paramProjection, cameraProjection);
this->program.setMatrix(this->program.paramView, cameraView);
}

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include "display/shader/Shader.hpp" #include "display/shader/Shader.hpp"
#include "SimpleTexturedShaderProgram.hpp" #include "SimpleTexturedShaderProgram.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
namespace Dawn { namespace Dawn {
class SimpleTexturedShader : public Shader { class SimpleTexturedShader : public Shader {
@ -13,21 +14,14 @@ namespace Dawn {
SimpleTexturedShaderProgram program; SimpleTexturedShaderProgram program;
public: public:
void compile() override { void compile() override;
this->program.compile();
}
std::vector<struct ShaderPass> getItemPasses( std::vector<struct ShaderPass> getItemPasses(
MeshRenderer *mesh, MeshRenderer *mesh, Material *material
Material *material ) override;
) override {
return std::vector<struct ShaderPass>();
}
void setGlobalParameters( void setGlobalParameters(
glm::mat4 cameraProjection, glm::mat4 cameraProjection, glm::mat4 cameraView
glm::mat4 cameraView ) override;
) override {
}
}; };
} }

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "SimpleTexturedMaterial.hpp" #include "SimpleTexturedMaterial.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn; using namespace Dawn;
@ -13,5 +14,5 @@ SimpleTexturedMaterial::SimpleTexturedMaterial(SceneItem *i) :
} }
Shader * SimpleTexturedMaterial::getShader() { Shader * SimpleTexturedMaterial::getShader() {
return this->shader; return &this->getGame()->renderManager.simpleShader;
} }

View File

@ -4,13 +4,11 @@
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "display/shader/SimpleTexturedShader.hpp"
#include "scene/components/display/Material.hpp" #include "scene/components/display/Material.hpp"
namespace Dawn { namespace Dawn {
class SimpleTexturedMaterial : public Material { class SimpleTexturedMaterial : public Material {
public: public:
SimpleTexturedShader *shader = nullptr;
Texture *texture = nullptr; Texture *texture = nullptr;
struct Color color = COLOR_WHITE; struct Color color = COLOR_WHITE;

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include "scene/Scene.hpp" #include "scene/Scene.hpp"
#include "game/DawnGame.hpp" #include "game/DawnGame.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
namespace Dawn { namespace Dawn {
template<class T> template<class T>
@ -35,9 +36,9 @@ namespace Dawn {
this->sceneItem = this->createSceneItem(); this->sceneItem = this->createSceneItem();
auto host = this->sceneItem->addComponent<MeshHost>(); auto host = this->sceneItem->addComponent<MeshHost>();
auto renderer = this->sceneItem->addComponent<MeshRenderer>(); auto renderer = this->sceneItem->addComponent<MeshRenderer>();
auto material = this->sceneItem->addComponent<Material>(); auto material = this->sceneItem->addComponent<SimpleTexturedMaterial>();
material->textureValues[material->getShader()->getParameterByName("u_Text")] = this->subScene.renderTarget.getTexture(); material->texture = this->subScene.renderTarget.getTexture();
auto renderTargetQuad = this->sceneItem->addComponent<SimpleRenderTargetQuad>(); auto renderTargetQuad = this->sceneItem->addComponent<SimpleRenderTargetQuad>();
renderTargetQuad->setRenderTarget(&this->subScene.renderTarget); renderTargetQuad->setRenderTarget(&this->subScene.renderTarget);