Textures are working now

This commit is contained in:
2023-11-19 11:39:48 -06:00
parent 830694ee0a
commit c2fb75df97
9 changed files with 93 additions and 69 deletions

View File

@ -39,7 +39,8 @@ namespace Dawn {
/**
* Cleans up the render pass.
*/
virtual ~IRenderPass() { }
virtual ~IRenderPass() {
}
};
template<class S, typename D>
@ -48,7 +49,7 @@ namespace Dawn {
std::shared_ptr<S> shader;
const std::unordered_map<
shadertexturebinding_t, std::shared_ptr<Texture>
> &textures;
> textures;
std::shared_ptr<Mesh> mesh;
const enum MeshDrawMode drawMode;
const int32_t indiceStart;
@ -98,7 +99,6 @@ namespace Dawn {
}
void bind() override {
std::cout << "textures: " << textures.size() << "\n";
shader->bind();
}
@ -108,7 +108,6 @@ namespace Dawn {
void upload() override {
for(auto &pair : textures) {
assertNotNull(pair.second, "Texture cannot be null!");
pair.second->bind(pair.first);
}
shader->upload();
@ -119,6 +118,9 @@ namespace Dawn {
mesh->draw(drawMode, indiceStart, indiceCount);
}
}
~RenderPass() override {
}
};
struct RenderPassContext {

View File

@ -19,7 +19,6 @@ void SimpleTexturedMaterial::setTexture(std::shared_ptr<Texture> texture) {
this->texture = texture;
}
void SimpleTexturedMaterial::setColor(const struct Color color) {
this->data.color = color;
}
@ -30,7 +29,6 @@ std::vector<std::shared_ptr<IRenderPass>> SimpleTexturedMaterial::getPasses(
this->data.model = this->getItem()->getWorldTransform();
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>
>();

View File

@ -11,7 +11,6 @@ namespace Dawn {
uint8_t r, g, b, a;
};
#pragma pack(push, 4)
struct Color final {
/**
* Returns a color from a string.
@ -71,7 +70,6 @@ namespace Dawn {
};
}
};
#pragma pack(pop)
#define COLOR_DEF(r,g,b,a) { r, g, b, a }
#define COLOR_WHITE COLOR_DEF(1.0f, 1.0f, 1.0f, 1.0f)
@ -85,5 +83,7 @@ namespace Dawn {
#define COLOR_CORNFLOWER_BLUE COLOR_DEF(0.4f, 0.6f, 0.9f, 1.0f)
#define COLOR_WHITE_TRANSPARENT COLOR_DEF(1.0f, 1.0f, 1.0f, 0.0f)
#define COLOR_BLACK_TRANSPARENT COLOR_DEF(0.0f, 0.0f, 0.0f, 0.0f)
#define COLOR_YELLOW COLOR_DEF(1.0f, 1.0f, 0.0f, 1.0f)
#define COLOR_CYAN COLOR_DEF(0.0f, 1.0f, 1.0f, 1.0f)
#define COLOR_TRANSPARENT COLOR_WHITE_TRANSPARENT
}

View File

@ -7,38 +7,38 @@
#include "display/Color.hpp"
namespace Dawn {
enum TextureFormat {
TEXTURE_FORMAT_R = 1,
TEXTURE_FORMAT_RG = 2,
TEXTURE_FORMAT_RGB = 3,
TEXTURE_FORMAT_RGBA = 4
enum class TextureFormat {
R = 1,
RG = 2,
RGB = 3,
RGBA = 4
};
enum TextureWrapMode {
TEXTURE_WRAP_MODE_REPEAT = 0,
TEXTURE_WRAP_MODE_MIRRORED_REPEAT = 1,
TEXTURE_WRAP_MODE_CLAMP_TO_EDGE = 2,
TEXTURE_WRAP_MODE_CLAMP_TO_BORDER = 3
enum class TextureWrapMode {
REPEAT = 0,
MIRRORED_REPEAT = 1,
CLAMP_TO_EDGE = 2,
CLAMP_TO_BORDER = 3
};
enum TextureFilterMode {
TEXTURE_FILTER_MODE_NEAREST = 0,
TEXTURE_FILTER_MODE_LINEAR = 1
enum class TextureFilterMode {
NEAREST = 0,
LINEAR = 1
};
enum TextureDataFormat {
TEXTURE_DATA_FORMAT_UNSIGNED_BYTE = 0,
TEXTURE_DATA_FORMAT_FLOAT = 1
enum class TextureDataFormat {
UNSIGNED_BYTE = 0,
FLOAT = 1
};
class ITexture {
public:
enum TextureWrapMode wrapModeX = TEXTURE_WRAP_MODE_REPEAT;
enum TextureWrapMode wrapModeY = TEXTURE_WRAP_MODE_REPEAT;
enum TextureFilterMode filterModeMin = TEXTURE_FILTER_MODE_NEAREST;
enum TextureFilterMode filterModeMag = TEXTURE_FILTER_MODE_NEAREST;
enum TextureFilterMode mipMapFilterModeMin = TEXTURE_FILTER_MODE_NEAREST;
enum TextureFilterMode mipMapFilterModeMag = TEXTURE_FILTER_MODE_NEAREST;
enum TextureWrapMode wrapModeX = TextureWrapMode::REPEAT;
enum TextureWrapMode wrapModeY = TextureWrapMode::REPEAT;
enum TextureFilterMode filterModeMin = TextureFilterMode::NEAREST;
enum TextureFilterMode filterModeMag = TextureFilterMode::NEAREST;
enum TextureFilterMode mipMapFilterModeMin = TextureFilterMode::NEAREST;
enum TextureFilterMode mipMapFilterModeMag = TextureFilterMode::NEAREST;
/**
* Returns the width of the texture.
@ -85,6 +85,14 @@ namespace Dawn {
*/
virtual void buffer(const struct ColorU8 pixels[]) = 0;
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.
*
* @param pixels Array of pixels you're trying to buffer.
*/
virtual void buffer(const struct Color pixels[]) = 0;
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.

View File

@ -84,9 +84,6 @@ void RenderPipeline::renderSceneCamera(
auto rp = renderable->getPasses(ctx);
renderPasses.insert(renderPasses.end(), rp.begin(), rp.end());
}
auto rp = renderPasses[0];
rp->bind();
// TODO: Make clearing the buffers editable!
renderTarget->bind();
@ -94,8 +91,6 @@ void RenderPipeline::renderSceneCamera(
RENDER_TARGET_CLEAR_COLOR |
RENDER_TARGET_CLEAR_DEPTH
);
rp->bind();
for(auto renderPass : renderPasses) {
renderPass->bind();

View File

@ -7,7 +7,7 @@
#include "dawnlibs.hpp"
namespace Dawn {
enum ShaderParameterType {
enum class ShaderParameterType {
VEC2,
VEC3,
VEC4,