Fixed UI not rendering (partially)
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
|
||||
#include "RenderPipeline.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "scene/components/scene/SubSceneController.hpp"
|
||||
|
||||
#if DAWN_DEBUG_BUILD
|
||||
#include "scene/debug/SceneDebugLine.hpp"
|
||||
@ -174,7 +175,14 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
||||
shaderBufferData.view = camera->transform->getWorldTransform();
|
||||
this->shaderBuffer.buffer(&shaderBufferData);
|
||||
|
||||
this->camera = camera;
|
||||
// Prepare a render context. This is just a nice way of letting renderables
|
||||
// know a bit about what is happening, they can choose to use this data to
|
||||
// render themselves differently.
|
||||
struct IRenderableContext context = {
|
||||
scene,
|
||||
camera,
|
||||
this
|
||||
};
|
||||
|
||||
// Get the list of things to render first.
|
||||
std::vector<struct ShaderPassItem> shaderPassItems;
|
||||
@ -183,8 +191,8 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
||||
auto renderables = scene->findComponents<IRenderable>();
|
||||
auto itRenderables = renderables.begin();
|
||||
while(itRenderables != renderables.end()) {
|
||||
vectorAppend(&shaderPassItems, (*itRenderables)->getRenderPasses());
|
||||
++itRenderables;
|
||||
vectorAppend(&shaderPassItems, (*itRenderables)->getRenderPasses(context));
|
||||
++itRenderables;
|
||||
}
|
||||
|
||||
// Debug Lines
|
||||
|
@ -4,13 +4,11 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "scene/components/display/Material.hpp"
|
||||
#include "scene/components/display/Camera.hpp"
|
||||
#include "scene/components/scene/SubSceneController.hpp"
|
||||
#include "scene/components/ui/UIComponent.hpp"
|
||||
#include "display/_RenderManager.hpp"
|
||||
#include "display/shader/ShaderPass.hpp"
|
||||
#include "scene/components/display/IRenderable.hpp"
|
||||
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
|
||||
#include "scene/components/display/Camera.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class RenderManager;
|
||||
@ -21,9 +19,6 @@ namespace Dawn {
|
||||
|
||||
public:
|
||||
RenderManager *renderManager;
|
||||
|
||||
// Temporary hack
|
||||
Camera *camera = nullptr;
|
||||
RenderPipelineShaderBuffer shaderBuffer;
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,6 @@
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
#include "display/shader/ShaderParameterBuffer.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct ShaderPassItem {
|
||||
|
@ -4,17 +4,30 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Scene;
|
||||
class Camera;
|
||||
class RenderPipeline;
|
||||
|
||||
struct IRenderableContext {
|
||||
Scene *scene;
|
||||
Camera *camera;
|
||||
RenderPipeline *renderPipeline;
|
||||
};
|
||||
|
||||
class IRenderable {
|
||||
public:
|
||||
/**
|
||||
* Returns the render passes for this renderable item, typically a scene
|
||||
* item component, e.g. a Material or a UI Item.
|
||||
*
|
||||
* @param context Context about the current renderer state.
|
||||
* @return Array of renderable passes.
|
||||
*/
|
||||
virtual std::vector<struct ShaderPassItem> getRenderPasses() = 0;
|
||||
virtual std::vector<struct ShaderPassItem> getRenderPasses(
|
||||
struct IRenderableContext &context
|
||||
) = 0;
|
||||
};
|
||||
}
|
@ -8,6 +8,7 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UICanvas.cpp
|
||||
UIComponent.cpp
|
||||
UIComponentRenderable.cpp
|
||||
UILabel.cpp
|
||||
UIImage.cpp
|
||||
UIBorder.cpp
|
||||
|
@ -11,7 +11,7 @@ using namespace Dawn;
|
||||
UIBorder::UIBorder(SceneItem *item) :
|
||||
texture(nullptr),
|
||||
borderSize(glm::vec2(8, 8)),
|
||||
UIComponent(item)
|
||||
UIComponentRenderable(item)
|
||||
{
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ float_t UIBorder::getContentHeight() {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> UIBorder::getRenderPasses() {
|
||||
std::vector<struct ShaderPassItem> UIBorder::getUIRenderPasses() {
|
||||
struct ShaderPassItem item;
|
||||
auto shader = getGame()->renderManager.uiShader;
|
||||
item.shader = shader;
|
||||
|
@ -4,13 +4,13 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "UIComponent.hpp"
|
||||
#include "UIComponentRenderable.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
|
||||
#define UI_BORDER_QUAD_COUNT 9
|
||||
|
||||
namespace Dawn {
|
||||
class UIBorder : public UIComponent, public UIComponentRenderable {
|
||||
class UIBorder : public UIComponentRenderable {
|
||||
private:
|
||||
Mesh mesh;
|
||||
|
||||
@ -24,7 +24,7 @@ namespace Dawn {
|
||||
|
||||
float_t getContentWidth() override;
|
||||
float_t getContentHeight() override;
|
||||
std::vector<struct ShaderPassItem> getRenderPasses() override;
|
||||
std::vector<struct ShaderPassItem> getUIRenderPasses() override;
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
@ -7,7 +7,6 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
|
||||
UIComponent::UIComponent(SceneItem *item) :
|
||||
SceneItemComponent(item),
|
||||
alignment(glm::vec4(0, 0, 128, 128)),
|
||||
|
@ -6,6 +6,8 @@
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "scene/components/display/IRenderable.hpp"
|
||||
#include "display/RenderPipeline.hpp"
|
||||
#include "display/RenderManager.hpp"
|
||||
#include "UICanvas.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
|
||||
@ -22,20 +24,6 @@ namespace Dawn {
|
||||
UI_COMPONENT_ALIGN_UNIT_PERCENT
|
||||
};
|
||||
|
||||
class UIComponentRenderable : public IRenderable {
|
||||
public:
|
||||
/**
|
||||
* Implemented UI Components that have rendering should implement this and
|
||||
* return their rendering items. Items are passed back to the render
|
||||
* pipeline.
|
||||
*
|
||||
* @param projection Camera projection, obtained from the canvas.
|
||||
* @param view Camera view, obtained from the canvas.
|
||||
* @return A list of renderable shader pass items for this renderable.
|
||||
*/
|
||||
virtual std::vector<struct ShaderPassItem> getRenderPasses() = 0;
|
||||
};
|
||||
|
||||
class UIComponent : public SceneItemComponent, public UIComponentDimensional {
|
||||
protected:
|
||||
float_t width = 1;
|
||||
@ -117,7 +105,7 @@ namespace Dawn {
|
||||
*
|
||||
* @return Pointer to the UI Canvas this component is a child of.
|
||||
*/
|
||||
UICanvas * getCanvas();
|
||||
virtual UICanvas * getCanvas();
|
||||
|
||||
float_t getWidth() override;
|
||||
float_t getHeight() override;
|
||||
|
26
src/dawn/scene/components/ui/UIComponentRenderable.cpp
Normal file
26
src/dawn/scene/components/ui/UIComponentRenderable.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIComponentRenderable.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
UIComponentRenderable::UIComponentRenderable(SceneItem *i) : UIComponent(i) {
|
||||
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> UIComponentRenderable::getRenderPasses(
|
||||
struct IRenderableContext &context
|
||||
) {
|
||||
if(
|
||||
context.camera->getRenderTarget() !=
|
||||
context.renderPipeline->renderManager->getBackBuffer()
|
||||
) {
|
||||
auto canvas = this->getCanvas();
|
||||
if(canvas->drawType == UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE) return {};
|
||||
}
|
||||
|
||||
return this->getUIRenderPasses();
|
||||
}
|
26
src/dawn/scene/components/ui/UIComponentRenderable.hpp
Normal file
26
src/dawn/scene/components/ui/UIComponentRenderable.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "UIComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIComponentRenderable : public UIComponent, public IRenderable {
|
||||
public:
|
||||
UIComponentRenderable(SceneItem *item);
|
||||
|
||||
std::vector<struct ShaderPassItem> getRenderPasses(
|
||||
struct IRenderableContext &context
|
||||
) override;
|
||||
|
||||
/**
|
||||
* Higher level means to determine the render passes for this UI item. We
|
||||
* handle some of the more common functionality in the above override.
|
||||
*
|
||||
* @return Array of render passes for this UI item.
|
||||
*/
|
||||
virtual std::vector<struct ShaderPassItem> getUIRenderPasses() = 0;
|
||||
};
|
||||
}
|
@ -10,7 +10,7 @@ using namespace Dawn;
|
||||
|
||||
UIImage::UIImage(SceneItem *item) :
|
||||
texture(nullptr),
|
||||
UIComponent(item)
|
||||
UIComponentRenderable(item)
|
||||
{
|
||||
|
||||
}
|
||||
@ -25,12 +25,12 @@ float_t UIImage::getContentHeight() {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> UIImage::getRenderPasses() {
|
||||
std::vector<struct ShaderPassItem> UIImage::getUIRenderPasses() {
|
||||
struct ShaderPassItem item;
|
||||
auto shader = getGame()->renderManager.uiShader;
|
||||
item.shader = shader;
|
||||
item.colorValues[shader->paramColor] = this->color;
|
||||
item.parameterBuffers[shader->bufferUiCanvas] = &this->getCanvas()->shaderBuffer;
|
||||
item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
|
||||
item.matrixValues[shader->paramModel] = this->transform->getWorldTransform();
|
||||
if(this->texture == nullptr) {
|
||||
item.boolValues[shader->paramHasTexture] = false;
|
||||
|
@ -4,11 +4,11 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "UIComponent.hpp"
|
||||
#include "UIComponentRenderable.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIImage : public UIComponent, public UIComponentRenderable {
|
||||
class UIImage : public UIComponentRenderable {
|
||||
private:
|
||||
Mesh mesh;
|
||||
|
||||
@ -22,7 +22,7 @@ namespace Dawn {
|
||||
|
||||
float_t getContentWidth() override;
|
||||
float_t getContentHeight() override;
|
||||
std::vector<struct ShaderPassItem> getRenderPasses() override;
|
||||
std::vector<struct ShaderPassItem> getUIRenderPasses() override;
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
using namespace Dawn;
|
||||
|
||||
UILabel::UILabel(SceneItem *item) :
|
||||
UIComponent(item),
|
||||
UIComponentRenderable(item),
|
||||
text(""),
|
||||
fontSize(10.0f),
|
||||
font(&item->scene->game->renderManager.defaultFont),
|
||||
@ -67,7 +67,7 @@ void UILabel::updateMesh() {
|
||||
this->eventFontRebuffered.invoke();
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> UILabel::getRenderPasses() {
|
||||
std::vector<struct ShaderPassItem> UILabel::getUIRenderPasses() {
|
||||
if(!this->hasText()) return {};
|
||||
this->updateMesh();
|
||||
|
||||
|
@ -4,14 +4,14 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "UIComponent.hpp"
|
||||
#include "UIComponentRenderable.hpp"
|
||||
#include "display/font/Font.hpp"
|
||||
|
||||
#define UI_LABEL_MAX_WIDTH_NONE -1
|
||||
#define UI_LABEL_MAX_WIDTH_ALIGN 0
|
||||
|
||||
namespace Dawn {
|
||||
class UILabel : public UIComponent, public UIComponentRenderable {
|
||||
class UILabel : public UIComponentRenderable {
|
||||
private:
|
||||
bool_t needsRebuffering = true;
|
||||
Mesh mesh;
|
||||
@ -53,7 +53,7 @@ namespace Dawn {
|
||||
|
||||
float_t getContentWidth() override;
|
||||
float_t getContentHeight() override;
|
||||
std::vector<struct ShaderPassItem> getRenderPasses() override;
|
||||
std::vector<struct ShaderPassItem> getUIRenderPasses() override;
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/_RenderManager.hpp"
|
||||
#include "display/BackBufferRenderTarget.hpp"
|
||||
#include "display/shader/ShaderManager.hpp"
|
||||
#include "display/shader/shaders/SimpleTexturedShader.hpp"
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include "display/Color.hpp"
|
||||
#include "debug/debug.hpp"
|
||||
|
||||
#include "ShaderParameterBuffer.hpp"
|
||||
|
||||
typedef GLuint shaderparameter_t;
|
||||
|
||||
namespace Dawn {
|
||||
|
@ -2,13 +2,6 @@
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
|
||||
|
@ -4,8 +4,8 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleTexturedShader : public Shader {
|
||||
|
@ -4,8 +4,8 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
|
||||
|
||||
#define UI_SHADER_PROGRAM_PRIORITY 100
|
||||
|
||||
|
@ -22,7 +22,7 @@ void SimpleBillboardedMaterial::onDispose() {
|
||||
this->getGame()->renderManager.getShaderManager()->releaseShader<SimpleBillboardedShader>(this->shaderLock);
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> SimpleBillboardedMaterial::getRenderPasses() {
|
||||
std::vector<struct ShaderPassItem> SimpleBillboardedMaterial::getRenderPasses(IRenderableContext &context) {
|
||||
return {
|
||||
|
||||
};
|
||||
|
@ -26,6 +26,6 @@ namespace Dawn {
|
||||
|
||||
void onStart() override;
|
||||
void onDispose() override;
|
||||
std::vector<struct ShaderPassItem> getRenderPasses() override;
|
||||
std::vector<struct ShaderPassItem> getRenderPasses(IRenderableContext &context) override;
|
||||
};
|
||||
}
|
@ -21,27 +21,21 @@ void SimpleTexturedMaterial::onDispose() {
|
||||
this->getGame()->renderManager.getShaderManager()->releaseShader<SimpleTexturedShader>(this->shaderLock);
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> SimpleTexturedMaterial::getRenderPasses() {
|
||||
std::vector<struct ShaderPassItem> SimpleTexturedMaterial::getRenderPasses(IRenderableContext &context) {
|
||||
auto mesh = this->item->getComponent<MeshRenderer>();
|
||||
auto shader = this->getGame()->renderManager.getShaderManager()->getShader<SimpleTexturedShader>(this->shaderLock);
|
||||
auto camera = this->getGame()->renderManager.getRenderPipeline()->camera;
|
||||
|
||||
assertNotNull(mesh);
|
||||
assertNotNull(mesh->mesh);
|
||||
assertNotNull(shader);
|
||||
assertNotNull(camera);
|
||||
|
||||
struct ShaderPassItem onlyPass;
|
||||
onlyPass.mesh = mesh->mesh;
|
||||
onlyPass.shader = shader;
|
||||
onlyPass.colorValues[shader->paramColor] = this->color;
|
||||
onlyPass.matrixValues[shader->paramModel] = this->transform->getWorldTransform();
|
||||
onlyPass.parameterBuffers[shader->bufferRenderPipeline] = &context.renderPipeline->shaderBuffer;
|
||||
|
||||
onlyPass.parameterBuffers[shader->bufferRenderPipeline] = &this->getGame()->renderManager.getRenderPipeline()->shaderBuffer;
|
||||
|
||||
// onlyPass.matrixValues[shader->paramView] = camera->transform->getWorldTransform();
|
||||
// onlyPass.matrixValues[shader->paramProjection] = camera->getProjection();
|
||||
|
||||
onlyPass.renderFlags = (
|
||||
RENDER_MANAGER_RENDER_FLAG_BLEND |
|
||||
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
|
||||
@ -54,8 +48,6 @@ std::vector<struct ShaderPassItem> SimpleTexturedMaterial::getRenderPasses() {
|
||||
} else {
|
||||
onlyPass.boolValues[shader->paramHasTexture] = false;
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> passes;
|
||||
passes.push_back(onlyPass);
|
||||
return passes;
|
||||
|
||||
return { onlyPass };
|
||||
}
|
@ -27,6 +27,6 @@ namespace Dawn {
|
||||
|
||||
void onStart() override;
|
||||
void onDispose() override;
|
||||
std::vector<struct ShaderPassItem> getRenderPasses() override;
|
||||
std::vector<struct ShaderPassItem> getRenderPasses(IRenderableContext &context) override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user