First working example

This commit is contained in:
2023-05-29 19:50:04 -07:00
parent 96dd33c6b8
commit 8da23b123a
21 changed files with 263 additions and 161 deletions

View File

@ -93,6 +93,8 @@ void RenderPipeline::init() {
// 0.0f
// );
// glyphMesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
this->shaderBuffer.init();
}
void RenderPipeline::render() {
@ -167,6 +169,11 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
assertNotNull(renderTarget);
// Update shader parameter buffers with current knowledge
struct RenderPipelineShaderBufferData shaderBufferData;
shaderBufferData.projection = camera->getProjection();
shaderBufferData.view = camera->transform->getWorldTransform();
this->shaderBuffer.buffer(&shaderBufferData);
this->camera = camera;
// Get the list of things to render first.
@ -219,6 +226,9 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
// Now we've sorted everything! Let's actually start rendering.
Shader *boundShader = nullptr;
std::map<textureslot_t, Texture*> boundTextures;
std::map<shaderbufferlocation_t, shaderbufferslot_t> locationSlotMap;
std::map<IShaderParameterBuffer<shaderbufferlocation_t>*, shaderbufferslot_t> bufferSlotMap;
shaderbufferslot_t globalSlot = 0;
// TODO: This will be editable!
renderTarget->bind();
@ -251,6 +261,29 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
++itTextureSlot;
}
// Bind the buffers to their slots
auto itBufferSlot = item.parameterBuffers.begin();
while(itBufferSlot != item.parameterBuffers.end()) {
// First check if buffer is already bound
auto location = itBufferSlot->first;
auto buff = itBufferSlot->second;
// auto existingBind = bufferSlotMap.find(buff);
shaderbufferslot_t slot;
// if(existingBind == bufferSlotMap.end()) {
// Not bound, let's find a slot we can use!
// slot = -1;
slot = globalSlot++;
// } else {
// // Already bound
// slot = existingBind->second;
// }
buff->bind(slot);
locationSlotMap[itBufferSlot->first] = slot;
++itBufferSlot;
}
// Now set each of the parameters. Nothing exciting here.
auto itColors = item.colorValues.begin();
while(itColors != item.colorValues.end()) {
@ -282,6 +315,12 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
++itText;
}
auto itBuffer = item.parameterBuffers.begin();
while(itBuffer != item.parameterBuffers.end()) {
item.shader->setParameterBuffer(itBuffer->first, locationSlotMap[itBuffer->first]);
++itBuffer;
}
auto itFloat = item.floatValues.begin();
while(itFloat != item.floatValues.end()) {
item.shader->setFloat(itFloat->first, itFloat->second);

View File

@ -10,6 +10,7 @@
#include "scene/components/scene/SubSceneController.hpp"
#include "scene/components/ui/UIComponent.hpp"
#include "display/shader/ShaderPass.hpp"
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
namespace Dawn {
class RenderManager;
@ -23,6 +24,7 @@ namespace Dawn {
// Temporary hack
Camera *camera = nullptr;
RenderPipelineShaderBuffer shaderBuffer;
/**
* Constructs a new RenderPipeline. Render Pipelines are my attempt to

View File

@ -6,6 +6,7 @@
#pragma once
#include "display/shader/Shader.hpp"
#include "display/mesh/Mesh.hpp"
#include "display/shader/ShaderParameterBuffer.hpp"
namespace Dawn {
struct ShaderPassItem {
@ -26,6 +27,7 @@ namespace Dawn {
std::map<shaderparameter_t, glm::vec3> vec3Values;
std::map<shaderparameter_t, textureslot_t> textureValues;
std::map<shaderparameter_t, float_t> floatValues;
std::map<shaderbufferlocation_t, IShaderParameterBuffer<shaderbufferslot_t>*> parameterBuffers;
// Textures
std::map<textureslot_t, Texture*> textureSlots;

View File

@ -7,7 +7,7 @@
#include "dawnlibs.hpp"
namespace Dawn {
template<typename T, typename L>
template<typename L>
class IShaderParameterBuffer {
public:
/**
@ -15,14 +15,6 @@ namespace Dawn {
*/
virtual void init() = 0;
/**
* Basic buffer method. Buffers the entire contents of the data struct to
* this shader parameter buffer.
*
* @param data Data to buffer to the parameter.
*/
virtual void buffer(T *data) = 0;
/**
* Bind this shader buffer to the supplied location.
*

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#include "SceneDebugLine.hpp"
#include "display/shader/SimpleTexturedShader.hpp"
#include "display/shader/shaders/SimpleTexturedShader.hpp"
#include "scene/components/display/Camera.hpp"
#include "scene/Scene.hpp"
#include "scene/components/physics/3d/Collider3D.hpp"