Subscenes

This commit is contained in:
2023-01-14 22:06:35 -08:00
parent 15e7efb7f3
commit 0558b3bb25
35 changed files with 733 additions and 116 deletions

View File

@ -10,6 +10,7 @@ target_sources(${DAWN_TARGET_NAME}
BackBufferRenderTarget.cpp
StandardRenderPipeline.cpp
Texture.cpp
TextureRenderTarget.cpp
)
# Subdirs

View File

@ -10,6 +10,8 @@
#include "util/memory.hpp"
namespace Dawn {
class TextureRenderTarget;
typedef GLuint textureslot_t;
class Texture : public ITexture {
@ -34,5 +36,7 @@ namespace Dawn {
void bind(textureslot_t slot);
~Texture();
friend class TextureRenderTarget;
};
}

View File

@ -0,0 +1,87 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TextureRenderTarget.hpp"
using namespace Dawn;
TextureRenderTarget::TextureRenderTarget(float_t width, float_t height) {
this->setSize(width, height);
}
Texture * TextureRenderTarget::getTexture() {
return &this->texture;
}
void TextureRenderTarget::setSize(float_t width, float_t height) {
assertTrue(width > 0);
assertTrue(height > 0);
assertTrue(width != this->getWidth());
assertTrue(height != this->getHeight());
// Delete old buffers.
if(this->rboId != -1) glDeleteRenderbuffers(1, &this->rboId);
if(this->fboId != -1) glDeleteFramebuffers(1, &this->fboId);
// Resize texture
this->texture.setSize((int32_t)width, (int32_t) height);
this->eventRenderTargetResized.invoke(this, width, height);
// Create Frame Buffer
glGenFramebuffers(1, &this->fboId);
glBindFramebuffer(GL_FRAMEBUFFER, this->fboId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, this->texture.id, 0
);
// Create Render Buffer
glGenRenderbuffers(1, &this->rboId);
glBindRenderbuffer(GL_RENDERBUFFER, this->rboId);
glRenderbufferStorage(
GL_RENDERBUFFER, GL_DEPTH24_STENCIL8,
this->texture.width, this->texture.height
);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, this->rboId
);
// Validate things went correct.
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
assertUnreachable();
}
}
float_t TextureRenderTarget::getWidth() {
return (float_t)this->texture.getWidth();
}
float_t TextureRenderTarget::getHeight() {
return (float_t)this->texture.getHeight();
}
void TextureRenderTarget::setClearColor(struct Color color) {
this->clearColor = color;
}
void TextureRenderTarget::clear(flag8_t clearFlags) {
glClearColor(
this->clearColor.r,
this->clearColor.g,
this->clearColor.b,
this->clearColor.a
);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void TextureRenderTarget::bind() {
glBindFramebuffer(GL_FRAMEBUFFER, this->fboId);
glViewport(0, 0, this->texture.getWidth(), this->texture.getHeight());
}
TextureRenderTarget::~TextureRenderTarget() {
if(this->rboId != -1) glDeleteRenderbuffers(1, &this->rboId);
if(this->fboId != -1) glDeleteFramebuffers(1, &this->fboId);
}

View File

@ -0,0 +1,37 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnopengl.hpp"
#include "display/RenderTarget.hpp"
#include "display/Texture.hpp"
namespace Dawn {
class RenderManager;
class TextureRenderTarget : public RenderTarget {
private:
GLuint fboId = -1;
GLuint rboId = -1;
Texture texture;
struct Color clearColor = COLOR_CORNFLOWER_BLUE;
public:
TextureRenderTarget(float_t width, float_t height);
Texture * getTexture();
void setSize(float_t width, float_t height);
float_t getWidth() override;
float_t getHeight() override;
void setClearColor(struct Color color) override;
void clear(flag8_t clearFlags) override;
void bind() override;
~TextureRenderTarget();
};
}

View File

@ -99,9 +99,9 @@ namespace Dawn {
this->setBoolean(this->paramHasTexture, false);
}
void setUICamera(glm::mat4 view, glm::mat4 projection) {
this->setMatrix(this->paramView, view);
void setUICamera(glm::mat4 projection, glm::mat4 view) {
this->setMatrix(this->paramProjection, projection);
this->setMatrix(this->paramView, view);
}
void setUIModel(glm::mat4 model) {