glClear is causing stack corrpution
This commit is contained in:
109
src/dawn/display/ITexture.hpp
Normal file
109
src/dawn/display/ITexture.hpp
Normal file
@ -0,0 +1,109 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#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 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 TextureFilterMode {
|
||||
TEXTURE_FILTER_MODE_NEAREST = 0,
|
||||
TEXTURE_FILTER_MODE_LINEAR = 1
|
||||
};
|
||||
|
||||
enum TextureDataFormat {
|
||||
TEXTURE_DATA_FORMAT_UNSIGNED_BYTE = 0,
|
||||
TEXTURE_DATA_FORMAT_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;
|
||||
|
||||
/**
|
||||
* Returns the width of the texture.
|
||||
*
|
||||
* @return Width of the texture.
|
||||
*/
|
||||
virtual int32_t getWidth() = 0;
|
||||
|
||||
/**
|
||||
* Returns the height of the texture.
|
||||
*
|
||||
* @return Height of the texture.
|
||||
*/
|
||||
virtual int32_t getHeight() = 0;
|
||||
|
||||
/**
|
||||
* Initializes a texture.
|
||||
*
|
||||
* @param width Width of the texture (in pixels).
|
||||
* @param height Height of the texture (in pixels).
|
||||
* @param format Data format of the texture to use.
|
||||
* @param dataFormat Data format of the texture to use.
|
||||
*/
|
||||
virtual void setSize(
|
||||
const int32_t width,
|
||||
const int32_t height,
|
||||
const enum TextureFormat format,
|
||||
const enum TextureDataFormat dataFormat
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Returns true only when the texture has been loaded, sized and put on
|
||||
* the gpu for rendering.
|
||||
*
|
||||
* @return True if ready, otherwise false.
|
||||
*/
|
||||
// virtual bool_t isReady() = 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 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 uint8_t pixels[]) = 0;
|
||||
|
||||
/**
|
||||
* Binds the texture to the given slot (for use by the shaders).
|
||||
*
|
||||
* @param slot Slot to bind to.
|
||||
*/
|
||||
virtual void bind(const uint8_t slot) = 0;
|
||||
|
||||
/**
|
||||
* Disposes of the texture.
|
||||
*/
|
||||
virtual ~ITexture() {
|
||||
}
|
||||
};
|
||||
}
|
@ -68,6 +68,7 @@ void RenderPipeline::renderSceneCamera(
|
||||
assertNotNull(game, "Game cannot be null");
|
||||
assertNotNull(scene, "Scene cannot be null");
|
||||
assertNotNull(camera, "Camera cannot be null");
|
||||
assertNotNull(renderTarget, "RenderTarget cannot be null");
|
||||
|
||||
struct RenderPassContext ctx = {
|
||||
game,
|
||||
@ -77,14 +78,15 @@ void RenderPipeline::renderSceneCamera(
|
||||
};
|
||||
|
||||
// Get list of renderables
|
||||
std::vector<std::shared_ptr<struct IRenderPass>> renderPasses;
|
||||
std::vector<std::shared_ptr<IRenderPass>> renderPasses;
|
||||
auto renderables = scene->findComponents<IRenderableComponent>();
|
||||
for(auto renderable : renderables) {
|
||||
auto rp = renderable->getPasses(ctx);
|
||||
renderPasses.insert(renderPasses.end(), rp.begin(), rp.end());
|
||||
}
|
||||
|
||||
// Sort the render passes
|
||||
auto rp = renderPasses[0];
|
||||
rp->bind();
|
||||
|
||||
// TODO: Make clearing the buffers editable!
|
||||
renderTarget->bind();
|
||||
@ -92,17 +94,15 @@ void RenderPipeline::renderSceneCamera(
|
||||
RENDER_TARGET_CLEAR_COLOR |
|
||||
RENDER_TARGET_CLEAR_DEPTH
|
||||
);
|
||||
|
||||
rp->bind();
|
||||
|
||||
std::for_each(
|
||||
renderPasses.begin(),
|
||||
renderPasses.end(),
|
||||
[&](std::shared_ptr<struct IRenderPass> pass) {
|
||||
pass->bind();
|
||||
pass->setData();
|
||||
pass->upload();
|
||||
pass->draw();
|
||||
}
|
||||
);
|
||||
for(auto renderPass : renderPasses) {
|
||||
renderPass->bind();
|
||||
renderPass->setData();
|
||||
renderPass->upload();
|
||||
renderPass->draw();
|
||||
}
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
|
@ -6,8 +6,8 @@
|
||||
#pragma once
|
||||
#include "event/Event.hpp"
|
||||
|
||||
#define RENDER_TARGET_CLEAR_COLOR 1 << 0
|
||||
#define RENDER_TARGET_CLEAR_DEPTH 1 << 1
|
||||
#define RENDER_TARGET_CLEAR_COLOR (1 << 0)
|
||||
#define RENDER_TARGET_CLEAR_DEPTH (1 << 1)
|
||||
|
||||
namespace Dawn {
|
||||
class RenderTarget {
|
||||
|
Reference in New Issue
Block a user