Subscenes
This commit is contained in:
@ -6,9 +6,9 @@
|
|||||||
# Check for build target, or default
|
# Check for build target, or default
|
||||||
if(NOT DEFINED DAWN_BUILD_TARGET)
|
if(NOT DEFINED DAWN_BUILD_TARGET)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(DAWN_BUILD_TARGET "target-platformergame-win32-glfw")
|
set(DAWN_BUILD_TARGET "target-pokergame-win32-glfw")
|
||||||
elseif(UNIX AND NOT APPLE)
|
elseif(UNIX AND NOT APPLE)
|
||||||
set(DAWN_BUILD_TARGET "target-platformergame-linux64-glfw")
|
set(DAWN_BUILD_TARGET "target-pokergame-linux64-glfw")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -29,6 +29,26 @@ void RenderPipeline::render() {
|
|||||||
void RenderPipeline::renderScene(Scene *scene) {
|
void RenderPipeline::renderScene(Scene *scene) {
|
||||||
assertNotNull(scene);
|
assertNotNull(scene);
|
||||||
|
|
||||||
|
// Render subscenes first.
|
||||||
|
auto subSceneControllers = scene->findComponents<SubSceneController>();
|
||||||
|
auto itSubScene = subSceneControllers.begin();
|
||||||
|
while(itSubScene != subSceneControllers.end()) {
|
||||||
|
auto subScene = (*itSubScene)->getSubScene();
|
||||||
|
if(subScene == nullptr) {
|
||||||
|
++itSubScene;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((*itSubScene)->onlyUpdateUnpaused && scene->game->timeManager.isPaused) {
|
||||||
|
++itSubScene;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->renderScene(subScene);
|
||||||
|
++itSubScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now render backbuffers.
|
||||||
auto backBuffer = this->renderManager->getBackBuffer();
|
auto backBuffer = this->renderManager->getBackBuffer();
|
||||||
auto cameras = scene->findComponents<Camera>();
|
auto cameras = scene->findComponents<Camera>();
|
||||||
Camera *backBufferCamera = nullptr;
|
Camera *backBufferCamera = nullptr;
|
||||||
@ -38,7 +58,8 @@ void RenderPipeline::renderScene(Scene *scene) {
|
|||||||
while(it != cameras.end()) {
|
while(it != cameras.end()) {
|
||||||
RenderTarget *cameraTarget = (*it)->getRenderTarget();
|
RenderTarget *cameraTarget = (*it)->getRenderTarget();
|
||||||
|
|
||||||
// Leave the backbuffer camera(s) to last, so we skip them.
|
// Leave the backbuffer camera(s) to last, so we skip them. we do this so
|
||||||
|
// that children framebuffers contain the CURRENT frame, not LAST frame.
|
||||||
if(cameraTarget == backBuffer) {
|
if(cameraTarget == backBuffer) {
|
||||||
backBufferCamera = *it;
|
backBufferCamera = *it;
|
||||||
} else {
|
} else {
|
||||||
@ -51,21 +72,15 @@ void RenderPipeline::renderScene(Scene *scene) {
|
|||||||
// Now render the backbuffer camera.
|
// Now render the backbuffer camera.
|
||||||
if(backBufferCamera == nullptr) return;
|
if(backBufferCamera == nullptr) return;
|
||||||
this->renderSceneCamera(scene, backBufferCamera);
|
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) {
|
void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
||||||
assertNotNull(scene);
|
assertNotNull(scene);
|
||||||
assertNotNull(camera);
|
assertNotNull(camera);
|
||||||
|
auto meshes = scene->findComponents<MeshRenderer>();
|
||||||
|
auto uiCanvasList = scene->findComponents<UICanvas>();
|
||||||
|
auto renderTarget = camera->getRenderTarget();
|
||||||
|
|
||||||
RenderTarget *renderTarget = camera->getRenderTarget();
|
|
||||||
assertNotNull(renderTarget);
|
assertNotNull(renderTarget);
|
||||||
|
|
||||||
renderTarget->bind();
|
renderTarget->bind();
|
||||||
@ -77,8 +92,8 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST |
|
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST |
|
||||||
RENDER_MANAGER_RENDER_FLAG_BLEND
|
RENDER_MANAGER_RENDER_FLAG_BLEND
|
||||||
);
|
);
|
||||||
|
|
||||||
auto meshes = scene->findComponents<MeshRenderer>();
|
// Render all Meshes on the scene
|
||||||
auto it = meshes.begin();
|
auto it = meshes.begin();
|
||||||
while(it != meshes.end()) {
|
while(it != meshes.end()) {
|
||||||
auto mesh = *it;
|
auto mesh = *it;
|
||||||
@ -91,6 +106,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto shader = material->getShader();
|
auto shader = material->getShader();
|
||||||
|
assertNotNull(shader);
|
||||||
shader->bind();
|
shader->bind();
|
||||||
shader->setGlobalParameters(camera->projection, camera->transform->getWorldTransform());
|
shader->setGlobalParameters(camera->projection, camera->transform->getWorldTransform());
|
||||||
shader->setMeshParameters(mesh->item->transform.getWorldTransform());
|
shader->setMeshParameters(mesh->item->transform.getWorldTransform());
|
||||||
@ -99,56 +115,69 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
mesh->mesh->draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
mesh->mesh->draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void RenderPipeline::renderUI(
|
|
||||||
Scene *scene,
|
|
||||||
Camera *camera,
|
|
||||||
UICanvas *canvas
|
|
||||||
) {
|
|
||||||
assertNotNull(scene);
|
|
||||||
assertNotNull(camera);
|
|
||||||
assertNotNull(canvas);
|
|
||||||
|
|
||||||
RenderTarget *renderTarget;
|
// Now we only render world-absolute UI canvas'
|
||||||
|
auto uiShader = this->renderManager->getUIShader();
|
||||||
|
assertNotNull(uiShader);
|
||||||
|
uiShader->bind();
|
||||||
|
uiShader->setUICamera(camera->projection, camera->transform->getWorldTransform());
|
||||||
|
this->renderManager->setRenderFlags(RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST);
|
||||||
|
|
||||||
glm::mat4 transform;
|
auto it2 = uiCanvasList.begin();
|
||||||
glm::mat4 projection;
|
while(it2 != uiCanvasList.end()) {
|
||||||
switch(canvas->drawType) {
|
auto canvas = *it2;
|
||||||
case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE:
|
|
||||||
transform = glm::mat4(1.0f);
|
switch(canvas->drawType) {
|
||||||
projection = glm::ortho(0.0f, canvas->getWidth(), canvas->getHeight(), 0.0f);
|
case UI_DRAW_TYPE_WORLD_ABSOLUTE:
|
||||||
renderTarget = camera->getRenderTarget();
|
break;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
assertUnreachable();
|
++it2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it3 = canvas->children.begin();
|
||||||
|
auto rootMatrix = canvas->transform->getWorldTransform();
|
||||||
|
while(it3 != canvas->children.end()) {
|
||||||
|
(*it3)->draw(uiShader,
|
||||||
|
glm::translate(glm::scale(rootMatrix, glm::vec3(1.0f, -1.0f, 1.0f)), glm::vec3(0, -renderTarget->getHeight(), 0))
|
||||||
|
);
|
||||||
|
++it3;
|
||||||
|
}
|
||||||
|
++it2;
|
||||||
}
|
}
|
||||||
|
|
||||||
assertNotNull(renderTarget);
|
|
||||||
|
// Now render camera-relative UI
|
||||||
// Clear / Bind / Update the render target.
|
|
||||||
renderTarget->bind();
|
|
||||||
// renderTarget->clear(
|
|
||||||
// RENDER_TARGET_CLEAR_FLAG_DEPTH |
|
|
||||||
// RENDER_TARGET_CLEAR_FLAG_COLOR
|
|
||||||
// );
|
|
||||||
this->renderManager->setRenderFlags(
|
this->renderManager->setRenderFlags(
|
||||||
RENDER_MANAGER_RENDER_FLAG_BLEND
|
RENDER_MANAGER_RENDER_FLAG_BLEND
|
||||||
);
|
);
|
||||||
|
uiShader->setUICamera(
|
||||||
|
glm::ortho(0.0f, renderTarget->getWidth(), renderTarget->getHeight(), 0.0f),
|
||||||
|
glm::mat4(1.0f)
|
||||||
|
);
|
||||||
|
|
||||||
// Prepare the UI Shader
|
it2 = uiCanvasList.begin();
|
||||||
auto shader = this->renderManager->getUIShader();
|
while(it2 != uiCanvasList.end()) {
|
||||||
assertNotNull(shader);
|
auto canvas = *it2;
|
||||||
|
|
||||||
shader->bind();
|
|
||||||
shader->setUICamera(transform, projection);
|
|
||||||
|
|
||||||
// Render the children
|
switch(canvas->drawType) {
|
||||||
glm::mat4 rootMatrix = canvas->transform->getWorldTransform();
|
case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE:
|
||||||
auto it = canvas->children.begin();
|
break;
|
||||||
while(it != canvas->children.end()) {
|
|
||||||
(*it)->draw(shader, rootMatrix);
|
default:
|
||||||
++it;
|
++it2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it3 = canvas->children.begin();
|
||||||
|
auto rootMatrix = canvas->transform->getWorldTransform();
|
||||||
|
while(it3 != canvas->children.end()) {
|
||||||
|
(*it3)->draw(uiShader, rootMatrix);
|
||||||
|
++it3;
|
||||||
|
}
|
||||||
|
++it2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,19 +51,6 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
virtual void renderSceneCamera(Scene *scene, Camera *camera);
|
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.
|
* Cleanup a render pipeline that has been initialized.
|
||||||
*/
|
*/
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class DawnGame;
|
class DawnGame;
|
||||||
|
class RenderPipeline;
|
||||||
|
|
||||||
class Scene {
|
class Scene {
|
||||||
private:
|
private:
|
||||||
@ -127,5 +128,7 @@ namespace Dawn {
|
|||||||
* Destroys a previously initialized Scene.
|
* Destroys a previously initialized Scene.
|
||||||
*/
|
*/
|
||||||
~Scene();
|
~Scene();
|
||||||
|
|
||||||
|
friend class RenderPipeline;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -7,4 +7,5 @@
|
|||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(example)
|
add_subdirectory(example)
|
||||||
add_subdirectory(physics)
|
add_subdirectory(physics)
|
||||||
|
add_subdirectory(scene)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
@ -11,7 +11,11 @@
|
|||||||
#include "scene/components/display/Material.hpp"
|
#include "scene/components/display/Material.hpp"
|
||||||
#include "scene/components/display/PixelPerfectCamera.hpp"
|
#include "scene/components/display/PixelPerfectCamera.hpp"
|
||||||
#include "scene/components/display/TiledSprite.hpp"
|
#include "scene/components/display/TiledSprite.hpp"
|
||||||
|
#include "scene/components/display/SimpleRenderTargetQuad.hpp"
|
||||||
|
|
||||||
#include "scene/components/example/ExampleSpin.hpp"
|
#include "scene/components/example/ExampleSpin.hpp"
|
||||||
|
|
||||||
|
#include "scene/components/scene/SubSceneController.hpp"
|
||||||
|
#include "scene/components/scene/SubSceneCameraAlign.hpp"
|
||||||
|
|
||||||
#include "scene/components/ui/UICanvas.hpp"
|
#include "scene/components/ui/UICanvas.hpp"
|
@ -13,4 +13,5 @@ target_sources(${DAWN_TARGET_NAME}
|
|||||||
MeshRenderer.cpp
|
MeshRenderer.cpp
|
||||||
PixelPerfectCamera.cpp
|
PixelPerfectCamera.cpp
|
||||||
TiledSprite.cpp
|
TiledSprite.cpp
|
||||||
|
SimpleRenderTargetQuad.cpp
|
||||||
)
|
)
|
@ -41,7 +41,13 @@ void PixelPerfectCamera::updateDimensions() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CAMERA_TYPE_PERSPECTIVE:
|
case CAMERA_TYPE_PERSPECTIVE:
|
||||||
assertDeprecated();
|
this->transform->lookAtPixelPerfect(
|
||||||
|
glm::vec3(0, 0, 0),
|
||||||
|
glm::vec3(0, 0, 0),
|
||||||
|
target->getHeight() / this->scale,
|
||||||
|
this->camera->fov
|
||||||
|
);
|
||||||
|
// this->transform->lookAt(glm::vec3(360, 360, 360), glm::vec3(0, 0, 0));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -19,7 +19,7 @@ namespace Dawn {
|
|||||||
void updateDimensions();
|
void updateDimensions();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float_t scale = 4.0f;
|
float_t scale = 1.0f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new PixelPerfectCamera Component.
|
* Create a new PixelPerfectCamera Component.
|
||||||
|
81
src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp
Normal file
81
src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "SimpleRenderTargetQuad.hpp"
|
||||||
|
#include "scene/Scene.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
|
||||||
|
SceneItemComponent(i)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleRenderTargetQuad::onRenderTargetResized(
|
||||||
|
RenderTarget *target, float_t w, float_t h
|
||||||
|
) {
|
||||||
|
assertTrue(target == this->renderTarget);
|
||||||
|
// Update mesh
|
||||||
|
QuadMesh::bufferQuadMesh(
|
||||||
|
&this->meshHost->mesh,
|
||||||
|
glm::vec2(0, 0), glm::vec2(0, 0),
|
||||||
|
glm::vec2(w, h), glm::vec2(1, 1),
|
||||||
|
0, 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) {
|
||||||
|
assertTrue(rt != this->renderTarget);
|
||||||
|
|
||||||
|
// Remove old event listener
|
||||||
|
if(this->renderTarget != nullptr) {
|
||||||
|
this->renderTarget->eventRenderTargetResized.removeListener(
|
||||||
|
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->renderTarget = rt;
|
||||||
|
|
||||||
|
// Add new event listener.
|
||||||
|
if(rt != nullptr) {
|
||||||
|
rt->eventRenderTargetResized.addListener(
|
||||||
|
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<SceneItemComponent*> SimpleRenderTargetQuad::getDependencies() {
|
||||||
|
return std::vector<SceneItemComponent*>{
|
||||||
|
(this->meshHost = this->item->getComponent<MeshHost>())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleRenderTargetQuad::onStart() {
|
||||||
|
assertNotNull(this->meshHost);
|
||||||
|
|
||||||
|
// Create quad mesh
|
||||||
|
this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
|
||||||
|
|
||||||
|
// Perform first resize.
|
||||||
|
if(this->renderTarget != nullptr) {
|
||||||
|
QuadMesh::bufferQuadMesh(
|
||||||
|
&this->meshHost->mesh,
|
||||||
|
glm::vec2(0, 0),
|
||||||
|
glm::vec2(0, 0),
|
||||||
|
glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()),
|
||||||
|
glm::vec2(1,1),
|
||||||
|
0, 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleRenderTargetQuad::~SimpleRenderTargetQuad() {
|
||||||
|
if(this->renderTarget != nullptr) {
|
||||||
|
this->renderTarget->eventRenderTargetResized.removeListener(
|
||||||
|
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
42
src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp
Normal file
42
src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "scene/components/display/MeshHost.hpp"
|
||||||
|
#include "display/RenderTarget.hpp"
|
||||||
|
#include "display/mesh/QuadMesh.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class SimpleRenderTargetQuad : public SceneItemComponent {
|
||||||
|
protected:
|
||||||
|
MeshHost *meshHost = nullptr;
|
||||||
|
RenderTarget *renderTarget = nullptr;
|
||||||
|
|
||||||
|
void onRenderTargetResized(RenderTarget *target, float_t w, float_t h);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Creates a SimpleRenderTargetQuad scene item component. This component
|
||||||
|
* will update the attached MeshHost any time the render target provided
|
||||||
|
* is updated / resized.
|
||||||
|
*
|
||||||
|
* @param item Item that this component is attached to.
|
||||||
|
*/
|
||||||
|
SimpleRenderTargetQuad(SceneItem *item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the render target to use for this quad. Can be set to nullptr when
|
||||||
|
* you no longer wish to listen for resize events.
|
||||||
|
*
|
||||||
|
* @param rt Render target to attach to.
|
||||||
|
*/
|
||||||
|
void setRenderTarget(RenderTarget *rt);
|
||||||
|
|
||||||
|
std::vector<SceneItemComponent*> getDependencies() override;
|
||||||
|
void onStart() override;
|
||||||
|
|
||||||
|
~SimpleRenderTargetQuad();
|
||||||
|
};
|
||||||
|
}
|
11
src/dawn/scene/components/scene/CMakeLists.txt
Normal file
11
src/dawn/scene/components/scene/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Copyright (c) 2022 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
|
PRIVATE
|
||||||
|
SubSceneCameraAlign.cpp
|
||||||
|
SubSceneController.cpp
|
||||||
|
)
|
102
src/dawn/scene/components/scene/SubSceneCameraAlign.cpp
Normal file
102
src/dawn/scene/components/scene/SubSceneCameraAlign.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "SubSceneCameraAlign.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
SubSceneCameraAlign::SubSceneCameraAlign(SceneItem *i) : SceneItemComponent(i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneCameraAlign::onRenderTargetResize(
|
||||||
|
RenderTarget *target, float_t w, float_t h
|
||||||
|
) {
|
||||||
|
this->realign();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneCameraAlign::realign() {
|
||||||
|
float_t diff;
|
||||||
|
if(this->camera == nullptr) return;
|
||||||
|
if(this->renderTarget == nullptr) return;
|
||||||
|
|
||||||
|
float_t ratio = this->renderTarget->getWidth() / this->renderTarget->getHeight();
|
||||||
|
float_t myRatio = this->camera->getRenderTarget()->getWidth() / this->camera->getRenderTarget()->getHeight();
|
||||||
|
|
||||||
|
this->camera->type = CAMERA_TYPE_ORTHONOGRAPHIC;
|
||||||
|
this->camera->transform->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0));
|
||||||
|
|
||||||
|
if(ratio > myRatio) {
|
||||||
|
// My Ratio is narrower
|
||||||
|
this->camera->orthoLeft = 0;
|
||||||
|
this->camera->orthoRight = this->renderTarget->getWidth();
|
||||||
|
diff = (this->renderTarget->getHeight() - (this->renderTarget->getWidth() / myRatio)) / 2.0f;
|
||||||
|
this->camera->orthoTop = this->renderTarget->getHeight() - diff;
|
||||||
|
this->camera->orthoBottom = diff;
|
||||||
|
} else {
|
||||||
|
// My ratio is wider
|
||||||
|
this->camera->orthoBottom = 0;
|
||||||
|
this->camera->orthoTop = this->renderTarget->getHeight();
|
||||||
|
diff = (this->renderTarget->getWidth() - (this->renderTarget->getHeight() * myRatio)) / 2.0f;
|
||||||
|
this->camera->orthoLeft = diff;
|
||||||
|
this->camera->orthoRight = this->renderTarget->getWidth() - diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneCameraAlign::setRenderTarget(TextureRenderTarget *renderTarget) {
|
||||||
|
assertTrue(this->renderTarget != renderTarget);
|
||||||
|
|
||||||
|
if(this->renderTarget != nullptr) {
|
||||||
|
this->renderTarget->eventRenderTargetResized.removeListener(
|
||||||
|
this, &SubSceneCameraAlign::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->renderTarget = renderTarget;
|
||||||
|
this->realign();
|
||||||
|
|
||||||
|
if(this->renderTarget != nullptr) {
|
||||||
|
this->renderTarget->eventRenderTargetResized.addListener(
|
||||||
|
this, &SubSceneCameraAlign::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneCameraAlign::setCamera(Camera *camera) {
|
||||||
|
assertTrue(this->camera != camera);
|
||||||
|
|
||||||
|
if(this->camera != nullptr) {
|
||||||
|
this->camera->getRenderTarget()->eventRenderTargetResized.removeListener(
|
||||||
|
this, &SubSceneCameraAlign::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->camera = camera;
|
||||||
|
this->realign();
|
||||||
|
|
||||||
|
if(this->camera != nullptr) {
|
||||||
|
this->camera->getRenderTarget()->eventRenderTargetResized.addListener(
|
||||||
|
this, &SubSceneCameraAlign::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneCameraAlign::onStart() {
|
||||||
|
this->realign();
|
||||||
|
}
|
||||||
|
|
||||||
|
SubSceneCameraAlign::~SubSceneCameraAlign() {
|
||||||
|
if(this->renderTarget != nullptr) {
|
||||||
|
this->renderTarget->eventRenderTargetResized.removeListener(
|
||||||
|
this, &SubSceneCameraAlign::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if(this->camera != nullptr) {
|
||||||
|
this->camera->getRenderTarget()->eventRenderTargetResized.removeListener(
|
||||||
|
this, &SubSceneCameraAlign::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
32
src/dawn/scene/components/scene/SubSceneCameraAlign.hpp
Normal file
32
src/dawn/scene/components/scene/SubSceneCameraAlign.hpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "scene/Scene.hpp"
|
||||||
|
#include "display/TextureRenderTarget.hpp"
|
||||||
|
#include "scene/components/display/Camera.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class SubSceneCameraAlign : public SceneItemComponent {
|
||||||
|
protected:
|
||||||
|
TextureRenderTarget *renderTarget = nullptr;
|
||||||
|
Camera *camera = nullptr;
|
||||||
|
|
||||||
|
void onRenderTargetResize(RenderTarget *target, float_t w, float_t h);
|
||||||
|
|
||||||
|
void realign();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
SubSceneCameraAlign(SceneItem *item);
|
||||||
|
|
||||||
|
void setRenderTarget(TextureRenderTarget *renderTarget);
|
||||||
|
void setCamera(Camera *camera);
|
||||||
|
|
||||||
|
void onStart() override;
|
||||||
|
|
||||||
|
~SubSceneCameraAlign();
|
||||||
|
};
|
||||||
|
}
|
45
src/dawn/scene/components/scene/SubSceneController.cpp
Normal file
45
src/dawn/scene/components/scene/SubSceneController.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "SubSceneController.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
SubSceneController::SubSceneController(SceneItem *i) : SceneItemComponent(i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneController::onSceneUpdate() {
|
||||||
|
if(this->onlyUpdateUnpaused) return;
|
||||||
|
if(this->subScene == nullptr) return;
|
||||||
|
this->subScene->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneController::onSceneUnpausedUpdate() {
|
||||||
|
if(!this->onlyUpdateUnpaused) return;
|
||||||
|
if(this->subScene == nullptr) return;
|
||||||
|
this->subScene->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene * SubSceneController::getSubScene() {
|
||||||
|
return this->subScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneController::setSubScene(Scene *scene) {
|
||||||
|
assertTrue(scene != this->subScene);
|
||||||
|
this->subScene = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubSceneController::onStart() {
|
||||||
|
auto myScene = this->getScene();
|
||||||
|
myScene->eventSceneUnpausedUpdate.addListener(this, &SubSceneController::onSceneUnpausedUpdate);
|
||||||
|
myScene->eventSceneUpdate.addListener(this, &SubSceneController::onSceneUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
SubSceneController::~SubSceneController() {
|
||||||
|
auto myScene = this->getScene();
|
||||||
|
myScene->eventSceneUnpausedUpdate.removeListener(this, &SubSceneController::onSceneUnpausedUpdate);
|
||||||
|
myScene->eventSceneUpdate.removeListener(this, &SubSceneController::onSceneUpdate);
|
||||||
|
}
|
29
src/dawn/scene/components/scene/SubSceneController.hpp
Normal file
29
src/dawn/scene/components/scene/SubSceneController.hpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "scene/Scene.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class SubSceneController : public SceneItemComponent {
|
||||||
|
protected:
|
||||||
|
Scene *subScene = nullptr;
|
||||||
|
|
||||||
|
void onSceneUpdate();
|
||||||
|
void onSceneUnpausedUpdate();
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool_t onlyUpdateUnpaused = true;
|
||||||
|
|
||||||
|
SubSceneController(SceneItem *item);
|
||||||
|
|
||||||
|
Scene * getSubScene();
|
||||||
|
void setSubScene(Scene *scene);
|
||||||
|
|
||||||
|
void onStart() override;
|
||||||
|
|
||||||
|
~SubSceneController();
|
||||||
|
};
|
||||||
|
}
|
@ -18,25 +18,7 @@ UICanvas * UICanvas::create(Scene *scene) {
|
|||||||
UICanvas::UICanvas(SceneItem *item) : SceneItemComponent(item) {
|
UICanvas::UICanvas(SceneItem *item) : SceneItemComponent(item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t UICanvas::getWidth() {
|
void UICanvas::onRenderTargetResize(RenderTarget *target, float_t w, float_t h){
|
||||||
return this->getGame()->renderManager.getBackBuffer()->getWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t UICanvas::getHeight() {
|
|
||||||
return this->getGame()->renderManager.getBackBuffer()->getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
void UICanvas::onStart() {
|
|
||||||
this->getGame()->renderManager.getBackBuffer()->eventRenderTargetResized
|
|
||||||
.addListener(this, &UICanvas::onBackBufferResize)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UICanvas::onBackBufferResize(
|
|
||||||
RenderTarget *target,
|
|
||||||
float_t width,
|
|
||||||
float_t height
|
|
||||||
) {
|
|
||||||
auto it = this->children.begin();
|
auto it = this->children.begin();
|
||||||
while(it != this->children.end()) {
|
while(it != this->children.end()) {
|
||||||
(*it)->updatePositions();
|
(*it)->updatePositions();
|
||||||
@ -44,14 +26,55 @@ void UICanvas::onBackBufferResize(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UICanvas::setCamera(Camera *camera) {
|
||||||
|
assertTrue(camera != this->camera);
|
||||||
|
|
||||||
|
if(this->camera != nullptr) {
|
||||||
|
this->camera->getRenderTarget()->eventRenderTargetResized.removeListener(
|
||||||
|
this, &UICanvas::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->camera = camera;
|
||||||
|
|
||||||
|
if(this->camera != nullptr) {
|
||||||
|
this->camera->getRenderTarget()->eventRenderTargetResized.addListener(
|
||||||
|
this, &UICanvas::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float_t UICanvas::getWidth() {
|
||||||
|
if(this->camera == nullptr) {
|
||||||
|
return this->getGame()->renderManager.getBackBuffer()->getWidth();
|
||||||
|
}
|
||||||
|
return this->camera->getRenderTarget()->getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
float_t UICanvas::getHeight() {
|
||||||
|
if(this->camera == nullptr) {
|
||||||
|
return this->getGame()->renderManager.getBackBuffer()->getHeight();
|
||||||
|
}
|
||||||
|
return this->camera->getRenderTarget()->getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UICanvas::onStart() {
|
||||||
|
if(this->camera == nullptr) {
|
||||||
|
auto camera = this->getScene()->findComponent<Camera>();
|
||||||
|
this->setCamera(camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UICanvas::~UICanvas() {
|
UICanvas::~UICanvas() {
|
||||||
auto it = this->children.begin();
|
auto it = this->children.begin();
|
||||||
while(it != this->children.end()) {
|
while(it != this->children.end()) {
|
||||||
delete *it;
|
delete *it;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->getGame()->renderManager.getBackBuffer()->eventRenderTargetResized
|
if(this->camera != nullptr) {
|
||||||
.removeListener(this, &UICanvas::onBackBufferResize)
|
this->camera->getRenderTarget()->eventRenderTargetResized.removeListener(
|
||||||
;
|
this, &UICanvas::onRenderTargetResize
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,6 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "scene/SceneItemComponent.hpp"
|
#include "scene/SceneItemComponent.hpp"
|
||||||
#include "display/RenderTarget.hpp"
|
#include "display/RenderTarget.hpp"
|
||||||
|
#include "scene/components/display/Camera.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
enum UIDrawType {
|
enum UIDrawType {
|
||||||
@ -18,11 +19,9 @@ namespace Dawn {
|
|||||||
|
|
||||||
class UICanvas : public SceneItemComponent {
|
class UICanvas : public SceneItemComponent {
|
||||||
protected:
|
protected:
|
||||||
void onBackBufferResize(
|
Camera *camera = nullptr;
|
||||||
RenderTarget *target,
|
|
||||||
float_t width,
|
void onRenderTargetResize(RenderTarget *target, float_t w, float_t h);
|
||||||
float_t height
|
|
||||||
);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -45,6 +44,13 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
UICanvas(SceneItem *item);
|
UICanvas(SceneItem *item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the camera used by the UI canvas.
|
||||||
|
*
|
||||||
|
* @param camera Camera to set for the UI canvas.
|
||||||
|
*/
|
||||||
|
void setCamera(Camera *camera);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct and append a UI item to this UI Canvas.
|
* Construct and append a UI item to this UI Canvas.
|
||||||
*
|
*
|
||||||
|
@ -57,6 +57,10 @@ void UILabel::setFontSize(float_t fontSize) {
|
|||||||
this->needsRebuffering = true;
|
this->needsRebuffering = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float_t UILabel::getFontSize() {
|
||||||
|
return this->fontSize;
|
||||||
|
}
|
||||||
|
|
||||||
float_t UILabel::getContentWidth() {
|
float_t UILabel::getContentWidth() {
|
||||||
this->updateMesh();
|
this->updateMesh();
|
||||||
return this->measure.getWidth();
|
return this->measure.getWidth();
|
||||||
|
@ -68,6 +68,13 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
void setFontSize(float_t fontSize);
|
void setFontSize(float_t fontSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the labels' current font size.
|
||||||
|
*
|
||||||
|
* @return Font size of the label.
|
||||||
|
*/
|
||||||
|
float_t getFontSize();
|
||||||
|
|
||||||
~UILabel();
|
~UILabel();
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -105,7 +105,7 @@ void VisualNovelTextbox::textboxOnSceneUpdate() {
|
|||||||
),
|
),
|
||||||
this->border.getBorderSize() + this->labelPadding
|
this->border.getBorderSize() + this->labelPadding
|
||||||
),
|
),
|
||||||
1.0f
|
5.0f
|
||||||
);
|
);
|
||||||
this->eventNewPage.invoke();
|
this->eventNewPage.invoke();
|
||||||
}
|
}
|
||||||
@ -167,6 +167,10 @@ void VisualNovelTextbox::setFontSize(float_t fontSize) {
|
|||||||
this->label.updateMesh();
|
this->label.updateMesh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float_t VisualNovelTextbox::getFontSize() {
|
||||||
|
return this->label.getFontSize();
|
||||||
|
}
|
||||||
|
|
||||||
void VisualNovelTextbox::setLabelPadding(glm::vec2 padding) {
|
void VisualNovelTextbox::setLabelPadding(glm::vec2 padding) {
|
||||||
this->labelPadding = padding;
|
this->labelPadding = padding;
|
||||||
this->updatePositions();
|
this->updatePositions();
|
||||||
|
@ -98,6 +98,13 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
void setFontSize(float_t fontSize);
|
void setFontSize(float_t fontSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current font size.
|
||||||
|
*
|
||||||
|
* @return Font size.
|
||||||
|
*/
|
||||||
|
float_t getFontSize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the padding of the label. This will increase the spacing between
|
* Sets the padding of the label. This will increase the spacing between
|
||||||
* the text and the border.
|
* the text and the border.
|
||||||
|
@ -60,10 +60,10 @@ int32_t DawnHost::init(DawnGame *game) {
|
|||||||
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_ENTER);
|
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_ENTER);
|
||||||
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_E);
|
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_E);
|
||||||
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_SPACE);
|
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_SPACE);
|
||||||
game->inputManager.bind(INPUT_BIND_NEGATIVE_X, GLFW_KEY_A);
|
// game->inputManager.bind(INPUT_BIND_NEGATIVE_X, GLFW_KEY_A);
|
||||||
game->inputManager.bind(INPUT_BIND_POSITIVE_X, GLFW_KEY_D);
|
// game->inputManager.bind(INPUT_BIND_POSITIVE_X, GLFW_KEY_D);
|
||||||
game->inputManager.bind(INPUT_BIND_NEGATIVE_Y, GLFW_KEY_S);
|
// game->inputManager.bind(INPUT_BIND_NEGATIVE_Y, GLFW_KEY_S);
|
||||||
game->inputManager.bind(INPUT_BIND_POSITIVE_Y, GLFW_KEY_W);
|
// game->inputManager.bind(INPUT_BIND_POSITIVE_Y, GLFW_KEY_W);
|
||||||
|
|
||||||
// Initialize the game
|
// Initialize the game
|
||||||
auto result = game->init();
|
auto result = game->init();
|
||||||
|
@ -10,6 +10,7 @@ target_sources(${DAWN_TARGET_NAME}
|
|||||||
BackBufferRenderTarget.cpp
|
BackBufferRenderTarget.cpp
|
||||||
StandardRenderPipeline.cpp
|
StandardRenderPipeline.cpp
|
||||||
Texture.cpp
|
Texture.cpp
|
||||||
|
TextureRenderTarget.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#include "util/memory.hpp"
|
#include "util/memory.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
|
class TextureRenderTarget;
|
||||||
|
|
||||||
typedef GLuint textureslot_t;
|
typedef GLuint textureslot_t;
|
||||||
|
|
||||||
class Texture : public ITexture {
|
class Texture : public ITexture {
|
||||||
@ -34,5 +36,7 @@ namespace Dawn {
|
|||||||
void bind(textureslot_t slot);
|
void bind(textureslot_t slot);
|
||||||
|
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
|
friend class TextureRenderTarget;
|
||||||
};
|
};
|
||||||
}
|
}
|
87
src/dawnopengl/display/TextureRenderTarget.cpp
Normal file
87
src/dawnopengl/display/TextureRenderTarget.cpp
Normal 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);
|
||||||
|
}
|
37
src/dawnopengl/display/TextureRenderTarget.hpp
Normal file
37
src/dawnopengl/display/TextureRenderTarget.hpp
Normal 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();
|
||||||
|
};
|
||||||
|
}
|
@ -99,9 +99,9 @@ namespace Dawn {
|
|||||||
this->setBoolean(this->paramHasTexture, false);
|
this->setBoolean(this->paramHasTexture, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUICamera(glm::mat4 view, glm::mat4 projection) {
|
void setUICamera(glm::mat4 projection, glm::mat4 view) {
|
||||||
this->setMatrix(this->paramView, view);
|
|
||||||
this->setMatrix(this->paramProjection, projection);
|
this->setMatrix(this->paramProjection, projection);
|
||||||
|
this->setMatrix(this->paramView, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUIModel(glm::mat4 model) {
|
void setUIModel(glm::mat4 model) {
|
||||||
|
@ -36,6 +36,7 @@ tool_texture(texture_tavern_morning borrowed/tavern_morning.png)
|
|||||||
tool_texture(texture_tavern_night borrowed/tavern_night.png)
|
tool_texture(texture_tavern_night borrowed/tavern_night.png)
|
||||||
tool_texture(texture_village_day borrowed/village_day.png)
|
tool_texture(texture_village_day borrowed/village_day.png)
|
||||||
tool_tileset(tileset_penny texture_penny characters/penny/penny-blink.png 1 22)
|
tool_tileset(tileset_penny texture_penny characters/penny/penny-blink.png 1 22)
|
||||||
|
tool_tileset(tileset_cards texture_cards ${DIR_GAME_ASSETS}/cards.png 14 4)
|
||||||
tool_truetype(truetype_ark
|
tool_truetype(truetype_ark
|
||||||
ark-pixel.ttf
|
ark-pixel.ttf
|
||||||
truetype_ark
|
truetype_ark
|
||||||
@ -46,8 +47,10 @@ tool_truetype(truetype_ark
|
|||||||
|
|
||||||
add_dependencies(${DAWN_TARGET_NAME}
|
add_dependencies(${DAWN_TARGET_NAME}
|
||||||
language_en
|
language_en
|
||||||
texture_test
|
|
||||||
tileset_penny
|
tileset_penny
|
||||||
|
tileset_cards
|
||||||
|
|
||||||
|
texture_test
|
||||||
truetype_ark
|
truetype_ark
|
||||||
texture_city_day
|
texture_city_day
|
||||||
texture_city_night
|
texture_city_night
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "DawnGame.hpp"
|
#include "DawnGame.hpp"
|
||||||
#include "scenes/Scene_1_1.hpp"
|
#include "scenes/SubsceneTest.hpp"
|
||||||
#include "scenes/TestScene.hpp"
|
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ int32_t DawnGame::init() {
|
|||||||
this->localeManager.init();
|
this->localeManager.init();
|
||||||
this->renderManager.init();
|
this->renderManager.init();
|
||||||
|
|
||||||
this->scene = new TestScene(this);
|
this->scene = new SubsceneTest(this);
|
||||||
|
|
||||||
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace Dawn {
|
|||||||
static void prefabApply(AssetManager *man, UIBorder *border) {
|
static void prefabApply(AssetManager *man, UIBorder *border) {
|
||||||
auto text = man->get<TextureAsset>("texture_test");
|
auto text = man->get<TextureAsset>("texture_test");
|
||||||
border->texture = &text->texture;
|
border->texture = &text->texture;
|
||||||
border->setBorderSize(glm::vec2(16, 16));
|
border->setBorderSize(glm::vec2(8, 8));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -22,11 +22,11 @@ namespace Dawn {
|
|||||||
auto assetFont = man->get<TrueTypeAsset>("truetype_ark");
|
auto assetFont = man->get<TrueTypeAsset>("truetype_ark");
|
||||||
UIBorderPrefab::apply(&textbox->border);
|
UIBorderPrefab::apply(&textbox->border);
|
||||||
textbox->setFont(&assetFont->font);
|
textbox->setFont(&assetFont->font);
|
||||||
textbox->setFontSize(40);
|
textbox->setFontSize(11);
|
||||||
textbox->setLabelPadding(glm::vec2(10, 8));
|
textbox->setLabelPadding(glm::vec2(4, 4));
|
||||||
textbox->setTransform(
|
textbox->setTransform(
|
||||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
|
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
|
||||||
glm::vec4(0, 238, 0, 0),
|
glm::vec4(0, assetFont->font.getLineHeight(textbox->getFontSize()) * 4, 0, 0),
|
||||||
0.0f
|
0.0f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,27 @@
|
|||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
PokerVNScene::PokerVNScene(DawnGame *game) : SimpleVNScene(game) {
|
PokerVNScene::PokerVNScene(DawnGame *game) :
|
||||||
|
SimpleVNScene(game),
|
||||||
|
renderTarget(320, 180)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Asset*> PokerVNScene::getRequiredAssets() {
|
std::vector<Asset*> PokerVNScene::getRequiredAssets() {
|
||||||
auto assMan = &this->game->assetManager;
|
auto assMan = &this->game->assetManager;
|
||||||
std::vector<Asset*> assets, l;
|
std::vector<Asset*> assets;
|
||||||
vectorAppend(&assets,SimpleVNScene::getRequiredAssets());
|
vectorAppend(&assets, SimpleVNScene::getRequiredAssets());
|
||||||
vectorAppend(&assets, &(l = PokerPlayerDisplay::getAssets(assMan)));
|
vectorAppend(&assets, PokerPlayerDisplay::getAssets(assMan));
|
||||||
return assets;
|
return assets;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PokerVNScene::vnStage() {
|
void PokerVNScene::vnStage() {
|
||||||
|
this->renderTarget.setClearColor(COLOR_RED);
|
||||||
|
this->camera->setRenderTarget(&this->renderTarget);
|
||||||
|
|
||||||
|
auto pixelPerfectCamera = this->camera->item->addComponent<PixelPerfectCamera>();
|
||||||
|
|
||||||
auto pokerGameItem = this->createSceneItem();
|
auto pokerGameItem = this->createSceneItem();
|
||||||
this->pokerGame = pokerGameItem->addComponent<PokerGame>();
|
this->pokerGame = pokerGameItem->addComponent<PokerGame>();
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "visualnovel/events/PokerBetLoopEvent.hpp"
|
#include "visualnovel/events/PokerBetLoopEvent.hpp"
|
||||||
#include "visualnovel/events/PokerInitialEvent.hpp"
|
#include "visualnovel/events/PokerInitialEvent.hpp"
|
||||||
#include "ui/PokerPlayerDisplay.hpp"
|
#include "ui/PokerPlayerDisplay.hpp"
|
||||||
|
#include "display/TextureRenderTarget.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class PokerVNScene : public SimpleVNScene {
|
class PokerVNScene : public SimpleVNScene {
|
||||||
@ -23,7 +24,10 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
virtual std::vector<PokerPlayer*> getPokerPlayers() = 0;
|
virtual std::vector<PokerPlayer*> getPokerPlayers() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
TextureRenderTarget renderTarget;
|
||||||
PokerGame *pokerGame;
|
PokerGame *pokerGame;
|
||||||
std::vector<PokerPlayer*> pokerPlayers;
|
std::vector<PokerPlayer*> pokerPlayers;
|
||||||
std::map<PokerPlayer*, PokerPlayerDisplay*> pokerPlayerDisplays;
|
std::map<PokerPlayer*, PokerPlayerDisplay*> pokerPlayerDisplays;
|
||||||
|
50
src/dawnpokergame/scenes/SubsceneTest.hpp
Normal file
50
src/dawnpokergame/scenes/SubsceneTest.hpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "scene/Scene.hpp"
|
||||||
|
#include "game/DawnGame.hpp"
|
||||||
|
#include "scenes/TestScene.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class SubsceneTest : public Scene {
|
||||||
|
public:
|
||||||
|
Camera *camera;
|
||||||
|
SceneItem *sceneItem;
|
||||||
|
TestScene subScene;
|
||||||
|
|
||||||
|
SubsceneTest(DawnGame *game) : Scene(game), subScene(game) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Asset*> getRequiredAssets() override {
|
||||||
|
return this->subScene.getRequiredAssets();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stage() override {
|
||||||
|
this->camera = Camera::create(this);
|
||||||
|
this->camera->transform->lookAt(glm::vec3(300, 300, 300), glm::vec3(0, 0, 0));
|
||||||
|
|
||||||
|
this->subScene.stage();
|
||||||
|
|
||||||
|
this->sceneItem = this->createSceneItem();
|
||||||
|
auto host = this->sceneItem->addComponent<MeshHost>();
|
||||||
|
auto renderer = this->sceneItem->addComponent<MeshRenderer>();
|
||||||
|
|
||||||
|
auto material = this->sceneItem->addComponent<Material>();
|
||||||
|
material->textureValues[material->getShader()->getParameterByName("u_Text")] = this->subScene.renderTarget.getTexture();
|
||||||
|
|
||||||
|
auto renderTargetQuad = this->sceneItem->addComponent<SimpleRenderTargetQuad>();
|
||||||
|
renderTargetQuad->setRenderTarget(&this->subScene.renderTarget);
|
||||||
|
|
||||||
|
auto subSceneController = this->sceneItem->addComponent<SubSceneController>();
|
||||||
|
subSceneController->setSubScene(&this->subScene);
|
||||||
|
|
||||||
|
auto subSceneCameraAlign = this->sceneItem->addComponent<SubSceneCameraAlign>();
|
||||||
|
subSceneCameraAlign->setRenderTarget(&this->subScene.renderTarget);
|
||||||
|
subSceneCameraAlign->setCamera(this->camera);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user