BIt more cleanup.
This commit is contained in:
@ -7,9 +7,7 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
BackBufferRenderTarget::BackBufferRenderTarget(RenderManager &renderManager) :
|
||||
renderManager(renderManager)
|
||||
{
|
||||
BackBufferRenderTarget::BackBufferRenderTarget() {
|
||||
}
|
||||
|
||||
float_t BackBufferRenderTarget::getScale() {
|
||||
@ -24,23 +22,23 @@ float_t BackBufferRenderTarget::getHeight() {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
void BackBufferRenderTarget::setSize(float_t width, float_t height) {
|
||||
void BackBufferRenderTarget::setSize(
|
||||
const float_t width,
|
||||
const float_t height
|
||||
) {
|
||||
if(this->width == width && this->height == height) return;
|
||||
|
||||
// Fixes a new bug that it seems GLFW has introduced.
|
||||
if(width == 0) width = 1;
|
||||
if(height == 0) height = 1;
|
||||
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->width = width == 0 ? 1 : width;
|
||||
this->height = height == 0 ? 1 : height;
|
||||
this->eventRenderTargetResized.invoke(*this, width, height);
|
||||
}
|
||||
|
||||
void BackBufferRenderTarget::setClearColor(struct Color color) {
|
||||
void BackBufferRenderTarget::setClearColor(const struct Color color) {
|
||||
this->clearColor = color;
|
||||
}
|
||||
|
||||
void BackBufferRenderTarget::clear(flag8_t clearFlags) {
|
||||
void BackBufferRenderTarget::clear(const flag8_t clearFlags) {
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
assertNoGLError();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -13,7 +13,6 @@ namespace Dawn {
|
||||
|
||||
class BackBufferRenderTarget : public RenderTarget {
|
||||
private:
|
||||
RenderManager &renderManager;
|
||||
float_t width = 1;
|
||||
float_t height = 1;
|
||||
struct Color clearColor = COLOR_CORNFLOWER_BLUE;
|
||||
@ -23,10 +22,8 @@ namespace Dawn {
|
||||
|
||||
/**
|
||||
* Construct the back buffer render target.
|
||||
*
|
||||
* @param renderManager Render Manager for this back buffer target.
|
||||
*/
|
||||
BackBufferRenderTarget(RenderManager &renderManager);
|
||||
BackBufferRenderTarget();
|
||||
|
||||
/**
|
||||
* Requests to modify the viewport directly. This is mostly to be called
|
||||
@ -38,13 +35,13 @@ namespace Dawn {
|
||||
* @param width New width of the back buffer.
|
||||
* @param height New height of the back buffer.
|
||||
*/
|
||||
void setSize(float_t width, float_t height);
|
||||
void setSize(const float_t width, const float_t height);
|
||||
|
||||
float_t getScale() override;
|
||||
float_t getWidth() override;
|
||||
float_t getHeight() override;
|
||||
void setClearColor(struct Color color) override;
|
||||
void clear(flag8_t clearFlags) override;
|
||||
void setClearColor(const struct Color color) override;
|
||||
void clear(const flag8_t clearFlags) override;
|
||||
void bind() override;
|
||||
};
|
||||
}
|
@ -13,7 +13,7 @@ using namespace Dawn;
|
||||
RenderManager::RenderManager() : IRenderManager() {
|
||||
renderPipeline = std::make_shared<RenderPipeline>();
|
||||
shaderManager = std::make_shared<ShaderManager>();
|
||||
backBuffer = std::make_shared<BackBufferRenderTarget>(*this);
|
||||
backBuffer = std::make_shared<BackBufferRenderTarget>();
|
||||
}
|
||||
|
||||
void RenderManager::init(const std::weak_ptr<DawnGame> game) {
|
||||
|
@ -8,12 +8,16 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TextureRenderTarget::TextureRenderTarget(float_t width, float_t height) {
|
||||
TextureRenderTarget::TextureRenderTarget(
|
||||
const float_t width,
|
||||
const float_t height
|
||||
) {
|
||||
this->texture = std::make_shared<Texture>();
|
||||
this->setSize(width, height);
|
||||
}
|
||||
|
||||
Texture * TextureRenderTarget::getTexture() {
|
||||
return &this->texture;
|
||||
std::shared_ptr<Texture> TextureRenderTarget::getTexture() {
|
||||
return this->texture;
|
||||
}
|
||||
|
||||
void TextureRenderTarget::setSize(float_t width, float_t height) {
|
||||
@ -29,7 +33,12 @@ void TextureRenderTarget::setSize(float_t width, float_t height) {
|
||||
assertNoGLError();
|
||||
|
||||
// Resize texture
|
||||
this->texture.setSize((int32_t)width, (int32_t)height, TEXTURE_FORMAT_RGBA, TEXTURE_DATA_FORMAT_FLOAT);
|
||||
this->texture->setSize(
|
||||
(int32_t)width,
|
||||
(int32_t)height,
|
||||
TEXTURE_FORMAT_RGBA,
|
||||
TEXTURE_DATA_FORMAT_FLOAT
|
||||
);
|
||||
this->eventRenderTargetResized.invoke(*this, width, height);
|
||||
|
||||
// Create Frame Buffer
|
||||
@ -38,7 +47,7 @@ void TextureRenderTarget::setSize(float_t width, float_t height) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, this->fboId);
|
||||
assertNoGLError();
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, this->texture.id, 0
|
||||
GL_TEXTURE_2D, this->texture->id, 0
|
||||
);
|
||||
assertNoGLError();
|
||||
|
||||
@ -48,14 +57,19 @@ void TextureRenderTarget::setSize(float_t width, float_t height) {
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, this->rboId);
|
||||
assertNoGLError();
|
||||
glRenderbufferStorage(
|
||||
GL_RENDERBUFFER, GL_DEPTH24_STENCIL8,
|
||||
this->texture.width, this->texture.height
|
||||
GL_RENDERBUFFER,
|
||||
GL_DEPTH24_STENCIL8,
|
||||
this->texture->width,
|
||||
this->texture->height
|
||||
);
|
||||
assertNoGLError();
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
assertNoGLError();
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
||||
GL_RENDERBUFFER, this->rboId
|
||||
glFramebufferRenderbuffer(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_DEPTH_STENCIL_ATTACHMENT,
|
||||
GL_RENDERBUFFER,
|
||||
this->rboId
|
||||
);
|
||||
assertNoGLError();
|
||||
|
||||
@ -70,18 +84,18 @@ float_t TextureRenderTarget::getScale() {
|
||||
}
|
||||
|
||||
float_t TextureRenderTarget::getWidth() {
|
||||
return (float_t)this->texture.getWidth();
|
||||
return (float_t)this->texture->getWidth();
|
||||
}
|
||||
|
||||
float_t TextureRenderTarget::getHeight() {
|
||||
return (float_t)this->texture.getHeight();
|
||||
return (float_t)this->texture->getHeight();
|
||||
}
|
||||
|
||||
void TextureRenderTarget::setClearColor(struct Color color) {
|
||||
void TextureRenderTarget::setClearColor(const struct Color color) {
|
||||
this->clearColor = color;
|
||||
}
|
||||
|
||||
void TextureRenderTarget::clear(flag8_t clearFlags) {
|
||||
void TextureRenderTarget::clear(const flag8_t clearFlags) {
|
||||
glClearColor(
|
||||
clearColor.r,
|
||||
clearColor.g,
|
||||
@ -93,7 +107,7 @@ void TextureRenderTarget::clear(flag8_t clearFlags) {
|
||||
|
||||
void TextureRenderTarget::bind() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, this->fboId);
|
||||
glViewport(0, 0, this->texture.getWidth(), this->texture.getHeight());
|
||||
glViewport(0, 0, this->texture->getWidth(), this->texture->getHeight());
|
||||
}
|
||||
|
||||
TextureRenderTarget::~TextureRenderTarget() {
|
||||
|
@ -16,21 +16,21 @@ namespace Dawn {
|
||||
GLuint fboId = -1;
|
||||
GLuint rboId = -1;
|
||||
|
||||
Texture texture;
|
||||
std::shared_ptr<Texture> texture;
|
||||
struct Color clearColor = COLOR_CORNFLOWER_BLUE;
|
||||
|
||||
public:
|
||||
TextureRenderTarget(float_t width, float_t height);
|
||||
TextureRenderTarget(const float_t width, const float_t height);
|
||||
|
||||
Texture * getTexture();
|
||||
std::shared_ptr<Texture> getTexture();
|
||||
|
||||
void setSize(float_t width, float_t height);
|
||||
void setSize(const float_t width, const float_t height);
|
||||
|
||||
float_t getScale() override;
|
||||
float_t getWidth() override;
|
||||
float_t getHeight() override;
|
||||
void setClearColor(struct Color color) override;
|
||||
void clear(flag8_t clearFlags) override;
|
||||
void setClearColor(const struct Color color) override;
|
||||
void clear(const flag8_t clearFlags) override;
|
||||
void bind() override;
|
||||
|
||||
~TextureRenderTarget();
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
#include "assert/assertgl.hpp"
|
||||
#include "display/mesh/_Mesh.hpp"
|
||||
#include "dawnopengl.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
|
Reference in New Issue
Block a user