glClear is causing stack corrpution

This commit is contained in:
2023-11-19 01:16:41 -06:00
parent 437b67ad06
commit 0515c48815
22 changed files with 503 additions and 37 deletions

View File

@ -12,7 +12,7 @@
#include "component/display/MeshRenderer.hpp"
namespace Dawn {
struct IRenderPass {
class IRenderPass {
public:
std::shared_ptr<Mesh> mesh;
@ -43,14 +43,17 @@ namespace Dawn {
};
template<class S, typename D>
struct RenderPass : public IRenderPass {
class RenderPass : public IRenderPass {
private:
std::shared_ptr<S> shader;
const D data;
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:
/**
@ -66,12 +69,16 @@ namespace Dawn {
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),
@ -91,6 +98,7 @@ namespace Dawn {
}
void bind() override {
std::cout << "textures: " << textures.size() << "\n";
shader->bind();
}
@ -99,6 +107,10 @@ namespace Dawn {
}
void upload() override {
for(auto &pair : textures) {
assertNotNull(pair.second, "Texture cannot be null!");
pair.second->bind(pair.first);
}
shader->upload();
}
@ -139,17 +151,21 @@ namespace Dawn {
* @return Created render pass.
*/
template<class S, typename D>
std::shared_ptr<struct IRenderPass> createRenderPass(
std::shared_ptr<IRenderPass> createRenderPass(
SceneComponent &self,
const D data,
const std::unordered_map<
shadertexturebinding_t, std::shared_ptr<Texture>
> textures = {},
const std::shared_ptr<Mesh> mesh = nullptr,
const enum MeshDrawMode drawMode = MeshDrawMode::TRIANGLES,
int32_t indiceStart = 0,
int32_t indiceCount = -1
) {
return std::make_shared<struct RenderPass<S,D>>(
return std::make_shared<RenderPass<S,D>>(
self,
data,
textures,
mesh,
drawMode,
indiceStart,

View File

@ -11,7 +11,16 @@ struct Color SimpleTexturedMaterial::getColor() {
return this->data.color;
}
void SimpleTexturedMaterial::setColor(struct Color color) {
std::shared_ptr<Texture> SimpleTexturedMaterial::getTexture() {
return this->texture;
}
void SimpleTexturedMaterial::setTexture(std::shared_ptr<Texture> texture) {
this->texture = texture;
}
void SimpleTexturedMaterial::setColor(const struct Color color) {
this->data.color = color;
}
@ -22,11 +31,23 @@ std::vector<std::shared_ptr<IRenderPass>> SimpleTexturedMaterial::getPasses(
this->data.projection = ctx.camera->getProjection();
this->data.view = ctx.camera->getItem()->getWorldTransform();
this->data.color = COLOR_RED;
auto textures = std::unordered_map<
shadertexturebinding_t, std::shared_ptr<Texture>
>();
if(this->texture) {
this->data.hasTexture = true;
this->data.texture = 0;
textures[this->data.texture] = this->texture;
} else {
this->data.hasTexture = false;
}
return {
createRenderPass<SimpleTexturedShader, struct SimpleTexturedShaderData>(
*this,
data
data,
textures
)
};
}

View File

@ -6,11 +6,13 @@
#pragma once
#include "component/display/material/Material.hpp"
#include "display/shader/SimpleTexturedShader.hpp"
#include "display/Texture.hpp"
namespace Dawn {
class SimpleTexturedMaterial : public Material {
private:
struct SimpleTexturedShaderData data;
std::shared_ptr<Texture> texture;
public:
/**
@ -18,12 +20,26 @@ namespace Dawn {
*/
struct Color getColor();
/**
* Returns the texture of this material.
*
* @return The texture of this material.
*/
std::shared_ptr<Texture> getTexture();
/**
* Sets the texture of this material.
*
* @param texture The texture to set.
*/
void setTexture(std::shared_ptr<Texture> texture);
/**
* Sets the color of this material.
*
* @param color The color to set.
*/
void setColor(struct Color color);
void setColor(const struct Color color);
std::vector<std::shared_ptr<IRenderPass>> getPasses(
struct RenderPassContext &ctx