Part one - removed references and smart pointers
This commit is contained in:
@ -1,140 +1,141 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "RenderPipeline.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
RenderPipeline::RenderPipeline(RenderManager &renderManager) :
|
||||
renderManager(renderManager)
|
||||
{
|
||||
}
|
||||
|
||||
void RenderPipeline::init() {
|
||||
|
||||
}
|
||||
|
||||
void RenderPipeline::render() {
|
||||
this->renderScene(*this->renderManager.game.scene);
|
||||
}
|
||||
|
||||
void RenderPipeline::renderScene(Scene &scene) {
|
||||
RenderTarget &backBuffer = this->renderManager.getBackBuffer();
|
||||
auto cameras = scene.findComponents<Camera>();
|
||||
std::shared_ptr<Camera> backBufferCamera = nullptr;
|
||||
|
||||
// First, render all non-backbuffer cameras.
|
||||
auto it = cameras.begin();
|
||||
while(it != cameras.end()) {
|
||||
RenderTarget &cameraTarget = (*it)->getRenderTarget();
|
||||
|
||||
// Leave the backbuffer camera(s) to last, so we skip them.
|
||||
if(&cameraTarget == &backBuffer) {
|
||||
backBufferCamera = *it;
|
||||
} else {
|
||||
this->renderSceneCamera(scene, **it);
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
// Now render the backbuffer camera.
|
||||
if(backBufferCamera == nullptr) return;
|
||||
this->renderSceneCamera(scene, *backBufferCamera);
|
||||
|
||||
// Now we try and render UI components
|
||||
auto uiCanvasList = scene.findComponents<UICanvas>();
|
||||
auto itCanvas = uiCanvasList.begin();
|
||||
while(itCanvas != uiCanvasList.end()) {
|
||||
this->renderUI(scene, *backBufferCamera, **itCanvas);
|
||||
++itCanvas;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPipeline::renderSceneCamera(Scene &scene, Camera &camera) {
|
||||
RenderTarget &renderTarget = camera.getRenderTarget();
|
||||
renderTarget.bind();
|
||||
renderTarget.clear(
|
||||
RENDER_TARGET_CLEAR_FLAG_DEPTH |
|
||||
RENDER_TARGET_CLEAR_FLAG_COLOR
|
||||
);
|
||||
this->renderManager.setRenderFlags(
|
||||
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST |
|
||||
RENDER_MANAGER_RENDER_FLAG_BLEND
|
||||
);
|
||||
|
||||
auto meshes = scene.findComponents<MeshRenderer>();
|
||||
auto it = meshes.begin();
|
||||
while(it != meshes.end()) {
|
||||
auto mesh = *it;
|
||||
auto material = mesh->item.getComponent<Material>();
|
||||
|
||||
// TODO: fallback material?
|
||||
if(material == nullptr) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto shader = material->getShader();
|
||||
shader->bind();
|
||||
shader->setGlobalParameters(camera.projection, camera.transform.getWorldTransform());
|
||||
shader->setMeshParameters(mesh->item.transform.getWorldTransform());
|
||||
material->setShaderParameters();
|
||||
|
||||
mesh->mesh->draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPipeline::renderUI(
|
||||
Scene &scene,
|
||||
Camera &camera,
|
||||
UICanvas &canvas
|
||||
) {
|
||||
// Get the
|
||||
RenderTarget *renderTarget;
|
||||
|
||||
glm::mat4 transform;
|
||||
glm::mat4 projection;
|
||||
switch(canvas.drawType) {
|
||||
case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE:
|
||||
transform = glm::mat4(1.0f);
|
||||
projection = glm::ortho(0.0f, canvas.getWidth(), canvas.getHeight(), 0.0f);
|
||||
renderTarget = &camera.getRenderTarget();
|
||||
break;
|
||||
default:
|
||||
throw "UI Draw modes are not yet supported.";
|
||||
}
|
||||
|
||||
// Clear / Bind / Update the render target.
|
||||
renderTarget->bind();
|
||||
renderTarget->clear(
|
||||
RENDER_TARGET_CLEAR_FLAG_DEPTH |
|
||||
RENDER_TARGET_CLEAR_FLAG_COLOR
|
||||
);
|
||||
this->renderManager.setRenderFlags(
|
||||
RENDER_MANAGER_RENDER_FLAG_BLEND |
|
||||
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
|
||||
);
|
||||
|
||||
// Prepare the UI Shader
|
||||
auto shader = this->renderManager.getUIShader();
|
||||
shader->bind();
|
||||
shader->setUICamera(transform, projection);
|
||||
|
||||
// Render the children
|
||||
glm::mat4 rootMatrix = canvas.transform.getWorldTransform();
|
||||
auto it = canvas.children.begin();
|
||||
while(it != canvas.children.end()) {
|
||||
(*it)->draw(*shader, rootMatrix);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "RenderPipeline.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
#include "scene/SceneItem.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
RenderPipeline::RenderPipeline(RenderManager *renderManager) {
|
||||
assertNotNull(renderManager);
|
||||
this->renderManager = renderManager;
|
||||
}
|
||||
|
||||
void RenderPipeline::init() {
|
||||
|
||||
}
|
||||
|
||||
void RenderPipeline::render() {
|
||||
this->renderScene(this->renderManager->game->scene);
|
||||
}
|
||||
|
||||
void RenderPipeline::renderScene(Scene *scene) {
|
||||
auto backBuffer = this->renderManager->getBackBuffer();
|
||||
auto cameras = scene->findComponents<Camera>();
|
||||
Camera *backBufferCamera = nullptr;
|
||||
|
||||
// First, render all non-backbuffer cameras.
|
||||
auto it = cameras.begin();
|
||||
while(it != cameras.end()) {
|
||||
RenderTarget *cameraTarget = (*it)->getRenderTarget();
|
||||
|
||||
// Leave the backbuffer camera(s) to last, so we skip them.
|
||||
if(cameraTarget == backBuffer) {
|
||||
backBufferCamera = *it;
|
||||
} else {
|
||||
this->renderSceneCamera(scene, *it);
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
// Now render the backbuffer camera.
|
||||
if(backBufferCamera == nullptr) return;
|
||||
this->renderSceneCamera(scene, backBufferCamera);
|
||||
|
||||
// Now we try and render UI components
|
||||
auto uiCanvasList = scene->findComponents<UICanvas>();
|
||||
auto itCanvas = uiCanvasList.begin();
|
||||
while(itCanvas != uiCanvasList.end()) {
|
||||
this->renderUI(scene, backBufferCamera, *itCanvas);
|
||||
++itCanvas;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
||||
RenderTarget *renderTarget = camera->getRenderTarget();
|
||||
renderTarget->bind();
|
||||
renderTarget->clear(
|
||||
RENDER_TARGET_CLEAR_FLAG_DEPTH |
|
||||
RENDER_TARGET_CLEAR_FLAG_COLOR
|
||||
);
|
||||
this->renderManager->setRenderFlags(
|
||||
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST |
|
||||
RENDER_MANAGER_RENDER_FLAG_BLEND
|
||||
);
|
||||
|
||||
auto meshes = scene->findComponents<MeshRenderer>();
|
||||
auto it = meshes.begin();
|
||||
while(it != meshes.end()) {
|
||||
auto mesh = *it;
|
||||
auto material = mesh->item->getComponent<Material>();
|
||||
|
||||
// TODO: fallback material?
|
||||
if(material == nullptr) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto shader = material->getShader();
|
||||
shader->bind();
|
||||
shader->setGlobalParameters(camera->projection, camera->transform->getWorldTransform());
|
||||
shader->setMeshParameters(mesh->item->transform.getWorldTransform());
|
||||
material->setShaderParameters();
|
||||
|
||||
mesh->mesh->draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPipeline::renderUI(
|
||||
Scene *scene,
|
||||
Camera *camera,
|
||||
UICanvas *canvas
|
||||
) {
|
||||
// Get the
|
||||
RenderTarget *renderTarget;
|
||||
|
||||
glm::mat4 transform;
|
||||
glm::mat4 projection;
|
||||
switch(canvas->drawType) {
|
||||
case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE:
|
||||
transform = glm::mat4(1.0f);
|
||||
projection = glm::ortho(0.0f, canvas->getWidth(), canvas->getHeight(), 0.0f);
|
||||
renderTarget = camera->getRenderTarget();
|
||||
break;
|
||||
default:
|
||||
throw "UI Draw modes are not yet supported.";
|
||||
}
|
||||
|
||||
// Clear / Bind / Update the render target.
|
||||
renderTarget->bind();
|
||||
renderTarget->clear(
|
||||
RENDER_TARGET_CLEAR_FLAG_DEPTH |
|
||||
RENDER_TARGET_CLEAR_FLAG_COLOR
|
||||
);
|
||||
this->renderManager->setRenderFlags(
|
||||
RENDER_MANAGER_RENDER_FLAG_BLEND |
|
||||
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
|
||||
);
|
||||
|
||||
// Prepare the UI Shader
|
||||
auto shader = this->renderManager->getUIShader();
|
||||
shader->bind();
|
||||
shader->setUICamera(transform, projection);
|
||||
|
||||
// Render the children
|
||||
glm::mat4 rootMatrix = canvas->transform->getWorldTransform();
|
||||
auto it = canvas->children.begin();
|
||||
while(it != canvas->children.end()) {
|
||||
(*it)->draw(shader, rootMatrix);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
|
||||
}
|
@ -1,72 +1,72 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "display/RenderManager.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "scene/components/ui/UICanvas.hpp"
|
||||
#include "ui/UIComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class RenderPipeline {
|
||||
public:
|
||||
RenderManager &renderManager;
|
||||
|
||||
/**
|
||||
* Constructs a new RenderPipeline. Render Pipelines are my attempt to
|
||||
* create both a flexible, but standard way to allow the individual games
|
||||
* to decide how they want to render the common scene-item models.
|
||||
*
|
||||
* @param renderManager Parent render manager this pipeline belongs to.
|
||||
*/
|
||||
RenderPipeline(RenderManager &renderManager);
|
||||
|
||||
/**
|
||||
* Initialize the render pipeline.
|
||||
*/
|
||||
virtual void init();
|
||||
|
||||
/**
|
||||
* Renders the games' currently active scene, and all of its' cameras.
|
||||
*/
|
||||
virtual void render();
|
||||
|
||||
/**
|
||||
* Render a specific scene, usually just called for the currently active
|
||||
* scene, but in future this could include sub-scenes.
|
||||
*
|
||||
* @param scene Scene to render.
|
||||
*/
|
||||
virtual void renderScene(Scene &scene);
|
||||
|
||||
/**
|
||||
* Render a specific camera on a specific scene.
|
||||
*
|
||||
* @param scene Scene to render.
|
||||
* @param camera Camera within the scene to render.
|
||||
*/
|
||||
virtual void renderSceneCamera(Scene &scene, Camera &camera);
|
||||
|
||||
/**
|
||||
* Renders a UI Canvas to the back buffer.
|
||||
*
|
||||
* @param scene Scene for the UI canvas.
|
||||
* @param camera Main backbuffer camera for the canvas.
|
||||
* @param canvas Canvas to render.
|
||||
*/
|
||||
virtual void renderUI(
|
||||
Scene &scene,
|
||||
Camera &camera,
|
||||
UICanvas &canvas
|
||||
);
|
||||
|
||||
/**
|
||||
* Cleanup a render pipeline that has been initialized.
|
||||
*/
|
||||
virtual ~RenderPipeline();
|
||||
};
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "display/RenderManager.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "scene/components/ui/UICanvas.hpp"
|
||||
#include "ui/UIComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class RenderPipeline {
|
||||
public:
|
||||
RenderManager *renderManager;
|
||||
|
||||
/**
|
||||
* Constructs a new RenderPipeline. Render Pipelines are my attempt to
|
||||
* create both a flexible, but standard way to allow the individual games
|
||||
* to decide how they want to render the common scene-item models.
|
||||
*
|
||||
* @param renderManager Parent render manager this pipeline belongs to.
|
||||
*/
|
||||
RenderPipeline(RenderManager *renderManager);
|
||||
|
||||
/**
|
||||
* Initialize the render pipeline.
|
||||
*/
|
||||
virtual void init();
|
||||
|
||||
/**
|
||||
* Renders the games' currently active scene, and all of its' cameras.
|
||||
*/
|
||||
virtual void render();
|
||||
|
||||
/**
|
||||
* Render a specific scene, usually just called for the currently active
|
||||
* scene, but in future this could include sub-scenes.
|
||||
*
|
||||
* @param scene Scene to render.
|
||||
*/
|
||||
virtual void renderScene(Scene *scene);
|
||||
|
||||
/**
|
||||
* Render a specific camera on a specific scene.
|
||||
*
|
||||
* @param scene Scene to render.
|
||||
* @param camera Camera within the scene to render.
|
||||
*/
|
||||
virtual void renderSceneCamera(Scene *scene, Camera *camera);
|
||||
|
||||
/**
|
||||
* Renders a UI Canvas to the back buffer.
|
||||
*
|
||||
* @param scene Scene for the UI canvas.
|
||||
* @param camera Main backbuffer camera for the canvas.
|
||||
* @param canvas Canvas to render.
|
||||
*/
|
||||
virtual void renderUI(
|
||||
Scene *scene,
|
||||
Camera *camera,
|
||||
UICanvas *canvas
|
||||
);
|
||||
|
||||
/**
|
||||
* Cleanup a render pipeline that has been initialized.
|
||||
*/
|
||||
virtual ~RenderPipeline();
|
||||
};
|
||||
}
|
@ -1,58 +1,58 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/flag.hpp"
|
||||
#include "display/Color.hpp"
|
||||
#include "event/Event.hpp"
|
||||
|
||||
#define RENDER_TARGET_CLEAR_FLAG_COLOR FLAG_DEFINE(0)
|
||||
#define RENDER_TARGET_CLEAR_FLAG_DEPTH FLAG_DEFINE(1)
|
||||
|
||||
namespace Dawn {
|
||||
class RenderTarget {
|
||||
public:
|
||||
Event<RenderTarget &, float_t, float_t> eventRenderTargetResized;
|
||||
|
||||
/**
|
||||
* Return the width of the render target.
|
||||
*
|
||||
* @return The width of the render target.
|
||||
*/
|
||||
virtual float_t getWidth() = 0;
|
||||
|
||||
/**
|
||||
* Return the height of the render target.
|
||||
*
|
||||
* @return The height of the render target.
|
||||
*/
|
||||
virtual float_t getHeight() = 0;
|
||||
|
||||
/**
|
||||
* Sets the clear color of the render target when the clear method for
|
||||
* the color buffer is requested.
|
||||
*
|
||||
* @param color Color to use for the clear operation.
|
||||
*/
|
||||
virtual void setClearColor(struct Color color) = 0;
|
||||
|
||||
/**
|
||||
* Request the existing data in the render target to be cleared out. We
|
||||
* typically assume the render target can support multiple buffer types,
|
||||
* so you can opt to only clear certain buffer types.
|
||||
*
|
||||
* @param clearFlags Flags to request what is going to be cleared.
|
||||
*/
|
||||
virtual void clear(flag8_t clearFlags) = 0;
|
||||
|
||||
/**
|
||||
* Bind the render target for rendering to. The proceeding render requests
|
||||
* will want to render to this render target directly. In future I may
|
||||
* see if we can have multiple render targets bound at once to make this
|
||||
* operation perform faster.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
};
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/flag.hpp"
|
||||
#include "display/Color.hpp"
|
||||
#include "event/Event.hpp"
|
||||
|
||||
#define RENDER_TARGET_CLEAR_FLAG_COLOR FLAG_DEFINE(0)
|
||||
#define RENDER_TARGET_CLEAR_FLAG_DEPTH FLAG_DEFINE(1)
|
||||
|
||||
namespace Dawn {
|
||||
class RenderTarget {
|
||||
public:
|
||||
Event<RenderTarget*, float_t, float_t> eventRenderTargetResized;
|
||||
|
||||
/**
|
||||
* Return the width of the render target.
|
||||
*
|
||||
* @return The width of the render target.
|
||||
*/
|
||||
virtual float_t getWidth() = 0;
|
||||
|
||||
/**
|
||||
* Return the height of the render target.
|
||||
*
|
||||
* @return The height of the render target.
|
||||
*/
|
||||
virtual float_t getHeight() = 0;
|
||||
|
||||
/**
|
||||
* Sets the clear color of the render target when the clear method for
|
||||
* the color buffer is requested.
|
||||
*
|
||||
* @param color Color to use for the clear operation.
|
||||
*/
|
||||
virtual void setClearColor(struct Color color) = 0;
|
||||
|
||||
/**
|
||||
* Request the existing data in the render target to be cleared out. We
|
||||
* typically assume the render target can support multiple buffer types,
|
||||
* so you can opt to only clear certain buffer types.
|
||||
*
|
||||
* @param clearFlags Flags to request what is going to be cleared.
|
||||
*/
|
||||
virtual void clear(flag8_t clearFlags) = 0;
|
||||
|
||||
/**
|
||||
* Bind the render target for rendering to. The proceeding render requests
|
||||
* will want to render to this render target directly. In future I may
|
||||
* see if we can have multiple render targets bound at once to make this
|
||||
* operation perform faster.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
};
|
||||
}
|
@ -1,160 +1,161 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Transform.hpp"
|
||||
#include "scene/SceneItem.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Transform::Transform(SceneItem &item) :
|
||||
item(item),
|
||||
transformLocal(1.0f),
|
||||
transformWorld(1.0f)
|
||||
{
|
||||
this->updateLocalValuesFromLocalTransform();
|
||||
}
|
||||
|
||||
void Transform::updateLocalValuesFromLocalTransform() {
|
||||
glm::vec3 skew;
|
||||
glm::vec4 perspective;
|
||||
glm::decompose(
|
||||
this->transformLocal,
|
||||
this->localScale,
|
||||
this->localRotation,
|
||||
this->localPosition,
|
||||
skew, perspective
|
||||
);
|
||||
}
|
||||
|
||||
void Transform::updateLocalTransformFromLocalValues() {
|
||||
glm::mat4 translate = glm::translate(glm::mat4(1.0), this->localPosition);
|
||||
glm::mat4 rotate = glm::mat4_cast(this->localRotation);
|
||||
glm::mat4 scale = glm::scale(glm::mat4(1.0), this->localScale);
|
||||
this->transformLocal = translate * rotate * scale;
|
||||
this->updateWorldTransformFromLocalTransform();
|
||||
}
|
||||
|
||||
void Transform::updateWorldTransformFromLocalTransform() {
|
||||
glm::mat4 newWorld(1.0f);
|
||||
auto parent = this->getParent();
|
||||
if(parent != nullptr) newWorld = parent->getWorldTransform();
|
||||
this->transformWorld = newWorld * transformLocal;
|
||||
}
|
||||
|
||||
void Transform::updateLocalTransformFromWorldTransform() {
|
||||
glm::mat4 parentMat(1.0f);
|
||||
auto parent = this->getParent();
|
||||
if(parent != nullptr) parentMat = parent->getWorldTransform();
|
||||
this->transformLocal = parentMat / this->transformWorld;
|
||||
this->updateLocalValuesFromLocalTransform();
|
||||
}
|
||||
|
||||
void Transform::updateChildrenTransforms() {
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
(*it)->updateWorldTransformFromLocalTransform();
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::lookAt(glm::vec3 pos, glm::vec3 look) {
|
||||
this->lookAt(pos, look, glm::vec3(0, 1, 0));
|
||||
}
|
||||
|
||||
void Transform::lookAt(glm::vec3 pos, glm::vec3 look, glm::vec3 up) {
|
||||
this->setWorldTransform(glm::lookAt(pos, look, up));
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 Transform::getLocalPosition() {
|
||||
return this->localPosition;
|
||||
}
|
||||
|
||||
void Transform::setLocalPosition(glm::vec3 position) {
|
||||
this->localPosition = position;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
glm::vec3 Transform::getLocalScale() {
|
||||
return this->localScale;
|
||||
}
|
||||
|
||||
void Transform::setLocalScale(glm::vec3 scale) {
|
||||
this->localScale = scale;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
glm::quat Transform::getLocalRotation() {
|
||||
return this->localRotation;
|
||||
}
|
||||
|
||||
void Transform::setLocalRotation(glm::quat rotation) {
|
||||
this->localRotation = rotation;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
|
||||
glm::mat4 Transform::getLocalTransform() {
|
||||
return this->transformLocal;
|
||||
}
|
||||
|
||||
void Transform::setLocalTransform(glm::mat4 transform) {
|
||||
this->transformLocal = transform;
|
||||
|
||||
this->updateLocalValuesFromLocalTransform();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
glm::mat4 Transform::getWorldTransform() {
|
||||
return this->transformWorld;
|
||||
}
|
||||
|
||||
void Transform::setWorldTransform(glm::mat4 transform) {
|
||||
this->transformWorld = transform;
|
||||
this->updateLocalTransformFromWorldTransform();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
|
||||
void Transform::setParent(Transform *parent) {
|
||||
if(parent == this) throw "Cannot self reference";
|
||||
|
||||
auto currentParent = this->getParent();
|
||||
if(currentParent == parent) return;
|
||||
|
||||
if(currentParent != nullptr) {
|
||||
auto it = currentParent->children.begin();
|
||||
while(it != currentParent->children.end()) {
|
||||
if(*it == this) {
|
||||
currentParent->children.erase(it);
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
this->parent = parent;
|
||||
if(parent != nullptr) parent->children.push_back(this);
|
||||
|
||||
this->updateLocalTransformFromWorldTransform();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
Transform * Transform::getParent() {
|
||||
return this->parent;
|
||||
}
|
||||
|
||||
Transform::~Transform() {
|
||||
this->setParent(nullptr);
|
||||
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
(*it)->setParent(nullptr);
|
||||
++it;
|
||||
}
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Transform.hpp"
|
||||
#include "scene/SceneItem.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Transform::Transform(SceneItem *item) :
|
||||
transformLocal(1.0f),
|
||||
transformWorld(1.0f)
|
||||
{
|
||||
assertNotNull(item);
|
||||
this->item = item;
|
||||
this->updateLocalValuesFromLocalTransform();
|
||||
}
|
||||
|
||||
void Transform::updateLocalValuesFromLocalTransform() {
|
||||
glm::vec3 skew;
|
||||
glm::vec4 perspective;
|
||||
glm::decompose(
|
||||
this->transformLocal,
|
||||
this->localScale,
|
||||
this->localRotation,
|
||||
this->localPosition,
|
||||
skew, perspective
|
||||
);
|
||||
}
|
||||
|
||||
void Transform::updateLocalTransformFromLocalValues() {
|
||||
glm::mat4 translate = glm::translate(glm::mat4(1.0), this->localPosition);
|
||||
glm::mat4 rotate = glm::mat4_cast(this->localRotation);
|
||||
glm::mat4 scale = glm::scale(glm::mat4(1.0), this->localScale);
|
||||
this->transformLocal = translate * rotate * scale;
|
||||
this->updateWorldTransformFromLocalTransform();
|
||||
}
|
||||
|
||||
void Transform::updateWorldTransformFromLocalTransform() {
|
||||
glm::mat4 newWorld(1.0f);
|
||||
auto parent = this->getParent();
|
||||
if(parent != nullptr) newWorld = parent->getWorldTransform();
|
||||
this->transformWorld = newWorld * transformLocal;
|
||||
}
|
||||
|
||||
void Transform::updateLocalTransformFromWorldTransform() {
|
||||
glm::mat4 parentMat(1.0f);
|
||||
auto parent = this->getParent();
|
||||
if(parent != nullptr) parentMat = parent->getWorldTransform();
|
||||
this->transformLocal = parentMat / this->transformWorld;
|
||||
this->updateLocalValuesFromLocalTransform();
|
||||
}
|
||||
|
||||
void Transform::updateChildrenTransforms() {
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
(*it)->updateWorldTransformFromLocalTransform();
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::lookAt(glm::vec3 pos, glm::vec3 look) {
|
||||
this->lookAt(pos, look, glm::vec3(0, 1, 0));
|
||||
}
|
||||
|
||||
void Transform::lookAt(glm::vec3 pos, glm::vec3 look, glm::vec3 up) {
|
||||
this->setWorldTransform(glm::lookAt(pos, look, up));
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 Transform::getLocalPosition() {
|
||||
return this->localPosition;
|
||||
}
|
||||
|
||||
void Transform::setLocalPosition(glm::vec3 position) {
|
||||
this->localPosition = position;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
glm::vec3 Transform::getLocalScale() {
|
||||
return this->localScale;
|
||||
}
|
||||
|
||||
void Transform::setLocalScale(glm::vec3 scale) {
|
||||
this->localScale = scale;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
glm::quat Transform::getLocalRotation() {
|
||||
return this->localRotation;
|
||||
}
|
||||
|
||||
void Transform::setLocalRotation(glm::quat rotation) {
|
||||
this->localRotation = rotation;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
|
||||
glm::mat4 Transform::getLocalTransform() {
|
||||
return this->transformLocal;
|
||||
}
|
||||
|
||||
void Transform::setLocalTransform(glm::mat4 transform) {
|
||||
this->transformLocal = transform;
|
||||
|
||||
this->updateLocalValuesFromLocalTransform();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
glm::mat4 Transform::getWorldTransform() {
|
||||
return this->transformWorld;
|
||||
}
|
||||
|
||||
void Transform::setWorldTransform(glm::mat4 transform) {
|
||||
this->transformWorld = transform;
|
||||
this->updateLocalTransformFromWorldTransform();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
|
||||
void Transform::setParent(Transform *parent) {
|
||||
assertTrue(parent != this);
|
||||
|
||||
auto currentParent = this->getParent();
|
||||
if(currentParent == parent) return;
|
||||
|
||||
if(currentParent != nullptr) {
|
||||
auto it = currentParent->children.begin();
|
||||
while(it != currentParent->children.end()) {
|
||||
if(*it == this) {
|
||||
currentParent->children.erase(it);
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
this->parent = parent;
|
||||
if(parent != nullptr) parent->children.push_back(this);
|
||||
|
||||
this->updateLocalTransformFromWorldTransform();
|
||||
this->updateChildrenTransforms();
|
||||
}
|
||||
|
||||
Transform * Transform::getParent() {
|
||||
return this->parent;
|
||||
}
|
||||
|
||||
Transform::~Transform() {
|
||||
this->setParent(nullptr);
|
||||
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
(*it)->setParent(nullptr);
|
||||
++it;
|
||||
}
|
||||
}
|
@ -1,145 +1,146 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "util/flag.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SceneItem;
|
||||
|
||||
class Transform : public std::enable_shared_from_this<Transform> {
|
||||
private:
|
||||
// Local (real) values
|
||||
glm::vec3 localPosition;
|
||||
glm::vec3 localScale;
|
||||
glm::quat localRotation;
|
||||
|
||||
// Cached (non-real) values
|
||||
glm::mat4 transformLocal;
|
||||
glm::mat4 transformWorld;
|
||||
|
||||
// glm::vec3 position;
|
||||
// glm::vec3 scale;
|
||||
// glm::quat rotation;
|
||||
|
||||
// Heirarchy
|
||||
Transform *parent = nullptr;
|
||||
std::vector<Transform *> children;
|
||||
|
||||
// Hidden methods
|
||||
void updateLocalValuesFromLocalTransform();
|
||||
void updateLocalTransformFromLocalValues();
|
||||
void updateWorldTransformFromLocalTransform();
|
||||
void updateLocalTransformFromWorldTransform();
|
||||
void updateChildrenTransforms();
|
||||
|
||||
public:
|
||||
SceneItem &item;
|
||||
|
||||
/**
|
||||
* Constructs a new transform instance. Currently I have bound transforms
|
||||
* to their parent SceneItem, but in future I may allow them to become
|
||||
* disconnected from each other, for example I really could use a special
|
||||
* transform designed purely for UI elements, since they don't act like
|
||||
* normal scene items, but for now Transforms and SceneItems are 1:1
|
||||
*
|
||||
* @param item Item that this transform belongs to.
|
||||
*/
|
||||
Transform(SceneItem &item);
|
||||
|
||||
/**
|
||||
* Orients this transform to look at a given point in world space.
|
||||
*
|
||||
* @param position Position of the origin of this transform.
|
||||
* @param look Position in world space this transform looks at.
|
||||
*/
|
||||
void lookAt(glm::vec3 position, glm::vec3 look);
|
||||
void lookAt(glm::vec3 position, glm::vec3 look, glm::vec3 up);
|
||||
|
||||
/**
|
||||
* Returns the local position (position relative to "my parent").
|
||||
* @return The 3D local position in parent-relative space.
|
||||
*/
|
||||
glm::vec3 getLocalPosition();
|
||||
|
||||
/**
|
||||
* Update / Set the local position of this transform relative to my parent
|
||||
* @param position Position to set for the local transform.
|
||||
*/
|
||||
void setLocalPosition(glm::vec3 position);
|
||||
|
||||
/**
|
||||
* Retusn the scale of this item, relative to my parent.
|
||||
* @return 3D Scale vector of this item in parent-relative space.
|
||||
*/
|
||||
glm::vec3 getLocalScale();
|
||||
|
||||
/**
|
||||
* Set the local scale of this item.
|
||||
* @param scale Scale of this item, relative to its parent.
|
||||
*/
|
||||
void setLocalScale(glm::vec3 scale);
|
||||
|
||||
/**
|
||||
* Returns the local rotation for this transform.
|
||||
* @return The local rotation (parent-relative).
|
||||
*/
|
||||
glm::quat getLocalRotation();
|
||||
|
||||
/**
|
||||
* Set the local (parent-relative) rotation for this transform.
|
||||
* @param rotation Rotation in parent relative space.
|
||||
*/
|
||||
void setLocalRotation(glm::quat rotation);
|
||||
|
||||
/**
|
||||
* Returns the transform matrix for this transform, in parent-relative
|
||||
* space.
|
||||
* @return The transform origin in parent-relative space.
|
||||
*/
|
||||
glm::mat4 getLocalTransform();
|
||||
|
||||
/**
|
||||
* Sets the local transform matrix for this transform.
|
||||
* @param transform Local (parent-relative) transform to set.
|
||||
*/
|
||||
void setLocalTransform(glm::mat4 transform);
|
||||
|
||||
/**
|
||||
* Returns the transformation matrix for this transform, in world-space.
|
||||
* @return The transform origin in world-space.
|
||||
*/
|
||||
glm::mat4 getWorldTransform();
|
||||
|
||||
/**
|
||||
* Updates the transform's world-space.
|
||||
* @param transform Sets the transform position in world-space.
|
||||
*/
|
||||
void setWorldTransform(glm::mat4 transform);
|
||||
|
||||
/**
|
||||
* Updates the transform that this transform is a child of. Will also
|
||||
* handle disconnecting any existing parent.
|
||||
*
|
||||
* @param p Parent that this transform is now a child of.
|
||||
*/
|
||||
void setParent(Transform *p);
|
||||
|
||||
/**
|
||||
* Returns the parent transform of this transform, or nullptr if there is
|
||||
* no parent for this transform.
|
||||
* @return Pointer to the parent transform, or nullptr.
|
||||
*/
|
||||
Transform * getParent();
|
||||
|
||||
/**
|
||||
* Dispose and clenaup this transform, also removes self from parent.
|
||||
*/
|
||||
~Transform();
|
||||
|
||||
friend SceneItem;
|
||||
};
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "util/flag.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SceneItem;
|
||||
|
||||
class Transform {
|
||||
private:
|
||||
// Local (real) values
|
||||
glm::vec3 localPosition;
|
||||
glm::vec3 localScale;
|
||||
glm::quat localRotation;
|
||||
|
||||
// Cached (non-real) values
|
||||
glm::mat4 transformLocal;
|
||||
glm::mat4 transformWorld;
|
||||
|
||||
// glm::vec3 position;
|
||||
// glm::vec3 scale;
|
||||
// glm::quat rotation;
|
||||
|
||||
// Heirarchy
|
||||
Transform *parent = nullptr;
|
||||
std::vector<Transform *> children;
|
||||
|
||||
// Hidden methods
|
||||
void updateLocalValuesFromLocalTransform();
|
||||
void updateLocalTransformFromLocalValues();
|
||||
void updateWorldTransformFromLocalTransform();
|
||||
void updateLocalTransformFromWorldTransform();
|
||||
void updateChildrenTransforms();
|
||||
|
||||
public:
|
||||
SceneItem *item;
|
||||
|
||||
/**
|
||||
* Constructs a new transform instance. Currently I have bound transforms
|
||||
* to their parent SceneItem, but in future I may allow them to become
|
||||
* disconnected from each other, for example I really could use a special
|
||||
* transform designed purely for UI elements, since they don't act like
|
||||
* normal scene items, but for now Transforms and SceneItems are 1:1
|
||||
*
|
||||
* @param item Item that this transform belongs to.
|
||||
*/
|
||||
Transform(SceneItem *item);
|
||||
|
||||
/**
|
||||
* Orients this transform to look at a given point in world space.
|
||||
*
|
||||
* @param position Position of the origin of this transform.
|
||||
* @param look Position in world space this transform looks at.
|
||||
*/
|
||||
void lookAt(glm::vec3 position, glm::vec3 look);
|
||||
void lookAt(glm::vec3 position, glm::vec3 look, glm::vec3 up);
|
||||
|
||||
/**
|
||||
* Returns the local position (position relative to "my parent").
|
||||
* @return The 3D local position in parent-relative space.
|
||||
*/
|
||||
glm::vec3 getLocalPosition();
|
||||
|
||||
/**
|
||||
* Update / Set the local position of this transform relative to my parent
|
||||
* @param position Position to set for the local transform.
|
||||
*/
|
||||
void setLocalPosition(glm::vec3 position);
|
||||
|
||||
/**
|
||||
* Retusn the scale of this item, relative to my parent.
|
||||
* @return 3D Scale vector of this item in parent-relative space.
|
||||
*/
|
||||
glm::vec3 getLocalScale();
|
||||
|
||||
/**
|
||||
* Set the local scale of this item.
|
||||
* @param scale Scale of this item, relative to its parent.
|
||||
*/
|
||||
void setLocalScale(glm::vec3 scale);
|
||||
|
||||
/**
|
||||
* Returns the local rotation for this transform.
|
||||
* @return The local rotation (parent-relative).
|
||||
*/
|
||||
glm::quat getLocalRotation();
|
||||
|
||||
/**
|
||||
* Set the local (parent-relative) rotation for this transform.
|
||||
* @param rotation Rotation in parent relative space.
|
||||
*/
|
||||
void setLocalRotation(glm::quat rotation);
|
||||
|
||||
/**
|
||||
* Returns the transform matrix for this transform, in parent-relative
|
||||
* space.
|
||||
* @return The transform origin in parent-relative space.
|
||||
*/
|
||||
glm::mat4 getLocalTransform();
|
||||
|
||||
/**
|
||||
* Sets the local transform matrix for this transform.
|
||||
* @param transform Local (parent-relative) transform to set.
|
||||
*/
|
||||
void setLocalTransform(glm::mat4 transform);
|
||||
|
||||
/**
|
||||
* Returns the transformation matrix for this transform, in world-space.
|
||||
* @return The transform origin in world-space.
|
||||
*/
|
||||
glm::mat4 getWorldTransform();
|
||||
|
||||
/**
|
||||
* Updates the transform's world-space.
|
||||
* @param transform Sets the transform position in world-space.
|
||||
*/
|
||||
void setWorldTransform(glm::mat4 transform);
|
||||
|
||||
/**
|
||||
* Updates the transform that this transform is a child of. Will also
|
||||
* handle disconnecting any existing parent.
|
||||
*
|
||||
* @param p Parent that this transform is now a child of.
|
||||
*/
|
||||
void setParent(Transform *p);
|
||||
|
||||
/**
|
||||
* Returns the parent transform of this transform, or nullptr if there is
|
||||
* no parent for this transform.
|
||||
* @return Pointer to the parent transform, or nullptr.
|
||||
*/
|
||||
Transform * getParent();
|
||||
|
||||
/**
|
||||
* Dispose and clenaup this transform, also removes self from parent.
|
||||
*/
|
||||
~Transform();
|
||||
|
||||
friend SceneItem;
|
||||
};
|
||||
}
|
@ -1,86 +1,89 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "RenderTarget.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "display/shader/UIShader.hpp"
|
||||
#include "util/flag.hpp"
|
||||
|
||||
#define RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST FLAG_DEFINE(0)
|
||||
#define RENDER_MANAGER_RENDER_FLAG_BLEND FLAG_DEFINE(1)
|
||||
|
||||
typedef flag_t renderflag_t;
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGame;
|
||||
class RenderPipeline;
|
||||
|
||||
class IRenderManager {
|
||||
protected:
|
||||
renderflag_t renderFlags = 0;
|
||||
|
||||
public:
|
||||
DawnGame &game;
|
||||
std::shared_ptr<RenderPipeline> renderPipeline;
|
||||
|
||||
/**
|
||||
* Default constructor for a render manager instance.
|
||||
*
|
||||
* @param game Game that this render manager belongs to.
|
||||
*/
|
||||
IRenderManager(DawnGame &game) : game(game) {}
|
||||
|
||||
/**
|
||||
* Returns the primary render target (the backbuffer) that draws directly
|
||||
* to the screen.
|
||||
*
|
||||
* @return Shared pointer to the backbuffer render target.
|
||||
*/
|
||||
virtual RenderTarget & getBackBuffer() = 0;
|
||||
|
||||
/**
|
||||
* Returns the current render pipeline intended to be used for rendering
|
||||
* the currently active scene on the game instance.
|
||||
*
|
||||
* @return Reference to the currently active main scene render pipeline.
|
||||
*/
|
||||
virtual RenderPipeline & getRenderPipeline() = 0;
|
||||
|
||||
/**
|
||||
* Returns the default shader, the default shader will be applied to the
|
||||
* materials first.
|
||||
*
|
||||
* @return Reference to the default shader.
|
||||
*/
|
||||
virtual std::shared_ptr<Shader> getDefaultShader() = 0;
|
||||
|
||||
/**
|
||||
* Returns the UI Shader used by the game's UI engine.
|
||||
*
|
||||
* @return Pointer to the UI Shader.
|
||||
*/
|
||||
virtual std::shared_ptr<UIShader> getUIShader() = 0;
|
||||
|
||||
/**
|
||||
* Sets the render flags for the render manager to use.
|
||||
*
|
||||
* @param renderFlags Render flags to use.
|
||||
*/
|
||||
virtual void setRenderFlags(renderflag_t renderFlags) = 0;
|
||||
|
||||
/**
|
||||
* Initialize / Start the Render Manager.
|
||||
*
|
||||
* @param game Game instance this render manager belongs to.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* Perform a synchronous frame update on the render manager.
|
||||
*/
|
||||
virtual void update() = 0;
|
||||
};
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "RenderTarget.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "display/shader/UIShader.hpp"
|
||||
#include "util/flag.hpp"
|
||||
|
||||
#define RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST FLAG_DEFINE(0)
|
||||
#define RENDER_MANAGER_RENDER_FLAG_BLEND FLAG_DEFINE(1)
|
||||
|
||||
typedef flag_t renderflag_t;
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGame;
|
||||
class RenderPipeline;
|
||||
|
||||
class IRenderManager {
|
||||
protected:
|
||||
renderflag_t renderFlags = 0;
|
||||
|
||||
public:
|
||||
DawnGame *game;
|
||||
RenderPipeline *renderPipeline;
|
||||
|
||||
/**
|
||||
* Default constructor for a render manager instance.
|
||||
*
|
||||
* @param game Game that this render manager belongs to.
|
||||
*/
|
||||
IRenderManager(DawnGame *game) {
|
||||
assertNotNull(game);
|
||||
this->game = game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primary render target (the backbuffer) that draws directly
|
||||
* to the screen.
|
||||
*
|
||||
* @return Shared pointer to the backbuffer render target.
|
||||
*/
|
||||
virtual RenderTarget * getBackBuffer() = 0;
|
||||
|
||||
/**
|
||||
* Returns the current render pipeline intended to be used for rendering
|
||||
* the currently active scene on the game instance.
|
||||
*
|
||||
* @return Reference to the currently active main scene render pipeline.
|
||||
*/
|
||||
virtual RenderPipeline * getRenderPipeline() = 0;
|
||||
|
||||
/**
|
||||
* Returns the default shader, the default shader will be applied to the
|
||||
* materials first.
|
||||
*
|
||||
* @return Reference to the default shader.
|
||||
*/
|
||||
virtual Shader * getDefaultShader() = 0;
|
||||
|
||||
/**
|
||||
* Returns the UI Shader used by the game's UI engine.
|
||||
*
|
||||
* @return Pointer to the UI Shader.
|
||||
*/
|
||||
virtual UIShader * getUIShader() = 0;
|
||||
|
||||
/**
|
||||
* Sets the render flags for the render manager to use.
|
||||
*
|
||||
* @param renderFlags Render flags to use.
|
||||
*/
|
||||
virtual void setRenderFlags(renderflag_t renderFlags) = 0;
|
||||
|
||||
/**
|
||||
* Initialize / Start the Render Manager.
|
||||
*
|
||||
* @param game Game instance this render manager belongs to.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* Perform a synchronous frame update on the render manager.
|
||||
*/
|
||||
virtual void update() = 0;
|
||||
};
|
||||
}
|
@ -1,19 +1,58 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Color.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class ITexture {
|
||||
public:
|
||||
virtual int32_t getWidth() = 0;
|
||||
virtual int32_t getHeight() = 0;
|
||||
virtual void setSize(int32_t width, int32_t height) = 0;
|
||||
virtual void fill(struct Color) = 0;
|
||||
virtual bool_t isReady() = 0;
|
||||
virtual void buffer(struct Color pixels[]) = 0;
|
||||
};
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Color.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class ITexture {
|
||||
public:
|
||||
/**
|
||||
* 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).
|
||||
*/
|
||||
virtual void setSize(int32_t width, int32_t height) = 0;
|
||||
|
||||
/**
|
||||
* Fill a texture with a single color. This is stupidly costly.
|
||||
*
|
||||
* @param color Color to fill.
|
||||
*/
|
||||
virtual void fill(struct Color) = 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.
|
||||
* @return The amount of bytes buffered to the texture.
|
||||
*/
|
||||
virtual void buffer(struct Color pixels[]) = 0;
|
||||
};
|
||||
}
|
@ -1,34 +1,72 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
#include "FontMeasure.hpp"
|
||||
|
||||
#define FONT_NEWLINE '\n'
|
||||
#define FONT_SPACE ' '
|
||||
|
||||
namespace Dawn {
|
||||
class Font {
|
||||
public:
|
||||
virtual void buffer(
|
||||
std::string text,
|
||||
float_t fontSize,
|
||||
float_t maxWidth,
|
||||
Mesh &mesh,
|
||||
struct FontMeasure *info
|
||||
) = 0;
|
||||
|
||||
virtual Texture & getTexture() = 0;
|
||||
virtual void draw(Mesh &mesh, int32_t startCharacter, int32_t length) = 0;
|
||||
virtual float_t getLineHeight(float_t fontSize) = 0;
|
||||
virtual float_t getDefaultFontSize() = 0;
|
||||
};
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
#include "FontMeasure.hpp"
|
||||
|
||||
#define FONT_NEWLINE '\n'
|
||||
#define FONT_SPACE ' '
|
||||
|
||||
namespace Dawn {
|
||||
class Font {
|
||||
public:
|
||||
/**
|
||||
* Buffer the characters of a string onto a primitive and get the result of the
|
||||
* buffer back as a resulting generic measurement information structure. Note
|
||||
* that measure is REQUIRED, and must be DISPOSED after it has been calculated.
|
||||
*
|
||||
* @param text String to buffer.
|
||||
* @param fontSize Font size to use for the buffer operation.
|
||||
* @param maxWidth Maximum width (in pixels) to use to textwrap. -1 for no wrap.
|
||||
* @param mesh Mesh to buffer the string on to.
|
||||
* @param info Pointer to where you want to store resulting measurements.
|
||||
*/
|
||||
virtual void buffer(
|
||||
std::string text,
|
||||
float_t fontSize,
|
||||
float_t maxWidth,
|
||||
Mesh *mesh,
|
||||
struct FontMeasure *info
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Returns the texture that is used for a given font.
|
||||
*
|
||||
* @return Pointer to the texture used by this font.
|
||||
*/
|
||||
virtual Texture * getTexture() = 0;
|
||||
|
||||
/**
|
||||
* Draw a previously buffered font primitive.
|
||||
*
|
||||
* @param mesh Mesh to draw.
|
||||
* @param start Start character to draw.
|
||||
* @param length Count of characters to draw, set to -1 to draw all.
|
||||
*/
|
||||
virtual void draw(Mesh *mesh, int32_t startCharacter, int32_t length) = 0;
|
||||
|
||||
/**
|
||||
* Returns the line height of a given font and font size combination.
|
||||
*
|
||||
* @param fontSize Font size to get the line height for.
|
||||
* @return The line height of this font at this font size.
|
||||
*/
|
||||
virtual float_t getLineHeight(float_t fontSize) = 0;
|
||||
|
||||
/**
|
||||
* Retreive the default font size of a given font. Useful if you want to use
|
||||
* the original font's font size for pixel-perfect rendering.
|
||||
*
|
||||
* @return The font size fo that font item.
|
||||
*/
|
||||
virtual float_t getDefaultFontSize() = 0;
|
||||
};
|
||||
}
|
@ -1,43 +1,50 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "FontMeasure.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
float_t FontMeasure::getWidth() {
|
||||
return this->width;
|
||||
}
|
||||
|
||||
float_t FontMeasure::getHeight() {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
int32_t FontMeasure::getQuadCount() {
|
||||
return this->realLength;
|
||||
}
|
||||
|
||||
float_t FontMeasure::getHeightOfLineCount(int32_t lineCount) {
|
||||
return this->lineHeight * lineCount;
|
||||
}
|
||||
|
||||
size_t FontMeasure::getLineCount() {
|
||||
return this->lines.size();
|
||||
}
|
||||
|
||||
int32_t FontMeasure::getQuadsOnLine(int32_t line) {
|
||||
return this->lines[line].length;
|
||||
}
|
||||
|
||||
int32_t FontMeasure::getQuadIndexOnLine(int32_t line) {
|
||||
return this->lines[line].start;
|
||||
}
|
||||
|
||||
void FontMeasure::addLine(int32_t start, int32_t len) {
|
||||
struct FontLineMeasure info;
|
||||
info.start = start;
|
||||
info.length = len;
|
||||
this->lines.push_back(info);
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "FontMeasure.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
float_t FontMeasure::getWidth() {
|
||||
return this->width;
|
||||
}
|
||||
|
||||
float_t FontMeasure::getHeight() {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
int32_t FontMeasure::getQuadCount() {
|
||||
return this->realLength;
|
||||
}
|
||||
|
||||
float_t FontMeasure::getHeightOfLineCount(int32_t lineCount) {
|
||||
assertTrue(lineCount > 0);
|
||||
return this->lineHeight * lineCount;
|
||||
}
|
||||
|
||||
size_t FontMeasure::getLineCount() {
|
||||
return this->lines.size();
|
||||
}
|
||||
|
||||
int32_t FontMeasure::getQuadsOnLine(int32_t line) {
|
||||
assertTrue(line >= 0);
|
||||
assertTrue(line < this->lines.size());
|
||||
return this->lines[line].length;
|
||||
}
|
||||
|
||||
int32_t FontMeasure::getQuadIndexOnLine(int32_t line) {
|
||||
assertTrue(line >= 0);
|
||||
assertTrue(line < this->lines.size());
|
||||
return this->lines[line].start;
|
||||
}
|
||||
|
||||
void FontMeasure::addLine(int32_t start, int32_t len) {
|
||||
assertTrue(start >= 0);
|
||||
assertTrue(len >= 0);
|
||||
struct FontLineMeasure info;
|
||||
info.start = start;
|
||||
info.length = len;
|
||||
this->lines.push_back(info);
|
||||
}
|
@ -1,50 +1,51 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct FontLineMeasure {
|
||||
/** What (real character) index the line starts at */
|
||||
int32_t start;
|
||||
/** How many (real) characters the line is in length */
|
||||
int32_t length;
|
||||
};
|
||||
|
||||
struct FontMeasure {
|
||||
public:
|
||||
/** How many raw chars are in the string */
|
||||
int32_t length;
|
||||
|
||||
/** How many real characters (non whitespace) are in the string */
|
||||
int32_t realLength;
|
||||
|
||||
/** The real character info for each line */
|
||||
std::vector<struct FontLineMeasure> lines;
|
||||
|
||||
/** Dimensions of the string */
|
||||
float_t width, height;
|
||||
|
||||
/** Height of a single line */
|
||||
float_t lineHeight;
|
||||
|
||||
/**
|
||||
* Internal method that adds a line to the text buffer process.
|
||||
*
|
||||
* @param start Start character index for the next line.
|
||||
* @param len Length of the next line.
|
||||
*/
|
||||
void addLine(int32_t start, int32_t length);
|
||||
|
||||
float_t getWidth();
|
||||
float_t getHeight();
|
||||
int32_t getQuadsOnLine(int32_t line);
|
||||
int32_t getQuadIndexOnLine(int32_t line);
|
||||
float_t getHeightOfLineCount(int32_t lineCount);
|
||||
size_t getLineCount();
|
||||
int32_t getQuadCount();
|
||||
};
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct FontLineMeasure {
|
||||
/** What (real character) index the line starts at */
|
||||
int32_t start;
|
||||
/** How many (real) characters the line is in length */
|
||||
int32_t length;
|
||||
};
|
||||
|
||||
struct FontMeasure {
|
||||
public:
|
||||
/** How many raw chars are in the string */
|
||||
int32_t length;
|
||||
|
||||
/** How many real characters (non whitespace) are in the string */
|
||||
int32_t realLength;
|
||||
|
||||
/** The real character info for each line */
|
||||
std::vector<struct FontLineMeasure> lines;
|
||||
|
||||
/** Dimensions of the string */
|
||||
float_t width, height;
|
||||
|
||||
/** Height of a single line */
|
||||
float_t lineHeight;
|
||||
|
||||
/**
|
||||
* Internal method that adds a line to the text buffer process.
|
||||
*
|
||||
* @param start Start character index for the next line.
|
||||
* @param len Length of the next line.
|
||||
*/
|
||||
void addLine(int32_t start, int32_t length);
|
||||
|
||||
float_t getWidth();
|
||||
float_t getHeight();
|
||||
int32_t getQuadsOnLine(int32_t line);
|
||||
int32_t getQuadIndexOnLine(int32_t line);
|
||||
float_t getHeightOfLineCount(int32_t lineCount);
|
||||
size_t getLineCount();
|
||||
int32_t getQuadCount();
|
||||
};
|
||||
}
|
@ -13,6 +13,12 @@
|
||||
using namespace Dawn;
|
||||
|
||||
void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){
|
||||
assertNotNull(quad);
|
||||
assertNotNull(x);
|
||||
assertNotNull(y);
|
||||
assertTrue(c >= TRUETYPE_FIRST_CHAR);
|
||||
assertTrue(c < (TRUETYPE_FIRST_CHAR+TRUETYPE_NUM_CHARS));
|
||||
|
||||
stbtt_GetBakedQuad(
|
||||
this->characterData,
|
||||
this->texture.getWidth(), this->texture.getHeight(),
|
||||
@ -40,11 +46,15 @@ void TrueTypeFont::buffer(
|
||||
std::string text,
|
||||
float_t fontSize,
|
||||
float_t maxWidth,
|
||||
Mesh &mesh,
|
||||
Mesh *mesh,
|
||||
struct FontMeasure *info
|
||||
) {
|
||||
auto stringLength = text.length();
|
||||
assertNotNull(mesh);
|
||||
assertNotNull(info);
|
||||
assertTrue(fontSize > 0);
|
||||
assertTrue(maxWidth == -1 || maxWidth > 0);
|
||||
|
||||
auto stringLength = text.length();
|
||||
if(stringLength == 0) {
|
||||
info->length = 0;
|
||||
info->realLength = 0;
|
||||
@ -53,15 +63,18 @@ void TrueTypeFont::buffer(
|
||||
info->width = 0;
|
||||
info->height = 0.0f;
|
||||
info->lineHeight = 0.0f;
|
||||
mesh.createBuffers(0, 0);
|
||||
mesh->createBuffers(0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
auto quads = new truetypequad_t[stringLength];
|
||||
assertNotNull(quads);
|
||||
|
||||
// Get the font scale
|
||||
auto scale = this->getScale(fontSize);
|
||||
|
||||
assertTrue(scale > 0);
|
||||
|
||||
// Adjust the max width to match the scale, and allow "no max width".
|
||||
maxWidth = maxWidth == -1 ? 9999999 : maxWidth * (1 / scale);
|
||||
|
||||
@ -143,7 +156,7 @@ void TrueTypeFont::buffer(
|
||||
}
|
||||
|
||||
// Initialize primitive
|
||||
mesh.createBuffers(
|
||||
mesh->createBuffers(
|
||||
QUAD_VERTICE_COUNT * info->realLength,
|
||||
QUAD_INDICE_COUNT * info->realLength
|
||||
);
|
||||
@ -163,7 +176,7 @@ void TrueTypeFont::buffer(
|
||||
info->height = mathMax<float_t>(info->height, quad->y1);
|
||||
|
||||
// Buffer the quad.
|
||||
QuadMesh::bufferQuadMesh(&mesh,
|
||||
QuadMesh::bufferQuadMesh(mesh,
|
||||
glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0),
|
||||
glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1),
|
||||
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
|
||||
@ -173,12 +186,14 @@ void TrueTypeFont::buffer(
|
||||
delete quads;
|
||||
}
|
||||
|
||||
Texture & TrueTypeFont::getTexture() {
|
||||
return this->texture;
|
||||
Texture * TrueTypeFont::getTexture() {
|
||||
return &this->texture;
|
||||
}
|
||||
|
||||
void TrueTypeFont::draw(Mesh &mesh, int32_t startchar, int32_t length) {
|
||||
mesh.draw(
|
||||
void TrueTypeFont::draw(Mesh *mesh, int32_t startchar, int32_t length) {
|
||||
assertNotNull(mesh);
|
||||
|
||||
mesh->draw(
|
||||
MESH_DRAW_MODE_TRIANGLES,
|
||||
startchar * QUAD_INDICE_COUNT,
|
||||
length == -1 ? length : length * QUAD_INDICE_COUNT
|
||||
@ -186,10 +201,10 @@ void TrueTypeFont::draw(Mesh &mesh, int32_t startchar, int32_t length) {
|
||||
}
|
||||
|
||||
float_t TrueTypeFont::getLineHeight(float_t fontSize) {
|
||||
assertTrue(fontSize > 0);
|
||||
return 13.0f;
|
||||
}
|
||||
|
||||
float_t TrueTypeFont::getDefaultFontSize() {
|
||||
return (float_t)this->fontSize;
|
||||
}
|
||||
|
||||
}
|
@ -71,12 +71,11 @@ namespace Dawn {
|
||||
std::string text,
|
||||
float_t fontSize,
|
||||
float_t maxWidth,
|
||||
Mesh &mesh,
|
||||
Mesh *mesh,
|
||||
struct FontMeasure *info
|
||||
) override;
|
||||
|
||||
Texture & getTexture() override;
|
||||
void draw(Mesh &mesh, int32_t startCharacter, int32_t length) override;
|
||||
Texture * getTexture() override;
|
||||
void draw(Mesh *mesh, int32_t startCharacter, int32_t length) override;
|
||||
float_t getLineHeight(float_t fontSize) override;
|
||||
float_t getDefaultFontSize() override;
|
||||
};
|
||||
|
@ -1,64 +1,66 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CubeMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void CubeMesh::buffer(
|
||||
Mesh &mesh,
|
||||
glm::vec3 pos, glm::vec3 size,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
mesh.bufferPositions(verticeStart, std::array<glm::vec3, CUBE_VERTICE_COUNT>{{
|
||||
pos,
|
||||
glm::vec3(pos.x+size.x, pos.y, pos.z),
|
||||
glm::vec3(pos.x, pos.y+size.y, pos.z),
|
||||
glm::vec3(pos.x+size.x, pos.y+size.y, pos.z),
|
||||
|
||||
glm::vec3(pos.x, pos.y, pos.z+size.z),
|
||||
glm::vec3(pos.x+size.x, pos.y, pos.z+size.z),
|
||||
glm::vec3(pos.x, pos.y+size.y, pos.z+size.z),
|
||||
pos + size
|
||||
}});
|
||||
|
||||
mesh.bufferCoordinates(verticeStart,std::array<glm::vec2,CUBE_VERTICE_COUNT>{{
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(1, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 1),
|
||||
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(1, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 1)
|
||||
}});
|
||||
|
||||
mesh.bufferIndices(indiceStart, std::array<meshindice_t, CUBE_INDICE_COUNT>{{
|
||||
// Back
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3,
|
||||
|
||||
// Right
|
||||
verticeStart + 1, verticeStart + 5, verticeStart + 7,
|
||||
verticeStart + 1, verticeStart + 3, verticeStart + 7,
|
||||
|
||||
// Left
|
||||
verticeStart + 4, verticeStart, verticeStart + 2,
|
||||
verticeStart + 4, verticeStart + 6, verticeStart + 2,
|
||||
|
||||
// Front
|
||||
verticeStart + 5, verticeStart + 4, verticeStart + 6,
|
||||
verticeStart + 5, verticeStart + 7, verticeStart + 6,
|
||||
|
||||
// Top
|
||||
verticeStart + 7, verticeStart + 2, verticeStart + 6,
|
||||
verticeStart + 7, verticeStart + 3, verticeStart + 2,
|
||||
|
||||
// Bottom
|
||||
verticeStart + 1, verticeStart, verticeStart + 4,
|
||||
verticeStart + 1, verticeStart + 4, verticeStart + 5
|
||||
}});
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CubeMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void CubeMesh::buffer(
|
||||
Mesh *mesh,
|
||||
glm::vec3 pos, glm::vec3 size,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
assertNotNull(mesh);
|
||||
|
||||
mesh->bufferPositions(verticeStart, std::array<glm::vec3, CUBE_VERTICE_COUNT>{{
|
||||
pos,
|
||||
glm::vec3(pos.x+size.x, pos.y, pos.z),
|
||||
glm::vec3(pos.x, pos.y+size.y, pos.z),
|
||||
glm::vec3(pos.x+size.x, pos.y+size.y, pos.z),
|
||||
|
||||
glm::vec3(pos.x, pos.y, pos.z+size.z),
|
||||
glm::vec3(pos.x+size.x, pos.y, pos.z+size.z),
|
||||
glm::vec3(pos.x, pos.y+size.y, pos.z+size.z),
|
||||
pos + size
|
||||
}});
|
||||
|
||||
mesh->bufferCoordinates(verticeStart,std::array<glm::vec2,CUBE_VERTICE_COUNT>{{
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(1, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 1),
|
||||
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(1, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 1)
|
||||
}});
|
||||
|
||||
mesh->bufferIndices(indiceStart, std::array<meshindice_t, CUBE_INDICE_COUNT>{{
|
||||
// Back
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3,
|
||||
|
||||
// Right
|
||||
verticeStart + 1, verticeStart + 5, verticeStart + 7,
|
||||
verticeStart + 1, verticeStart + 3, verticeStart + 7,
|
||||
|
||||
// Left
|
||||
verticeStart + 4, verticeStart, verticeStart + 2,
|
||||
verticeStart + 4, verticeStart + 6, verticeStart + 2,
|
||||
|
||||
// Front
|
||||
verticeStart + 5, verticeStart + 4, verticeStart + 6,
|
||||
verticeStart + 5, verticeStart + 7, verticeStart + 6,
|
||||
|
||||
// Top
|
||||
verticeStart + 7, verticeStart + 2, verticeStart + 6,
|
||||
verticeStart + 7, verticeStart + 3, verticeStart + 2,
|
||||
|
||||
// Bottom
|
||||
verticeStart + 1, verticeStart, verticeStart + 4,
|
||||
verticeStart + 1, verticeStart + 4, verticeStart + 5
|
||||
}});
|
||||
}
|
@ -1,21 +1,21 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
#define CUBE_VERTICE_COUNT 8
|
||||
#define CUBE_INDICE_COUNT 36
|
||||
|
||||
namespace Dawn {
|
||||
class CubeMesh {
|
||||
public:
|
||||
static void buffer(
|
||||
Mesh &mesh,
|
||||
glm::vec3 pos, glm::vec3 size,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
);
|
||||
};
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
#define CUBE_VERTICE_COUNT 8
|
||||
#define CUBE_INDICE_COUNT 36
|
||||
|
||||
namespace Dawn {
|
||||
class CubeMesh {
|
||||
public:
|
||||
static void buffer(
|
||||
Mesh *mesh,
|
||||
glm::vec3 pos, glm::vec3 size,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
);
|
||||
};
|
||||
}
|
@ -1,49 +1,51 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void QuadMesh::bufferQuadMeshWithZ(
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
float_t z, int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
mesh->bufferPositions(
|
||||
verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{
|
||||
glm::vec3(xy0, z),
|
||||
glm::vec3(xy1.x, xy0.y, z),
|
||||
glm::vec3(xy0.x, xy1.y, z),
|
||||
glm::vec3(xy1, z)
|
||||
}}
|
||||
);
|
||||
|
||||
mesh->bufferCoordinates(
|
||||
verticeStart, std::array<glm::vec2, QUAD_VERTICE_COUNT>{{
|
||||
uv0, glm::vec2(uv1.x, uv0.y),
|
||||
glm::vec2(uv0.x, uv1.y), uv1
|
||||
}}
|
||||
);
|
||||
|
||||
mesh->bufferIndices(
|
||||
indiceStart, std::array<meshindice_t, QUAD_INDICE_COUNT>{{
|
||||
verticeStart, verticeStart + 1, verticeStart + 2,
|
||||
verticeStart + 1, verticeStart + 2, verticeStart + 3
|
||||
}}
|
||||
);
|
||||
}
|
||||
|
||||
void QuadMesh::bufferQuadMesh(
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
QuadMesh::bufferQuadMeshWithZ(
|
||||
mesh, xy0, uv0, xy1, uv1, 0, verticeStart, indiceStart
|
||||
);
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void QuadMesh::bufferQuadMeshWithZ(
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
float_t z, int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
assertNotNull(mesh);
|
||||
|
||||
mesh->bufferPositions(
|
||||
verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{
|
||||
glm::vec3(xy0, z),
|
||||
glm::vec3(xy1.x, xy0.y, z),
|
||||
glm::vec3(xy0.x, xy1.y, z),
|
||||
glm::vec3(xy1, z)
|
||||
}}
|
||||
);
|
||||
|
||||
mesh->bufferCoordinates(
|
||||
verticeStart, std::array<glm::vec2, QUAD_VERTICE_COUNT>{{
|
||||
uv0, glm::vec2(uv1.x, uv0.y),
|
||||
glm::vec2(uv0.x, uv1.y), uv1
|
||||
}}
|
||||
);
|
||||
|
||||
mesh->bufferIndices(
|
||||
indiceStart, std::array<meshindice_t, QUAD_INDICE_COUNT>{{
|
||||
verticeStart, verticeStart + 1, verticeStart + 2,
|
||||
verticeStart + 1, verticeStart + 2, verticeStart + 3
|
||||
}}
|
||||
);
|
||||
}
|
||||
|
||||
void QuadMesh::bufferQuadMesh(
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
QuadMesh::bufferQuadMeshWithZ(
|
||||
mesh, xy0, uv0, xy1, uv1, 0, verticeStart, indiceStart
|
||||
);
|
||||
}
|
@ -1,25 +1,27 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "display/mesh/TriangleMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void TriangleMesh::createTriangleMesh(Mesh &mesh) {
|
||||
mesh.createBuffers(3, 3);
|
||||
mesh.bufferPositions(0, std::array<glm::vec3, 3>{{
|
||||
glm::vec3(-0.5f, -0.5f, 0),
|
||||
glm::vec3(0.5f, -0.5f, 0),
|
||||
glm::vec3(0, 0.5f, 0)
|
||||
}});
|
||||
mesh.bufferCoordinates(0, std::array<glm::vec2, 3>{{
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 0)
|
||||
}});
|
||||
mesh.bufferIndices(0, std::array<meshindice_t,3>{{
|
||||
0, 1, 2
|
||||
}});
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "display/mesh/TriangleMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void TriangleMesh::createTriangleMesh(Mesh *mesh) {
|
||||
assertNotNull(mesh);
|
||||
|
||||
mesh->createBuffers(3, 3);
|
||||
mesh->bufferPositions(0, std::array<glm::vec3, 3>{{
|
||||
glm::vec3(-0.5f, -0.5f, 0),
|
||||
glm::vec3(0.5f, -0.5f, 0),
|
||||
glm::vec3(0, 0.5f, 0)
|
||||
}});
|
||||
mesh->bufferCoordinates(0, std::array<glm::vec2, 3>{{
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 0)
|
||||
}});
|
||||
mesh->bufferIndices(0, std::array<meshindice_t,3>{{
|
||||
0, 1, 2
|
||||
}});
|
||||
}
|
@ -1,19 +1,19 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TriangleMesh {
|
||||
public:
|
||||
/**
|
||||
* Initializes a mesh to hold a single triangle.
|
||||
*
|
||||
* @param mesh Mesh to initialize as a triangle.
|
||||
*/
|
||||
static void createTriangleMesh(Mesh &mesh);
|
||||
};
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TriangleMesh {
|
||||
public:
|
||||
/**
|
||||
* Initializes a mesh to hold a single triangle.
|
||||
*
|
||||
* @param mesh Mesh to initialize as a triangle.
|
||||
*/
|
||||
static void createTriangleMesh(Mesh *mesh);
|
||||
};
|
||||
}
|
@ -33,7 +33,7 @@ namespace Dawn {
|
||||
*
|
||||
* @param material Material to set the default parameters on to.
|
||||
*/
|
||||
virtual void setDefaultParameters(Material &material) = 0;
|
||||
virtual void setDefaultParameters(Material *material) = 0;
|
||||
|
||||
/**
|
||||
* Requested by the render pipeline (typically) to set global level (once
|
||||
|
Reference in New Issue
Block a user